widgets

package
v0.0.0-...-b5b2f04 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 10 Imported by: 6

Documentation

Overview

Widget and Layout definition and implementation.

Index

Constants

This section is empty.

Variables

View Source
var (
	NeedRenderEventType = events.NewType("NeedRender")
)

Functions

func IsMounted

func IsMounted(n *tree.Node[Widget]) bool

IsMounted return whether a Node is mounted on an active Widget tree.

func NeedRenderEventListener

func NeedRenderEventListener(handler func(NeedRenderEvent)) (events.Type, events.Handler)

NeedRenderEventListener returns an events.Listener that will call the given handler on resize events.

func ParentStyle

func ParentStyle(parent *tree.Node) styles.ComputedStyle

ParentStyle finds the first ancestor of node that is styled and returns its computed style.

Types

type BaseLayout

type BaseLayout struct {
	Widget
	LayoutRenderable
}

BaseLayout is a basic layout widget. It can either be used alone or embedded within a struct. BaseLayout - Dispatch mouse events to children - Drawing children

func NewBaseLayout

func NewBaseLayout(
	widget Widget,
	renderable LayoutRenderable,
) *BaseLayout

NewBaseLayout returns a BaseLayout that embed the given widget.

func (*BaseLayout) Renderable

func (bl *BaseLayout) Renderable() render.Renderable

Renderable implements render.RenderableAccessor.

func (*BaseLayout) Style

func (bl *BaseLayout) Style() styles.Style

Style implements styles.Styled.

type BaseLayoutRenderable

type BaseLayoutRenderable struct {
	*render.VoidRenderable
	// contains filtered or unexported fields
}

BaseLayoutRenderable is a wrapper of render.VoidRenderable that implements LayoutRenderable.

func NewBaseLayoutRenderable

func NewBaseLayoutRenderable(nodeAccessor tree.NodeAccessor, layoutChildren LayoutChildren) *BaseLayoutRenderable

NewBaseLayoutRenderable returns a new LayoutRenderable for the given NodeAccessor.

func (BaseLayoutRenderable) ChildrenLayout

func (lr BaseLayoutRenderable) ChildrenLayout() *ChildrenLayout

ChildrenRects implements LayoutRenderable.

func (BaseLayoutRenderable) Draw

func (lr BaseLayoutRenderable) Draw(surface draw.Surface)

Draw implements layout.Layout. BaseLayoutRenderable draw

func (BaseLayoutRenderable) Layout

Layout implements layout.Layout.

type ChildLayout

type ChildLayout struct {
	// Node associated to rectangle.
	Node *tree.Node
	// Bounds relative to layout origin.
	Bounds geometry.Rectangle
}

ChildLayout define position and size of a child Node.

type ChildrenLayout

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

ChildrenLayout contains position and size of children Node.

func (*ChildrenLayout) Append

func (cl *ChildrenLayout) Append(child ChildLayout)

Append appends the given ChildLayout.

func (*ChildrenLayout) Get

func (cl *ChildrenLayout) Get(i int) ChildLayout

Get returns ChildLayout relative to parent origin.

func (*ChildrenLayout) Size

func (cl *ChildrenLayout) Size() int

Size returns number of ChildLayout stored.

type ComposedWidget

type ComposedWidget struct {
	*PanicWidget
	styles.Styled
	render.RenderableAccessor
}

ComposedWidget define a Widget composed of a PanicWidget, a styles.Styled and a render.RenderableAccessor.

func NewComposedWidget

func NewComposedWidget(styled styles.Styled, renderableAccessor render.RenderableAccessor) *ComposedWidget

func (ComposedWidget) Renderable

func (cw ComposedWidget) Renderable() render.Renderable

Renderable implements render.RenderableAccessor.

func (ComposedWidget) Style

func (cw ComposedWidget) Style() styles.Style

Style implements styles.Styled.

type Event

type Event interface {
	events.Event

	// Target returns targeted widget by the event.
	Target() Widget
}

Event define an event within a widget tree.

type InheritStyle

