diff --git a/changelog.md b/changelog.md index a946335e9cd0..ef0c234462dd 100644 --- a/changelog.md +++ b/changelog.md @@ -15,6 +15,7 @@ * Highlight the titles of MP games with vacant slots. * Improved MP Lobby layout on low resolutions. * Improved reporting of network errors in the MP lobby (issue #3005). + * Ensure the chat widget remains the correct size even after a window resize. ### Miscellaneous and bug fixes * Removed misleading tooltip text stating registered nicknames are optional for the official MP server. diff --git a/src/gui/widgets/size_lock.cpp b/src/gui/widgets/size_lock.cpp index dadb4e5a96a7..2104fe44a12d 100644 --- a/src/gui/widgets/size_lock.cpp +++ b/src/gui/widgets/size_lock.cpp @@ -25,12 +25,13 @@ namespace gui2 { - REGISTER_WIDGET(size_lock) size_lock::size_lock(const implementation::builder_size_lock& builder) : container_base(builder, get_control_type()) , widget_(nullptr) + , width_(builder.width_) + , height_(builder.height_) { } @@ -38,27 +39,21 @@ void size_lock::place(const point& origin, const point& size) { point content_size = widget_->get_best_size(); - if (content_size.x > size.x) - { + if(content_size.x > size.x) { reduce_width(size.x); content_size = widget_->get_best_size(); } - if (content_size.y > size.y) - { - try - { + if(content_size.y > size.y) { + try { reduce_height(size.y); - } - catch(layout_exception_width_modified&) - { + } catch(layout_exception_width_modified&) { } content_size = widget_->get_best_size(); } - if (content_size.x > size.x) - { + if(content_size.x > size.x) { reduce_width(size.x); content_size = widget_->get_best_size(); } @@ -78,13 +73,23 @@ void size_lock::finalize(builder_widget_const_ptr widget_builder) set_rows_cols(1u, 1u); widget_ = widget_builder->build(); - set_child(widget_, 0u, 0u, - grid::VERTICAL_GROW_SEND_TO_CLIENT | grid::HORIZONTAL_GROW_SEND_TO_CLIENT, - 0u); + set_child(widget_, 0u, 0u, grid::VERTICAL_GROW_SEND_TO_CLIENT | grid::HORIZONTAL_GROW_SEND_TO_CLIENT, 0u); +} + +point size_lock::calculate_best_size() const +{ + const wfl::map_formula_callable& size = get_screen_size_variables(); + + unsigned width = width_(size); + unsigned height = height_(size); + + VALIDATE(width > 0 || height > 0, _("Invalid size.")); + + return point(width, height); } -size_lock_definition::size_lock_definition(const config& cfg) : - styled_widget_definition(cfg) +size_lock_definition::size_lock_definition(const config& cfg) + : styled_widget_definition(cfg) { DBG_GUI_P << "Parsing fixed size widget " << id << '\n'; @@ -108,8 +113,9 @@ size_lock_definition::size_lock_definition(const config& cfg) : * @end{tag}{name="size_lock_definition"} * @end{tag}{name="gui/"} */ -size_lock_definition::resolution::resolution(const config& cfg) : - resolution_definition(cfg), grid(nullptr) +size_lock_definition::resolution::resolution(const config& cfg) + : resolution_definition(cfg) + , grid(nullptr) { // Add a dummy state since every widget needs a state. static config dummy("draw"); @@ -147,9 +153,11 @@ size_lock_definition::resolution::resolution(const config& cfg) : namespace implementation { - -builder_size_lock::builder_size_lock(const config& cfg) : - builder_styled_widget(cfg), content_(nullptr), width_(cfg["width"]), height_(cfg["height"]) +builder_size_lock::builder_size_lock(const config& cfg) + : builder_styled_widget(cfg) + , content_(nullptr) + , width_(cfg["width"]) + , height_(cfg["height"]) { VALIDATE(cfg.has_child("widget"), _("No widget defined.")); content_ = create_widget_builder(cfg.child("widget")); @@ -159,28 +167,15 @@ widget* builder_size_lock::build() const { size_lock* widget = new size_lock(*this); - DBG_GUI_G << "Window builder: placed fixed size widget '" << id << - "' with definition '" << definition << "'.\n"; + DBG_GUI_G << "Window builder: placed fixed size widget '" << id << "' with definition '" << definition << "'.\n"; const auto conf = widget->cast_config_to(); assert(conf != nullptr); widget->init_grid(conf->grid); - - wfl::map_formula_callable size = get_screen_size_variables(); - - const unsigned width = width_(size); - const unsigned height = height_(size); - - VALIDATE(width > 0 || height > 0, _("Invalid size.")); - - widget->set_target_size(point(width, height)); - widget->finalize(content_); return widget; } - } - } diff --git a/src/gui/widgets/size_lock.hpp b/src/gui/widgets/size_lock.hpp index 26fa0c400807..9abf061dfd31 100644 --- a/src/gui/widgets/size_lock.hpp +++ b/src/gui/widgets/size_lock.hpp @@ -56,19 +56,12 @@ class size_lock : public container_base /** See @ref widget::layout_children. */ void layout_children() override; - void set_target_size(const point& size) - { - size_ = size; - } - protected: - point calculate_best_size() const override - { - return size_; - } + point calculate_best_size() const override; private: - point size_; + typed_formula width_; + typed_formula height_; /** * Points to the actual widget. @@ -118,10 +111,11 @@ struct builder_size_lock : public builder_styled_widget widget* build() const; -private: - builder_widget_const_ptr content_; typed_formula width_; typed_formula height_; + +private: + builder_widget_const_ptr content_; }; } }