From 37c4146805146acdb8574b5b920b2421f3e983f2 Mon Sep 17 00:00:00 2001 From: Mikhail Kupchik Date: Tue, 12 Mar 2024 12:40:57 -0700 Subject: [PATCH 1/3] Fix bool/int inconsistency for TextArea property As TextArea::m_selectable field is a bool, it makes sense for TextArea::is_selectable() and TextArea::set_selectable() methods to return and accept bool. --- include/nanogui/textarea.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nanogui/textarea.h b/include/nanogui/textarea.h index 2fb26851..40eae124 100644 --- a/include/nanogui/textarea.h +++ b/include/nanogui/textarea.h @@ -74,10 +74,10 @@ class NANOGUI_EXPORT TextArea : public Widget { int padding() const { return m_padding; } /// Set whether the text can be selected using the mouse - void set_selectable(int selectable) { m_selectable = selectable; } + void set_selectable(bool selectable) { m_selectable = selectable; } /// Return whether the text can be selected using the mouse - int is_selectable() const { return m_selectable; } + bool is_selectable() const { return m_selectable; } /// Append text at the end of the widget void append(const std::string &text); From 05f063de6bc42f7279312ddd81fc171baefb0729 Mon Sep 17 00:00:00 2001 From: Mikhail Kupchik Date: Tue, 12 Mar 2024 12:44:03 -0700 Subject: [PATCH 2/3] Remove duplicate code in TabWidgetBase::perform_layout() It's enough to clear m_tab_offsets once in this context. --- src/tabwidget.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp index fe9051e5..bcfb1a3b 100644 --- a/src/tabwidget.cpp +++ b/src/tabwidget.cpp @@ -77,7 +77,6 @@ void TabWidgetBase::perform_layout(NVGcontext* ctx) { nvgFontSize(ctx, font_size()); nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_TOP); - m_tab_offsets.clear(); int width = 0; float unused[4]; for (const std::string &label : m_tab_captions) { From 40ff1f1c3ae988997f63ce6918b70bae3e3dbf3f Mon Sep 17 00:00:00 2001 From: Mikhail Kupchik Date: Tue, 12 Mar 2024 13:49:32 -0700 Subject: [PATCH 3/3] Fix duplicate check in TextArea::draw() TextArea::draw() checks there's a selected area before drawing highlighted background. However, there's a duplicate condition `m_selection_end != Vector2i(-1)` in this check, presumably due to a typo. Let's do this check properly, using the same rules as in TextArea::keyboard_event(). --- src/textarea.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/textarea.cpp b/src/textarea.cpp index a10cf179..1cc95003 100644 --- a/src/textarea.cpp +++ b/src/textarea.cpp @@ -156,7 +156,7 @@ void TextArea::draw(NVGcontext *ctx) { std::swap(selection_start, selection_end); flip = true; } - if (m_selection_end != Vector2i(-1) && m_selection_end != Vector2i(-1)) { + if (m_selection_start != Vector2i(-1) && m_selection_end != Vector2i(-1)) { nvgBeginPath(ctx); nvgFillColor(ctx, m_selection_color); if (selection_end.y() == selection_start.y()) { @@ -186,7 +186,7 @@ void TextArea::draw(NVGcontext *ctx) { Vector2i offset = block.offset + m_pos + m_padding; - if (m_selection_end != Vector2i(-1) && m_selection_end != Vector2i(-1) && + if (m_selection_start != Vector2i(-1) && m_selection_end != Vector2i(-1) && offset.y() > selection_start.y() && offset.y() < selection_end.y()) { nvgFillColor(ctx, m_selection_color); nvgBeginPath(ctx);