mirror of
https://github.com/diamondburned/cchat-gtk.git
synced 2024-10-31 19:44:23 +00:00
Improved add button design
This commit is contained in:
parent
9df0aca1fa
commit
06f64e7a97
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue