1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

LibGUI: Dynamically resize editing content rect in IconView

This makes IconView aware of the text width of the
ModelEditingDelegate widget when editing an index and allows us to
resize the content rect as needed.

This also removes the border from the textbox since it could collide
with the icon in ColumnsView. While editing we also skip painting the
inactive selection rect since it would otherwise show when the content
rect gets smaller.
This commit is contained in:
Marcus Nilsson 2021-09-05 13:32:23 +02:00 committed by Andreas Kling
parent 207319ecf1
commit 0583f75926
6 changed files with 42 additions and 4 deletions

View file

@ -35,6 +35,7 @@ public:
Function<void()> on_commit;
Function<void()> on_rollback;
Function<void()> on_change;
virtual Variant value() const = 0;
virtual void set_value(Variant const&, SelectionBehavior selection_behavior = SelectionBehavior::SelectAll) = 0;
@ -55,6 +56,11 @@ protected:
if (on_rollback)
on_rollback();
}
void change()
{
if (on_change)
on_change();
}
const ModelIndex& index() const { return m_index; }
@ -72,12 +78,17 @@ public:
virtual RefPtr<Widget> create_widget() override
{
auto textbox = TextBox::construct();
textbox->set_frame_shape(Gfx::FrameShape::NoFrame);
textbox->on_return_pressed = [this] {
commit();
};
textbox->on_escape_pressed = [this] {
rollback();
};
textbox->on_change = [this] {
change();
};
return textbox;
}
virtual Variant value() const override { return static_cast<const TextBox*>(widget())->text(); }