Moved the easy close behaviour to the window.
At some places click dismiss is used which will be the new name of the feature since it's a more fitting name.
This commit is contained in:
parent
78d25d7d6c
commit
7fe3294f39
5 changed files with 99 additions and 39 deletions
|
@ -98,6 +98,37 @@
|
|||
|
||||
[/foreground]
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
||||
[grid]
|
||||
id = "_content_grid"
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
||||
[button]
|
||||
id = "click_dismiss"
|
||||
definition = "default"
|
||||
|
||||
label = "Close"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/resolution]
|
||||
|
||||
[/window_definition]
|
||||
|
|
|
@ -100,20 +100,6 @@ void tmessage::pre_show(CVideo& /*video*/, twindow& window)
|
|||
|
||||
// Override the user value, to make sure it's set properly.
|
||||
window.set_easy_close(auto_close_);
|
||||
if(auto_close_) {
|
||||
/*
|
||||
* Hide the buttton and do the layout, if window.does_easy_close() is
|
||||
* false the scroll_label has a scrollbar so we need to show the
|
||||
* button. When the button is hidden the text for the label is bigger
|
||||
* and thus not need a scrollbar. Also when the button is visible
|
||||
* easy_close will always return false.
|
||||
*/
|
||||
window.layout();
|
||||
|
||||
if(window.disable_easy_close()) {
|
||||
set_button_visible(ok, twidget::VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tmessage::post_show(twindow& /*window*/)
|
||||
|
|
|
@ -196,25 +196,7 @@ void twml_message_::pre_show(CVideo& /*video*/, twindow& window)
|
|||
} else {
|
||||
options->set_visible(twidget::INVISIBLE);
|
||||
}
|
||||
|
||||
if(!has_input_) {
|
||||
/*
|
||||
* Hide the buttton and do the layout, if window.does_easy_close() is
|
||||
* false the scroll_label has a scrollbar so we need to show the
|
||||
* button. When the button is hidden the text for the label is bigger
|
||||
* and thus not need a scrollbar. Also when the button is visible
|
||||
* easy_close will always return false.
|
||||
*/
|
||||
tbutton* button =
|
||||
dynamic_cast<tbutton*>(window.find_widget("ok", false));
|
||||
VALIDATE(button, missing_widget("ok"));
|
||||
button->set_visible(twidget::INVISIBLE);
|
||||
window.layout();
|
||||
|
||||
if(window.disable_easy_close()) {
|
||||
button->set_visible(twidget::VISIBLE);
|
||||
}
|
||||
}
|
||||
window.set_easy_close(!has_input_ && option_list_.empty());
|
||||
}
|
||||
|
||||
void twml_message_::post_show(twindow& window)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "log.hpp"
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
#include "gui/auxiliary/layout_exception.hpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
|
||||
#include "gui/widgets/debug.hpp"
|
||||
#endif
|
||||
|
@ -662,7 +663,7 @@ void twindow::remove_linked_widget(const std::string& id
|
|||
|
||||
void twindow::layout()
|
||||
{
|
||||
/**** Initialize and get initial size. *****/
|
||||
/***** Initialize. *****/
|
||||
|
||||
boost::intrusive_ptr<const twindow_definition::tresolution> conf =
|
||||
boost::dynamic_pointer_cast<const twindow_definition::tresolution>
|
||||
|
@ -671,9 +672,6 @@ void twindow::layout()
|
|||
|
||||
log_scope2(log_gui_layout, "Window: Recalculate size");
|
||||
|
||||
layout_init(true);
|
||||
generate_dot_file("layout_init", LAYOUT);
|
||||
|
||||
const game_logic::map_formula_callable variables =
|
||||
get_screen_size_variables();
|
||||
|
||||
|
@ -689,6 +687,27 @@ void twindow::layout()
|
|||
: settings::screen_height
|
||||
: h_(variables);
|
||||
|
||||
/***** Handle click dismiss status. *****/
|
||||
tbutton* click_dismiss_button = NULL;
|
||||
if((click_dismiss_button
|
||||
= NEW_find_widget<tbutton>(this, "click_dismiss", false, false))) {
|
||||
|
||||
click_dismiss_button->set_visible(twidget::INVISIBLE);
|
||||
}
|
||||
if(easy_close_) {
|
||||
tbutton* button = NEW_find_widget<tbutton>(this, "ok", false, false);
|
||||
if(button) {
|
||||
button->set_visible(twidget::INVISIBLE);
|
||||
click_dismiss_button = button;
|
||||
}
|
||||
VALIDATE(click_dismiss_button
|
||||
, _("Click dismiss needs a 'click_dismiss' or 'ok' button."));
|
||||
}
|
||||
|
||||
/***** Layout. *****/
|
||||
layout_init(true);
|
||||
generate_dot_file("layout_init", LAYOUT);
|
||||
|
||||
layout_linked_widgets();
|
||||
|
||||
try {
|
||||
|
@ -711,12 +730,45 @@ void twindow::layout()
|
|||
"which doesn't fit on the screen."), sstr.str());
|
||||
}
|
||||
|
||||
/****** Validate click dismiss status. *****/
|
||||
if(easy_close_ && disable_easy_close()) {
|
||||
assert(click_dismiss_button);
|
||||
click_dismiss_button->set_visible(twidget::VISIBLE);
|
||||
|
||||
|
||||
layout_init(true);
|
||||
generate_dot_file("layout_init", LAYOUT);
|
||||
|
||||
layout_linked_widgets();
|
||||
|
||||
try {
|
||||
twindow_implementation::layout(
|
||||
*this, maximum_width, maximum_height);
|
||||
|
||||
} catch(tlayout_exception_resize_failed&) {
|
||||
|
||||
/** @todo implement the scrollbars on the window. */
|
||||
|
||||
std::stringstream sstr;
|
||||
sstr << __FILE__ << ":" << __LINE__ << " in function '" << __func__
|
||||
<< "' found the following problem: Failed to size window;"
|
||||
<< " wanted size " << get_best_size()
|
||||
<< " available size "
|
||||
<< maximum_width << ',' << maximum_height
|
||||
<< " screen size "
|
||||
<< settings::screen_width << ',' << settings::screen_height
|
||||
<< '.';
|
||||
|
||||
throw twml_exception(_("Failed to show a dialog, "
|
||||
"which doesn't fit on the screen."), sstr.str());
|
||||
}
|
||||
}
|
||||
|
||||
/***** Get the best location for the window *****/
|
||||
tpoint size = get_best_size();
|
||||
|
||||
assert(size.x <= maximum_width && size.y <= maximum_height);
|
||||
|
||||
/***** Get the best location for the window *****/
|
||||
|
||||
tpoint origin(0, 0);
|
||||
|
||||
if(automatic_placement_) {
|
||||
|
|
|
@ -453,6 +453,15 @@ private:
|
|||
* be closed. The widgets in the window may override this behaviour by
|
||||
* registering themselves as blockers. This is tested by the function
|
||||
* disable_easy_close().
|
||||
*
|
||||
* The handling of easy close is done in the window, in order to do so a
|
||||
* window either needs a click_dismiss or an ok button. Both will be hidden
|
||||
* when not needed and when needed first the ok is tried and then the
|
||||
* click_dismiss button. this allows adding a click_dismiss button to the
|
||||
* window definition and use the ok from the window instance.
|
||||
*
|
||||
* @todo After testing the click dismiss feature it should be documented in
|
||||
* the wiki.
|
||||
*/
|
||||
bool easy_close_;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue