Skip to content

Commit 19a268b

Browse files
committed
ui: add back and forward buttons to the toolbar
Going back through opened functions needed Alt+Left or the menu, with nothing on screen to show that history existed. Arrows left of the search box, as in VS Code, step through it and dim when there is nothing that way.
1 parent 002e451 commit 19a268b

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎fileui.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ type FileUI struct {
6767
// Window chrome.
6868
AppMenu gui.Menu
6969
GoToButton widget.Clickable
70+
BackButton widget.Clickable
71+
ForwardButton widget.Clickable
7072
QuickOpen gui.QuickOpen[disasm.Func]
7173
EmptyOpen widget.Clickable
7274
SettingsButton widget.Clickable
@@ -518,6 +520,12 @@ func (ui *FileUI) handleActions(gtx layout.Context) {
518520
for ui.SettingsButton.Clicked(gtx) {
519521
ui.openSettings()
520522
}
523+
for ui.BackButton.Clicked(gtx) {
524+
ui.navigateBack()
525+
}
526+
for ui.ForwardButton.Clicked(gtx) {
527+
ui.navigateForward()
528+
}
521529
for ui.GoToButton.Clicked(gtx) {
522530
ui.QuickOpen.Show(gtx)
523531
}

‎fileui_chrome.go‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,16 @@ func (ui *FileUI) layoutToolbarRow(gtx layout.Context) layout.Dimensions {
178178
return ui.AppMenu.Layout(gtx, th, ui.appMenuItems(), ui.layoutBrand)
179179
}),
180180
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
181-
return layout.Inset{Left: 10, Right: 12}.Layout(gtx, ui.layoutPath)
181+
// Fill the space, so the arrows sit by the search.
182+
dims := layout.Inset{Left: 10, Right: 12}.Layout(gtx, ui.layoutPath)
183+
dims.Size.X = gtx.Constraints.Max.X
184+
return dims
185+
}),
186+
layout.Rigid(gui.IconButton{Theme: th, Clickable: &ui.BackButton, Icon: BackIcon,
187+
Description: "Back", Disabled: !ui.Navigation.CanBack()}.Layout),
188+
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
189+
return layout.Inset{Left: 2, Right: 8}.Layout(gtx, gui.IconButton{Theme: th, Clickable: &ui.ForwardButton, Icon: ForwardIcon,
190+
Description: "Forward", Disabled: !ui.Navigation.CanForward()}.Layout)
182191
}),
183192
)
184193
}),

‎icons.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ var (
2121
HistoryIcon = mustIcon(icons.ActionHistory)
2222
WatchIcon = mustIcon(icons.ActionVisibility)
2323
MarksIcon = mustIcon(icons.ActionAssessment)
24+
BackIcon = mustIcon(icons.NavigationArrowBack)
25+
ForwardIcon = mustIcon(icons.NavigationArrowForward)
2426
)

‎internal/gui/controls.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,17 @@ type IconButton struct {
5050
Clickable *widget.Clickable
5151
Icon *widget.Icon
5252
Description string
53+
// Disabled dims the icon and ignores clicks.
54+
Disabled bool
5355
}
5456

5557
func (b IconButton) Layout(gtx layout.Context) layout.Dimensions {
5658
c := b.Theme.Colors
59+
fg := c.MutedText
60+
if b.Disabled {
61+
gtx = gtx.Disabled()
62+
fg.A /= 3
63+
}
5764
return b.Clickable.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
5865
semantic.Button.Add(gtx.Ops)
5966
semantic.DescriptionOp(b.Description).Add(gtx.Ops)
@@ -64,7 +71,7 @@ func (b IconButton) Layout(gtx layout.Context) layout.Dimensions {
6471
return frame(gtx, bg, bg, layout.UniformInset(5), func(gtx layout.Context) layout.Dimensions {
6572
size := gtx.Metric.Dp(16)
6673
gtx.Constraints = layout.Exact(image.Pt(size, size))
67-
return b.Icon.Layout(gtx, c.MutedText)
74+
return b.Icon.Layout(gtx, fg)
6875
})
6976
})
7077
}

0 commit comments

Comments
 (0)