Add the easy close feature to the new widgets.
The easy close feature closes windows by a single mouse click, without the need for a close button. Also converted the test dialog for the remove addons to use this feature and commenting out the button in the config (it will be needed later again).
This commit is contained in:
parent
b08ae9ce97
commit
cbac265dfb
20 changed files with 123 additions and 4 deletions
|
@ -33,6 +33,9 @@ Version 1.5.5+svn:
|
|||
in addition to the playable map area. The used mask must have the same
|
||||
border_size as the map (i.e. currently 1), else this will be ignored.
|
||||
* Restore x1, y1, x2, and y2 after events fired from events.
|
||||
* User interface:
|
||||
* The new widget library now also supports closing a dialog with a mouse
|
||||
click without a close button.
|
||||
* Miscellaneous and bug fixes:
|
||||
* fixed addon update version logic (patch #1110)
|
||||
|
||||
|
|
|
@ -329,6 +329,8 @@
|
|||
[resolution]
|
||||
definition = "default"
|
||||
|
||||
easy_close = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
@ -401,7 +403,9 @@
|
|||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
# Comment out the button for now since it's no longer needed.
|
||||
# It will be reenabled later to show the buttons optionally.
|
||||
#ifdef GUI_NO_SUCH_DEFINITION
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
@ -419,7 +423,7 @@
|
|||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
#endif
|
||||
[/grid]
|
||||
|
||||
[/resolution]
|
||||
|
|
|
@ -71,6 +71,7 @@ void tbutton::set_state(const tstate state)
|
|||
{
|
||||
if(state != state_) {
|
||||
state_ = state;
|
||||
set_block_easy_close(get_visible() && get_active());
|
||||
set_dirty(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,9 @@ public:
|
|||
/** Inherited from tcontrol. */
|
||||
unsigned get_state() const { return state_; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
bool does_block_easy_close() const { return true; }
|
||||
|
||||
/***** ***** ***** setters / getters for members ***** ****** *****/
|
||||
|
||||
void set_retval(const int retval) { retval_ = retval; }
|
||||
|
|
|
@ -125,6 +125,15 @@ public:
|
|||
/** Inherited from tcontrol. */
|
||||
void set_active(const bool active);
|
||||
|
||||
/**
|
||||
* Inherited from tcontrol.
|
||||
*
|
||||
* NOTE normally containers don't block, but their children may. But
|
||||
* normally the state for the children is set as well so we don't need to
|
||||
* delegate the request to our children.
|
||||
*/
|
||||
bool does_block_easy_close() const { return false; }
|
||||
|
||||
/***** **** ***** ***** wrappers to the grid **** ********* *****/
|
||||
|
||||
tgrid::iterator begin() { return grid_.begin(); }
|
||||
|
|
|
@ -53,6 +53,31 @@ void tcontrol::set_members(const std::map<
|
|||
}
|
||||
}
|
||||
|
||||
void tcontrol::set_block_easy_close(const bool block)
|
||||
{
|
||||
twindow* window = get_window();
|
||||
if(!window) {
|
||||
/*
|
||||
* This can happen in a listbox when the row data is manipulated before
|
||||
* the listbox is finalized. In that case that widget should do set the
|
||||
* state in its finalizer.
|
||||
*/
|
||||
DBG_GUI << "tcontrol(" + get_control_type() + ") " + __func__ + ": "
|
||||
"No window set, this might be a bug.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
if(block) {
|
||||
if(id().empty()) {
|
||||
set_id(get_uid());
|
||||
}
|
||||
window->add_easy_close_blocker(id());
|
||||
} else if(!id().empty()) {
|
||||
// It might never have been enabled so the id might be empty.
|
||||
window->remove_easy_close_blocker(id());
|
||||
}
|
||||
}
|
||||
|
||||
void tcontrol::mouse_hover(tevent_handler& event)
|
||||
{
|
||||
DBG_G_E << "Control: mouse hover.\n";
|
||||
|
@ -252,6 +277,15 @@ void tcontrol::set_size(const SDL_Rect& rect)
|
|||
update_canvas();
|
||||
}
|
||||
|
||||
void tcontrol::set_visible(const bool visible)
|
||||
{
|
||||
if(visible_ != visible) {
|
||||
visible_ = visible;
|
||||
set_block_easy_close(visible_ && does_block_easy_close());
|
||||
set_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
void tcontrol::set_label(const t_string& label)
|
||||
{
|
||||
if(label == label_) {
|
||||
|
|
|
@ -73,6 +73,31 @@ protected:
|
|||
|
||||
public:
|
||||
|
||||
/***** ***** ***** ***** Easy close handling ***** ***** ***** *****/
|
||||
|
||||
/**
|
||||
* Adds or removes a widget to/from the easy close block list.
|
||||
*
|
||||
* For adding to the block list an id is required, if not set it will get
|
||||
* one.
|
||||
*
|
||||
* @param block If true it's added to the blocklist, removed
|
||||
* otherwise.
|
||||
*/
|
||||
void set_block_easy_close(const bool block = true);
|
||||
|
||||
/**
|
||||
* Does the widget block the easy close feature?
|
||||
*
|
||||
* NOTE widgets that return true here, probably also need to make
|
||||
* modifications to their set_state() function. Easy close blocking _must_
|
||||
* be disabled when the widget is disabled or not visible. (The tcontrol
|
||||
* class handles the visibility part.)
|
||||
*
|
||||
* @returns Whether or not it blocks.
|
||||
*/
|
||||
virtual bool does_block_easy_close() const = 0;
|
||||
|
||||
/***** ***** ***** ***** Inherited ***** ***** ***** *****/
|
||||
|
||||
/** Inherted from tevent_executor. */
|
||||
|
@ -164,8 +189,7 @@ public:
|
|||
/***** ***** ***** setters / getters for members ***** ****** *****/
|
||||
|
||||
bool get_visible() const { return visible_; }
|
||||
void set_visible(const bool visible = true)
|
||||
{ if(visible_ != visible) { visible_ = visible; set_dirty();} }
|
||||
void set_visible(const bool visible = true);
|
||||
|
||||
bool get_use_tooltip_on_label_overflow() const { return use_tooltip_on_label_overflow_; }
|
||||
void set_use_tooltip_on_label_overflow(const bool use_tooltip = true)
|
||||
|
|
|
@ -91,6 +91,16 @@ void tgrid::set_child(twidget* widget, const unsigned row,
|
|||
// make sure the new child is valid before deferring
|
||||
cell.set_id(cell.widget()->id());
|
||||
cell.widget()->set_parent(this);
|
||||
|
||||
// Init the easy close state here, normally when put in a grid the grid
|
||||
// does have a parent window.
|
||||
tcontrol* control = dynamic_cast<tcontrol*>(cell.widget());
|
||||
if(control) {
|
||||
control->set_block_easy_close(
|
||||
control->get_visible()
|
||||
&& control->get_active()
|
||||
&& control->does_block_easy_close());
|
||||
}
|
||||
} else {
|
||||
cell.set_id("");
|
||||
}
|
||||
|
|
|
@ -50,6 +50,9 @@ public:
|
|||
/** Inherited from tcontrol. */
|
||||
unsigned get_state() const { return ENABLED; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
bool does_block_easy_close() const { return false; }
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,6 +44,9 @@ public:
|
|||
/** Inherited from tcontrol. */
|
||||
unsigned get_state() const { return state_; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
bool does_block_easy_close() const { return false; }
|
||||
|
||||
/***** ***** ***** setters / getters for members ***** ****** *****/
|
||||
|
||||
void set_can_wrap(const bool wrap) { can_wrap_ = wrap; }
|
||||
|
|
|
@ -52,6 +52,9 @@ public:
|
|||
/** Inherited from tcontrol. */
|
||||
unsigned get_state() const { return 0; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
bool does_block_easy_close() const { return false; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
void draw(surface& surface, const bool force = false,
|
||||
const bool invalidate_background = false);
|
||||
|
|
|
@ -199,6 +199,7 @@ void tscrollbar_::set_state(const tstate state)
|
|||
{
|
||||
if(state != state_) {
|
||||
state_ = state;
|
||||
set_block_easy_close(get_visible() && get_active());
|
||||
set_dirty(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,6 +121,9 @@ public:
|
|||
/** Inherited from tcontrol. */
|
||||
unsigned get_state() const { return state_; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
bool does_block_easy_close() const { return true; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
void set_size(const SDL_Rect& rect);
|
||||
|
||||
|
|
|
@ -46,6 +46,9 @@ public:
|
|||
/** Inherited from tcontrol. */
|
||||
unsigned get_state() const { return 0; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
bool does_block_easy_close() const { return false; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
tpoint get_best_size() const
|
||||
{ return best_size_ != tpoint(0, 0) ? best_size_ : tcontrol::get_best_size(); }
|
||||
|
|
|
@ -311,6 +311,7 @@ void ttext_::set_state(const tstate state)
|
|||
{
|
||||
if(state != state_) {
|
||||
state_ = state;
|
||||
set_block_easy_close(get_visible() && get_active());
|
||||
set_dirty(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,6 +69,9 @@ public:
|
|||
/** Inherited from tcontrol. */
|
||||
unsigned get_state() const { return state_; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
bool does_block_easy_close() const { return true; }
|
||||
|
||||
/***** ***** ***** ***** expose some functions ***** ***** ***** *****/
|
||||
|
||||
void set_maximum_length(const size_t maximum_length);
|
||||
|
|
|
@ -141,6 +141,7 @@ void ttoggle_button::set_state(const tstate state)
|
|||
{
|
||||
if(state != state_) {
|
||||
state_ = state;
|
||||
set_block_easy_close(get_visible() && get_active());
|
||||
set_dirty(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,6 +69,9 @@ public:
|
|||
/** Inherited from tcontrol. */
|
||||
unsigned get_state() const { return state_; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
bool does_block_easy_close() const { return true; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
void update_canvas();
|
||||
|
||||
|
|
|
@ -45,6 +45,9 @@ public:
|
|||
/** Inherited from tcontrol. */
|
||||
unsigned get_state() const { return 0; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
bool does_block_easy_close() const { return false; }
|
||||
|
||||
private:
|
||||
/** Inherited from tcontrol. */
|
||||
const std::string& get_control_type() const
|
||||
|
|
|
@ -433,6 +433,10 @@ void tvertical_scrollbar_container_::finalize_setup()
|
|||
find_scrollbar_grid();
|
||||
content_find_grid();
|
||||
|
||||
// Set the easy close status.
|
||||
/** @todo needs more testing. */
|
||||
set_block_easy_close(get_visible() && get_active() && does_block_easy_close());
|
||||
|
||||
// Call the virtual function to subclasses can do their finalization part.
|
||||
finalize();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue