ui

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package ui brings robust ui system based on elements. It is deeply inspired by css and html and it uses goml for ui building, this allows you to define your game ui almost as easily as making a website. Goml and goss (how original names!) gives the visuals and you can use Scene.ID() to access elements easily then register event listeners on them. there are some predefined elements you can use as Sprite, Text, Button and more. But that does not mean yo cantot create your own element with complex behavior. Every Element has ths Module, that is what defines the behavior. You can easily take already defined module, and build on top of it. Don't start from scratch when defining one. Use ModuleBase that already implements all methods so you can worry only about methods you need. when you are done with your module, you can register it under an identifier by makeing a ModuleFactory and adding it to parser. Then you can freely use the module in your goml "code" as you would use for example button. Look into examples/ui to see how to setup the ui loop.

Style Docs

When going trough docs you may come across style documentation. Its in following form:

field_name: type //comment

This notation describes that if field with given type is added to style of element, something will be altered. For example:

background: rgba // defines the background color of element

If you provide `background: blue;` in goml, background will be blue. Now lets explane the type.

rgba - color that can be defined as:

name 					// comes from rgba package color map
float					// white color with altered Alpha channel
float float float		// eed green and blue channels (0 - 1)
float float float float	// all channels specified
hex (ffffff=white)		// hex notation

vec - vector type

float		// results into vector with equal dimensions
float float	// each dimension can be differrent

aabb - defines collection of four floats coresponding to left bottom right top respectively

float float float float	// most verbose declaration
float float				// left and right coresponds to first float, top and bottom to second
float					// all four floats coresponds to given value

bool - can be 'true' of 'false'

Index

Constants

View Source
const (
	MouseEntered = "mouse_entered"
	MouseExited  = "mouse_exited"
	Click        = "click"
	Deselect     = "deselect"
	Select       = "select"
	TextChanged  = "text_changed"
	Error        = "error"
	Enter        = "enter"
)

even constants

View Source
const Fill float64 = load.Fill

Fill - if Margin is equal Fill it will take a remaining space in element if there are multiple elements with fill margin, space is split between them

Variables

View Source
var (

	// IgnoreHidden filters out all hidden children
	IgnoreHidden = FCfg{
		Filter: hf,
	}
	// IgnoreHiddenReverse does the same as ignore hidden but also loops in reverse order
	IgnoreHiddenReverse = FCfg{
		Filter:  hf,
		Reverse: true,
	}
)
View Source
var (
	ErrGoml           = sterr.New("error in goml")
	ErrUrlp           = sterr.New("error when loading attributes")
	ErrPath           = sterr.New("in element %v")
	ErrMissingFactory = sterr.New("missing factory with name %s")
)

ParserRelated errors

View Source
var Compositions = map[string]Composition{
	"vertical":   Vertical,
	"horizontal": Horizontal,
}

Compositions maps each composition to its string representation

View Source
var ErrNoScene = sterr.New("processor is missing scene to process (use p.SetScene)")

Error thrown when processors scene is nil

View Source
var ResizeModes = map[string]ResizeMode{
	"expand": Expand,
	"exact":  Exact,
	"shrink": Shrink,
	"ignore": Ignore,
}

ResizeModes maps each resize mode to its string reperesentation

Functions

This section is empty.

Types

type Area

type Area struct {
	Text
	HoldMap

	LineIdx, Line int

	Blinker         timer.Timer
	CursorThickness float64
	CursorMask      mat.RGBA
	// contains filtered or unexported fields
}

Area is a text input element, you can get its content by turning Area.Content into string.

style:

cursor_drawer:			custom_type // something that draws the cursor, it is taken by name from assets
cursor_thickness:		float		// how thick the cursor is
cursor_mask:			rgba		// mask of cursor
cursor_blink_frequency:	float		// how often cursor blinks
auto_frequency:			float		// when you hold some button that controls the input, action starts
									// repeating and this sets how often it repeats
hold_responce_speed:	float		// how long you have to hold on to button until it starts repeating

func (*Area) Dirty

func (a *Area) Dirty()

Dirty is similar to Text.Dirty but it preserves the Start and End.

func (*Area) DrawOnTop

func (a *Area) DrawOnTop(tg ggl.Target, canvas *drw.Geom)

DrawOnTop implements Module interface

