Created
March 29, 2018 22:13
-
-
Save zet4/0c2943481d3e63e691e5777379f6277e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package nanoui | |
import ( | |
"go.awoo.fun/of/pkg/nanovg" | |
) | |
// Handler is executed whenever an event occours, use type-switching to get the exact event you want. | |
type Handler interface { | |
Handle(interface{}) error | |
} | |
// Drawer handles the drawing of the elements and is called every frame. | |
type Drawer interface { | |
Draw(bounds []int, ctx *nanovg.Context) | |
} | |
// Component is a combination of Handler and a Drawer. | |
type Component interface { | |
Handler | |
Drawer | |
} | |
// Layouter handles calculating layout for given component in a container. | |
type Layouter interface { | |
Layout(container Components, element int) (bounds []int) | |
} | |
// Styler returns value for given styleset & property combination. | |
type Styler interface { | |
Style(styleset, property string) (value interface{}, ok bool) | |
} | |
// NewDesigner returns a new Designer for building GUI layouts. | |
func NewDesigner(style Styler) Designer { | |
return nil // TODO | |
} | |
// Designer provides methods for laying out a series of Components. | |
type Designer interface { | |
Components | |
// Design finalizes the component tree and returns root Components. | |
Design() Components | |
// AddHandlers adds inline event handlers for current group. | |
AddHandlers(...Handler) | |
// AddDrawers adds inline drawers for current group. | |
AddDrawers(...Drawer) | |
// AddComponents adds Components to the current group. | |
AddComponents(...Component) | |
// With adds a new layer with optionally custom Layouter. | |
// If empty inherits parent's Layouter. | |
With(Layouter, func(d Designer)) | |
} | |
// Components is a container of all the Components... | |
type Components interface { | |
Component | |
// Root returns the base container, likely to have NVGContext. | |
Root() Components | |
// Parent returns the parent container. | |
Parent() Components | |
// Layout returns the Layouter for this container. | |
Layout() Layouter | |
// Components returns list of Components this container has. | |
Components() []Components | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment