Skip to content

Commit

Permalink
GUI2/Status Label Helper: take source containing widget as a pointer
Browse files Browse the repository at this point in the history
They were only used in the context of pointers anyway,
  • Loading branch information
Vultraz committed Aug 25, 2017
1 parent 2325092 commit c27aa6e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions src/gui/dialogs/editor/generator_settings.cpp
Expand Up @@ -59,14 +59,14 @@ void generator_settings::pre_show(window& window)
connect_signal_notify_modified(*players_->get_widget(), std::bind(
&generator_settings::adjust_minimum_size_by_players, this, std::ref(window)));

gui2::bind_status_label<slider>(window, "players");
gui2::bind_status_label<slider>(&window, "players");

update_width_label_ = gui2::bind_status_label<slider>(window, "width");
update_height_label_ = gui2::bind_status_label<slider>(window, "height");
update_width_label_ = gui2::bind_status_label<slider>(&window, "width");
update_height_label_ = gui2::bind_status_label<slider>(&window, "height");

gui2::bind_status_label<slider>(window, "villages", [](slider& s)->std::string { return formatter() << s.get_value() << _("/1000 tiles"); });
gui2::bind_status_label<slider>(window, "castle_size");
gui2::bind_status_label<slider>(window, "landform", [](slider& s)->std::string {
gui2::bind_status_label<slider>(&window, "villages", [](slider& s)->std::string { return formatter() << s.get_value() << _("/1000 tiles"); });
gui2::bind_status_label<slider>(&window, "castle_size");
gui2::bind_status_label<slider>(&window, "landform", [](slider& s)->std::string {
return s.get_value() == 0 ? _("Inland") : (s.get_value() < max_coastal ? _("Coastal") : _("Island")); });
}

Expand Down
18 changes: 9 additions & 9 deletions src/gui/dialogs/multiplayer/mp_create_game.cpp
Expand Up @@ -293,15 +293,15 @@ void mp_create_game::pre_show(window& win)
//
// Set up the setting status labels
//
bind_status_label<slider>(win, turns_->id());
bind_status_label<slider>(win, gold_->id());
bind_status_label<slider>(win, support_->id());
bind_status_label<slider>(win, experience_->id());

bind_status_label<slider>(win, init_turn_limit_->id());
bind_status_label<slider>(win, turn_bonus_->id());
bind_status_label<slider>(win, reservoir_->id());
bind_status_label<slider>(win, action_bonus_->id());
bind_status_label<slider>(&win, turns_->id());
bind_status_label<slider>(&win, gold_->id());
bind_status_label<slider>(&win, support_->id());
bind_status_label<slider>(&win, experience_->id());

bind_status_label<slider>(&win, init_turn_limit_->id());
bind_status_label<slider>(&win, turn_bonus_->id());
bind_status_label<slider>(&win, reservoir_->id());
bind_status_label<slider>(&win, action_bonus_->id());

//
// Set up tab control
Expand Down
12 changes: 6 additions & 6 deletions src/gui/dialogs/preferences_dialog.cpp
Expand Up @@ -596,7 +596,7 @@ void preferences_dialog::post_build(window& window)
[&, pref_name]() { set(pref_name, toggle_box.get_value_bool()); }
));

gui2::bind_status_label<toggle_button>(*main_grid, "value_toggle", [](toggle_button& t)->std::string {
gui2::bind_status_label<toggle_button>(main_grid, "value_toggle", [](toggle_button& t)->std::string {
return t.get_value_bool() ? _("yes") : _("no");
}, "value");

Expand All @@ -622,7 +622,7 @@ void preferences_dialog::post_build(window& window)
[&, pref_name]() { set(pref_name, slide.get_value()); }
));

gui2::bind_status_label<slider>(*main_grid, "setter", [](slider& s)->std::string {
gui2::bind_status_label<slider>(main_grid, "setter", [](slider& s)->std::string {
return std::to_string(s.get_value());
}, "value");

Expand Down Expand Up @@ -659,7 +659,7 @@ void preferences_dialog::post_build(window& window)
set(pref_name, option_ids[dynamic_cast<menu_button&>(w).get_value()]);
});

gui2::bind_status_label<menu_button>(*main_grid, "setter", [](menu_button& m)->std::string {
gui2::bind_status_label<menu_button>(main_grid, "setter", [](menu_button& m)->std::string {
return m.get_value_string();
}, "value");

Expand Down Expand Up @@ -969,15 +969,15 @@ void preferences_dialog::pre_show(window& window)
// is not the case for those in Advanced
//

gui2::bind_status_label<slider>(window, "max_saves_slider", [](slider& s)->std::string {
gui2::bind_status_label<slider>(&window, "max_saves_slider", [](slider& s)->std::string {
return s.get_value() == INFINITE_AUTO_SAVES ? _("") : s.get_value_label().str();
});

gui2::bind_status_label<slider>(window, "turbo_slider", [](slider& s)->std::string {
gui2::bind_status_label<slider>(&window, "turbo_slider", [](slider& s)->std::string {
return s.get_value_label();
});

gui2::bind_status_label<slider>(window, "scaling_slider", [](slider& s)->std::string {
gui2::bind_status_label<slider>(&window, "scaling_slider", [](slider& s)->std::string {
return s.get_value_label() + "%";
});

Expand Down
6 changes: 3 additions & 3 deletions src/gui/widgets/status_label_helper.hpp
Expand Up @@ -62,7 +62,7 @@ default_status_value_getter(T& w)
*/
template<typename W>
std::function<void()> bind_status_label(
widget& find_in,
widget* find_in,
const std::string& source_id,
const std::function<std::string(W&)> value_getter = default_status_value_getter<W>,
const std::string& label_id = "")
Expand All @@ -71,10 +71,10 @@ std::function<void()> bind_status_label(
const std::string label_id_ = label_id.empty() ? source_id + "_label" : label_id;

// Find the source value widget.
W& source = find_widget<W>(&find_in, source_id, false);
W& source = find_widget<W>(find_in, source_id, false);

// Find the target status label.
styled_widget& label = find_widget<styled_widget>(&find_in, label_id_, false);
styled_widget& label = find_widget<styled_widget>(find_in, label_id_, false);

const auto update_label = [&, value_getter]() {
const std::string value = value_getter(source);
Expand Down

0 comments on commit c27aa6e

Please sign in to comment.