func (*Area) Init

func (a *Area) Init(e *Element)

Init implements Module interface

func (*Area) New

func (a *Area) New() Module

New implements ModuleFactory interface

func (*Area) Update

func (a *Area) Update(w *ggl.Window, delta float64)

Update implements Module interface

type Assets

type Assets struct {
	// spritesheet that scene will use
	pck.Sheet
	// Markdown is for text rendering
	Markdowns map[string]*txt.Markdown
	// Cursors are avaliable cursor drawers
	Cursors map[string]CursorDrawer
	// styles should be supplied from .goss files
	goss.Styles
}

Assets contains all data that is important for ui elements

type Bar

type Bar struct {
	Use bool
	// contains filtered or unexported fields
}

Bar holds information about scroll bar

func (*Bar) CalcRatio

func (b *Bar) CalcRatio(size float64)

CalcRatio calculates length and reminder of bar

func (*Bar) Move

func (b *Bar) Move(vel float64)

Move moves the bar

type Button

type Button struct {
	Patch

	Text   Text
	States [len(buttonStates)]ButtonState

	Current  ButtonStateEnum
	Disabled bool
	// contains filtered or unexported fields
}

Button is a button, has lot of space for customization, it can be in three states: idle, hover and pressed, each mode can have different message, texture, padding and mask use of texture is optional and button uses Patch for more flexibility, whe button is initialized, it creates its own Text element witch visible text

style:

	all_text: 								string		// sets text on all state
 idle/hover/pressed/disabled+_text: 		string		// sets text for each state
	all_masks: 								rgba		// sets mask on all states
 idle/hover/pressed/disabled+_mask: 		rgba		// sets mask for each state
 all_regions:                			aabb|name   // sets region on all states
	idle/hover/pressed/disabled+_region:	aabb|name	// sets region for each state
 all_padding:                			aabb	   	// sets padding on all states
	idle/hover/pressed/disabled+_padding:	aabb		// sets padding for each state

func (*Button) ApplyState

func (b *Button) ApplyState(state ButtonStateEnum)

ApplyState applies the button state by index

func (*Button) Init

func (b *Button) Init(e *Element)

Init implements Module interface

func (*Button) New

func (b *Button) New() Module

New implements ModuleFactory interface

func (*Button) PostInit

func (b *Button) PostInit()

func (*Button) SetText

func (b *Button) SetText(text string)

SetText sets text on all states to given value

func (*Button) Update

func (b *Button) Update(w *ggl.Window, delta float64)

Update implements Module interface

type ButtonState

type ButtonState struct {
	Mask            mat.RGBA
	Region, Padding mat.AABB
	Text            str.String
}

ButtonState ...

type ButtonStateEnum

type ButtonStateEnum uint8
const (
	Idle ButtonStateEnum = iota
	Hover
	Pressed
	Disabled
	None
)

type Children

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

Children stores its items in underlying slice and map just keeps indexes

func NChildren

func NChildren() Children

NChildren initializes inner map

func (*Children) Clear

func (o *Children) Clear()

Clear removes all elements

func (*Children) Index

func (o *Children) Index(name string) (int, bool)

Index returns index of a key's value

func (*Children) Insert

func (o *Children) Insert(key string, idx int, value *Element)

Insert insets element under index and key

func (*Children) IsNil

func (o *Children) IsNil() bool

IsNil reports whether Children instance is uninitialized

func (*Children) Put

func (o *Children) Put(key string, value *Element)

Put ...

func (*Children) ReIndex

func (o *Children) ReIndex(old, new int)

ReIndex changes index of an element

func (*Children) Remove

func (o *Children) Remove(key string) (val *Element, idx int, ok bool)

Remove can be very slow if map is huge

func (*Children) RemoveIndex

func (o *Children) RemoveIndex(idx int) (cell OMC)

RemoveIndex removes by index

func (*Children) Rename

func (o *Children) Rename(old, new string) bool

Rename renames element and keeps index

func (*Children) Slice

func (o *Children) Slice() []OMC

Slice returns underlying slice

func (*Children) Value

func (o *Children) Value(key string) (val *Element, idx int, ok bool)

Value ...

type Composition

type Composition uint8

Composition ...

const (
	// Vertical makes children ordered vertically
	Vertical Composition = iota
	// Horizontal makes children ordered horizontally
	Horizontal
)

