2020-06-07 04:27:28 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/diamondburned/cchat"
|
2020-06-30 07:20:13 +00:00
|
|
|
"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 {
|
2020-06-30 07:20:13 +00:00
|
|
|
*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 {
|
2020-06-30 07:20:13 +00:00
|
|
|
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 {
|
2020-06-30 07:20:13 +00:00
|
|
|
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()
|
|
|
|
|
2020-06-30 07:20:13 +00:00
|
|
|
// 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.
|
2020-06-30 07:20:13 +00:00
|
|
|
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
|
|
|
|
2020-06-30 07:20:13 +00:00
|
|
|
return &header{b, add, menu}
|
2020-06-07 04:27:28 +00:00
|
|
|
}
|