Path: blob/main/internal/window/backbutton/backbutton.go
366 views
package backbutton12import (3"github.com/diamondburned/gotk4-adwaita/pkg/adw"4"github.com/diamondburned/gotk4/pkg/gtk/v4"5)67// BackButtonIcon is the default icon name for a fold reveal button.8const BackButtonIcon = "sidebar-show-symbolic"910// BackButton is a button that toggles whether or not the fold's sidebar11// should be revealed.12type BackButton struct {13*gtk.ToggleButton14}1516// New creates a new fold reveal button. The button is hidden by default until a17// sidebar is connected to it.18func New() *BackButton {19button := gtk.NewToggleButton()20button.SetIconName(BackButtonIcon)21button.SetVisible(false)22button.SetHAlign(gtk.AlignCenter)23button.SetVAlign(gtk.AlignCenter)2425return &BackButton{26ToggleButton: button,27}28}2930// SetIconName sets the reveal button's icon name.31func (b *BackButton) SetIconName(icon string) {32b.Button.SetIconName(icon)33}3435// ConnectFold connects the current sidebar reveal button to the given36// sidebar.37func (b *BackButton) ConnectSplitView(view *adw.OverlaySplitView) {38view.NotifyProperty("show-sidebar", func() {39b.SetActive(view.ShowSidebar())40})4142view.NotifyProperty("collapsed", func() {43collapsed := view.Collapsed()44b.Button.SetVisible(collapsed)45})4647// Specifically bind to "clicked" rather than notifying on "active" to48// prevent infinite recursion.49b.Button.ConnectClicked(func() {50view.SetShowSidebar(b.Active())51})52}535455