func (Composition) None

func (c Composition) None() bool

None returns whether this is zero value

type CursorDrawer

type CursorDrawer interface {
	Draw(t ggl.Target, canvas *drw.Geom, base, size mat.Vec, mask mat.RGBA)
}

CursorDrawer is something that draws the cursor inside the Area when area is selected.

type Dimension

type Dimension uint8
const (
	X Dimension = iota
	Y
)

type Element

type Element struct {
	Props
	InputState

	Proc   drw.Preprocessor
	Parent *Element
	Scene  *Scene
	Module Module
	Raw    goml.Element
	Events event.String

	Frame     mat.AABB
	ChildSize mat.Vec

	Styles []string
	// contains filtered or unexported fields
}

Element is only building piece of ui. It has a lot of components. Most significant is Module witch defines appearance and behavior. Then there are Events witch serves a role of comunication with game by connecting listeners. Next are attributes and style, witch is provided by goml and goss. Also if it is not obvious, elements create recursive tree that is encapsulated in scene, and scene is handled by processor, this allows switching between scenes. Every element queries for folloving style propertyes:

margin: 			aabb						// space that element must have around it self, can be fill*
padding:            aabb                        // space inside element that must be empty
size: 				vec							// size element must spam, can be fill*
composition: 		vertical|horizontal			// composition of children (on top of each other or next to each other)
resize_mode/_x/_y: 	expand|shrink|exact|ignore	// how element will react to size of its children and parent
relative:           bool                        // if property is true, element will ignore size of neighboring children
offset:             vec                         // offset adds offset to element from its supposed position

Element also accepts some attributes:

name: every element has to have unique identifier among other children, think of it as a name in file system you can access any child with Element.Child method, if there is child named "car" and it has child "wheel" you can access it from cars parent by "car.wheel". If you don't specify name, string index is assigned

id: id has to be unique for all elements, if there are two or more elements with same id, last one loaded keep the id, you can then quickly access the node by using Scene.ID method which is only reason why ids exist

group: similar to id but multiple elements can be in one group, if you use Scene.Group slice of elements gets returned

style: in style you can specify styling of element with goss syntax. For example "margin: fill;size: 100;" will is equivalent to setting properties of element manually like:

e.Margin = mat.A(Fill, Fill, Fill, FIll)
e.Size = mat.V(100, 100)

styles: there you can specify scene loaded styles that you want to include in element, this way you can write just style name on multiple places and not hardcode attribute for each element with same styling. List or space separated string is accepted as multiple styles can be used ("style1 style2" or ["stile1" "style2"])

hidden: hidden make element hidden from the start, you can write just hidden with no value, and it will be considered true

*fill = reminding space inside parent will be taken, if there is more children with fill prop, space is split equally

Style behavior works very match like css, if you specify list of stiles they will be merged together, each overriding previous in list. The hierarchy is default_style < styles_attribute < style_attribute < inheritance. Yes there is also inheritance. If you provide something like "margin: inherit;" margin will be copied from parents style if he has a margin. As order of children matters, ordered map is used for storing the children. You can index by Element.ChildAt and negative python indexing is supported.

func NElement

func NElement() *Element

NElement constructor initialides internal maps.

func (*Element) AddChild

func (e *Element) AddChild(name string, o *Element)

AddChild adds child to Element, child is initialized if root of e is scene root.

func (*Element) AddGoml

func (e *Element) AddGoml(source []byte) error

AddGoml parses inputted goml source and adds parsed elements to e.

Panics if e.Scene == nil or e.Scene.Parser == nil.

func (*Element) Child

func (e *Element) Child(path string) (*Element, bool)

Child takes dot separated path, by which you can get any child ony any level. If you have element with child "a" and that child has child "b" you ll get the child by "a.b"

func (*Element) ChildAt

func (e *Element) ChildAt(index int) *Element

ChildAt gets child by index.

func (*Element) ChildCount

func (e *Element) ChildCount() int

ChildCount returns child count on first layer. Useful with ChildAt to loop over all children.

func (*Element) FindChild

func (e *Element) FindChild(name string, cap int, cursor *[]*Element) bool

FindChild performs recursive search for child, cap specifies how match children is enough.

Passing negative value makes cursor unlimited.

