mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:37:37 +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:
parent
207319ecf1
commit
0583f75926
6 changed files with 42 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
Gfx::IntRect IconView::paint_invalidation_rect(const ModelIndex& index) const
|
||||
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
|
||||
{
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue