Skip to content

Commit

Permalink
feat: simplify BackButton
Browse files Browse the repository at this point in the history
  • Loading branch information
tfuxu authored and diamondburned committed Aug 27, 2024
1 parent 3904703 commit c1be799
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
21 changes: 6 additions & 15 deletions internal/window/backbutton/backbutton.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,20 @@ const BackButtonIcon = "sidebar-show-symbolic"
// BackButton is a button that toggles whether or not the fold's sidebar
// should be revealed.
type BackButton struct {
*gtk.Revealer
Button *gtk.ToggleButton
*gtk.ToggleButton
}

// New creates a new fold reveal button. The button is hidden by default until a
// sidebar is connected to it.
func New() *BackButton {
button := gtk.NewToggleButton()
button.SetIconName(BackButtonIcon)
button.SetSensitive(false)
button.SetVisible(false)
button.SetHAlign(gtk.AlignCenter)
button.SetVAlign(gtk.AlignCenter)

revealer := gtk.NewRevealer()
revealer.AddCSSClass("adaptive-sidebar-reveal-button")
revealer.SetTransitionType(gtk.RevealerTransitionTypeCrossfade)
revealer.SetChild(button)
revealer.SetRevealChild(false)

return &BackButton{
Revealer: revealer,
Button: button,
ToggleButton: button,
}
}

Expand All @@ -45,18 +37,17 @@ func (b *BackButton) SetIconName(icon string) {
// sidebar.
func (b *BackButton) ConnectSplitView(view *adw.OverlaySplitView) {
view.NotifyProperty("show-sidebar", func() {
b.Button.SetActive(view.ShowSidebar())
b.SetActive(view.ShowSidebar())
})

view.NotifyProperty("collapsed", func() {
collapsed := view.Collapsed()
b.SetRevealChild(collapsed)
b.Button.SetSensitive(collapsed)
b.Button.SetVisible(collapsed)
})

// Specifically bind to "clicked" rather than notifying on "active" to
// prevent infinite recursion.
b.Button.ConnectClicked(func() {
view.SetShowSidebar(b.Button.Active())
view.SetShowSidebar(b.Active())
})
}
8 changes: 0 additions & 8 deletions internal/window/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ var chatPageCSS = cssutil.Applier("window-chatpage", `
border-radius: 0;
box-shadow: none;
}
.right-header .adaptive-sidebar-reveal-button {
margin: 0;
}
.right-header .adaptive-sidebar-reveal-button button {
margin-left: 8px;
margin-right: 4px;
}
.right-header-label {
font-weight: bold;
}
Expand Down Expand Up @@ -115,7 +108,6 @@ func NewChatPage(ctx context.Context, w *Window) *ChatPage {
p.rightTitle.SetHExpand(true)

back := backbutton.New()
back.SetTransitionType(gtk.RevealerTransitionTypeSlideRight)

newTabButton := gtk.NewButtonFromIconName("list-add-symbolic")
newTabButton.SetTooltipText("Open a New Tab")
Expand Down

0 comments on commit c1be799

Please sign in to comment.