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

74 lines
1.8 KiB
Go
Raw Normal View History

2020-06-07 04:27:28 +00:00
package service
import (
"github.com/diamondburned/cchat"
"github.com/diamondburned/cchat-gtk/internal/ui/rich"
2020-06-29 01:38:09 +00:00
"github.com/diamondburned/cchat-gtk/internal/ui/service/config"
"github.com/diamondburned/cchat-gtk/internal/ui/service/menu"
2020-06-07 04:27:28 +00:00
"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
2020-06-29 01:38:09 +00:00
Menu *menu.LazyMenu
2020-06-07 04:27:28 +00:00
}
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
2020-06-29 01:38:09 +00:00
// Construct a menu and its items.
var menu = menu.NewLazyMenu(reveal)
if configurator, ok := svc.(config.Configurator); ok {
menu.AddItems(config.MenuItem(configurator))
}
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
}