Skip to content

Commit

Permalink
GUI2: allow labels to shrink to avoid scrollbars
Browse files Browse the repository at this point in the history
This adds a new can_shrink key to widgets that allows the 'no label' codepath of styled_widget::request_reduce_width to be called.
In this case, it allows labels to shrink without forcing window scrollbars.
  • Loading branch information
Vultraz committed Feb 24, 2017
1 parent 2388438 commit 22eebc6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions data/gui/schema.cfg
Expand Up @@ -481,6 +481,11 @@
type="unsigned"
default=0
[/key]
[key]
name="can_shrink"
type="bool"
default=false
[/key]
[tag]
name="linked_group"
min="0"
Expand Down
2 changes: 2 additions & 0 deletions data/gui/widget/label_default.cfg
Expand Up @@ -20,6 +20,8 @@
max_width = 0
max_height = 0

can_shrink = true

text_font_family = {FONT_FAMILY}
text_font_size = {FONT_SIZE}
text_font_style = {FONT_STYLE}
Expand Down
1 change: 1 addition & 0 deletions src/gui/core/widget_definition.cpp
Expand Up @@ -98,6 +98,7 @@ resolution_definition::resolution_definition(const config& cfg)
, default_height(cfg["default_height"])
, max_width(cfg["max_width"])
, max_height(cfg["max_height"])
, can_shrink(cfg["can_shrink"].to_bool())
, linked_groups()
, text_extra_width(cfg["text_extra_width"])
, text_extra_height(cfg["text_extra_height"])
Expand Down
2 changes: 2 additions & 0 deletions src/gui/core/widget_definition.hpp
Expand Up @@ -57,6 +57,8 @@ struct resolution_definition
unsigned max_width;
unsigned max_height;

bool can_shrink;

std::vector<linked_group_definition> linked_groups;

unsigned text_extra_width;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/styled_widget.cpp
Expand Up @@ -219,7 +219,7 @@ void styled_widget::request_reduce_width(const unsigned maximum_width)
<< "' maximum_width " << maximum_width << " result " << size
<< ".\n";

} else if(label_.empty()) {
} else if(label_.empty() || config_->can_shrink) {
point size = get_best_size();
point min_size = get_config_minimum_size();
size.x = std::min(size.x, std::max<int>(maximum_width, min_size.x));
Expand Down

0 comments on commit 22eebc6

Please sign in to comment.