glui

package
v0.0.0-...-9a070ab Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TopLeft      Position = 0
	TopCenter             = 0b1_0_10_01
	TopRight              = 0b1_0_01_01
	LeftCenter            = 0b0_1_01_10
	Center                = 0b1_1_10_10
	RightCenter           = 0b1_1_01_10
	BottomLeft            = 0b0_1_01_01
	BottomCenter          = 0b1_1_10_01
	BottomRight           = 0b1_1_01_01
)

|.|.|..|..| ^ ^ ^ ^ | | | centerY | | centerX | bottom right

Variables

This section is empty.

Functions

This section is empty.

Types

type Alignment

type Alignment uint8
const (
	AlignStart Alignment = iota
	AlignEnd
	AlignMiddle
)

type Axis

type Axis uint8
const (
	Horizontal Axis = 1 << iota
	Vertical
)

func (Axis) Cut

func (a Axis) Cut(r geom.Rect, size geom.Vec2) geom.Rect

func (Axis) Grow

func (a Axis) Grow(size, incr geom.Vec2) geom.Vec2

func (Axis) Reverse

func (a Axis) Reverse() Axis

func (Axis) ValueOf

func (a Axis) ValueOf(pt geom.Vec2) float32

type Callback

type Callback func(input *glen.InputState, delta time.Duration)

type ClickCallback

type ClickCallback func(ctx *Context, area geom.Rect)

func OnDoubleClick

func OnDoubleClick(wait time.Duration, btn glen.MouseButton, onSingleClick, onDoubleClick ClickCallback) ClickCallback

type ClickListCallback

type ClickListCallback func(index int, ctx *Context, area geom.Rect)

type ClickTCallback

type ClickTCallback[T any] func(item T, ctx *Context, area geom.Rect)

func OnDoubleClickT

func OnDoubleClickT[T any](
	wait time.Duration,
	btn glen.MouseButton,
	onSingleClick, onDoubleClick ClickTCallback[T],
) ClickTCallback[T]

type Context

type Context struct {
	Window     *glen.Window
	Renderer   *shape2d.Renderer
	Instances  []shape2d.Instance
	Callbacks  []Callback
	Ready      bool
	Root       Widget
	Background glen.Color
	// contains filtered or unexported fields
}

func NewContext

func NewContext(window *glen.Window, bg glen.Color) *Context

func (*Context) AddOverlay

func (ctx *Context) AddOverlay(overlay Overlay)

func (*Context) ClearOverlays

func (ctx *Context) ClearOverlays()

func (*Context) DelOverlay

func (ctx *Context) DelOverlay(overlay Overlay) (deleted bool)

func (*Context) Focus

func (ctx *Context) Focus(w Widget)

Focus sets the focused widget, nil to unfocus.

func (*Context) HasOverlay

func (ctx *Context) HasOverlay(overlay Overlay) bool

func (*Context) IsFocused

func (ctx *Context) IsFocused(w Widget) bool

IsFocused returns true if the given widget is focused.

func (*Context) IsMouseIn

func (ctx *Context) IsMouseIn(area geom.Rect) bool

IsMouseIn returns true if the mouse is inside the given area. Must be used to account for overlays.

func (*Context) OnFrame

func (ctx *Context) OnFrame(window *glen.Window, delta time.Duration)

type Flex

type Flex struct {
	Axis      Axis
	Alignment Alignment
}

func (Flex) Widget

func (fx Flex) Widget(list func(index int, first bool) FlexItem) Widget

func (Flex) Widgets

func (fx Flex) Widgets(items ...FlexItem) Widget

type FlexItem

type FlexItem struct {
	Ratio float32
	Widget
}

type Grid

type Grid struct {
	Columns int
	Rows    int
	// Cell returns the size of all cells in the grid.
	Cell func(cols, rows int, area geom.Rect) geom.Vec2
}

func (Grid) Widget

func (g Grid) Widget(list WidgetList) Widget

func (Grid) Widgets

func (g Grid) Widgets(widgets ...Widget) Widget

type Grid2

type Grid2 struct {
	Columns int
	Rows    int
	Cell    func(x, y int) geom.Vec2
}

TODO Grid2

func (Grid2) Widget

func (g Grid2) Widget(list WidgetList) Widget

type Input

type Input struct {
	TextStyle   Text
	Placeholder Widget
	Cursor      Widget
	CursorBlink time.Duration
}

func (Input) Widget

func (ip Input) Widget(
	disabled *bool,
	text string,
	onStart func() (focused bool),
	onChange func(text []rune),
	onEnd func(text string, esc bool) (keepFocus bool),
) Widget

func (Input) WidgetFunc

func (ip Input) WidgetFunc(
	disabled *bool,
	content func() string,
	onStart func() (focused bool),
	onChange func(text []rune),
	onEnd func(text string, esc bool) (keepFocus bool),
) Widget

type Label

type Label struct {
	Tint      glen.Color
	Font      glen.TextureFont
	Alignment Alignment
}

Label is best used with static strings as it caches their representation.

func (Label) Widget

func (label Label) Widget(text string) (w Widget)

func (Label) WidgetRunes

func (label Label) WidgetRunes(text []rune) Widget

type List

type List struct {
	Axis      Axis
	Alignment Alignment
}

func (List) Widget

func (l List) Widget(firstIndex *atomic.Int32, list WidgetList) Widget

Widget needs all items to have the same width (horizontal) or height (vertical).

func (List) Widgets

func (l List) Widgets(firstIndex *atomic.Int32, widgets ...Widget) Widget

type Overlay

type Overlay func(self Overlay) (widget Widget, area geom.Rect)

type Position

type Position uint8

type Rect

