Skip to content

Commit

Permalink
gui2/ttransient_message: Hide title and image widgets when unused
Browse files Browse the repository at this point in the history
When the title or image widget labels are left empty, the widgets
continue to take up space in the grid, which is particularly conspicuous
with our current border,border_size=all,5 convention.

Commit 037ec6a exposes the underlying
problem quite clearly in most dialogs because the image widget's cell
takes up extra space to the left of the dialog while empty -- see the
Objectives popup for an example.

Hiding the relevant widgets when missing label values is trivial to do,
even if it requires additional boilerplate in the
gui2::ttransient_message case (no existing pre_show() method override),
so it should be a good solution as any until cell borders gain the
ability to become null when the contained widget is otherwise unused.

NOTE: I had to move the inclusion of gettext.hpp around a bit in order
to avoid name collisions with Boost headers introduced along with the
two new GUI2 inclusions in transient_message.cpp. The _ gettext
shorthand macro is truly a PITA to have near some of the most
complicated Boost libraries.
  • Loading branch information
irydacea committed Mar 13, 2014
1 parent d36fbdc commit fa9f75b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/gui/dialogs/transient_message.cpp
Expand Up @@ -16,10 +16,13 @@

#include "gui/dialogs/transient_message.hpp"

#include "gettext.hpp"
#include "gui/auxiliary/find_widget.tpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "log.hpp"

#include "gettext.hpp"

namespace gui2
{

Expand All @@ -30,12 +33,27 @@ ttransient_message::ttransient_message(const std::string& title,
const std::string& message,
const bool message_use_markup,
const std::string& image)
: hide_title_(title.empty())
, hide_image_(image.empty())
{
register_label("title", true, title, title_use_markup);
register_label("message", true, message, message_use_markup);
register_image("image", true, image);
}

void ttransient_message::pre_show(CVideo& /*video*/, twindow& window)
{
if(hide_title_) {
twidget& title = find_widget<twidget>(&window, "title", false);
title.set_visible(twidget::tvisible::invisible);
}

if(hide_image_) {
twidget& image = find_widget<twidget>(&window, "image", false);
image.set_visible(twidget::tvisible::invisible);
}
}

void show_transient_message(CVideo& video,
const std::string& title,
const std::string& message,
Expand Down
6 changes: 6 additions & 0 deletions src/gui/dialogs/transient_message.hpp
Expand Up @@ -31,8 +31,14 @@ class ttransient_message : public tdialog
const std::string& image);

private:
bool hide_title_;
bool hide_image_;

/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;

/** Inherited from tdialog. */
virtual void pre_show(CVideo& video, twindow& window);
};

/**
Expand Down

0 comments on commit fa9f75b

Please sign in to comment.