figuring a way of having a clean internal interface for the data and other stuff I reckon. I forgot
This commit is contained in:
@@ -103,7 +103,7 @@ func (lc *LayoutController) registerHooks() {
|
||||
|
||||
func (lc *LayoutController) parseWindowFormData(
|
||||
form views.CDashDisplayWindowFormView,
|
||||
) (*cdashdisplay.UIWindow, error) {
|
||||
) (*cdashdisplay.DesktopUIWindow, error) {
|
||||
|
||||
xValue, err := strconv.ParseUint(form.X.GetText(), 10, 64)
|
||||
if err != nil {
|
||||
@@ -140,6 +140,11 @@ func (lc *LayoutController) parseWindowFormData(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
telemFieldInputID, telemField := form.TelemetryField.GetCurrentOption()
|
||||
if telemFieldInputID == -1 {
|
||||
return nil, fmt.Errorf("no option selected for telemetry field")
|
||||
}
|
||||
|
||||
showIDValue := cdashdisplay.ShowIDFalse
|
||||
if form.ShowID.IsChecked() {
|
||||
showIDValue = cdashdisplay.ShowIDTrue
|
||||
@@ -149,7 +154,7 @@ func (lc *LayoutController) parseWindowFormData(
|
||||
winDecor.TextSize = uint8(textSizeValue - 1)
|
||||
winDecor.TitleSize = uint8(titleSizeValue - 1)
|
||||
|
||||
uiWindow := &cdashdisplay.UIWindow{
|
||||
uiWindow := cdashdisplay.UIWindow{
|
||||
Dims: cdashdisplay.UIDimensions{
|
||||
X0: uint16(xValue),
|
||||
Y0: uint16(yValue),
|
||||
@@ -165,9 +170,20 @@ func (lc *LayoutController) parseWindowFormData(
|
||||
Title: helper.B32(form.Title.GetText()),
|
||||
}
|
||||
|
||||
return uiWindow, nil
|
||||
uiData := cdashdisplay.DesktopUIData{
|
||||
TelemetryField: telemField,
|
||||
}
|
||||
|
||||
return &cdashdisplay.DesktopUIWindow{
|
||||
UIWindow: uiWindow,
|
||||
UIData: uiData,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// createWindow is the function the callback for the "Create" button on the new window
|
||||
// form
|
||||
// - parses the contents of the new window form
|
||||
// - sends that data to the correct device service
|
||||
func (lc *LayoutController) createWindow() {
|
||||
window, err := lc.parseWindowFormData(*lc.LayoutToolView.LayoutActions.CreateWindowView.Form)
|
||||
if err != nil {
|
||||
@@ -175,13 +191,16 @@ func (lc *LayoutController) createWindow() {
|
||||
return
|
||||
}
|
||||
|
||||
wID, err := lc.DevService.CreateWindow(window)
|
||||
lc.Messages <- fmt.Sprintf("pre update w address: %p\n", window)
|
||||
window, err = lc.DevService.CreateWindow(window)
|
||||
if err != nil {
|
||||
lc.Messages <- "failed to create window\n"
|
||||
return
|
||||
}
|
||||
lc.Messages <- fmt.Sprintf("post update w address: %p\n", window)
|
||||
lc.Messages <- fmt.Sprintf("%+v\n", window)
|
||||
|
||||
err = lc.updateFormView(wID, window)
|
||||
err = lc.updateFormView(window)
|
||||
if err != nil {
|
||||
// NOTE: if we fail to append the window to the views we must delete it
|
||||
// altogether given we won't be able to manipulate it any further
|
||||
@@ -189,15 +208,19 @@ func (lc *LayoutController) createWindow() {
|
||||
}
|
||||
}
|
||||
|
||||
func (lc *LayoutController) updateFormView(idx int16, win *cdashdisplay.UIWindow) error {
|
||||
// updateFormView updates the new window form to be an existing window form and we change
|
||||
// the buttons for that purpuse
|
||||
func (lc *LayoutController) updateFormView(win *cdashdisplay.DesktopUIWindow) error {
|
||||
// OnSuccess we update our form to be an existing window form
|
||||
err := lc.LayoutToolView.WindowCreatedSuccessfuly(idx, win)
|
||||
err := lc.LayoutToolView.WindowCreatedSuccessfuly(win)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set the update window button behaviour
|
||||
formView := lc.LayoutToolView.FormQuickAccess[idx]
|
||||
formView := lc.LayoutToolView.FormQuickAccess[win.UIData.IDX]
|
||||
lc.Messages <- fmt.Sprintf("QA FORM: %+v\n", lc.LayoutToolView.FormQuickAccess)
|
||||
|
||||
err = SetFormButtonCallback(formView.Form.Form, "Update", func() {
|
||||
lc.Messages <- "pressed update form button\n"
|
||||
window, err := lc.parseWindowFormData(*formView.Form)
|
||||
@@ -207,16 +230,9 @@ func (lc *LayoutController) updateFormView(idx int16, win *cdashdisplay.UIWindow
|
||||
}
|
||||
lc.Messages <- fmt.Sprintf("window data in form: %v\n", window)
|
||||
|
||||
if err != nil {
|
||||
lc.Messages <- "failed to parse form: " + err.Error() + "\n"
|
||||
return
|
||||
}
|
||||
window.UIData.IDX = formView.WinID
|
||||
|
||||
lc.updateWindowAction(idx, win)
|
||||
// lc.updateWindowAction(&models.UIWindow{
|
||||
// IDX: win.IDX,
|
||||
// Window: *window,
|
||||
// })
|
||||
lc.updateWindowAction(window)
|
||||
})
|
||||
if err != nil {
|
||||
lc.Messages <- "failed to set callback for update button\n"
|
||||
@@ -232,6 +248,8 @@ func (lc *LayoutController) updateFormView(idx int16, win *cdashdisplay.UIWindow
|
||||
return ev
|
||||
})
|
||||
|
||||
lc.App.SetFocus(formView.Form.Form)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -272,8 +290,8 @@ func (lc *LayoutController) newWindowAction() {
|
||||
lc.App.SetFocus(newWindowForm.Form.Form)
|
||||
}
|
||||
|
||||
func (lc *LayoutController) updateWindowAction(idx int16, win *cdashdisplay.UIWindow) {
|
||||
err := lc.DevService.UpdateWindow(idx, win)
|
||||
func (lc *LayoutController) updateWindowAction(win *cdashdisplay.DesktopUIWindow) {
|
||||
err := lc.DevService.UpdateWindow(win)
|
||||
|
||||
lc.Messages <- fmt.Sprintf("Window: %v\n", win)
|
||||
|
||||
@@ -284,8 +302,8 @@ func (lc *LayoutController) updateWindowAction(idx int16, win *cdashdisplay.UIWi
|
||||
}
|
||||
|
||||
func (lc *LayoutController) displayLoadedLayouts() {
|
||||
for idx, w := range lc.DevService.CDash.State.Layout.Windows {
|
||||
err := lc.updateFormView(idx, w)
|
||||
for _, w := range lc.DevService.CDash.State.Layout.Windows {
|
||||
err := lc.updateFormView(w)
|
||||
if err != nil {
|
||||
lc.Messages <- "failed to add window to list"
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"esdi/cdashdisplay"
|
||||
helper "esdi/helpers"
|
||||
"esdi/peripheral"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
@@ -43,13 +44,15 @@ func (cds *CDashService) FindDevice() {
|
||||
cds.Messages <- "found cdashdisplay on: " + display.WT.Cfg.Name + "\n"
|
||||
}
|
||||
|
||||
func (cds *CDashService) CreateWindow(win *cdashdisplay.UIWindow) (int16, error) {
|
||||
wID, err := cds.CDash.CreateWindow(*win)
|
||||
func (cds *CDashService) CreateWindow(
|
||||
win *cdashdisplay.DesktopUIWindow,
|
||||
) (*cdashdisplay.DesktopUIWindow, error) {
|
||||
updatedWindow, err := cds.CDash.CreateWindow(win)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return wID, nil
|
||||
return updatedWindow, nil
|
||||
}
|
||||
|
||||
func (cds *CDashService) LoadLayout(layoutPath string) error {
|
||||
@@ -60,8 +63,9 @@ func (cds *CDashService) SaveLayout(layoutPath string) error {
|
||||
return cds.CDash.SaveLayout(layoutPath)
|
||||
}
|
||||
|
||||
func (cds *CDashService) UpdateWindow(idx int16, win *cdashdisplay.UIWindow) error {
|
||||
return cds.CDash.UpdateWindow(idx, win)
|
||||
func (cds *CDashService) UpdateWindow(win *cdashdisplay.DesktopUIWindow) error {
|
||||
cds.Messages <- fmt.Sprintf("Updating a window:\n%+v\n", win)
|
||||
return cds.CDash.UpdateWindow(win)
|
||||
}
|
||||
|
||||
func (cds *CDashService) DeleteWindow(idx int16) error {
|
||||
|
||||
@@ -74,7 +74,7 @@ type ResizeWindowEv struct {
|
||||
|
||||
type WindowCreatedEv struct {
|
||||
ID int16
|
||||
Win cdashdisplay.UIWindow
|
||||
Win cdashdisplay.CDashWin
|
||||
}
|
||||
|
||||
type WindowMovedEv struct {
|
||||
|
||||
@@ -59,7 +59,7 @@ func NewLayoutTreeView() *LayoutTreeView {
|
||||
return view
|
||||
}
|
||||
|
||||
func (lt *LayoutTreeView) AddWindow(idx int16, win *cdashdisplay.UIWindow) error {
|
||||
func (lt *LayoutTreeView) AddWindow(win *cdashdisplay.DesktopUIWindow) error {
|
||||
root := lt.Tree.GetRoot()
|
||||
if root == nil {
|
||||
return fmt.Errorf("unable to get root of treeview")
|
||||
@@ -67,8 +67,8 @@ func (lt *LayoutTreeView) AddWindow(idx int16, win *cdashdisplay.UIWindow) error
|
||||
|
||||
// Create this new node
|
||||
newWindow := tview.NewTreeNode(
|
||||
windowInfoPageTitle(idx, win.Title.String()),
|
||||
).SetReference(idx)
|
||||
windowInfoPageTitle(win.UIData.IDX, win.Title.String()),
|
||||
).SetReference(win.UIData.IDX)
|
||||
|
||||
root.AddChild(newWindow)
|
||||
|
||||
@@ -126,14 +126,16 @@ func NewLayoutToolView() *LayoutToolView {
|
||||
return view
|
||||
}
|
||||
|
||||
func (ltv *LayoutToolView) WindowCreatedSuccessfuly(idx int16, win *cdashdisplay.UIWindow) error {
|
||||
func (ltv *LayoutToolView) WindowCreatedSuccessfuly(
|
||||
win *cdashdisplay.DesktopUIWindow,
|
||||
) error {
|
||||
updateWindowForm := NewWindowFormView(win)
|
||||
|
||||
// Update the pages ID
|
||||
ltv.LayoutActions.Pages.RemovePage(LayoutToolNewWindowID)
|
||||
AddAndShowPage(
|
||||
ltv.LayoutActions.Pages,
|
||||
windowInfoPageID(idx),
|
||||
windowInfoPageID(win.UIData.IDX),
|
||||
updateWindowForm.Form.Form,
|
||||
)
|
||||
|
||||
@@ -141,10 +143,10 @@ func (ltv *LayoutToolView) WindowCreatedSuccessfuly(idx int16, win *cdashdisplay
|
||||
ltv.LayoutActions.CreateWindowView = nil
|
||||
|
||||
// Add this form thing to the quick access map
|
||||
ltv.FormQuickAccess[idx] = updateWindowForm
|
||||
ltv.FormQuickAccess[win.UIData.IDX] = updateWindowForm
|
||||
|
||||
// Add it to the tree view
|
||||
return ltv.LayoutTree.AddWindow(idx, win)
|
||||
return ltv.LayoutTree.AddWindow(win)
|
||||
}
|
||||
|
||||
func (ltv *LayoutToolView) ShowCreateWindowForm() {
|
||||
@@ -178,7 +180,7 @@ func (ltv *LayoutToolView) DeleteWindowByNode(node *tview.TreeNode) {
|
||||
// Did we delete everything ???
|
||||
}
|
||||
|
||||
func (ltv *LayoutToolView) UpdateFormView(idx int16, win *cdashdisplay.UIWindow) {
|
||||
func (ltv *LayoutToolView) UpdateFormView(idx int16, win *cdashdisplay.DesktopUIWindow) {
|
||||
// Update the form view
|
||||
ltv.FormQuickAccess[idx].SetValues(win)
|
||||
|
||||
|
||||
@@ -4,22 +4,24 @@ import (
|
||||
"fmt"
|
||||
|
||||
"esdi/cdashdisplay"
|
||||
"esdi/telemetry"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
type CDashDisplayWindowFormView struct {
|
||||
Form *tview.Form
|
||||
X *tview.InputField
|
||||
Y *tview.InputField
|
||||
Width *tview.InputField
|
||||
Height *tview.InputField
|
||||
Title *tview.InputField
|
||||
PreviewValue *tview.InputField
|
||||
ShowID *tview.Checkbox
|
||||
WinType *tview.DropDown
|
||||
TitleSize *tview.DropDown
|
||||
TextSize *tview.DropDown
|
||||
Form *tview.Form
|
||||
X *tview.InputField
|
||||
Y *tview.InputField
|
||||
Width *tview.InputField
|
||||
Height *tview.InputField
|
||||
Title *tview.InputField
|
||||
PreviewValue *tview.InputField
|
||||
ShowID *tview.Checkbox
|
||||
WinType *tview.DropDown
|
||||
TitleSize *tview.DropDown
|
||||
TextSize *tview.DropDown
|
||||
TelemetryField *tview.DropDown
|
||||
}
|
||||
|
||||
func NewCDashDisplayWindowFormView() *CDashDisplayWindowFormView {
|
||||
@@ -35,6 +37,7 @@ func NewCDashDisplayWindowFormView() *CDashDisplayWindowFormView {
|
||||
view.WinType = tview.NewDropDown().SetLabel("type").
|
||||
SetOptions([]string{"string", "bar"}, func(s string, id int) {}).
|
||||
SetCurrentOption(0)
|
||||
|
||||
view.TitleSize = tview.NewDropDown().SetLabel("Title Size").SetCurrentOption(0)
|
||||
for k := range 20 {
|
||||
view.TitleSize.AddOption(fmt.Sprintf("%d", k+1), blankDropdownOptionCallback)
|
||||
@@ -47,6 +50,12 @@ func NewCDashDisplayWindowFormView() *CDashDisplayWindowFormView {
|
||||
}
|
||||
view.TextSize.SetCurrentOption(0)
|
||||
|
||||
view.TelemetryField = tview.NewDropDown().SetLabel("Telemetry Field")
|
||||
for _, fieldName := range telemetry.FieldNames {
|
||||
view.TelemetryField.AddOption(fieldName, blankDropdownOptionCallback)
|
||||
}
|
||||
view.TelemetryField.SetCurrentOption(0)
|
||||
|
||||
view.Form = tview.NewForm().
|
||||
AddFormItem(view.X).
|
||||
AddFormItem(view.Y).
|
||||
@@ -87,13 +96,16 @@ func NewCreateWindowFormView() *CreateWindowFormView {
|
||||
|
||||
type WindowFormView struct {
|
||||
Form *CDashDisplayWindowFormView
|
||||
WinID int16
|
||||
UpdateBtn *tview.Button
|
||||
}
|
||||
|
||||
func NewWindowFormView(win *cdashdisplay.UIWindow) *WindowFormView {
|
||||
func NewWindowFormView(win *cdashdisplay.DesktopUIWindow) *WindowFormView {
|
||||
view := &WindowFormView{
|
||||
Form: NewCDashDisplayWindowFormView(),
|
||||
Form: NewCDashDisplayWindowFormView(),
|
||||
WinID: win.UIData.IDX,
|
||||
}
|
||||
view.Form.Form.SetTitle(windowEditFormTitle(win.UIData.IDX, win.Title.String()))
|
||||
|
||||
view.UpdateBtn = tview.NewButton("Update")
|
||||
// Need to inject the button functionality later
|
||||
@@ -106,7 +118,7 @@ func NewWindowFormView(win *cdashdisplay.UIWindow) *WindowFormView {
|
||||
return view
|
||||
}
|
||||
|
||||
func (fv *WindowFormView) SetValues(win *cdashdisplay.UIWindow) {
|
||||
func (fv *WindowFormView) SetValues(win *cdashdisplay.DesktopUIWindow) {
|
||||
fv.Form.X.SetText(fmt.Sprintf("%d", win.Dims.X0))
|
||||
fv.Form.Y.SetText(fmt.Sprintf("%d", win.Dims.Y0))
|
||||
fv.Form.Width.SetText(fmt.Sprintf("%d", win.Dims.Width))
|
||||
@@ -117,6 +129,12 @@ func (fv *WindowFormView) SetValues(win *cdashdisplay.UIWindow) {
|
||||
fv.Form.WinType.SetCurrentOption(0) // NOTE: this needs to set the correct option
|
||||
fv.Form.TitleSize.SetCurrentOption(int(win.Decor.TitleSize))
|
||||
fv.Form.TextSize.SetCurrentOption(int(win.Decor.TextSize))
|
||||
|
||||
telemFieldID, ok := telemetry.GetFieldID(win.UIData.TelemetryField)
|
||||
if !ok {
|
||||
telemFieldID = 0
|
||||
}
|
||||
fv.Form.TelemetryField.SetCurrentOption(int(telemFieldID))
|
||||
}
|
||||
|
||||
func windowInfoPageID(idx int16) string {
|
||||
@@ -126,3 +144,7 @@ func windowInfoPageID(idx int16) string {
|
||||
func windowInfoPageTitle(idx int16, title string) string {
|
||||
return fmt.Sprintf("%s [%02d]", title, idx)
|
||||
}
|
||||
|
||||
func windowEditFormTitle(idx int16, title string) string {
|
||||
return fmt.Sprintf("[%2d] %s", idx, title)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user