type Rect struct {
	Width        float32
	Size         geom.Vec2
	Color        glen.Color
	CornerRadius float32
	Rotation     uint16
}

func (Rect) Widget

func (rect Rect) Widget() Widget

type Rigid

type Rigid struct {
	Axis      Axis
	Alignment Alignment
}

func (Rigid) Widget

func (r Rigid) Widget(list WidgetList) Widget

func (Rigid) Widgets

func (r Rigid) Widgets(widgets ...Widget) Widget

type Spacing

type Spacing uint8
const (
	// SpaceEnd puts any remaining space at the end.
	SpaceEnd Spacing = iota
	// SpaceStart puts any remaining space at the start.
	SpaceStart
	// SpaceAround puts any remaining space evenly at the start and the end.
	SpaceAround
	// SpaceBetween puts any remaining space evenly between children.
	SpaceBetween
	// SpaceEvenly puts any remaining space evenly between start, children and end.
	SpaceEvenly
)

type Split

type Split struct {
	Axis        Axis
	MouseButton glen.MouseButton
}

func (Split) Widget

func (sp Split) Widget(resizing *bool, ratio *float32, w1, w2, handle Widget) Widget

type Tabs

type Tabs struct {
	Axis      Axis
	Alignment Alignment
}

func (Tabs) Widget

func (t Tabs) Widget(tabs, content WidgetList) Widget

type Text

type Text struct {
	Tint      glen.Color
	Font      glen.TextureFont
	Alignment Alignment
}

func (Text) Widget

func (t Text) Widget(text string) Widget

func (Text) WidgetFunc

func (t Text) WidgetFunc(text func() string) Widget

func (Text) WidgetRunes

func (t Text) WidgetRunes(text []rune) Widget

type Tree

type Tree[T comparable] struct {
	Axis        Axis
	Alignment   Alignment
	MouseButton glen.MouseButton
}

func (Tree[T]) Widget

func (tr Tree[T]) Widget(
	tree TreeWidget[T],
	onBusy Widget,
	onClick ClickTCallback[T],
) Widget

type TreeWidget

type TreeWidget[T comparable] interface {
	Ready() *atomic.Bool
	Root() iter.Seq[T]
	IsLeaf(T) bool
	Children(T) iter.Seq[T]
	WidgetT(item T, depth int, open bool) Widget
}

type Widget

type Widget func(ctx *Context, area geom.Rect) (size geom.Vec2)

Widget defines a function that renders a UI component within a given rectangular area and returns its occupied size. Calling Widget with a nil Context will not render anything but return its size nonetheless.

var Empty Widget = func(ctx *Context, area geom.Rect) geom.Vec2 {
	return geom.Vec2{}
}

func Checkbox

func Checkbox(disabled, checked *bool, ok, nok Widget, onChange func(checked bool)) Widget

func OnClick

func OnClick(disabled *bool, btn glen.MouseButton, w Widget, callback ClickCallback) Widget

OnClick does not trigger a Context refresh upon click.

func OnDrag

func OnDrag(btn glen.MouseButton, w Widget,
	onStart func(ctx *Context, area geom.Rect, pos geom.Vec2) (dragArea geom.Rect),
	onStop func(ctx *Context, pos geom.Vec2),
	onDrag func(ctx *Context, area geom.Rect, delta geom.Vec2)) Widget

OnDrag triggers its callbacks upon dragging in the provided widget area.

func OnHover

func OnHover(disabled, hovered *bool, w Widget, callbackOn, callbackOff func(ctx *Context)) Widget

OnHover does not trigger a Context refresh upon hover or unhover.

func Pan

func Pan(axis Axis, widget Widget) Widget

Pan the widget within its container.

func Slider

func Slider(axis Axis, disabled, sliding *bool, ratio *float32, background, handle Widget, onChange func(ctx *Context)) Widget

func Space

func Space(size geom.Vec2) Widget

func Stack

func Stack(widgets ...Widget) Widget

func StackOnTop

func StackOnTop(w1, w2 Widget) Widget

Stack w2 on top of w1. w1's area is w2's size.

func Tooltip

func Tooltip(disabled *bool, widget, tip Widget, delay time.Duration) Widget

func (Widget) Contain

func (w Widget) Contain(widget Widget) Widget

func (Widget) ContainRatio

func (w Widget) ContainRatio(ratio geom.Vec2) Widget

func (Widget) ContainSize

func (w Widget) ContainSize(size geom.Vec2) Widget

func (Widget) Equal

func (w Widget) Equal(widget Widget) bool

func (Widget) Fixed

func (w Widget) Fixed(size geom.Vec2) Widget

func (Widget) FixedRatio

func (w Widget) FixedRatio(ratio geom.Vec2) Widget

func (Widget) Inset

func (w Widget) Inset(inset float32) Widget

func (Widget) InsetV

func (w Widget) InsetV(inset geom.Vec2) Widget

func (Widget) Place

func (w Widget) Place(pos Position) Widget

type WidgetList

type WidgetList func(index int, first bool) Widget

WidgetList represents a list of widgets. Return nil to indicate the end of the list.

func OnClickList

func OnClickList(btn glen.MouseButton, list WidgetList, callback ClickListCallback) WidgetList

OnClickList does not trigger a Context refresh upon click.

func Slice

func Slice(widgets ...Widget) WidgetList

type Wrap

type Wrap struct {
	Axis      Axis
	Alignment Alignment
	MainSize  func(area geom.Rect) float32 // main axis size
}

Wrap assumes that all items have the same size along the main axis.

func (Wrap) Widget

func (wr Wrap) Widget(list WidgetList) Widget

func (Wrap) Widgets

func (wr Wrap) Widgets(widgets ...Widget) Widget

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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