func (*Element) ForChild

func (e *Element) ForChild(con func(ch *Element))

ForChild performs con for each child.

func (*Element) Group

func (e *Element) Group() string

Group is group getter

func (*Element) Hidden

func (e *Element) Hidden() bool

Hidden is hidden getter

func (*Element) ID

func (e *Element) ID() string

ID getter.

func (*Element) Index

func (e *Element) Index() int

Index getter.

func (*Element) InsertChild

func (e *Element) InsertChild(name string, index int, o *Element)

InsertChild allows specifying destination index were child should be inserted.

Index can differ if you insert with name that some element already have as old element will get removed.

func (*Element) Listen

func (e *Element) Listen(name string, runner event.StringRunner) *event.Listener

Listen registers event listener on element, and returns the listener.

func (*Element) LoadGoml

func (e *Element) LoadGoml(paths ...string) error

LoadGoml abstracts loading of file and calls Element.AddGoml on bites

func (*Element) MarginRealSize

func (e *Element) MarginRealSize() mat.Vec

MarginRealSize returns real size Margin will spam, Fill is considered 0

func (*Element) Name

func (e *Element) Name() string

Name getter.

func (*Element) PaddingSize

func (e *Element) PaddingSize() mat.Vec

PaddingSize returns total size element padding spams

func (*Element) Path

func (e *Element) Path() string

Path returns elements path. Path rebuilding is slow and mainly mant for debbuging purposes.

func (*Element) PopChild

func (e *Element) PopChild(index int) *Element

PopChild removes child by index

func (*Element) ReIndex

func (e *Element) ReIndex(old, new int)

ReIndex moves child from old to new index.

func (*Element) RemoveChild

func (e *Element) RemoveChild(name string) *Element

RemoveChild removes child by name and returns nil if there is no child with that name on this level

func (*Element) Rename

func (e *Element) Rename(old, new string) bool

Rename old to new if there is element which name equals old. If there is already element with name equal to new, it will get removed.

func (*Element) SetGroup

func (e *Element) SetGroup(group string)

SetGroup moves element from one group to another

func (*Element) SetHidden

func (e *Element) SetHidden(value bool)

SetHidden is hidden setter

func (*Element) SetID

func (e *Element) SetID(id string)

SetID changes element id, element is no longer accessable from old id

func (*Element) SetIndex

func (e *Element) SetIndex(value int)

SetIndex sets index of element amongst other children.

It does not make sense to set index if element has no parent and nothin will happen.

func (*Element) SetName

func (e *Element) SetName(value string)

SetName will change name of element, if you rename it to a name of some other element, that element will be removed.

type ErrorEventData

type ErrorEventData struct {
	Element *Element
	Err     error
}

ErrorEventData ...

type FCfg

type FCfg struct {
	Filter  func(ch *Element) bool
	Reverse bool
}

FCfg is configuration for Element.forChild method

type Formatter

type Formatter interface {
	// Size should returns element size stored in elements configuration
	Size() float64
	// Set stets currently processed element
	Set(*Element)
	// Ptr returns pointer to currently resized element dimension
	Ptr() *float64
	// Sum sums up the margin/padding simension
	Sum(mat.AABB) float64
	// Provide calls method on elements module with given arguments
	Provide(float64, float64) float64
	// MarginPtr returns pointers to margin dimensions
	MarginPtr() [2]*float64
	// Condition modifies boolean as needed for resizing
	Condition(bool) bool
	// ChildSize sets final child size fo element
	ChildSize(float64)
}

Formatter handles horizontal or vertical resizing

type FormatterBase

type FormatterBase struct {
	*Element
}

func (*FormatterBase) Set

func (r *FormatterBase) Set(e *Element)

type HoldMap

type HoldMap struct {
	HoldResponceSpeed, AutoFrequency float64
	// contains filtered or unexported fields
}

HoldMap is extracted behavior of text edit, see HoldMat.Hold

func (HoldMap) Hold

func (h HoldMap) Hold(b key.Key, win *ggl.Window, delta float64, do func()) bool

Hold supports Hold and repeat effect, if you hold button for long enough, action starts repeating.

type HorizontalFormatter

type HorizontalFormatter struct {
	FormatterBase
}

HorizontalFormatter is used when resolving Horizontal sizes and margins methods are not documented, for doc look for Formatter interface

