mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
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.
This commit is contained in:
parent
a01d11ac19
commit
3ee5694e97
4 changed files with 12 additions and 20 deletions
|
@ -59,7 +59,7 @@ private:
|
|||
ComboBox::ComboBox()
|
||||
{
|
||||
m_editor = add<ComboBoxEditor>();
|
||||
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> model)
|
||||
|
|
|
@ -26,15 +26,16 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibGUI/Widget.h>
|
||||
#include <LibGUI/Frame.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class ComboBoxEditor;
|
||||
class ControlBoxButton;
|
||||
|
||||
class ComboBox : public Widget {
|
||||
C_OBJECT(ComboBox)
|
||||
class ComboBox : public Frame {
|
||||
C_OBJECT(ComboBox);
|
||||
|
||||
public:
|
||||
virtual ~ComboBox() override;
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue