|
@@ -8,8 +8,10 @@
|
|
|
#include <LibCore/Timer.h>
|
|
|
#include <LibGUI/IconView.h>
|
|
|
#include <LibGUI/Model.h>
|
|
|
+#include <LibGUI/ModelEditingDelegate.h>
|
|
|
#include <LibGUI/Painter.h>
|
|
|
#include <LibGUI/Scrollbar.h>
|
|
|
+
|
|
|
#include <LibGfx/Palette.h>
|
|
|
|
|
|
REGISTER_WIDGET(GUI, IconView);
|
|
@@ -401,10 +403,24 @@ Gfx::IntRect IconView::editing_rect(ModelIndex const& index) const
|
|
|
if (!index.is_valid())
|
|
|
return {};
|
|
|
auto& item_data = get_item_data(index.row());
|
|
|
- return item_data.text_rect.inflated(4, 4);
|
|
|
+ auto editing_rect = item_data.text_rect;
|
|
|
+ editing_rect.set_height(font_for_index(index)->glyph_height() + 8);
|
|
|
+ editing_rect.set_y(item_data.text_rect.y() - 2);
|
|
|
+ return editing_rect;
|
|
|
+}
|
|
|
+
|
|
|
+void IconView::editing_widget_did_change(const ModelIndex& index)
|
|
|
+{
|
|
|
+ if (m_editing_delegate->value().is_string()) {
|
|
|
+ auto text_width = font_for_index(index)->width(m_editing_delegate->value().as_string());
|
|
|
+ m_edit_widget_content_rect.set_width(min(text_width + 8, effective_item_size().width()));
|
|
|
+ m_edit_widget_content_rect.center_horizontally_within(editing_rect(index).translated(frame_thickness(), frame_thickness()));
|
|
|
+ update_edit_widget_position();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-Gfx::IntRect IconView::paint_invalidation_rect(const ModelIndex& index) const
|
|
|
+Gfx::IntRect
|
|
|
+IconView::paint_invalidation_rect(const ModelIndex& index) const
|
|
|
{
|
|
|
if (!index.is_valid())
|
|
|
return {};
|
|
@@ -548,7 +564,8 @@ void IconView::paint_event(PaintEvent& event)
|
|
|
|
|
|
const auto& text_rect = item_data.text_rect;
|
|
|
|
|
|
- painter.fill_rect(text_rect, background_color);
|
|
|
+ if (m_edit_index != item_data.index)
|
|
|
+ painter.fill_rect(text_rect, background_color);
|
|
|
|
|
|
if (is_focused() && item_data.index == cursor_index()) {
|
|
|
painter.draw_rect(text_rect, widget_background_color);
|