func (*HorizontalFormatter) ChildSize

func (r *HorizontalFormatter) ChildSize(value float64)

func (*HorizontalFormatter) Condition

func (r *HorizontalFormatter) Condition(b bool) bool

func (*HorizontalFormatter) MarginPtr

func (r *HorizontalFormatter) MarginPtr() [2]*float64

func (*HorizontalFormatter) Provide

func (r *HorizontalFormatter) Provide(takable, taken float64) float64

func (*HorizontalFormatter) Ptr

func (r *HorizontalFormatter) Ptr() *float64

func (*HorizontalFormatter) Size

func (r *HorizontalFormatter) Size() float64

func (*HorizontalFormatter) Sum

func (r *HorizontalFormatter) Sum(a mat.AABB) float64

type InputState

type InputState struct {
	Hovering bool
}

InputState ...

type Module

type Module interface {
	// DefaultStyle should returns default style of element that will be used as base, returning zero value is fine
	DefaultStyle() goss.Style
	// Init is called when module is inserted into element that is part of a scene
	Init(*Element)
	// PostInit is called after all children of element called Init
	PostInit()
	// Draw should draw the div, draw your triangles onto given target, you can use Geom as canvas
	// though you have to draw it to target too, Geom is cleared and restarted before draw call
	Draw(ggl.Target, *drw.Geom)
	// DrawOnTop does the same thing as draw, but on top of children
	DrawOnTop(ggl.Target, *drw.Geom)
	// Update is stage where your event handling and visual updates should happen
	Update(*ggl.Window, float64)
	// OnFrameChange is called by processor when frame of element changes
	OnFrameChange()

	// Width and Height offers module what it has in disposition and module should return
	// how match it will take, its not recommended to take more then is takable, taken is
	// amount of space element would take with no modification
	Width(takable, taken float64) float64
	Height(takable, taken float64) float64
}

Module is most significant part of element, it implements all behavior, if you want modules to comunicate with each other put them into one module and make that instantiate elements for them, this way you can perform comunication in main module with no reflection

type ModuleBase

type ModuleBase struct {
	*Element
	Background mat.RGBA
}

ModuleBase is a base of every module, you should embed this struct in your module and "override" default methods, though don't forget to call original Init that initializes the styles, if you don't give your element a module, this will be paced as placeholder

func (*ModuleBase) DefaultStyle

func (m *ModuleBase) DefaultStyle() goss.Style

DefaultStyle implements Module interface

func (*ModuleBase) Draw

func (m *ModuleBase) Draw(t ggl.Target, g *drw.Geom)

Draw implements Module interface

func (*ModuleBase) DrawOnTop

func (m *ModuleBase) DrawOnTop(t ggl.Target, g *drw.Geom)

DrawOnTop implements Module interface

func (*ModuleBase) Height

func (m *ModuleBase) Height(takable, taken float64) float64

Height implements Module interface

func (*ModuleBase) Init

func (m *ModuleBase) Init(div *Element)

Init implements Module interface

func (*ModuleBase) New

func (m *ModuleBase) New() Module

New implements ModuleFactory interface

func (*ModuleBase) OnFrameChange

func (*ModuleBase) OnFrameChange()

OnFrameChange implements Module interface

func (*ModuleBase) PostInit

func (m *ModuleBase) PostInit()

func (*ModuleBase) Update

func (*ModuleBase) Update(*ggl.Window, float64)

Update implements Module interface

func (*ModuleBase) Width

func (m *ModuleBase) Width(takable, taken float64) float64

Width implements Module interface

type ModuleFactory

type ModuleFactory interface {
	New() Module
}

ModuleFactory should be an producer of module instances for parser it gives you option to handle initialization your self, witch you can signalize by returning true

type NoFactory

type NoFactory struct{}

NoFactory is used for creating div

func (*NoFactory) New

func (*NoFactory) New() Module

New implements ModuleFactory interface

type Notifier

type Notifier bool

Notifier ...

func (*Notifier) Done

func (n *Notifier) Done()

Done turns of the notification

func (*Notifier) Notify

func (n *Notifier) Notify()

Notify initiates notification

func (Notifier) Should

func (n Notifier) Should() bool

Should returns whether there is notification

type OMC

