From 489456a0d5d4f6bef5a9d9b7abe8f12abf18c40d Mon Sep 17 00:00:00 2001 From: lick <2188718831@qq.com> Date: Wed, 18 Nov 2026 19:25:07 -0800 Subject: [PATCH] fix(ui): restore TreeState.Disclosure on top of base/ui layering --- base/style_types.go | 9 +++++++++ base/tree.go | 3 +++ cmd/viva/templates/tree.go.txt | 7 ++----- components/tree.go | 7 ++----- ui/tree_paint.go | 9 ++++++++- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/base/style_types.go b/base/style_types.go index 5045d98df..545cb95d7 100644 --- a/base/style_types.go +++ b/base/style_types.go @@ -40,6 +40,15 @@ type HoverIntent struct { since time.Time } +// TreeDisclosure replaces the chevrons a tree draws for its branches: the icon of a +// closed and of an open branch, their size, and the width of the column they occupy +// before the row's content. +type TreeDisclosure struct { + Collapsed, Expanded gfx.Icon + Size float32 + Slot float32 +} + // ScrollBarStyle overrides the geometry of a scroll area's bars. Zero fields keep // Viva's own values, so an application changes only what it needs. type ScrollBarStyle struct { diff --git a/base/tree.go b/base/tree.go index 672fcfcad..e88a16658 100644 --- a/base/tree.go +++ b/base/tree.go @@ -61,6 +61,9 @@ type TreeState struct { c C rowLabel func(int) string Content func(int) + // Disclosure replaces the arrows the tree draws for branches and the width of the + // column they occupy before the row's content. Nil keeps Viva's defaults. + Disclosure *TreeDisclosure } type TreeRow struct { diff --git a/cmd/viva/templates/tree.go.txt b/cmd/viva/templates/tree.go.txt index 319b20f13..b097e5197 100644 --- a/cmd/viva/templates/tree.go.txt +++ b/cmd/viva/templates/tree.go.txt @@ -1,6 +1,7 @@ package {{PACKAGE}} import ( + "github.com/vivaui/viva/base" "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/style" ) @@ -10,11 +11,7 @@ import ( // before the row's content. Zero fields keep Viva's own chevrons (16 points in a 24 // point column), so an application that ships IDEA's arrows can use them without // moving the rows. -type TreeDisclosure struct { - Collapsed, Expanded gfx.Icon - Size float32 - Slot float32 -} +type TreeDisclosure = base.TreeDisclosure // Tree paints a compact vertical hierarchy. Applications own the hierarchy, // expansion, selection, and scrolling; the component owns indentation, diff --git a/components/tree.go b/components/tree.go index 71f0fbf5c..485ac0767 100644 --- a/components/tree.go +++ b/components/tree.go @@ -1,6 +1,7 @@ package components import ( + "github.com/vivaui/viva/base" "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/style" ) @@ -10,11 +11,7 @@ import ( // before the row's content. Zero fields keep Viva's own chevrons (16 points in a 24 // point column), so an application that ships IDEA's arrows can use them without // moving the rows. -type TreeDisclosure struct { - Collapsed, Expanded gfx.Icon - Size float32 - Slot float32 -} +type TreeDisclosure = base.TreeDisclosure // Tree paints a compact vertical hierarchy. Applications own the hierarchy, // expansion, selection, and scrolling; the component owns indentation, diff --git a/ui/tree_paint.go b/ui/tree_paint.go index b46a91cbc..3313e6bb7 100644 --- a/ui/tree_paint.go +++ b/ui/tree_paint.go @@ -30,7 +30,11 @@ func treeStateRow(s *TreeState, i int, rowBox Box) { theme := &f.Palette left := float32(item.Depth) * s.IndentValue(theme) if node.Branch { - left += 24 // the chevron, as components.Tree places it + slot := float32(24) // the chevron, as components.Tree places it + if s.Disclosure != nil && s.Disclosure.Slot > 0 { + slot = s.Disclosure.Slot + } + left += slot } rowBox.Children(func() { b := Row(c).Height(s.HeightOf(node, theme)).Shrink(0).PadRight(8).PadLeft(left).Gap(theme.Metrics.GapItem).Items(Center).Draw(s.GetPaint()) @@ -54,6 +58,9 @@ func treeStateDraw(s *TreeState, d *DrawContext) { continue } tree := components.BeginTree(d.Canvas, *d.Theme, d.Rect).RowHeight(d.Rect.Height).Indent(s.IndentValue(d.Theme)) + if s.Disclosure != nil { + tree = tree.Disclosure(*s.Disclosure) + } tree.Item(row.GetItem()) if s.DragPtr().GetActive() { s.DragOver(row, d)