1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2025-11-29 08:05:42 +00:00

Improved add button design

This commit is contained in:
diamondburned (Forefront) 2020-06-19 23:19:25 -07:00
parent 9df0aca1fa
commit 06f64e7a97
2 changed files with 44 additions and 23 deletions

View file

@ -11,39 +11,60 @@ import (
const IconSize = 32 const IconSize = 32
type header struct { type header struct {
*gtk.Box *gtk.ToggleButton // no rich text here but it's left aligned
reveal *rich.ToggleButtonImage // no rich text here but it's left aligned
add *gtk.Button box *gtk.Box
label *rich.Label
icon *rich.Icon
Add *gtk.Button
Menu *gtk.Menu Menu *gtk.Menu
} }
func newHeader(svc cchat.Service) *header { func newHeader(svc cchat.Service) *header {
reveal := rich.NewToggleButtonImage(svc.Name()) i := rich.NewIcon(0)
reveal.Box.SetHAlign(gtk.ALIGN_START) i.AddProcessors(imgutil.Round(true))
reveal.Image.AddProcessors(imgutil.Round(true)) i.SetPlaceholderIcon("folder-remote-symbolic", IconSize)
reveal.Image.SetPlaceholderIcon("folder-remote-symbolic", IconSize) i.Show()
reveal.SetRelief(gtk.RELIEF_NONE)
reveal.SetMode(true) if iconer, ok := svc.(cchat.Icon); ok {
reveal.Show() i.AsyncSetIconer(iconer, "Error getting session logo")
}
l := rich.NewLabel(svc.Name())
l.Show()
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
box.PackStart(i, false, false, 0)
box.PackStart(l, true, true, 5)
box.SetMarginEnd(IconSize) // spare space for the add button
box.Show()
add, _ := gtk.ButtonNewFromIconName("list-add-symbolic", gtk.ICON_SIZE_BUTTON) add, _ := gtk.ButtonNewFromIconName("list-add-symbolic", gtk.ICON_SIZE_BUTTON)
add.SetRelief(gtk.RELIEF_NONE) add.SetRelief(gtk.RELIEF_NONE)
add.SetSizeRequest(IconSize, IconSize) add.SetSizeRequest(IconSize, IconSize)
add.SetHAlign(gtk.ALIGN_END)
add.Show() add.Show()
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) // Do jank stuff to overlay the add button on top of our button.
box.PackStart(reveal, true, true, 0) overlay, _ := gtk.OverlayNew()
box.PackStart(add, false, false, 0) overlay.Add(box)
box.Show() overlay.AddOverlay(add)
overlay.Show()
if iconer, ok := svc.(cchat.Icon); ok { reveal, _ := gtk.ToggleButtonNew()
reveal.Image.AsyncSetIconer(iconer, "Error getting session logo") reveal.Add(overlay)
} reveal.SetRelief(gtk.RELIEF_NONE)
reveal.SetMode(true)
reveal.Show()
// Spawn the menu on right click. // Spawn the menu on right click.
menu, _ := gtk.MenuNew() menu, _ := gtk.MenuNew()
primitives.BindMenu(reveal, menu) primitives.BindMenu(reveal, menu)
return &header{box, reveal, add, menu} return &header{reveal, box, l, i, add, menu}
}
func (h *header) GetText() string {
return h.label.GetText()
} }

View file

@ -87,7 +87,7 @@ func NewContainer(svc cchat.Service, ctrl Controller) *Container {
chrev.Show() chrev.Show()
header := newHeader(svc) header := newHeader(svc)
header.reveal.SetActive(chrev.GetRevealChild()) header.SetActive(chrev.GetRevealChild())
box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0) box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
box.Show() box.Show()
@ -106,14 +106,14 @@ func NewContainer(svc cchat.Service, ctrl Controller) *Container {
} }
// On click, toggle reveal. // On click, toggle reveal.
header.reveal.Connect("clicked", func() { header.Connect("clicked", func() {
revealed := !chrev.GetRevealChild() revealed := !chrev.GetRevealChild()
chrev.SetRevealChild(revealed) chrev.SetRevealChild(revealed)
header.reveal.SetActive(revealed) header.SetActive(revealed)
}) })
// On click, show the auth dialog. // On click, show the auth dialog.
header.add.Connect("clicked", func() { header.Add.Connect("clicked", func() {
ctrl.AuthenticateSession(container, svc) ctrl.AuthenticateSession(container, svc)
}) })
@ -231,5 +231,5 @@ func (c *Container) SaveAllSessions() {
} }
func (c *Container) Breadcrumb() breadcrumb.Breadcrumb { func (c *Container) Breadcrumb() breadcrumb.Breadcrumb {
return breadcrumb.Try(nil, c.header.reveal.GetText()) return breadcrumb.Try(nil, c.header.GetText())
} }