summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-09-24 11:40:19 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-24 11:40:19 +0200
commitece555b684a6e6dc46e471ba06b669ebfbfcc160 (patch)
tree2ee60a007b4a7b86bb3b38b7ddd59a71fc979d32 /Libraries/LibGUI
parent7d30cf71223e27db4569a11d8e1c750056650ee7 (diff)
downloadserenity-ece555b684a6e6dc46e471ba06b669ebfbfcc160.zip
LibGUI: Support inline editing in GUI::IconView
IconView now responds to the editing key (F2) if the view is editable. It does feel a little bit weird to have content_rect() return the text rect for an item, and not the whole item rect. This internal API could probably be better.
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r--Libraries/LibGUI/IconView.cpp16
-rw-r--r--Libraries/LibGUI/IconView.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/Libraries/LibGUI/IconView.cpp b/Libraries/LibGUI/IconView.cpp
index 9b26ee78b1..42a7498d43 100644
--- a/Libraries/LibGUI/IconView.cpp
+++ b/Libraries/LibGUI/IconView.cpp
@@ -388,6 +388,14 @@ void IconView::update_item_rects(int item_index, ItemData& item_data) const
item_data.text_rect.set_top(item_rect.y() + item_data.text_offset_y);
}
+Gfx::IntRect IconView::content_rect(const ModelIndex& index) const
+{
+ if (!index.is_valid())
+ return {};
+ auto& item_data = get_item_data(index.row());
+ return item_data.text_rect;
+}
+
void IconView::get_item_rects(int item_index, ItemData& item_data, const Gfx::Font& font) const
{
auto item_rect = this->item_rect(item_index);
@@ -602,6 +610,14 @@ void IconView::keydown_event(KeyEvent& event)
if (!m_visual_row_count || !m_visual_column_count)
return;
+ if (event.key() == KeyCode::Key_F2) {
+ if (is_editable() && edit_triggers() & EditTrigger::EditKeyPressed) {
+ begin_editing(cursor_index());
+ event.accept();
+ return;
+ }
+ }
+
if (event.key() == KeyCode::Key_Return) {
activate_selected();
return;
diff --git a/Libraries/LibGUI/IconView.h b/Libraries/LibGUI/IconView.h
index c4ae146e86..24f0326ca8 100644
--- a/Libraries/LibGUI/IconView.h
+++ b/Libraries/LibGUI/IconView.h
@@ -49,6 +49,7 @@ public:
void set_model_column(int column) { m_model_column = column; }
virtual ModelIndex index_at_event_position(const Gfx::IntPoint&) const override;
+ virtual Gfx::IntRect content_rect(const ModelIndex&) const override;
virtual void select_all() override;