Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
diamondburned
GitHub Repository: diamondburned/gtkcord4
Path: blob/main/internal/window/backbutton/backbutton.go
366 views
1
package backbutton
2
3
import (
4
"github.com/diamondburned/gotk4-adwaita/pkg/adw"
5
"github.com/diamondburned/gotk4/pkg/gtk/v4"
6
)
7
8
// BackButtonIcon is the default icon name for a fold reveal button.
9
const BackButtonIcon = "sidebar-show-symbolic"
10
11
// BackButton is a button that toggles whether or not the fold's sidebar
12
// should be revealed.
13
type BackButton struct {
14
*gtk.ToggleButton
15
}
16
17
// New creates a new fold reveal button. The button is hidden by default until a
18
// sidebar is connected to it.
19
func New() *BackButton {
20
button := gtk.NewToggleButton()
21
button.SetIconName(BackButtonIcon)
22
button.SetVisible(false)
23
button.SetHAlign(gtk.AlignCenter)
24
button.SetVAlign(gtk.AlignCenter)
25
26
return &BackButton{
27
ToggleButton: button,
28
}
29
}
30
31
// SetIconName sets the reveal button's icon name.
32
func (b *BackButton) SetIconName(icon string) {
33
b.Button.SetIconName(icon)
34
}
35
36
// ConnectFold connects the current sidebar reveal button to the given
37
// sidebar.
38
func (b *BackButton) ConnectSplitView(view *adw.OverlaySplitView) {
39
view.NotifyProperty("show-sidebar", func() {
40
b.SetActive(view.ShowSidebar())
41
})
42
43
view.NotifyProperty("collapsed", func() {
44
collapsed := view.Collapsed()
45
b.Button.SetVisible(collapsed)
46
})
47
48
// Specifically bind to "clicked" rather than notifying on "active" to
49
// prevent infinite recursion.
50
b.Button.ConnectClicked(func() {
51
view.SetShowSidebar(b.Active())
52
})
53
}
54
55