From 3ee5694e9781fe679c35a5116ed76a1a490e1c34 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 12 Dec 2020 23:17:41 +0100 Subject: [PATCH] LibGUI: Simplify ComboBox/TextEditor relationship a bit Instead of TextEditor knowing about the ComboBox button on the right hand side, we now make ComboBox inherit from GUI::Frame, and make the inner text editor widget frameless. This allows us to place the button ourselves inside ComboBox without any frame artifacts, and TextEditor no longer needs to keep track of the geometry of that button. --- Libraries/LibGUI/ComboBox.cpp | 12 +++++++----- Libraries/LibGUI/ComboBox.h | 7 ++++--- Libraries/LibGUI/TextEditor.cpp | 9 +-------- Libraries/LibGUI/TextEditor.h | 4 ---- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Libraries/LibGUI/ComboBox.cpp b/Libraries/LibGUI/ComboBox.cpp index bb7404a1b03..8e68432c1e7 100644 --- a/Libraries/LibGUI/ComboBox.cpp +++ b/Libraries/LibGUI/ComboBox.cpp @@ -59,7 +59,7 @@ private: ComboBox::ComboBox() { m_editor = add(); - m_editor->set_has_open_button(true); + m_editor->set_frame_thickness(0); m_editor->on_return_pressed = [this] { if (on_return_pressed) on_return_pressed(); @@ -139,11 +139,13 @@ ComboBox::~ComboBox() void ComboBox::resize_event(ResizeEvent& event) { - int frame_thickness = m_editor->frame_thickness(); - int button_height = event.size().height() - frame_thickness * 2; + Widget::resize_event(event); + int button_height = event.size().height() - frame_thickness() * 2; int button_width = 15; - m_open_button->set_relative_rect(width() - button_width - frame_thickness, frame_thickness, button_width, button_height); - m_editor->set_relative_rect(0, 0, width(), height()); + m_open_button->set_relative_rect(width() - button_width - frame_thickness(), frame_thickness(), button_width, button_height); + auto editor_rect = frame_inner_rect(); + editor_rect.set_width(editor_rect.width() - button_width); + m_editor->set_relative_rect(editor_rect); } void ComboBox::set_model(NonnullRefPtr model) diff --git a/Libraries/LibGUI/ComboBox.h b/Libraries/LibGUI/ComboBox.h index b9c3fe8e217..a7e432fef71 100644 --- a/Libraries/LibGUI/ComboBox.h +++ b/Libraries/LibGUI/ComboBox.h @@ -26,15 +26,16 @@ #pragma once -#include +#include namespace GUI { class ComboBoxEditor; class ControlBoxButton; -class ComboBox : public Widget { - C_OBJECT(ComboBox) +class ComboBox : public Frame { + C_OBJECT(ComboBox); + public: virtual ~ComboBox() override; diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp index 67db277df3f..cc233c08730 100644 --- a/Libraries/LibGUI/TextEditor.cpp +++ b/Libraries/LibGUI/TextEditor.cpp @@ -386,7 +386,7 @@ void TextEditor::paint_event(PaintEvent& event) Gfx::IntRect display_rect { widget_inner_rect().x() + 1, widget_inner_rect().y() + 1, - widget_inner_rect().width() - button_padding(), + widget_inner_rect().width() - 2, widget_inner_rect().height() - 2 }; painter.add_clip_rect(display_rect); @@ -1437,13 +1437,6 @@ void TextEditor::set_mode(const Mode mode) set_override_cursor(Gfx::StandardCursor::None); } -void TextEditor::set_has_open_button(bool has_button) -{ - if (m_has_open_button == has_button) - return; - m_has_open_button = has_button; -} - void TextEditor::set_has_visible_list(bool visible) { if (m_has_visible_list == visible) diff --git a/Libraries/LibGUI/TextEditor.h b/Libraries/LibGUI/TextEditor.h index 4ac08ac69c6..693cb182412 100644 --- a/Libraries/LibGUI/TextEditor.h +++ b/Libraries/LibGUI/TextEditor.h @@ -68,8 +68,6 @@ public: bool has_visible_list() const { return m_has_visible_list; } void set_has_visible_list(bool); - bool has_open_button() const { return m_has_open_button; } - void set_has_open_button(bool); virtual bool is_automatic_indentation_enabled() const final { return m_automatic_indentation_enabled; } void set_automatic_indentation_enabled(bool enabled) { m_automatic_indentation_enabled = enabled; } @@ -212,7 +210,6 @@ private: int icon_size() const { return 16; } int icon_padding() const { return 2; } - int button_padding() const { return m_has_open_button ? 17 : 2; } class ReflowDeferrer { public: @@ -282,7 +279,6 @@ private: bool m_automatic_indentation_enabled { false }; bool m_line_wrapping_enabled { false }; bool m_has_visible_list { false }; - bool m_has_open_button { false }; bool m_visualize_trailing_whitespace { true }; int m_line_spacing { 4 }; size_t m_soft_tab_width { 4 };