~widelands-dev/widelands/map-filter-dropdowns

« back to all changes in this revision

Viewing changes to src/ui_basic/button.cc

  • Committer: GunChleoc
  • Date: 2019-06-03 15:48:44 UTC
  • Revision ID: fios@foramnagaidhlig.net-20190603154844-lyimiacpq8ix6n8y
Redesign filters in Mapselect
- Add autofit text width capabilities to buttons and dropdowns
- Replace broken "Show all maps" checkbox with button
- Replace team-related checkboxes with dropdown

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
        assert(!get_can_focus());
64
64
}
65
65
 
66
 
Button::Button  //  for textual buttons. If h = 0, h will resize according to the font's height.
 
66
/// For textual buttons. If h = 0, h will resize according to the font's height. If both h = 0 and w = 0, will resize for text width as well.
 
67
Button::Button
67
68
   (Panel* const parent,
68
69
    const std::string& name,
69
70
    int32_t const x,
86
87
            tooltip_text,
87
88
            init_state,
88
89
            UI::Button::ImageMode::kShrink) {
89
 
        // Automatically resize for font height and give it a margin.
90
 
        if (h < 1) {
 
90
        if (h == 0) {
 
91
                // Automatically resize for font height and give it a margin.
 
92
                int new_width = get_w();
91
93
                const int new_height =
92
 
                   text_height(g_gr->styles().button_style(init_style).enabled().font()) + 4;
93
 
                set_desired_size(w, new_height);
94
 
                set_size(w, new_height);
 
94
                   std::max(text_height(g_gr->styles().button_style(init_style).enabled().font()),
 
95
                                        text_height(g_gr->styles().button_style(init_style).enabled().font()))
 
96
                                + 4 * kButtonImageMargin;
 
97
                if (w == 0) {
 
98
                        // Automatically resize for text width too.
 
99
                        new_width = std::max(text_width(richtext_escape(title_), style_->enabled().font()),
 
100
                                                                 text_width(richtext_escape(title_), style_->disabled().font()))
 
101
                                                + 8 * kButtonImageMargin;
 
102
                }
 
103
                set_desired_size(new_width, new_height);
 
104
                set_size(new_width, new_height);
95
105
        }
96
106
}
97
107