ui

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: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MeasureWidthRoundingError  = 0.001
	MeasureHeightRoundingError = 0.001
)
View Source
const (
	LayoutGridWidthRoundingError = 0.001
)

Variables

View Source
var (
	BufferPoolCreate = func() *VertexBuffers {
		return NewVertexBuffers(BufferCapacity, Buffers)
	}
	ClipPoolCreate = func() *VertexBuffers {
		return NewVertexBuffers(ClipCapacity, Buffers)
	}
	BufferPoolQueueCreate = func() *VertexQueue {
		return NewVertexQueue(BufferQueueCapacity)
	}
	BufferPoolReset = func(vbs *VertexBuffers) *VertexBuffers {
		vbs.Clear()
		return vbs
	}
	BufferPoolQueueReset = func(vbs *VertexQueue) *VertexQueue {
		vbs.Clear()
		return vbs
	}

	BufferPoolSize      = 256
	BufferCapacity      = 64
	ClipPoolSize        = 24
	ClipCapacity        = 1024
	BufferQueueCapacity = 12
	BufferQueuePoolSize = 256
	Buffers             = 1

	BufferPool      = ds.NewPool(BufferPoolSize, BufferPoolCreate, BufferPoolReset)
	BufferQueuePool = ds.NewPool(BufferQueuePoolSize, BufferPoolQueueCreate, BufferPoolQueueReset)

	ClipPool   = ds.NewPool(ClipPoolSize, ClipPoolCreate, BufferPoolReset)
	ClipMemory = ds.NewStack[*VertexBuffers](32)
)
View Source
var AmountFormatRegex = regexp.MustCompile(`^([+-]?\d*(\.\d+)?)((%)?[a-zA-Z]*)$`)
View Source
var ShapeRoundedAngles = [][]float32{{math.Pi, math.Pi * 0.5}, {math.Pi * 0.5, 0}, {math.Pi * 2, math.Pi * 1.5}, {math.Pi * 1.5, math.Pi}}
View Source
var ShapeRoundedPlacements = [][]float32{{0, 0}, {1, 0}, {1, 1}, {0, 1}} // 0=1, 1=-1     *2 (0,2) -1 (-1,1)
View Source
var TextFormatRegex = regexp.MustCompile(`\\{|\{([^:}]+):?([^}]*)\}|.|\s`)
View Source
var TextMeasureErrorAmount float32 = 5

Functions

func AddSuffixes

func AddSuffixes(unit Unit, suffixes ...string)

func Collinear

func Collinear(a, b, c gfx.Coord) bool

Returns if the three points lie on the same line.

func Ease

func Ease(delta float32, easing func(float32) float32) float32

func InPolygon

func InPolygon(polygon []gfx.Coord, pt gfx.Coord) bool

func Length

func Length(dx, dy float32) float32

Computes the length of the given vector/difference.

func LengthSq

func LengthSq(dx, dy float32) float32

Computes the length of the given vector/difference.

func Normal

func Normal(vx, vy float32) (nx, ny, length float32)

Computes the normal of a vector and returns the length as well.

func NormalBetween

func NormalBetween(origin, point gfx.Coord) (nx, ny, length float32)

Computes the normal between an origin and a point and returns the length as well.

func Override

func Override[V any](value V) *V

Provides an override for a value, which is really just a pointer to a copy of the value. This is useful function for the simple properties in the types which have concrete and override types (like Text/Paragraph/Paragraphs Styles)

Types

type Alignment

type Alignment float32
const (
	AlignmentTop    Alignment = 0
	AlignmentLeft   Alignment = 0
	AlignmentMiddle Alignment = 0.5
	AlignmentCenter Alignment = 0.5
	AlignmentRight  Alignment = 1
	AlignmentBottom Alignment = 1
)

func (Alignment) Compute

func (a Alignment) Compute(span float32) float32

func (Alignment) MarshalText

func (a Alignment) MarshalText() ([]byte, error)

func (*Alignment) UnmarshalText

func (a *Alignment) UnmarshalText(text []byte) error

type Amount

type Amount struct {
	Value float32
	Unit  Unit
}

A unit amount

func (Amount) Get

func (a Amount) Get(ctx *AmountContext, widthRelative bool) float32

func (Amount) IsZero

func (a Amount) IsZero() bool

func (Amount) MarshalText

func (a Amount) MarshalText() ([]byte, error)

func (*Amount) Set

func (a *Amount) Set(value float32, unit Unit)

func (*Amount) UnmarshalText

func (a *Amount) UnmarshalText(text []byte) error

type AmountBounds

type AmountBounds struct {
	Left   Amount
	Right  Amount
	Top    Amount
	Bottom Amount
}

func NewAmountBounds

func NewAmountBounds(left, top, right, bottom float32) AmountBounds

func NewAmountBoundsUniform

func NewAmountBoundsUniform(value float32, unit Unit) AmountBounds

func NewAmountBoundsUnit

func NewAmountBoundsUnit(left, top, right, bottom float32, unit Unit) AmountBounds

func (AmountBounds) GetBounds

func (a AmountBounds) GetBounds(ctx *AmountContext) Bounds

func (AmountBounds) IsZero

func (a AmountBounds) IsZero() bool

func (*AmountBounds) Set

func (a *AmountBounds) Set(value float32, unit Unit)

func (*AmountBounds) SetAmount

func (a *AmountBounds) SetAmount(amount Amount)

func (AmountBounds) WithAmount

func (a AmountBounds) WithAmount(amount Amount) AmountBounds

type AmountContext

type AmountContext struct {
	Parent   UnitContext
	FontSize float32
	View     UnitContext
	Window   UnitContext
	Screen   UnitContext
}

func (*AmountContext) ForFont

func (c *AmountContext) ForFont(font Amount) *AmountContext

func (AmountContext) GetScalar

func (c AmountContext) GetScalar(unit Unit, widthRelative bool) float32

func (*AmountContext) IsSameSize

func (c *AmountContext) IsSameSize(width, height float32, fontSize Amount) bool

func (*AmountContext) Resize

func (c *AmountContext) Resize(width, height float32, fontSize Amount) *AmountContext

type AmountCorners

type AmountCorners struct {
	TopLeft     Amount
	TopRight    Amount
	BottomLeft  Amount
	BottomRight Amount
}

func NewAmountCorners

func NewAmountCorners(topLeft, topRight, bottomRight, bottomLeft float32) AmountCorners

func NewAmountCornersUniform

func NewAmountCornersUniform(value float32, unit Unit) AmountCorners

func NewAmountCornersUnit

func NewAmountCornersUnit(topLeft, topRight, bottomRight, bottomLeft float32, unit Unit) AmountCorners

func (*AmountCorners) Set

func (a *AmountCorners) Set(value float32, unit Unit)

type AmountPoint

type AmountPoint struct {
	X Amount
	Y Amount
}

func NewAmountPoint

func NewAmountPoint(x, y float32) AmountPoint

func NewAmountPointParent

func NewAmountPointParent(x, y float32) AmountPoint

func NewAmountPointUnit

func NewAmountPointUnit(x, y float32, unit Unit) AmountPoint

func (AmountPoint) Get

func (a AmountPoint) Get(ctx *AmountContext) (float32, float32)

func (AmountPoint) IsZero

func (a AmountPoint) IsZero() bool

func (AmountPoint) Lerp

func (start AmountPoint) Lerp(end AmountPoint, delta float32) AmountPoint

func (*AmountPoint) Set

func (a *AmountPoint) Set(value float32, unit Unit)

type Anchor

type Anchor struct {
	Base  float32
	Delta float32
}

func (Anchor) Get

func (a Anchor) Get(total float32) float32

func (Anchor) Is

func (a Anchor) Is(base float32, delta float32) bool

func (Anchor) IsZero

func (a Anchor) IsZero() bool

func (*Anchor) Set

func (a *Anchor) Set(base float32, delta float32)

func (*Anchor) SetRelative

func (a *Anchor) SetRelative(value float32, relative bool)

type Animation

type Animation interface {
	Init(base *Base)
	Update(base *Base, animationTime float32, update Update) Dirty
	IsDone(base *Base, animationTime float32) bool
	PostProcess(base *Base, animationTime float32, ctx *RenderContext, out *VertexBuffers)
}

type AnimationEvent

type AnimationEvent uint
const (
	AnimationEventNone AnimationEvent = iota
	AnimationEventShow
	AnimationEventHide
	AnimationEventRemove
	AnimationEventFocus
	AnimationEventBlur
	AnimationEventPointerEnter
	AnimationEventPointerLeave
	AnimationEventPointerDown
	AnimationEventPointerUp
	AnimationEventDragStart
	AnimationEventDragStop
	AnimationEventDragCancel
	AnimationEventDragEnter
	AnimationEventDrop
	AnimationEventDisabled
	AnimationEventEnabled
)

type AnimationFactory

type AnimationFactory interface {
	GetAnimation(base *Base) Animation
}

type AnimationState

type AnimationState struct {
	Current      Animation
	CurrentTime  float32
	CurrentEvent AnimationEvent
	// contains filtered or unexported fields
}

func (*AnimationState) IsAnimating

func (as *AnimationState) IsAnimating() bool

func (*AnimationState) PostProcess

func (as *AnimationState) PostProcess(base *Base, ctx *RenderContext, out *VertexBuffers)

func (*AnimationState) Set

func (as *AnimationState) Set(a Animation, ev AnimationEvent)

func (*AnimationState) Stop

func (as *AnimationState) Stop(now bool)

func (*AnimationState) Update

func (as *AnimationState) Update(base *Base, update Update) Dirty

type Animations

type Animations struct {
	ForEvent ds.EnumMap[AnimationEvent, AnimationFactory]
	Named    id.DenseKeyMap[AnimationFactory, uint16, uint8]
}

func (*Animations) Merge

func (a *Animations) Merge(other *Animations, replace bool)

type Background

type Background interface {
	Init(b *Base)
	Update(b *Base, update Update) Dirty
	Backgroundify(b *Base, bounds Bounds, ctx *RenderContext, out *Vertex)
}

type BackgroundColor

type BackgroundColor struct {
	Color color.Able
}

func (BackgroundColor) Backgroundify

func (bc BackgroundColor) Backgroundify(b *Base, bounds Bounds, ctx *RenderContext, out *Vertex)

func (BackgroundColor) Init

func (bc BackgroundColor) Init(b *Base)

func (BackgroundColor) Update

func (bc BackgroundColor) Update(b *Base, update Update) Dirty

type BackgroundImage

type BackgroundImage struct {
	Tile gfx.Tile
}

func (BackgroundImage) Backgroundify

func (bi BackgroundImage) Backgroundify(b *Base, bounds Bounds, ctx *RenderContext, out *Vertex)

func (BackgroundImage) Init

func (bi BackgroundImage) Init(b *Base)

func (BackgroundImage) Update

func (bc BackgroundImage) Update(b *Base, update Update) Dirty

type BackgroundLinearGradient

type BackgroundLinearGradient struct {
	StartColor color.Able
	Start      gfx.Coord
	EndColor   color.Able
	End        gfx.Coord
}

func (BackgroundLinearGradient) Backgroundify

func (bg BackgroundLinearGradient) Backgroundify(b *Base, bounds Bounds, ctx *RenderContext, out *Vertex)

func (BackgroundLinearGradient) Init

func (bc BackgroundLinearGradient) Init(b *Base)

func (BackgroundLinearGradient) Update

func (bc BackgroundLinearGradient) Update(b *Base, update Update) Dirty

type BackgroundRadialGradient

type BackgroundRadialGradient struct {
	InnerColor color.Able
	OuterColor color.Able
	Radius     AmountPoint
	Offset     AmountPoint
}

