package ui import "gioui.org/unit" // Region defines a screen area in device-independent pixels (Dp). type Region struct { X, Y unit.Dp W, H unit.Dp } // Element is the base interface for all UI elements. type Element interface { Region() Region Visible() bool } // TextAlign specifies horizontal text alignment. type TextAlign int const ( AlignStart TextAlign = iota AlignCenter AlignEnd ) // Label displays static text. type Label struct { id string region Region visible bool Text string Align TextAlign FontSize unit.Sp // 0 = theme default Color Color // 0 = theme default Bold bool } func (l Label) Region() Region { return l.region } func (l Label) Visible() bool { return l.visible } func (l Label) ID() string { return l.id } // TextField accepts text input or displays multiline text. type TextField struct { id string region Region visible bool Value string Placeholder string Focused bool Multiline bool ScrollOffset unit.Dp } func (tf TextField) Region() Region { return tf.region } func (tf TextField) Visible() bool { return tf.visible } func (tf TextField) ID() string { return tf.id } // ListView displays a scrollable list of items. type ListView struct { id string region Region visible bool Items []ListItem ScrollOffset int Selected int } func (lv ListView) Region() Region { return lv.region } func (lv ListView) Visible() bool { return lv.visible } func (lv ListView) ID() string { return lv.id } // ListItem is a single entry in a ListView. type ListItem struct { Text string Subtext string Selected bool } // Color is an RGBA color. type Color struct { R, G, B, A uint8 } // Theme holds styling defaults for the UI. type Theme struct { FontSize unit.Sp } // NewLabel creates a visible Label element. func NewLabel(text string, fontSize unit.Sp, region Region) Label { return Label{ region: region, visible: true, Text: text, FontSize: fontSize, } } // NewListView creates a visible ListView element. func NewListView(region Region, items []ListItem) ListView { return ListView{ region: region, visible: true, Items: items, } }