scene

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package scene provides tools for flexible GUI building.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dispose

func Dispose[S, T any](root Element[S, T])

Dispose disposes scene with given root element.

func Draw

func Draw[S, T any](root Element[S, T], screen S)

Draw draws scene with given root element on given screen.

func Update

func Update[S, T any](root Element[S, T], bbox basic.Rect)

Update updates scene with given root element.

Types

type Attrs added in v0.5.0

type Attrs struct {

	// MaxHeight specifies maximum height of element.
	MaxHeight basic.Opt[basic.Float]

	// MaxWidth specifies maximum width of element.
	MaxWidth basic.Opt[basic.Float]

	// MinHeight specifies minimum height of element.
	MinHeight basic.Opt[basic.Float]

	// MinWidth specifies minimum width of element.
	MinWidth basic.Opt[basic.Float]

	// PreHeight specifies preliminary height of element.
	PreHeight basic.Opt[basic.Float]

	// PreWidth specifies preliminary width of element.
	PreWidth basic.Opt[basic.Float]
}

Attrs associated with element.

func (Attrs) FixHeight added in v0.5.0

func (a Attrs) FixHeight(value basic.Float) Attrs

FixHeight returns outline with fixed element height.

func (Attrs) FixWidth added in v0.5.0

func (a Attrs) FixWidth(value basic.Float) Attrs

FixWidth returns outline with fixed element width.

type BaseElement

type BaseElement[S, T, P any] struct {
	// contains filtered or unexported fields
}

BaseElement is the base implementation of the Element interface with props of type P.

BaseElement is intended for internal use only as part of real element.

func (*BaseElement[S, T, P]) Actuate

func (e *BaseElement[S, T, P]) Actuate()

Actuate implements the Element interface.

func (*BaseElement[S, T, P]) Arrange

func (e *BaseElement[S, T, P]) Arrange(bbox basic.Rect)

Arrange implements the Element interface.

func (*BaseElement[S, T, P]) Attrs added in v0.5.0

func (e *BaseElement[S, T, P]) Attrs() Attrs

Attrs implements the Element interface.

func (*BaseElement[S, T, P]) Dispose

func (e *BaseElement[S, T, P]) Dispose()

Dispose implements the Element interface.

func (*BaseElement[S, T, P]) Draw

func (e *BaseElement[S, T, P]) Draw(screen S)

Draw implements the Element interface.

func (*BaseElement[S, T, P]) Exclude

func (e *BaseElement[S, T, P]) Exclude()

Exclude implements the Element interface.

func (*BaseElement[S, T, P]) Inhibit

func (e *BaseElement[S, T, P]) Inhibit()

Inhibit implements the Element interface.

func (*BaseElement[S, T, P]) Init added in v0.5.0

func (e *BaseElement[S, T, P]) Init(traitFunc TraitFunc[T], propsFunc PropsFunc[P])

Init initializes element.

Init does not validate input parameters.

func (*BaseElement[S, T, P]) IsOff added in v0.5.0

func (e *BaseElement[S, T, P]) IsOff() bool

IsOff implements the Element interface.

This method should only be overloaded if element can be off internally.

func (*BaseElement[S, T, P]) Prepare

func (e *BaseElement[S, T, P]) Prepare()

Prepare implements the Element interface.

func (*BaseElement[S, T, P]) Props added in v0.5.0

func (e *BaseElement[S, T, P]) Props() P

Props returns element props.

Props result is valid only after refresh stage.

func (*BaseElement[S, T, P]) Refresh

func (e *BaseElement[S, T, P]) Refresh()

Refresh implements the Element interface.

func (*BaseElement[S, T, P]) Trait added in v0.5.0

func (e *BaseElement[S, T, P]) Trait() T

Trait implements the Element interface.

func (*BaseElement[S, T, P]) Update

func (e *BaseElement[S, T, P]) Update()

Update implements the Element interface.

type Element

type Element[S, T any] interface {

	// Trait returns trait of element.
	//
	// Trait result is valid only after refresh stage.
	Trait() T

	// IsOff reports whether element is off.
	//
	// IsOff result is valid only after refresh stage.
	IsOff() bool

	// Attrs returns attrs of element.
	//
	// Attrs result is valid only after prepare stage.
	Attrs() Attrs

	// Refresh refreshes element, e.g. by recalculating its trait and props.
	//
	// Containers should refresh all items at this stage, regardless of their statuses.
	Refresh()

	// Prepare prepares element for this iteration, e.g. by precalculating some parameters.
	//
	// Containers should prepare visible items and exclude hidden ones at this stage.
	Prepare()

	// Exclude excludes element for this iteration, e.g. by cleaning up some resources for idle time.
	//
	// Containers should exclude all items at this stage, regardless of their statuses.
	Exclude()

	// Arrange arranges element content within given bounding box, e.g. by executing layout algorithm.
	//
	// Containers should arrange visible items at this stage.
	Arrange(bbox basic.Rect)

	// Actuate actuates element, e.g. by handling input.
	//
	// Containers should actuate interactive items and inhibit other ones at this stage.
	//
	// Containers should iterate through items in reverse order at this stage.
	Actuate()

	// Inhibit inhibits element, e.g. by ignoring input.
	//
	// Containers should inhibit all items at this stage, regardless of their statuses.
	//
	// Containers should iterate through items in reverse order at this stage.
	Inhibit()

	// Update updates element.
	//
	// Containers should update visible items at this stage.
	Update()

	// Draw draws element on given screen.
	//
	// Containers should draw visible items at this stage.
	Draw(screen S)

	// Dispose disposes element.
	//
	// Containers should dispose all items at this stage, regardless of their statuses.
	Dispose()
}

Element of scene displayed on screen of type S and extended by trait of type T.

Element can be in one of following statuses:

  • Interactive: element is displayed and interacts;
  • Visible: element is displayed, but may not interact (interactive elements are visible);
  • Hidden: element is not displayed and does not interact (off elements are hidden).

type PropsFunc added in v0.5.0

type PropsFunc[P any] func(P) P

PropsFunc accepts current props of type P and returns new ones.

type TraitFunc added in v0.5.0

type TraitFunc[T any] func(T) T

TraitFunc accepts current trait of type T and returns new one.

Directories

Path Synopsis
Package element subpackages provide commonly used GUI elements.
Package element subpackages provide commonly used GUI elements.
flexbox
Package flexbox provides container of GUI elements that uses Flex Layout Algorithm for placing them.
Package flexbox provides container of GUI elements that uses Flex Layout Algorithm for placing them.
nothing
Package nothing provides empty GUI element.
Package nothing provides empty GUI element.
overlay
Package overlay provides container of GUI elements that places them one of top of the other considering side anchors.
Package overlay provides container of GUI elements that places them one of top of the other considering side anchors.
padding
Package padding provides wrapper of GUI element that adds extra empty space around it.
Package padding provides wrapper of GUI element that adds extra empty space around it.
pageset
Package pageset provides container of GUI elements that allows to switch them like pages.
Package pageset provides container of GUI elements that allows to switch them like pages.
turnoff
Package turnoff provides wrapper of GUI element that allows turn it off.
Package turnoff provides wrapper of GUI element that allows turn it off.
x
Package x subpackages provides extra GUI elements (experimental).
Package x subpackages provides extra GUI elements (experimental).

Jump to

Keyboard shortcuts

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