Path: blob/main/internal/sidebar/sidebutton/mention.go
366 views
package sidebutton12import (3"strconv"45"github.com/diamondburned/gotk4/pkg/gtk/v4"6"github.com/diamondburned/gotkit/gtkutil/cssutil"7)89// MentionsIndicator is a small indicator that shows the mention count.10type MentionsIndicator struct {11*gtk.Revealer12Label *gtk.Label1314count int15reveal bool16}1718var mentionCSS = cssutil.Applier("sidebar-mention", `19.sidebar-mention {20background: none;21}22.sidebar-mention.sidebar-mention-active,23.sidebar-mention.sidebar-mention-active label {24border-radius: 100px;25background-color: @theme_bg_color;26}27.sidebar-mention.sidebar-mention-active label {28color: white;29background-color: @mentioned;30min-width: 12pt;31min-height: 12pt;32padding: 0;33margin: 2px;34font-size: 8pt;35font-weight: bold;36}37`)3839// NewMentionsIndicator creates a new mention indicator.40func NewMentionsIndicator() *MentionsIndicator {41m := &MentionsIndicator{42Revealer: gtk.NewRevealer(),43Label: gtk.NewLabel(""),44reveal: true,45}4647m.SetChild(m.Label)48m.SetHAlign(gtk.AlignEnd)49m.SetVAlign(gtk.AlignEnd)50m.SetTransitionType(gtk.RevealerTransitionTypeCrossfade)51m.SetTransitionDuration(100)5253m.update()54mentionCSS(m)55return m56}5758// SetCount sets the mention count.59func (m *MentionsIndicator) SetCount(count int) {60if count == m.count {61return62}6364m.count = count65m.update()66}6768// Count returns the mention count.69func (m *MentionsIndicator) Count() int {70return m.count71}7273// SetRevealChild sets whether the indicator should be revealed.74// This lets the user hide the indicator even if there are mentions.75func (m *MentionsIndicator) SetRevealChild(reveal bool) {76m.reveal = reveal77m.update()78}7980func (m *MentionsIndicator) update() {81if m.count == 0 {82m.RemoveCSSClass("sidebar-mention-active")83m.Revealer.SetRevealChild(false)84return85}8687m.AddCSSClass("sidebar-mention-active")88m.Label.SetText(strconv.Itoa(m.count))89m.Revealer.SetRevealChild(m.reveal && m.count > 0)90}919293