-
Notifications
You must be signed in to change notification settings - Fork 5
ui.um
Marek Maskarinec edited this page Sep 14, 2022
·
7 revisions
type Theme* = struct {
fg, bg: uint32
borderColor: uint32
borderSize: th.fu
}
type Generic* = struct {
r: rect.Rect
gridPos: th.Vf2
gridSpan: th.Vf2
theme: Theme
ctx: interface{}
onEvent: fn(eventType: th.uu, ctx: interface{})
pressed: bool
selected: bool
}
A structure all elements have to contain. t can be set manually by the user, s being the dimensions, or it can be set by another elements. onEvent is an event callback. It will pass whatever is set in the ctx field. Event types: eventUnknown eventHover eventPress eventJustPress eventRelease
type Element* = interface {
handle()
draw()
get(): ^Generic
}
An interface every ui element has to implements.
type TextRenderer* = interface {
draw(text: str, pos: th.Vf2, color: uint32, scale: th.fu = 1.0)
measure(text: str): th.Vf2
}
Interface used anywhere, where text is rendered.
type PixelFont* = struct { }```
Bindings around canvas's font rendering functions to make them usable
with the TextRenderer interface.
## fn draw*
`fn (pf: ^PixelFont) draw*(text: str, pos: th.Vf2, color: uint32, scale: th.fu = 1.0) {`
## fn measure*
`fn (pf: ^PixelFont) measure*(text: str): th.Vf2 {`
## fn mkGeneric*
`fn mkGeneric*(): Generic {`
## fn grid*
`fn (g: ^Generic) grid*(x, y: th.uu): ^Generic {`
Functions that sets the grid pos of a Generic
## fn span*
`fn (g: ^Generic) span*(x, y: th.uu): ^Generic {`
Function setting the grid span of a Generic
## fn handle*
`fn (g: ^Generic) handle*() {`
Generic's handle function. It checks for events. If you create your own
ui element and want to have more control over how events are fired, you
don't have to use it.
## fn drawBorder*
`fn drawBorder*(p, d: th.Vf2, t: Theme) {`