Add GTK application implementation

This commit is contained in:
Olli 2026-02-26 10:41:33 +01:00
commit b7c0307f6b
29 changed files with 2564 additions and 266 deletions

View file

@ -0,0 +1,58 @@
package gui
import (
"github.com/diamondburned/gotk4-adwaita/pkg/adw"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
"suruatoel.xyz/mcg/data"
)
type connectionPanel struct {
*adw.Bin
hostEntry *adw.EntryRow
portSpinner *gtk.SpinButton
passwordEntry *adw.PasswordEntryRow
}
func newConnectionPanel(config Configuration) *connectionPanel {
panel := connectionPanel{}
panel.loadWidgets()
panel.loadDefaultValues(config)
panel.connectSignals()
return &panel
}
func (p *connectionPanel) loadWidgets() {
builder := gtk.NewBuilderFromString(data.ConnectionPanelXML)
p.Bin = builder.GetObject("McgConnectionPanel").Cast().(*adw.Bin)
p.hostEntry = builder.GetObject("host_row").Cast().(*adw.EntryRow)
p.portSpinner = builder.GetObject("port_spinner").Cast().(*gtk.SpinButton)
p.passwordEntry = builder.GetObject("password_row").Cast().(*adw.PasswordEntryRow)
}
func (p *connectionPanel) connectSignals() {
p.hostEntry.ConnectApply(p.callback)
p.portSpinner.ConnectValueChanged(p.callback)
p.passwordEntry.ConnectApply(p.callback)
}
func (p *connectionPanel) loadDefaultValues(config Configuration) {
p.hostEntry.SetText(config.Host)
p.portSpinner.SetValue(float64(config.Port))
p.passwordEntry.SetText(config.Password)
}
func (p *connectionPanel) UpdateConfig(config *Configuration) {
config.Host = p.hostEntry.Text()
config.Port = uint64(p.portSpinner.Value())
config.Password = p.passwordEntry.Text()
}
func (p *connectionPanel) callback() {
}
func (p *connectionPanel) ConnectionDetails() (string, int, string) {
return p.hostEntry.Text(), p.portSpinner.ValueAsInt(), p.passwordEntry.Text()
}