Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions base/style_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions base/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions cmd/viva/templates/tree.go.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package {{PACKAGE}}

import (
"github.com/vivaui/viva/base"
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/style"
)
Expand All @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions components/tree.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package components

import (
"github.com/vivaui/viva/base"
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/style"
)
Expand All @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion ui/tree_paint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand Down
Loading