package main import ( "image/color" "log" "gioui.org/io/system" "gioui.org/layout" "gioui.org/text" "gioui.org/widget" "gioui.org/widget/material" ) func (l *Limox) draw(e system.FrameEvent) { switch l.State { case Connected: l.rosterView(e) default: l.mainView(e) } } func (l *Limox) rosterView(e system.FrameEvent) { gtx := layout.NewContext(&l.Operations, e) flex := layout.Flex{ Axis: layout.Vertical, Spacing: layout.SpaceStart, } widgets := make([]layout.Widget, 0) for _, v := range l.Roster { widgets = append(widgets, func(gtx layout.Context) layout.Dimensions { jid := material.H6(l.Theme, v.Jid) return jid.Layout(gtx) }) } flex.Layout(gtx, layout.Rigid( func(gtx layout.Context) layout.Dimensions { wl := widget.List{ List: layout.List{ Axis: layout.Vertical, }, } ml := material.List(l.Theme, wl) return list.Layout(gtx, len(widgets), func(gtx layout.Context, i int) layout.Dimensions { return layout.UniformInset(unit.Dp(16)).Layout(gtx, widgets[i]) }) }, ), // l := material.List(th, list).Layout(gtx, len(widgets), func(gtx C, i int) D { // return layout.UniformInset(unit.Dp(16)).Layout(gtx, widgets[i]) // } layout.Rigid( func(gtx layout.Context) layout.Dimensions { btn := material.Button(l.Theme, &l.DisconnectButton, "Disconnect") return btn.Layout(gtx) }, ), ) e.Frame(gtx.Ops) } func (l *Limox) mainView(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.ConnectButton, 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.Printf("Unknown Limox state '%d'\n", l.State) } return label }