Make wrapping for dialogs work nicely.
As long as the text is shown without a scrollbar the window closes on a mouse click. When the scrollbar is needed a button will also be shown and a mouse click (expect on the button) won't close the window anymore.
This commit is contained in:
parent
f62d37120e
commit
d0883b1cd1
4 changed files with 49 additions and 8 deletions
|
@ -575,9 +575,7 @@
|
|||
[/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]
|
||||
|
@ -586,6 +584,9 @@
|
|||
horizontal_alignment = "center"
|
||||
|
||||
[button]
|
||||
# This button will be shown or hidden depending on the
|
||||
# whether or not a scrollbar is needed to show the
|
||||
# text.
|
||||
id = "ok"
|
||||
definition = "default"
|
||||
|
||||
|
@ -595,7 +596,7 @@
|
|||
[/column]
|
||||
|
||||
[/row]
|
||||
#endif
|
||||
|
||||
[/grid]
|
||||
|
||||
[/resolution]
|
||||
|
|
|
@ -44,13 +44,38 @@ void tmessage::pre_show(CVideo& /*video*/, twindow& window)
|
|||
VALIDATE(label, missing_widget("label"));
|
||||
|
||||
label->set_label(message_);
|
||||
|
||||
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.
|
||||
*/
|
||||
/** @todo The space for invisible items is always reserved. Look about
|
||||
* how to change that. (Maybe get_best_size() in twidget can do that by
|
||||
* returning 0,0 when called upon invisible items. Or the tgrid::tchild
|
||||
* should do that since an item with 0,0 might get a border.)
|
||||
*/
|
||||
tcontrol* button =
|
||||
dynamic_cast<tcontrol*>(window.find_widget("ok", false));
|
||||
button->set_visible(false);
|
||||
|
||||
window.layout();
|
||||
|
||||
if(! window.does_easy_close()) {
|
||||
button->set_visible();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @todo the caption is ignored. */
|
||||
void show_message(CVideo& video, const std::string& title,
|
||||
const std::string& message, const std::string& /*button_caption*/)
|
||||
const std::string& message, const std::string& /*button_caption*/,
|
||||
const bool auto_close)
|
||||
{
|
||||
tmessage(title, message).show(video);
|
||||
tmessage(title, message, auto_close).show(video);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -28,10 +28,12 @@ namespace gui2 {
|
|||
class tmessage : public tdialog
|
||||
{
|
||||
public:
|
||||
tmessage(const std::string& title, const std::string& message)
|
||||
tmessage(const std::string& title, const std::string& message,
|
||||
const bool auto_close)
|
||||
: title_(title)
|
||||
, image_()
|
||||
, message_(message)
|
||||
, auto_close_(auto_close)
|
||||
{}
|
||||
|
||||
/***** ***** ***** setters / getters for members ***** ****** *****/
|
||||
|
@ -56,6 +58,12 @@ private:
|
|||
/** The message to show to the user. */
|
||||
std::string message_;
|
||||
|
||||
/**
|
||||
* Does the window need to use easy_close when the dialog doesn't need a
|
||||
* scrollbar.
|
||||
*/
|
||||
bool auto_close_;
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
twindow build_window(CVideo& video);
|
||||
|
||||
|
@ -76,9 +84,13 @@ private:
|
|||
* @param title The title of the dialog.
|
||||
* @param message The message to show in the dialog.
|
||||
* @param button_caption The caption of the close button.
|
||||
* @param auto_close When true the window will hide the ok button
|
||||
* when the message doesn't need a scrollbar to
|
||||
* show itself.
|
||||
*/
|
||||
void show_message(CVideo& video, const std::string& title,
|
||||
const std::string& message, const std::string& button_caption = "");
|
||||
const std::string& message, const std::string& button_caption = "",
|
||||
const bool auto_close = true);
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -47,6 +47,9 @@ class tdebug_layout_graph;
|
|||
class twindow : public tpanel, public tevent_handler
|
||||
{
|
||||
friend class tdebug_layout_graph;
|
||||
|
||||
// Wants to use layout().
|
||||
friend class tmessage;
|
||||
public:
|
||||
twindow(CVideo& video,
|
||||
tformula<unsigned>x,
|
||||
|
|
Loading…
Add table
Reference in a new issue