From 06f64e7a9703d0555671e5e04f972252a25f4f0f Mon Sep 17 00:00:00 2001 From: "diamondburned (Forefront)" Date: Fri, 19 Jun 2020 23:19:25 -0700 Subject: [PATCH] Improved add button design --- internal/ui/service/header.go | 57 +++++++++++++++++++++++----------- internal/ui/service/service.go | 10 +++--- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/internal/ui/service/header.go b/internal/ui/service/header.go index 5ed03b9..8aab916 100644 --- a/internal/ui/service/header.go +++ b/internal/ui/service/header.go @@ -11,39 +11,60 @@ import ( const IconSize = 32 type header struct { - *gtk.Box - reveal *rich.ToggleButtonImage // no rich text here but it's left aligned - add *gtk.Button + *gtk.ToggleButton // no rich text here but it's left aligned + + box *gtk.Box + label *rich.Label + icon *rich.Icon + Add *gtk.Button Menu *gtk.Menu } func newHeader(svc cchat.Service) *header { - reveal := rich.NewToggleButtonImage(svc.Name()) - reveal.Box.SetHAlign(gtk.ALIGN_START) - reveal.Image.AddProcessors(imgutil.Round(true)) - reveal.Image.SetPlaceholderIcon("folder-remote-symbolic", IconSize) - reveal.SetRelief(gtk.RELIEF_NONE) - reveal.SetMode(true) - reveal.Show() + i := rich.NewIcon(0) + i.AddProcessors(imgutil.Round(true)) + i.SetPlaceholderIcon("folder-remote-symbolic", IconSize) + i.Show() + + if iconer, ok := svc.(cchat.Icon); ok { + 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.SetRelief(gtk.RELIEF_NONE) add.SetSizeRequest(IconSize, IconSize) + add.SetHAlign(gtk.ALIGN_END) add.Show() - box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) - box.PackStart(reveal, true, true, 0) - box.PackStart(add, false, false, 0) - box.Show() + // Do jank stuff to overlay the add button on top of our button. + overlay, _ := gtk.OverlayNew() + overlay.Add(box) + overlay.AddOverlay(add) + overlay.Show() - if iconer, ok := svc.(cchat.Icon); ok { - reveal.Image.AsyncSetIconer(iconer, "Error getting session logo") - } + reveal, _ := gtk.ToggleButtonNew() + reveal.Add(overlay) + reveal.SetRelief(gtk.RELIEF_NONE) + reveal.SetMode(true) + reveal.Show() // Spawn the menu on right click. menu, _ := gtk.MenuNew() 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() } diff --git a/internal/ui/service/service.go b/internal/ui/service/service.go index ed20b0b..43af443 100644 --- a/internal/ui/service/service.go +++ b/internal/ui/service/service.go @@ -87,7 +87,7 @@ func NewContainer(svc cchat.Service, ctrl Controller) *Container { chrev.Show() header := newHeader(svc) - header.reveal.SetActive(chrev.GetRevealChild()) + header.SetActive(chrev.GetRevealChild()) box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0) box.Show() @@ -106,14 +106,14 @@ func NewContainer(svc cchat.Service, ctrl Controller) *Container { } // On click, toggle reveal. - header.reveal.Connect("clicked", func() { + header.Connect("clicked", func() { revealed := !chrev.GetRevealChild() chrev.SetRevealChild(revealed) - header.reveal.SetActive(revealed) + header.SetActive(revealed) }) // On click, show the auth dialog. - header.add.Connect("clicked", func() { + header.Add.Connect("clicked", func() { ctrl.AuthenticateSession(container, svc) }) @@ -231,5 +231,5 @@ func (c *Container) SaveAllSessions() { } func (c *Container) Breadcrumb() breadcrumb.Breadcrumb { - return breadcrumb.Try(nil, c.header.reveal.GetText()) + return breadcrumb.Try(nil, c.header.GetText()) }