1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-12-23 20:56:42 +00:00
cchat-gtk/internal/ui/header.go

74 lines
1.3 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"
"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-06 00:47:28 +00:00
left *gtk.Box // TODO
right *headerRight
2020-05-26 06:51:06 +00:00
}
func newHeader() *header {
2020-06-06 00:47:28 +00:00
left, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
left.SetSizeRequest(LeftWidth, -1)
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+" "),
)
}
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
}