mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-18 15:46:49 +00:00
Remove layout_initialise() calls from content_resize_request()
The calls were there to work around automatic rewrapping of text caused by a hack in `scroll_label::set_label()`. @Vultraz removed that hack in commit ae76bb0efbc53f102cc772ace3941c5867e2c91c. After that, there wasn't any reason to call `layout_initialise()` any more. Well, other than that removal of scrollbars set as `AUTO_VISIBLE_FIRST_RUN` relied on full layout initialization. I implemented a secondary, faster mechanism for that. This commit removes unnecessary code, and speeds up switching between add-ons in the add-on manager further still.
This commit is contained in:
parent
fb700d775f
commit
9b1ca36b5c
@ -60,7 +60,10 @@ void scroll_label::set_label(const t_string& lbl)
|
|||||||
label* widget = find_widget<label>(content_grid(), "_label", false, true);
|
label* widget = find_widget<label>(content_grid(), "_label", false, true);
|
||||||
widget->set_label(lbl);
|
widget->set_label(lbl);
|
||||||
|
|
||||||
content_resize_request();
|
bool resize_needed = !content_resize_request();
|
||||||
|
if(resize_needed) {
|
||||||
|
place(get_origin(), get_size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +352,8 @@ set_scrollbar_mode(grid* scrollbar_grid,
|
|||||||
scrollbar_base* scrollbar,
|
scrollbar_base* scrollbar,
|
||||||
scrollbar_container::scrollbar_mode& scrollbar_mode,
|
scrollbar_container::scrollbar_mode& scrollbar_mode,
|
||||||
const unsigned items,
|
const unsigned items,
|
||||||
const unsigned visible_items)
|
const unsigned visible_items,
|
||||||
|
grid* content_grid)
|
||||||
{
|
{
|
||||||
assert(scrollbar_grid && scrollbar);
|
assert(scrollbar_grid && scrollbar);
|
||||||
|
|
||||||
@ -372,6 +373,13 @@ set_scrollbar_mode(grid* scrollbar_grid,
|
|||||||
scrollbar_grid->set_visible(scrollbar_needed
|
scrollbar_grid->set_visible(scrollbar_needed
|
||||||
? widget::visibility::visible
|
? widget::visibility::visible
|
||||||
: widget::visibility::hidden);
|
: widget::visibility::hidden);
|
||||||
|
} else if(scrollbar_mode == scrollbar_container::AUTO_VISIBLE_FIRST_RUN) {
|
||||||
|
if(items <= visible_items && content_grid != nullptr &&
|
||||||
|
scrollbar_grid->get_visible() == widget::visibility::visible) {
|
||||||
|
scrollbar_grid->set_visible(widget::visibility::hidden);
|
||||||
|
// Give newly freed space to the items.
|
||||||
|
content_grid->layout_initialise(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static bool is_inserted_before(unsigned insertion_pos, unsigned old_item_count, unsigned old_position, unsigned visible_items)
|
static bool is_inserted_before(unsigned insertion_pos, unsigned old_item_count, unsigned old_position, unsigned visible_items)
|
||||||
@ -397,7 +405,7 @@ adjust_scrollbar_mode(grid* scrollbar_grid,
|
|||||||
{
|
{
|
||||||
assert(scrollbar_grid && scrollbar);
|
assert(scrollbar_grid && scrollbar);
|
||||||
if(items_before != scrollbar->get_item_count()) {
|
if(items_before != scrollbar->get_item_count()) {
|
||||||
return set_scrollbar_mode(scrollbar_grid, scrollbar, scrollbar_mode, items_after, visible_items);
|
return set_scrollbar_mode(scrollbar_grid, scrollbar, scrollbar_mode, items_after, visible_items, nullptr);
|
||||||
}
|
}
|
||||||
//TODO: does this also work well in case the items were removed?
|
//TODO: does this also work well in case the items were removed?
|
||||||
const unsigned previous_item_position = scrollbar->get_item_position();
|
const unsigned previous_item_position = scrollbar->get_item_position();
|
||||||
@ -447,14 +455,16 @@ void scrollbar_container::place(const point& origin, const point& size)
|
|||||||
vertical_scrollbar_,
|
vertical_scrollbar_,
|
||||||
vertical_scrollbar_mode_,
|
vertical_scrollbar_mode_,
|
||||||
content_grid_->get_height(),
|
content_grid_->get_height(),
|
||||||
content_->get_height());
|
content_->get_height(),
|
||||||
|
content_grid_);
|
||||||
|
|
||||||
// Set horizontal scrollbar
|
// Set horizontal scrollbar
|
||||||
set_scrollbar_mode(horizontal_scrollbar_grid_,
|
set_scrollbar_mode(horizontal_scrollbar_grid_,
|
||||||
horizontal_scrollbar_,
|
horizontal_scrollbar_,
|
||||||
horizontal_scrollbar_mode_,
|
horizontal_scrollbar_mode_,
|
||||||
content_grid_->get_width(),
|
content_grid_->get_width(),
|
||||||
content_->get_width());
|
content_->get_width(),
|
||||||
|
content_grid_);
|
||||||
|
|
||||||
// Update the buttons.
|
// Update the buttons.
|
||||||
set_scrollbar_button_status();
|
set_scrollbar_button_status();
|
||||||
@ -583,7 +593,6 @@ bool scrollbar_container::content_resize_request(const bool force_sizing)
|
|||||||
|
|
||||||
DBG_GUI_L << LOG_HEADER
|
DBG_GUI_L << LOG_HEADER
|
||||||
<< " can't use horizontal scrollbar, ask grid.\n";
|
<< " can't use horizontal scrollbar, ask grid.\n";
|
||||||
layout_initialise(true);
|
|
||||||
grid* grid = get_parent_grid();
|
grid* grid = get_parent_grid();
|
||||||
assert(grid);
|
assert(grid);
|
||||||
grid->relayout();
|
grid->relayout();
|
||||||
@ -600,7 +609,6 @@ bool scrollbar_container::content_resize_request(const bool force_sizing)
|
|||||||
|
|
||||||
DBG_GUI_L << LOG_HEADER
|
DBG_GUI_L << LOG_HEADER
|
||||||
<< " can't use vertical scrollbar, ask grid.\n";
|
<< " can't use vertical scrollbar, ask grid.\n";
|
||||||
layout_initialise(true);
|
|
||||||
grid* grid = get_parent_grid();
|
grid* grid = get_parent_grid();
|
||||||
assert(grid);
|
assert(grid);
|
||||||
grid->relayout();
|
grid->relayout();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user