1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-10-31 19:44:23 +00:00
cchat-gtk/internal/ui/service/session/session.go

57 lines
1.2 KiB
Go
Raw Normal View History

2020-05-26 06:51:06 +00:00
package session
import (
"github.com/diamondburned/cchat"
"github.com/diamondburned/cchat-gtk/internal/log"
2020-05-28 19:26:55 +00:00
"github.com/diamondburned/cchat-gtk/internal/ui/primitives"
2020-05-26 06:51:06 +00:00
"github.com/diamondburned/cchat-gtk/internal/ui/service/session/server"
"github.com/gotk3/gotk3/gtk"
"github.com/pkg/errors"
)
type Row struct {
*gtk.Box
2020-05-28 19:26:55 +00:00
Button *gtk.ToggleButton
2020-05-26 06:51:06 +00:00
Session cchat.Session
Servers *server.Children
}
2020-05-28 19:26:55 +00:00
func New(ses cchat.Session, rowctrl server.RowController) *Row {
2020-05-26 06:51:06 +00:00
n, err := ses.Name()
if err != nil {
log.Error(errors.Wrap(err, "Failed to get the username"))
n = "no name"
}
2020-05-28 19:26:55 +00:00
button, _ := gtk.ToggleButtonNewWithLabel(n)
primitives.BinLeftAlignLabel(button)
2020-05-26 06:51:06 +00:00
button.SetRelief(gtk.RELIEF_NONE)
2020-05-28 19:26:55 +00:00
button.Show()
servers := server.NewChildren(ses, rowctrl)
box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
box.Show()
box.SetMarginStart(server.ChildrenMargin)
box.PackStart(button, false, false, 0)
box.PackStart(servers, false, false, 0)
primitives.AddClass(box, "session")
2020-05-26 06:51:06 +00:00
2020-05-28 19:26:55 +00:00
// On click, toggle reveal.
button.Connect("clicked", func() {
revealed := !servers.GetRevealChild()
servers.SetRevealChild(revealed)
button.SetActive(revealed)
})
2020-05-26 06:51:06 +00:00
return &Row{
Box: box,
Button: button,
Session: ses,
2020-05-28 19:26:55 +00:00
Servers: servers,
2020-05-26 06:51:06 +00:00
}
}