func (BackgroundRadialGradient) Backgroundify

func (bg BackgroundRadialGradient) Backgroundify(b *Base, bounds Bounds, ctx *RenderContext, out *Vertex)

func (BackgroundRadialGradient) Init

func (bg BackgroundRadialGradient) Init(b *Base)

func (BackgroundRadialGradient) Update

func (bc BackgroundRadialGradient) Update(b *Base, update Update) Dirty

type Base

type Base struct {
	Name                        id.Identifier
	Layers                      []Layer
	Placement                   Placement
	RelativePlacement           Placement
	Bounds                      Bounds
	Children                    []*Base
	ChildrenOrderless           bool
	Focusable                   bool
	Draggable                   bool
	Droppable                   bool
	Events                      Events
	States                      State
	Clip                        Placement
	Transform                   Transform
	TextStyles                  *TextStylesOverride
	Shape                       Shape
	OverShape                   []gfx.Coord
	Transparency                float32
	Color                       color.Modify
	Animation                   AnimationState
	Animations                  *Animations
	Cursors                     Cursors
	Hooks                       Hooks
	Colors                      color.Colors
	Margin                      AmountBounds
	MinSize                     AmountPoint
	MaxSize                     AmountPoint
	Layout                      Layout
	LayoutData                  LayoutData
	IgnoreLayoutPreferredWidth  bool
	IgnoreLayoutPreferredHeight bool
	// contains filtered or unexported fields
}

The Base UI component.

func (*Base) AddChildren

func (b *Base) AddChildren(children ...*Base)

Adds the given children to this parent and initializes them. This will dirty this component and all parents.

func (*Base) AddStates

func (b *Base) AddStates(state State)

Adds the given states to the component. See SetState. This operation has no effect if the state is unchanged.

func (*Base) AnimationFor

func (b *Base) AnimationFor(ev AnimationEvent) AnimationFactory

func (*Base) AnimationNamed

func (b *Base) AnimationNamed(name id.Identifier) AnimationFactory

func (*Base) ApplyTemplate

func (b *Base) ApplyTemplate(t *Template)

Applies the template to this component, anywhere it appears an option is defined on the template but not the component.

func (*Base) At

func (b *Base) At(pt gfx.Coord) *Base

Returns the component at the given point within this component. If a TransparencyThreshold is defined on the UI and this component is too transparent it is considered invisible to pointer events. If the UI is configured to transform the pointer to the relative orientation of this component then the coordinate is passed through the inverse transform of this component before further inspection is done. If the point is not within the Bounds or OverShape of this component then nil is returned. Otherwise all ShownChildren are inspected using the same logic as above and the first one to return a non-nil value is returned.

func (*Base) BringToFront

func (b *Base) BringToFront()

Sets this component to be the last one rendered in it's render parent.

func (*Base) ChildrenUpdated

func (b *Base) ChildrenUpdated()

Marks the children as updated and they required placement and visual updates.

func (*Base) ClearListeners

func (b *Base) ClearListeners()

Removes all listeners (init, place, update, render, remove, post processes, events) from this component.

func (*Base) ComputeRenderContext

func (b *Base) ComputeRenderContext() *RenderContext

Computes the render context for this component looking up through the parents to get the effective text styles and relative to the bounds of this component.

func (*Base) CouldRender

func (b *Base) CouldRender() bool

Returns whether a component could render based on its invisible, animation, and hidden states.

func (*Base) Dirty

func (b *Base) Dirty(dirty Dirty)

Dirties this component and potentially dirties the the parent lineage.

func (*Base) Edit

func (b *Base) Edit(editor func(*Base)) *Base

A handy function for editing the state of a component defined inline.

func (*Base) GetColorable

func (b *Base) GetColorable(t color.Themed) color.Able

Gets the color if any for the themed color.

func (*Base) GetDirty

func (b *Base) GetDirty() Dirty

The current dirty state of this component.

func (*Base) HasPostProcess

func (b *Base) HasPostProcess() bool

Returns whether a component has a post processing function that needs to be applied.

func (*Base) Hide

func (b *Base) Hide()

Hides the component if it's not already hiding or hidden. If a hide animation is defined the animation will play out before the component is hidden and effectively removed from it's render parent's layout.

func (*Base) Init

func (b *Base) Init()

Initializes the state of the component. Before this is done it is expected that the component has been set on a UI and/or has a parent component. This should only be called when the UI is first initialized or on a child component that is added or removed.

func (*Base) IsChild

func (b *Base) IsChild(c *Base) bool

If the component is a child to this component.

func (*Base) IsChildOrSelf

func (b *Base) IsChildOrSelf(c *Base) bool

If the component is a child to this component or is this component.

func (Base) IsDisabled

func (b Base) IsDisabled() bool

Returns whether this component is any disabled states.

func (Base) IsDraggable

func (b Base) IsDraggable() bool

Returns whether this component is draggable. It must be marked draggable and it cannot be in a state where it doesn't receive input events.

func (*Base) IsDragging

func (b *Base) IsDragging() bool

Returns if this component is the one currently being drug.

func (Base) IsDroppable

func (b Base) IsDroppable() bool

Returns whether this component is droppable. It must be marked droppable and it cannot be in a state where it doesn't receive input events.

func (Base) IsFocusable

func (b Base) IsFocusable() bool

Returns whether this component is focusable. It must be marked focusable and it cannot be in a state where it doesn't receive input events.

func (Base) IsHidden

func (b Base) IsHidden() bool

Returns if this component is considered hidden. It is only hidden when hiding is done and it's not trying to show.

func (*Base) IsInside

func (b *Base) IsInside(pt gfx.Coord) bool

Returns true if the point is inside the Bounds of this component. The point is expected to be transformed to the relative orientation of this component. If an OverShape is defined then point-in-polygon logic is used to determine inside-ness.

func (*Base) IsInvisible

func (b *Base) IsInvisible() bool

Returns whether this component is invisible based on its transparency or color.

func (*Base) IsParent

func (b *Base) IsParent(p *Base) bool

If the component is a parent to this component.

func (*Base) IsParentOrSelf

func (b *Base) IsParentOrSelf(p *Base) bool

If the component is a parent to this component or is this component.

func (*Base) IsRenderParent

func (b *Base) IsRenderParent(child *Base) bool

Returns true if this component is the render parent to the given component.

func (Base) IsShown

func (b Base) IsShown() bool

Returns if this component is considered shown (not hidden). It may be in the process of showing or hiding and still be considered shown.

func (*Base) OnBlur

func (b *Base) OnBlur(ev *Event)

Handles a blur event. Updates state and plays any necessary animations.

func (*Base) OnDrag

func (b *Base) OnDrag(ev *DragEvent)

Handles a drag or drop event. Updates state and plays any necessary animations.

func (*Base) OnFocus

func (b *Base) OnFocus(ev *Event)

Handles a focus event. Updates state and plays any necessary animations.

func (*Base) OnKey

func (b *Base) OnKey(ev *KeyEvent)

Handles a key event. This is only invoked when this component or one of its children are focused.

func (*Base) OnPointer

func (b *Base) OnPointer(ev *PointerEvent)

Handles a pointer event. This is only invoked when the pointer is over this component or one of it's children. Updates state, plays any necessary animations, and can update the cursor.

func (*Base) Order

func (b *Base) Order() int

Returns index this component is in it's render parent's children. Any hidden components in the parent are not adjusted for to maintain consistent ordering.

func (*Base) Parent

func (b *Base) Parent() *Base

The parent of this component, if any.

func (*Base) Place

func (b *Base) Place(ctx *RenderContext, parent Bounds, force bool)

Places this component within the given bounds. If the component does not have any dirty placements this may have no effect unless force is passed with true which will cause all components in the tree to be placed. The context is expected to have the size that matches the dimensions of the parent bounds passed.

func (*Base) PlaceMinHeight

func (b *Base) PlaceMinHeight()

Updates the components placement to be the smallest height possible for the current width and the given render context.

func (*Base) PlaceMinWidth

func (b *Base) PlaceMinWidth()

Updates the components placement to be the smallest width possible.

func (*Base) PlaceWidth

func (b *Base) PlaceWidth(width float32)

Updates the components placement to be the desired width if possible.

func (*Base) PlaceWidthFor

func (b *Base) PlaceWidthFor(width float32, ctx *RenderContext)

Updates the components placement to be the desired width if possible for the given render context.

func (*Base) Play

func (b *Base) Play(factory AnimationFactory) bool

func (*Base) PlayEvent

func (b *Base) PlayEvent(ev AnimationEvent) bool

func (*Base) PlayMaybe

func (b *Base) PlayMaybe(name string) bool

func (*Base) PlayName

func (b *Base) PlayName(name id.Identifier) bool

func (*Base) PostProcess

func (b *Base) PostProcess(ctx *RenderContext, out *VertexBuffers)

Performs the post processing that's defined on this component to the given vertex buffers.

func (*Base) PreferredSize

func (b *Base) PreferredSize(ctx *RenderContext, maxWidth float32) gfx.Coord

PreferredSize computes the preferred size possibly given a width we are fitting this component into. If maxWidth = 0 then the preferred size return will present one with a minimum possible width.

func (*Base) Relayout

func (b *Base) Relayout()

Marks the component's layout as dirty so its children are layed out next placement.

func (*Base) Remove

func (b *Base) Remove()

Removes the component if it's not already removed or removing. If a remove animation is defined the animation will play out before the component is actually removed from the parent & render parent. On removal much of the cached state of the component is freed until the component is Init again by a new parent.

func (*Base) RemoveStates

func (b *Base) RemoveStates(state State)

Removes the given states from the component. See SetState. This operation has no effect if the state is unchanged.

func (*Base) Render

func (b *Base) Render(ctx *RenderContext, queue *VertexQueue)

Renders a component and adds all buffers to the given queue. If the component is not visible this returns immediately. This will use cached buffers if possible, otherwise they may need to be regenerated. If this component has any post processing then the vertices applied to the queue by this component are cloned and post processing is applied to the clones to preserve the cached state.

func (*Base) Rerender

func (b *Base) Rerender()

Marks the component as visually dirty (layers, children, & post processing) so it's rendered on next render.

func (*Base) SendToBack

func (b *Base) SendToBack()

Sets this component to be the first one rendered in it's render parent.

func (*Base) SetBounds

func (b *Base) SetBounds(newBounds Bounds) bool

Sets the bounds of the component. If the bounds are different then each layer is placed with the new bounds. If the component does not currently have a dirty placement it is added. The component is also marked visually dirty. Returns whether the bounds have changed.

func (*Base) SetClip

func (b *Base) SetClip(clip Placement)

Sets the clip placement of the children and marks the child placement as dirty if the placement is different. All parents are notified they have a dirty child placement.

func (*Base) SetColor

func (b *Base) SetColor(color color.Modify)

Sets the color modification function that's applied to all vertices of this component and marks the post processing as dirty if the modification function appears to be different. All parents are notified they have a dirty child visual.

func (*Base) SetDisabled

func (b *Base) SetDisabled(disabled bool)

Sets the disabled state of this component. Any associated disabled or enabled animations will be played if there is a change in state.

func (*Base) SetOrder

func (b *Base) SetOrder(order int)

Sets the index this component is in it's render parent's children. Any hidden components in the parent are not adjusted for to maintain consistent ordering.

func (*Base) SetPlacement

func (b *Base) SetPlacement(placement Placement)

Sets the placement of the component and marks the placement as dirty if the placement is different. All parents are notified they have a dirty child placement.

func (*Base) SetRelativePlacement

func (b *Base) SetRelativePlacement(placement Placement)

