Text box arena, ui init func

This commit is contained in:
Ilia Demianenko 2023-10-04 19:40:02 -07:00
parent 30d45cd7fd
commit f1727dbc8d
2 changed files with 11 additions and 12 deletions

View File

@ -26,7 +26,7 @@ export fn oc_on_init() void {
surface = oc.Surface.canvas(); surface = oc.Surface.canvas();
canvas = oc.Canvas.create(); canvas = oc.Canvas.create();
ui_ctx.init(); ui.init(&ui_ctx);
var fonts = [_]*oc.Font{ &font_regular, &font_bold }; var fonts = [_]*oc.Font{ &font_regular, &font_bold };
var font_names = [_][]const u8{ "/OpenSans-Regular.ttf", "/OpenSans-Bold.ttf" }; var font_names = [_][]const u8{ "/OpenSans-Regular.ttf", "/OpenSans-Bold.ttf" };
@ -300,7 +300,7 @@ fn widgets(arena: *oc.Arena) void {
.height = .text, .height = .text,
}, },
}); });
var textResult = ui.textBox("text", arena.*, text); var textResult = ui.textBox("text", arena, text);
if (textResult.changed) { if (textResult.changed) {
text_arena.clear(); text_arena.clear();
text = text_arena.pushStr(textResult.text) catch { text = text_arena.pushStr(textResult.text) catch {

View File

@ -2795,9 +2795,6 @@ pub const ui = struct {
edit_word_selection_initial_mark: i32, edit_word_selection_initial_mark: i32,
theme: *Theme, theme: *Theme,
extern fn oc_ui_init(context: *Context) void;
pub const init = oc_ui_init;
}; };
const LayoutAlignmentInternal = extern struct { const LayoutAlignmentInternal = extern struct {
@ -2875,7 +2872,7 @@ pub const ui = struct {
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
// [UI]: context initialization and frame cycle // [UI]: context initialization and frame cycle
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
extern fn oc_ui_init(context: *Context) void;
extern fn oc_ui_get_context() *Context; extern fn oc_ui_get_context() *Context;
extern fn oc_ui_set_context(context: *Context) void; extern fn oc_ui_set_context(context: *Context) void;
@ -2885,19 +2882,21 @@ pub const ui = struct {
extern fn oc_ui_draw() void; extern fn oc_ui_draw() void;
extern fn oc_ui_set_theme(theme: *Theme) void; extern fn oc_ui_set_theme(theme: *Theme) void;
pub const init = oc_ui_init;
pub const getContext = oc_ui_get_context; pub const getContext = oc_ui_get_context;
pub const setContext = oc_ui_set_context; pub const setContext = oc_ui_set_context;
pub const processCEvent = oc_ui_process_event;
pub const endFrame = oc_ui_end_frame; pub const processCEvent = oc_ui_process_event;
pub const draw = oc_ui_draw;
pub const setTheme = oc_ui_set_theme;
pub fn beginFrame(size: Vec2, default_style: *Style) void { pub fn beginFrame(size: Vec2, default_style: *Style) void {
var default_style_and_mask = convertStyle(default_style); var default_style_and_mask = convertStyle(default_style);
oc_ui_begin_frame(size, &default_style_and_mask.style, default_style_and_mask.mask); oc_ui_begin_frame(size, &default_style_and_mask.style, default_style_and_mask.mask);
} }
pub const endFrame = oc_ui_end_frame;
pub const draw = oc_ui_draw;
pub const setTheme = oc_ui_set_theme;
const StyleAndMaskInternal = struct { const StyleAndMaskInternal = struct {
style: StyleInternal, style: StyleInternal,
mask: StyleMaskInternal, mask: StyleMaskInternal,
@ -3192,7 +3191,7 @@ pub const ui = struct {
accepted: bool, accepted: bool,
text: Str8, text: Str8,
}; };
extern fn oc_ui_text_box_str8(name: Str8, arena: Arena, text: Str8) TextBoxResultInternal; extern fn oc_ui_text_box_str8(name: Str8, arena: *Arena, text: Str8) TextBoxResultInternal;
const SelectPopupInfoInternal = extern struct { const SelectPopupInfoInternal = extern struct {
changed: bool, changed: bool,
@ -3269,7 +3268,7 @@ pub const ui = struct {
text: []u8, text: []u8,
}; };
pub fn textBox(name: []const u8, arena: Arena, text: []const u8) TextBoxResult { pub fn textBox(name: []const u8, arena: *Arena, text: []const u8) TextBoxResult {
var result_internal = oc_ui_text_box_str8(Str8.fromSlice(name), arena, Str8.fromSlice(text)); var result_internal = oc_ui_text_box_str8(Str8.fromSlice(name), arena, Str8.fromSlice(text));
return .{ return .{
.changed = result_internal.changed, .changed = result_internal.changed,