type OMC struct {
	Key   string
	Value *Element
}

OMC is component of ordered map that stores key the index is under

type Parser

type Parser struct {
	GP *goml.Parser
	GS goss.Parser
	// contains filtered or unexported fields
}

Parser handles element parsing form goml, if you don't know goml syntax read the tutorial on github.com/jakubDoka/goml

func NParser

func NParser() *Parser

NParser creates ready-to-use Parser

func (*Parser) AddFactory

func (p *Parser) AddFactory(name string, mf ModuleFactory)

AddFactory adds a element factory to parser, every element with given name will receive module from the factory

func (*Parser) Parse

func (p *Parser) Parse(source []byte) ([]*Element, error)

Parse parses goml source into list of elements

type Patch

type Patch struct {
	ModuleBase

	Patch           ggl.Patch
	Padding, Region mat.AABB
	Mask            mat.RGBA
	Scale           mat.Vec
}

Patch is similar tor Sprite but uses ggl.Patch instead thus has more styling options

style:

	region:			aabb|name	// rendert texture region
 padding:		aabb	 	// patch padding
	patch_mask:		rgba		// path mask, if there is no region it acts as background color
 patch_scale:	vec			// because Patch is more flexible, specifying scale can create more variations

func (*Patch) Draw

func (p *Patch) Draw(t ggl.Target, canvas *drw.Geom)

Draw implements Module interface

func (*Patch) Init

func (p *Patch) Init(e *Element)

Init implements Module interface

func (*Patch) New

func (p *Patch) New() Module

New implements ModuleFactory interface

func (*Patch) OnFrameChange

func (p *Patch) OnFrameChange()

OnFrameChange implements Module interface

func (*Patch) SetPadding

func (p *Patch) SetPadding(value mat.AABB)

SetPadding sets patch padding and deals with all technical issues

func (*Patch) SetRegion

func (p *Patch) SetRegion(value mat.AABB)

SetRegion sets patch region, and deals with all technical issues

type Processor

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

Processor handles scene composition, it resizes all elements and draws them

func (*Processor) Fetch

func (p *Processor) Fetch(t ggl.Target)

Fetch passes triangles to given target

panics if scene is not set

func (*Processor) Redraw

func (p *Processor) Redraw()

Redraw redraws the scene

should not be called manually, use scene.Redraw.Notify() instead

panics if scene is not set

func (*Processor) Render

func (p *Processor) Render(r ggl.Renderer)

Render make Renderer render ui (yes)

panics if scene is not set

func (*Processor) Resize

func (p *Processor) Resize()

Resize prefroms scene resizing

should not be called manually, use scene.Resize.Notify() instead

panics if scene is not set

func (*Processor) SetFrame

func (p *Processor) SetFrame(value mat.AABB)

SetFrame sets the frame of Processor witch also updates all elements inside you can call this every frame if your window is resizable as update will not get triggered if value == oldFrame

panics if scene is not set

func (*Processor) SetScene

func (p *Processor) SetScene(s *Scene)

SetScene sets current scene processor uses

you have to set scene before performing any other operations

func (*Processor) Update

func (p *Processor) Update(w *ggl.Window, delta float64)

Update calls update on all elements and performs resizing and redrawing if needed call this every frame, resizing and should not happen if user is not interacting with ui. Of corse you can trigger either one by:

scene.Resize.Notify()
scene.Redraw.Notify()

note that resizing also triggers consequent Redrawing

panics if scene is not set

type Props

type Props struct {
	RawStyle
	// Margin defines spacing between elements, it supports Fill mode
	Margin mat.AABB
	// Padding defines how match space inside the elements should be free
	// Fill is not supported
	Padding mat.AABB
	// Size defines default size of element
	Size mat.Vec
	// Composition defines orientation of children in div, if horizontal
	// or vertical, if Composition.None() then it is initialized to be Vertical
	Composition
	// resize mode sets how element should react to size of children, see
	// constants documentation, if ResizeMode.None() then it is initialized with Expand
	Resizing [2]ResizeMode
	// Relative if true makes element ignore size of neighbors this it will be sized
	// and positioned merely by its offset
	Relative bool
	// Offset is used when moving elements inside scroll but if Relative is true
	// offset will be applied as offset from position where element would end up
	// if it were only element in the parent
	Offest mat.Vec
}

