summaryrefslogtreecommitdiff
path: root/view.go
blob: 5bc7b33f26b0c5a0eee2d83de8b129250902f9c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"bufio"
	"strings"

	"go.wit.com/log"
	"go.wit.com/widget"
)

func splitLines(s string) []string {
	var lines []string
	sc := bufio.NewScanner(strings.NewReader(s))
	for sc.Scan() {
		lines = append(lines, sc.Text())
	}
	return lines
}

func (w *guiWidget) textResize() bool {
	// w := n.tk
	var width, height int = 0, 0
	var changed bool = false

	for i, s := range splitLines(w.labelN) {
		log.Log(INFO, "textResize() len =", len(s), i, s)
		if width < len(s) {
			width = len(s)
		}
		height += 1
	}
	if w.gocuiSize.w1 != w.gocuiSize.w0+width+me.FramePadW {
		w.gocuiSize.w1 = w.gocuiSize.w0 + width + me.FramePadW
		changed = true
	}
	if w.gocuiSize.h1 != w.gocuiSize.h0+height+me.FramePadH {
		w.gocuiSize.h1 = w.gocuiSize.h0 + height + me.FramePadH
		changed = true
	}
	if changed {
		// w.showWidgetPlacement("textResize() changed")
	}
	return changed
}

func (w *guiWidget) hideWidgets() {
	if w == nil {
		return
	}
	w.isCurrent = false
	switch w.node.WidgetType {
	case widget.Root:
	case widget.Flag:
	case widget.Window:
	case widget.Box:
	case widget.Grid:
	default:
		w.Hide()
	}
	for _, child := range w.children {
		child.hideWidgets()
	}
}

func hideFake() {
	var w *guiWidget
	w = me.treeRoot.TK.(*guiWidget)
	w.hideFake()
}

func showFake() {
	var w *guiWidget
	w = me.treeRoot.TK.(*guiWidget)
	w.showFake()
}

func (w *guiWidget) hideFake() {
	if w.isFake {
		w.Hide()
	}
	for _, child := range w.children {
		child.hideFake()
	}
}

// shows the 'fake' widgets for widgets that
// are not normally displayed (like a grid widget)
func (w *guiWidget) showFake() {
	if w.isFake {
		w.drawView()
		w.showWidgetPlacement("showFake:")
	}
	for _, child := range w.children {
		child.showFake()
	}
}

func (w *guiWidget) showWidgets() {
	w.Show()

	for _, child := range w.children {
		child.showWidgets()
	}
}