From 037e00a0a2637062b402febcedceccbc75e4307f Mon Sep 17 00:00:00 2001 From: David Vanderson Date: Mon, 28 Jul 2025 15:04:48 -0400 Subject: [PATCH] consolidate box and boxEqual This brings us closer to having high-level functions include init_opts to future-proof them against adding more functionality. Sorry for the breakage. .vertical is now the default, so code like: dvui.box(@src(), .vertical, ...) goes to: dvui.box(@src(), .{}, ...) And code like: dvui.box(@src(), .horizontal, ...) goes to: dvui.box(@src(), .{ .dir = .horizontal }, ...) --- README.md | 6 +-- examples/app.zig | 2 +- examples/dx11-standalone.zig | 2 +- examples/raylib-ontop.zig | 4 +- examples/raylib-standalone.zig | 4 +- examples/sdl-standalone.zig | 4 +- readme-implementation.md | 6 +-- src/Debug.zig | 52 ++++++++++++------------- src/Examples.zig | 16 ++++---- src/Examples/animations.zig | 16 ++++---- src/Examples/basic_widgets.zig | 36 ++++++++--------- src/Examples/calculator.zig | 6 +-- src/Examples/debugging.zig | 12 +++--- src/Examples/dialogs.zig | 18 ++++----- src/Examples/grid.zig | 42 ++++++++++---------- src/Examples/icon_browser.zig | 4 +- src/Examples/layout.zig | 48 +++++++++++------------ src/Examples/menus.zig | 30 +++++++-------- src/Examples/plots.zig | 8 ++-- src/Examples/reorder_tree.zig | 24 ++++++------ src/Examples/scroll_canvas.zig | 12 +++--- src/Examples/scrolling.zig | 28 +++++++------- src/Examples/struct_ui.zig | 10 ++--- src/Examples/styling.zig | 28 +++++++------- src/Examples/text_entry.zig | 30 +++++++-------- src/Examples/text_layout.zig | 6 +-- src/Examples/theming.zig | 22 +++++------ src/Rect.zig | 14 +++---- src/dvui.zig | 39 +++++++------------ src/structEntry.zig | 64 +++++++++++++++---------------- src/widgets/BoxWidget.zig | 2 +- src/widgets/ColorPickerWidget.zig | 8 ++-- src/widgets/DropdownWidget.zig | 2 +- src/widgets/PlotWidget.zig | 10 ++--- src/widgets/TextEntryWidget.zig | 2 +- src/widgets/TextLayoutWidget.zig | 2 +- 36 files changed, 304 insertions(+), 315 deletions(-) diff --git a/README.md b/README.md index 47c795d3..0cd2d6e3 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ For an intro to immediate mode guis, see: https://github.com/ocornut/imgui/wiki# ```zig // Let's wrap the sliderEntry widget so we have 3 that represent a Color pub fn colorSliders(src: std.builtin.SourceLocation, color: *dvui.Color, opts: Options) void { - var hbox = dvui.box(src, .horizontal, opts); + var hbox = dvui.box(src, .{ .dir = .horizontal }, opts); defer hbox.deinit(); var red: f32 = @floatFromInt(color.r); @@ -216,7 +216,7 @@ The estimate is visible in the demo window Animations > Clock > "Estimate of fra The easiest way to use widgets is through the high-level functions that create and install them: ```zig { - var box = dvui.box(@src(), .vertical, .{.expand = .both}); + var box = dvui.box(@src(), .{}, .{.expand = .both}); defer box.deinit(); // widgets run here will be children of box @@ -227,7 +227,7 @@ These functions allocate memory for the widget onto an internal arena allocator Instead you can allocate the widget on the stack using the lower-level functions: ```zig { - var box = BoxWidget.init(@src(), .vertical, false, .{.expand = .both}); + var box = BoxWidget.init(@src(), .{}, .{.expand = .both}); // box now has an id, can look up animations/timers box.install(); diff --git a/examples/app.zig b/examples/app.zig index ad5f97f1..254a7bd6 100644 --- a/examples/app.zig +++ b/examples/app.zig @@ -127,7 +127,7 @@ pub fn frame() !dvui.App.Result { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Pinch Zoom or Scale", .{}, .{}); if (dvui.buttonIcon(@src(), "plus", dvui.entypo.plus, .{}, .{}, .{})) { diff --git a/examples/dx11-standalone.zig b/examples/dx11-standalone.zig index d1c62030..75d77048 100644 --- a/examples/dx11-standalone.zig +++ b/examples/dx11-standalone.zig @@ -184,7 +184,7 @@ fn gui_frame() !void { { dvui.labelNoFmt(@src(), "These are drawn directly by the backend, not going through DVUI.", .{}, .{ .margin = .{ .x = 4 } }); - var box = dvui.box(@src(), .horizontal, .{ .expand = .horizontal, .min_size_content = .{ .h = 40 }, .background = true, .margin = .{ .x = 8, .w = 8 } }); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal, .min_size_content = .{ .h = 40 }, .background = true, .margin = .{ .x = 8, .w = 8 } }); defer box.deinit(); // Here is some arbitrary drawing that doesn't have to go through DVUI. diff --git a/examples/raylib-ontop.zig b/examples/raylib-ontop.zig index 0d1000e7..59435a4c 100644 --- a/examples/raylib-ontop.zig +++ b/examples/raylib-ontop.zig @@ -61,7 +61,7 @@ pub fn main() !void { ray.ClearBackground(RaylibBackend.dvuiColorToRaylib(dvui.themeGet().color_fill_window)); { - var b = dvui.box(@src(), .vertical, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); + var b = dvui.box(@src(), .{}, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); defer b.deinit(); if (ray.GuiIsLocked()) { @@ -111,7 +111,7 @@ fn colorPicker(result: *dvui.Color) void { const color_hex = result.toHexString(); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.labelNoFmt(@src(), &color_hex, .{}, .{ diff --git a/examples/raylib-standalone.zig b/examples/raylib-standalone.zig index d3fbdc16..9f2429b2 100644 --- a/examples/raylib-standalone.zig +++ b/examples/raylib-standalone.zig @@ -169,7 +169,7 @@ fn dvui_frame() bool { defer scaler.deinit(); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); if (dvui.button(@src(), "Zoom In", .{}, .{})) { @@ -183,7 +183,7 @@ fn dvui_frame() bool { dvui.labelNoFmt(@src(), "Below is drawn directly by the backend, not going through DVUI.", .{}, .{ .margin = .{ .x = 4 } }); - var box = dvui.box(@src(), .vertical, .{ .expand = .horizontal, .min_size_content = .{ .h = 40 }, .background = true, .margin = .{ .x = 8, .w = 8 } }); + var box = dvui.box(@src(), .{}, .{ .expand = .horizontal, .min_size_content = .{ .h = 40 }, .background = true, .margin = .{ .x = 8, .w = 8 } }); defer box.deinit(); // Here is some arbitrary drawing that doesn't have to go through DVUI. diff --git a/examples/sdl-standalone.zig b/examples/sdl-standalone.zig index fac7d531..a23fbcde 100644 --- a/examples/sdl-standalone.zig +++ b/examples/sdl-standalone.zig @@ -182,7 +182,7 @@ fn gui_frame() bool { defer scaler.deinit(); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); if (dvui.button(@src(), "Zoom In", .{}, .{})) { @@ -196,7 +196,7 @@ fn gui_frame() bool { dvui.labelNoFmt(@src(), "Below is drawn directly by the backend, not going through DVUI.", .{}, .{ .margin = .{ .x = 4 } }); - var box = dvui.box(@src(), .horizontal, .{ .expand = .horizontal, .min_size_content = .{ .h = 40 }, .background = true, .margin = .{ .x = 8, .w = 8 } }); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal, .min_size_content = .{ .h = 40 }, .background = true, .margin = .{ .x = 8, .w = 8 } }); defer box.deinit(); // Here is some arbitrary drawing that doesn't have to go through DVUI. diff --git a/readme-implementation.md b/readme-implementation.md index 3c895bd0..6f92ab34 100644 --- a/readme-implementation.md +++ b/readme-implementation.md @@ -155,7 +155,7 @@ Examples ```zig // caller is responsible for passing src and .id_extra if needed fn my_wrapper(src: std.builtin.SourceLocation, opts: Options) void { - var wrapper_box = dvui.box(src, .horizontal, opts); + var wrapper_box = dvui.box(src, .{ .dir = .horizontal }, opts); defer wrapper_box.deinit(); // label is a child of wrapper_box, so can just call @src() here @@ -164,13 +164,13 @@ fn my_wrapper(src: std.builtin.SourceLocation, opts: Options) void { pub fn frame() void { // normally we pass @src() and that is good enough - var vbox = dvui.box(@src(), .vertical, .{}); + var vbox = dvui.box(@src(), .{}, .{}); defer vbox.deinit(); for (0..3) |i| { // this will be called multiple times with the same parent and // @src(), so pass .id_extra here to keep the IDs unique - var hbox = dvui.box(@src(), .horizontal, .{ .id_extra = i }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .id_extra = i }); // label is a child of hbox, so can just call @src() here dvui.label(@src(), "Label {d}", .{i}, .{}); diff --git a/src/Debug.zig b/src/Debug.zig index b9e50153..9bd0371d 100644 --- a/src/Debug.zig +++ b/src/Debug.zig @@ -111,7 +111,7 @@ pub fn show(self: *Debug) void { float.dragAreaSet(dvui.windowHeader("DVUI Debug", "", &self.open)); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.labelNoFmt(@src(), "Hex id of widget to highlight:", .{}, .{ .gravity_y = 0.5 }); @@ -132,7 +132,7 @@ pub fn show(self: *Debug) void { tl.install(.{}); { - var corner_box = dvui.box(@src(), .vertical, .{ .gravity_x = 1, .margin = .all(8) }); + var corner_box = dvui.box(@src(), .{}, .{ .gravity_x = 1, .margin = .all(8) }); defer corner_box.deinit(); var color: ?Options.ColorOrName = null; @@ -264,7 +264,7 @@ pub fn show(self: *Debug) void { const id = entry.key_ptr.*; const options, const src = entry.value_ptr.*; - const row = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + const row = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer row.deinit(); var reset_wd: dvui.WidgetData = undefined; @@ -300,7 +300,7 @@ pub fn show(self: *Debug) void { if (button.clicked()) self.widget_id = id; - const stack = dvui.box(@src(), .vertical, .{ + const stack = dvui.box(@src(), .{}, .{ .expand = .both, .color_fill = if (button.pressed()) .fill_press else null, }); @@ -328,7 +328,7 @@ pub fn show(self: *Debug) void { defer scroll.deinit(); for (self.under_mouse_stack.items, 0..) |item, i| { - var hbox = dvui.box(@src(), .horizontal, .{ .id_extra = i }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .id_extra = i }); defer hbox.deinit(); if (dvui.buttonIcon(@src(), "find", dvui.entypo.magnifying_glass, .{}, .{}, .{})) { @@ -345,7 +345,7 @@ const OptionsEditorTab = enum { layout, style }; pub fn optionsEditor(self: *Options, wd: *const dvui.WidgetData) bool { var changed = false; - var vbox = dvui.box(@src(), .vertical, .{ .name = "Editor Box", .expand = .both }); + var vbox = dvui.box(@src(), .{}, .{ .name = "Editor Box", .expand = .both }); defer vbox.deinit(); const active_tab = dvui.dataGetPtrDefault(null, vbox.data().id, "Tab", OptionsEditorTab, .layout); @@ -459,7 +459,7 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { const link_radius = dvui.dataGetPtrDefault(null, id, "link_radius", bool, true); { // First bar - var row = dvui.box(@src(), .horizontal, .{}); + var row = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer row.deinit(); { @@ -496,7 +496,7 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { } { // Min size - var row = dvui.box(@src(), .horizontal, .{}); + var row = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer row.deinit(); var has_min_size = self.min_size_content != null; @@ -520,7 +520,7 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { } { // Max size - var row = dvui.box(@src(), .horizontal, .{}); + var row = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer row.deinit(); var has_max_size = self.max_size_content != null; @@ -544,10 +544,10 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { } { // Top Row - var row = dvui.boxEqual(@src(), .horizontal, .{}); + var row = dvui.box(@src(), .{ .dir = .horizontal, .equal_space = true }, .{}); defer row.deinit(); { // Top Left - var col = dvui.box(@src(), .vertical, .{ .border = .all(1), .expand = .vertical }); + var col = dvui.box(@src(), .{}, .{ .border = .all(1), .expand = .vertical }); defer col.deinit(); if (dvui.sliderEntry(@src(), "radius: {d:0}", .{ .value = &corner_radius.x, .min = 0, .max = 200, .interval = 1 }, .{ .gravity_y = 0.5 })) { @@ -558,7 +558,7 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { } } { // Top Center - var col = dvui.box(@src(), .vertical, .{ .border = .all(1) }); + var col = dvui.box(@src(), .{}, .{ .border = .all(1) }); defer col.deinit(); if (dvui.sliderEntry(@src(), "margin: {d:0.0}", .{ .value = &margin.y, .min = 0, .max = 20.0, .interval = 1 }, .{})) { @@ -581,7 +581,7 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { } } { // Top Right - var col = dvui.box(@src(), .vertical, .{ .border = .all(1), .expand = .vertical }); + var col = dvui.box(@src(), .{}, .{ .border = .all(1), .expand = .vertical }); defer col.deinit(); if (dvui.sliderEntry(@src(), "radius: {d:0}", .{ .value = &corner_radius.y, .min = 0, .max = 200, .interval = 1 }, .{ .gravity_y = 0.5 })) { @@ -594,10 +594,10 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { } { // Middle Row - var row = dvui.boxEqual(@src(), .horizontal, .{}); + var row = dvui.box(@src(), .{ .dir = .horizontal, .equal_space = true }, .{}); defer row.deinit(); { // Middle Left - var col = dvui.box(@src(), .vertical, .{ .border = .all(1) }); + var col = dvui.box(@src(), .{}, .{ .border = .all(1) }); defer col.deinit(); if (dvui.sliderEntry(@src(), "margin: {d:0.0}", .{ .value = &margin.x, .min = 0, .max = 20.0, .interval = 1 }, .{})) { @@ -620,14 +620,14 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { } } { // Middle Center - var col = dvui.box(@src(), .horizontal, .{ .border = .all(1), .expand = .both }); + var col = dvui.box(@src(), .{ .dir = .horizontal }, .{ .border = .all(1), .expand = .both }); defer col.deinit(); if (dvui.slider(@src(), .vertical, gravity_y, .{ .expand = .vertical })) { changed = true; } - var side = dvui.box(@src(), .vertical, .{ .expand = .both }); + var side = dvui.box(@src(), .{}, .{ .expand = .both }); defer side.deinit(); dvui.labelNoFmt(@src(), "gravity", .{}, .{ .gravity_y = 0.5 }); @@ -637,7 +637,7 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { } } { // Middle Right - var col = dvui.box(@src(), .vertical, .{ .border = .all(1) }); + var col = dvui.box(@src(), .{}, .{ .border = .all(1) }); defer col.deinit(); if (dvui.sliderEntry(@src(), "margin: {d:0.0}", .{ .value = &margin.w, .min = 0, .max = 20.0, .interval = 1 }, .{})) { @@ -662,10 +662,10 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { } { // Bottom Row - var row = dvui.boxEqual(@src(), .horizontal, .{}); + var row = dvui.box(@src(), .{ .dir = .horizontal, .equal_space = true }, .{}); defer row.deinit(); { // Bottom Left - var col = dvui.box(@src(), .vertical, .{ .border = .all(1), .expand = .vertical }); + var col = dvui.box(@src(), .{}, .{ .border = .all(1), .expand = .vertical }); defer col.deinit(); if (dvui.sliderEntry(@src(), "radius: {d:0}", .{ .value = &corner_radius.h, .min = 0, .max = 200, .interval = 1 }, .{ .gravity_y = 0.5 })) { @@ -676,7 +676,7 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { } } { // Bottom Center - var col = dvui.box(@src(), .vertical, .{ .border = .all(1) }); + var col = dvui.box(@src(), .{}, .{ .border = .all(1) }); defer col.deinit(); if (dvui.sliderEntry(@src(), "margin: {d:0.0}", .{ .value = &margin.h, .min = 0, .max = 20.0, .interval = 1 }, .{})) { @@ -699,7 +699,7 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { } } { // Bottom Right - var col = dvui.box(@src(), .vertical, .{ .border = .all(1), .expand = .vertical }); + var col = dvui.box(@src(), .{}, .{ .border = .all(1), .expand = .vertical }); defer col.deinit(); if (dvui.sliderEntry(@src(), "radius: {d:0}", .{ .value = &corner_radius.w, .min = 0, .max = 200, .interval = 1 }, .{ .gravity_y = 0.5 })) { @@ -712,7 +712,7 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { } { - var row = dvui.box(@src(), .horizontal, .{}); + var row = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer row.deinit(); dvui.labelNoFmt(@src(), "Link: ", .{}, .{}); @@ -741,7 +741,7 @@ fn layoutPage(self: *Options, id: dvui.WidgetId) bool { fn stylePage(self: *Options, id: dvui.WidgetId) bool { var changed = false; - var row = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + var row = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); { dvui.label(@src(), "Font Style", .{}, .{ .gravity_y = 0.5 }); const font_styles = std.meta.tags(Options.FontStyle); @@ -774,7 +774,7 @@ fn stylePage(self: *Options, id: dvui.WidgetId) bool { } row.deinit(); - row = dvui.box(@src(), .horizontal, .{ .expand = .horizontal, .margin = .{ .y = 5 } }); + row = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal, .margin = .{ .y = 5 } }); defer row.deinit(); const active_color = dvui.dataGetPtrDefault(null, id, "Color", Options.ColorAsk, .accent); @@ -829,7 +829,7 @@ fn stylePage(self: *Options, id: dvui.WidgetId) bool { } { - var col = dvui.box(@src(), .vertical, .{ .expand = .both, .margin = .all(5) }); + var col = dvui.box(@src(), .{}, .{ .expand = .both, .margin = .all(5) }); defer col.deinit(); const field: ?*Options.ColorOrName = switch (active_color.*) { diff --git a/src/Examples.zig b/src/Examples.zig index 9d881675..3514d0dc 100644 --- a/src/Examples.zig +++ b/src/Examples.zig @@ -108,7 +108,7 @@ pub fn demo() void { var invalidate: bool = false; { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); if (dvui.button(@src(), "Debug Window", .{}, .{})) { dvui.toggleDebugWindow(); @@ -145,7 +145,7 @@ pub fn demo() void { cache = dvui.cache(@src(), .{ .invalidate = invalidate }, .{ .expand = .both }); } if (!use_cache or cache.uncached()) { - const box = dvui.box(@src(), .vertical, .{ .expand = .both }); + const box = dvui.box(@src(), .{}, .{ .expand = .both }); defer box.deinit(); var options: dvui.Options = .{ .gravity_x = 0.5, .gravity_y = 1.0 }; @@ -160,7 +160,7 @@ pub fn demo() void { const oldclip = dvui.clip(demo_scaler.data().contentRectScale().r); defer dvui.clipSet(oldclip); - const box2 = dvui.box(@src(), .vertical, .{ .rect = dvui.Rect.fromPoint(e.scaleOffset().offset).toSize(.{ .w = 400, .h = 1000 }) }); + const box2 = dvui.box(@src(), .{}, .{ .rect = dvui.Rect.fromPoint(e.scaleOffset().offset).toSize(.{ .w = 400, .h = 1000 }) }); defer box2.deinit(); switch (e) { @@ -201,11 +201,11 @@ pub fn demo() void { } if (paned.showSecond()) { - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both }); defer vbox.deinit(); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); if (paned.collapsed() and dvui.button(@src(), "Back to Demos", .{}, .{ .min_size_content = .{ .h = 30 }, .tag = "dvui_demo_window_back" })) { @@ -283,7 +283,7 @@ pub fn dialogDirect() void { { _ = dvui.spacer(@src(), .{ .expand = .vertical }); - var hbox = dvui.box(@src(), .horizontal, .{ .gravity_x = 1.0 }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .gravity_x = 1.0 }); defer hbox.deinit(); if (dvui.button(@src(), "Yes", .{}, .{})) { @@ -304,7 +304,7 @@ pub fn show_stroke_test_window() void { dvui.label(@src(), "Stroke Test", .{}, .{}); _ = dvui.checkbox(@src(), &StrokeTest.stroke_test_closed, "Closed", .{}); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Endcap Style", .{}, .{}); @@ -353,7 +353,7 @@ pub fn grids() void { } }; - var tbox = dvui.box(@src(), .vertical, .{ .border = Rect.all(1), .expand = .both }); + var tbox = dvui.box(@src(), .{}, .{ .border = Rect.all(1), .expand = .both }); defer tbox.deinit(); { var tabs = dvui.TabsWidget.init(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); diff --git a/src/Examples/animations.zig b/src/Examples/animations.zig index d1a34ec5..53f9e777 100644 --- a/src/Examples/animations.zig +++ b/src/Examples/animations.zig @@ -35,11 +35,11 @@ pub fn animations() void { }; { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); { - var hbox2 = dvui.box(@src(), .vertical, .{ .min_size_content = .{ .w = 200 } }); + var hbox2 = dvui.box(@src(), .{}, .{ .min_size_content = .{ .w = 200 } }); defer hbox2.deinit(); var button_wiggle = ButtonWidget.init(@src(), .{}, .{ .gravity_x = 0.5 }); @@ -90,7 +90,7 @@ pub fn animations() void { if (dvui.expander(@src(), "Easings", .{}, .{ .expand = .horizontal })) { { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.labelNoFmt(@src(), "Animate", .{}, .{ .gravity_y = 0.5 }); @@ -131,7 +131,7 @@ pub fn animations() void { var start = false; var end = false; { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); if (dvui.button(@src(), "start", .{}, .{})) { @@ -205,7 +205,7 @@ pub fn animations() void { } if (dvui.expander(@src(), "Texture Frames", .{}, .{ .expand = .horizontal })) { - var box = dvui.box(@src(), .vertical, .{ .margin = .{ .x = 10 } }); + var box = dvui.box(@src(), .{}, .{ .margin = .{ .x = 10 } }); defer box.deinit(); const pixels = dvui.dataGetPtrDefault(null, box.data().id, "pixels", [4]dvui.Color.PMA, .{ .yellow, .cyan, .red, .magenta }); @@ -231,14 +231,14 @@ pub fn animations() void { }; { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "frame: {d}", .{frame}, .{}); _ = dvui.checkbox(@src(), &global.round_corners, "Round Corners", .{}); //dvui.label(@src(), "num textures: {d}", .{dvui.backend.num_textures}, .{}); } - var frame_box = dvui.box(@src(), .horizontal, .{ .min_size_content = .{ .w = 50, .h = 50 } }); + var frame_box = dvui.box(@src(), .{ .dir = .horizontal }, .{ .min_size_content = .{ .w = 50, .h = 50 } }); defer frame_box.deinit(); _ = dvui.image(@src(), .{ .source = image_source }, .{ .expand = .both, .corner_radius = if (global.round_corners) dvui.Rect.all(10) else .{} }); @@ -380,7 +380,7 @@ test "DOCIMG animations" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); animations(); return .ok; diff --git a/src/Examples/basic_widgets.zig b/src/Examples/basic_widgets.zig index e6e70699..802620d8 100644 --- a/src/Examples/basic_widgets.zig +++ b/src/Examples/basic_widgets.zig @@ -23,7 +23,7 @@ var dropdown_val: usize = 1; /// ![image](Examples-basic_widgets.png) pub fn basicWidgets() void { { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Label", .{}, .{ .gravity_y = 0.5 }); @@ -38,7 +38,7 @@ pub fn basicWidgets() void { dvui.tooltip(@src(), .{ .active_rect = ttout.borderRectScale().r }, "Here's a tooltip", .{}, .{}); { - var vbox = dvui.box(@src(), .vertical, .{}); + var vbox = dvui.box(@src(), .{}, .{}); defer vbox.deinit(); { @@ -61,7 +61,7 @@ pub fn basicWidgets() void { const opts = bw.data().options.strip().override(.{ .gravity_y = 0.5 }); - var bbox = dvui.box(@src(), .horizontal, opts); + var bbox = dvui.box(@src(), .{ .dir = .horizontal }, opts); defer bbox.deinit(); dvui.icon( @@ -79,7 +79,7 @@ pub fn basicWidgets() void { } } { - var hbox_inner = dvui.box(@src(), .horizontal, .{}); + var hbox_inner = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox_inner.deinit(); _ = dvui.checkbox(@src(), &checkbox_gray, "Gray", .{}); _ = dvui.checkbox(@src(), &checkbox_enabled, "Enabled", .{}); @@ -88,7 +88,7 @@ pub fn basicWidgets() void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Link:", .{}, .{ .gravity_y = 0.5 }); @@ -105,7 +105,7 @@ pub fn basicWidgets() void { _ = dvui.checkbox(@src(), &checkbox_bool, "Checkbox", .{}); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Text Entry", .{}, .{ .gravity_y = 0.5 }); @@ -120,7 +120,7 @@ pub fn basicWidgets() void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); const entries = [_][]const u8{ "First", "Second", "Third is a really long one that doesn't fit" }; @@ -131,7 +131,7 @@ pub fn basicWidgets() void { } { - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal, .min_size_content = .{ .h = 40 } }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal, .min_size_content = .{ .h = 40 } }); defer hbox.deinit(); dvui.label(@src(), "Sliders", .{}, .{ .gravity_y = 0.5 }); @@ -141,7 +141,7 @@ pub fn basicWidgets() void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Slider Entry", .{}, .{ .gravity_y = 0.5 }); @@ -161,7 +161,7 @@ pub fn basicWidgets() void { } { - var hbox = dvui.box(@src(), .horizontal, .{ .padding = .{ .x = 10 } }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .padding = .{ .x = 10 } }); defer hbox.deinit(); _ = dvui.checkbox(@src(), &slider_entry_min, "Min", .{}); @@ -174,7 +174,7 @@ pub fn basicWidgets() void { _ = dvui.spacer(@src(), .{ .min_size_content = .height(4) }); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Raster Images", .{}, .{ .gravity_y = 0.5 }); @@ -189,7 +189,7 @@ pub fn basicWidgets() void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Svg Images", .{}, .{ .gravity_y = 0.5 }); @@ -207,7 +207,7 @@ pub fn basicWidgets() void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Icons", .{}, .{ .gravity_y = 0.5 }); @@ -223,7 +223,7 @@ pub fn basicWidgets() void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Resize Rotate Icons/Images", .{}, .{ .gravity_y = 0.5 }); @@ -285,7 +285,7 @@ pub fn dropdownAdvanced() void { // Here's what is shown when the dropdown is not dropped { - var hbox2 = dvui.box(@src(), .horizontal, .{ .expand = .both }); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both }); dvui.icon( @src(), "air", @@ -317,7 +317,7 @@ pub fn dropdownAdvanced() void { var mi = dd.addChoice(); defer mi.deinit(); - var hbox2 = dvui.box(@src(), .horizontal, .{ .expand = .both }); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both }); defer hbox2.deinit(); var opts: Options = if (mi.show_active) dvui.themeGet().accent() else .{}; @@ -344,7 +344,7 @@ pub fn dropdownAdvanced() void { var mi = dd.addChoice(); defer mi.deinit(); - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both }); defer vbox.deinit(); var opts: Options = if (mi.show_active) dvui.themeGet().accent() else .{}; @@ -370,7 +370,7 @@ test "DOCIMG basic_widgets" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); basicWidgets(); return .ok; diff --git a/src/Examples/calculator.zig b/src/Examples/calculator.zig index 6b1b04d9..12fd8dae 100644 --- a/src/Examples/calculator.zig +++ b/src/Examples/calculator.zig @@ -7,14 +7,14 @@ var reset_on_digit: bool = false; /// ![image](Examples-calculator.png) pub fn calculator() void { - var vbox = dvui.box(@src(), .vertical, .{}); + var vbox = dvui.box(@src(), .{}, .{}); defer vbox.deinit(); const loop_labels = [_]u8{ 'C', 'N', '%', '/', '7', '8', '9', 'x', '4', '5', '6', '-', '1', '2', '3', '+', '0', '.', '=' }; dvui.label(@src(), "{d}", .{if (calculand) |val| round(val) else round(calculation)}, .{ .gravity_x = 1.0 }); for (0..5) |row_i| { - var b = dvui.box(@src(), .horizontal, .{ .min_size_content = .{ .w = 110 }, .id_extra = row_i }); + var b = dvui.box(@src(), .{ .dir = .horizontal }, .{ .min_size_content = .{ .w = 110 }, .id_extra = row_i }); defer b.deinit(); for (row_i * 4..(row_i + 1) * 4) |i| { @@ -132,7 +132,7 @@ test "DOCIMG calculator" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); calculator(); return .ok; diff --git a/src/Examples/debugging.zig b/src/Examples/debugging.zig index 283504f3..8a0db663 100644 --- a/src/Examples/debugging.zig +++ b/src/Examples/debugging.zig @@ -1,7 +1,7 @@ /// ![image](Examples-debugging.png) pub fn debuggingErrors() void { { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Scroll Speed", .{}, .{}); _ = dvui.sliderEntry(@src(), "{d:0.1}", .{ .value = &dvui.scroll_speed, .min = 0.1, .max = 50, .interval = 0.1 }, .{}); @@ -17,7 +17,7 @@ pub fn debuggingErrors() void { dvui.label(@src(), "- mouse click in text layout/entry shows touch draggables and menu", .{}, .{ .margin = .{ .x = 10 } }); if (dvui.expander(@src(), "Virtual Parent (affects IDs but not layout)", .{}, .{ .expand = .horizontal })) { - var hbox = dvui.box(@src(), .horizontal, .{ .margin = .{ .x = 10 } }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .margin = .{ .x = 10 } }); defer hbox.deinit(); dvui.label(@src(), "makeLabels twice:", .{}, .{}); @@ -26,7 +26,7 @@ pub fn debuggingErrors() void { } if (dvui.expander(@src(), "Duplicate id (will log error)", .{}, .{ .expand = .horizontal })) { - var b = dvui.box(@src(), .vertical, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); + var b = dvui.box(@src(), .{}, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); defer b.deinit(); for (0..2) |i| { dvui.label(@src(), "this should be highlighted (and error logged)", .{}, .{}); @@ -39,7 +39,7 @@ pub fn debuggingErrors() void { } if (dvui.expander(@src(), "Invalid utf-8 text", .{}, .{ .expand = .horizontal })) { - var b = dvui.box(@src(), .vertical, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); + var b = dvui.box(@src(), .{}, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); defer b.deinit(); dvui.labelNoFmt(@src(), "this \xFFtext\xFF includes some \xFF invalid utf-8\xFF\xFF\xFF which is replaced with \xFF", .{}, .{}); } @@ -53,7 +53,7 @@ pub fn debuggingErrors() void { } if (dvui.expander(@src(), "Key bindings", .{}, .{ .expand = .horizontal })) { - var b = dvui.box(@src(), .vertical, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); + var b = dvui.box(@src(), .{}, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); defer b.deinit(); const g = struct { @@ -159,7 +159,7 @@ test "DOCIMG debugging" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); debuggingErrors(); return .ok; diff --git a/src/Examples/dialogs.zig b/src/Examples/dialogs.zig index e065f50a..d4679384 100644 --- a/src/Examples/dialogs.zig +++ b/src/Examples/dialogs.zig @@ -4,7 +4,7 @@ var progress_val: f32 = 0.0; /// ![image](Examples-dialogs.png) pub fn dialogs(demo_win_id: dvui.WidgetId) void { { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); if (dvui.button(@src(), "Direct Dialog", .{}, .{})) { Examples.show_dialog = true; @@ -16,7 +16,7 @@ pub fn dialogs(demo_win_id: dvui.WidgetId) void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); if (dvui.button(@src(), "Non modal", .{}, .{})) { @@ -38,7 +38,7 @@ pub fn dialogs(demo_win_id: dvui.WidgetId) void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); if (dvui.button(@src(), "Toast 1", .{}, .{})) { @@ -59,7 +59,7 @@ pub fn dialogs(demo_win_id: dvui.WidgetId) void { } { - var vbox = dvui.box(@src(), .vertical, .{.min_size_content = .{.w = 250, .h = 80}, .border = .all(1)}); + var vbox = dvui.box(@src(), .{}, .{ .min_size_content = .{ .w = 250, .h = 80 }, .border = .all(1) }); defer vbox.deinit(); if (dvui.button(@src(), "Toast In Box", .{}, .{})) { @@ -71,7 +71,7 @@ pub fn dialogs(demo_win_id: dvui.WidgetId) void { dvui.label(@src(), "\nDialogs and toasts from other threads", .{}, .{}); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); if (dvui.button(@src(), "Dialog after 1 second", .{}, .{})) { @@ -100,7 +100,7 @@ pub fn dialogs(demo_win_id: dvui.WidgetId) void { } { - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer hbox.deinit(); if (dvui.button(@src(), "Show Progress from another Thread", .{}, .{})) { @@ -123,7 +123,7 @@ pub fn dialogs(demo_win_id: dvui.WidgetId) void { dvui.label(@src(), "\nNative Dialogs", .{}, .{}); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); const single_file_id = hbox.widget().extendId(@src(), 0); @@ -183,7 +183,7 @@ pub fn dialogs(demo_win_id: dvui.WidgetId) void { } } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); if (dvui.button(@src(), "Open Folder", .{}, .{})) { @@ -249,7 +249,7 @@ test "DOCIMG dialogs" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); dialogs(box.data().id); return .ok; diff --git a/src/Examples/grid.zig b/src/Examples/grid.zig index 0528d488..55a4282d 100644 --- a/src/Examples/grid.zig +++ b/src/Examples/grid.zig @@ -12,11 +12,11 @@ pub fn gridStyling() void { const Banding = enum { none, rows, cols }; }; - var outer_hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + var outer_hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer outer_hbox.deinit(); { - var outer_vbox = dvui.box(@src(), .vertical, .{ + var outer_vbox = dvui.box(@src(), .{}, .{ .min_size_content = grid_panel_size, .max_size_content = .size(grid_panel_size), .expand = .vertical, @@ -33,13 +33,13 @@ pub fn gridStyling() void { var fbox = dvui.flexbox(@src(), .{ .justify_content = .start }, .{}); defer fbox.deinit(); { - var vbox = dvui.box(@src(), .vertical, .{ .expand = .horizontal }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .horizontal }); defer vbox.deinit(); _ = dvui.checkbox(@src(), &top, "Top", .{}); _ = dvui.checkbox(@src(), &left, "Left", .{}); } { - var vbox = dvui.box(@src(), .vertical, .{ .expand = .horizontal }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .horizontal }); defer vbox.deinit(); _ = dvui.checkbox(@src(), &right, "Right", .{}); _ = dvui.checkbox(@src(), &bottom, "Bottom", .{}); @@ -68,7 +68,7 @@ pub fn gridStyling() void { } if (dvui.expander(@src(), "Other", .{ .default_expanded = true }, .{ .expand = .horizontal })) { { - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer hbox.deinit(); dvui.labelNoFmt(@src(), "Margin:", .{}, .{ .min_size_content = .{ .w = 60 }, .gravity_y = 0.5 }); const result = dvui.textEntryNumber(@src(), f32, .{ .min = 0, .max = 10, .value = &local.margin, .show_min_max = true }, .{}); @@ -78,7 +78,7 @@ pub fn gridStyling() void { } } { - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer hbox.deinit(); dvui.labelNoFmt(@src(), "Padding:", .{}, .{ .min_size_content = .{ .w = 60 }, .gravity_y = 0.5 }); const result = dvui.textEntryNumber(@src(), f32, .{ .min = 0, .max = 10, .value = &local.padding, .show_min_max = true }, .{}); @@ -452,7 +452,7 @@ pub fn gridLayouts() void { } } { - var outer_vbox = dvui.box(@src(), .vertical, .{ + var outer_vbox = dvui.box(@src(), .{}, .{ .expand = .horizontal, .border = Rect.all(1), }); @@ -538,7 +538,7 @@ pub fn gridVirtualScrolling() void { local.generated_primes = true; } - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both }); defer vbox.deinit(); var grid = dvui.grid(@src(), .numCols(2), .{ .scroll_opts = .{ .scroll_info = &local.scroll_info }, @@ -743,10 +743,10 @@ pub fn gridSelection() void { }; } }; - var outer_vbox = dvui.box(@src(), .vertical, .{ .expand = .both }); + var outer_vbox = dvui.box(@src(), .{}, .{ .expand = .both }); defer outer_vbox.deinit(); { - var top_controls = dvui.box(@src(), .horizontal, .{ .gravity_y = 0 }); + var top_controls = dvui.box(@src(), .{ .dir = .horizontal }, .{ .gravity_y = 0 }); defer top_controls.deinit(); dvui.labelNoFmt(@src(), "Filter (contains): ", .{}, .{ .margin = dvui.TextEntryWidget.defaults.margin }); var text = dvui.textEntry(@src(), .{}, .{ .expand = .horizontal }); @@ -759,10 +759,10 @@ pub fn gridSelection() void { defer text.deinit(); } { - var vbox = dvui.box(@src(), .vertical, .{ .gravity_y = 1.0 }); + var vbox = dvui.box(@src(), .{}, .{ .gravity_y = 1.0 }); defer vbox.deinit(); if (dvui.expander(@src(), "Options", .{ .default_expanded = true }, .{ .expand = .horizontal })) { - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer hbox.deinit(); var selected = local.selection_mode == .multi_select; if (dvui.checkbox(@src(), &selected, "Multi-Select", .{ .margin = dvui.Rect.all(6) })) { @@ -1025,7 +1025,7 @@ pub fn gridNavigation() void { } }; - var main_box = dvui.box(@src(), .horizontal, .{ .expand = .both, .color_fill = .fill_window, .background = true, .border = dvui.Rect.all(1) }); + var main_box = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both, .color_fill = .fill_window, .background = true, .border = dvui.Rect.all(1) }); defer main_box.deinit(); if (dvui.firstFrame(main_box.data().id)) { local.initialized = false; @@ -1035,13 +1035,13 @@ pub fn gridNavigation() void { }; } { - var vbox = dvui.box(@src(), .vertical, .{ .expand = .vertical, .border = dvui.Rect.all(1) }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .vertical, .border = dvui.Rect.all(1) }); defer vbox.deinit(); { - var bottom_panel = dvui.box(@src(), .vertical, .{ .gravity_y = 1.0 }); + var bottom_panel = dvui.box(@src(), .{}, .{ .gravity_y = 1.0 }); defer bottom_panel.deinit(); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); { dvui.labelNoFmt(@src(), "X Axis:", .{}, .{ .margin = dvui.TextEntryWidget.defaults.margin }); @@ -1079,7 +1079,7 @@ pub fn gridNavigation() void { } } { - var top_panel = dvui.box(@src(), .horizontal, .{ .gravity_y = 0 }); + var top_panel = dvui.box(@src(), .{ .dir = .horizontal }, .{ .gravity_y = 0 }); defer top_panel.deinit(); dvui.labelNoFmt(@src(), "Plot Title:", .{}, .{ .margin = dvui.TextEntryWidget.defaults.margin }); var text = dvui.textEntry(@src(), .{}, .{ .tab_index = 1, .expand = .horizontal }); @@ -1120,7 +1120,7 @@ pub fn gridNavigation() void { defer cell_num.col_num += 1; var cell = grid.bodyCell(@src(), cell_num, style.cellOptions(cell_num)); defer cell.deinit(); - var cell_vbox = dvui.box(@src(), .vertical, .{ .expand = .both }); + var cell_vbox = dvui.box(@src(), .{}, .{ .expand = .both }); defer cell_vbox.deinit(); _ = dvui.textEntryNumber(@src(), f64, .{ .value = x, .min = 0, .max = 100, .show_min_max = true }, style.options(focus_cell).override(.{ .gravity_y = 0 })); @@ -1139,7 +1139,7 @@ pub fn gridNavigation() void { defer cell_num.col_num += 1; var cell = grid.bodyCell(@src(), cell_num, style.cellOptions(cell_num)); defer cell.deinit(); - var cell_vbox = dvui.box(@src(), .vertical, .{ .expand = .both }); + var cell_vbox = dvui.box(@src(), .{}, .{ .expand = .both }); defer cell_vbox.deinit(); _ = dvui.textEntryNumber(@src(), f64, .{ .value = y1, .min = -100, .max = 100, .show_min_max = true }, style.options(focus_cell).override(.{ .color_text = .red })); @@ -1159,7 +1159,7 @@ pub fn gridNavigation() void { defer cell_num.col_num += 1; var cell = grid.bodyCell(@src(), cell_num, style.cellOptions(cell_num)); defer cell.deinit(); - var cell_vbox = dvui.box(@src(), .vertical, .{ .expand = .both }); + var cell_vbox = dvui.box(@src(), .{}, .{ .expand = .both }); defer cell_vbox.deinit(); _ = dvui.textEntryNumber(@src(), f64, .{ .value = y2, .min = -100, .max = 100, .show_min_max = true }, style.options(focus_cell).override(.{ .color_text = .blue })); @@ -1216,7 +1216,7 @@ pub fn gridNavigation() void { } } { - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both, .border = dvui.Rect.all(1) }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both, .border = dvui.Rect.all(1) }); defer vbox.deinit(); var x_axis: dvui.PlotWidget.Axis = .{ .name = local.x_axis_title, .min = 0, .max = 100 }; var y_axis: dvui.PlotWidget.Axis = .{ diff --git a/src/Examples/icon_browser.zig b/src/Examples/icon_browser.zig index 97ac122e..fb86e258 100644 --- a/src/Examples/icon_browser.zig +++ b/src/Examples/icon_browser.zig @@ -66,7 +66,7 @@ pub fn iconBrowser(src: std.builtin.SourceLocation, show_flag: *bool, comptime i if (cursor <= (visibleRect.y + visibleRect.h) and (cursor + settings.row_height) >= visibleRect.y) { const r = Rect{ .x = 0, .y = cursor, .w = 0, .h = settings.row_height }; - var iconbox = dvui.box(@src(), .horizontal, .{ .id_extra = i, .expand = .horizontal, .rect = r }); + var iconbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .id_extra = i, .expand = .horizontal, .rect = r }); var buf: [100]u8 = undefined; const text = std.fmt.bufPrint(&buf, icon_decl_name ++ ".{s}", .{name}) catch ""; @@ -109,7 +109,7 @@ test "DOCIMG iconBrowser" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); var show_flag: bool = true; iconBrowser(@src(), &show_flag, "entypo", dvui.entypo); diff --git a/src/Examples/layout.zig b/src/Examples/layout.zig index cb1cb7e8..93cc3af3 100644 --- a/src/Examples/layout.zig +++ b/src/Examples/layout.zig @@ -12,7 +12,7 @@ var paned_collapsed_width: f32 = 400; /// ![image](Examples-layout.png) pub fn layout() void { { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); const Static = struct { @@ -26,11 +26,11 @@ pub fn layout() void { }; { - var vbox = dvui.box(@src(), .vertical, .{}); + var vbox = dvui.box(@src(), .{}, .{}); defer vbox.deinit(); { - var hbox2 = dvui.box(@src(), .horizontal, .{}); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox2.deinit(); dvui.label(@src(), "Layout", .{}, .{}); @@ -52,7 +52,7 @@ pub fn layout() void { opts.max_size_content = .size(opts.min_size_contentGet()); } - var o = dvui.box(@src(), .vertical, opts); + var o = dvui.box(@src(), .{}, opts); defer o.deinit(); const old_clip = dvui.clip(o.data().backgroundRectScale().r); defer dvui.clipSet(old_clip); @@ -79,7 +79,7 @@ pub fn layout() void { } { - var vbox = dvui.box(@src(), .vertical, .{}); + var vbox = dvui.box(@src(), .{}, .{}); defer vbox.deinit(); dvui.label(@src(), "Gravity", .{}, .{}); _ = dvui.sliderEntry(@src(), "X: {d:0.2}", .{ .value = &layout_gravity_x, .min = 0, .max = 1.0, .interval = 0.01 }, .{}); @@ -95,7 +95,7 @@ pub fn layout() void { } { - var vbox = dvui.box(@src(), .vertical, .{}); + var vbox = dvui.box(@src(), .{}, .{}); defer vbox.deinit(); dvui.label(@src(), "Expand", .{}, .{}); inline for (std.meta.tags(dvui.Options.Expand)) |opt| { @@ -118,7 +118,7 @@ pub fn layout() void { } if (Static.shrink) { - var vbox = dvui.box(@src(), .vertical, .{}); + var vbox = dvui.box(@src(), .{}, .{}); defer vbox.deinit(); dvui.label(@src(), "Shrink", .{}, .{}); inline for (std.meta.tags(dvui.Options.Expand)) |opt| { @@ -131,19 +131,19 @@ pub fn layout() void { dvui.label(@src(), "margin/border/padding", .{}, .{}); { - var vbox = dvui.box(@src(), .vertical, .{}); + var vbox = dvui.box(@src(), .{}, .{}); defer vbox.deinit(); - var vbox2 = dvui.box(@src(), .vertical, .{ .gravity_x = 0.5 }); + var vbox2 = dvui.box(@src(), .{}, .{ .gravity_x = 0.5 }); _ = dvui.sliderEntry(@src(), "margin {d:0.0}", .{ .value = &layout_margin.y, .min = 0, .max = 20.0, .interval = 1 }, .{}); _ = dvui.sliderEntry(@src(), "border {d:0.0}", .{ .value = &layout_border.y, .min = 0, .max = 20.0, .interval = 1 }, .{}); _ = dvui.sliderEntry(@src(), "padding {d:0.0}", .{ .value = &layout_padding.y, .min = 0, .max = 20.0, .interval = 1 }, .{}); vbox2.deinit(); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); { - vbox2 = dvui.box(@src(), .vertical, .{ .gravity_y = 0.5 }); + vbox2 = dvui.box(@src(), .{}, .{ .gravity_y = 0.5 }); defer vbox2.deinit(); _ = dvui.sliderEntry(@src(), "margin {d:0.0}", .{ .value = &layout_margin.x, .min = 0, .max = 20.0, .interval = 1 }, .{}); _ = dvui.sliderEntry(@src(), "border {d:0.0}", .{ .value = &layout_border.x, .min = 0, .max = 20.0, .interval = 1 }, .{}); @@ -161,7 +161,7 @@ pub fn layout() void { } } { - vbox2 = dvui.box(@src(), .vertical, .{ .gravity_y = 0.5 }); + vbox2 = dvui.box(@src(), .{}, .{ .gravity_y = 0.5 }); defer vbox2.deinit(); _ = dvui.sliderEntry(@src(), "margin {d:0.0}", .{ .value = &layout_margin.w, .min = 0, .max = 20.0, .interval = 1 }, .{}); _ = dvui.sliderEntry(@src(), "border {d:0.0}", .{ .value = &layout_border.w, .min = 0, .max = 20.0, .interval = 1 }, .{}); @@ -169,7 +169,7 @@ pub fn layout() void { } } { - vbox2 = dvui.box(@src(), .vertical, .{ .gravity_x = 0.5 }); + vbox2 = dvui.box(@src(), .{}, .{ .gravity_x = 0.5 }); defer vbox2.deinit(); _ = dvui.sliderEntry(@src(), "margin {d:0.0}", .{ .value = &layout_margin.h, .min = 0, .max = 20.0, .interval = 1 }, .{}); _ = dvui.sliderEntry(@src(), "border {d:0.0}", .{ .value = &layout_border.h, .min = 0, .max = 20.0, .interval = 1 }, .{}); @@ -189,10 +189,10 @@ pub fn layout() void { hbox.drawBackground(); defer hbox.deinit(); { - var hbox2 = dvui.box(@src(), .horizontal, .{ .min_size_content = .{ .w = breakpoint / 2, .h = 140 }, .max_size_content = .width(breakpoint / 2), .expand = if (equal) .horizontal else .none }); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal }, .{ .min_size_content = .{ .w = breakpoint / 2, .h = 140 }, .max_size_content = .width(breakpoint / 2), .expand = if (equal) .horizontal else .none }); defer hbox2.deinit(); { - var vbox = dvui.box(@src(), .vertical, opts); + var vbox = dvui.box(@src(), .{}, opts); defer vbox.deinit(); _ = dvui.button(@src(), "vertical", .{}, .{ .gravity_x = 0.5 }); @@ -200,7 +200,7 @@ pub fn layout() void { _ = dvui.button(@src(), "a", .{}, .{ .gravity_x = 0.5 }); } { - var vbox = dvui.boxEqual(@src(), .vertical, opts); + var vbox = dvui.box(@src(), .{ .equal_space = true }, opts); defer vbox.deinit(); _ = dvui.button(@src(), "vert equal", .{}, .{ .gravity_x = 0.5 }); @@ -209,10 +209,10 @@ pub fn layout() void { } } { - var vbox2 = dvui.box(@src(), .vertical, .{ .max_size_content = .zero, .expand = .both }); + var vbox2 = dvui.box(@src(), .{}, .{ .max_size_content = .zero, .expand = .both }); defer vbox2.deinit(); { - var hbox2 = dvui.box(@src(), .horizontal, opts); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal }, opts); defer hbox2.deinit(); _ = dvui.button(@src(), "horizontal", .{}, .{ .gravity_y = 0.5 }); @@ -220,7 +220,7 @@ pub fn layout() void { _ = dvui.button(@src(), "a", .{}, .{ .gravity_y = 0.5 }); } { - var hbox2 = dvui.boxEqual(@src(), .horizontal, opts); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal, .equal_space = true }, opts); defer hbox2.deinit(); _ = dvui.button(@src(), "horiz\nequal", .{}, .{ .gravity_y = 0.5 }); @@ -231,7 +231,7 @@ pub fn layout() void { } { { - var hbox2 = dvui.box(@src(), .horizontal, .{}); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox2.deinit(); dvui.label(@src(), "FlexBox", .{}, .{}); inline for (std.meta.tags(dvui.FlexBoxWidget.ContentPosition)) |opt| { @@ -250,7 +250,7 @@ pub fn layout() void { defer fbox.deinit(); for (0..11) |i| { - var labelbox = dvui.box(@src(), .vertical, .{ .id_extra = i, .margin = .{ .x = 4, .y = 4 }, .border = dvui.Rect.all(1), .background = true }); + var labelbox = dvui.box(@src(), .{}, .{ .id_extra = i, .margin = .{ .x = 4, .y = 4 }, .border = dvui.Rect.all(1), .background = true }); defer labelbox.deinit(); if (i % 2 == 0) { @@ -267,7 +267,7 @@ pub fn layout() void { defer paned.deinit(); if (paned.showFirst()) { - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both, .background = true }); defer vbox.deinit(); dvui.label(@src(), "Left Side", .{}, .{}); @@ -279,7 +279,7 @@ pub fn layout() void { } if (paned.showSecond()) { - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both, .background = true }); defer vbox.deinit(); dvui.label(@src(), "Right Side", .{}, .{}); @@ -302,7 +302,7 @@ test "DOCIMG layout" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); layout(); return .ok; diff --git a/src/Examples/menus.zig b/src/Examples/menus.zig index d345e0c5..1bba044a 100644 --- a/src/Examples/menus.zig +++ b/src/Examples/menus.zig @@ -9,7 +9,7 @@ var radio_choice: RadioChoice = @enumFromInt(0); /// ![image](Examples-menus.png) pub fn menus() void { - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both, .margin = .{ .x = 4 } }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both, .margin = .{ .x = 4 } }); defer vbox.deinit(); { @@ -30,7 +30,7 @@ pub fn menus() void { } { - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer hbox.deinit(); { var m = dvui.menu(@src(), .horizontal, .{}); @@ -69,7 +69,7 @@ pub fn menus() void { _ = dvui.spacer(@src(), .{ .min_size_content = .height(12) }); { - var hbox = dvui.box(@src(), .horizontal, .{ .border = dvui.Rect.all(1), .min_size_content = .{ .h = 50 }, .max_size_content = .width(300) }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .border = dvui.Rect.all(1), .min_size_content = .{ .h = 50 }, .max_size_content = .width(300) }); defer hbox.deinit(); var tl = dvui.textLayout(@src(), .{}, .{ .background = false }); @@ -82,7 +82,7 @@ pub fn menus() void { _ = dvui.spacer(@src(), .{ .min_size_content = .height(4) }); { - var hbox = dvui.box(@src(), .horizontal, .{ .border = dvui.Rect.all(1), .min_size_content = .{ .h = 50 }, .max_size_content = .width(300) }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .border = dvui.Rect.all(1), .min_size_content = .{ .h = 50 }, .max_size_content = .width(300) }); defer hbox.deinit(); var tl = dvui.textLayout(@src(), .{}, .{ .background = false }); @@ -99,7 +99,7 @@ pub fn menus() void { var animator = dvui.animate(@src(), .{ .kind = .alpha, .duration = 250_000 }, .{ .expand = .both }); defer animator.deinit(); - var vbox2 = dvui.box(@src(), .vertical, dvui.FloatingTooltipWidget.defaults.override(.{ .expand = .both })); + var vbox2 = dvui.box(@src(), .{}, dvui.FloatingTooltipWidget.defaults.override(.{ .expand = .both })); defer vbox2.deinit(); var tl2 = dvui.textLayout(@src(), .{}, .{ .background = false }); @@ -125,7 +125,7 @@ pub fn menus() void { _ = dvui.spacer(@src(), .{ .min_size_content = .height(12) }); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); const layout_dir = dvui.dataGetPtrDefault(null, hbox.data().id, "layout_dir", dvui.enums.Direction, .horizontal); const active_tab = dvui.dataGetPtrDefault(null, hbox.data().id, "active_tab", usize, 0); { @@ -138,7 +138,7 @@ pub fn menus() void { } } // reverse orientation because horizontal tabs go above content - var tbox = dvui.box(@src(), if (layout_dir.* == .vertical) .horizontal else .vertical, .{ .max_size_content = .{ .w = 400, .h = 200 } }); + var tbox = dvui.box(@src(), .{ .dir = if (layout_dir.* == .vertical) .horizontal else .vertical }, .{ .max_size_content = .{ .w = 400, .h = 200 } }); defer tbox.deinit(); { @@ -158,7 +158,7 @@ pub fn menus() void { var tab = tabs.addTab(active_tab.* == i, .{}); defer tab.deinit(); - var tab_box = dvui.box(@src(), .horizontal, .{}); + var tab_box = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer tab_box.deinit(); dvui.icon(@src(), "cycle", entypo.cycle, .{}, .{}); @@ -185,7 +185,7 @@ pub fn menus() void { .horizontal => border.y = 0, .vertical => border.x = 0, } - var vbox3 = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window, .border = border }); + var vbox3 = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window, .border = border }); defer vbox3.deinit(); dvui.label(@src(), "This is tab {d}", .{active_tab.*}, .{ .expand = .both, .gravity_x = 0.5, .gravity_y = 0.5 }); @@ -217,7 +217,7 @@ pub fn submenus() void { pub fn focus() void { if (dvui.expander(@src(), "Changing Focus", .{}, .{ .expand = .horizontal })) { - var b = dvui.box(@src(), .vertical, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); + var b = dvui.box(@src(), .{}, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); defer b.deinit(); var tl = dvui.textLayout(@src(), .{}, .{ .background = false }); @@ -238,7 +238,7 @@ pub fn focus() void { const uniqueId = dvui.parentGet().extendId(@src(), 0); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); if (dvui.button(@src(), "Focus Next textEntry", .{}, .{})) { @@ -264,7 +264,7 @@ pub fn focus() void { _ = dvui.spacer(@src(), .{ .min_size_content = .height(10) }); { - var b = dvui.box(@src(), .vertical, .{ .margin = .{ .x = 10, .y = 2 }, .border = dvui.Rect.all(1) }); + var b = dvui.box(@src(), .{}, .{ .margin = .{ .x = 10, .y = 2 }, .border = dvui.Rect.all(1) }); defer b.deinit(); const last_focus_id = dvui.lastFocusedIdInFrame(); @@ -274,7 +274,7 @@ pub fn focus() void { tl.deinit(); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); for (0..6) |i| { @@ -298,7 +298,7 @@ pub fn focus() void { _ = dvui.spacer(@src(), .{ .min_size_content = .height(10) }); { - var b = dvui.box(@src(), .vertical, .{ .expand = .horizontal }); + var b = dvui.box(@src(), .{}, .{ .expand = .horizontal }); defer b.deinit(); var tl = dvui.textLayout(@src(), .{}, .{ .background = false }); @@ -339,7 +339,7 @@ test "DOCIMG menus" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); menus(); return .ok; diff --git a/src/Examples/plots.zig b/src/Examples/plots.zig index 89c63094..f01e1f3d 100644 --- a/src/Examples/plots.zig +++ b/src/Examples/plots.zig @@ -1,7 +1,7 @@ /// ![image](Examples-plots.png) pub fn plots() void { { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Simple", .{}, .{}); @@ -12,7 +12,7 @@ pub fn plots() void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Color and Thick", .{}, .{}); @@ -27,7 +27,7 @@ pub fn plots() void { save = true; } - var vbox = dvui.box(@src(), .vertical, .{ .min_size_content = .{ .w = 300, .h = 100 }, .expand = .ratio }); + var vbox = dvui.box(@src(), .{}, .{ .min_size_content = .{ .w = 300, .h = 100 }, .expand = .ratio }); defer vbox.deinit(); var pic: ?dvui.Picture = null; @@ -115,7 +115,7 @@ test "DOCIMG plots" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); plots(); return .ok; diff --git a/src/Examples/reorder_tree.zig b/src/Examples/reorder_tree.zig index 125d54ba..15d000f3 100644 --- a/src/Examples/reorder_tree.zig +++ b/src/Examples/reorder_tree.zig @@ -9,11 +9,11 @@ pub fn reorderLists() void { const layo = dvui.dataGetPtrDefault(null, uniqueId, "reorderLayout", reorderLayout, .horizontal); if (dvui.expander(@src(), "Simple", .{ .default_expanded = true }, .{ .expand = .horizontal })) { - var vbox = dvui.box(@src(), .vertical, .{ .margin = .{ .x = 10 } }); + var vbox = dvui.box(@src(), .{}, .{ .margin = .{ .x = 10 } }); defer vbox.deinit(); { - var hbox2 = dvui.box(@src(), .horizontal, .{}); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox2.deinit(); const entries = [_][]const u8{ "Vertical", "Horizontal", "Flex" }; @@ -25,7 +25,7 @@ pub fn reorderLists() void { } { - var hbox2 = dvui.box(@src(), .horizontal, .{}); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox2.deinit(); dvui.label(@src(), "Drag", .{}, .{}); dvui.icon(@src(), "drag_icon", dvui.entypo.menu, .{}, .{ .min_size_content = .{ .h = 22 } }); @@ -36,7 +36,7 @@ pub fn reorderLists() void { } if (dvui.expander(@src(), "Advanced", .{}, .{ .expand = .horizontal })) { - var vbox = dvui.box(@src(), .vertical, .{ .margin = .{ .x = 10 } }); + var vbox = dvui.box(@src(), .{}, .{ .margin = .{ .x = 10 } }); defer vbox.deinit(); dvui.label(@src(), "Drag off list to remove.", .{}, .{}); @@ -44,7 +44,7 @@ pub fn reorderLists() void { } if (dvui.expander(@src(), "Tree", .{ .default_expanded = true }, .{ .expand = .horizontal })) { - var vbox = dvui.box(@src(), .vertical, .{ .margin = .{ .x = 10 }, .expand = .both }); + var vbox = dvui.box(@src(), .{}, .{ .margin = .{ .x = 10 }, .expand = .both }); defer vbox.deinit(); reorderTree(); @@ -76,8 +76,8 @@ pub fn reorderListsSimple(lay: reorderLayout) void { var vbox: ?*dvui.BoxWidget = null; var fbox: ?*dvui.FlexBoxWidget = null; switch (lay) { - .vertical => vbox = dvui.box(@src(), .vertical, .{ .expand = .both }), - .horizontal => vbox = dvui.box(@src(), .horizontal, .{ .expand = .both }), + .vertical => vbox = dvui.box(@src(), .{}, .{ .expand = .both }), + .horizontal => vbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both }), .flex => fbox = dvui.flexbox(@src(), .{}, .{ .expand = .both }), } defer { @@ -98,7 +98,7 @@ pub fn reorderListsSimple(lay: reorderLayout) void { } // actual content of the list entry - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .both, .border = dvui.Rect.all(1), .background = true, .color_fill = .fill_window }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both, .border = dvui.Rect.all(1), .background = true, .color_fill = .fill_window }); defer hbox.deinit(); dvui.label(@src(), "{s}", .{s}, .{}); @@ -152,7 +152,7 @@ pub fn reorderListsAdvanced() void { } }; - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); // template you can drag to add to list @@ -162,7 +162,7 @@ pub fn reorderListsAdvanced() void { if (g.strings_len == g.strings.len) { dvui.label(@src(), "List Full", .{}, .{ .gravity_x = 1.0 }); } else { - var hbox2 = dvui.box(@src(), .horizontal, .{ .gravity_x = 1.0, .border = dvui.Rect.all(1), .margin = dvui.Rect.all(4), .background = true, .color_fill = .fill_window }); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal }, .{ .gravity_x = 1.0, .border = dvui.Rect.all(1), .margin = dvui.Rect.all(4), .background = true, .color_fill = .fill_window }); defer hbox2.deinit(); dvui.label(@src(), "Drag to add : {d}", .{g.strings_len}, .{}); @@ -184,7 +184,7 @@ pub fn reorderListsAdvanced() void { defer reorder.deinit(); // determines layout of list - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both }); defer vbox.deinit(); if (added_idx) |ai| { @@ -229,7 +229,7 @@ pub fn reorderListsAdvanced() void { } // actual content of the list entry - var hbox2 = dvui.box(@src(), .horizontal, .{ .expand = .both, .border = dvui.Rect.all(1), .background = true, .color_fill = .fill_window }); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both, .border = dvui.Rect.all(1), .background = true, .color_fill = .fill_window }); defer hbox2.deinit(); dvui.label(@src(), "{s}", .{s}, .{}); diff --git a/src/Examples/scroll_canvas.zig b/src/Examples/scroll_canvas.zig index 54970655..1279a3eb 100644 --- a/src/Examples/scroll_canvas.zig +++ b/src/Examples/scroll_canvas.zig @@ -1,6 +1,6 @@ /// ![image](Examples-scrollCanvas.png) pub fn scrollCanvas() void { - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both }); defer vbox.deinit(); const scroll_info = dvui.dataGetPtrDefault(null, vbox.data().id, "scroll_info", ScrollInfo, .{ .vertical = .given, .horizontal = .given }); @@ -67,7 +67,7 @@ pub fn scrollCanvas() void { const evts = dvui.events(); for (boxes, 0..) |*b, i| { - var dragBox = dvui.box(@src(), .vertical, .{ + var dragBox = dvui.box(@src(), .{}, .{ .id_extra = i, .rect = dvui.Rect{ .x = b.x, .y = b.y }, .padding = .{ .h = 5, .w = 5, .x = 5, .y = 5 }, @@ -117,7 +117,7 @@ pub fn scrollCanvas() void { dvui.label(@src(), "Box {d} {d:0>3.0}x{d:0>3.0}", .{ i, b.x, b.y }, .{}); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); if (dvui.buttonIcon( @src(), @@ -143,7 +143,7 @@ pub fn scrollCanvas() void { } { - var hbox = dvui.box(@src(), .horizontal, .{ .margin = dvui.Rect.all(4), .border = dvui.Rect.all(1), .padding = dvui.Rect.all(4), .background = true, .color_fill = .fill_window }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .margin = dvui.Rect.all(4), .border = dvui.Rect.all(1), .padding = dvui.Rect.all(4), .background = true, .color_fill = .fill_window }); defer hbox.deinit(); for (evts) |*e| { @@ -159,7 +159,7 @@ pub fn scrollCanvas() void { _ = dvui.spacer(@src(), .{ .min_size_content = .width(5), .id_extra = k }); } const col = if (dragging_this) dvui.Color.lime.opacity(0.5) else dvui.Color.blue; - var dbox = dvui.box(@src(), .vertical, .{ .id_extra = k, .min_size_content = .{ .w = 20, .h = 20 }, .background = true, .color_fill = .{ .color = col } }); + var dbox = dvui.box(@src(), .{}, .{ .id_extra = k, .min_size_content = .{ .w = 20, .h = 20 }, .background = true, .color_fill = .{ .color = col } }); defer dbox.deinit(); for (evts) |*e| { @@ -390,7 +390,7 @@ test "DOCIMG scrollCanvas" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); scrollCanvas(); return .ok; diff --git a/src/Examples/scrolling.zig b/src/Examples/scrolling.zig index 953be991..2e2ac664 100644 --- a/src/Examples/scrolling.zig +++ b/src/Examples/scrolling.zig @@ -7,7 +7,7 @@ pub fn scrolling() void { }; { - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer hbox.deinit(); const Data = dvui.dataGetPtrDefault(null, hbox.data().id, "data", Data1, .{}); @@ -16,7 +16,7 @@ pub fn scrolling() void { var scroll_lock_visible = false; { - var vbox = dvui.box(@src(), .vertical, .{ .expand = .vertical }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .vertical }); defer vbox.deinit(); dvui.label(@src(), "{d} total widgets", .{2 * (Data.msg_end - Data.msg_start)}, .{}); @@ -26,7 +26,7 @@ pub fn scrolling() void { } { - var h2 = dvui.box(@src(), .horizontal, .{}); + var h2 = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer h2.deinit(); if (dvui.button(@src(), "Add Above", .{}, .{})) { Data.msg_start -|= 10; @@ -65,7 +65,7 @@ pub fn scrolling() void { _ = dvui.spacer(@src(), .{ .expand = .vertical }); { - var h2 = dvui.box(@src(), .horizontal, .{}); + var h2 = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer h2.deinit(); if (dvui.button(@src(), "Add Below", .{}, .{})) { Data.msg_end += 10; @@ -86,7 +86,7 @@ pub fn scrolling() void { } } { - var vbox = dvui.box(@src(), .vertical, .{ .expand = .horizontal, .max_size_content = .height(300) }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .horizontal, .max_size_content = .height(300) }); defer vbox.deinit(); dvui.label(@src(), "{d:0>4.2}% visible, offset {d} frac {d:0>4.2}", .{ Data.scroll_info.visibleFraction(.vertical) * 100.0, Data.scroll_info.viewport.y, Data.scroll_info.offsetFraction(.vertical) }, .{}); @@ -122,7 +122,7 @@ pub fn scrolling() void { _ = dvui.separator(@src(), .{ .expand = .horizontal }); _ = dvui.spacer(@src(), .{ .min_size_content = .all(12) }); - var box2 = dvui.box(@src(), .vertical, .{ .expand = .horizontal }); + var box2 = dvui.box(@src(), .{}, .{ .expand = .horizontal }); defer box2.deinit(); const siTop = dvui.dataGetPtrDefault(null, box2.data().id, "siTop", ScrollInfo, .{ .horizontal = .auto }); @@ -138,10 +138,10 @@ pub fn scrolling() void { main_area.installScrollBars(); { - var hboxTop = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + var hboxTop = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer hboxTop.deinit(); - var lbox = dvui.box(@src(), .vertical, .{ .min_size_content = .width(left_side_width) }); + var lbox = dvui.box(@src(), .{}, .{ .min_size_content = .width(left_side_width) }); dvui.label(@src(), "Linked\nScrolling", .{}, .{ .gravity_x = 0.5, .gravity_y = 0.5 }); lbox.deinit(); @@ -152,7 +152,7 @@ pub fn scrolling() void { defer top_area.deinit(); { // inside top area - var topbox = dvui.box(@src(), .horizontal, .{}); + var topbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer topbox.deinit(); for (0..20) |i| { @@ -165,13 +165,13 @@ pub fn scrolling() void { _ = dvui.spacer(@src(), .{ .min_size_content = .all(10) }); { - var hbox3 = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + var hbox3 = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer hbox3.deinit(); var side_area = dvui.scrollArea(@src(), .{ .scroll_info = siLeft, .frame_viewport = .{ .y = fv.y }, .vertical_bar = .hide, .process_events_after = false }, .{ .min_size_content = .{ .w = left_side_width, .h = 200 }, .expand = .vertical }); { // inside side area - var sidebox = dvui.box(@src(), .vertical, .{}); + var sidebox = dvui.box(@src(), .{}, .{}); defer sidebox.deinit(); for (0..20) |i| { @@ -191,10 +191,10 @@ pub fn scrolling() void { { // inside main area - var mainbox = dvui.box(@src(), .vertical, .{}); + var mainbox = dvui.box(@src(), .{}, .{}); defer mainbox.deinit(); { - var mainbox2 = dvui.box(@src(), .horizontal, .{}); + var mainbox2 = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer mainbox2.deinit(); for (0..20) |i| { dvui.label(@src(), "label {d}", .{i}, .{ .id_extra = i }); @@ -229,7 +229,7 @@ test "DOCIMG scrolling" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); scrolling(); return .ok; diff --git a/src/Examples/struct_ui.zig b/src/Examples/struct_ui.zig index 84e1fa68..29909a9e 100644 --- a/src/Examples/struct_ui.zig +++ b/src/Examples/struct_ui.zig @@ -1,6 +1,6 @@ /// ![image](Examples-struct_ui.png) pub fn structUI() void { - var b = dvui.box(@src(), .vertical, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); + var b = dvui.box(@src(), .{}, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); defer b.deinit(); const Top = struct { @@ -38,7 +38,7 @@ pub fn structUI() void { /// ![image](Examples-themeEditor.png) pub fn themeEditor() void { - var b2 = dvui.box(@src(), .vertical, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); + var b2 = dvui.box(@src(), .{}, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); defer b2.deinit(); const color_field_options = dvui.StructFieldOptions(dvui.Color, .{ .style_err, .style_accent }){ .fields = .{ @@ -87,7 +87,7 @@ test "DOCIMG struct_ui" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); structUI(); return .ok; @@ -104,7 +104,7 @@ test "DOCIMG themeEditor" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); themeEditor(); return .ok; @@ -129,7 +129,7 @@ test "DOCIMG themeEditor" { } pub fn themeSerialization() void { - var serialize_box = dvui.box(@src(), .vertical, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); + var serialize_box = dvui.box(@src(), .{}, .{ .expand = .horizontal, .margin = .{ .x = 10 } }); defer serialize_box.deinit(); dvui.labelNoFmt(@src(), "TODO: demonstrate loading a quicktheme here", .{}, .{}); diff --git a/src/Examples/styling.zig b/src/Examples/styling.zig index 619f1762..105c8cc4 100644 --- a/src/Examples/styling.zig +++ b/src/Examples/styling.zig @@ -5,7 +5,7 @@ var backbox_color: dvui.Color = .black; /// ![image](Examples-styling.png) pub fn styling() void { { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); _ = dvui.button(@src(), "Accent", .{}, dvui.themeGet().accent()); @@ -16,7 +16,7 @@ pub fn styling() void { } { - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal, .min_size_content = .{ .h = 9 } }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal, .min_size_content = .{ .h = 9 } }); defer hbox.deinit(); dvui.label(@src(), "separators", .{}, .{ .gravity_y = 0.5 }); @@ -26,7 +26,7 @@ pub fn styling() void { dvui.label(@src(), "corner radius", .{}, .{}); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); const opts: Options = .{ .border = Rect.all(1), .background = true, .min_size_content = .{ .w = 20 } }; @@ -49,10 +49,10 @@ pub fn styling() void { } { - var vbox = dvui.box(@src(), .vertical, .{}); + var vbox = dvui.box(@src(), .{}, .{}); defer vbox.deinit(); - var backbox = dvui.box(@src(), .horizontal, .{ .min_size_content = .{ .h = 40 }, .expand = .horizontal, .background = true, .color_fill = .{ .color = backbox_color } }); + var backbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .min_size_content = .{ .h = 40 }, .expand = .horizontal, .background = true, .color_fill = .{ .color = backbox_color } }); backbox.deinit(); if (dvui.sliderEntry(@src(), "A: {d:0.2}", .{ .value = &hsv_color.a, .min = 0, .max = 1, .interval = 0.01 }, .{ .min_size_content = .{}, .expand = .horizontal })) { @@ -67,7 +67,7 @@ pub fn styling() void { } } { - var vbox = dvui.box(@src(), .vertical, .{}); + var vbox = dvui.box(@src(), .{}, .{}); defer vbox.deinit(); if (rgbSliders(@src(), &backbox_color, .{})) { @@ -82,7 +82,7 @@ pub fn styling() void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); const border = dvui.dataGetPtrDefault(null, hbox.data().id, "border", bool, true); @@ -95,7 +95,7 @@ pub fn styling() void { // We are using two boxes here so the box shadow can have different corner_radius values. { - var vbox = dvui.box(@src(), .vertical, .{ .margin = dvui.Rect.all(30), .min_size_content = .{ .w = 200, .h = 100 }, .corner_radius = dvui.Rect.all(5), .background = true, .border = if (border.*) dvui.Rect.all(1) else null, .box_shadow = .{ .color = .fromColor(backbox_color), .corner_radius = dvui.Rect.all(radius.*), .shrink = shrink.*, .offset = offset.*, .fade = fade.*, .alpha = alpha.* } }); + var vbox = dvui.box(@src(), .{}, .{ .margin = dvui.Rect.all(30), .min_size_content = .{ .w = 200, .h = 100 }, .corner_radius = dvui.Rect.all(5), .background = true, .border = if (border.*) dvui.Rect.all(1) else null, .box_shadow = .{ .color = .fromColor(backbox_color), .corner_radius = dvui.Rect.all(radius.*), .shrink = shrink.*, .offset = offset.*, .fade = fade.*, .alpha = alpha.* } }); defer vbox.deinit(); dvui.label(@src(), "Box shadows", .{}, .{ .gravity_x = 0.5 }); _ = dvui.checkbox(@src(), border, "border", .{}); @@ -107,19 +107,19 @@ pub fn styling() void { _ = dvui.sliderEntry(@src(), "alpha: {d:0.2}", .{ .value = alpha, .min = 0, .max = 1, .interval = 0.01 }, .{ .gravity_x = 0.5 }); } { - var vbox2 = dvui.box(@src(), .vertical, .{ .margin = .{ .y = 30 } }); + var vbox2 = dvui.box(@src(), .{}, .{ .margin = .{ .y = 30 } }); defer vbox2.deinit(); const gradient = dvui.dataGetPtrDefault(null, vbox2.data().id, "gradient", usize, 0); { - var gbox = dvui.box(@src(), .horizontal, .{}); + var gbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer gbox.deinit(); dvui.label(@src(), "Gradient", .{}, .{ .gravity_y = 0.5 }); _ = dvui.dropdown(@src(), &.{ "flat", "horizontal", "vertical", "radial" }, gradient, .{}); } - var drawBox = dvui.box(@src(), .vertical, .{ .min_size_content = .{ .w = 200, .h = 100 } }); + var drawBox = dvui.box(@src(), .{}, .{ .min_size_content = .{ .w = 200, .h = 100 } }); defer drawBox.deinit(); const rs = drawBox.data().contentRectScale(); @@ -165,7 +165,7 @@ pub fn styling() void { // Let's wrap the sliderEntry widget so we have 3 that represent a Color pub fn rgbSliders(src: std.builtin.SourceLocation, color: *dvui.Color, opts: Options) bool { - var hbox = dvui.boxEqual(src, .horizontal, opts); + var hbox = dvui.box(src, .{ .dir = .horizontal, .equal_space = true }, opts); defer hbox.deinit(); var red: f32 = @floatFromInt(color.r); @@ -192,7 +192,7 @@ pub fn rgbSliders(src: std.builtin.SourceLocation, color: *dvui.Color, opts: Opt // Let's wrap the sliderEntry widget so we have 3 that represent a HSLuv Color pub fn hsluvSliders(src: std.builtin.SourceLocation, hsluv: *dvui.Color.HSLuv, opts: Options) bool { - var hbox = dvui.boxEqual(src, .horizontal, opts); + var hbox = dvui.box(src, .{ .dir = .horizontal, .equal_space = true }, opts); defer hbox.deinit(); var changed = false; @@ -219,7 +219,7 @@ test "DOCIMG styling" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); styling(); return .ok; diff --git a/src/Examples/text_entry.zig b/src/Examples/text_entry.zig index ecad8789..8c27009a 100644 --- a/src/Examples/text_entry.zig +++ b/src/Examples/text_entry.zig @@ -13,7 +13,7 @@ pub fn textEntryWidgets(demo_win_id: dvui.WidgetId) void { var enter_pressed = false; { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Singleline", .{}, .{ .gravity_y = 0.5 }); @@ -28,7 +28,7 @@ pub fn textEntryWidgets(demo_win_id: dvui.WidgetId) void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); left_alignment.spacer(@src(), 0); @@ -48,7 +48,7 @@ pub fn textEntryWidgets(demo_win_id: dvui.WidgetId) void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Password", .{}, .{ .gravity_y = 0.5 }); @@ -104,11 +104,11 @@ pub fn textEntryWidgets(demo_win_id: dvui.WidgetId) void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); { - var vbox = dvui.box(@src(), .vertical, .{ .gravity_y = 0.5 }); + var vbox = dvui.box(@src(), .{}, .{ .gravity_y = 0.5 }); defer vbox.deinit(); dvui.label(@src(), "Multiline", .{}, .{}); @@ -156,7 +156,7 @@ pub fn textEntryWidgets(demo_win_id: dvui.WidgetId) void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Multiline Font", .{}, .{ .gravity_y = 0.5 }); @@ -176,12 +176,12 @@ pub fn textEntryWidgets(demo_win_id: dvui.WidgetId) void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); left_alignment.spacer(@src(), 0); - var vbox = dvui.box(@src(), .vertical, .{}); + var vbox = dvui.box(@src(), .{}, .{}); defer vbox.deinit(); var la2 = dvui.Alignment.init(@src(), 0); @@ -192,7 +192,7 @@ pub fn textEntryWidgets(demo_win_id: dvui.WidgetId) void { dvui.backend.wasm.wasm_add_noto_font(); } } else { - var hbox2 = dvui.box(@src(), .horizontal, .{}); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal }, .{}); dvui.label(@src(), "Name", .{}, .{ .gravity_y = 0.5 }); la2.spacer(@src(), 0); @@ -209,7 +209,7 @@ pub fn textEntryWidgets(demo_win_id: dvui.WidgetId) void { te_name.deinit(); hbox2.deinit(); - var hbox3 = dvui.box(@src(), .horizontal, .{}); + var hbox3 = dvui.box(@src(), .{ .dir = .horizontal }, .{}); var new_filename: ?[]const u8 = null; @@ -295,7 +295,7 @@ pub fn textEntryWidgets(demo_win_id: dvui.WidgetId) void { // Combobox { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "ComboBox", .{}, .{ .gravity_y = 0.5 }); @@ -331,7 +331,7 @@ pub fn textEntryWidgets(demo_win_id: dvui.WidgetId) void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Suggest", .{}, .{ .gravity_y = 0.5 }); @@ -405,7 +405,7 @@ pub fn textEntryWidgets(demo_win_id: dvui.WidgetId) void { }; { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "Parse", .{}, .{ .gravity_y = 0.5 }); @@ -447,7 +447,7 @@ pub fn textEntryWidgets(demo_win_id: dvui.WidgetId) void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); left_alignment.spacer(@src(), 0); @@ -492,7 +492,7 @@ test "DOCIMG text_entry" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); textEntryWidgets(box.data().id); return .ok; diff --git a/src/Examples/text_layout.zig b/src/Examples/text_layout.zig index 77260ca6..e42dc2f3 100644 --- a/src/Examples/text_layout.zig +++ b/src/Examples/text_layout.zig @@ -9,7 +9,7 @@ pub fn layoutText() void { tl.install(.{}); defer tl.deinit(); - var cbox = dvui.box(@src(), .vertical, .{ .margin = dvui.Rect.all(6), .min_size_content = .{ .w = 40 } }); + var cbox = dvui.box(@src(), .{ .dir = .vertical }, .{ .margin = dvui.Rect.all(6), .min_size_content = .{ .w = 40 } }); if (dvui.buttonIcon( @src(), "play", @@ -32,7 +32,7 @@ pub fn layoutText() void { } cbox.deinit(); - cbox = dvui.box(@src(), .vertical, .{ .margin = Rect.all(4), .padding = Rect.all(4), .gravity_x = 1.0, .background = true, .color_fill = .fill_window, .min_size_content = .{ .w = 160 }, .max_size_content = .width(160) }); + cbox = dvui.box(@src(), .{}, .{ .margin = Rect.all(4), .padding = Rect.all(4), .gravity_x = 1.0, .background = true, .color_fill = .fill_window, .min_size_content = .{ .w = 160 }, .max_size_content = .width(160) }); dvui.icon(@src(), "aircraft", entypo.aircraft, .{}, .{ .min_size_content = .{ .h = 30 }, .gravity_x = 0.5 }); dvui.label(@src(), "Caption Heading", .{}, .{ .font_style = .caption_heading, .gravity_x = 0.5 }); var tl_caption = dvui.textLayout(@src(), .{}, .{ .expand = .horizontal, .background = false }); @@ -89,7 +89,7 @@ test "DOCIMG text_layout" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); layoutText(); return .ok; diff --git a/src/Examples/theming.zig b/src/Examples/theming.zig index 827de565..53cfbaf5 100644 --- a/src/Examples/theming.zig +++ b/src/Examples/theming.zig @@ -19,11 +19,11 @@ pub fn theming() void { defer paned.deinit(); if (paned.showFirst()) { - const vbox = dvui.box(@src(), .vertical, .{ .expand = .both, .margin = .{ .y = 10 } }); + const vbox = dvui.box(@src(), .{}, .{ .expand = .both, .margin = .{ .y = 10 } }); defer vbox.deinit(); { - const hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + const hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer hbox.deinit(); if (paned.collapsed() and dvui.button(@src(), "To Preview", .{}, .{ .gravity_x = 1 })) { paned.animateSplit(0); @@ -48,7 +48,7 @@ pub fn theming() void { } { - const hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + const hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer hbox.deinit(); dvui.labelNoFmt(@src(), "Name:", .{}, .{ .gravity_y = 0.5 }); @@ -96,7 +96,7 @@ pub fn theming() void { defer dvui.themeSet(&prev_theme); dvui.themeSet(&custom_theme); - var vbox = dvui.box(@src(), .vertical, .{ .background = true, .padding = .all(10), .corner_radius = .all(10) }); + var vbox = dvui.box(@src(), .{}, .{ .background = true, .padding = .all(10), .corner_radius = .all(10) }); defer vbox.deinit(); if (paned.collapsed() and dvui.button(@src(), "To Editor", .{}, .{ .gravity_x = 1 })) { @@ -104,7 +104,7 @@ pub fn theming() void { } { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); _ = dvui.button(@src(), "Accent", .{}, dvui.themeGet().accent()); @@ -140,7 +140,7 @@ const ThemeEditingPage = enum { fn colors(theme: *dvui.Theme) bool { var changed = false; - const hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal, .margin = .{ .y = 5 } }); + const hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal, .margin = .{ .y = 5 } }); defer hbox.deinit(); const active_color = dvui.dataGetPtrDefault(null, hbox.data().id, "Color", Options.ColorsFromTheme, .accent); @@ -204,7 +204,7 @@ fn colors(theme: *dvui.Theme) bool { fn fonts(theme: *dvui.Theme) bool { var changed = false; - const hbox = dvui.box(@src(), .horizontal, .{}); + const hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); const active_font = dvui.dataGetPtrDefault(null, hbox.data().id, "Fonts", Options.FontStyle, .body); @@ -238,7 +238,7 @@ fn fonts(theme: *dvui.Theme) bool { inline else => |f| &@field(theme, "font_" ++ @tagName(f)), }; - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both }); defer vbox.deinit(); if (dvui.sliderEntry(@src(), "Size: {d:0}", .{ .min = 4, .max = 100, .interval = 1, .value = &edited_font.size }, .{})) { @@ -285,7 +285,7 @@ const Styles = enum { fn styles(theme: *dvui.Theme) bool { var changed = false; - const hbox = dvui.box(@src(), .horizontal, .{ .expand = .horizontal, .margin = .{ .y = 5 } }); + const hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal, .margin = .{ .y = 5 } }); defer hbox.deinit(); const active_style = dvui.dataGetPtrDefault(null, hbox.data().id, "Style", Styles, .accent); @@ -343,7 +343,7 @@ fn styles(theme: *dvui.Theme) bool { } } - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both, .margin = .all(5) }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both, .margin = .all(5) }); defer vbox.deinit(); var tabs = dvui.TabsWidget.init(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); @@ -433,7 +433,7 @@ test "DOCIMG theming" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); theming(); return .ok; diff --git a/src/Rect.zig b/src/Rect.zig index 494113e7..d4356225 100644 --- a/src/Rect.zig +++ b/src/Rect.zig @@ -257,7 +257,7 @@ pub fn RectType(comptime units: dvui.enums.Units) type { const res = rect.scale(0.5, Rect); try std.testing.expectEqualDeep(Rect{ .x = 25, .y = 25, .w = 75, .h = 75 }, res); - var box = dvui.box(@src(), .horizontal, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); defer box.deinit(); Rect.Physical.cast(rect).stroke(.{}, .{ .thickness = 1, .color = .gray, .closed = true }); Rect.Physical.cast(res).stroke(.{}, .{ .thickness = 1, .color = .red, .closed = true }); @@ -286,7 +286,7 @@ pub fn RectType(comptime units: dvui.enums.Units) type { const res = rect.offset(.{ .x = 50, .y = 50 }); // width and height does nothing try std.testing.expectEqualDeep(Rect{ .x = 100, .y = 100, .w = 100, .h = 100 }, res); - var box = dvui.box(@src(), .horizontal, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); defer box.deinit(); Rect.Physical.cast(rect).stroke(.{}, .{ .thickness = 1, .color = .gray, .closed = true }); Rect.Physical.cast(res).stroke(.{}, .{ .thickness = 1, .color = .red, .closed = true }); @@ -321,7 +321,7 @@ pub fn RectType(comptime units: dvui.enums.Units) type { const res = rect.offsetNegPoint(.{ .x = 50, .y = 50 }); try std.testing.expectEqualDeep(Rect{ .x = 50, .y = 50, .w = 100, .h = 100 }, res); - var box = dvui.box(@src(), .horizontal, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); defer box.deinit(); Rect.Physical.cast(rect).stroke(.{}, .{ .thickness = 1, .color = .gray, .closed = true }); Rect.Physical.cast(res).stroke(.{}, .{ .thickness = 1, .color = .red, .closed = true }); @@ -354,7 +354,7 @@ pub fn RectType(comptime units: dvui.enums.Units) type { const ab = Rect.intersect(a, b); try std.testing.expectEqualDeep(Rect{ .x = 100, .y = 100, .w = 50, .h = 50 }, ab); - var box = dvui.box(@src(), .horizontal, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); defer box.deinit(); Rect.Physical.cast(a).stroke(.{}, .{ .thickness = 1, .color = .gray, .closed = true }); Rect.Physical.cast(b).stroke(.{}, .{ .thickness = 1, .color = .gray, .closed = true }); @@ -388,7 +388,7 @@ pub fn RectType(comptime units: dvui.enums.Units) type { const ab = Rect.unionWith(a, b); try std.testing.expectEqualDeep(Rect{ .x = 50, .y = 50, .w = 150, .h = 150 }, ab); - var box = dvui.box(@src(), .horizontal, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); defer box.deinit(); Rect.Physical.cast(a).stroke(.{}, .{ .thickness = 1, .color = .gray, .closed = true }); Rect.Physical.cast(b).stroke(.{}, .{ .thickness = 1, .color = .gray, .closed = true }); @@ -417,7 +417,7 @@ pub fn RectType(comptime units: dvui.enums.Units) type { const res = rect.inset(.{ .x = 50, .y = 50, .w = 25, .h = 25 }); try std.testing.expectEqualDeep(Rect{ .x = 100, .y = 100, .w = 75, .h = 75 }, res); - var box = dvui.box(@src(), .horizontal, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); defer box.deinit(); Rect.Physical.cast(rect).stroke(.{}, .{ .thickness = 1, .color = .gray, .closed = true }); Rect.Physical.cast(res).stroke(.{}, .{ .thickness = 1, .color = .red, .closed = true }); @@ -451,7 +451,7 @@ pub fn RectType(comptime units: dvui.enums.Units) type { const res = rect.outset(.{ .x = 50, .y = 50, .w = 25, .h = 25 }); try std.testing.expectEqualDeep(Rect{ .x = 50, .y = 50, .w = 125, .h = 125 }, res); - var box = dvui.box(@src(), .horizontal, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{ .background = true, .color_fill = .{ .name = .fill_window }, .expand = .both }); defer box.deinit(); Rect.Physical.cast(rect).stroke(.{}, .{ .thickness = 1, .color = .gray, .closed = true }); Rect.Physical.cast(res).stroke(.{}, .{ .thickness = 1, .color = .red, .closed = true }); diff --git a/src/dvui.zig b/src/dvui.zig index e0e2bc7a..027065cf 100644 --- a/src/dvui.zig +++ b/src/dvui.zig @@ -3920,7 +3920,7 @@ pub fn dialogDisplay(id: WidgetId) !void { { // Add the buttons at the bottom first, so that they are guaranteed to be shown - var hbox = dvui.box(@src(), .horizontal, .{ .gravity_x = 0.5, .gravity_y = 1.0 }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .gravity_x = 0.5, .gravity_y = 1.0 }); defer hbox.deinit(); if (cancel_label) |cl| { @@ -4412,7 +4412,7 @@ pub fn toastsShow(id: ?WidgetId, rect: Rect.Natural) void { toast_win.drawBackground(); toast_win.autoSize(); // affects next frame - var vbox = dvui.box(@src(), .vertical, .{}); + var vbox = dvui.box(@src(), .{}, .{}); defer vbox.deinit(); while (it.next()) |t| { @@ -4781,25 +4781,14 @@ pub fn overlay(src: std.builtin.SourceLocation, opts: Options) *OverlayWidget { /// Extra space is allocated evenly to all packed children expanded in dir /// direction. /// -/// See `boxEqual` and `flexbox`. +/// If init_opts.equal_space is true, all packed children get equal space. /// -/// Only valid between `Window.begin`and `Window.end`. -pub fn box(src: std.builtin.SourceLocation, dir: enums.Direction, opts: Options) *BoxWidget { - var ret = widgetAlloc(BoxWidget); - ret.* = BoxWidget.init(src, .{ .dir = dir }, opts); - ret.install(); - ret.drawBackground(); - return ret; -} - -/// Same as `box` but all packed children receive equal space. -/// -/// See `box` and `flexbox`. +/// See `flexbox`. /// /// Only valid between `Window.begin`and `Window.end`. -pub fn boxEqual(src: std.builtin.SourceLocation, dir: enums.Direction, opts: Options) *BoxWidget { +pub fn box(src: std.builtin.SourceLocation, init_opts: BoxWidget.InitOptions, opts: Options) *BoxWidget { var ret = widgetAlloc(BoxWidget); - ret.* = BoxWidget.init(src, .{ .dir = dir, .equal_space = true }, opts); + ret.* = BoxWidget.init(src, init_opts, opts); ret.install(); ret.drawBackground(); return ret; @@ -4807,7 +4796,7 @@ pub fn boxEqual(src: std.builtin.SourceLocation, dir: enums.Direction, opts: Opt /// Box laying out children horizontally, making new rows as needed. /// -/// See `box` and `boxEqual`. +/// See `box`. /// /// Only valid between `Window.begin`and `Window.end`. pub fn flexbox(src: std.builtin.SourceLocation, init_opts: FlexBoxWidget.InitOptions, opts: Options) *FlexBoxWidget { @@ -4970,7 +4959,7 @@ pub fn gridHeadingCheckbox( { _ = dvui.separator(@src(), .{ .expand = .vertical, .gravity_x = 1.0 }); - var hbox = dvui.box(@src(), .horizontal, header_options); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, header_options); defer hbox.deinit(); is_clicked = dvui.checkbox(@src(), &selected, null, checkbox_opts); @@ -5619,7 +5608,7 @@ pub fn buttonLabelAndIcon(src: std.builtin.SourceLocation, label_str: []const u8 // draw background/border bw.drawBackground(); { - var outer_hbox = box(src, .horizontal, .{ .expand = .horizontal }); + var outer_hbox = box(src, .{ .dir = .horizontal }, .{ .expand = .horizontal }); defer outer_hbox.deinit(); icon(@src(), label_str, tvg_bytes, .{}, opts.strip().override(.{ .gravity_x = 1.0, .color_text = opts.color_text })); labelEx(@src(), "{s}", .{label_str}, .{ .align_x = 0.5 }, opts.strip().override(.{ .expand = .both })); @@ -5647,7 +5636,7 @@ pub fn slider(src: std.builtin.SourceLocation, dir: enums.Direction, fraction: * const options = slider_defaults.override(opts); - var b = box(src, dir, options); + var b = box(src, .{ .dir = dir }, options); defer b.deinit(); tabIndexSet(b.data().id, options.tab_index); @@ -6199,7 +6188,7 @@ pub const Progress_InitOptions = struct { pub fn progress(src: std.builtin.SourceLocation, init_opts: Progress_InitOptions, opts: Options) void { const options = progress_defaults.override(opts); - var b = box(src, init_opts.dir, options); + var b = box(src, .{ .dir = init_opts.dir }, options); defer b.deinit(); const rs = b.data().contentRectScale(); @@ -6253,7 +6242,7 @@ pub fn checkboxEx(src: std.builtin.SourceLocation, target: *bool, label_str: ?[] } } - var b = box(@src(), .horizontal, options.strip().override(.{ .expand = .both })); + var b = box(@src(), .{ .dir = .horizontal }, options.strip().override(.{ .expand = .both })); defer b.deinit(); const check_size = options.fontGet().textHeight(); @@ -6339,7 +6328,7 @@ pub fn radio(src: std.builtin.SourceLocation, active: bool, label_str: ?[]const ret = true; } - var b = box(@src(), .horizontal, options.strip().override(.{ .expand = .both })); + var b = box(@src(), .{ .dir = .horizontal }, options.strip().override(.{ .expand = .both })); defer b.deinit(); const radio_size = options.fontGet().textHeight(); @@ -6696,7 +6685,7 @@ pub fn colorPicker(src: std.builtin.SourceLocation, init_opts: ColorPickerInitOp var changed = picker.color_changed; var rgb = init_opts.hsv.toColor(); - var side_box = dvui.box(@src(), .vertical, .{}); + var side_box = dvui.box(@src(), .{}, .{}); defer side_box.deinit(); const slider_expand = Options.Expand.fromDirection(.horizontal); diff --git a/src/structEntry.zig b/src/structEntry.zig index 5ebca559..a1952c5f 100644 --- a/src/structEntry.zig +++ b/src/structEntry.zig @@ -32,12 +32,12 @@ fn intFieldWidget( if (opt.disabled) return; switch (opt.widget_type) { .number_entry => { - var box = dvui.box(@src(), .horizontal, .{}); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer box.deinit(); dvui.label(@src(), "{s}", .{opt.label_override orelse name}, .{}); - var hbox_aligned = dvui.box(@src(), .horizontal, .{ .margin = alignment.margin(box.data().id) }); + var hbox_aligned = dvui.box(@src(), .{ .dir = .horizontal }, .{ .margin = alignment.margin(box.data().id) }); defer hbox_aligned.deinit(); alignment.record(box.data().id, hbox_aligned.data()); @@ -52,7 +52,7 @@ fn intFieldWidget( dvui.label(@src(), "{}", .{result.*}, .{}); }, .slider => { - var box = dvui.box(@src(), .horizontal, .{}); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer box.deinit(); dvui.label(@src(), "{s}", .{name}, .{}); @@ -108,11 +108,11 @@ pub fn floatFieldWidget( ) void { if (opt.disabled) return; - var box = dvui.box(@src(), .horizontal, .{}); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer box.deinit(); dvui.label(@src(), "{s}", .{opt.label_override orelse name}, .{}); - var hbox_aligned = dvui.box(@src(), .horizontal, .{ .margin = alignment.margin(box.data().id) }); + var hbox_aligned = dvui.box(@src(), .{ .dir = .horizontal }, .{ .margin = alignment.margin(box.data().id) }); defer hbox_aligned.deinit(); alignment.record(box.data().id, hbox_aligned.data()); @@ -139,13 +139,13 @@ fn enumFieldWidget( ) void { if (opt.disabled) return; - var box = dvui.box(@src(), .horizontal, .{}); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer box.deinit(); dvui.label(@src(), "{s}", .{opt.label_override orelse name}, .{}); switch (opt.widget_type) { .dropdown => { - var hbox_aligned = dvui.box(@src(), .horizontal, .{ .margin = alignment.margin(box.data().id) }); + var hbox_aligned = dvui.box(@src(), .{ .dir = .horizontal }, .{ .margin = alignment.margin(box.data().id) }); defer hbox_aligned.deinit(); alignment.record(box.data().id, hbox_aligned.data()); @@ -186,7 +186,7 @@ fn boolFieldWidget( alignment: *dvui.Alignment, ) void { if (opt.disabled) return; - var box = dvui.box(@src(), .horizontal, .{}); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer box.deinit(); //TODO implement dvui_opts for other types @@ -194,7 +194,7 @@ fn boolFieldWidget( .checkbox => { dvui.label(@src(), "{s}", .{opt.label_override orelse name}, .{}); - var hbox_aligned = dvui.box(@src(), .horizontal, .{ .margin = alignment.margin(box.data().id) }); + var hbox_aligned = dvui.box(@src(), .{ .dir = .horizontal }, .{ .margin = alignment.margin(box.data().id) }); defer hbox_aligned.deinit(); alignment.record(box.data().id, hbox_aligned.data()); @@ -243,7 +243,7 @@ fn textFieldWidget( if (opt.disabled) return; //TODO respect alloc setting - var box = dvui.box(@src(), .horizontal, .{}); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer box.deinit(); dvui.label(@src(), "{s}", .{opt.label_override orelse name}, .{}); @@ -272,7 +272,7 @@ fn textFieldWidget( switch (treatment) { .mutate_value_in_place_only => { - var hbox_aligned = dvui.box(@src(), .horizontal, .{ .margin = alignment.margin(box.data().id) }); + var hbox_aligned = dvui.box(@src(), .{ .dir = .horizontal }, .{ .margin = alignment.margin(box.data().id) }); defer hbox_aligned.deinit(); alignment.record(box.data().id, hbox_aligned.data()); @@ -280,7 +280,7 @@ fn textFieldWidget( defer text_box.deinit(); }, .mutate_value_and_realloc => { - var hbox_aligned = dvui.box(@src(), .horizontal, .{ .margin = alignment.margin(box.data().id) }); + var hbox_aligned = dvui.box(@src(), .{ .dir = .horizontal }, .{ .margin = alignment.margin(box.data().id) }); defer hbox_aligned.deinit(); alignment.record(box.data().id, hbox_aligned.data()); @@ -341,7 +341,7 @@ pub fn unionFieldWidget( allocator: ?std.mem.Allocator, alignment: *dvui.Alignment, ) void { - var box = dvui.box(@src(), .vertical, .{}); + var box = dvui.box(@src(), .{}, .{}); defer box.deinit(); const FieldEnum = std.meta.FieldEnum(T); @@ -350,7 +350,7 @@ pub fn unionFieldWidget( var choice: usize = @intFromEnum(std.meta.activeTag(result.*)); { - var hbox = dvui.box(@src(), .vertical, .{}); + var hbox = dvui.box(@src(), .{}, .{}); defer hbox.deinit(); const label = opt.label_override orelse name; if (label.len != 0) { @@ -373,9 +373,9 @@ pub fn unionFieldWidget( } const field_result: *field.type = &@field(result.*, field.name); - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .both }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both }); defer hbox.deinit(); - var line = dvui.box(@src(), .vertical, .{ + var line = dvui.box(@src(), .{}, .{ .border = border, .expand = .vertical, .background = true, @@ -408,23 +408,23 @@ pub fn optionalFieldWidget( alignment: *dvui.Alignment, ) void { if (opt.disabled) return; - var box = dvui.box(@src(), .vertical, .{}); + var box = dvui.box(@src(), .{}, .{}); defer box.deinit(); const Child = @typeInfo(T).optional.child; const checkbox_state = dvui.dataGetPtrDefault(null, box.widget().data().id, "checked", bool, false); { - var hbox = dvui.box(@src(), .horizontal, .{}); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer hbox.deinit(); dvui.label(@src(), "{s}?", .{opt.label_override orelse name}, .{}); _ = dvui.checkbox(@src(), checkbox_state, null, .{}); } if (checkbox_state.*) { - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .both }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both }); defer hbox.deinit(); - var line = dvui.box(@src(), .vertical, .{ + var line = dvui.box(@src(), .{}, .{ .border = border, .expand = .vertical, .background = true, @@ -494,7 +494,7 @@ pub fn singlePointerFieldWidget( alignment: *dvui.Alignment, ) void { if (opt.disabled) return; - var box = dvui.box(@src(), .horizontal, .{}); + var box = dvui.box(@src(), .{ .dir = .horizontal }, .{}); defer box.deinit(); const Child = @typeInfo(T).pointer.child; @@ -620,7 +620,7 @@ pub fn sliceFieldWidget( .padding = dvui.Rect.all(4), }); - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both }); dvui.label(@src(), "{s}", .{opt.label_override orelse name}, .{}); for (result.*, 0..) |_, i| { @@ -636,7 +636,7 @@ pub fn sliceFieldWidget( insert_before_idx = i; // this entry was dropped onto } - var hbox = dvui.box(@src(), .horizontal, .{ + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both, .border = dvui.Rect.all(1), .background = true, @@ -678,7 +678,7 @@ pub fn sliceFieldWidget( _ = dvui.spacer(@src(), .{ .min_size_content = .height(4) }); - var hbox = dvui.box(@src(), .horizontal, .{ + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both, .border = dvui.Rect.all(1), .background = true, @@ -732,7 +732,7 @@ fn structFieldWidget( if (opt.disabled) return; const fields = @typeInfo(T).@"struct".fields; - var box = dvui.box(@src(), .vertical, .{ .expand = .both }); + var box = dvui.box(@src(), .{}, .{ .expand = .both }); defer box.deinit(); const label = opt.label_override orelse name; @@ -752,7 +752,7 @@ fn structFieldWidget( separate = false; } - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .both }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both }); defer hbox.deinit(); if (separate) { @@ -764,7 +764,7 @@ fn structFieldWidget( } if (expand) { - var vbox = dvui.box(@src(), .vertical, .{ .expand = .both }); + var vbox = dvui.box(@src(), .{}, .{ .expand = .both }); defer vbox.deinit(); var left_alignment = dvui.Alignment.init(@src(), 0); @@ -776,7 +776,7 @@ fn structFieldWidget( if (!options.disabled) { const result_ptr = &@field(result.*, field.name); - var widgetbox = dvui.box(@src(), .vertical, .{ + var widgetbox = dvui.box(@src(), .{}, .{ .expand = .both, .id_extra = i, //.margin = left_alignment.margin(hbox.data().id) @@ -877,7 +877,7 @@ pub fn structEntry( result: *T, opts: dvui.Options, ) void { - var box = dvui.box(src, .vertical, opts); + var box = dvui.box(src, .{}, opts); defer box.deinit(); structFieldWidget("", T, exclude, result, .{}, false, null); } @@ -890,7 +890,7 @@ pub fn structEntryEx( result: *T, field_options: StructFieldOptions(T, exclude), ) void { - var box = dvui.box(src, .vertical, .{ .expand = .both }); + var box = dvui.box(src, .{}, .{ .expand = .both }); defer box.deinit(); structFieldWidget(name, T, exclude, result, field_options, false, null); } @@ -903,7 +903,7 @@ pub fn structEntryAlloc( result: *T, opts: dvui.Options, ) void { - var box = dvui.box(src, .vertical, opts); + var box = dvui.box(src, .{}, opts); defer box.deinit(); structFieldWidget("", T, exclude, result, .{}, true, allocator); } @@ -917,7 +917,7 @@ pub fn structEntryExAlloc( result: *T, field_options: StructFieldOptions(T), ) void { - var box = dvui.box(src, .vertical, .{ .expand = .both }); + var box = dvui.box(src, .{}, .{ .expand = .both }); defer box.deinit(); structFieldWidget(name, T, exclude, result, field_options, true, allocator); } diff --git a/src/widgets/BoxWidget.zig b/src/widgets/BoxWidget.zig index 025e61e5..acfb6861 100644 --- a/src/widgets/BoxWidget.zig +++ b/src/widgets/BoxWidget.zig @@ -16,7 +16,7 @@ const BoxWidget = @This(); pub const InitOptions = struct { /// Direction the box packs children in. - dir: enums.Direction, + dir: enums.Direction = .vertical, /// Whether to give equal space to all packed children. equal_space: bool = false, diff --git a/src/widgets/ColorPickerWidget.zig b/src/widgets/ColorPickerWidget.zig index 571aac92..51380f5c 100644 --- a/src/widgets/ColorPickerWidget.zig +++ b/src/widgets/ColorPickerWidget.zig @@ -32,7 +32,7 @@ pub fn init(src: std.builtin.SourceLocation, init_opts: InitOptions, opts: Optio } pub fn install(self: *ColorPickerWidget) void { - self.box = dvui.box(self.src, self.init_opts.dir, self.opts); + self.box = dvui.box(self.src, .{ .dir = self.init_opts.dir }, self.opts); if (valueSaturationBox(@src(), self.init_opts.hsv, .{})) { self.color_changed = true; @@ -60,7 +60,7 @@ pub const value_saturation_box_defaults = Options{ pub fn valueSaturationBox(src: std.builtin.SourceLocation, hsv: *Color.HSV, opts: Options) bool { const options = value_saturation_box_defaults.override(opts); - var b = dvui.box(src, .horizontal, options); + var b = dvui.box(src, .{ .dir = .horizontal }, options); defer b.deinit(); dvui.tabIndexSet(b.data().id, options.tab_index); @@ -190,7 +190,7 @@ pub fn hueSlider(src: std.builtin.SourceLocation, dir: dvui.enums.Direction, hue const options = hue_slider_defaults.override(opts); - var b = dvui.box(src, dir, options); + var b = dvui.box(src, .{ .dir = dir }, options); defer b.deinit(); dvui.tabIndexSet(b.data().id, options.tab_index); @@ -362,7 +362,7 @@ test "DOCIMG ColorPickerWidget" { const frame = struct { fn frame() !dvui.App.Result { - var box = dvui.box(@src(), .vertical, .{ .expand = .both, .background = true, .color_fill = .fill_window }); + var box = dvui.box(@src(), .{}, .{ .expand = .both, .background = true, .color_fill = .fill_window }); defer box.deinit(); var hsv: dvui.Color.HSV = .{ .h = 120, .s = 0.8, .v = 0.9 }; diff --git a/src/widgets/DropdownWidget.zig b/src/widgets/DropdownWidget.zig index 25152aa5..4fe09ebf 100644 --- a/src/widgets/DropdownWidget.zig +++ b/src/widgets/DropdownWidget.zig @@ -70,7 +70,7 @@ pub fn install(self: *DropdownWidget) void { self.menuItem.drawBackground(.{ .focus_as_outline = true }); if (self.init_options.label) |ll| { - var hbox = dvui.box(@src(), .horizontal, .{ .expand = .both }); + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both }); var lw = LabelWidget.initNoFmt(@src(), ll, .{}, self.options.strip().override(.{ .gravity_y = 0.5 })); lw.install(); diff --git a/src/widgets/PlotWidget.zig b/src/widgets/PlotWidget.zig index a4ed5892..7203b2e9 100644 --- a/src/widgets/PlotWidget.zig +++ b/src/widgets/PlotWidget.zig @@ -143,10 +143,10 @@ pub fn install(self: *PlotWidget) void { } } - var hbox1 = dvui.box(@src(), .horizontal, .{ .expand = .both }); + var hbox1 = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both }); // y axis - var yaxis = dvui.box(@src(), .horizontal, .{ .expand = .vertical, .min_size_content = .{ .w = tick_width } }); + var yaxis = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .vertical, .min_size_content = .{ .w = tick_width } }); var yaxis_rect = yaxis.data().rect; if (self.y_axis.name) |yname| { if (yname.len > 0) { @@ -160,7 +160,7 @@ pub fn install(self: *PlotWidget) void { //xaxis_padding.deinit(); // data area - var data_box = dvui.box(@src(), .horizontal, .{ .expand = .both }); + var data_box = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .both }); // mouse hover if (self.init_options.mouse_hover) { @@ -194,7 +194,7 @@ pub fn install(self: *PlotWidget) void { hbox1.deinit(); - var hbox2 = dvui.box(@src(), .horizontal, .{ .expand = .horizontal }); + var hbox2 = dvui.box(@src(), .{ .dir = .horizontal }, .{ .expand = .horizontal }); // bottom left corner under y axis _ = dvui.spacer(@src(), .{ .min_size_content = .width(yaxis_rect.w), .expand = .vertical }); @@ -207,7 +207,7 @@ pub fn install(self: *PlotWidget) void { } // x axis - var xaxis = dvui.box(@src(), .vertical, .{ .gravity_y = 1.0, .expand = .horizontal, .min_size_content = .{ .h = x_tick_height } }); + var xaxis = dvui.box(@src(), .{}, .{ .gravity_y = 1.0, .expand = .horizontal, .min_size_content = .{ .h = x_tick_height } }); if (self.x_axis.name) |xname| { if (xname.len > 0) { dvui.label(@src(), "{s}", .{xname}, .{ .gravity_x = 0.5, .gravity_y = 0.5 }); diff --git a/src/widgets/TextEntryWidget.zig b/src/widgets/TextEntryWidget.zig index 23a19a6f..04f6f3ca 100644 --- a/src/widgets/TextEntryWidget.zig +++ b/src/widgets/TextEntryWidget.zig @@ -162,7 +162,7 @@ pub fn install(self: *TextEntryWidget) void { if (self.textLayout.touchEditing()) |floating_widget| { defer floating_widget.deinit(); - var hbox = dvui.box(@src(), .horizontal, .{ + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .corner_radius = dvui.ButtonWidget.defaults.corner_radiusGet(), .background = true, .border = dvui.Rect.all(1), diff --git a/src/widgets/TextLayoutWidget.zig b/src/widgets/TextLayoutWidget.zig index 890e68a0..184da131 100644 --- a/src/widgets/TextLayoutWidget.zig +++ b/src/widgets/TextLayoutWidget.zig @@ -1434,7 +1434,7 @@ pub fn touchEditing(self: *TextLayoutWidget) ?*FloatingWidget { } pub fn touchEditingMenu(self: *TextLayoutWidget) void { - var hbox = dvui.box(@src(), .horizontal, .{ + var hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .corner_radius = dvui.ButtonWidget.defaults.corner_radiusGet(), .background = true, .border = dvui.Rect.all(1), -- knotmirror 0.0.1