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
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()
}

View File

@ -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())
}