ux

package
v0.0.0-...-20810c9 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

ux is a package that supplies basic components built on the ui package.

The components in the ux package are structured in the following way: - XSettings: common options for the X component that can be specified globally - X: the X component options that can be built into a component - XBase: the built X component

The options and built component can be passed as children to other components, anything that implements HasComponent can be. When passing options (which would be the most common use case) it is built by the parent while the parent is being built.

Each Kind can have a Template defined, and each component has a kind or can be given a custom kind that dictates which template it uses. For example ux defines one kind of Button but you can define `const KindFAB ux.Kind = 45` and then pass `Kind: KindFAB` to `Button` and also define the FAB template on the theme.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	*ui.Template
	Kind Kind
}

type Button

type Button struct {
	Base
	Settings ButtonSettings

	Text          string
	TextValue     Value[string]
	TextPlacement ui.Placement
	LeftIcon      *Icon
	RightIcon     *Icon

	OnClick   Listener[*ButtonBase]
	OnEnter   Listener[*ButtonBase]
	OnAction  Listener[*ButtonBase]
	OnPointer func(ev *ui.PointerEvent)
}

func (Button) Build

func (b Button) Build(theme *Theme) *ButtonBase

func (Button) GetComponent

func (b Button) GetComponent(theme *Theme) *ui.Base

type ButtonBase

type ButtonBase struct {
	Component  *ui.Base
	Text       Value[string]
	Options    Button
	TextVisual *ui.VisualText
	// contains filtered or unexported fields
}

func (*ButtonBase) Action

func (b *ButtonBase) Action(name string) *input.Action

func (*ButtonBase) ClickAction

func (b *ButtonBase) ClickAction(name string) *input.Action

func (*ButtonBase) Clicked

func (b *ButtonBase) Clicked() bool

func (*ButtonBase) EnterAction

func (b *ButtonBase) EnterAction(name string) *input.Action

func (*ButtonBase) Entered

func (b *ButtonBase) Entered() bool

func (*ButtonBase) GetComponent

func (b *ButtonBase) GetComponent(theme *Theme) *ui.Base

type ButtonSettings

type ButtonSettings struct {
	Padding ui.AmountBounds
}

type Checkbox

type Checkbox struct {
	Label        string
	LabelValue   Value[string]
	Checked      bool
	CheckedValue Value[bool]

	OnCheck   func()
	OnUncheck func()
	OnChange  func(checked bool)
}

type CheckboxSettings

type CheckboxSettings struct {
	CheckboxSize    gfx.Coord
	CheckedTile     gfx.Tile
	UncheckedTile   gfx.Tile
	CheckedLayers   []ui.Layer
	UncheckedLayers []ui.Layer
}

type Computed

type Computed[V comparable] struct {
	// contains filtered or unexported fields
}

A value that is computed when GetChanged is invoked and it returns a new value then last time. Set has no effect.

func NewComputed

func NewComputed[V comparable](getValue func() V) *Computed[V]

func (*Computed[V]) GetChanged

func (w *Computed[V]) GetChanged() *V

func (*Computed[V]) Set

func (w *Computed[V]) Set(value V)

type Constant

type Constant[V any] struct {
	// contains filtered or unexported fields
}

A value that is changed by set.

func NewConstant

func NewConstant[V any](value V) *Constant[V]

func (*Constant[V]) Changed

func (c *Constant[V]) Changed() bool

func (*Constant[V]) GetChanged

func (c *Constant[V]) GetChanged() *V

func (*Constant[V]) Set

func (c *Constant[V]) Set(value V)

type Counter

type Counter int

A counter for the number of times something occurs.

func (*Counter) Add

func (c *Counter) Add(amount int)

func (*Counter) Changed

func (c *Counter) Changed() bool

type Dialog

type Dialog struct {
	Title      string
	TitleValue Value[string]

	Children []HasComponent

	RetainOrderOnDrag        bool
	HideMaximize             bool
	HideClose                bool
	AllowOutside             bool
	DisableDragging          bool
	DisableResize            bool
	DisableResizeLeft        bool
	DisableResizeBottomLeft  bool
	DisableResizeBottom      bool
	DisableResizeBottomRight bool
	DisableResizeRight       bool

	OnResize   func(b ui.Bounds)
	OnDrag     func(b ui.Bounds)
	OnMaximize func()
	OnMinimize func()
	OnClose    func()
}

type DialogSettings

type DialogSettings struct {
	BarHeight        ui.Amount
	BarPadding       ui.AmountBounds
	ChildrenPadding  ui.AmountBounds
	DragTransparency float32
}
type Dropdown[I any] struct {
	Items           []I
	PlaceholderText string
	Placeholder     HasComponent
	Value           I
	ItemText        func(item I) string
	ItemComponent   func(item I) HasComponent
	OnChange        func(item I)
	ValueCompare    func(a, b I) bool

	DropdownSettings
}
type DropdownBase[I any] struct {
}
type DropdownSettings struct {
	TriggerOnDown  bool
	TriggerOnEnter bool
	TriggerOnFocus bool
	ShowAnimation  ui.AnimationFactory
	HideAnimation  ui.AnimationFactory
}

type Dynamic

