diff --git a/colorNew.go b/colorNew.go index ca333f9..f537c5c 100644 --- a/colorNew.go +++ b/colorNew.go @@ -9,7 +9,9 @@ import ( "github.com/awesome-gocui/gocui" ) -func (tk *guiWidget) enableColor() { +// DONE ON ENABLE() WIDGET +// restores the last saved color and makes it active +func (tk *guiWidget) restoreEnableColor() { if tk.color == nil { tk.color = new(colorT) } @@ -19,10 +21,23 @@ func (tk *guiWidget) enableColor() { tk.color.selFg = tk.colorLast.selFg tk.color.selBg = tk.colorLast.selBg - tk.updateColor() + tk.activateColor() } -func (tk *guiWidget) updateColor() { +// DONE ON DISABLE() WIDGET +// makes the button look disabled +func (tk *guiWidget) setColorDisable() { + // save the current color + tk.color.frame = superLightGrey + tk.color.fg = gocui.ColorBlack + tk.color.bg = superLightGrey + tk.color.selFg = superLightGrey + tk.color.selBg = superLightGrey + tk.activateColor() +} + +// sets the current gocui highlight colors +func (tk *guiWidget) activateColor() { if tk.v == nil { return } @@ -33,6 +48,22 @@ func (tk *guiWidget) updateColor() { tk.v.SelBgColor = tk.color.selBg } +// saves the color and makes it active +func (tk *guiWidget) updateColor() { + if tk.v == nil { + return + } + tk.colorLast.frame = tk.color.frame + tk.colorLast.fg = tk.color.fg + tk.colorLast.bg = tk.color.bg + tk.colorLast.selFg = tk.color.selFg + tk.colorLast.selBg = tk.color.selBg + + tk.activateColor() +} + +// Below are all the colors. TODO: move to protobuf and save in a config file + func (tk *guiWidget) setColorWindowFrame() { if tk.color == nil { tk.color = new(colorT) @@ -220,23 +251,3 @@ func (tk *guiWidget) setColorModal() { } tk.updateColor() } - -// makes the button look disabled -func (tk *guiWidget) setColorDisable() { - // save the current color - if tk.color != nil { - tk.colorLast.frame = tk.color.frame - tk.colorLast.fg = tk.color.fg - tk.colorLast.bg = tk.color.bg - tk.colorLast.selFg = tk.color.selFg - tk.colorLast.selBg = tk.color.selBg - } else { - - tk.color.frame = superLightGrey - tk.color.fg = gocui.ColorBlack - tk.color.bg = superLightGrey - tk.color.selFg = superLightGrey - tk.color.selBg = superLightGrey - } - tk.updateColor() -} diff --git a/eventMouseClick.go b/eventMouseClick.go index eda0a26..ce0b6a6 100644 --- a/eventMouseClick.go +++ b/eventMouseClick.go @@ -10,6 +10,15 @@ import ( "go.wit.com/widget" ) +func (tk *guiWidget) doButtonClick() { + if tk.node.IsEnabled() { + tk.dumpWidget("click()") // enable this to debug widget clicks + me.myTree.SendFromUser(tk.node) + } else { + tk.dumpWidget("disabled()") // enable this to debug widget clicks + } +} + // this whole things was impossible to make but it got me where I am now // the debugging is way way better now with it being visible in the Stdout window // so now it's possible to redo all this and make it better @@ -28,9 +37,7 @@ func (tk *guiWidget) doWidgetClick(w int, h int) { } me.myTree.SendUserEvent(tk.node) case widget.Button: - // if tk.node.Enabled() { - me.myTree.SendFromUser(tk.node) - // } + tk.doButtonClick() case widget.Combobox: tk.showDropdown() case widget.Dropdown: @@ -87,8 +94,7 @@ func doMouseClick(w int, h int) { me.myTree.SendUserEvent(tk.node) return case widget.Button: - tk.dumpWidget("click()") // enable this to debug widget clicks - me.myTree.SendFromUser(tk.node) + tk.doButtonClick() return case widget.Combobox: tk.showDropdown() diff --git a/plugin.go b/plugin.go index d758aca..2cec989 100644 --- a/plugin.go +++ b/plugin.go @@ -6,6 +6,7 @@ package main import ( // if you include more than just this import // then your plugin might be doing something un-ideal (just a guess from 2023/02/27) + "go.wit.com/log" "go.wit.com/toolkits/tree" "go.wit.com/widget" @@ -115,10 +116,14 @@ func newaction(n *tree.Node, atype widget.ActionType) { standardClose() case widget.Enable: w.enable = true - w.enableColor() + w.node.State.Enable = true + w.restoreEnableColor() + log.Info("enable widget in gocui", atype, n.WidgetType, n.ProgName()) case widget.Disable: w.enable = false + w.node.State.Enable = false w.setColorDisable() + log.Info("disable widget in gocui", atype, n.WidgetType, n.ProgName()) case widget.Delete: if w == nil { return