Demote can_shrink key from global widget scope to label-only

It was causing problems being enabled for all labels (ie, some labels being shrunken when it wasn't desirable),
and it didn't make much sense for all widgets anyway.
This commit is contained in:
Charles Dang 2017-03-17 06:21:13 +11:00
parent e0b85e5dda
commit adb5ef90ad
8 changed files with 33 additions and 11 deletions

View file

@ -481,11 +481,6 @@
type="unsigned"
default=0
[/key]
[key]
name="can_shrink"
type="bool"
default=false
[/key]
[tag]
name="linked_group"
min="0"
@ -612,6 +607,11 @@
type="bool"
default=false
[/key]
[key]
name="can_shrink"
type="bool"
default=false
[/key]
[/tag]
[/tag]
[tag]

View file

@ -20,8 +20,6 @@
max_width = 0
max_height = 0
can_shrink = true
text_font_family = {FONT_FAMILY}
text_font_size = {FONT_SIZE}
text_font_style = {FONT_STYLE}

View file

@ -98,7 +98,6 @@ 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"])

View file

@ -57,8 +57,6 @@ struct resolution_definition
unsigned max_width;
unsigned max_height;
bool can_shrink;
std::vector<linked_group_definition> linked_groups;
unsigned text_extra_width;

View file

@ -47,6 +47,7 @@ label::label()
, characters_per_line_(0)
, link_aware_(false)
, link_color_(color_t::from_hex_string("ffff00"))
, can_shrink_(false)
{
connect_signal<event::LEFT_BUTTON_CLICK>(std::bind(&label::signal_handler_left_button_click, this, _2, _3));
connect_signal<event::RIGHT_BUTTON_CLICK>(std::bind(&label::signal_handler_right_button_click, this, _2, _3));
@ -318,6 +319,7 @@ builder_label::builder_label(const config& cfg)
, wrap(cfg["wrap"].to_bool())
, characters_per_line(cfg["characters_per_line"])
, text_alignment(decode_text_alignment(cfg["text_alignment"]))
, can_shrink(cfg["can_shrink"].to_bool(false))
{
}
@ -330,6 +332,7 @@ widget* builder_label::build() const
lbl->set_can_wrap(wrap);
lbl->set_characters_per_line(characters_per_line);
lbl->set_text_alignment(text_alignment);
lbl->set_can_shrink(can_shrink);
DBG_GUI_G << "Window builder: placed label '" << id << "' with definition '"
<< definition << "'.\n";

View file

@ -69,6 +69,12 @@ public:
void set_link_color(const color_t& color);
virtual bool can_mouse_focus() const override { return !tooltip().empty(); }
void set_can_shrink(bool can_shrink)
{
can_shrink_ = can_shrink;
}
private:
/**
* Possible states of the widget.
@ -112,6 +118,14 @@ private:
*/
color_t link_color_;
bool can_shrink_;
/** Inherited from styled_widget. */
virtual bool text_can_shrink() override
{
return can_shrink_;
}
/** See @ref styled_widget::get_control_type. */
virtual const std::string& get_control_type() const override;
@ -165,6 +179,8 @@ struct builder_label : public builder_styled_widget
unsigned characters_per_line;
PangoAlignment text_alignment;
bool can_shrink;
};
} // namespace implementation

View file

@ -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() || config_->can_shrink) {
} else if(label_.empty() || text_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));

View file

@ -474,6 +474,14 @@ private:
point get_best_text_size(point minimum_size,
point maximum_size = {0, 0}) const;
/**
* Gets whether a widget can shrink past its optimal size even if it's text-based (such as labels);
*/
virtual bool text_can_shrink()
{
return false;
}
/**
* Contains a helper cache for the rendering.
*