Stop multiline_text from infinite growing and show scrollbar instead
Fixes the following bugs : Stop scroll_text from growing infinitely and instead show the scrollbars when the text dimensions exceed the default size of the underlying multiline_text in some dialogs (such as edit_pbl, the pbl publishing editor). Allow horizontal_grow/vertical_grow to work correctly. Currently, the widget stops vertically growing due to absence of max_height=0, again in some specific dialogs.
This commit is contained in:
parent
2b5a9476d3
commit
8d3a52eb3f
5 changed files with 56 additions and 12 deletions
|
@ -151,7 +151,7 @@
|
|||
default_height = {HEIGHT}
|
||||
|
||||
max_width = 0
|
||||
max_height = {HEIGHT}
|
||||
max_height = 0
|
||||
|
||||
text_font_size = {FONT_SIZE}
|
||||
text_font_family = {FONT_FAMILY}
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include "wml_exception.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
#define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
|
||||
#define LOG_HEADER LOG_SCOPE_HEADER + ':'
|
||||
|
@ -47,6 +46,8 @@ scroll_text::scroll_text(const implementation::builder_scroll_text& builder)
|
|||
, state_(ENABLED)
|
||||
, wrap_on_(false)
|
||||
, text_alignment_(builder.text_alignment)
|
||||
, editable_(true)
|
||||
, max_size_(point(0,0))
|
||||
{
|
||||
connect_signal<event::LEFT_BUTTON_DOWN>(
|
||||
std::bind(&scroll_text::signal_handler_left_button_down, this, std::placeholders::_2),
|
||||
|
@ -160,9 +161,44 @@ void scroll_text::place(const point& origin, const point& size) {
|
|||
scroll_horizontal_scrollbar(scrollbar_base::BEGIN);
|
||||
scroll_vertical_scrollbar(scrollbar_base::BEGIN);
|
||||
}
|
||||
|
||||
set_max_size(widget->get_config_default_size());
|
||||
}
|
||||
}
|
||||
|
||||
point scroll_text::calculate_best_size() const
|
||||
{
|
||||
point calc_size = scrollbar_container::calculate_best_size();
|
||||
|
||||
if ((calc_size.x > max_size_.x) && (max_size_.x != 0)) {
|
||||
calc_size.x = max_size_.x;
|
||||
}
|
||||
|
||||
if ((calc_size.y > max_size_.y) && (max_size_.y != 0)) {
|
||||
calc_size.y = max_size_.y;
|
||||
}
|
||||
|
||||
return calc_size;
|
||||
}
|
||||
|
||||
void scroll_text::set_max_size(point max_size)
|
||||
{
|
||||
// ------ get vertical scrollbar size ------
|
||||
const point vertical_scrollbar = get_vertical_scrollbar_grid()->get_visible() == widget::visibility::invisible
|
||||
? point()
|
||||
: get_vertical_scrollbar_grid()->get_best_size();
|
||||
|
||||
// ------ get horizontal scrollbar size ------
|
||||
const point horizontal_scrollbar = get_horizontal_scrollbar_grid()->get_visible() == widget::visibility::invisible
|
||||
? point()
|
||||
: get_horizontal_scrollbar_grid()->get_best_size();
|
||||
|
||||
// padding = 3
|
||||
max_size_ = point(max_size.x + vertical_scrollbar.x + 3, max_size.y + horizontal_scrollbar.y + 3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void scroll_text::set_can_wrap(bool can_wrap)
|
||||
{
|
||||
wrap_on_ = can_wrap;
|
||||
|
@ -185,7 +221,7 @@ void scroll_text::signal_handler_left_button_down(const event::ui_event event)
|
|||
scroll_text_definition::scroll_text_definition(const config& cfg)
|
||||
: styled_widget_definition(cfg)
|
||||
{
|
||||
DBG_GUI_P << "Parsing scroll label " << id;
|
||||
DBG_GUI_P << "Parsing scroll text " << id;
|
||||
|
||||
load_resolutions<resolution>(cfg);
|
||||
}
|
||||
|
@ -194,10 +230,10 @@ scroll_text_definition::resolution::resolution(const config& cfg)
|
|||
: resolution_definition(cfg), grid(nullptr)
|
||||
{
|
||||
// Note the order should be the same as the enum state_t is scroll_text.hpp.
|
||||
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for scroll label control")));
|
||||
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for scroll label control")));
|
||||
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for scroll text control")));
|
||||
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for scroll text control")));
|
||||
|
||||
auto child = VALIDATE_WML_CHILD(cfg, "grid", _("No grid defined for scroll label control"));
|
||||
auto child = VALIDATE_WML_CHILD(cfg, "grid", _("No grid defined for scroll text control"));
|
||||
grid = std::make_shared<builder_grid>(child);
|
||||
}
|
||||
|
||||
|
@ -213,7 +249,7 @@ builder_scroll_text::builder_scroll_text(const config& cfg)
|
|||
, text_alignment(decode_text_alignment(cfg["text_alignment"]))
|
||||
, editable(cfg["editable"].to_bool(true))
|
||||
{
|
||||
/** Horizontal scrollbar default to auto. AUTO_VISIBLE_FIRST_RUN doesn't work. */
|
||||
// Scrollbar default to auto. AUTO_VISIBLE_FIRST_RUN doesn't work.
|
||||
if (horizontal_scrollbar_mode == scrollbar_container::AUTO_VISIBLE_FIRST_RUN) {
|
||||
horizontal_scrollbar_mode = scrollbar_container::AUTO_VISIBLE;
|
||||
}
|
||||
|
@ -238,7 +274,7 @@ std::unique_ptr<widget> builder_scroll_text::build() const
|
|||
widget->init_grid(*conf->grid);
|
||||
widget->finalize_setup();
|
||||
|
||||
DBG_GUI_G << "Window builder: placed scroll label '" << id
|
||||
DBG_GUI_G << "Window builder: placed scroll text '" << id
|
||||
<< "' with definition '" << definition << "'.";
|
||||
|
||||
return widget;
|
||||
|
|
|
@ -144,6 +144,8 @@ private:
|
|||
|
||||
bool editable_;
|
||||
|
||||
point max_size_;
|
||||
|
||||
void finalize_subclass() override;
|
||||
|
||||
/** Used for moving scrollbars.
|
||||
|
@ -163,6 +165,12 @@ private:
|
|||
|
||||
void place(const point& origin, const point& size);
|
||||
|
||||
/** See @ref widget::calculate_best_size. */
|
||||
point calculate_best_size() const override;
|
||||
|
||||
/** Sets the size of the text beyond which scrollbars should be visible. */
|
||||
void set_max_size(point max_size);
|
||||
|
||||
public:
|
||||
/** Static type getter that does not rely on the widget being constructed. */
|
||||
static const std::string& type();
|
||||
|
|
|
@ -101,7 +101,7 @@ public:
|
|||
*/
|
||||
virtual bool can_wrap() const override;
|
||||
|
||||
private:
|
||||
protected:
|
||||
/** See @ref widget::calculate_best_size. */
|
||||
virtual point calculate_best_size() const override;
|
||||
|
||||
|
|
|
@ -140,10 +140,10 @@ spinner_definition::resolution::resolution(const config& cfg)
|
|||
: resolution_definition(cfg), grid(nullptr)
|
||||
{
|
||||
// Note the order should be the same as the enum state_t is spinner.hpp.
|
||||
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for scroll label control")));
|
||||
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for scroll label control")));
|
||||
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for spinner control")));
|
||||
state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for spinner control")));
|
||||
|
||||
auto child = VALIDATE_WML_CHILD(cfg, "grid", _("No grid defined for scroll label control"));
|
||||
auto child = VALIDATE_WML_CHILD(cfg, "grid", _("No grid defined for spinner control"));
|
||||
grid = std::make_shared<builder_grid>(child);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue