ui

package
v0.0.0-...-6cb71f3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func Fill

func Fill(dst *image.RGBA, r image.Rectangle, c color.Color)

Fill paints rectangle r of dst with c. Pass dst.Bounds() to clear the whole image before drawing.

Types

type Clipboard

type Clipboard interface {
	SetClipboard(string)
	Clipboard() string
}

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 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 NewMenu

func NewMenu(face *text.Face, theme *Theme) *Menu

NewMenu returns a hidden menu rendered with face and theme.

func (m *Menu) Bounds() image.Rectangle

Bounds returns the menu's current on-screen rectangle (valid while Visible).

func (m *Menu) Close()

Close hides the menu without firing OnSelect.

func (m *Menu) Draw(dst *image.RGBA)

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 (m *Menu) Key(code uint32, _ wlui.Modifiers) bool

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 (m *Menu) Open(items []string, selected, x, y, minWidth int)

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 (m *Menu) PointerDown(x, y int) bool

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 (m *Menu) PointerMotion(x, y int) bool

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.

func (m *Menu) Visible() bool

Visible reports whether the menu is currently shown.

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

func NewTextArea(face *text.Face, theme *Theme, clip Clipboard) *TextArea

NewTextArea returns an empty multi-line text area rendered with face and theme. clip may be nil to disable cut/copy/paste.

func (t *TextArea) Blink()

Blink toggles the caret blink phase. The host calls it on a timer.

func (*TextArea) Clear

func (t *TextArea) Clear()

Clear empties the area.

func (*TextArea) Copy

func (t *TextArea) Copy()

Copy puts the selected text on the clipboard.

func (*TextArea) Cut

func (t *TextArea) Cut()

Cut copies the selection to the clipboard and removes it.

func (*TextArea) Draw

func (t *TextArea) Draw(dst *image.RGBA, r image.Rectangle)

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

func (t *TextArea) Key(code uint32, mods wlui.Modifiers) bool

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

func (t *TextArea) PointerDown(x, y int) bool

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

func (t *TextArea) PointerDrag(x, y int)

PointerDrag extends a drag-selection to (x, y) while the button is held.

func (*TextArea) PointerUp

func (t *TextArea) PointerUp()

PointerUp ends a drag-selection.

func (*TextArea) PreferredHeight

func (t *TextArea) PreferredHeight(rows int) int

PreferredHeight is a sensible area height for the given number of text rows.

func (*TextArea) Rune

func (t *TextArea) Rune(r 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

func (t *TextArea) SetFocused(focused bool)

SetFocused sets keyboard focus and resets the caret to its visible phase so it shows immediately rather than waiting for the next blink.

func (*TextArea) SetText

func (t *TextArea) SetText(s string)

SetText replaces the contents, placing the caret at the end and clearing any selection.

func (*TextArea) Text

func (t *TextArea) Text() string

Text returns the current contents.

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

func NewTextField(face *text.Face, theme *Theme, clip Clipboard) *TextField

NewTextField returns an empty single-line text field rendered with face and theme. clip may be nil to disable cut/copy/paste.

func (t *TextField) Blink()

Blink toggles the caret blink phase. The host calls it on a timer.

func (*TextField) Clear

func (t *TextField) Clear()

Clear empties the field.

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

func (t *TextField) Draw(dst *image.RGBA, r image.Rectangle)

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

func (t *TextField) Key(code uint32, mods wlui.Modifiers) bool

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

func (t *TextField) PointerDown(x, y int) bool

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

func (t *TextField) PointerDrag(x, y int)

PointerDrag extends a drag-selection to x while the button is held.

func (*TextField) PointerUp

func (t *TextField) PointerUp()

PointerUp ends a drag-selection.

func (*TextField) PreferredHeight

func (t *TextField) PreferredHeight() int

PreferredHeight is a sensible field height for the face: one line plus padding.

func (*TextField) Rune

func (t *TextField) Rune(r 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

func (t *TextField) SetFocused(focused bool)

SetFocused sets keyboard focus and resets the caret to its visible phase so it shows immediately rather than waiting for the next blink.

func (*TextField) SetText

func (t *TextField) SetText(s string)

SetText replaces the contents, placing the caret at the end and clearing any selection.

func (*TextField) Text

func (t *TextField) Text() string

Text returns the current contents.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL