diff options
| -rw-r--r-- | dropdown.go | 71 | ||||
| -rw-r--r-- | eventBindings.go | 3 | ||||
| -rw-r--r-- | eventMouse.go | 30 | ||||
| -rw-r--r-- | eventMouseClick.go | 65 | ||||
| -rw-r--r-- | structs.go | 106 |
5 files changed, 140 insertions, 135 deletions
diff --git a/dropdown.go b/dropdown.go index 6c3a9ff..328f7ff 100644 --- a/dropdown.go +++ b/dropdown.go @@ -90,54 +90,29 @@ func addDropdownNew(wId int) *tree.Node { func (tk *guiWidget) showDropdown() { // todo: fix this after switching to protobuf - // var items []string - // items = tk.node.State.Strings - //for i, s := range items { - /* - var ddItems string - for i, s := range tk.node.Strings() { - // log.Log(GOCUI, "showDropdown()", tk.String(), i, s) - ddItems += s + "\n" - } - */ - - // log.Log(GOCUI, "new dropdown items should be set to:", ddItems) - // sizeW, sizeH := tk.Size() - // log.Log(GOCUI, "showDropdown() size W,H=", sizeW, sizeH) - startW, startH := tk.Position() - log.Log(GOCUI, "showDropdown() IS BROKEN W,H=", startW, startH) - // me.dropdownV.MoveToOffset(startW+3, startH+2) - // me.dropdownV.labelN = ddItems - // me.dropdownV.Show() -} - -/* -func hideDDview() error { - w, h := me.baseGui.MousePosition() - log.Log(GOCUI, "hide dropdown menu() view (w,h) =", w, h) - if me.dropdownV == nil { - return gocui.ErrUnknownView - } - if me.dropdownV.v == nil { - return gocui.ErrUnknownView + me.dropdown.items = []string{} // zero out whatever was there before + for i, s := range tk.node.Strings() { + log.Log(GOCUI, "showDropdown()", tk.String(), i, s) + me.dropdown.items = append(me.dropdown.items, s) } - me.dropdownV.SetVisible(false) - return nil -} -func showDDview() error { - w, h := me.baseGui.MousePosition() - log.Log(GOCUI, "show dropdown menu() view (w,h) =", w, h) - if me.dropdownV == nil { - return gocui.ErrUnknownView + log.Log(GOCUI, "new dropdown items should be set to:", me.dropdown.items) + + if me.dropdown.tk == nil { + me.dropdown.tk = addDropdownTK(-77) } - if me.dropdownV.v == nil { - return gocui.ErrUnknownView + if me.dropdown.tk == nil { + log.Log(GOCUI, "showDropdown() IS BROKEN") + return } - me.dropdownV.SetVisible(true) - return nil + startW, startH := tk.Position() + log.Log(GOCUI, "showDropdown() SHOWING AT W,H=", startW, startH) + me.dropdown.tk.MoveToOffset(startW+3, startH+2) + me.dropdown.tk.labelN = strings.Join(me.dropdown.items, "\n") + me.dropdown.tk.Show() + me.dropdown.active = true + me.dropdown.callerTK = tk } -*/ // if there is a drop down view active, treat it like a dialog box and close it func (w *guiWidget) dropdownClicked(mouseW, mouseH int) string { @@ -150,7 +125,7 @@ func (w *guiWidget) dropdownClicked(mouseW, mouseH int) string { // log.Log(GOCUI, "dropdownClicked() at (w,h) =", mouseW, mouseH) itemNumber := mouseH - startH - items := strings.Split(w.labelN, "\n") + items := me.dropdown.items // log.Log(GOCUI, "dropdownClicked() look for item", itemNumber, "len(items) =", len(items)) if itemNumber < 1 { return "" @@ -159,11 +134,11 @@ func (w *guiWidget) dropdownClicked(mouseW, mouseH int) string { if len(items) >= itemNumber { // log.Log(GOCUI, "dropdownClicked() found", items[itemNumber-1]) if items[itemNumber-1] != "" { - if me.dropdownW != nil { + if me.dropdown.tk != nil { // log.Log(GOCUI, "dropdownClicked() send event for", me.dropdownW.cuiName, me.dropdownW.node.WidgetType) - me.dropdownW.SetText(items[itemNumber-1]) - me.dropdownW.node.SetCurrentS(items[itemNumber-1]) - me.myTree.SendUserEvent(me.dropdownW.node) + me.dropdown.callerTK.SetText(items[itemNumber-1]) + me.dropdown.callerTK.node.SetCurrentS(items[itemNumber-1]) + me.myTree.SendUserEvent(me.dropdown.callerTK.node) } } return items[itemNumber-1] diff --git a/eventBindings.go b/eventBindings.go index 600bea0..183a21d 100644 --- a/eventBindings.go +++ b/eventBindings.go @@ -37,6 +37,8 @@ func registerHandlers(g *gocui.Gui) { g.SetKeybinding("", 'q', gocui.ModNone, doExit) // 'q' exit // debugging + g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, theNotsure) // '2' use this to test new ideas + g.SetKeybinding("", gocui.KeyTab, gocui.ModShift, theNotsure) // '2' use this to test new ideas g.SetKeybinding("", '2', gocui.ModNone, theNotsure) // '2' use this to test new ideas g.SetKeybinding("", 'S', gocui.ModNone, theSuperMouse) // 'S' Super Mouse mode! g.SetKeybinding("", 'M', gocui.ModNone, printWidgetPlacements) // 'M' list all widgets with positions @@ -94,6 +96,7 @@ func addDropdown() *tree.Node { // use this to test code ideas // put whatever you want here and hit '2' to activate it func theNotsure(g *gocui.Gui, v *gocui.View) error { log.Info("got keypress 2. now what?") + log.Info("try to switch windows here") // w, h := g.MousePosition() // me.newWindowTrigger <- true return nil diff --git a/eventMouse.go b/eventMouse.go index 6d0c684..c4871ec 100644 --- a/eventMouse.go +++ b/eventMouse.go @@ -36,25 +36,47 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error { // widget was underneath so you can active // the right response for the toolkit user's app func mouseDown(g *gocui.Gui, v *gocui.View) error { - mx, my := g.MousePosition() log.Info("mouseDown() setting globalMouseDown = true") me.globalMouseDown = true + if me.dropdown.active { + w, h := g.MousePosition() + log.Info("mouseDown() stopping here. dropdwon menu is in effect") + for _, tk := range findByXY(w, h) { + if tk.node.WidgetType == widget.Flag { + log.Info("SENDING CLICK TO Dropdown Flag") + tk.doWidgetClick(w, h) + return nil + } + } + log.Info("never found dropdown") + me.dropdown.active = false + return nil + } + var found bool = false - for _, tk := range findByXY(mx, my) { + w, h := g.MousePosition() + for _, tk := range findByXY(w, h) { tk.dumpWidget("mouseDown()") if tk.node.WidgetType == widget.Button { log.Info("SENDING CLICK TO Button") - tk.doWidgetClick(mx, my) + tk.doWidgetClick(w, h) return nil } if tk.node.WidgetType == widget.Checkbox { log.Info("SENDING CLICK TO Checkbox") - tk.doWidgetClick(mx, my) + tk.doWidgetClick(w, h) + return nil + } + if tk.node.WidgetType == widget.Dropdown { + log.Info("SENDING CLICK TO Dropdown") + tk.doWidgetClick(w, h) return nil } found = true } + + mx, my := g.MousePosition() for _, tk := range findByXY(mx, my) { if tk.node.WidgetType == widget.Window { tk.dragW = mx - tk.gocuiSize.w0 diff --git a/eventMouseClick.go b/eventMouseClick.go index bfff2d4..aa8be6e 100644 --- a/eventMouseClick.go +++ b/eventMouseClick.go @@ -30,16 +30,18 @@ func (tk *guiWidget) doWidgetClick(w int, h int) { tk.redrawWindow(w-2, h-2) // TODO: fix these hard coded things with offsets return case widget.Group: - if tk.active { - tk.active = false - tk.placeWidgets(tk.startW, tk.startH) - tk.showWidgets() - } else { - tk.active = true - for _, child := range tk.children { - child.hideWidgets() + /* + if tk.active { + tk.active = false + tk.placeWidgets(tk.startW, tk.startH) + tk.showWidgets() + } else { + tk.active = true + for _, child := range tk.children { + child.hideWidgets() + } } - } + */ case widget.Checkbox: if tk.node.State.Checked { log.Log(WARN, "checkbox is being set to false") @@ -52,43 +54,36 @@ func (tk *guiWidget) doWidgetClick(w int, h int) { } me.myTree.SendUserEvent(tk.node) case widget.Grid: - newR := tk.realGocuiSize() - - // w,h := n.logicalSize() - // w := newR.w1 - newR.w0 - // h := newR.h1 - newR.h0 - - tk.placeGrid(newR.w0, newR.h0) - tk.showWidgets() + /* + newR := tk.realGocuiSize() + tk.placeGrid(newR.w0, newR.h0) + tk.showWidgets() + */ case widget.Box: - if tk.node.State.Direction == widget.Horizontal { - log.Log(GOCUI, "BOX IS HORIZONTAL", tk.String()) - } else { - log.Log(GOCUI, "BOX IS VERTICAL", tk.String()) - } - tk.placeWidgets(tk.startW, tk.startH) - tk.toggleTree() + /* + if tk.node.State.Direction == widget.Horizontal { + log.Log(GOCUI, "BOX IS HORIZONTAL", tk.String()) + } else { + log.Log(GOCUI, "BOX IS VERTICAL", tk.String()) + } + tk.placeWidgets(tk.startW, tk.startH) + tk.toggleTree() + */ case widget.Button: - // doUserEvent(n) me.myTree.SendFromUser(tk.node) case widget.Combobox: - log.Log(GOCUI, "do the combobox here") tk.showDropdown() - me.dropdownW = tk case widget.Dropdown: - // log.Log(GOCUI, "do the dropdown here") tk.showDropdown() - me.dropdownW = tk case widget.Stdout: - log.Log(GOCUI, "stdout widget found!") - tk.dumpWidget("stdout click") + /* + log.Log(GOCUI, "stdout widget found!") + tk.dumpWidget("stdout click") + */ case widget.Flag: - // log.Log(GOCUI, "flag widget found!") tk.dropdownClicked(w, h) - // got_ := dropdownClicked(w, h) - // log.Log(GOCUI, "flag click got", got) default: - tk.dumpWidget("blank click()") + tk.dumpWidget("undef click()") } } @@ -29,62 +29,72 @@ var me config // it got me here, but now it's time to clean it up for good // I can't get a GO plugins that use protobuf to load yet (versioning mismatch) type config struct { - baseGui *gocui.Gui // the main gocui handle - treeRoot *tree.Node // the base of the binary tree. it should have id == 0 - myTree *tree.TreeInfo // ? - ctrlDown *tree.Node // shown if you click the mouse when the ctrl key is pressed - currentWindow *guiWidget // this is the current tab or window to show - helpLabel *gocui.View // ? - showHelp bool // toggle boolean for the help menu (deprecate?) - dropdownW *guiWidget // grab the dropdown choices from this widget - FramePadW int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side - FramePadH int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side - PadW int `default:"1" dense:"0"` // pad spacing - PadH int `default:"1" dense:"0"` // pad spacing - WindowW int `default:"8" dense:"0"` // how far down to start Window or Tab headings - WindowH int `default:"-1"` // how far down to start Window or Tab headings - TabW int `default:"5" dense:"0"` // how far down to start Window or Tab headings - TabH int `default:"1" dense:"0"` // how far down to start Window or Tab headings - WindowPadW int `default:"8" dense:"0"` // additional amount of space to put between window & tab widgets - TabPadW int `default:"4" dense:"0"` // additional amount of space to put between window & tab widgets - GroupPadW int `default:"2" dense:"1"` // additional amount of space to indent on a group - BoxPadW int `default:"2" dense:"1"` // additional amount of space to indent on a box - GridPadW int `default:"2" dense:"1"` // additional amount of space to indent on a grid - RawW int `default:"1"` // the raw beginning of each window (or tab) - RawH int `default:"5"` // the raw beginning of each window (or tab) - FakeW int `default:"20"` // offset for the hidden widgets - padded bool // add space between things like buttons - bookshelf bool // do you want things arranged in the box like a bookshelf or a stack? - canvas bool // if set to true, the windows are a raw canvas - menubar bool // for windows - stretchy bool // expand things like buttons to the maximum size - margin bool // add space around the frames of windows - writeMutex sync.Mutex // writeMutex protects writes to *guiWidget (it's global right now maybe) - dtoggle bool // is a dropdown or combobox currently active? - ecount int // counts how many mouse and keyboard events have occurred - supermouse bool // prints out every widget found while you move the mouse around - depth int // used for listWidgets() debugging - globalMouseDown bool // yep, mouse is pressed - newWindowTrigger chan bool // work around hack to redraw windows a bit after NewWindow() - stdout stdout // information for the STDOUT window - showDebug bool // todo: move this into config struct + baseGui *gocui.Gui // the main gocui handle + treeRoot *tree.Node // the base of the binary tree. it should have id == 0 + myTree *tree.TreeInfo // ? + ctrlDown *tree.Node // shown if you click the mouse when the ctrl key is pressed + currentWindow *guiWidget // this is the current tab or window to show + helpLabel *gocui.View // ? + showHelp bool // toggle boolean for the help menu (deprecate?) + // dropdownW *guiWidget // grab the dropdown choices from this widget + FramePadW int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side + FramePadH int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side + PadW int `default:"1" dense:"0"` // pad spacing + PadH int `default:"1" dense:"0"` // pad spacing + WindowW int `default:"8" dense:"0"` // how far down to start Window or Tab headings + WindowH int `default:"-1"` // how far down to start Window or Tab headings + TabW int `default:"5" dense:"0"` // how far down to start Window or Tab headings + TabH int `default:"1" dense:"0"` // how far down to start Window or Tab headings + WindowPadW int `default:"8" dense:"0"` // additional amount of space to put between window & tab widgets + TabPadW int `default:"4" dense:"0"` // additional amount of space to put between window & tab widgets + GroupPadW int `default:"2" dense:"1"` // additional amount of space to indent on a group + BoxPadW int `default:"2" dense:"1"` // additional amount of space to indent on a box + GridPadW int `default:"2" dense:"1"` // additional amount of space to indent on a grid + RawW int `default:"1"` // the raw beginning of each window (or tab) + RawH int `default:"5"` // the raw beginning of each window (or tab) + FakeW int `default:"20"` // offset for the hidden widgets + padded bool // add space between things like buttons + bookshelf bool // do you want things arranged in the box like a bookshelf or a stack? + canvas bool // if set to true, the windows are a raw canvas + menubar bool // for windows + stretchy bool // expand things like buttons to the maximum size + margin bool // add space around the frames of windows + writeMutex sync.Mutex // writeMutex protects writes to *guiWidget (it's global right now maybe) + ecount int // counts how many mouse and keyboard events have occurred + supermouse bool // prints out every widget found while you move the mouse around + depth int // used for listWidgets() debugging + globalMouseDown bool // yep, mouse is pressed + newWindowTrigger chan bool // work around hack to redraw windows a bit after NewWindow() + stdout stdout // information for the STDOUT window + showDebug bool // todo: move this into config struct + dropdown dropdown // the dropdown menu } // settings for the stdout window type stdout struct { tk *guiWidget // where to show STDOUT w int // the width - h int // the width + h int // the height outputOnTop bool // is the STDOUT window on top? outputOffscreen bool // is the STDOUT window offscreen? - // offscreenW int // where to place the window offscreen - // offscreenH int // where to place the window offscreen - lastW int // the last 'w' location (used to move from offscreen to onscreen) - lastH int // the last 'h' location (used to move from offscreen to onscreen) - mouseOffsetW int // the current 'w' offset - mouseOffsetH int // the current 'h' offset - init bool // moves the window offscreen on startup - resize bool // user is resizing the window + lastW int // the last 'w' location (used to move from offscreen to onscreen) + lastH int // the last 'h' location (used to move from offscreen to onscreen) + mouseOffsetW int // the current 'w' offset + mouseOffsetH int // the current 'h' offset + init bool // moves the window offscreen on startup + resize bool // user is resizing the window +} + +// settings for the dropdown window +type dropdown struct { + tk *guiWidget // where to show STDOUT + callerTK *guiWidget // which widget called the dropdown menu + items []string // what is currently in the menu + w int // the width + h int // the height + active bool // is the dropdown menu currently in use? + init bool // moves the window offscreen on startup + // dtoggle bool // is a dropdown or combobox currently active? } // this is the gocui way |