Sets the relative placement of the component and marks the placement as dirty if the placement is different. All parents are notified they have a dirty child placement.

func (*Base) SetRenderParent

func (b *Base) SetRenderParent(parent *Base)

Changes the render parent of this component. You can have a component exist in one tree which decides its initial placement but actually be considered outside its parent and rendered under another. The ordering, final layout, and rendering is done by the render parent. You can pass nil to this to reset it back to the parent and remove from the current render parent.

func (*Base) SetState

func (b *Base) SetState(state State)

Sets the state of the component. If no state is given the default state is applied. If the component is not visually dirty the state change is checked against the layers and if any of the layers is shown/hidden based on the state change the component is marked visually dirty. If post processing exists for the new state the component is marked dirty for post processing.

func (*Base) SetTransform

func (b *Base) SetTransform(transform Transform)

Sets the transform of the component and marks the post processing as dirty if the transform is different. All parents are notified they have a dirty child visual.

func (*Base) SetTransparency

func (b *Base) SetTransparency(transparency float32)

Sets the transparency of the component and marks the post processing as dirty if the transparency is different. All parents are notified they have a dirty child visual.

func (*Base) SetVisible

func (b *Base) SetVisible(show bool)

Sets the visibility of this component to either show or hide. See Show & Hide.

func (*Base) Show

func (b *Base) Show()

Shows the component if it's not already shown or showing. If a show animation is defined the animation will play out before the component is considered shown and can be interacted with. As soon as the showing process begins it's effectively added back to its render parent in the same position it previously was in it's layout.

func (*Base) ShownChildren

func (b *Base) ShownChildren() []*Base

Returns the children that are rendered by this component.

func (*Base) UI

func (b *Base) UI() *UI

The UI this component belongs to.

func (*Base) Update

func (b *Base) Update(update Update)

Updates the component. This includes it's layers, children, animation, and hooks. Each can return a dirty state which is applied to the component. A child is only updated by its parent, never by its render parent. If the component is hidden and UI.UpdateHidden is false then this has no effect. A component that is playing a hide, show, or remove animation needs to be updated to complete the desired action.

type BaseGlyph

type BaseGlyph struct {
	Text  rune
	Font  id.Identifier
	Size  Amount
	Color color.Color
	// contains filtered or unexported fields
}

func (*BaseGlyph) GetState

func (g *BaseGlyph) GetState(ctx *RenderContext, wrap TextWrap, prev Glyph) GlyphState

func (*BaseGlyph) Render

func (g *BaseGlyph) Render(ctx *RenderContext, topLeft gfx.Coord, b *Base) RenderedGlyph

func (BaseGlyph) String

func (g BaseGlyph) String() string

type BasicAnimation

type BasicAnimation struct {
	Duration             float32
	Easing               ease.Easing
	Save                 bool
	SaveSkipColor        bool
	SaveSkipTransparency bool
	SaveSkipTransform    bool
	Frames               []BasicAnimationFrame
}

func (BasicAnimation) Copy

func (a BasicAnimation) Copy() BasicAnimation

func (BasicAnimation) GetAnimation

func (a BasicAnimation) GetAnimation(b *Base) Animation

func (BasicAnimation) GetProps

func (a BasicAnimation) GetProps() BasicAnimationProp

func (BasicAnimation) IndexForTime

func (a BasicAnimation) IndexForTime(time float32) int

func (BasicAnimation) Init

func (a BasicAnimation) Init(base *Base)

func (BasicAnimation) IsDone

func (a BasicAnimation) IsDone(base *Base, animationTime float32) bool

func (BasicAnimation) Merge

func (BasicAnimation) Only

func (BasicAnimation) PostProcess

func (a BasicAnimation) PostProcess(base *Base, animationTime float32, ctx *RenderContext, out *VertexBuffers)

func (BasicAnimation) PreLerpForTime

func (a BasicAnimation) PreLerpForTime(time float32) BasicAnimationFrame

func (BasicAnimation) Reverse

func (a BasicAnimation) Reverse() BasicAnimation

func (BasicAnimation) Update

func (a BasicAnimation) Update(base *Base, animationTime float32, update Update) Dirty

func (BasicAnimation) WithDuration

func (a BasicAnimation) WithDuration(duration float32) BasicAnimation

func (BasicAnimation) WithEasing

func (a BasicAnimation) WithEasing(easing ease.Easing) BasicAnimation

func (BasicAnimation) WithNoSave

func (a BasicAnimation) WithNoSave() BasicAnimation

func (BasicAnimation) WithSave

func (a BasicAnimation) WithSave(save, skipColor, skipTransparent, skipTransform bool) BasicAnimation

func (BasicAnimation) Without

type BasicAnimationFrame

type BasicAnimationFrame struct {
	Translate    AmountPoint
	Scale        *gfx.Coord
	Rotate       float32
	Origin       AmountPoint
	Time         float32
	Color        color.Modify
	Transparency float32
	Easing       ease.Easing
}

func (BasicAnimationFrame) Lerp

func (BasicAnimationFrame) PreLerp

type BasicAnimationFrameInterpolated

type BasicAnimationFrameInterpolated struct {
	ScaleX, ScaleY         float32
	OriginX, OriginY       float32
	TranslateX, TranslateY float32
	Rotation               float32
	Color                  color.Modify
	Transparency           float32
}

func (BasicAnimationFrameInterpolated) Transform

func (inter BasicAnimationFrameInterpolated) Transform() Transform

type BasicAnimationProp

type BasicAnimationProp int
const (
	BasicAnimationPropScale BasicAnimationProp = 1 << iota
	BasicAnimationPropOrigin
	BasicAnimationPropTranslate
	BasicAnimationPropRotate
	BasicAnimationPropColor
	BasicAnimationPropTransparency
	BasicAnimationPropEasing
)

type BasicTextAnimation

type BasicTextAnimation struct {
	Settings []BasicTextAnimationSettings
	Easing   ease.Easing
	// contains filtered or unexported fields
}

func (*BasicTextAnimation) EasedTime

func (a *BasicTextAnimation) EasedTime(time float32) float32

func (BasicTextAnimation) GetAnimation

func (a BasicTextAnimation) GetAnimation(text *RenderedText) TextAnimation

func (*BasicTextAnimation) GetStates

func (*BasicTextAnimation) Init

func (a *BasicTextAnimation) Init(base *Base)

func (*BasicTextAnimation) IsDone

func (a *BasicTextAnimation) IsDone(base *Base, animationTime float32) bool

func (*BasicTextAnimation) Render

func (a *BasicTextAnimation) Render(b *Base, animationTime float32, bounds Bounds, ctx *RenderContext, out *VertexBuffer)

func (*BasicTextAnimation) Update

func (a *BasicTextAnimation) Update(b *Base, animationTime float32, update Update) Dirty

func (*BasicTextAnimation) ValueAt

func (a *BasicTextAnimation) ValueAt(time float32) (state int, value int, timeInValue float32)

type BasicTextAnimationKind

type BasicTextAnimationKind int
const (
	BasicTextAnimationKindChar BasicTextAnimationKind = iota
	BasicTextAnimationKindWord
	BasicTextAnimationKindLine
	BasicTextAnimationKindParagraph
	BasicTextAnimationKindColumn
)

func (BasicTextAnimationKind) Get

type BasicTextAnimationSettings

type BasicTextAnimationSettings struct {
	// How to break up the text into pieces to animate
	Kind BasicTextAnimationKind
	// The frames to animate over the given duration for a piece
	Frames []BasicAnimationFrame
	// How long to animate a piece
	Duration float32
	// How long between starting each piece animation
	Delay float32
	// Optional easing function for determining the frame
	Easing ease.Easing
	// The index of the glyph to start at
	Start int
}

func (BasicTextAnimationSettings) GetFrames

func (s BasicTextAnimationSettings) GetFrames(time float32) (first int, delta float32)

func (BasicTextAnimationSettings) GetState

func (s BasicTextAnimationSettings) GetState(text *RenderedText, endExclusive int) BasicTextAnimationState

type BasicTextAnimationState

type BasicTextAnimationState struct {
	Start, End int
	Min, Max   int
	Total      int
	Duration   float32
}

type Bounds

type Bounds struct {
	Left, Top, Right, Bottom float32
}

func NewBounds

func NewBounds(left, top, right, bottom float32) Bounds

func (Bounds) Add

func (b Bounds) Add(a Bounds) Bounds

func (Bounds) Center

func (b Bounds) Center() (float32, float32)

func (*Bounds) Clear

func (b *Bounds) Clear()

func (Bounds) ClipCoord

func (b Bounds) ClipCoord(c gfx.Coord) gfx.Coord

func (Bounds) ClipLine

func (b Bounds) ClipLine(x0, y0, x1, y1 float32) ClippedLine

func (Bounds) Closest

func (b Bounds) Closest(x, y float32) (float32, float32)

func (Bounds) ClosestCoord

func (b Bounds) ClosestCoord(c gfx.Coord) gfx.Coord

func (Bounds) Contains

func (b Bounds) Contains(a Bounds) bool

func (Bounds) Delta

func (b Bounds) Delta(x, y float32) (float32, float32)

func (Bounds) Dimensions

func (b Bounds) Dimensions() (float32, float32)

func (Bounds) Dx

func (b Bounds) Dx(x float32) float32

func (Bounds) Dy

func (b Bounds) Dy(y float32) float32

func (Bounds) Expand

func (b Bounds) Expand(a Bounds) Bounds

func (Bounds) Height

func (b Bounds) Height() float32

func (*Bounds) Include

func (b *Bounds) Include(x, y float32)

func (Bounds) Inside

func (b Bounds) Inside(x, y float32) bool

func (Bounds) InsideCoord

func (b Bounds) InsideCoord(c gfx.Coord) bool

func (Bounds) Intersects

func (b Bounds) Intersects(a Bounds) bool

func (Bounds) IsEmpty

func (b Bounds) IsEmpty() bool

func (Bounds) IsNegative

func (b Bounds) IsNegative() bool

func (Bounds) IsPositive

func (b Bounds) IsPositive() bool

func (Bounds) IsUniform

func (b Bounds) IsUniform() bool

func (Bounds) IsZero

func (b Bounds) IsZero() bool

func (Bounds) Lerp

func (b Bounds) Lerp(x, y float32) (float32, float32)

func (Bounds) Lerpx

func (b Bounds) Lerpx(dx float32) float32

func (Bounds) Lerpy

func (b Bounds) Lerpy(dy float32) float32

func (Bounds) Scale

func (b Bounds) Scale(s float32) Bounds

func (Bounds) Side

func (b Bounds) Side(x, y float32) BoundsSide

func (Bounds) SideInside

func (b Bounds) SideInside(x, y float32, side BoundsSide) bool

func (Bounds) SideIntersect

func (b Bounds) SideIntersect(x0, y0, x1, y1 float32, side BoundsSide) (x, y, delta float32)

func (Bounds) Size

func (b Bounds) Size() gfx.Coord

func (Bounds) String

func (b Bounds) String() string

func (Bounds) Sub

func (b Bounds) Sub(a Bounds) Bounds

func (*Bounds) Translate

func (b *Bounds) Translate(x, y float32)

func (Bounds) Union

func (b Bounds) Union(a Bounds) Bounds

func (Bounds) Width

func (b Bounds) Width() float32

type BoundsSide

type BoundsSide int
const (
	BoundsSideNone BoundsSide = (1 << iota) >> 1
	BoundsSideLeft
	BoundsSideTop
	BoundsSideRight
	BoundsSideBottom

	BoundsSideAll = BoundsSideLeft | BoundsSideTop | BoundsSideRight | BoundsSideBottom
)

type CanStop

