1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-11-01 03:54:16 +00:00
cchat-gtk/internal/ui/service/header.go

71 lines
1.6 KiB
Go
Raw Normal View History

2020-06-07 04:27:28 +00:00
package service
import (
"github.com/diamondburned/cchat"
2020-06-07 07:06:13 +00:00
"github.com/diamondburned/cchat-gtk/internal/ui/primitives"
2020-06-07 04:27:28 +00:00
"github.com/diamondburned/cchat-gtk/internal/ui/rich"
"github.com/diamondburned/imgutil"
"github.com/gotk3/gotk3/gtk"
)
const IconSize = 32
type header struct {
2020-06-20 06:19:25 +00:00
*gtk.ToggleButton // no rich text here but it's left aligned
box *gtk.Box
label *rich.Label
icon *rich.Icon
Add *gtk.Button
2020-06-07 04:27:28 +00:00
Menu *gtk.Menu
}
func newHeader(svc cchat.Service) *header {
2020-06-20 06:19:25 +00:00
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()
2020-06-07 04:27:28 +00:00
add, _ := gtk.ButtonNewFromIconName("list-add-symbolic", gtk.ICON_SIZE_BUTTON)
add.SetRelief(gtk.RELIEF_NONE)
add.SetSizeRequest(IconSize, IconSize)
2020-06-20 06:19:25 +00:00
add.SetHAlign(gtk.ALIGN_END)
2020-06-07 04:27:28 +00:00
add.Show()
2020-06-20 06:19:25 +00:00
// Do jank stuff to overlay the add button on top of our button.
overlay, _ := gtk.OverlayNew()
overlay.Add(box)
overlay.AddOverlay(add)
overlay.Show()
2020-06-07 04:27:28 +00:00
2020-06-20 06:19:25 +00:00
reveal, _ := gtk.ToggleButtonNew()
reveal.Add(overlay)
reveal.SetRelief(gtk.RELIEF_NONE)
reveal.SetMode(true)
reveal.Show()
2020-06-07 04:27:28 +00:00
// Spawn the menu on right click.
2020-06-07 07:06:13 +00:00
menu, _ := gtk.MenuNew()
primitives.BindMenu(reveal, menu)
2020-06-07 04:27:28 +00:00
2020-06-20 06:19:25 +00:00
return &header{reveal, box, l, i, add, menu}
}
func (h *header) GetText() string {
return h.label.GetText()
2020-06-07 04:27:28 +00:00
}