refactor for protobuf

This commit is contained in:
Jeff Carr 2025-02-19 03:33:04 -06:00
parent 31324ad083
commit 3f09b2b6e4
4 changed files with 32 additions and 21 deletions

10
size.go
View File

@ -35,7 +35,7 @@ func (tk *guiWidget) Size() (int, int) {
return 0, 0
}
switch tk.node.WidgetType {
switch tk.WidgetType() {
case widget.Window:
var maxH int = 0
var maxW int = 0
@ -125,7 +125,7 @@ func (w *guiWidget) sizeGrid() (int, int) {
}
func (w *guiWidget) sizeBox() (int, int) {
if w.node.WidgetType != widget.Box {
if w.WidgetType() != widget.Box {
return 0, 0
}
if w.Hidden() {
@ -254,7 +254,7 @@ func (tk *guiWidget) setFullSize() bool {
tk.full.h1 = r.h1
changed = true
}
if tk.node.WidgetType == widget.Button {
if tk.WidgetType() == widget.Button {
tk.full.h1 = tk.full.h0 + 1
}
if tk.isWindowDense() && tk.isInGrid() {
@ -350,13 +350,13 @@ func (tk *guiWidget) getFullSize() rectType {
return r
}
if tk.node.WidgetType == widget.Grid {
if tk.WidgetType() == widget.Grid {
return tk.gridFullSize()
}
// these are 'simple' widgets
// the full size is exactly what gocui uses
switch tk.node.WidgetType {
switch tk.WidgetType() {
case widget.Label:
r := tk.buttonFullSize()
r.w1 += 5

View File

@ -152,3 +152,18 @@ func (tk *guiWidget) findWidgetByView(v *gocui.View) *guiWidget {
}
return nil
}
func (tk *guiWidget) WidgetType() widget.WidgetType {
if tk.node == nil {
return widget.Label
}
return tk.node.WidgetType
}
func (tk *guiWidget) WidgetId() int {
return tk.node.WidgetId
}
func (tk *guiWidget) GetLabel() string {
return tk.node.GetLabel()
}

View File

@ -24,7 +24,7 @@ func (tk *guiWidget) textResize() {
}
// todo: fix all this old code
if tk.node.WidgetType == widget.Textbox {
if tk.WidgetType() == widget.Textbox {
if w < 5 {
w = 5
}
@ -50,7 +50,7 @@ func (w *guiWidget) hideWidgets() {
if w == nil {
return
}
switch w.node.WidgetType {
switch w.WidgetType() {
case widget.Root:
case widget.Flag:
case widget.Window:

View File

@ -13,7 +13,7 @@ import (
)
func (tk *guiWidget) setTitle(s string) {
if tk.node.WidgetType != widget.Window {
if tk.WidgetType() != widget.Window {
return
}
if tk.v == nil {
@ -26,14 +26,13 @@ func (tk *guiWidget) setTitle(s string) {
me.baseGui.SetView(tk.v.Name(), rect.w0-1, rect.h0, rect.w1+1, rect.h1, 0)
tk.v.Clear()
f := " %-" + fmt.Sprintf("%d", tk.full.Width()-3) + "s %s"
// tmp := tk.node.GetLabel() + " " + tk.v.Name() + " " + f
tmp := tk.node.GetLabel()
tmp := tk.GetLabel()
labelN := fmt.Sprintf(f, tmp, "X")
tk.v.WriteString(labelN)
}
func (tk *guiWidget) redrawWindow(w int, h int) {
if tk.node.WidgetType != widget.Window {
if tk.WidgetType() != widget.Window {
return
}
// tk.dumpWidget(fmt.Sprintf("redrawWindow(%d,%d)", w, h))
@ -43,8 +42,8 @@ func (tk *guiWidget) redrawWindow(w int, h int) {
// pin the window to (w,h)
tk.gocuiSize.w0 = w
tk.gocuiSize.h0 = h
tk.gocuiSize.w1 = w + len(tk.node.GetLabel())
tk.labelN = tk.node.GetLabel() // could set XX here also but don't have final size of window yet
tk.gocuiSize.w1 = w + len(tk.GetLabel())
tk.labelN = tk.GetLabel() // could set XX here also but don't have final size of window yet
tk.force.w0 = w
tk.force.w1 = w
tk.force.h0 = h
@ -77,8 +76,7 @@ func (tk *guiWidget) redrawWindow(w int, h int) {
tk.showWidgets()
if tk.windowFrame == nil {
tk.addWindowFrameTK(0 - tk.node.WidgetId)
tk.windowFrame.node.State.Label = "" // temporary name. blank out when ready for release
tk.addWindowFrameTK(0 - tk.WidgetId())
tk.windowFrame.makeTK([]string{""})
}
@ -106,7 +104,7 @@ func (tk *guiWidget) redrawWindow(w int, h int) {
tk.showWidgets()
// draw the window title
tk.setTitle(tk.node.GetLabel())
tk.setTitle(tk.GetLabel())
}
// re-draws the buttons for each of the windows
@ -154,8 +152,6 @@ func (win *guiWidget) addWindowFrame(wId int) *tree.Node {
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)
@ -175,7 +171,7 @@ func (win *guiWidget) addWindowFrame(wId int) *tree.Node {
}
func (tk *guiWidget) isWindowActive() bool {
if !(tk.node.WidgetType == widget.Window || tk.node.WidgetType == widget.Stdout) {
if !(tk.WidgetType() == widget.Window || tk.WidgetType() == widget.Stdout) {
// only allow Window or the Stdout widgets to be made active
return false
}
@ -184,12 +180,12 @@ func (tk *guiWidget) isWindowActive() bool {
// always redraws at the corner of the gocuiSize box
func (tk *guiWidget) makeWindowActive() {
if !(tk.node.WidgetType == widget.Window || tk.node.WidgetType == widget.Stdout) {
if !(tk.WidgetType() == widget.Window || tk.WidgetType() == widget.Stdout) {
// only allow Window or the Stdout widgets to be made active
return
}
if tk.node.WidgetType == widget.Stdout {
if tk.WidgetType() == widget.Stdout {
me.stdout.outputOnTop = true
} else {
// me.stdout.outputOnTop = false // ?