gocui/window.go

101 lines
2.3 KiB
Go
Raw Normal View History

2025-02-01 11:42:31 -06:00
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
2025-02-04 13:31:48 -06:00
"fmt"
2025-02-05 14:11:37 -06:00
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
2025-02-04 14:27:32 -06:00
func (tk *guiWidget) redrawWindow(w int, h int) {
if tk.node.WidgetType != widget.Window {
return
}
2025-02-05 12:32:41 -06:00
// pin the window to (w,h)
tk.gocuiSize.w0 = w
tk.gocuiSize.h0 = h
tk.force.w0 = w
tk.force.w1 = w
tk.force.h0 = h
tk.force.h1 = h
2025-02-05 11:58:27 -06:00
2025-02-04 14:27:32 -06:00
tk.setFullSize() // might make the green box the right size
tk.frame = false
tk.hasTabs = false
2025-02-04 14:27:32 -06:00
tk.DrawAt(w, h)
tk.setColor(&colorActiveW) // sets the window to Green BG
tk.placeWidgets(w, h) // compute the sizes & places for each widget
tk.setFullSize()
me.baseGui.SetView(tk.cuiName, tk.gocuiSize.w0, tk.gocuiSize.h0, tk.gocuiSize.w1, tk.gocuiSize.h1, 0)
tk.Show()
tk.showWidgets()
2025-02-05 14:11:37 -06:00
if tk.windowFrame == nil {
tk.addWindowFrameTK(0 - tk.node.WidgetId)
tk.windowFrame.node.State.Label = "windowFrame"
tk.windowFrame.makeTK([]string{"windowFrame"})
}
tk.windowFrame.MoveToOffset(w, h+2)
tk.windowFrame.drawView()
tk.windowFrame.Show()
2025-02-04 14:27:32 -06:00
}
// re-draws the buttons for each of the windows
2025-02-04 14:45:23 -06:00
func redoWindows(nextW int, nextH int) {
2025-02-04 14:27:32 -06:00
for _, win := range findWindows() {
2025-02-04 15:48:14 -06:00
win.dumpWidget(fmt.Sprintf("redoWindowsS (%d,%d)", nextW, nextH))
win.redrawWindow(nextW, nextH)
2025-02-04 15:48:14 -06:00
win.dumpWidget(fmt.Sprintf("redoWindowsE (%d,%d)", nextW, nextH))
2025-02-04 14:27:32 -06:00
// increment the width for the next window
2025-02-05 12:32:41 -06:00
nextW += 40
nextH += 10
}
}
2025-02-05 14:11:37 -06:00
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 = "DropBox text"
tk.node = n
if tk.node.Parent == nil {
tk.node.Parent = me.treeRoot
}
// copy the data from the action message
tk.node.State.Label = "DropBox"
// set the name used by gocui to the id
tk.cuiName = fmt.Sprintf("%d DR", wId)
tk.color = &colorFlag
// 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
}