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
|
|
|
|
|
2024-02-02 14:49:17 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2025-02-04 13:31:48 -06:00
|
|
|
"fmt"
|
|
|
|
|
2025-02-06 14:35:01 -06:00
|
|
|
log "go.wit.com/log"
|
2025-02-05 14:11:37 -06:00
|
|
|
"go.wit.com/toolkits/tree"
|
2024-02-02 14:49:17 -06:00
|
|
|
"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-06 23:35:15 -06:00
|
|
|
// tk.dumpWidget(fmt.Sprintf("redrawWindow(%d,%d)", w, h))
|
2025-02-06 20:34:29 -06:00
|
|
|
if tk.full.Height() > 40 {
|
|
|
|
tk.window.dense = true
|
|
|
|
}
|
2025-02-05 12:32:41 -06:00
|
|
|
// pin the window to (w,h)
|
|
|
|
tk.gocuiSize.w0 = w
|
|
|
|
tk.gocuiSize.h0 = h
|
2025-02-06 01:42:40 -06:00
|
|
|
tk.gocuiSize.w1 = w + len(tk.GetText())
|
2025-02-05 12:32:41 -06:00
|
|
|
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
|
|
|
|
|
2025-02-04 14:54:24 -06:00
|
|
|
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
|
2025-02-06 17:29:17 -06:00
|
|
|
|
|
|
|
if tk.window.collapsed {
|
|
|
|
// don't show anything but the title bar
|
|
|
|
tk.hideWindow()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tk.placeWidgets(w, h) // compute the sizes & places for each widget
|
2025-02-04 14:27:32 -06:00
|
|
|
|
2025-02-05 16:30:06 -06:00
|
|
|
// this is a test. this should not be needed
|
|
|
|
tk.full.w0 = tk.force.w0
|
|
|
|
tk.full.h0 = tk.force.h0
|
|
|
|
|
2025-02-04 14:27:32 -06:00
|
|
|
tk.setFullSize()
|
2025-02-06 14:35:01 -06:00
|
|
|
v, err := me.baseGui.SetView(tk.cuiName, tk.gocuiSize.w0, tk.gocuiSize.h0, tk.gocuiSize.w1, tk.gocuiSize.h1, 0)
|
|
|
|
if err != nil {
|
|
|
|
log.Info("crap. got an err", err)
|
|
|
|
}
|
|
|
|
if tk.v != v {
|
|
|
|
log.Info("crap. got another problem v != tk.v")
|
|
|
|
}
|
2025-02-05 10:41:10 -06:00
|
|
|
tk.Show()
|
2025-02-06 14:13:31 -06:00
|
|
|
tk.v.Clear()
|
|
|
|
fmt.Fprint(tk.v, "ZZZ"+tk.GetText())
|
2025-02-05 10:41:10 -06:00
|
|
|
tk.showWidgets()
|
2025-02-05 14:11:37 -06:00
|
|
|
|
2025-02-06 01:42:40 -06:00
|
|
|
// RE-VERIFY THIS CAN'T BE DONE IN A BETTER WAY. However, for now, this works finally so I am leaving it alone
|
|
|
|
|
2025-02-05 14:11:37 -06:00
|
|
|
if tk.windowFrame == nil {
|
|
|
|
tk.addWindowFrameTK(0 - tk.node.WidgetId)
|
2025-02-06 14:13:31 -06:00
|
|
|
tk.windowFrame.node.State.Label = " ZZzzzFrame" // temporary name. blank out when ready for release
|
|
|
|
tk.windowFrame.makeTK([]string{" ZZzzzFrame"})
|
2025-02-05 14:11:37 -06:00
|
|
|
}
|
2025-02-06 01:42:40 -06:00
|
|
|
|
|
|
|
// this seems to correctly create the window frame
|
2025-02-05 14:29:38 -06:00
|
|
|
r := tk.getFullSize()
|
2025-02-05 16:30:06 -06:00
|
|
|
tk.windowFrame.gocuiSize.w0 = tk.force.w0
|
2025-02-05 14:48:35 -06:00
|
|
|
tk.windowFrame.gocuiSize.w1 = r.w1 + 1
|
2025-02-05 16:30:06 -06:00
|
|
|
tk.windowFrame.gocuiSize.h0 = tk.force.h0 + 2
|
2025-02-05 14:48:35 -06:00
|
|
|
tk.windowFrame.gocuiSize.h1 = r.h1 + 1
|
2025-02-05 16:30:06 -06:00
|
|
|
tk.windowFrame.full.w0 = tk.force.w0
|
2025-02-05 14:48:35 -06:00
|
|
|
tk.windowFrame.full.w1 = r.w1 + 1
|
2025-02-05 16:30:06 -06:00
|
|
|
tk.windowFrame.full.h0 = tk.force.h0 + 2
|
2025-02-05 14:48:35 -06:00
|
|
|
tk.windowFrame.full.h1 = r.h1 + 1
|
|
|
|
tk.windowFrame.Hide()
|
2025-02-05 14:11:37 -06:00
|
|
|
tk.windowFrame.Show()
|
2025-02-06 01:42:40 -06:00
|
|
|
|
|
|
|
// set the window frame below the window widget, but this resizes the window widget it seems
|
2025-02-05 14:29:38 -06:00
|
|
|
me.baseGui.SetViewBeneath(tk.windowFrame.cuiName, tk.cuiName, 1)
|
2025-02-06 01:42:40 -06:00
|
|
|
// so now we have to resize the window frame, but this moves it to the top?
|
2025-02-05 14:42:50 -06:00
|
|
|
me.baseGui.SetView(tk.windowFrame.cuiName, tk.windowFrame.full.w0, tk.windowFrame.full.h0, tk.windowFrame.full.w1, tk.windowFrame.full.h1, 0)
|
2025-02-06 01:42:40 -06:00
|
|
|
|
|
|
|
// so we have to redraw the widgets in the window anyway and then they will appear above he frame
|
2025-02-05 14:42:50 -06:00
|
|
|
tk.hideWidgets()
|
|
|
|
tk.showWidgets()
|
2025-02-04 14:27:32 -06:00
|
|
|
}
|
|
|
|
|
2024-02-05 03:19:08 -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-06 14:46:32 -06:00
|
|
|
for _, tk := range findWindows() {
|
|
|
|
tk.dumpWidget(fmt.Sprintf("redoWindowsS (%d,%d)", nextW, nextH))
|
|
|
|
if tk.window.wasDragged {
|
|
|
|
// don't move windows around the user has dragged to a certain location
|
|
|
|
tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0)
|
2025-02-06 22:17:05 -06:00
|
|
|
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
|
2025-02-06 14:46:32 -06:00
|
|
|
} else {
|
|
|
|
w, _ := me.baseGui.Size()
|
|
|
|
if nextW > w-20 {
|
|
|
|
nextW = 0
|
|
|
|
nextH += 4
|
|
|
|
}
|
|
|
|
// probably a new window?
|
|
|
|
tk.redrawWindow(nextW, nextH)
|
|
|
|
}
|
|
|
|
tk.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-06 14:46:32 -06:00
|
|
|
nextW += tk.gocuiSize.Width() + 10
|
2025-02-05 17:31:56 -06:00
|
|
|
// nextH += 10
|
2024-02-02 14:49:17 -06:00
|
|
|
}
|
|
|
|
}
|
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
|
2025-02-05 14:29:38 -06:00
|
|
|
tk.labelN = "windowFrame text"
|
|
|
|
tk.internal = true
|
2025-02-05 14:11:37 -06:00
|
|
|
|
|
|
|
tk.node = n
|
|
|
|
if tk.node.Parent == nil {
|
|
|
|
tk.node.Parent = me.treeRoot
|
|
|
|
}
|
|
|
|
// copy the data from the action message
|
2025-02-05 14:29:38 -06:00
|
|
|
tk.node.State.Label = "windowFrame"
|
2025-02-05 14:11:37 -06:00
|
|
|
|
|
|
|
// set the name used by gocui to the id
|
|
|
|
tk.cuiName = fmt.Sprintf("%d DR", wId)
|
|
|
|
|
2025-02-05 14:29:38 -06:00
|
|
|
tk.color = &colorGroup
|
2025-02-05 14:11:37 -06:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2025-02-06 13:47:19 -06:00
|
|
|
|
|
|
|
func (tk *guiWidget) makeWindowActive() {
|
|
|
|
if !(tk.node.WidgetType == widget.Window || tk.node.WidgetType == widget.Stdout) {
|
|
|
|
// only allow Window or the Stdout widgets to be made active
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// disable and increment all the windows
|
|
|
|
for _, tk := range me.allwin {
|
|
|
|
tk.window.order += 1
|
|
|
|
tk.window.active = false
|
2025-02-06 15:19:39 -06:00
|
|
|
tk.setColor(&colorWindow) // color for inactive windows
|
2025-02-06 13:47:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// set this window as the active one
|
|
|
|
tk.window.active = true
|
|
|
|
tk.window.order = 0
|
|
|
|
|
2025-02-06 14:13:31 -06:00
|
|
|
/*
|
|
|
|
// print out the window list
|
|
|
|
for _, tk := range me.allwin {
|
|
|
|
log.Info("makeWindowActive() Window", tk.labelN, tk.window.active, tk.window.order)
|
|
|
|
}
|
|
|
|
*/
|
2025-02-06 13:47:19 -06:00
|
|
|
}
|