diff options
-rw-r--r-- | LibGUI/GFrame.h | 3 | ||||
-rw-r--r-- | LibGUI/GScrollableWidget.cpp | 25 | ||||
-rw-r--r-- | LibGUI/GScrollableWidget.h | 6 | ||||
-rw-r--r-- | LibGUI/GTextEditor.cpp | 19 |
4 files changed, 30 insertions, 23 deletions
diff --git a/LibGUI/GFrame.h b/LibGUI/GFrame.h index c33b53cbbd..73ede6190c 100644 --- a/LibGUI/GFrame.h +++ b/LibGUI/GFrame.h @@ -19,7 +19,8 @@ public: Shape frame_shape() const { return m_shape; } void set_frame_shape(Shape shape) { m_shape = shape; } - Rect frame_inner_rect() const { return rect().shrunken(m_thickness * 2, m_thickness * 2); } + Rect frame_inner_rect_for_size(const Size& size) const { return { m_thickness, m_thickness, size.width() - m_thickness * 2, size.height() - m_thickness * 2 }; } + Rect frame_inner_rect() const { return frame_inner_rect_for_size(size()); } virtual const char* class_name() const override { return "GFrame"; } diff --git a/LibGUI/GScrollableWidget.cpp b/LibGUI/GScrollableWidget.cpp index d0ec6a12cc..44d47b5bf9 100644 --- a/LibGUI/GScrollableWidget.cpp +++ b/LibGUI/GScrollableWidget.cpp @@ -2,7 +2,7 @@ #include <LibGUI/GScrollBar.h> GScrollableWidget::GScrollableWidget(GWidget* parent) - : GWidget(parent) + : GFrame(parent) { m_vertical_scrollbar = new GScrollBar(Orientation::Vertical, this); m_vertical_scrollbar->set_step(4); @@ -27,25 +27,26 @@ GScrollableWidget::~GScrollableWidget() void GScrollableWidget::resize_event(GResizeEvent& event) { + auto inner_rect = frame_inner_rect_for_size(event.size()); update_scrollbar_ranges(); int height_wanted_by_horizontal_scrollbar = m_horizontal_scrollbar->is_visible() ? m_horizontal_scrollbar->height() : 0; int width_wanted_by_vertical_scrollbar = m_vertical_scrollbar->is_visible() ? m_vertical_scrollbar->width() : 0; - m_vertical_scrollbar->set_relative_rect(event.size().width() - m_vertical_scrollbar->preferred_size().width(), 0, m_vertical_scrollbar->preferred_size().width(), event.size().height() - height_wanted_by_horizontal_scrollbar); - m_horizontal_scrollbar->set_relative_rect(0, event.size().height() - m_horizontal_scrollbar->preferred_size().height(), event.size().width() - m_vertical_scrollbar->preferred_size().width(), width_wanted_by_vertical_scrollbar); + m_vertical_scrollbar->set_relative_rect(inner_rect.right() + 1 - m_vertical_scrollbar->preferred_size().width(), inner_rect.top(), m_vertical_scrollbar->preferred_size().width(), inner_rect.height() - height_wanted_by_horizontal_scrollbar); + m_horizontal_scrollbar->set_relative_rect(inner_rect.left(), inner_rect.bottom() + 1 - m_horizontal_scrollbar->preferred_size().height(), inner_rect.width() - m_vertical_scrollbar->preferred_size().width(), width_wanted_by_vertical_scrollbar); m_corner_widget->set_visible(m_vertical_scrollbar->is_visible() && m_horizontal_scrollbar->is_visible()); if (m_corner_widget->is_visible()) { - Rect corner_rect { m_horizontal_scrollbar->rect().right() + 1, m_vertical_scrollbar->rect().bottom() + 1, height_occupied_by_horizontal_scrollbar(), width_occupied_by_vertical_scrollbar() }; + Rect corner_rect { m_horizontal_scrollbar->rect().right() + 2, m_vertical_scrollbar->rect().bottom() + 2, width_occupied_by_vertical_scrollbar(), height_occupied_by_horizontal_scrollbar() }; m_corner_widget->set_relative_rect(corner_rect); } } Size GScrollableWidget::available_size() const { - int available_width = width() - m_size_occupied_by_fixed_elements.width() - width_occupied_by_vertical_scrollbar(); - int available_height = height() - m_size_occupied_by_fixed_elements.height() - height_occupied_by_horizontal_scrollbar(); + int available_width = frame_inner_rect().width() - m_size_occupied_by_fixed_elements.width() - width_occupied_by_vertical_scrollbar(); + int available_height = frame_inner_rect().height() - m_size_occupied_by_fixed_elements.height() - height_occupied_by_horizontal_scrollbar(); return { available_width, available_height }; } @@ -93,8 +94,8 @@ Rect GScrollableWidget::visible_content_rect() const return { m_horizontal_scrollbar->value(), m_vertical_scrollbar->value(), - width() - width_occupied_by_vertical_scrollbar() - m_size_occupied_by_fixed_elements.width(), - height() - height_occupied_by_horizontal_scrollbar() - m_size_occupied_by_fixed_elements.height() + frame_inner_rect().width() - width_occupied_by_vertical_scrollbar() - m_size_occupied_by_fixed_elements.width(), + frame_inner_rect().height() - height_occupied_by_horizontal_scrollbar() - m_size_occupied_by_fixed_elements.height() }; } @@ -144,3 +145,11 @@ void GScrollableWidget::scroll_to_bottom() { scroll_into_view({ 0, content_height(), 1, 1 }, Orientation::Vertical); } + +Rect GScrollableWidget::widget_inner_rect() const +{ + auto rect = frame_inner_rect(); + rect.set_width(rect.width() - width_occupied_by_vertical_scrollbar()); + rect.set_height(rect.height() - height_occupied_by_horizontal_scrollbar()); + return rect; +} diff --git a/LibGUI/GScrollableWidget.h b/LibGUI/GScrollableWidget.h index 30f430bb14..9d890d820a 100644 --- a/LibGUI/GScrollableWidget.h +++ b/LibGUI/GScrollableWidget.h @@ -1,10 +1,10 @@ #pragma once -#include <LibGUI/GWidget.h> +#include <LibGUI/GFrame.h> class GScrollBar; -class GScrollableWidget : public GWidget { +class GScrollableWidget : public GFrame { public: virtual ~GScrollableWidget() override; @@ -14,6 +14,8 @@ public: Rect visible_content_rect() const; + Rect widget_inner_rect() const; + void scroll_into_view(const Rect&, Orientation); void scroll_into_view(const Rect&, bool scroll_horizontally, bool scroll_vertically); diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp index 597721e64b..060bb34041 100644 --- a/LibGUI/GTextEditor.cpp +++ b/LibGUI/GTextEditor.cpp @@ -1,4 +1,4 @@ -#include <LibGUI/GTextEditor.h> + #include <LibGUI/GTextEditor.h> #include <LibGUI/GScrollBar.h> #include <LibGUI/GFontDatabase.h> #include <LibGUI/GClipboard.h> @@ -13,6 +13,9 @@ GTextEditor::GTextEditor(Type type, GWidget* parent) : GScrollableWidget(parent) , m_type(type) { + set_frame_shape(GFrame::Shape::Panel); + set_frame_shadow(GFrame::Shadow::Sunken); + set_frame_thickness(1); set_scrollbars_enabled(is_multi_line()); m_ruler_visible = is_multi_line(); set_font(GFontDatabase::the().get_by_name("Csilla Thin")); @@ -147,9 +150,10 @@ Rect GTextEditor::ruler_content_rect(int line_index) const void GTextEditor::paint_event(GPaintEvent& event) { + GFrame::paint_event(event); + Painter painter(*this); - Rect item_area_rect { 0, 0, width() - width_occupied_by_vertical_scrollbar(), height() - height_occupied_by_horizontal_scrollbar() }; - painter.set_clip_rect(item_area_rect); + painter.set_clip_rect(widget_inner_rect()); painter.set_clip_rect(event.rect()); painter.fill_rect(event.rect(), Color::White); @@ -160,8 +164,6 @@ void GTextEditor::paint_event(GPaintEvent& event) painter.draw_line(ruler_rect.top_right(), ruler_rect.bottom_right(), Color::DarkGray); } - painter.save(); - painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value()); if (m_ruler_visible) painter.translate(ruler_width(), 0); @@ -210,13 +212,6 @@ void GTextEditor::paint_event(GPaintEvent& event) if (is_focused() && m_cursor_state) painter.fill_rect(cursor_content_rect(), Color::Red); - - painter.restore(); - - if (is_focused()) - painter.draw_rect(item_area_rect, Color::from_rgb(0x84351a)); - else if (is_single_line()) - painter.draw_rect(item_area_rect, Color::MidGray); } void GTextEditor::toggle_selection_if_needed_for_event(const GKeyEvent& event) |