diff options
| author | Jeff Carr <[email protected]> | 2022-11-09 08:38:50 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2022-11-09 08:38:50 -0600 |
| commit | ed382bec55be25039e4dcf020d1512139855c9bb (patch) | |
| tree | fb3a671fd07c03a75cedb8d56b2241108cd792ff /toolkit/gocui/button.go | |
| parent | b410d0fd083ee89eed410cda2123a22cddcd3f44 (diff) | |
cleanup of the example commands. more plugin workv0.4.6
add a button in two plugins at the same time!
added a button in andlabs/ui & gocui
attempt a common widget struct between wit/gui & the plugins
start handling missing plugins
rename Makefile command examples
remote examples used for testing
filename improvements
golang src code uses lowercase and _ in filenames
fix crash when button click function == nil
fix wrong name 'gocli' -> 'gocui'
keep fighting with goreadme generated README.md
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/gocui/button.go')
| -rw-r--r-- | toolkit/gocui/button.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/toolkit/gocui/button.go b/toolkit/gocui/button.go new file mode 100644 index 0000000..8fb6e05 --- /dev/null +++ b/toolkit/gocui/button.go @@ -0,0 +1,48 @@ +package main + +import ( + "errors" + "fmt" + "log" + "strings" + + "github.com/awesome-gocui/gocui" +) + +func (w *Widget) AddButton() { +// func (g greeting) AddButton() { + log.Println("gui.gocui.AddButton()", w.Name) + addButton2(w.Name, w.Event) +} + +func addButton2(name string, e func(*Widget) *Widget) { + addButton(name) +} + +func addButton(name string) error { + t := len(name) + v, err := baseGui.SetView(name, currentX, currentY, currentX+t+3, currentY+2, 0) + if err == nil { + return err + } + if !errors.Is(err, gocui.ErrUnknownView) { + return err + } + + v.Wrap = true + fmt.Fprintln(v, " " + name) + fmt.Fprintln(v, strings.Repeat("foo\n", 2)) + + if _, err := baseGui.SetCurrentView(name); err != nil { + return err + } + + views = append(views, name) + curView = len(views) - 1 + idxView += 1 + currentY += 3 + if (groupSize < len(views)) { + groupSize = len(views) + } + return nil +} |
