mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:48:10 +00:00
LibGUI: Move the editing widget along with the content when scrolling.
This commit is contained in:
parent
568f3125f3
commit
9cab7a0707
5 changed files with 21 additions and 1 deletions
|
@ -41,3 +41,15 @@ void GAbstractView::did_update_model()
|
||||||
void GAbstractView::did_update_selection()
|
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()));
|
||||||
|
}
|
||||||
|
|
|
@ -29,10 +29,13 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void model_notification(const GModelNotification&);
|
virtual void model_notification(const GModelNotification&);
|
||||||
|
virtual void did_scroll() override;
|
||||||
|
void update_edit_widget_position();
|
||||||
|
|
||||||
bool m_editable { false };
|
bool m_editable { false };
|
||||||
GModelIndex m_edit_index;
|
GModelIndex m_edit_index;
|
||||||
GTextBox* m_edit_widget { nullptr };
|
GTextBox* m_edit_widget { nullptr };
|
||||||
|
Rect m_edit_widget_content_rect;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RetainPtr<GModel> m_model;
|
RetainPtr<GModel> m_model;
|
||||||
|
|
|
@ -7,6 +7,7 @@ GScrollableWidget::GScrollableWidget(GWidget* parent)
|
||||||
m_vertical_scrollbar = new GScrollBar(Orientation::Vertical, this);
|
m_vertical_scrollbar = new GScrollBar(Orientation::Vertical, this);
|
||||||
m_vertical_scrollbar->set_step(4);
|
m_vertical_scrollbar->set_step(4);
|
||||||
m_vertical_scrollbar->on_change = [this] (int) {
|
m_vertical_scrollbar->on_change = [this] (int) {
|
||||||
|
did_scroll();
|
||||||
update();
|
update();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ GScrollableWidget::GScrollableWidget(GWidget* parent)
|
||||||
m_horizontal_scrollbar->set_step(4);
|
m_horizontal_scrollbar->set_step(4);
|
||||||
m_horizontal_scrollbar->set_big_step(30);
|
m_horizontal_scrollbar->set_big_step(30);
|
||||||
m_horizontal_scrollbar->on_change = [this] (int) {
|
m_horizontal_scrollbar->on_change = [this] (int) {
|
||||||
|
did_scroll();
|
||||||
update();
|
update();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
explicit GScrollableWidget(GWidget* parent);
|
explicit GScrollableWidget(GWidget* parent);
|
||||||
virtual void resize_event(GResizeEvent&) override;
|
virtual void resize_event(GResizeEvent&) override;
|
||||||
|
virtual void did_scroll() { }
|
||||||
void set_content_size(const Size&);
|
void set_content_size(const Size&);
|
||||||
void set_size_occupied_by_fixed_elements(const Size&);
|
void set_size_occupied_by_fixed_elements(const Size&);
|
||||||
|
|
||||||
|
|
|
@ -339,8 +339,10 @@ void GTableView::begin_editing(const GModelIndex& index)
|
||||||
delete m_edit_widget;
|
delete m_edit_widget;
|
||||||
m_edit_index = index;
|
m_edit_index = index;
|
||||||
m_edit_widget = new GTextBox(this);
|
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_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->set_focus(true);
|
||||||
m_edit_widget->on_return_pressed = [this] {
|
m_edit_widget->on_return_pressed = [this] {
|
||||||
ASSERT(model());
|
ASSERT(model());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue