Text element
This commit is contained in:
parent
316ec8e178
commit
a02960283c
4 changed files with 194 additions and 132 deletions
20
ui.odin
20
ui.odin
|
|
@ -3,6 +3,7 @@ package main
|
|||
import "core:math/linalg"
|
||||
import "core:fmt"
|
||||
import "core:mem"
|
||||
import rl "libraries/raylib"
|
||||
|
||||
@(private="file") state_current: ^UiState
|
||||
|
||||
|
|
@ -10,12 +11,14 @@ UiElementType :: enum {
|
|||
Input,
|
||||
Button,
|
||||
Container,
|
||||
Text,
|
||||
}
|
||||
|
||||
UiElementData :: union {
|
||||
UiElementData_Button,
|
||||
UiElementData_Input,
|
||||
UiElementData_Container,
|
||||
UiElementData_Text,
|
||||
}
|
||||
|
||||
UiElement :: struct {
|
||||
|
|
@ -42,7 +45,9 @@ UiState :: struct {
|
|||
}
|
||||
|
||||
UiStyle :: struct {
|
||||
margin, padding: f32,
|
||||
margin, padding: f32,
|
||||
font_size, font_sep: f32,
|
||||
font: rl.Font,
|
||||
}
|
||||
|
||||
ui_init :: proc(state: ^UiState, style: UiStyle, origin: v2, allocator: mem.Allocator) {
|
||||
|
|
@ -118,6 +123,19 @@ ui_input :: proc(size: v2, data: UiElementData_Input) {
|
|||
append(&state.elements, UiElement{id = state.id_current, area = area, type = .Input, data = data})
|
||||
}
|
||||
|
||||
UiElementData_Text :: struct {
|
||||
text: cstring,
|
||||
color: rl.Color,
|
||||
}
|
||||
|
||||
ui_text :: proc(data: UiElementData_Text) {
|
||||
state := state_current
|
||||
size := rl.MeasureTextEx(state.style.font, data.text, state.style.font_size, state.style.font_sep)
|
||||
area := _ui_advance_element(state, size)
|
||||
state.id_current.element_index += 1
|
||||
append(&state.elements, UiElement{id = state.id_current, area = area, type = .Text, data = data})
|
||||
}
|
||||
|
||||
ui_same_line :: proc() {
|
||||
state_current.same_line = true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue