diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-18 23:57:07 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-18 23:57:07 +0200 |
commit | 9cab7a070722c26f8cc7f40b00475ab091e44b75 (patch) | |
tree | 27cfd4dad9075305e3e5f3e7fd1eb5af935585e1 | |
parent | 568f3125f3ecae6005874844df649a6000bb83cf (diff) | |
download | serenity-9cab7a070722c26f8cc7f40b00475ab091e44b75.zip |
LibGUI: Move the editing widget along with the content when scrolling.
-rw-r--r-- | LibGUI/GAbstractView.cpp | 12 | ||||
-rw-r--r-- | LibGUI/GAbstractView.h | 3 | ||||
-rw-r--r-- | LibGUI/GScrollableWidget.cpp | 2 | ||||
-rw-r--r-- | LibGUI/GScrollableWidget.h | 1 | ||||
-rw-r--r-- | LibGUI/GTableView.cpp | 4 |
5 files changed, 21 insertions, 1 deletions
diff --git a/LibGUI/GAbstractView.cpp b/LibGUI/GAbstractView.cpp index 0187225368..5d67294790 100644 --- a/LibGUI/GAbstractView.cpp +++ b/LibGUI/GAbstractView.cpp @@ -41,3 +41,15 @@ void GAbstractView::did_update_model() void GAbstractView::did_update_selection() { } + +void GAbstractView::did_scroll() +{ + update_edit_widget_position(); +} + +void GAbstractView::update_edit_widget_position() +{ + if (!m_edit_widget) + return; + m_edit_widget->set_relative_rect(m_edit_widget_content_rect.translated(-horizontal_scrollbar().value(), -vertical_scrollbar().value())); +} diff --git a/LibGUI/GAbstractView.h b/LibGUI/GAbstractView.h index f0c33c5bd9..ac019a673e 100644 --- a/LibGUI/GAbstractView.h +++ b/LibGUI/GAbstractView.h @@ -29,10 +29,13 @@ public: protected: virtual void model_notification(const GModelNotification&); + virtual void did_scroll() override; + void update_edit_widget_position(); bool m_editable { false }; GModelIndex m_edit_index; GTextBox* m_edit_widget { nullptr }; + Rect m_edit_widget_content_rect; private: RetainPtr<GModel> m_model; diff --git a/LibGUI/GScrollableWidget.cpp b/LibGUI/GScrollableWidget.cpp index 01d84e7c66..a4ce1620ca 100644 --- a/LibGUI/GScrollableWidget.cpp +++ b/LibGUI/GScrollableWidget.cpp @@ -7,6 +7,7 @@ GScrollableWidget::GScrollableWidget(GWidget* parent) m_vertical_scrollbar = new GScrollBar(Orientation::Vertical, this); m_vertical_scrollbar->set_step(4); m_vertical_scrollbar->on_change = [this] (int) { + did_scroll(); update(); }; @@ -14,6 +15,7 @@ GScrollableWidget::GScrollableWidget(GWidget* parent) m_horizontal_scrollbar->set_step(4); m_horizontal_scrollbar->set_big_step(30); m_horizontal_scrollbar->on_change = [this] (int) { + did_scroll(); update(); }; diff --git a/LibGUI/GScrollableWidget.h b/LibGUI/GScrollableWidget.h index 9d890d820a..60c80a321f 100644 --- a/LibGUI/GScrollableWidget.h +++ b/LibGUI/GScrollableWidget.h @@ -39,6 +39,7 @@ public: protected: explicit GScrollableWidget(GWidget* parent); virtual void resize_event(GResizeEvent&) override; + virtual void did_scroll() { } void set_content_size(const Size&); void set_size_occupied_by_fixed_elements(const Size&); diff --git a/LibGUI/GTableView.cpp b/LibGUI/GTableView.cpp index 85b54cc2b6..65be3d6f57 100644 --- a/LibGUI/GTableView.cpp +++ b/LibGUI/GTableView.cpp @@ -339,8 +339,10 @@ void GTableView::begin_editing(const GModelIndex& index) delete m_edit_widget; m_edit_index = index; m_edit_widget = new GTextBox(this); + m_edit_widget->move_to_back(); m_edit_widget->set_text(model()->data(index, GModel::Role::Display).to_string()); - m_edit_widget->set_relative_rect(cell_content_rect(index)); + m_edit_widget_content_rect = cell_content_rect(index); + update_edit_widget_position(); m_edit_widget->set_focus(true); m_edit_widget->on_return_pressed = [this] { ASSERT(model()); |