type InheritStyle struct {
	// NodeAccessor provide node associated with this style. It is used to retrieve
	// parent node and thus parent style.
	NodeAccessor tree.NodeAccessor
	// Style associated with this node. Nil property are inherited on Compute.
	InnerStyle Style
}

InheritStyle define a Style wrapper that adds inheritance capability to it. Inheritance happens when styles.Style.Compute is called.

func (InheritStyle) Compute

func (i InheritStyle) Compute() styles.ComputedStyle

Compute implements styles.Style.

func (InheritStyle) Style

func (i InheritStyle) Style() styles.Style

Style implements styles.Styled.

type LayoutChildren

type LayoutChildren interface {
	// LayoutChildren layout each children and append them in the given
	// ChildrenLayout.
	LayoutChildren(_ layout.Constraint, _ *ChildrenLayout) geometry.Size
}

LayoutChildren define any type that can layout its children.

type LayoutChildrenFunc

type LayoutChildrenFunc func(_ layout.Constraint, _ *ChildrenLayout) geometry.Size

LayoutChildrenFunc is function type that implements LayoutChildren interface.

func (LayoutChildrenFunc) LayoutChildren

func (lcf LayoutChildrenFunc) LayoutChildren(co layout.Constraint, r *ChildrenLayout) geometry.Size

LayoutChildren implements LayoutChildren.

type LayoutRenderable

type LayoutRenderable interface {
	render.Renderable
	// Returns children bounding rectangle relative to layout origin
	ChildrenLayout() *ChildrenLayout
}

LayoutRenderable define render.Renderable for layouts Widget.

type LayoutRenderableCache

type LayoutRenderableCache struct {
	render.Cache[*BaseLayoutRenderable]
}

LayoutRenderableCache define a LayoutRenderable with cache.

func NewLayoutRenderableCache

func NewLayoutRenderableCache(nodeAccessor tree.NodeAccessor, layout LayoutChildren) LayoutRenderableCache

NewLayoutRenderableCache returns a new LayoutRenderable.

func (LayoutRenderableCache) ChildrenLayout

func (lrc LayoutRenderableCache) ChildrenLayout() *ChildrenLayout

ChildrenLayout implements LayoutRenderable.

type NeedRenderEvent

type NeedRenderEvent struct {
	events.Event
}

NeedRenderEvent is emitted by Root widget when widgets tree needs to be rendered.

type PanicWidget

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

PanicWidget define a minimal (and incomplete) Widget type. PanicWidget implements panic methods for styles.Styled and render.RenderableAccessor interfaces.

func NewPanicWidget

func NewPanicWidget(nodeData Widget) *PanicWidget

NewPanicWidget returns a new PanicWidget object configured with the given options.

func (*PanicWidget) Node

func (bw *PanicWidget) Node() *tree.Node[Widget]

Node implements the Widget interface.

func (*PanicWidget) Renderable

func (*PanicWidget) Renderable() render.Renderable

Renderable implements Widget.

func (*PanicWidget) Style

func (*PanicWidget) Style() styles.Style

Style implements styles.Styled.

func (*PanicWidget) Swap

func (bw *PanicWidget) Swap(other Widget)

Swap implements Widget.

type Root

type Root struct {
	Widget
	// contains filtered or unexported fields
}

Root define root of widgets tree.

func NewRoot

func NewRoot(w Widget) Root

NewRoot returns a new Root widget that wraps the given Widget and its render.Renderable.

func (Root) MarkDirty

func (rr Root) MarkDirty()

func (Root) Renderable

func (r Root) Renderable() render.Renderable

Renderable implements render.RenderableAccessor.

type Style

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

Style define a basic style type for widgets.

func (Style) Background

func (s Style) Background(c colors.Color) Style
func (s Style) Blink(b bool) Style

func (Style) Bold

func (s Style) Bold(b bool) Style

func (Style) Border

func (s Style) Border(borders ...styles.BorderSide) Style

func (Style) BorderBottom

func (s Style) BorderBottom(b styles.BorderSide) Style

func (Style) BorderLeft

