diff options
author | xengineering <me@xengineering.eu> | 2023-04-16 22:02:47 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-04-18 21:01:14 +0200 |
commit | 4d4d3f00ddee089de5b29bfe322022173c239aff (patch) | |
tree | 8c9c4862eb435c7c3d9683b6d49e821dd1caa195 /gui.go | |
parent | bcbeb1b8e07049098459b7512d59dbdea7752289 (diff) | |
download | limox-4d4d3f00ddee089de5b29bfe322022173c239aff.tar limox-4d4d3f00ddee089de5b29bfe322022173c239aff.tar.zst limox-4d4d3f00ddee089de5b29bfe322022173c239aff.zip |
Split Go code into multiple files
Diffstat (limited to 'gui.go')
-rw-r--r-- | gui.go | 76 |
1 files changed, 76 insertions, 0 deletions
@@ -0,0 +1,76 @@ +package main + +import ( + "image/color" + "log" + + "gioui.org/io/system" + "gioui.org/layout" + "gioui.org/text" + "gioui.org/widget/material" +) + +type GuiEvent uint8 + +const ( + Disconnect GuiEvent = iota +) + +func (l *Limox) draw(e system.FrameEvent) { + gtx := layout.NewContext(&l.Operations, e) + + flex := layout.Flex{ + Axis: layout.Vertical, + Spacing: layout.SpaceBetween, + } + + flex.Layout(gtx, + layout.Rigid( + func(gtx layout.Context) layout.Dimensions { + h2 := material.H2(l.Theme, "LimoX") + h2.Color = color.NRGBA{R: 20, G: 20, B: 20, A: 255} + h2.Alignment = text.Middle + return h2.Layout(gtx) + }, + ), + layout.Rigid( + func(gtx layout.Context) layout.Dimensions { + jid := material.Editor(l.Theme, &l.JidEditor, "user@example.com") + jid.Editor.Alignment = text.Middle + return jid.Layout(gtx) + }, + ), + layout.Rigid( + func(gtx layout.Context) layout.Dimensions { + pwd := material.Editor(l.Theme, &l.PwdEditor, "mySafePassword") + pwd.Editor.Alignment = text.Middle + pwd.Editor.Mask = '*' + return pwd.Layout(gtx) + }, + ), + layout.Rigid( + func(gtx layout.Context) layout.Dimensions { + btn := material.Button(l.Theme, &l.MainButton, + l.buttonLabel()) + return btn.Layout(gtx) + }, + ), + ) + + e.Frame(gtx.Ops) +} + +func (l *Limox) buttonLabel() string { + var label string + switch l.State { + case Disconnected: + label = "Connect" + case Connecting: + label = "Abort" + case Connected: + label = "Disconnect" + default: + log.Fatalf("Unknown Limox state '%d'\n", l.State) + } + return label +} |