From 1408aa129584477430df75a2fa07da5077edad54 Mon Sep 17 00:00:00 2001 From: sin-ack Date: Sun, 8 Aug 2021 09:52:15 +0000 Subject: [PATCH] LibGUI: Do not allow tree column to shrink beyond indent and icon We always display the tree indent and the icon, so we shouldn't allow the tree column to shrink beyond that size. --- Userland/Libraries/LibGUI/TreeView.cpp | 16 ++++++++++++++++ Userland/Libraries/LibGUI/TreeView.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/Userland/Libraries/LibGUI/TreeView.cpp b/Userland/Libraries/LibGUI/TreeView.cpp index dd0c433fe0..1ec3202e92 100644 --- a/Userland/Libraries/LibGUI/TreeView.cpp +++ b/Userland/Libraries/LibGUI/TreeView.cpp @@ -738,4 +738,20 @@ Gfx::IntRect TreeView::content_rect(ModelIndex const& index) const return found_rect; } +int TreeView::minimum_column_width(int column) +{ + if (column != model()->tree_column()) { + return 2; + } + + int maximum_indent_level = 1; + + traverse_in_paint_order([&](ModelIndex const&, Gfx::IntRect const&, Gfx::IntRect const&, int indent_level) { + maximum_indent_level = max(maximum_indent_level, indent_level); + return IterationDecision::Continue; + }); + + return indent_width_in_pixels() * maximum_indent_level + icon_size() + icon_spacing() + 2; +} + } diff --git a/Userland/Libraries/LibGUI/TreeView.h b/Userland/Libraries/LibGUI/TreeView.h index 1cddb0f4e0..6b91783af1 100644 --- a/Userland/Libraries/LibGUI/TreeView.h +++ b/Userland/Libraries/LibGUI/TreeView.h @@ -36,6 +36,8 @@ public: virtual Gfx::IntRect content_rect(ModelIndex const&) const override; virtual Gfx::IntRect paint_invalidation_rect(ModelIndex const& index) const override { return content_rect(index); } + virtual int minimum_column_width(int column) override; + protected: TreeView();