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

48 lines
1.2 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/primitives/buttonoverlay"
2020-06-07 04:27:28 +00:00
"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 {
*rich.ToggleButtonImage
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 {
b := rich.NewToggleButtonImage(svc.Name())
b.Image.AddProcessors(imgutil.Round(true))
b.Image.SetPlaceholderIcon("folder-remote-symbolic", IconSize)
b.SetRelief(gtk.RELIEF_NONE)
b.SetMode(true)
b.Show()
2020-06-20 06:19:25 +00:00
if iconer, ok := svc.(cchat.Icon); ok {
b.Image.AsyncSetIconer(iconer, "Error getting session logo")
2020-06-20 06:19:25 +00:00
}
2020-06-07 04:27:28 +00:00
add, _ := gtk.ButtonNewFromIconName("list-add-symbolic", gtk.ICON_SIZE_BUTTON)
add.Show()
// Add the button overlay into the main button.
buttonoverlay.Take(b, add, IconSize)
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(b)
2020-06-29 01:38:09 +00:00
if configurator, ok := svc.(config.Configurator); ok {
menu.AddItems(config.MenuItem(configurator))
}
2020-06-07 04:27:28 +00:00
return &header{b, add, menu}
2020-06-07 04:27:28 +00:00
}