func (s Style) BorderLeft(b styles.BorderSide) Style

func (Style) BorderRight

func (s Style) BorderRight(b styles.BorderSide) Style

func (Style) BorderTop

func (s Style) BorderTop(b styles.BorderSide) Style

func (Style) BorderX

func (s Style) BorderX(b styles.BorderSide) Style

func (Style) BorderY

func (s Style) BorderY(b styles.BorderSide) Style

func (Style) Compute

func (s Style) Compute() styles.ComputedStyle

Compute implements styles.Style.

func (Style) Dim

func (s Style) Dim(b bool) Style

func (Style) Foreground

func (s Style) Foreground(c colors.Color) Style

func (Style) InheritBackground

func (s Style) InheritBackground() Style

func (Style) InheritBorders

func (s Style) InheritBorders() Style

func (Style) InheritForeground

func (s Style) InheritForeground() Style

func (Style) InheritMargin

func (s Style) InheritMargin() Style

func (Style) InheritPadding

func (s Style) InheritPadding() Style

func (Style) InheritTextDecoration

func (s Style) InheritTextDecoration() Style

func (Style) Italic

func (s Style) Italic(b bool) Style

func (Style) Margin

func (s Style) Margin(margins ...int) Style

func (Style) MarginBottom

func (s Style) MarginBottom(m int) Style

func (Style) MarginLeft

func (s Style) MarginLeft(m int) Style

func (Style) MarginRight

func (s Style) MarginRight(m int) Style

func (Style) MarginTop

func (s Style) MarginTop(m int) Style

func (Style) MarginX

func (s Style) MarginX(m int) Style

func (Style) MarginY

func (s Style) MarginY(m int) Style

func (Style) Padding

func (s Style) Padding(paddings ...int) Style

func (Style) PaddingBottom

func (s Style) PaddingBottom(l int) Style

func (Style) PaddingLeft

func (s Style) PaddingLeft(l int) Style

func (Style) PaddingRight

func (s Style) PaddingRight(l int) Style

func (Style) PaddingTop

func (s Style) PaddingTop(l int) Style

func (Style) PaddingX

func (s Style) PaddingX(l int) Style

func (Style) PaddingY

func (s Style) PaddingY(l int) Style

func (Style) Reverse

func (s Style) Reverse(b bool) Style

func (Style) StrikeThrough

func (s Style) StrikeThrough(b bool) Style

func (Style) Style

func (s Style) Style() styles.Style

Style implements styles.Styled.

func (Style) Underline

func (s Style) Underline(b bool) Style

type StyledLayoutRenderable

type StyledLayoutRenderable struct {
	styles.Renderable[LayoutRenderable]
}

StyledLayoutRenderable define a LayoutRenderable wrapper that adds styling to it.

func NewStyledLayoutRenderable

func NewStyledLayoutRenderable(styled styles.Styled, layoutRenderable LayoutRenderable) StyledLayoutRenderable

NewStyledLayoutRenderable returns a new StyledLayoutRenderable that wraps the given LayoutRenderable.

func (StyledLayoutRenderable) ChildrenLayout

func (slr StyledLayoutRenderable) ChildrenLayout() *ChildrenLayout

ChildrenLayout implements LayoutRenderable.

func (StyledLayoutRenderable) Draw

func (slr StyledLayoutRenderable) Draw(surface draw.Surface)

Draw implements draw.Drawer.

func (StyledLayoutRenderable) Layout

Layout implements layout.Layout.

func (StyledLayoutRenderable) Style

func (slr StyledLayoutRenderable) Style() styles.Style

Style implements styled.Styled.

type Widget

type Widget interface {
	events.Target
	styles.Styled
	tree.NodeAccessor[Widget]
	render.RenderableAccessor

	// Swap swaps this widget node with node of the given one.
	Swap(Widget)
	// contains filtered or unexported methods
}

Widget is a generic interface that define any component part of the widget/element tree. Any types that implement the Widget interface can be added to the widget tree. You must embed *BaseWidget or *BoxWidget to implement this interface as it contains private methods.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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