1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-09-28 13:08:47 +00:00
cchat-gtk/internal/ui/header.go

95 lines
1.7 KiB
Go
Raw Normal View History

2020-05-26 06:51:06 +00:00
package ui
2020-06-06 00:47:28 +00:00
import (
"html"
"strings"
2020-06-20 04:40:34 +00:00
"github.com/diamondburned/cchat-gtk/internal/ui/primitives"
2020-06-06 00:47:28 +00:00
"github.com/diamondburned/cchat-gtk/internal/ui/service/breadcrumb"
"github.com/gotk3/gotk3/gtk"
)
2020-05-26 06:51:06 +00:00
type header struct {
*gtk.Box
2020-06-20 04:40:34 +00:00
left *headerLeft // TODO
2020-06-06 00:47:28 +00:00
right *headerRight
2020-05-26 06:51:06 +00:00
}
func newHeader() *header {
2020-06-20 04:40:34 +00:00
left := newHeaderLeft()
2020-06-06 00:47:28 +00:00
left.Show()
right := newHeaderRight()
right.Show()
separator, _ := gtk.SeparatorNew(gtk.ORIENTATION_VERTICAL)
separator.Show()
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
box.PackStart(left, false, false, 0)
box.PackStart(separator, false, false, 0)
box.PackStart(right, true, true, 0)
2020-05-26 06:51:06 +00:00
box.Show()
2020-06-06 00:47:28 +00:00
2020-05-26 06:51:06 +00:00
// TODO
2020-06-06 00:47:28 +00:00
return &header{
box,
left,
right,
}
}
const BreadcrumbSlash = `<span weight="light" rise="-1024" size="x-large">/</span>`
func (h *header) SetBreadcrumb(b breadcrumb.Breadcrumb) {
for i := range b {
b[i] = html.EscapeString(b[i])
}
h.right.breadcrumb.SetMarkup(
BreadcrumbSlash + " " + strings.Join(b, " "+BreadcrumbSlash+" "),
)
}
2020-06-20 04:40:34 +00:00
type headerLeft struct {
*gtk.Box
openmenu *gtk.MenuButton
}
func newHeaderLeft() *headerLeft {
openmenu := primitives.NewMenuActionButton([][2]string{
{"Preferences", "app.preferences"},
{"Quit", "app.quit"},
})
openmenu.Show()
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
box.PackStart(openmenu, false, false, 5)
return &headerLeft{
Box: box,
openmenu: openmenu,
}
}
2020-06-06 00:47:28 +00:00
type headerRight struct {
*gtk.Box
breadcrumb *gtk.Label
}
func newHeaderRight() *headerRight {
bc, _ := gtk.LabelNew(BreadcrumbSlash)
bc.SetUseMarkup(true)
bc.SetXAlign(0.0)
bc.Show()
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
box.PackStart(bc, true, true, 14)
box.Show()
return &headerRight{
Box: box,
breadcrumb: bc,
}
2020-05-26 06:51:06 +00:00
}