summaryrefslogtreecommitdiff
path: root/window.go
blob: 10394309c51834b4923dfd246b35d5299fbb2f29 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"fmt"

	"go.wit.com/toolkits/tree"
	"go.wit.com/widget"
)

func (tk *guiWidget) redrawWindow(w int, h int) {
	if tk.node.WidgetType != widget.Window {
		return
	}
	// pin the window to (w,h)
	tk.gocuiSize.w0 = w
	tk.gocuiSize.h0 = h
	tk.gocuiSize.w1 = w + len(tk.GetText())
	tk.force.w0 = w
	tk.force.w1 = w
	tk.force.h0 = h
	tk.force.h1 = h

	tk.setFullSize() // might make the green box the right size

	tk.frame = false
	tk.hasTabs = false

	tk.DrawAt(w, h)
	tk.setColor(&colorActiveW) // sets the window to Green BG
	tk.placeWidgets(w, h)      // compute the sizes & places for each widget

	// this is a test. this should not be needed
	tk.full.w0 = tk.force.w0
	tk.full.h0 = tk.force.h0

	tk.setFullSize()
	me.baseGui.SetView(tk.cuiName, tk.gocuiSize.w0, tk.gocuiSize.h0, tk.gocuiSize.w1, tk.gocuiSize.h1, 0)
	tk.Show()
	tk.showWidgets()

	// RE-VERIFY THIS CAN'T BE DONE IN A BETTER WAY. However, for now, this works finally so I am leaving it alone

	if tk.windowFrame == nil {
		tk.addWindowFrameTK(0 - tk.node.WidgetId)
		tk.windowFrame.node.State.Label = "windowFrame"
		tk.windowFrame.makeTK([]string{"windowFrame"})
	}

	// this seems to correctly create the window frame
	r := tk.getFullSize()
	tk.windowFrame.gocuiSize.w0 = tk.force.w0
	tk.windowFrame.gocuiSize.w1 = r.w1 + 1
	tk.windowFrame.gocuiSize.h0 = tk.force.h0 + 2
	tk.windowFrame.gocuiSize.h1 = r.h1 + 1
	tk.windowFrame.full.w0 = tk.force.w0
	tk.windowFrame.full.w1 = r.w1 + 1
	tk.windowFrame.full.h0 = tk.force.h0 + 2
	tk.windowFrame.full.h1 = r.h1 + 1
	tk.windowFrame.Hide()
	tk.windowFrame.Show()

	// set the window frame below the window widget, but this resizes the window widget it seems
	me.baseGui.SetViewBeneath(tk.windowFrame.cuiName, tk.cuiName, 1)
	// so now we have to resize the window frame, but this moves it to the top?
	me.baseGui.SetView(tk.windowFrame.cuiName, tk.windowFrame.full.w0, tk.windowFrame.full.h0, tk.windowFrame.full.w1, tk.windowFrame.full.h1, 0)

	// so we have to redraw the widgets in the window anyway and then they will appear above he frame
	tk.hideWidgets()
	tk.showWidgets()
}

// re-draws the buttons for each of the windows
func redoWindows(nextW int, nextH int) {
	for _, win := range findWindows() {
		win.dumpWidget(fmt.Sprintf("redoWindowsS (%d,%d)", nextW, nextH))
		win.redrawWindow(nextW, nextH)
		win.dumpWidget(fmt.Sprintf("redoWindowsE (%d,%d)", nextW, nextH))

		// increment the width for the next window
		nextW += win.gocuiSize.Width() + 10
		// nextH += 10
	}
}

func (tk *guiWidget) addWindowFrameTK(wId int) {
	n := tk.addWindowFrame(wId)
	tk.windowFrame = n.TK.(*guiWidget)
}

func (win *guiWidget) addWindowFrame(wId int) *tree.Node {
	n := new(tree.Node)
	n.WidgetType = widget.Flag
	n.WidgetId = wId
	n.ParentId = 0

	// store the internal toolkit information
	tk := new(guiWidget)
	tk.frame = true
	tk.labelN = "windowFrame text"
	tk.internal = true

	tk.node = n
	if tk.node.Parent == nil {
		tk.node.Parent = me.treeRoot
	}
	// copy the data from the action message
	tk.node.State.Label = "windowFrame"

	// set the name used by gocui to the id
	tk.cuiName = fmt.Sprintf("%d DR", wId)

	tk.color = &colorGroup

	// add this new widget on the binary tree
	tk.parent = win
	if tk.parent == nil {
		panic("addDropdown() didn't get treeRoot guiWidget")
	} else {
		tk.parent.children = append(tk.parent.children, tk)
	}

	n.TK = tk
	return n
}