Props determinate look of Element and its properties

func (*Props) Expands

func (s *Props) Expands(dim Dimension) bool

func (*Props) Horizontal

func (s *Props) Horizontal() bool

Horizontal reports whether style composition is horizontal

func (*Props) Ingors

func (s *Props) Ingors(dim Dimension) bool

func (*Props) Init

func (s *Props) Init()

Init initializes the style

func (*Props) Shrinks

func (s *Props) Shrinks(dim Dimension) bool

type RawStyle

type RawStyle struct {
	load.RawStyle
}

RawStyle extends load.RawStyle by some functionality

func (RawStyle) Align

func (r RawStyle) Align(key string, def txt.Align) (v txt.Align)

func (RawStyle) Composition

func (r RawStyle) Composition(key string) (c Composition)

Composition parses style composition, if parsing fails, Vertical is returned

func (RawStyle) CursorDrawer

func (r RawStyle) CursorDrawer(key string, drawers map[string]CursorDrawer, def CursorDrawer) (v CursorDrawer)

CursorDrawer retrieves a cursor drawer from style

func (RawStyle) ResizeMode

func (r RawStyle) ResizeMode(key string) (e ResizeMode)

ResizeMode parser resize mode, if pasring fails Expand is returned

type ResizeMode

type ResizeMode uint8

ResizeMode ...

const (
	// element expands to size of children but does not shrink under default size
	Expand ResizeMode = iota
	// element will shrink or expand based of children
	Exact
	// element will shrink to size of children, but children can overflow
	Shrink
	// element will ignore children size and leave overflow or underflow
	Ignore
)

Resize modes

func (ResizeMode) None

func (c ResizeMode) None() bool

None returns whether this is zero value

type Scene

type Scene struct {
	Redraw, Resize Notifier
	Root           Element
	Assets         *Assets
	Batch          ggl.Batch

	TextSelected bool

	*Parser
	// contains filtered or unexported fields
}

Scene is a ui scene, it stores all elements and notifiers for Processor to process

func NEmptyScene

func NEmptyScene() *Scene

in comparison to NScene this function can me used before window creation

func NScene

func NScene() *Scene

NScene returns ready-to-use scene, do not use Scene{}

use only after you created the window

method panics if this is called before window creation

func (*Scene) AddGoss

func (s *Scene) AddGoss(source []byte) error

func (*Scene) Group

func (s *Scene) Group(group string) []*Element

Group returns all elements in given group

func (*Scene) ID

func (s *Scene) ID(id string) *Element

ID returns element or null if no element is under id

func (*Scene) InitStyle

func (s *Scene) InitStyle(e *Element)

InitStyle initializes the stile on given element, this can be called multiple times if style changes

panics if assets are nil

func (*Scene) LoadGoss

func (s *Scene) LoadGoss(paths ...string) error

func (*Scene) Log

func (s *Scene) Log(e *Element, err error)

Log Invokes Error event on scene root and passes ErrorEventData as event argument

func (*Scene) ReloadStyle

func (s *Scene) ReloadStyle(e *Element)

ReloadStyle reloads style of an element and all its children f.e.

s.ReloadStyle(&s.Root) // reload ewerithing

panics if assets are nil

func (*Scene) SetSheet

func (s *Scene) SetSheet(sheet pck.Sheet)

SetSheet sets the sprite sheet Scene will use

type Scroll

type Scroll struct {
	ModuleBase
	drw.SpriteViewport

	BarWidth, Friction, ScrollSensitivity  float64
	BarColor, RailColor, IntersectionColor mat.RGBA
	X, Y                                   Bar
	// contains filtered or unexported fields
}

Scroll can make element visible trough scrollable viewport

style:

bar_width:			float	// sets bar thickness
friction:			float	// higher the value, less sliding, negative == no sliding
scroll_sensitivity:	float	// how match will scroll slide
bar_color:			rgba	// bar handle color
rail_color:			rgba	// bar rail color
intersection_color:	rgba	// if both bars are active, rectangle appears in a corner
bar_x/bar_y/bars:	bool	// makes bars visible and active

func (*Scroll) DrawOnTop

func (s *Scroll) DrawOnTop(t ggl.Target, c *drw.Geom)

DrawOnTop implements module interface

func (*Scroll) Init

