Files
imgui/microui/microui.odin

150 lines
3.6 KiB
Odin

package microui_wrapper
import "core:log"
import mu "vendor:microui"
Context :: mu.Context
@(private) set_clipboard :: proc(userdata: rawptr, text: string) -> bool {
return false
}
@(private) get_clipboard :: proc(userdata: rawptr) -> (string, bool) {
return {}, false
}
@(private) text_width :: proc(font: mu.Font, text: string) -> i32 {
// log.warnf("TODO: SS - Implement %v.", #procedure)
return 0 // TEMP: SS
}
@(private) text_height :: proc(font: mu.Font) -> i32 {
// log.warnf("TODO: SS - Implement %v.", #procedure)
return 0 // TEMP: SS
}
Command :: mu.Command
Command_Jump :: mu.Command_Jump // Internal. Should not be used externally.
Command_Clip :: mu.Command_Clip
Command_Icon :: mu.Command_Icon
Command_Rect :: mu.Command_Rect
Command_Text :: mu.Command_Text
Rect :: mu.Rect
Input :: struct {
mouse_x, mouse_y: u16,
mouse_buttons_pressed: mu.Mouse_Set,
mouse_buttons_released: mu.Mouse_Set,
}
init :: proc(ctx: ^Context) -> bool {
assert(ctx != nil)
clipboard_user_data: rawptr = nil // TEMP: SS
mu.init(ctx, set_clipboard, get_clipboard, clipboard_user_data)
ctx.text_width = text_width
ctx.text_height = text_height
return true
}
begin :: proc(ctx: ^Context, input: Input) {
assert(ctx != nil)
{ // Apply input.
mx := i32(input.mouse_x)
my := i32(input.mouse_y)
mu.input_mouse_move(ctx, mx, my)
for b in input.mouse_buttons_pressed {
mu.input_mouse_down(ctx, mx, my, b)
}
for b in input.mouse_buttons_released {
mu.input_mouse_up(ctx, mx, my, b)
}
}
// Now, begin.
mu.begin(ctx)
{ // TEMP: SS - Just trying it out.
// if mu.begin_window(
// ctx,
// "Test",
// mu.Rect {
// x = 0, y = 20,
// w = 256, h = 256,
// },
// opt = {}
// ) {
// mu.label(ctx, "First:")
// if mu.button(ctx, "Button1") == {.SUBMIT} {
// log.infof("Button1 pressed")
// }
// mu.label(ctx, "Second:");
// if mu.button(ctx, "Button2") == {.SUBMIT} {
// mu.open_popup(ctx, "My Popup");
// }
// if (mu.begin_popup(ctx, "My Popup")) {
// mu.label(ctx, "Hello world!")
// if mu.button(ctx, "Button3") == {.SUBMIT} {
// log.infof("Button3 pressed")
// }
// mu.end_popup(ctx)
// }
// mu.end_window(ctx)
// }
}
}
end :: proc(ctx: ^Context) {
assert(ctx != nil)
mu.end(ctx)
}
begin_window :: proc(ctx: ^Context, title: string, rect: mu.Rect) -> bool {
assert(ctx != nil)
opt := mu.Options {
// .NO_CLOSE, // TEMP: SS - Some weird bug is happening. Windows are closing randomly, but this helps..
}
return mu.begin_window(
ctx,
title,
rect,
opt,
)
}
end_window :: proc(ctx: ^Context) {
assert(ctx != nil)
mu.end_window(ctx)
}
button :: proc(ctx: ^Context, title: string) -> bool {
return mu.button(ctx, title) == {.SUBMIT}
}
pop_draw_command :: proc(ctx: ^Context, last_cmd: ^mu.Command) -> ^mu.Command {
cmd: ^mu.Command = last_cmd
if !mu.next_command(ctx, &cmd) {
return nil
}
assert(cmd != nil)
return cmd
}
shutdown :: proc(ctx: ^Context) {
assert(ctx != nil)
ctx^ = {}
}