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
- Variables
- type Area
- type Assets
- type Bar
- type Button
- type ButtonState
- type ButtonStateEnum
- type Children
- func (o *Children) Clear()
- func (o *Children) Index(name string) (int, bool)
- func (o *Children) Insert(key string, idx int, value *Element)
- func (o *Children) IsNil() bool
- func (o *Children) Put(key string, value *Element)
- func (o *Children) ReIndex(old, new int)
- func (o *Children) Remove(key string) (val *Element, idx int, ok bool)
- func (o *Children) RemoveIndex(idx int) (cell OMC)
- func (o *Children) Rename(old, new string) bool
- func (o *Children) Slice() []OMC
- func (o *Children) Value(key string) (val *Element, idx int, ok bool)
- type Composition
- type CursorDrawer
- type Dimension
- type Element
- func (e *Element) AddChild(name string, o *Element)
- func (e *Element) AddGoml(source []byte) error
- func (e *Element) Child(path string) (*Element, bool)
- func (e *Element) ChildAt(index int) *Element
- func (e *Element) ChildCount() int
- func (e *Element) FindChild(name string, cap int, cursor *[]*Element) bool
- func (e *Element) ForChild(con func(ch *Element))
- func (e *Element) Group() string
- func (e *Element) Hidden() bool
- func (e *Element) ID() string
- func (e *Element) Index() int
- func (e *Element) InsertChild(name string, index int, o *Element)
- func (e *Element) Listen(name string, runner event.StringRunner) *event.Listener
- func (e *Element) LoadGoml(paths ...string) error
- func (e *Element) MarginRealSize() mat.Vec
- func (e *Element) Name() string
- func (e *Element) PaddingSize() mat.Vec
- func (e *Element) Path() string
- func (e *Element) PopChild(index int) *Element
- func (e *Element) ReIndex(old, new int)
- func (e *Element) RemoveChild(name string) *Element
- func (e *Element) Rename(old, new string) bool
- func (e *Element) SetGroup(group string)
- func (e *Element) SetHidden(value bool)
- func (e *Element) SetID(id string)
- func (e *Element) SetIndex(value int)
- func (e *Element) SetName(value string)
- type ErrorEventData
- type FCfg
- type Formatter
- type FormatterBase
- type HoldMap
- type HorizontalFormatter
- func (r *HorizontalFormatter) ChildSize(value float64)
- func (r *HorizontalFormatter) Condition(b bool) bool
- func (r *HorizontalFormatter) MarginPtr() [2]*float64
- func (r *HorizontalFormatter) Provide(takable, taken float64) float64
- func (r *HorizontalFormatter) Ptr() *float64
- func (r *HorizontalFormatter) Size() float64
- func (r *HorizontalFormatter) Sum(a mat.AABB) float64
- type InputState
- type Module
- type ModuleBase
- func (m *ModuleBase) DefaultStyle() goss.Style
- func (m *ModuleBase) Draw(t ggl.Target, g *drw.Geom)
- func (m *ModuleBase) DrawOnTop(t ggl.Target, g *drw.Geom)
- func (m *ModuleBase) Height(takable, taken float64) float64
- func (m *ModuleBase) Init(div *Element)
- func (m *ModuleBase) New() Module
- func (*ModuleBase) OnFrameChange()
- func (m *ModuleBase) PostInit()
- func (*ModuleBase) Update(*ggl.Window, float64)
- func (m *ModuleBase) Width(takable, taken float64) float64
- type ModuleFactory
- type NoFactory
- type Notifier
- type OMC
- type Parser
- type Patch
- type Processor
- type Props
- type RawStyle
- type ResizeMode
- type Scene
- func (s *Scene) AddGoss(source []byte) error
- func (s *Scene) Group(group string) []*Element
- func (s *Scene) ID(id string) *Element
- func (s *Scene) InitStyle(e *Element)
- func (s *Scene) LoadGoss(paths ...string) error
- func (s *Scene) Log(e *Element, err error)
- func (s *Scene) ReloadStyle(e *Element)
- func (s *Scene) SetSheet(sheet pck.Sheet)
- type Scroll
- type Sprite
- type Text
- func (t *Text) Clip(start, end int) error
- func (t *Text) DefaultStyle() goss.Style
- func (t *Text) Dirty()
- func (t *Text) Draw(tr ggl.Target, g *drw.Geom)
- func (t *Text) DrawOnTop(tg ggl.Target, canvas *drw.Geom)
- func (t *Text) Height(takable, taken float64) float64
- func (t *Text) Init(e *Element)
- func (t *Text) New() Module
- func (t *Text) OnFrameChange()
- func (t *Text) SetText(text string)
- func (t *Text) Update(w *ggl.Window, delta float64)
- func (t *Text) UpdateParagraph(width float64)
- func (t *Text) Width(takable, taken float64) float64
- type VerticalFormatter
- func (r *VerticalFormatter) ChildSize(value float64)
- func (r *VerticalFormatter) Condition(b bool) bool
- func (r *VerticalFormatter) MarginPtr() [2]*float64
- func (r *VerticalFormatter) Provide(takable, taken float64) float64
- func (r *VerticalFormatter) Ptr() *float64
- func (r *VerticalFormatter) Size() float64
- func (r *VerticalFormatter) Sum(a mat.AABB) float64
Constants ¶
const ( MouseEntered = "mouse_entered" MouseExited = "mouse_exited" Click = "click" Deselect = "deselect" Select = "select" TextChanged = "text_changed" Error = "error" Enter = "enter" )
even constants
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 ¶
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, } )
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
var Compositions = map[string]Composition{ "vertical": Vertical, "horizontal": Horizontal, }
Compositions maps each composition to its string representation
var ErrNoScene = sterr.New("processor is missing scene to process (use p.SetScene)")
Error thrown when processors scene is nil
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.
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
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
type ButtonState ¶
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 (*Children) RemoveIndex ¶
RemoveIndex removes by index
type Composition ¶
type Composition uint8
Composition ...
const ( // Vertical makes children ordered vertically Vertical Composition = iota // Horizontal makes children ordered horizontally Horizontal )
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 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 (*Element) AddChild ¶
AddChild adds child to Element, child is initialized if root of e is scene root.
func (*Element) AddGoml ¶
AddGoml parses inputted goml source and adds parsed elements to e.
Panics if e.Scene == nil or e.Scene.Parser == nil.
func (*Element) Child ¶
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) ChildCount ¶
ChildCount returns child count on first layer. Useful with ChildAt to loop over all children.
func (*Element) FindChild ¶
FindChild performs recursive search for child, cap specifies how match children is enough.
Passing negative value makes cursor unlimited.
func (*Element) InsertChild ¶
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) MarginRealSize ¶
MarginRealSize returns real size Margin will spam, Fill is considered 0
func (*Element) PaddingSize ¶
PaddingSize returns total size element padding spams
func (*Element) Path ¶
Path returns elements path. Path rebuilding is slow and mainly mant for debbuging purposes.
func (*Element) RemoveChild ¶
RemoveChild removes child by name and returns nil if there is no child with that name on this level
func (*Element) Rename ¶
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.
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
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
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 ¶
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) 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 Parser ¶
Parser handles element parsing form goml, if you don't know goml syntax read the tutorial on github.com/jakubDoka/goml
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
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) OnFrameChange ¶
func (p *Patch) OnFrameChange()
OnFrameChange implements Module interface
func (*Patch) SetPadding ¶
SetPadding sets patch padding 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) 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) 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 ¶
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 ¶
SetScene sets current scene processor uses
you have to set scene before performing any other operations
func (*Processor) Update ¶
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) Horizontal ¶
Horizontal reports whether style composition is horizontal
type RawStyle ¶
RawStyle extends load.RawStyle by some functionality
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
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) InitStyle ¶
InitStyle initializes the stile on given element, this can be called multiple times if style changes
panics if assets are nil
func (*Scene) Log ¶
Log Invokes Error event on scene root and passes ErrorEventData as event argument
func (*Scene) ReloadStyle ¶
ReloadStyle reloads style of an element and all its children f.e.
s.ReloadStyle(&s.Root) // reload ewerithing
panics if assets are nil
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) OnFrameChange ¶
func (s *Scroll) OnFrameChange()
OnFrameChange 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) 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_effects: bool // makes text effects like color and differrent fonts active text_markdown: name // sets a markdown that text will use to render
func (*Text) DefaultStyle ¶
DefaultStyle implements Module interface
func (*Text) OnFrameChange ¶
func (t *Text) OnFrameChange()
OnFrameChange implements Module interface
func (*Text) UpdateParagraph ¶
UpdateParagraph updates the paragraph to fit given width, though can end up bigger
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