type CanStop interface {
	Stopped() bool
}

type ClipShow

type ClipShow int
const (
	ClipShowNone ClipShow = iota
	ClipShowLeft
	ClipShowRight
	ClipShowTop
	ClipShowBottom
)

func (ClipShow) MarshalText

func (a ClipShow) MarshalText() ([]byte, error)

func (*ClipShow) UnmarshalText

func (c *ClipShow) UnmarshalText(text []byte) error

type ClippedLine

type ClippedLine struct {
	Start      gfx.Coord
	StartDelta float32
	StartSide  BoundsSide
	End        gfx.Coord
	EndDelta   float32
	EndSide    BoundsSide
	Outside    bool
}

func (ClippedLine) Inside

func (cl ClippedLine) Inside() bool

type ComponentMap

type ComponentMap struct {
	// contains filtered or unexported fields
}

func NewComponentMap

func NewComponentMap() ComponentMap

func (*ComponentMap) Add

func (cm *ComponentMap) Add(c *Base)

func (*ComponentMap) AddLineage

func (cm *ComponentMap) AddLineage(c *Base)

func (*ComponentMap) AddMany

func (cm *ComponentMap) AddMany(c []*Base)

func (ComponentMap) Compare

func (old ComponentMap) Compare(new ComponentMap) (inOld []*Base, inBoth []*Base, inNew []*Base)

func (ComponentMap) Components

func (cm ComponentMap) Components() []*Base

func (ComponentMap) Has

func (cm ComponentMap) Has(c *Base) bool

type CursorEvent

type CursorEvent uint8
const (
	CursorEventHover CursorEvent = iota
	CursorEventDown
	CursorEventDrag
	CursorEventDisabled
)

type Cursors

type Cursors struct {
	ds.EnumMap[CursorEvent, id.Identifier]
}

func NewCursors

func NewCursors(m map[CursorEvent]id.Identifier) Cursors

func (Cursors) HandleDrag

func (c Cursors) HandleDrag(ev *DragEvent, b *Base)

func (Cursors) HandlePointer

func (c Cursors) HandlePointer(ev *PointerEvent, b *Base)

func (Cursors) OverCursor

func (c Cursors) OverCursor(b *Base, ignoreDragging bool) id.Identifier

type Dirty

type Dirty = Flags

The possible dirty states of a component. Dirty states are used to keep track of what operations needs to be done (if at all) on component Place and Render. If a component tree is not animating or has a post processing state (for example) then render/clipping logic can be avoided for the current frame and cached render data can be used.

const (
	// No dirty state
	DirtyNone Dirty = (1 << iota) >> 1
	// The components placement in its parent has changed. After placement is done if the
	// bounds of the component has changed the visual is also marked dirty.
	DirtyPlacement
	// The components layers need to be rendered.
	DirtyVisual
	// The components children had placement changed and need to be layout and placed again.
	DirtyChildPlacement
	// The components children had its layer, children, or post processing changed.
	DirtyChildVisual
	// The component's post processing has changed and needs to be processed again.
	DirtyPostProcess
)

func (Dirty) ParentDirty

func (d Dirty) ParentDirty() Dirty

Converts this Dirty into what should be added to the parent's Dirty state. If the placement is dirty, then the parent state will have DirtyChildPlacement. If the visual is dirty, then the parent state will have DirtyChildVisual. If the post process is dirty, then the parent state will have DirtyChildVisual.

type DragEvent

type DragEvent struct {
	Event
	Point      gfx.Coord
	Start      gfx.Coord
	DeltaStart gfx.Coord
	DeltaMove  gfx.Coord
	Type       DragEventType
	Dragging   *Base
	*HasCursor
}

type DragEventType

type DragEventType int
const (
	DragEventStart DragEventType = iota
	DragEventMove
	DragEventEnd
	DragEventCancel
	DragEventOver
	DragEventDrop
)

type Event

type Event struct {
	Time    time.Time
	Stop    bool
	Capture bool
	Cancel  bool
	Target  *Base
}

func (*Event) PreventDefault

func (e *Event) PreventDefault()

func (*Event) StopPropagation

func (e *Event) StopPropagation()

func (*Event) Stopped

func (e *Event) Stopped() bool

type Events

type Events struct {
	OnPointer Listener[*PointerEvent]
	OnKey     Listener[*KeyEvent]
	OnFocus   Listener[*Event]
	OnBlur    Listener[*Event]
	OnDrag    Listener[*DragEvent]
}

func (*Events) Add

func (e *Events) Add(add Events, before bool)

func (*Events) Clear

func (e *Events) Clear()

type ExtentTile

type ExtentTile struct {
	gfx.Tile
	Extent Bounds
}

func NewExtentTile

func NewExtentTile(tile gfx.Tile, extent Bounds) ExtentTile

type Flags

type Flags uint64

func (*Flags) Add

func (f *Flags) Add(other Flags)

func (Flags) All

func (f Flags) All(other Flags) bool

func (Flags) Any

func (f Flags) Any() bool

func (*Flags) Clear

func (f *Flags) Clear()

func (Flags) Exactly

func (f Flags) Exactly(other Flags) bool

func (Flags) Is

func (f Flags) Is(other Flags) bool

func (Flags) None

func (f Flags) None() bool

func (Flags) Not

func (f Flags) Not(other Flags) bool

func (Flags) NotAll

func (f Flags) NotAll(other Flags) bool

func (*Flags) Remove

func (f *Flags) Remove(other Flags)

func (*Flags) Removed

func (f *Flags) Removed(other Flags) bool

func (*Flags) Take

func (f *Flags) Take() Flags

func (Flags) WithAdd

func (f Flags) WithAdd(other Flags) Flags

func (Flags) WithRemove

func (f Flags) WithRemove(other Flags) Flags

type Font

type Font struct {
	// The name of the font
	Name string
	// The texture of the font
	Texture string
	// The lineheight relative to the font size. 1.0=matches font-size
	LineHeight float32
	// Within a line how far down is the baseline from the top relative to the font size.
	Baseline float32
	// Data about each rune in the font
	Runes map[rune]FontRune
	// Kerning data when run B follows rune A
	Kerning map[rune]map[rune]float32
}

func (Font) GetKerning

func (f Font) GetKerning(prev rune, next rune) float32

type FontRune

type FontRune struct {
	// The extends around the baseline point at the start of the font rune
	ExtentTile
	// The advance width of the rune
	Width float32
}

type Glyph

type Glyph interface {
	GetState(ctx *RenderContext, wrap TextWrap, prev Glyph) GlyphState
	Render(ctx *RenderContext, start gfx.Coord, base *Base) RenderedGlyph
	String() string
}

type GlyphState

type GlyphState struct {
	Size        gfx.Coord
	CanBreak    bool
	ShouldBreak bool
	Empty       bool
}

type GlyphVisibility

type GlyphVisibility int
const (
	GlyphVisibilityVisible GlyphVisibility = iota
	GlyphVisibilityPartial
	GlyphVisibilityInvisible
)

type HasCursor

type HasCursor struct {
	Cursor        *id.Identifier
	CursorSet     bool
	CursorTrigger *Base
}

func (*HasCursor) RemoveCursor

func (ev *HasCursor) RemoveCursor(cursor id.Identifier)

func (*HasCursor) SetCursor

func (ev *HasCursor) SetCursor(cursor id.Identifier, trigger *Base, force bool)

type HookBase

type HookBase func(b *Base)

func (*HookBase) Add

func (h *HookBase) Add(add HookBase, before bool)

func (*HookBase) Clear

func (h *HookBase) Clear()

func (HookBase) Run

func (h HookBase) Run(b *Base)

type HookPlace

type HookPlace func(b *Base, parent Bounds, ctx *RenderContext, force bool)

func (*HookPlace) Add

func (h *HookPlace) Add(add HookPlace, before bool)

func (*HookPlace) Clear

func (h *HookPlace) Clear()

func (HookPlace) Run

func (h HookPlace) Run(b *Base, parent Bounds, ctx *RenderContext, force bool)

type HookRender

type HookRender func(b *Base, ctx *RenderContext, out *VertexQueue)

func (*HookRender) Add

func (h *HookRender) Add(add HookRender, before bool)

func (*HookRender) Clear

func (h *HookRender) Clear()

type HookUpdate

type HookUpdate func(b *Base, update Update) Dirty

func (*HookUpdate) Add

func (h *HookUpdate) Add(add HookUpdate, before bool)

func (*HookUpdate) Clear

func (h *HookUpdate) Clear()

func (HookUpdate) Run

func (h HookUpdate) Run(b *Base, update Update)

type Hooks

type Hooks struct {
	OnInit                HookBase
	OnPlace               HookPlace
	OnUpdate              HookUpdate
	OnRender              HookRender
	OnRemove              HookBase
	OnPostProcess         PostProcess
	OnPostProcessLayers   PostProcess
	OnPostProcessChildren PostProcess
}

func (*Hooks) Add

func (h *Hooks) Add(add Hooks, before bool)

func (*Hooks) Clear

func (h *Hooks) Clear()

type IndexIterator

type IndexIterator = buf.IndexIterator[Vertex, VertexBuffer]

func NewIndexIterator

func NewIndexIterator(iterable buf.Iterable[Vertex, VertexBuffer], beginning bool) IndexIterator

type KeyEvent

type KeyEvent struct {
	Event
	Key  string
	Char rune
	Type KeyEventType
}

type KeyEventType

type KeyEventType int
const (
	KeyEventDown KeyEventType = iota
	KeyEventUp
	KeyEventPress
)

type Layer

type Layer struct {
	Placement  Placement
	Bounds     Bounds
	Visual     Visual
	Background Background
	States     StateFn
}

func (Layer) ComputeRenderContext

func (l Layer) ComputeRenderContext(b *Base) *RenderContext

func (Layer) ForStates

func (l Layer) ForStates(s State) bool

func (*Layer) Init

func (l *Layer) Init(b *Base)

func (*Layer) Place

func (l *Layer) Place(b *Base, parent Bounds)

func (Layer) PreferredSize

func (l Layer) PreferredSize(b *Base, ctx *RenderContext, maxWidth float32) gfx.Coord

func (Layer) Render

func (l Layer) Render(b *Base, ctx *RenderContext, out *VertexBuffers)

func (*Layer) Update

func (l *Layer) Update(b *Base, update Update) Dirty

type Layout

type Layout interface {
	Init(b *Base)
	PreferredSize(b *Base, ctx *RenderContext, maxWidth float32, layoutable []*Base) gfx.Coord
	Layout(b *Base, ctx *RenderContext, bounds Bounds, layoutable []*Base)
}

type LayoutColumn

type LayoutColumn struct {
	FullWidth           bool
	FullHeight          bool
	EqualWidths         bool
	HorizontalAlignment Alignment
	Spacing             Amount
}

