Documentation
¶
Overview ¶
Package ui provides shared theming and drawing helpers for GoNIX GUI apps built on wlui — the small, home-grown beginnings of a widget layer. Apps draw into the same *image.RGBA a wlui.Handler paints; this package only depends on the standard image packages (no cgo, no toolkit), so it adds nothing to the closure.
Today it offers a shared colour Theme (so apps stop duplicating palettes) and a rectangle Fill. Widgets (Button, TextField, List, …) will be harvested here from the apps as they recur.
Index ¶
- Variables
- func Fill(dst *image.RGBA, r image.Rectangle, c color.Color)
- type Clipboard
- type Menu
- func (m *Menu) Bounds() image.Rectangle
- func (m *Menu) Close()
- func (m *Menu) Draw(dst *image.RGBA)
- func (m *Menu) Key(code uint32, _ wlui.Modifiers) bool
- func (m *Menu) Open(items []string, selected, x, y, minWidth int)
- func (m *Menu) PointerDown(x, y int) bool
- func (m *Menu) PointerMotion(x, y int) bool
- func (m *Menu) Visible() bool
- type TextArea
- func (t *TextArea) Blink()
- func (t *TextArea) Clear()
- func (t *TextArea) Copy()
- func (t *TextArea) Cut()
- func (t *TextArea) Draw(dst *image.RGBA, r image.Rectangle)
- func (t *TextArea) Key(code uint32, mods wlui.Modifiers) bool
- func (t *TextArea) Paste()
- func (t *TextArea) PointerDown(x, y int) bool
- func (t *TextArea) PointerDrag(x, y int)
- func (t *TextArea) PointerUp()
- func (t *TextArea) PreferredHeight(rows int) int
- func (t *TextArea) Rune(r rune)
- func (t *TextArea) SelectAll()
- func (t *TextArea) SetFocused(focused bool)
- func (t *TextArea) SetText(s string)
- func (t *TextArea) Text() string
- type TextField
- func (t *TextField) Blink()
- func (t *TextField) Clear()
- func (t *TextField) Copy()
- func (t *TextField) Cut()
- func (t *TextField) Draw(dst *image.RGBA, r image.Rectangle)
- func (t *TextField) Key(code uint32, mods wlui.Modifiers) bool
- func (t *TextField) Paste()
- func (t *TextField) PointerDown(x, y int) bool
- func (t *TextField) PointerDrag(x, y int)
- func (t *TextField) PointerUp()
- func (t *TextField) PreferredHeight() int
- func (t *TextField) Rune(r rune)
- func (t *TextField) SelectAll()
- func (t *TextField) SetFocused(focused bool)
- func (t *TextField) SetText(s string)
- func (t *TextField) Text() string
- type Theme
Constants ¶
This section is empty.
Variables ¶
var Dark = Theme{ Background: color.RGBA{0x1e, 0x1e, 0x1e, 0xff}, Foreground: color.RGBA{0xd4, 0xd4, 0xd4, 0xff}, Dim: color.RGBA{0x9a, 0x9a, 0x9a, 0xff}, BarBackground: color.RGBA{0x33, 0x33, 0x3a, 0xff}, BarForeground: color.RGBA{0xe6, 0xe6, 0xe6, 0xff}, Menu: color.RGBA{0x2a, 0x2a, 0x30, 0xff}, Accent: color.RGBA{0x0a, 0x4d, 0x8c, 0xff}, Selection: color.RGBA{0x26, 0x4f, 0x78, 0xff}, Cursor: color.RGBA{0xff, 0xff, 0xff, 0xff}, }
Dark is the default GoNIX dark theme.
Functions ¶
Types ¶
type Clipboard ¶
Clipboard is the subset of *wlui.Window a TextField needs for cut/copy/paste. A nil Clipboard disables those operations; *wlui.Window satisfies it, so apps pass their window. The interface keeps the widget decoupled from the window (and unit-testable with a fake clipboard).
type Menu ¶
type Menu struct {
// OnSelect, if set, is called with the chosen item's index when an item is
// activated (clicked or Enter). The menu closes first.
OnSelect func(int)
// contains filtered or unexported fields
}
Menu is a themed popup list of text items — the dropdown a host opens for a <select>, a context menu, or any "pick one of these" affordance. It is software-rendered into the same *image.RGBA the app paints, using a text.Face and a ui.Theme, so it matches the rest of the widget set (Menu/Accent/ Selection palette) and adds nothing to the closure.
The host positions the menu with Open (which sizes it from the items and the face), forwards pointer motion/clicks and Up/Down/Enter/Esc keys, and calls Draw each frame while Visible. Selecting an item (click or Enter) fires OnSelect with its index and closes the menu; Esc or an outside click closes it via Close. The zero value is not ready; construct one with NewMenu.
func (*Menu) Draw ¶
Draw paints the menu (background, border and items, with the highlighted item in the accent colour). It is a no-op when the menu is hidden.
func (*Menu) Key ¶
Key handles keyboard navigation while the menu is open, returning true if it consumed the event. Up/Down move the highlight, Enter activates it, Esc closes.
func (*Menu) Open ¶
Open shows the menu with the given items, its top-left anchored at (x, y) and the highlight on the selected item. minWidth is a lower bound on the menu width (e.g. the originating control's width); the menu grows to fit its widest item. The host should clamp (x, y) so the menu stays on-screen.
func (*Menu) PointerDown ¶
PointerDown handles a click: an item click activates it (fires OnSelect and closes); a click outside closes the menu. It returns true when the menu consumed the click (a click inside, or a click outside that dismissed an open menu), so the host can suppress its own handling.
func (*Menu) PointerMotion ¶
PointerMotion highlights the item under (x, y). It returns true when the point is within the menu, so the host knows the event was the menu's.
type TextArea ¶
type TextArea struct {
// Focused controls whether the caret is drawn; the host sets it when the
// widget has keyboard focus.
Focused bool
// OnChange, if set, is called after the text changes (edit, paste, cut).
OnChange func()
// contains filtered or unexported fields
}
TextArea is a multi-line editable text input widget for wlui apps, the multi-line sibling of TextField: caret movement (including up/down between lines), keyboard and mouse text selection across lines, clipboard cut/copy/ paste (Ctrl+X/C/V), select-all (Ctrl+A) and Enter to insert a newline. Like TextField it is software-rendered into the same *image.RGBA the app paints, using a text.Face and a ui.Theme, so it needs no cgo or toolkit. The host wires its wlui.Handler key/rune/pointer events to the widget and calls Draw each frame.
The text is held as a flat rune buffer with '\n' separators (so selection and editing are uniform with TextField); line layout is derived for rendering and hit-testing. The zero value is not ready; construct one with NewTextArea.
func NewTextArea ¶
NewTextArea returns an empty multi-line text area rendered with face and theme. clip may be nil to disable cut/copy/paste.
func (*TextArea) Blink ¶
func (t *TextArea) Blink()
Blink toggles the caret blink phase. The host calls it on a timer.
func (*TextArea) Cut ¶
func (t *TextArea) Cut()
Cut copies the selection to the clipboard and removes it.
func (*TextArea) Draw ¶
Draw paints the area into r: text, selection highlight and (when Focused and on the visible blink phase) the caret. The host fills r with the desired background first; Draw does not clear it. Drawing is clipped to r, so content outside the viewport is cropped, not spilled.
func (*TextArea) Key ¶
Key handles an evdev key code with the given modifiers, returning true if it consumed the event. The host forwards wlui.Handler.Key (with Window.Modifiers()) to it; an unconsumed event (false) is the host's to use as an app shortcut.
func (*TextArea) Paste ¶
func (t *TextArea) Paste()
Paste inserts the clipboard text at the caret, replacing any selection.
func (*TextArea) PointerDown ¶
PointerDown places the caret under (x, y) (window-relative pixels) and begins a possible drag-selection. It returns true when (x, y) is within the widget's last drawn bounds, so the host can use it to take focus.
func (*TextArea) PointerDrag ¶
PointerDrag extends a drag-selection to (x, y) while the button is held.
func (*TextArea) PreferredHeight ¶
PreferredHeight is a sensible area height for the given number of text rows.
func (*TextArea) Rune ¶
Rune inserts a printable rune at the caret (replacing any selection). The host forwards wlui.Handler.Rune to it. Control runes are ignored (Enter is handled in Key so it can insert a newline).
func (*TextArea) SelectAll ¶
func (t *TextArea) SelectAll()
SelectAll selects the whole value, placing the caret at the end.
func (*TextArea) SetFocused ¶
SetFocused sets keyboard focus and resets the caret to its visible phase so it shows immediately rather than waiting for the next blink.
type TextField ¶
type TextField struct {
// Focused controls whether the caret is drawn; the host sets it when the
// field has keyboard focus.
Focused bool
// Mask, when set, renders every rune as a bullet (a password field) and
// disables Copy/Cut so the secret can't be lifted off the clipboard. Editing,
// caret movement and selection still work on the real runes.
Mask bool
// OnChange, if set, is called after the text changes (edit, paste, cut).
OnChange func()
// OnSubmit, if set, is called when Enter is pressed.
OnSubmit func()
// contains filtered or unexported fields
}
TextField is a single-line editable text input widget for wlui apps: cursor movement, keyboard and mouse text selection, clipboard cut/copy/paste (Ctrl+X/C/V) and select-all (Ctrl+A). It is software-rendered into the same *image.RGBA the app paints, using a text.Face and a ui.Theme, so it needs no cgo or toolkit. The host wires its wlui.Handler key/rune/pointer events to the widget and calls Draw each frame.
The zero value is not ready; construct one with NewTextField.
func NewTextField ¶
NewTextField returns an empty single-line text field rendered with face and theme. clip may be nil to disable cut/copy/paste.
func (*TextField) Blink ¶
func (t *TextField) Blink()
Blink toggles the caret blink phase. The host calls it on a timer.
func (*TextField) Copy ¶
func (t *TextField) Copy()
Copy puts the selected text on the clipboard (a no-op for a masked field, so the secret can't be lifted off the clipboard).
func (*TextField) Cut ¶
func (t *TextField) Cut()
Cut copies the selection to the clipboard and removes it (a no-op for a masked field — see Copy).
func (*TextField) Draw ¶
Draw paints the field into r: text, selection highlight and (when Focused and on the visible blink phase) the caret. The host fills r with the desired background first; Draw does not clear it, so the field can sit on any chrome. Drawing is clipped to r, so text wider than the field is cropped, not spilled.
func (*TextField) Key ¶
Key handles an evdev key code with the given modifiers, returning true if it consumed the event. The host forwards wlui.Handler.Key (with Window.Modifiers()) to it; an unconsumed event (false) is the host's to use as an app shortcut.
func (*TextField) Paste ¶
func (t *TextField) Paste()
Paste inserts the clipboard text at the caret, replacing any selection.
func (*TextField) PointerDown ¶
PointerDown places the caret under x (a window-relative pixel) and begins a possible drag-selection. It returns true when (x,y) is within the field's last drawn bounds, so the host can use it to take focus.
func (*TextField) PointerDrag ¶
PointerDrag extends a drag-selection to x while the button is held.
func (*TextField) PreferredHeight ¶
PreferredHeight is a sensible field height for the face: one line plus padding.
func (*TextField) Rune ¶
Rune inserts a printable rune at the caret (replacing any selection). The host forwards wlui.Handler.Rune to it. Control runes are ignored.
func (*TextField) SelectAll ¶
func (t *TextField) SelectAll()
SelectAll selects the whole value, placing the caret at the end.
func (*TextField) SetFocused ¶
SetFocused sets keyboard focus and resets the caret to its visible phase so it shows immediately rather than waiting for the next blink.
type Theme ¶
type Theme struct {
Background color.RGBA // window/content background
Foreground color.RGBA // primary text
Dim color.RGBA // secondary / disabled text
BarBackground color.RGBA // menu/status bar background
BarForeground color.RGBA // menu/status bar text
Menu color.RGBA // dropdown / popup background
Accent color.RGBA // highlighted item / active chrome
Selection color.RGBA // selected-text background
Cursor color.RGBA // text caret
}
Theme is a colour palette shared across apps for a consistent look. Apps reference a Theme rather than hard-coding colours, so a future theme switch is a one-line change.