LibGUI: Move the editing widget along with the content when scrolling.

This commit is contained in:
Andreas Kling 2019-04-18 23:57:07 +02:00
parent 568f3125f3
commit 9cab7a0707
Notes: sideshowbarker 2024-07-19 14:39:37 +09:00
5 changed files with 21 additions and 1 deletions

View file

@ -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()));
}

View file

@ -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;

View file

@ -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();
};

View file

@ -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&);

View file

@ -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());