diff --git a/core/editor.go b/core/editor.go index b5f234bc..f3b627c9 100644 --- a/core/editor.go +++ b/core/editor.go @@ -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) } //---------- diff --git a/ui/mainmenu.go b/ui/mainmenu.go index 19793cf3..549637c8 100644 --- a/ui/mainmenu.go +++ b/ui/mainmenu.go @@ -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 } @@ -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) diff --git a/ui/toolbar.go b/ui/toolbar.go index d039443c..85f7651d 100644 --- a/ui/toolbar.go +++ b/ui/toolbar.go @@ -3,6 +3,7 @@ package ui import ( "image" + "github.com/jmigpin/editor/util/drawutil/drawer4" "github.com/jmigpin/editor/util/uiutil/event" ) @@ -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 } diff --git a/util/drawutil/drawer4/drawer.go b/util/drawutil/drawer4/drawer.go index d1ed454c..3c6aa875 100644 --- a/util/drawutil/drawer4/drawer.go +++ b/util/drawutil/drawer4/drawer.go @@ -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 { @@ -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