func (s *Scroll) Init(e *Element)

Init implements module interface

func (*Scroll) New

func (s *Scroll) New() Module

New implements ModuleFactory interface

func (*Scroll) OnFrameChange

func (s *Scroll) OnFrameChange()

OnFrameChange implements module interface

func (*Scroll) Update

func (s *Scroll) Update(w *ggl.Window, delta float64)

Update implements module interface

type Sprite

type Sprite struct {
	ModuleBase
	Sprite ggl.Sprite

	Mask mat.RGBA
}

Sprite is sprite for ui elements style:

mask:	rgba		// texture modulation
region:	aabb|name	// from where texture should be sampled from

func (*Sprite) Draw

func (s *Sprite) Draw(t ggl.Target, canvas *drw.Geom)

Draw implements Module interface

func (*Sprite) Init

func (s *Sprite) Init(e *Element)

Init implements Module interface

func (*Sprite) New

func (s *Sprite) New() Module

New implements ModuleFactory interface

func (*Sprite) OnFrameChange

func (s *Sprite) OnFrameChange()

OnFrameChange implements Module interface

type Text

type Text struct {
	ModuleBase
	txt.Paragraph
	*txt.Markdown
	Composed                  bool
	SelectionColor            mat.RGBA
	Start, End, LineIdx, Line int
	// contains filtered or unexported fields
}

Text handles text rendering

style:

	text_scale:				vec						// size of font
	text_color:				rgba					// color by with text is pre-multiplied
	text_size:				vec						// works as element size
	text_margin:			aabb					// works as element margin
 text_padding:			aabb					// works as element padding
	text_background:		rgba					// works as moduleBase background
	text_selection_color:	rgba					// color if text selection
	text_align:				float|left|middle|right	// text align
	text_no_effects:		bool					// makes text effects like color and differrent fonts disabled
	text_markdown:			name					// sets a markdown that text will use to render

func (*Text) Clip

func (t *Text) Clip(start, end int) error

Clip copies the range into clipboard

func (*Text) DefaultStyle

func (t *Text) DefaultStyle() goss.Style

DefaultStyle implements Module interface

func (*Text) Dirty

func (t *Text) Dirty()

Dirty forces text to update

func (*Text) Draw

func (t *Text) Draw(tr ggl.Target, g *drw.Geom)

Draw implements Module interface

func (*Text) DrawOnTop

func (t *Text) DrawOnTop(tg ggl.Target, canvas *drw.Geom)

DrawOnTop implements Module interface

func (*Text) Height

func (t *Text) Height(takable, taken float64) float64

Height implements Module interface

func (*Text) Init

func (t *Text) Init(e *Element)

Init implements Module interface

func (*Text) New

func (t *Text) New() Module

New implements module factory interface

func (*Text) OnFrameChange

func (t *Text) OnFrameChange()

OnFrameChange implements Module interface

func (*Text) SetText

func (t *Text) SetText(text string)

SetText sets text and displays the change

func (*Text) Update

func (t *Text) Update(w *ggl.Window, delta float64)

Update implements Module interface

func (*Text) UpdateParagraph

func (t *Text) UpdateParagraph(width float64)

UpdateParagraph updates the paragraph to fit given width, though can end up bigger

func (*Text) Width

func (t *Text) Width(takable, taken float64) float64

Width implements Module interface

type VerticalFormatter

type VerticalFormatter struct {
	FormatterBase
}

VerticalFormatter is used when resolving Vertical sizes and margins methods are not documented, for doc look for Formatter interface

func (*VerticalFormatter) ChildSize

func (r *VerticalFormatter) ChildSize(value float64)

func (*VerticalFormatter) Condition

func (r *VerticalFormatter) Condition(b bool) bool

func (*VerticalFormatter) MarginPtr

func (r *VerticalFormatter) MarginPtr() [2]*float64

func (*VerticalFormatter) Provide

func (r *VerticalFormatter) Provide(takable, taken float64) float64

func (*VerticalFormatter) Ptr

func (r *VerticalFormatter) Ptr() *float64

func (*VerticalFormatter) Size

func (r *VerticalFormatter) Size() float64

func (*VerticalFormatter) Sum

func (r *VerticalFormatter) Sum(a mat.AABB) float64

Jump to

Keyboard shortcuts

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