Skip to content

Commit

Permalink
ui/mainmenu: update cmds list; simplify mainmenu content to show sort…
Browse files Browse the repository at this point in the history
…ed list. Make it scrollable.

util/drawutil/drawer4: add option to fix call to early exit when measuring content.
  • Loading branch information
jmigpin committed Jun 11, 2022
1 parent 3c5f56a commit 4d2524a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 22 deletions.
57 changes: 41 additions & 16 deletions core/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,22 +382,47 @@ func (ed *Editor) setupRootMenuToolbar() {
ed.updateERowsToolbarsHomeVars()
})

tb.SetStrClearHistory(`CopyFilePosition
ColorTheme
CtxutilCallsState
FontRunes | FontTheme
GoDebug | GoRename
GotoLine
NewColumn
NewFile | SaveAllFiles
NewRow | ReopenRow | MaximizeRow
ListDir | ListDir -hidden | ListDir -sub
ListSessions | OpenSession | DeleteSession
LsprotoRename | LsprotoCloseAll
OpenFilemanager | OpenTerminal
Reload | ReloadAll | ReloadAllFiles
RuneCodes
Exit | Stop | Clear | Version`)
w := [][]string{
[]string{"ColorTheme"},
[]string{"CopyFilePosition"},
[]string{"CtxutilCallsState"},
[]string{"FontRunes", "FontTheme"},
[]string{"GoDebug", "GoRename"},
[]string{"GotoLine"},
[]string{"NewColumn"},
[]string{"NewFile", "SaveAllFiles", "Save"},
[]string{"NewRow", "ReopenRow", "MaximizeRow"},
[]string{"ListDir", "ListDir -hidden", "ListDir -sub"},
[]string{"ListSessions", "OpenSession", "DeleteSession", "SaveSession"},
[]string{"LsprotoRename", "LsprotoCloseAll"},
[]string{"LsprotoCallers", "LsprotoCallees"},
[]string{"OpenFilemanager", "OpenTerminal"},
[]string{"Reload", "ReloadAll", "ReloadAllFiles"},
[]string{"RuneCodes"},
}
last := []string{"Exit", "Version", "Stop", "Clear"}

//// method 1: sort categorized
//sort.Slice(w, func(a, b int) bool {
// v1, v2 := w[a], w[b]
// return v1[0] < v2[0]
//})
//w2 := []string{}
//for _, a := range w {
// w2 = append(w2, strings.Join(a, " | "))
//}
//s1 := strings.Join(w2, "\n")

// method 2: simple sorted list
w2 := []string{}
for _, a := range w {
w2 = append(w2, a...)
}
sort.Slice(w2, func(a, b int) bool { return w2[a] < w2[b] })
w2 = append(w2, "\n"+strings.Join(last, " | "))
s1 := strings.Join(w2, "\n")

tb.SetStrClearHistory(s1)
}

//----------
Expand Down
11 changes: 8 additions & 3 deletions ui/mainmenu.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package ui

import (
"github.com/jmigpin/editor/util/drawutil/drawer4"
"github.com/jmigpin/editor/util/uiutil/widget"
)

type MainMenuButton struct {
*widget.FloatBoxButton
sa *widget.ScrollArea
Toolbar *Toolbar
}

Expand All @@ -25,9 +27,12 @@ func NewMainMenuButton(root *Root) *MainMenuButton {

// float content
mmb.Toolbar = NewToolbar(root.UI)
pad := widget.NewPad(root.UI, mmb.Toolbar)
pad.SetAll(10)
border := widget.NewBorder(root.UI, pad)
if d, ok := mmb.Toolbar.Drawer.(*drawer4.Drawer); ok {
d.Opt.EarlyExitMeasure = false // full measure to avoid flicker (want the menu size stable)
}
mmb.sa = widget.NewScrollArea(root.UI, mmb.Toolbar, false, true)
mmb.sa.LeftScroll = ScrollBarLeft
border := widget.NewBorder(root.UI, mmb.sa)
border.SetAll(1)
n1 := WrapInBottomShadowOrNone(root.UI, border)
content.Append(n1)
Expand Down
4 changes: 4 additions & 0 deletions ui/toolbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ui
import (
"image"

"github.com/jmigpin/editor/util/drawutil/drawer4"
"github.com/jmigpin/editor/util/uiutil/event"
)

Expand All @@ -15,6 +16,9 @@ func NewToolbar(ui *UI) *Toolbar {
tb := &Toolbar{}
tb.TextArea = NewTextArea(ui)
tb.SetThemePaletteNamePrefix("toolbar_")
if d, ok := tb.TextArea.Drawer.(*drawer4.Drawer); ok {
d.Opt.EarlyExitMeasure = true // performance
}
return tb
}

Expand Down
7 changes: 4 additions & 3 deletions util/drawutil/drawer4/drawer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ type Drawer struct {

// external options
Opt struct {
QuickMeasure bool // just return the bounds size
RuneReader struct {
QuickMeasure bool // just return the bounds size
EarlyExitMeasure bool // allow early exit
RuneReader struct {
StartOffsetX int
}
LineWrap struct {
Expand Down Expand Up @@ -383,7 +384,7 @@ func (d *Drawer) measure2() image.Point {
// Full content measure in pixels. To be used only for small content.
func (d *Drawer) measureContent() image.Point {
d.st = State{}
iters := d.sIters(true, &d.iters.measure)
iters := d.sIters(d.Opt.EarlyExitMeasure, &d.iters.measure)
d.loopInit(iters)
d.loop()
// remove bounds min and return only the measure
Expand Down

0 comments on commit 4d2524a

Please sign in to comment.