-
Notifications
You must be signed in to change notification settings - Fork 5
ui.um
Marek Maskarinec edited this page Apr 15, 2021
·
7 revisions
A simple ui framework.
// start of the program
mainbox := ui.mkbox([]ui.element{ui.mklabel("Hello World", 1, 0xff)}, false)
ui.main = mainbox
// in loop
ui.handle(cam.w, cam.h)
## consts
`TOP` - used for text alignment to top/left
`MID` - used for text alignment to middle
`BOT` - used for text alignment ot bottom/right
`CENTER` - used for image scaling. This will not resize it at all.
`SCALE` - used for image scaling. This will resize it, but not deform.
## type element
```go
type element* = interface {
draw()
calculate()
handle()
gspan(): ^int
gpadding(): ^rectangle.rect
gdimensions(): ^rectangle.rect
}
Element interface. Element is the main element of ui.
type box* = struct {
children: []element // children in the box
padding, dimensions: rectangle.rect
span: int
vertical: bool // switch between vbox and hbox
image: image.img // background image
imagemode: int // image mode. see constants
imgs: int
imgx, imgy: int
}
Box element. It organizes other elements. You can even nest them.
type label* = struct {
text: str
textsize: real
textcolor: uint32
valign: int
halign: int
bgcolor: uint32
padding, dimensions: rectangle.rect
span: int
}
Label element. Self explanatory.
type button* = struct {
label: label
toggled: bool
pressed: bool
justpressed: bool
clickfunc: bool
padding, dimensions: rectangle.rect
span: int
onpress, onjustpress: fn()
ontoggle: fn(toggled: bool)
}
Button element. You can either hook up callbacks or use the pressed, justpressed and toggled fields.
fn mkbox*(c: []element, vertical: bool): box
Makes a box.
fn mklabel*(text: str, textsize: real, textcolor: uint32): label
Makes a label.
fn mkbutton*(l: label): button
Makes a button.
fn handle*(w, h: int32)
Handles ui. Pass w and h of the camera.