canvas

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2020 License: MIT Imports: 7 Imported by: 0

README

Graph

  • graph items can have attached controllers to trigger specific actions

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DrawAction = func(gtx *layout.Context, th *material.Theme) func(element gui.Item) (bool, error) {
	return func(element gui.Item) (bool, error) {

		if el, ok := element.(gui.DrawItem); ok {
			err := el.Draw(gtx, th)
			if err != nil {
				return false, err
			}
		}
		return true, nil
	}
}

DrawFunction is a helper method to invoke the Draw method on an elements

View Source
var EventAction = func(pointer f32.Point) func(element gui.Item) (bool, error) {
	return func(element gui.Item) (bool, error) {
		var active bool

		if el, ok := element.(DynamicElement); ok {
			a, err := el.Event(pointer)
			if err != nil {
				return false, err
			}
			if a {
				active = true
			}
		}
		return active, nil
	}
}

EventAction is a helper method to invoke the Event method on an elements

Functions

This section is empty.

Types

type Action

type Action func(element gui.Item) (bool, error)

Action defines an action to be applied to an Item

type ActiveController

type ActiveController struct {
}

ActiveController is a dummy always 'active' controller

func (*ActiveController) Ack

func (c *ActiveController) Ack() EventEmitter

func (*ActiveController) Color

func (c *ActiveController) Color() color.RGBA

func (*ActiveController) Disable

func (c *ActiveController) Disable()

func (*ActiveController) Enable

func (c *ActiveController) Enable()

func (*ActiveController) IsActive

func (c *ActiveController) IsActive() bool

func (*ActiveController) Label

func (c *ActiveController) Label() string

func (*ActiveController) Set

func (c *ActiveController) Set(active bool)

func (*ActiveController) Trigger

func (c *ActiveController) Trigger() EventReceiver

type CompoundElement

type CompoundElement interface {
	Add(element gui.Item, controller Control)
	Remove(id uint32)
	Elements(gtx *layout.Context, apply Action) (bool, error)
}

TODO : replace with items abstraction CompoundElement represents an element that can have children

type Container

type Container struct {
	*gui.InteractiveElement
	CompoundElement
}

Container represents a ui scene

func NewContainer

func NewContainer(rect *f32.Rectangle) *Container

NewContainer creates a new scene

func (*Container) Draw

func (c *Container) Draw(gtx *layout.Context, th *material.Theme) error

Draw propagates the draw call to all the scene chldren

func (*Container) Event

func (c *Container) Event(gtx *layout.Context, e *pointer.Event) (f32.Point, bool, error)

Event propagates a pointer event to all the scene chldren

func (*Container) Layout

func (c *Container) Layout(ops *op.Ops) layout.Dimensions

type Control

type Control interface {
	Label() string
	Color() color.RGBA
	Disable()
	Enable()
	IsActive() bool
	Set(active bool)
	Trigger() EventReceiver
	Ack() EventEmitter
}

Control is an interface for a controller on the elements behavior

type DynamicElement

type DynamicElement interface {
	gui.Area
	Event(pointer f32.Point) (bool, error)
	Activate() error
	Reset() error
	IsActive() bool
}

DynamicElement represents an interactive UI element

type Event

type Event struct {
	T EventType
	A bool
	S string
}

type EventEmitter

type EventEmitter chan<- Event

type EventReceiver

type EventReceiver <-chan Event

type EventType

type EventType int
const (
	Trigger EventType = iota + 1
	Ack
)

type Events

type Events chan Event

type RawCompoundElement

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

RawCompundElement is the base implementation for a compund element

func NewCompoundElement

func NewCompoundElement() *RawCompoundElement

NewCompoundElement creates a new compound element

func (*RawCompoundElement) Add

func (s *RawCompoundElement) Add(element gui.Item, controller Control)

Add adds a new element to the group

func (*RawCompoundElement) Elements

func (s *RawCompoundElement) Elements(gtx *layout.Context, apply Action) (bool, error)

Elements applies the specified action to all child elements

func (*RawCompoundElement) Remove

func (s *RawCompoundElement) Remove(id uint32)

Remove removes an element by id from the group

func (*RawCompoundElement) Size

func (s *RawCompoundElement) Size() int

Size returns the number of child elements

type RawDynamicElement

type RawDynamicElement struct {
	gui.Area
	// contains filtered or unexported fields
}

RawDynamicElement is the base implementation of a dynamic element

func NewDynamicElement

func NewDynamicElement(rect *f32.Rectangle) *RawDynamicElement

NewDynamicElement creates a new dynamic element

func (*RawDynamicElement) Activate

func (s *RawDynamicElement) Activate() error

Activate triggers the activation of a dynamic element

func (*RawDynamicElement) Event

func (s *RawDynamicElement) Event(pointer f32.Point) (bool, error)

Event propagates the scene event to the element

func (*RawDynamicElement) IsActive

func (s *RawDynamicElement) IsActive() bool

IsActive returns the activation status of a dynamic element

func (*RawDynamicElement) Reset

func (s *RawDynamicElement) Reset() error

Reset resets the state of an dynamic element

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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