widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #05821
[Merge] lp:~widelands-dev/widelands/bug-1532279 into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1532279 into lp:widelands.
Commit message:
ScrollMode in MultilineTextarea is now an enum class, and it is now set through the constructor only. Added new enum member "kNoScrolling", which will expand the MultilineTextarea rather than creating a scrollbar. Using this mode in Spinboxes now to prevent the creation of a Scrollbar there.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1532279 in widelands: "Spin box not displayed correct in options menu"
https://bugs.launchpad.net/widelands/+bug/1532279
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1532279/+merge/284728
See commit message. This should fix the scrollbar button problem in the Spinboxes for good. A good test case is the Options menu in Arabic.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1532279 into lp:widelands.
=== modified file 'src/ui_basic/multilinetextarea.cc'
--- src/ui_basic/multilinetextarea.cc 2016-01-31 14:49:09 +0000
+++ src/ui_basic/multilinetextarea.cc 2016-02-02 12:58:58 +0000
@@ -36,14 +36,14 @@
const int32_t x, const int32_t y, const uint32_t w, const uint32_t h,
const std::string& text,
const Align align,
- const bool always_show_scrollbar)
+ MultilineTextarea::ScrollMode scroll_mode)
:
Panel (parent, x, y, w, h),
m_text (text),
m_style(UI::TextStyle::ui_small()),
isrichtext(false),
m_scrollbar (this, get_w() - scrollbar_w(), 0, scrollbar_w(), h, false),
- m_scrollmode(ScrollNormal)
+ m_scrollmode(scroll_mode)
{
assert(scrollbar_w() <= w);
set_thinks(false);
@@ -56,7 +56,8 @@
m_scrollbar.set_singlestepsize(UI::g_fh1->render(as_uifont(".", UI_FONT_SIZE_SMALL))->height());
m_scrollbar.set_pagesize(h - 2 * UI::g_fh1->render(as_uifont(".", UI_FONT_SIZE_BIG))->height());
m_scrollbar.set_steps(1);
- m_scrollbar.set_force_draw(always_show_scrollbar);
+ m_scrollbar.set_force_draw(m_scrollmode == ScrollMode::kScrollNormalForced ||
+ m_scrollmode == ScrollMode::kScrollLogForced);
recompute();
}
@@ -81,7 +82,7 @@
uint32_t height;
// We wrap the text twice. We need to do this to account for the presence/absence of the scollbar.
- bool scroolbar_was_enabled = m_scrollbar.is_enabled();
+ bool scrollbar_was_enabled = m_scrollbar.is_enabled();
for (int i = 0; i < 2; ++i) {
if (m_text.compare(0, 3, "<rt")) {
isrichtext = false;
@@ -99,15 +100,21 @@
bool setbottom = false;
- if (m_scrollmode == ScrollLog)
+ if (m_scrollmode == ScrollMode::kScrollLog || m_scrollmode == ScrollMode::kScrollLogForced) {
if (m_scrollbar.get_scrollpos() >= m_scrollbar.get_steps() - 1)
setbottom = true;
+ } else if (m_scrollmode == ScrollMode::kNoScrolling) {
+ m_scrollbar.set_scrollpos(0);
+ m_scrollbar.set_steps(1);
+ set_desired_size(get_w(), height);
+ set_size(get_w(), height);
+ }
m_scrollbar.set_steps(height - get_h());
if (setbottom)
m_scrollbar.set_scrollpos(height - get_h());
- if (m_scrollbar.is_enabled() == scroolbar_was_enabled) {
+ if (m_scrollbar.is_enabled() == scrollbar_was_enabled) {
break; // No need to wrap twice.
}
}
@@ -120,16 +127,6 @@
{
}
-/**
- * Change the scroll mode. This will not change the current scroll position;
- * it only affects the behaviour of set_text().
- */
-void MultilineTextarea::set_scrollmode(ScrollMode mode)
-{
- m_scrollmode = mode;
-}
-
-
/// Take care about scrollbar on resize
void MultilineTextarea::layout()
{
=== modified file 'src/ui_basic/multilinetextarea.h'
--- src/ui_basic/multilinetextarea.h 2016-01-29 08:50:22 +0000
+++ src/ui_basic/multilinetextarea.h 2016-02-02 12:58:58 +0000
@@ -37,9 +37,12 @@
* The textarea transparently handles explicit line-breaks and word wrapping.
*/
struct MultilineTextarea : public Panel {
- enum ScrollMode {
- ScrollNormal = 0, ///< (default) only explicit or forced scrolling
- ScrollLog = 1, ///< follow the bottom of the text
+ enum class ScrollMode {
+ kNoScrolling, // Expand the height instead of showing a scroll bar
+ kScrollNormal, // (default) only explicit scrolling
+ kScrollNormalForced, // forced scrolling
+ kScrollLog, // follow the bottom of the text
+ kScrollLogForced // follow the bottom of the text, and forced
};
MultilineTextarea
@@ -47,13 +50,11 @@
const int32_t x, const int32_t y, const uint32_t w, const uint32_t h,
const std::string& text = std::string(),
const Align = UI::Align::kLeft,
- const bool always_show_scrollbar = false);
+ MultilineTextarea::ScrollMode scroll_mode = MultilineTextarea::ScrollMode::kScrollNormal);
const std::string& get_text() const {return m_text;}
- ScrollMode get_scrollmode() const {return m_scrollmode;}
void set_text(const std::string&);
- void set_scrollmode(ScrollMode mode);
uint32_t scrollbar_w() const {return 24;}
uint32_t get_eff_w() const {return m_scrollbar.is_enabled() ? get_w() - scrollbar_w() : get_w();}
=== modified file 'src/ui_basic/spinbox.cc'
--- src/ui_basic/spinbox.cc 2016-01-31 10:57:58 +0000
+++ src/ui_basic/spinbox.cc 2016-02-02 12:58:58 +0000
@@ -129,15 +129,11 @@
box_ = new UI::Box(this, 0, 0, UI::Box::Horizontal, actual_w, texth, padding);
- // Find out how much height we need for the label. We give it 6 rows maximum.
- const Image* rendered_text = UI::g_fh1->render(as_uifont(label_text));
- uint32_t available_width = w - unit_w - no_padding * padding;
- uint32_t extra_rows =
- available_width > 0 ?
- std::min(static_cast<int>(rendered_text->width() / available_width), 6) : 0;
-
- UI::MultilineTextarea* label = new UI::MultilineTextarea(box_, 0, 0, available_width,
- texth * (extra_rows + 1), label_text);
+ UI::MultilineTextarea* label = new UI::MultilineTextarea(box_, 0, 0,
+ w - unit_w - no_padding * padding, texth,
+ label_text,
+ UI::Align::kLeft,
+ UI::MultilineTextarea::ScrollMode::kNoScrolling);
box_->add(label, UI::Align::kHCenter);
sbi_->text = new UI::Textarea(box_, "", UI::Align::kCenter);
=== modified file 'src/wui/game_debug_ui.cc'
--- src/wui/game_debug_ui.cc 2016-01-28 05:24:34 +0000
+++ src/wui/game_debug_ui.cc 2016-02-02 12:58:58 +0000
@@ -70,9 +70,8 @@
UI::Panel(&parent, 0, 0, 350, 200),
m_egbase (egbase),
m_object (&obj),
-m_log (this, 0, 0, 350, 200, "")
+m_log (this, 0, 0, 350, 200, "", UI::Align::kLeft, UI::MultilineTextarea::ScrollMode::kScrollLog)
{
- m_log.set_scrollmode(UI::MultilineTextarea::ScrollLog);
obj.set_logsink(this);
}
=== modified file 'src/wui/game_message_menu.cc'
--- src/wui/game_message_menu.cc 2016-01-31 21:03:15 +0000
+++ src/wui/game_message_menu.cc 2016-02-02 12:58:58 +0000
@@ -58,7 +58,7 @@
kMessageBodyY,
kWindowWidth - 2 * kPadding,
get_inner_h() - kMessageBodyY - 2 * kPadding - kButtonSize,
- "", UI::Align::kLeft, 1),
+ "", UI::Align::kLeft, UI::MultilineTextarea::ScrollMode::kScrollNormalForced),
mode(Inbox)
{
=== modified file 'src/wui/game_objectives_menu.cc'
--- src/wui/game_objectives_menu.cc 2015-12-17 09:36:59 +0000
+++ src/wui/game_objectives_menu.cc 2016-02-02 12:58:58 +0000
@@ -55,7 +55,7 @@
get_inner_w() - 10, FULL_OBJECTIVE_TEXT,
"",
UI::Align::kLeft,
- 1)
+ UI::MultilineTextarea::ScrollMode::kScrollNormalForced)
{
list.selected.connect(boost::bind(&GameObjectivesMenu::selected, this, _1));
if (get_usedefaultpos())
=== modified file 'src/wui/gamechatpanel.cc'
--- src/wui/gamechatpanel.cc 2016-01-29 08:50:22 +0000
+++ src/wui/gamechatpanel.cc 2016-02-02 12:58:58 +0000
@@ -34,11 +34,11 @@
:
UI::Panel(parent, x, y, w, h),
chat_ (chat),
- chatbox (this, 0, 0, w, h - 25, "", UI::Align::kLeft, 1),
+ chatbox (this, 0, 0, w, h - 25, "", UI::Align::kLeft,
+ UI::MultilineTextarea::ScrollMode::kScrollLogForced),
editbox (this, 0, h - 20, w),
chat_message_counter(std::numeric_limits<uint32_t>::max())
{
- chatbox.set_scrollmode(UI::MultilineTextarea::ScrollLog);
editbox.ok.connect(boost::bind(&GameChatPanel::key_enter, this));
editbox.cancel.connect(boost::bind(&GameChatPanel::key_escape, this));
editbox.activate_history(true);
Follow ups