type Dynamic[V comparable] struct {
	// contains filtered or unexported fields
}

A value that is computed when GetChanged is invoked but also supports setting.

func NewDynamic

func NewDynamic[V comparable](get func() V, set func(V)) *Dynamic[V]

func (*Dynamic[V]) GetChanged

func (d *Dynamic[V]) GetChanged() *V

func (*Dynamic[V]) Set

func (d *Dynamic[V]) Set(value V)

type Editable

type Editable struct {
	Text      string
	TextValue Value[string]

	OnChange func(string)
}

type EditableSettings

type EditableSettings struct {
}

type HasComponent

type HasComponent interface {
	GetComponent(theme *Theme) *ui.Base
}

type Icon

type Icon struct {
}

type IconSettings

type IconSettings struct {
}

type Kind

type Kind int
const (
	KindDefault Kind = iota
	KindNone
	KindButton
	KindCheckbox
	KindEditable
	KindScrollable
	KindDropdown
	KindInputText
	KindInputDropdown
	KindInputArea
	KindInputNumber
	KindCollapsible
	KindDialog
)

func (Kind) Get

func (k Kind) Get(defaultKind Kind) Kind

type Listener

type Listener[E any] func(ev E)

A listener is a function where multiple can be added.

func (*Listener[E]) Add

func (a *Listener[E]) Add(b Listener[E], before bool)

func (*Listener[E]) Clear

func (a *Listener[E]) Clear()

func (Listener[E]) Trigger

func (l Listener[E]) Trigger(ev E)

type Live

type Live[V any] struct {
	// contains filtered or unexported fields
}

A value that is expected to change every time GetChanged is invoked.

func NewLive

func NewLive[V any](get func() V, set func(V)) *Live[V]

func (*Live[V]) GetChanged

func (d *Live[V]) GetChanged() *V

func (*Live[V]) Set

func (d *Live[V]) Set(value V)

type Relative

type Relative struct {
	RelativeSettings

	Placement  RelativePlacement
	RelativeTo HasComponent
	Content    HasComponent

	OnShow Listener[*RelativeBase]
	OnHide Listener[*RelativeBase]
}

func (Relative) Build

func (r Relative) Build(theme *Theme) *RelativeBase

func (Relative) GetComponent

func (b Relative) GetComponent(theme *Theme) *ui.Base

type RelativeBase

type RelativeBase struct {
	Component  *ui.Base
	RelativeTo *ui.Base
	Content    *ui.Base
	Enabled    Value[bool]
	Visible    Value[bool]
	Options    Relative
	// contains filtered or unexported fields
}

func (*RelativeBase) GetComponent

func (rb *RelativeBase) GetComponent(theme *Theme) *ui.Base

func (*RelativeBase) Hide

func (rb *RelativeBase) Hide()

func (*RelativeBase) Show

func (rb *RelativeBase) Show()

func (*RelativeBase) Toggle

func (rb *RelativeBase) Toggle()

func (*RelativeBase) Trigger

func (rb *RelativeBase) Trigger(on RelativeOnEvent)

type RelativeOnEvent

type RelativeOnEvent int
const (
	RelativeOnNone RelativeOnEvent = (1 << iota) >> 1
	RelativeOnPointerEnter
	RelativeOnPointerLeave
	RelativeOnFocus
	RelativeOnBlur
	RelativeOnClick
	RelativeOnEscape
	RelativeOnSpace
	RelativeOnOutside
	RelativeOnKeyDown
)

type RelativePlacement

type RelativePlacement struct {
	Anchor                  ui.AmountPoint
	Align                   ui.AmountPoint
	Offset                  ui.AmountPoint
	Distance                float32
	MatchWidth, MatchHeight bool
}

type RelativeSettings

type RelativeSettings struct {
	HideOn        RelativeOnEvent
	ShowOn        RelativeOnEvent
	ToggleOn      RelativeOnEvent
	ShowAnimation ui.AnimationFactory
	HideAnimation ui.AnimationFactory
}

type Settings

type Settings struct {
	Button   ButtonSettings
	Dialog   DialogSettings
	Checkbox CheckboxSettings
	Editable EditableSettings
	Icon     IconSettings
	Dropdown DropdownSettings
}

type Theme

type Theme struct {
	Settings          Settings
	ScrollSensitivity gfx.Coord
	Templates         map[Kind]*ui.Template
}

type Trigger

type Trigger float32

A trigger used for input actions.

func (Trigger) Init

func (t Trigger) Init(inputs input.InputSystem)

func (Trigger) InputCount

func (t Trigger) InputCount() int

func (*Trigger) Set

func (t *Trigger) Set(value float32)

func (Trigger) Update

func (t Trigger) Update(inputs input.InputSystem) (input.Data, bool)

type Value

type Value[V any] interface {
	// If the value has changed since the last time this method was called
	// a non-nil value will be returned pointing to the new value.
	GetChanged() *V
	// Sets the value.
	Set(value V)
}

A value that can be tracked for changes.

func CoalesceValue

func CoalesceValue[V any](value Value[V], constant V) Value[V]

Returns a Value[V] given an optional value and its constant alternative if a value was not given.

Jump to

Keyboard shortcuts

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