Fix up API calls for initialization

This commit is contained in:
Mitchell Hashimoto
2025-12-31 11:00:21 -08:00
parent 978400b0b0
commit 896361f426
6 changed files with 69 additions and 21 deletions

View File

@@ -1070,8 +1070,11 @@ pub const Inspector = struct {
// Cache our scale because we use it for cursor position calculations.
self.content_scale = x;
// Setup a new style and scale it appropriately.
var style: cimgui.c.ImGuiStyle = .{};
// Setup a new style and scale it appropriately. We must use the
// ImGuiStyle constructor to get proper default values (e.g.,
// CurveTessellationTol) rather than zero-initialized values.
var style: cimgui.c.ImGuiStyle = undefined;
cimgui.ext.ImGuiStyle_ImGuiStyle(&style);
cimgui.c.ImGuiStyle_ScaleAllSizes(&style, @floatCast(x));
const active_style = cimgui.c.ImGui_GetStyle();
active_style.* = style;

View File

@@ -255,8 +255,11 @@ pub const ImguiWidget = extern struct {
io.DisplaySize = .{ .x = @floatFromInt(width), .y = @floatFromInt(height) };
io.DisplayFramebufferScale = .{ .x = 1, .y = 1 };
// Setup a new style and scale it appropriately.
var style: cimgui.c.ImGuiStyle = .{};
// Setup a new style and scale it appropriately. We must use the
// ImGuiStyle constructor to get proper default values (e.g.,
// CurveTessellationTol) rather than zero-initialized values.
var style: cimgui.c.ImGuiStyle = undefined;
cimgui.ext.ImGuiStyle_ImGuiStyle(&style);
cimgui.c.ImGuiStyle_ScaleAllSizes(&style, @floatFromInt(scale_factor));
const active_style = cimgui.c.ImGui_GetStyle();
active_style.* = style;

View File

@@ -138,23 +138,24 @@ pub fn setup() void {
io.IniFilename = null;
io.LogFilename = null;
// Use our own embedded font
{
// TODO: This will have to be recalculated for different screen DPIs.
// This is currently hardcoded to a 2x content scale.
const font_size = 16 * 2;
var font_config: cimgui.c.ImFontConfig = .{};
font_config.FontDataOwnedByAtlas = false;
_ = cimgui.c.ImFontAtlas_AddFontFromMemoryTTF(
io.Fonts,
@ptrCast(@constCast(font.embedded.regular)),
font.embedded.regular.len,
font_size,
&font_config,
null,
);
}
// // Use our own embedded font
// {
// // TODO: This will have to be recalculated for different screen DPIs.
// // This is currently hardcoded to a 2x content scale.
// const font_size = 16 * 2;
//
// var font_config: cimgui.c.ImFontConfig = .{};
// cimgui.ext.ImFontConfig_ImFontConfig(&font_config);
// font_config.FontDataOwnedByAtlas = false;
// _ = cimgui.c.ImFontAtlas_AddFontFromMemoryTTF(
// io.Fonts,
// @ptrCast(@constCast(font.embedded.regular.ptr)),
// @intCast(font.embedded.regular.len),
// font_size,
// &font_config,
// null,
// );
// }
}
pub fn init(surface: *Surface) !Inspector {