A layout which places all children in a column (vertical stack). The children can have their width expanded to the full width or default to their preferred size. If they are not expanded to full width they can be horizontally aligned. Optionally the size inferred by the placement can be factored into the preferred size as well (it's not by default).

func (LayoutColumn) Init

func (l LayoutColumn) Init(b *Base)

func (LayoutColumn) Layout

func (l LayoutColumn) Layout(b *Base, ctx *RenderContext, bounds Bounds, layoutable []*Base)

func (LayoutColumn) PreferredSize

func (l LayoutColumn) PreferredSize(b *Base, ctx *RenderContext, maxWidth float32, layoutable []*Base) gfx.Coord

type LayoutData

type LayoutData struct {
	// The weight for the width when the layout is stretched.
	WidthWeight float32
	// Each cell component is expanded to the column width
	FullWidth *bool
	// When FullWidth is false, how to align the cell component horizontally in the cell
	HorizontalAlignment *Alignment
	// The weight for the height when the layout is stretched.
	HeightWeight float32
	// Each cell component is expanded to the row height
	FullHeight *bool
	// When FullHeight is false, how to align the cell component veritcally in the cell
	VerticalAlignment *Alignment
	// For certain layouts, should the preferred size be enforced?
	EnforcePreferredSize *bool
	// For certain layouts, should the component be moved within the parent's bounds?
	KeepInside              *bool
	KeepInsideForgetSize    *bool
	KeepInsideIgnoreMargins *bool
}

Layout information that can be specified at the component level that a layout may or may not use during placement.

func (LayoutData) WithEnforcePreferredSize

func (ld LayoutData) WithEnforcePreferredSize(enforce bool) LayoutData

func (LayoutData) WithFullHeight

func (ld LayoutData) WithFullHeight(fullHeight bool) LayoutData

func (LayoutData) WithFullWidth

func (ld LayoutData) WithFullWidth(fullWidth bool) LayoutData

func (LayoutData) WithHeightWeight

func (ld LayoutData) WithHeightWeight(heightWeight float32) LayoutData

func (LayoutData) WithHorizontalAlignment

func (ld LayoutData) WithHorizontalAlignment(alignment Alignment) LayoutData

func (LayoutData) WithKeepInside

func (ld LayoutData) WithKeepInside(keepInside bool) LayoutData

func (LayoutData) WithKeepInsideForgetSize

func (ld LayoutData) WithKeepInsideForgetSize(forgetSize bool) LayoutData

func (LayoutData) WithKeepInsideIgnoreMargins

func (ld LayoutData) WithKeepInsideIgnoreMargins(ignoreMargins bool) LayoutData

func (LayoutData) WithVerticalAlignment

func (ld LayoutData) WithVerticalAlignment(alignment Alignment) LayoutData

func (LayoutData) WithWidthWeight

func (ld LayoutData) WithWidthWeight(widthWeight float32) LayoutData

type LayoutGrid

type LayoutGrid struct {
	// The grid will take up the full width of the bounds. May result in ignoring other width settings.
	FullWidth bool
	// The grid will take up the full height of the bounds. May result in ignoring other height settings.
	FullHeight bool
	// How much space between rows
	VerticalSpacing Amount
	// How much space between columns
	HorizontalSpacing Amount
	// Whether the number of columns should be dynamically calculated.
	ColumnsDynamic bool
	// When dynamically calculating columns, this will be the min number of columns in the grid.
	ColumnsMin int
	// When dynamically calculating columns, this will be the max number of columns in the grid.
	ColumnsMax int
	// A value used in determining how many columns should be in the grid when not defined.
	// A value of 0.0 will try to fit as many columns as possible while a value of 1.0 will try to fit as few columns as possible.
	ColumnsDynamicDelta float32
	// If the cell heights should be a ratio of their width. A value of 0.0 has no affect.
	// A value of 0.5 will make the height half the width.
	AspectRatio float32
	// If all the rows in the grid should try to have equal heights. Min/Max heights may interfere with this.
	EqualHeights bool
	// If all the columns in the grid should try to have equal widths. Min/Max widths may interfere with this.
	EqualWidths bool
	// The columns in the grid. You can use Columns or ColumnsMin to control the number of columns in the grid.
	// When the number of column definitions is below the number of columns the last column definition will be used.
	// At least one column is typically defined.
	Columns []LayoutGridColumn
	// The rows in the table. If the table has anymore rows beyond what's defined the last row will be used.
	// At least one row is typically defined.
	Rows []LayoutGridRow
}

A layout which places all children in a grid. The number of columns in the grid can be given or MinWidths can be given with a non-zero X component. That component is used with the spacing and the width of the parent to maintain a dynamic number of columns based on the min width. The width of the cell is evenly distributed is EqualWidths. The height of the cell can be determined by the max preferred size of a child in a row while also using the MinHeights defined on the layout which all can be overridden if a non-zero AspectRatio is defined which will make all rows have the same height respective to the cell width. Alignment of a component within a cell is determine by Vertical and Horizontal alignment, unless FullWidth & FullHeight are given which means the component expands to fit the cell.

func (LayoutGrid) Init

func (l LayoutGrid) Init(b *Base)

func (LayoutGrid) Layout

func (l LayoutGrid) Layout(b *Base, ctx *RenderContext, bounds Bounds, layoutable []*Base)

func (LayoutGrid) PreferredSize

func (l LayoutGrid) PreferredSize(b *Base, ctx *RenderContext, maxWidth float32, layoutable []*Base) gfx.Coord

type LayoutGridColumn

type LayoutGridColumn struct {
	// When stretching the columns to match the width of the bounds - how should each column
	// be stretched? A value of zero will cause no stretching, and non-zero values will be
	// divided up based on the value / the sum of values. One or zero weights will cause
	// the widths to be equally stretched.
	Weight float32
	// Each cell component is expanded to the column width
	FullWidth bool
	// When FullWidth is false, how to align the cell component horizontally in the cell
	HorizontalAlignment Alignment
	// Each cell component is expanded to the row height
	FullHeight *bool
	// When FullHeight is false, how to align the cell component vertically in the cell
	VerticalAlignment *Alignment
	// Defines the min widths for one or all columns.
	Min float32
	// Defines the max widths for one or all columns.
	Max float32
}

A definition for a single column in the table layout.

type LayoutGridRow

type LayoutGridRow struct {
	// When stretching the rows to match the height of the bounds - how should each row
	// be stretched? A value of zero will cause no stretching, and non-zero values will be
	// divided up based on the value / the sum of values. One or zero weights will cause
	// the heights to be equally stretched.
	Weight float32
	// Each cell component is expanded to the row height
	FullHeight bool
	// When FullHeight is false, how to align the cell component veritcally in the cell
	VerticalAlignment Alignment
	// Each cell component is expanded to the column width
	FullWidth *bool
	// When FullWidth is false, how to align the cell component horizontally in the cell
	HorizontalAlignment *Alignment
	// Defines the min heights for one or all rows. If the number of rows extends beyond the number
	// of min heights defined, they will use the last min height defined.
	Min float32
	// Defines the max heights for one or all rows. If the number of rows extends beyond the number
	// of max heights defined, they will use the last max height defined.
	Max float32
}

A definition for a single row in the table layout.

type LayoutInline

type LayoutInline struct {
	// The default vertical alignment of a component in a line.
	LineVerticalAlignment Alignment
	// The default horizontal alignment of a component in a stretched out
	// line in the parent component. This is only used when FullWidth=true
	// and LineFullWidth=false.
	LineHorizontalAlignment Alignment
	// The alignment of all the lines in the parent component.
	VerticalAlignment Alignment
	// The alignment of all the lines in the parent component.
	HorizontalAlignment Alignment
	// The spacing between each line.
	VerticalSpacing Amount
	// The spacing between each component in a line.
	HorizontalSpacing Amount
	// If all the components in a given line share the same height.
	LineFullHeight bool
	// If all the components in a given line take up the full width available.
	// This only has an effect when FullWidth is true.
	LineFullWidth bool
	// If all the lines share the same height.
	EqualHeights bool
	// If all components in a line should share the same width
	LineEqualWidths bool
	// If the layout should stretch the lines to the height of the parent.
	// The height weights of the components are used to stretch and if none are
	// defined then they are all equally stretched.
	FullHeight bool
	// If the layout should stretch the lines to the width of the parent.
	// The width weights of the components are used to stretch and if none are
	// defined then they are all equally stretched.
	FullWidth bool
}

A layout which places all children on after another and wraps them if it can't fit in a line.

func (LayoutInline) Init

func (l LayoutInline) Init(b *Base)

func (LayoutInline) Layout

func (l LayoutInline) Layout(b *Base, ctx *RenderContext, bounds Bounds, layoutable []*Base)

func (LayoutInline) PreferredSize

func (l LayoutInline) PreferredSize(b *Base, ctx *RenderContext, maxWidth float32, layoutable []*Base) gfx.Coord

type LayoutRow

type LayoutRow struct {
	FullHeight        bool
	FullWidth         bool
	EqualHeights      bool
	VerticalAlignment Alignment
	Spacing           Amount
	ExpandRight       bool
}

A layout which places all children in a row (horizontal stack). The children can have their height expanded to the full height or default to their preferred size. If they are not expanded to full height they can be vertically aligned. Optionally the size inferred by the placement can be factored into the preferred size as well (it's not by default).

func (LayoutRow) Init

func (l LayoutRow) Init(b *Base)

func (LayoutRow) Layout

func (l LayoutRow) Layout(b *Base, ctx *RenderContext, bounds Bounds, layoutable []*Base)

func (LayoutRow) PreferredSize

func (l LayoutRow) PreferredSize(b *Base, ctx *RenderContext, maxWidth float32, layoutable []*Base) gfx.Coord

type LayoutSizing

type LayoutSizing struct {
	FullWidth, FullHeight float32
	Width, Height         float32
	OffsetX, OffsetY      float32
	Data                  *LayoutData
}

func (LayoutSizing) HeightPadding

func (ls LayoutSizing) HeightPadding() float32

func (*LayoutSizing) SetFullHeight

func (ls *LayoutSizing) SetFullHeight(fullHeight float32)

func (*LayoutSizing) SetFullWidth

func (ls *LayoutSizing) SetFullWidth(fullWidth float32)

func (LayoutSizing) WidthPadding

func (ls LayoutSizing) WidthPadding() float32

type LayoutSizings

type LayoutSizings struct {
	Sizings                 []LayoutSizing
	MaxWidth, MaxHeight     float32
	TotalWidth, TotalHeight float32
	TotalWidthWeight        float32
	TotalHeightWeight       float32
}

func (LayoutSizings) GetHeightWeight

func (ls LayoutSizings) GetHeightWeight(i int) float32

func (LayoutSizings) GetWidthWeight

func (ls LayoutSizings) GetWidthWeight(i int) float32

type LayoutStatic

type LayoutStatic struct {
	EnforcePreferredSize    bool
	KeepInside              bool
	KeepInsideForgetSize    bool
	KeepInsideIgnoreMargins bool
}

A layout which uses the defined placements on each child but can help with enforcing their preferred size and keeping them in the parent. Perfect for open spaces with draggable components.

func (LayoutStatic) Init

func (l LayoutStatic) Init(b *Base)

func (LayoutStatic) Layout

func (l LayoutStatic) Layout(b *Base, ctx *RenderContext, bounds Bounds, layoutable []*Base)

func (LayoutStatic) PreferredSize

func (l LayoutStatic) PreferredSize(b *Base, ctx *RenderContext, maxWidth float32, layoutable []*Base) gfx.Coord

type Layoutable

type Layoutable interface {
	Placement() Placement
	Margin() Bounds
	MinSize() gfx.Coord
}

type Listener

type Listener[E CanStop] func(ev E)

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 Paragraph

type Paragraph struct {
	Styles *ParagraphStylesOverride
	Glyphs []Glyph
}

func (Paragraph) GetLineHeight

func (paragraph Paragraph) GetLineHeight(ctx *RenderContext, style *ParagraphStyles, actualLineHeight float32) float32

func (Paragraph) GetStates

func (paragraph Paragraph) GetStates(ctx *RenderContext, style *ParagraphStyles) []GlyphState

func (Paragraph) Measure

func (paragraph Paragraph) Measure(ctx *RenderContext, paragraphs Paragraphs) gfx.Coord

func (Paragraph) MinWidth

func (paragraph Paragraph) MinWidth(ctx *RenderContext, keepEmpty bool) float32

func (Paragraph) Render

func (paragraph Paragraph) Render(ctx *RenderContext, paragraphs Paragraphs, b *Base) RenderedText

func (Paragraph) String

func (paragraph Paragraph) String() string

type ParagraphStyles

type ParagraphStyles struct {
	Spacing               Amount       // extra space between glyphs TODO
	LineSpacing           Amount       // extra space between lines
	LineHeight            Amount       // 0=calculated per line
	LineVerticalAlignment Alignment    // 0=top, 0.5=middle, 1=bottom
	Indent                Amount       // shift first line in a wrappable line
	HorizontalAlignment   Alignment    // 0=left, 0.5=middle, 1=right
	Wrap                  TextWrap     // when we are going beyond the width, how do we decide to wrap
	ParagraphPadding      AmountBounds // padding around the paragraph
}

func (*ParagraphStyles) Override

type ParagraphStylesOverride

type ParagraphStylesOverride struct {
	Spacing               *Amount       // extra space between glyphs
	LineSpacing           *Amount       // extra space between lines
	LineHeight            *Amount       // 0=calculated per line
	LineVerticalAlignment *Alignment    // 0=top, 0.5=middle, 1=bottom
	Indent                *Amount       // shift first line in a wrappable line
	HorizontalAlignment   *Alignment    // 0=left, 0.5=middle, 1=right
	Wrap                  *TextWrap     // when we are going beyond the width, how do we decide to wrap
	ParagraphPadding      *AmountBounds // padding around the paragraph
}

func (*ParagraphStylesOverride) Clone

func (*ParagraphStylesOverride) HasOverride

func (o *ParagraphStylesOverride) HasOverride() bool

type Paragraphs

type Paragraphs struct {
	Styles     *ParagraphsStylesOverride
	Paragraphs []Paragraph
	MaxWidth   float32
	MaxHeight  float32
	KeepEmpty  bool
}

func MustTextToParagraphs

func MustTextToParagraphs(text string) Paragraphs

func TextToParagraphs

func TextToParagraphs(text string) (paragraphs Paragraphs, err error)

Parses text and converts it to glyphs using a special format. In the text you can set: - font = {f:name} or {f:} to reset to default - color = {c:#RRGGBB} or {c:#RRGGBBAA} or {c:red} or {c:} to reset to default - size = {s:12} or {s:50%} or {s:} to reset to default - new paragraph = {p} or {p:reset} to reset paragraph style - set kerning to paragraph = {k:5} - set horizontal alignment in paragraph = {h:0.5} - set vertical alignment within a line in paragraph = {v:0} - set wrap in paragraph = {w:none} or {w:word} or {w:char} - set line spacing in paragraph = {ls:10} - set line height in paragraph = {lh:10} or {lh:120%} - set indent = {i:5em} - set padding in paragraph = {pa:10} or {pl:10%} or {pr:0} or {pb} or {pt:} - set spacing between paragraphs = {ps:10} - set vertical alignment of paragraphs in area = {pv:0.5} - set max height in area = {mh:100} - set max width in area = {mw:100} - set clip show x in area = {cx} aka {cx:} aka {cx:none} or {cx:left} or {cx:right} - set clip show y in area = {cy} aka {cy:} aka {cy:none} or {cy:top} or {cy:bottom}

Ex: "Hello {f:roboto}World{f:} {s:20}HOW{s:} {c:#00F}blue {c:red}red {c:} \{"

func (Paragraphs) Measure

func (paragraphs Paragraphs) Measure(ctx *RenderContext) gfx.Coord

func (Paragraphs) MinWidth

func (paragraphs Paragraphs) MinWidth(ctx *RenderContext) float32

func (Paragraphs) Render

func (paragraphs Paragraphs) Render(ctx *RenderContext, b *Base) RenderedText

func (Paragraphs) String

func (paragraphs Paragraphs) String() string

func (Paragraphs) ToString

func (paragraphs Paragraphs) ToString(paragraphSeparator string) string

func (Paragraphs) Wrap

func (paragraphs Paragraphs) Wrap(lineWidth float32) bool

type ParagraphsStyles

type ParagraphsStyles struct {
	ParagraphSpacing  Amount    // how much space between paragraphs
	VerticalAlignment Alignment // how to align all paragraphs in an area
	ClipShowX         ClipShow  // when text cannot fit in the area width, which side should we prefer to show (left, right, none)
	ClipShowY         ClipShow  // when text cannot fit in the area height, which side should we prefer to show (top, bottom, none)
}

func (*ParagraphsStyles) Override

type ParagraphsStylesOverride

type ParagraphsStylesOverride struct {
	ParagraphSpacing  *Amount    // how much space between paragraphs
	VerticalAlignment *Alignment // how to align all paragraphs in an area
	ClipShowX         *ClipShow  // when text cannot fit in the area width, which side should we prefer to show (left, right, none)
	ClipShowY         *ClipShow  // when text cannot fit in the area height, which side should we prefer to show (top, bottom, none)
}

func (*ParagraphsStylesOverride) HasOverride

func (o *ParagraphsStylesOverride) HasOverride() bool

type Placement

type Placement struct {
	Left   Anchor
	Right  Anchor
	Top    Anchor
	Bottom Anchor
}

func Absolute

func Absolute(left, top, width, height float32) Placement

func Centered

func Centered(width float32, height float32) Placement

func MaximizeOffset

func MaximizeOffset(left, top, right, bottom float32) Placement

func Maximized

func Maximized() Placement

func (Placement) Attach

func (p Placement) Attach(dx float32, dy float32, width float32, height float32) Placement

func (Placement) BottomFixedHeight

func (p Placement) BottomFixedHeight(bottomOffset float32, height float32, leftOffset float32, rightOffset float32) Placement

func (Placement) Center

func (p Placement) Center(width float32, height float32) Placement

func (Placement) Contains

func (p Placement) Contains(x float32, y float32, parentWidth float32, parentHeight float32) bool

func (Placement) Defined

func (p Placement) Defined() bool

func (Placement) FitInside

func (p Placement) FitInside(width, height float32, keepSize bool) Placement

func (Placement) GetBounds

func (p Placement) GetBounds(parentWidth float32, parentHeight float32) Bounds

func (Placement) GetBoundsIn

func (p Placement) GetBoundsIn(parent Bounds) Bounds

func (*Placement) GetBoundsi

func (p *Placement) GetBoundsi(parentWidth float32, parentHeight float32) geom.Bounds2i

func (Placement) GetHeight

func (p Placement) GetHeight(parentHeight float32) float32

func (Placement) GetMinHeight

func (p Placement) GetMinHeight(parentHeight float32, minHeight float32) float32

func (Placement) GetMinWidth

func (p Placement) GetMinWidth(parentWidth float32, minWidth float32) float32

func (Placement) GetWidth

func (p Placement) GetWidth(parentWidth float32) float32

func (Placement) Grow

func (p Placement) Grow(amount float32) Placement

func (*Placement) Init

func (p *Placement) Init(defaultPlacement Placement)

func (Placement) IsMaximized

func (p Placement) IsMaximized() bool

func (Placement) LeftFixedWidth

func (p Placement) LeftFixedWidth(leftOffset float32, width float32, topOffset float32, bottomOffset float32) Placement

func (Placement) Maximize

func (p Placement) Maximize() Placement

func (Placement) MinParentHeight

func (p Placement) MinParentHeight() float32

func (Placement) MinParentSize

func (p Placement) MinParentSize() gfx.Coord

func (Placement) MinParentWidth

func (p Placement) MinParentWidth() float32

func (Placement) Padded

func (p Placement) Padded(padding Bounds) Placement

func (Placement) Padding

func (p Placement) Padding() gfx.Coord

func (Placement) ParentHeight

func (p Placement) ParentHeight(minHeight float32) float32

func (Placement) ParentSize

func (p Placement) ParentSize(minWidth, minHeight float32) gfx.Coord

func (Placement) ParentWidth

func (p Placement) ParentWidth(minWidth float32) float32

func (Placement) PreferredHeight

func (p Placement) PreferredHeight() float32

func (Placement) PreferredWidth

func (p Placement) PreferredWidth() float32

func (Placement) Relative

func (p Placement) Relative(leftAnchor float32, topAnchor float32, rightAnchor float32, bottomAnchor float32) Placement

func (Placement) RightFixedWidth

func (p Placement) RightFixedWidth(rightOffset float32, width float32, topOffset float32, bottomOffset float32) Placement

func (Placement) Shift

func (p Placement) Shift(dx, dy float32) Placement

func (Placement) Shrink

func (p Placement) Shrink(amount float32) Placement

func (Placement) TopFixedHeight

func (p Placement) TopFixedHeight(topOffset float32, height float32, leftOffset float32, rightOffset float32) Placement

func (Placement) WithBottom

func (p Placement) WithBottom(bottom, parentHeight float32) Placement

func (Placement) WithHeight

func (p Placement) WithHeight(height float32) Placement

func (Placement) WithHeightRelative

func (p Placement) WithHeightRelative(height, parentHeight float32) Placement

func (Placement) WithLeft

func (p Placement) WithLeft(left, parentWidth float32) Placement

func (Placement) WithRight

func (p Placement) WithRight(right, parentWidth float32) Placement

func (Placement) WithSize

func (p Placement) WithSize(width, height float32) Placement

func (Placement) WithSizeRelative

func (p Placement) WithSizeRelative(width, height, parentWidth, parentHeight float32) Placement

func (Placement) WithTop

func (p Placement) WithTop(top, parentHeight float32) Placement

func (Placement) WithWidth

func (p Placement) WithWidth(width float32) Placement

func (Placement) WithWidthRelative

func (p Placement) WithWidthRelative(width, parentWidth float32) Placement

type PlacementAnimation

type PlacementAnimation struct {
	Target       Placement
	Easing       ease.Easing
	Duration     float32
	ApplyMaxSize bool
	// contains filtered or unexported fields
}

func (PlacementAnimation) GetAnimation

func (a PlacementAnimation) GetAnimation(base *Base) Animation

func (*PlacementAnimation) Init

func (a *PlacementAnimation) Init(base *Base)

func (*PlacementAnimation) IsDone

func (a *PlacementAnimation) IsDone(base *Base, animationTime float32) bool

func (*PlacementAnimation) PostProcess

func (a *PlacementAnimation) PostProcess(base *Base, animationTime float32, ctx *RenderContext, out *VertexBuffers)

func (*PlacementAnimation) Update

func (a *PlacementAnimation) Update(base *Base, animationTime float32, update Update) Dirty

type PointerButtons

type PointerButtons struct {
	Down     bool
	DownTime int64
}

type PointerEvent

type PointerEvent struct {
	Event
	Point  gfx.Coord
	Button int
	Wheel  gfx.Coord
	Type   PointerEventType
	*HasCursor
}

type PointerEventType

type PointerEventType int
const (
	// Press down (might not be followed by up)
	PointerEventDown PointerEventType = iota
	// Press up (might not be followed by )
	PointerEventUp
	// When a component previously received a down but the latest down excludes them.
	PointerEventDownOut
	// When a component previously received an up but the latest up excludes them.
	PointerEventUpOut
	// A pointer has leaved a component.
	PointerEventLeave
	// A pointer has entered a component.
	PointerEventEnter
	// A scroll/wheel event.
	PointerEventWheel
	// The pointer has moved.
	PointerEventMove
)

type PostProcess

type PostProcess func(b *Base, ctx *RenderContext, out *VertexBuffers)

func PostProcessVertex

func PostProcessVertex(modify VertexModifier) PostProcess

func (*PostProcess) Add

func (pp *PostProcess) Add(other PostProcess, before bool)

func (*PostProcess) Clear

func (pp *PostProcess) Clear()

func (PostProcess) Run

func (pp PostProcess) Run(b *Base, ctx *RenderContext, out *VertexBuffers)

type RenderContext

type RenderContext struct {
	AmountContext *AmountContext
	Theme         *Theme
	TextStyles    *TextStyles
}

func (*RenderContext) WithAmountContext

func (ctx *RenderContext) WithAmountContext(amt *AmountContext) *RenderContext

func (*RenderContext) WithBounds

func (ctx *RenderContext) WithBounds(parent Bounds) *RenderContext

func (*RenderContext) WithBoundsAndTextStyles

func (ctx *RenderContext) WithBoundsAndTextStyles(parent Bounds, styles *TextStylesOverride) *RenderContext

func (*RenderContext) WithParent

func (ctx *RenderContext) WithParent(width, height float32) *RenderContext

func (*RenderContext) WithTextStyles

func (ctx *RenderContext) WithTextStyles(styles *TextStyles) *RenderContext

type RenderedGlyph

type RenderedGlyph struct {
	gfx.Tile
	Bounds         Bounds
	Color          color.Color
	Visibility     GlyphVisibility
	Line           int
	Column         int
	Word           int
	Paragraph      int
	ParagraphIndex int
	Index          int
	Empty          bool
}

func (RenderedGlyph) Write

func (g RenderedGlyph) Write(quad []Vertex)

type RenderedText

type RenderedText struct {
	Bounds     Bounds
	Glyphs     []RenderedGlyph
	Paragraphs Paragraphs
}

func (RenderedText) Closest

func (text RenderedText) Closest(x, y float32) int

func (RenderedText) ClosestByLine

func (text RenderedText) ClosestByLine(x, y float32) int

func (RenderedText) CountVisible

func (text RenderedText) CountVisible(threshold *GlyphVisibility) int

func (*RenderedText) Translate

func (paragraph *RenderedText) Translate(x, y float32)

func (RenderedText) UpdateVisibility

func (text RenderedText) UpdateVisibility(visibleBounds Bounds)

type Shape

type Shape interface {
	Init()
	Shapify(b Bounds, ctx *RenderContext) []gfx.Coord
}

type ShapePolygon

type ShapePolygon struct {
	Points   []gfx.Coord
	Absolute bool
	Copy     bool
}

func (ShapePolygon) Init

func (o ShapePolygon) Init()

func (ShapePolygon) Shapify

func (o ShapePolygon) Shapify(b Bounds, ctx *RenderContext) []gfx.Coord

type ShapeRectangle

type ShapeRectangle struct{}

func (ShapeRectangle) Init

func (o ShapeRectangle) Init()

func (ShapeRectangle) Shapify

func (o ShapeRectangle) Shapify(b Bounds, ctx *RenderContext) []gfx.Coord

type ShapeRounded

type ShapeRounded struct {
	Radius       AmountCorners
	UnitToPoints float32
}

func (ShapeRounded) Init

func (o ShapeRounded) Init()

func (ShapeRounded) Shapify

func (o ShapeRounded) Shapify(b Bounds, ctx *RenderContext) []gfx.Coord

type ShapeSharpen

type ShapeSharpen struct {
	Shape Shape
	Times int
}

func (ShapeSharpen) Init

func (o ShapeSharpen) Init()

func (ShapeSharpen) Shapify

func (o ShapeSharpen) Shapify(b Bounds, ctx *RenderContext) []gfx.Coord

type State

type State = Flags

One or more states of a component. The states can define which layers or post processing is done.

const (
	// Default enabled state
	StateDefault State = 1 << iota
	// Enabled state with pointer over component
	StateHover
	// Enabled state with pointer down on component. Can be other states as well.
	StatePressed
	// Enabled state when component is the currently focused one.
	StateFocused
	// Component was disabled by user and should receive no input events.
	StateDisabled
	// Enabled state when component is being drug.
	StateDragging
	// Enabled state when component accepts drops and there's a drag element over it.
	StateDragOver
	// General state for more complex components (checked, chosen option, etc).
	StateSelected
	// Disabled state when component is hidden from render parent and is not placed.
	StateHidden
	// Disabled state when component has removing animation that's playing.
	StateRemoving
	// Disabled state when component has hiding animation that's playing.
	StateHiding
	// Disabled state when component has showing animation that's playing.
	StateShowing

	// All states that can't receive input events.
	StatesDisabled = StateDisabled | StateRemoving | StateShowing | StateHiding | StateHidden
)

type StateFn

type StateFn = func(s State) bool

A function which accepts a state and returns true/false. Used to control which layers are updated & rendered for a component's state.

type Template

type Template struct {
	PreLayers                   []Layer
	PostLayers                  []Layer
	Focusable                   bool
	Draggable                   bool
	Droppable                   bool
	PreEvents                   Events
	PostEvents                  Events
	RelativePlacement           Placement
	Clip                        Placement
	TextStyles                  *TextStylesOverride
	Shape                       Shape
	OverShape                   []gfx.Coord
	Transparency                float32
	Color                       color.Modify
	Animations                  *Animations
	AnimationsMerge             bool
	Cursors                     Cursors
	CursorsMerge                bool
	Colors                      color.Colors
	ColorsMerge                 bool
	PreHooks                    Hooks
	PostHooks                   Hooks
	Margin                      AmountBounds
	MinSize                     AmountPoint
	MaxSize                     AmountPoint
	Layout                      Layout
	IgnoreLayoutPreferredWidth  bool
	IgnoreLayoutPreferredHeight bool
}

A template for a base which can be applied.

type TextAnimation

type TextAnimation interface {
	Init(base *Base)
	Update(base *Base, animationTime float32, update Update) Dirty
	IsDone(base *Base, animationTime float32) bool
	Render(base *Base, animationTime float32, bounds Bounds, ctx *RenderContext, out *VertexBuffer)
}

type TextAnimationFactory

type TextAnimationFactory interface {
	GetAnimation(text *RenderedText) TextAnimation
}

type TextStyles

type TextStyles struct {
	ParagraphStyles
	ParagraphsStyles
	Color    color.Able
	Font     id.Identifier
	FontSize Amount
}

func (*TextStyles) Override

func (s *TextStyles) Override(o *TextStylesOverride) *TextStyles

type TextStylesOverride

type TextStylesOverride struct {
	ParagraphStylesOverride  *ParagraphStylesOverride
	ParagraphsStylesOverride *ParagraphsStylesOverride
	Color                    *color.Able
	Font                     *id.Identifier
	FontSize                 *Amount
}

func (*TextStylesOverride) HasOverride

func (o *TextStylesOverride) HasOverride() bool

type TextWrap

type TextWrap string
const (
	TextWrapNone TextWrap = "none"
	TextWrapWord TextWrap = "word"
	TextWrapChar TextWrap = "char"
)

func (TextWrap) MarshalText

func (w TextWrap) MarshalText() ([]byte, error)

func (*TextWrap) UnmarshalText

func (w *TextWrap) UnmarshalText(text []byte) error

type Theme

type Theme struct {
	TextStyles       TextStyles
	StatePostProcess map[State]PostProcess
	Fonts            id.DenseMap[*Font, uint16, uint8]
	Cursors          id.DenseMap[ExtentTile, uint16, uint8]
	DefaultCursor    id.Identifier
	Animations       Animations
	Colors           color.Colors
}

The Theme of a UI. Contains the base text styles, state specific post processing, the collection of supported fonts & cursors, the default cursor, the theme wide named animations, and the theme wide colors.

type Transform

type Transform struct {
	// contains filtered or unexported fields
}

func Identity

func Identity() Transform

func (*Transform) Determinant

func (t *Transform) Determinant() float32

func (*Transform) GetDegrees

func (t *Transform) GetDegrees() float32

func (*Transform) GetInvert

func (t *Transform) GetInvert() Transform

func (*Transform) GetRadians

func (t *Transform) GetRadians() float32

func (*Transform) GetScale

func (t *Transform) GetScale() (x, y float32)

func (*Transform) GetTranslate

func (t *Transform) GetTranslate() (float32, float32)

func (Transform) HasAffect

func (t Transform) HasAffect() bool

func (*Transform) Identity

func (t *Transform) Identity()

func (*Transform) Invert

func (t *Transform) Invert()

func (Transform) IsEffectivelyIdentity

func (t Transform) IsEffectivelyIdentity() bool

func (Transform) IsIdentity

func (t Transform) IsIdentity() bool

func (Transform) IsZero

func (t Transform) IsZero() bool

func (*Transform) Multiply

func (t *Transform) Multiply(b Transform)

func (*Transform) PreScale

func (t *Transform) PreScale(sx, sy float32)

func (*Transform) PreTranslate

func (t *Transform) PreTranslate(tx, ty float32)

func (*Transform) Rotate

func (t *Transform) Rotate(radians float32)

func (*Transform) RotateDegrees

func (t *Transform) RotateDegrees(degrees float32)

func (*Transform) Scale

func (t *Transform) Scale(sx, sy float32)

func (*Transform) Set

func (t *Transform) Set(sx, ry, rx, sy, tx, ty float32)

func (*Transform) SetRotate

func (t *Transform) SetRotate(radians float32)

func (*Transform) SetRotateAround

func (t *Transform) SetRotateAround(radians, anchorX, anchorY float32)

func (*Transform) SetRotateDegrees

func (t *Transform) SetRotateDegrees(degrees float32)

func (*Transform) SetRotateDegreesAround

func (t *Transform) SetRotateDegreesAround(radians, anchorX, anchorY float32)

func (*Transform) SetRotateDegreesScaleAround

func (t *Transform) SetRotateDegreesScaleAround(degrees, scaleX, scaleY, anchorX, anchorY float32)

func (*Transform) SetRotateScaleAround

func (t *Transform) SetRotateScaleAround(radians, scaleX, scaleY, anchorX, anchorY float32)

func (*Transform) SetScale

func (t *Transform) SetScale(sx, sy float32)

func (*Transform) SetScaleAround

func (t *Transform) SetScaleAround(sx, sy, anchorX, anchorY float32)

func (*Transform) SetShear

func (t *Transform) SetShear(sx, sy float32)

func (*Transform) SetShearAround

func (t *Transform) SetShearAround(sx, sy, anchorX, anchorY float32)

func (*Transform) SetTranslate

func (t *Transform) SetTranslate(tx, ty float32)

func (*Transform) Shear

func (t *Transform) Shear(sx, sy float32)

func (*Transform) Transform

func (t *Transform) Transform(x, y float32) (float32, float32)

func (*Transform) TransformCoord

func (t *Transform) TransformCoord(c gfx.Coord) gfx.Coord

func (*Transform) TransformVector

func (t *Transform) TransformVector(vx, vy float32) (float32, float32)

func (*Transform) TransformVectorCoord

func (t *Transform) TransformVectorCoord(v gfx.Coord) gfx.Coord

func (*Transform) Translate

func (t *Transform) Translate(tx, ty float32)

type UI

type UI struct {
	PointerButtons []PointerButtons
	PointerPoint   gfx.Coord
	Root           *Base
	PointerOver    *Base
	Focused        *Base
	Dragging       *Base
	DragStart      gfx.Coord
	DragCancels    ds.Set[string]
	Theme          *Theme
	Cursor         id.Identifier
	Named          id.DenseMap[*Base, uint16, uint16]

	TransformPointer      bool
	TransparencyThreshold float32
	UpdateHidden          bool
	PointerEntersOnDrag   bool
	PointerMovesOnDrag    bool
	// contains filtered or unexported fields
}

func NewUI

func NewUI() *UI

func (*UI) GetCursor

func (ui *UI) GetCursor() (cursorVertex []Vertex)

func (*UI) Init

func (ui *UI) Init()

func (*UI) IsPointerOver

func (ui *UI) IsPointerOver() bool

func (*UI) NeedsRender

func (ui *UI) NeedsRender() bool

func (*UI) Place

func (ui *UI) Place(newBounds Bounds)

func (*UI) ProcessKeyEvent

func (ui *UI) ProcessKeyEvent(ev KeyEvent) error

func (*UI) ProcessPointerEvent

func (ui *UI) ProcessPointerEvent(ev PointerEvent) error

func (*UI) Render

func (ui *UI) Render(queue *VertexQueue)

func (*UI) RenderContext

func (ui *UI) RenderContext() *RenderContext

func (*UI) SetContext

func (ui *UI) SetContext(ctx *AmountContext)

func (*UI) Update

func (ui *UI) Update(update Update)

type Unit

type Unit int
const (
	UnitConstant     Unit = iota // "" px
	UnitFont                     // %f f rem %rem em %em
	UnitParent                   // % p %p
	UnitParentWidth              // %w w %pw pw
	UnitParentHeight             // %h h %ph ph
	UnitView                     // %v v
	UnitViewWidth                // %vw vw
	UnitViewHeight               // %vh vh
	UnitWindow                   // %n n
	UnitWindowWidth              // %nw nw
	UnitWindowHeight             // %nh nh
	UnitScreen                   // %s s
	UnitScreenWidth              // %sw sw
	UnitScreenHeight             // %sh sh
)

func (Unit) Get

func (a Unit) Get(value float32, ctx *AmountContext, widthRelative bool) float32

func (Unit) SupportsPercent

func (a Unit) SupportsPercent() bool

type UnitContext

type UnitContext struct {
	Width  float32
	Height float32
}

func (UnitContext) Get

func (c UnitContext) Get(widthRelative bool) float32

type Update

type Update struct {
	DeltaTime time.Duration
}

type Vertex

type Vertex struct {
	X, Y     float32
	Tex      gfx.TextureCoord
	HasCoord bool
	Color    color.Color
	HasColor bool
}

func (*Vertex) AddColor

func (v *Vertex) AddColor(c color.Color)

func (*Vertex) InitColor

func (v *Vertex) InitColor()

func (Vertex) Lerp

func (from Vertex) Lerp(to Vertex, delta float32) Vertex

func (Vertex) LerpWith

func (from Vertex) LerpWith(to Vertex, delta, x, y float32) Vertex

func (*Vertex) SetCoord

func (vert *Vertex) SetCoord(coord gfx.TextureCoord)

type VertexBuffer

type VertexBuffer struct {
	buf.Buffer[Vertex]

	Blend     gfx.Blend
	Primitive gfx.Primitive
}

func (*VertexBuffer) AddLine

func (b *VertexBuffer) AddLine() []Vertex

func (*VertexBuffer) AddQuad

func (b *VertexBuffer) AddQuad() []Vertex

func (*VertexBuffer) AddReservedLine

func (b *VertexBuffer) AddReservedLine(v0, v1 Vertex)

func (*VertexBuffer) AddReservedQuad

func (b *VertexBuffer) AddReservedQuad(v0, v1, v2, v3 Vertex)

func (*VertexBuffer) AddReservedTriangle

func (b *VertexBuffer) AddReservedTriangle(v0, v1, v2 Vertex)

func (*VertexBuffer) AddTriangle

func (b *VertexBuffer) AddTriangle() []Vertex

func (*VertexBuffer) Clear

func (b *VertexBuffer) Clear()

func (*VertexBuffer) Clip

func (b *VertexBuffer) Clip(bounds Bounds, out *VertexBuffer)

func (*VertexBuffer) ClipCompatible

func (b *VertexBuffer) ClipCompatible(vb *VertexBuffer) bool

func (*VertexBuffer) CloneTo

func (b *VertexBuffer) CloneTo(out *VertexBuffer) *VertexBuffer

func (*VertexBuffer) Compatible

func (b *VertexBuffer) Compatible(vb *VertexBuffer) bool

func (VertexBuffer) Empty

func (b VertexBuffer) Empty() bool

func (*VertexBuffer) GetReservedLine

func (b *VertexBuffer) GetReservedLine() (data []Vertex)

func (*VertexBuffer) GetReservedQuad

func (b *VertexBuffer) GetReservedQuad() (data []Vertex)

func (*VertexBuffer) GetReservedTriangle

func (b *VertexBuffer) GetReservedTriangle() (data []Vertex)

func (*VertexBuffer) Init

func (b *VertexBuffer) Init(capacity int)

func (VertexBuffer) Remaining

func (b VertexBuffer) Remaining() int

func (*VertexBuffer) ReserveLines

func (b *VertexBuffer) ReserveLines(lines int)

func (*VertexBuffer) ReserveQuads

func (b *VertexBuffer) ReserveQuads(quads int)

func (*VertexBuffer) ReserveTriangles

func (b *VertexBuffer) ReserveTriangles(triangles int)

type VertexBuffers

type VertexBuffers struct {
	buf.Buffers[Vertex, VertexBuffer]

	Blend     gfx.Blend
	Primitive gfx.Primitive
}

func NewVertexBuffers

func NewVertexBuffers(capacity int, buffers int) *VertexBuffers

func (*VertexBuffers) Clip

func (vbs *VertexBuffers) Clip(bounds Bounds, render func(clippable *VertexBuffers))

func (*VertexBuffers) ClipInto

func (clipped *VertexBuffers) ClipInto(bounds Bounds, source VertexIterable)

func (*VertexBuffers) CloneTo

func (vbs *VertexBuffers) CloneTo(target *VertexBuffers)

func (*VertexBuffers) Get

func (vbs *VertexBuffers) Get(primitive gfx.Primitive, blend gfx.Blend) *VertexBuffer

func (*VertexBuffers) NewLike

func (vbs *VertexBuffers) NewLike() *VertexBuffers

func (*VertexBuffers) With

func (vbs *VertexBuffers) With(primitive gfx.Primitive, blend gfx.Blend, render func(out *VertexBuffers))

type VertexIterable

type VertexIterable = buf.Iterable[Vertex, VertexBuffer]

type VertexIterator

type VertexIterator = buf.DataIterator[Vertex, VertexBuffer]

func NewVertexIterator

func NewVertexIterator(iterable buf.Iterable[Vertex, VertexBuffer], beginning bool) VertexIterator

type VertexModifier

type VertexModifier func(*Vertex)

type VertexQueue

type VertexQueue struct {
	buf.Queue[Vertex, VertexBuffer]
}

func NewVertexQueue

func NewVertexQueue(capacity int) *VertexQueue

func (*VertexQueue) Clip

func (vbs *VertexQueue) Clip(bounds Bounds, clipOut **VertexBuffers, render func(clippable *VertexQueue, clipping bool))

func (*VertexQueue) ToBuffers

func (vbs *VertexQueue) ToBuffers() *VertexBuffers

type Visual

type Visual interface {
	Init(b *Base)
	Update(b *Base, update Update) Dirty
	Visualize(b *Base, bounds Bounds, ctx *RenderContext, out *VertexBuffers)
	PreferredSize(b *Base, ctx *RenderContext, maxWidth float32) gfx.Coord
}

type VisualBorderScale

type VisualBorderScale struct {
	NormalX, NormalY, Weight float32
	Spread                   bool
}

type VisualBordered

type VisualBordered struct {
	Width      float32
	OuterColor color.Able
	InnerColor color.Able
	Scales     []VisualBorderScale
	Shape      Shape
}

func (VisualBordered) Init

func (s VisualBordered) Init(b *Base)

func (VisualBordered) PreferredSize

func (s VisualBordered) PreferredSize(b *Base, ctx *RenderContext, maxWidth float32) gfx.Coord

func (VisualBordered) Update

func (s VisualBordered) Update(b *Base, update Update) Dirty

func (VisualBordered) Visualize

func (s VisualBordered) Visualize(b *Base, bounds Bounds, ctx *RenderContext, out *VertexBuffers)

type VisualFilled

type VisualFilled struct {
	Shape Shape
}

func (VisualFilled) Init

func (s VisualFilled) Init(b *Base)

func (VisualFilled) PreferredSize

func (s VisualFilled) PreferredSize(b *Base, ctx *RenderContext, maxWidth float32) gfx.Coord

func (VisualFilled) Update

func (s VisualFilled) Update(b *Base, update Update) Dirty

func (VisualFilled) Visualize

func (s VisualFilled) Visualize(b *Base, bounds Bounds, ctx *RenderContext, out *VertexBuffers)

type VisualFrame

type VisualFrame struct {
	Sizes   AmountBounds
	Tile    []gfx.Tile
	Columns int
}

func (VisualFrame) Init

func (r VisualFrame) Init(b *Base)

func (VisualFrame) PreferredSize

func (s VisualFrame) PreferredSize(b *Base, ctx *RenderContext, maxWidth float32) gfx.Coord

func (VisualFrame) Update

func (r VisualFrame) Update(b *Base, update Update) Dirty

func (VisualFrame) Visualize

func (r VisualFrame) Visualize(b *Base, bounds Bounds, ctx *RenderContext, out *VertexBuffers)

type VisualShadow

type VisualShadow struct {
	Shape      Shape
	Blur       AmountBounds
	Offsets    AmountBounds
	AlwaysFill bool
}

func (VisualShadow) Init

func (s VisualShadow) Init(b *Base)

func (VisualShadow) PreferredSize

func (s VisualShadow) PreferredSize(b *Base, ctx *RenderContext, maxWidth float32) gfx.Coord

func (VisualShadow) Update

func (s VisualShadow) Update(b *Base, update Update) Dirty

func (VisualShadow) Visualize

func (s VisualShadow) Visualize(b *Base, bounds Bounds, ctx *RenderContext, out *VertexBuffers)

type VisualText

type VisualText struct {
	Paragraphs       Paragraphs
	VisibleThreshold *GlyphVisibility
	Clip             bool
	Animation        TextAnimation
	AnimationFactory TextAnimationFactory
	// contains filtered or unexported fields
}

func MustTextToVisual

func MustTextToVisual(text string) *VisualText

func TextToVisual

func TextToVisual(text string) (*VisualText, error)

func (*VisualText) Clipped

func (s *VisualText) Clipped() *VisualText

func (*VisualText) Dirty

func (s *VisualText) Dirty() *VisualText

func (*VisualText) Init

func (s *VisualText) Init(b *Base)

func (*VisualText) Play

func (s *VisualText) Play(factory TextAnimationFactory) *VisualText

func (VisualText) PreferredSize

func (s VisualText) PreferredSize(b *Base, ctx *RenderContext, maxWidth float32) gfx.Coord

func (VisualText) Rendered

func (s VisualText) Rendered() RenderedText

func (VisualText) RenderedBounds

func (s VisualText) RenderedBounds() Bounds

func (*VisualText) SetParagraphs

func (s *VisualText) SetParagraphs(para Paragraphs) *VisualText

func (*VisualText) SetText

func (s *VisualText) SetText(text string) *VisualText

func (*VisualText) Stop

func (s *VisualText) Stop() *VisualText

func (*VisualText) Update

func (s *VisualText) Update(b *Base, update Update) Dirty

func (*VisualText) Visibility

func (s *VisualText) Visibility(threshold GlyphVisibility) *VisualText

func (*VisualText) Visualize

func (s *VisualText) Visualize(b *Base, bounds Bounds, ctx *RenderContext, out *VertexBuffers)

func (*VisualText) WillClip

func (s *VisualText) WillClip() bool

Directories

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

Jump to

Keyboard shortcuts

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