Added the window updated command, can update titles now. Very nice

This commit is contained in:
2026-02-13 23:36:27 +00:00
parent 9fde9ccd5f
commit c0e33c3585
10 changed files with 237 additions and 48 deletions
+76 -1
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"strconv"
"esdi/cdashdisplay"
"esdi/tui/internal/dom"
"esdi/tui/internal/events"
"esdi/tui/internal/models"
@@ -104,5 +105,79 @@ func createNewWindowForm(bus *events.Bus, doc *dom.DOM) {
}
AddAndShowPage(bus, doc, doc.GetElemByID(layoutToolActionPagesID).(*tview.Pages),
formNode)
formNode, true)
}
func windowInfoPageID(idx int16) string {
return fmt.Sprintf("layout-tool-win-info-%d", idx)
}
func windowInfoForm(bus *events.Bus, doc *dom.DOM, idx int16,
win *cdashdisplay.UIWindow) *dom.UINode {
var err error
x0 := tview.NewInputField().SetLabel("x").SetText(fmt.Sprintf("%d", win.Dims.X0))
y0 := tview.NewInputField().SetLabel("y").SetText(fmt.Sprintf("%d", win.Dims.Y0))
width := tview.NewInputField().SetLabel("width").SetText(fmt.Sprintf("%d", win.Dims.Width))
height := tview.NewInputField().SetLabel("height").SetText(fmt.Sprintf("%d", win.Dims.Height))
title := tview.NewInputField().SetLabel("title").SetText(win.Title.String())
winType := tview.NewDropDown().SetLabel("type").
SetOptions([]string{"string", "bar"}, func(s string, id int) {
// Here we have to add extra options for the configuration of default
// values and so on
}).
SetCurrentOption(0)
form := tview.NewForm().
AddFormItem(x0).
AddFormItem(y0).
AddFormItem(width).
AddFormItem(height).
AddFormItem(title).
AddFormItem(winType).
AddButton("Update", func() {
bus.Emit(ui.LogEv{Log: "update event was created\n"})
// Validate the inputs
window, err := validateFormInputs(
x0.GetText(),
y0.GetText(),
width.GetText(),
height.GetText(),
title.GetText(),
)
if err != nil {
bus.Emit(ui.LogEv{Log: fmt.Sprintf("failed to parse form: %s\n", err.Error())})
return
}
bus.Emit(ui.LogEv{Log: "sending update window ev\n"})
bus.Emit(ui.UpdateWindowEv{ID: idx, Window: window})
})
form.SetBorder(true).
SetTitle(fmt.Sprintf("Info - %s [%2d]", win.Title.String(), idx)).
SetTitleAlign(tview.AlignLeft).
SetInputCapture(func(ev *tcell.EventKey) *tcell.EventKey {
switch ev.Key() {
case tcell.KeyEscape:
bus.Emit(ui.ChangeFocusEv{Target: doc.GetElemByID(layoutToolTreeID)})
}
return ev
})
var formNode *dom.UINode
elemId := windowInfoPageID(idx)
formNode = doc.GetNodeByID(elemId)
layoutToolActionPagesElem := doc.GetElemByID(layoutToolActionPagesID)
if formNode == nil {
formNode, err = doc.NewUINode(elemId, layoutToolActionPagesElem, form)
if err != nil {
panic("failed to create UI node for the new window form: " + err.Error())
}
}
// AddAndShowPage(bus, doc, layoutToolActionPagesElem.(*tview.Pages), formNode)
return formNode
}