Skip to content

Commit

Permalink
move module cimgui to imgui
Browse files Browse the repository at this point in the history
ci: undo betterC on wasm32-target
  • Loading branch information
kassane committed Jan 15, 2025
1 parent ac160f3 commit 1e59e31
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
- name: (Zig) Build Native
run: zig build -Dimgui --summary all
- name: (Zig + emsdk) Build Wasm
run: zig build -Dimgui -DzigCC --summary all -Dtarget=wasm32-emscripten-none -Doptimize=ReleaseSmall -DbetterC
run: zig build -Dimgui -DzigCC --summary all -Dtarget=wasm32-emscripten-none -Doptimize=ReleaseSmall
16 changes: 8 additions & 8 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,17 @@ pub fn buildLibSokol(b: *Build, options: LibSokolOptions) !*CompileStep {
.file = b.path(csrc_root ++ "sokol_imgui.c"),
.flags = cflags,
});
const cimgui = try buildImgui(b, .{
const imgui = try buildImgui(b, .{
.target = options.target,
.optimize = options.optimize,
.emsdk = options.emsdk,
.use_tsan = lib.root_module.sanitize_thread orelse false,
.use_ubsan = lib.root_module.sanitize_c orelse false,
});
for (cimgui.root_module.include_dirs.items) |dir| {
for (imgui.root_module.include_dirs.items) |dir| {
try lib.root_module.include_dirs.append(b.allocator, dir);
}
lib.linkLibrary(cimgui);
lib.linkLibrary(imgui);
}
return lib;
}
Expand Down Expand Up @@ -422,7 +422,7 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*std.Build.Step.InstallDi
"-i=sokol",
"-i=shaders",
"-i=handmade",
"-i=cimgui",
"-i=imgui",
});

// sokol include path
Expand Down Expand Up @@ -1013,8 +1013,8 @@ fn buildImgui(b: *Build, options: libImGuiOptions) !*CompileStep {
libimgui.root_module.sanitize_thread = options.use_tsan;

if (b.lazyDependency("imgui", .{})) |dep| {
const cimgui = dep.path(imguiver_path);
libimgui.addIncludePath(cimgui);
const imgui = dep.path(imguiver_path);
libimgui.addIncludePath(imgui);

if (options.emsdk) |emsdk| {
if (libimgui.rootModuleTarget().isWasm()) {
Expand All @@ -1032,13 +1032,13 @@ fn buildImgui(b: *Build, options: libImGuiOptions) !*CompileStep {
}
}
libimgui.addCSourceFiles(.{
.root = cimgui,
.root = imgui,
.files = &.{
"cimgui.cpp",
},
});
libimgui.addCSourceFiles(.{
.root = cimgui,
.root = imgui,
.files = &.{
"imgui.cpp",
"imgui_draw.cpp",
Expand Down
40 changes: 20 additions & 20 deletions dub.sdl

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/examples/droptest.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import sg = sokol.gfx;
import sgapp = sokol.glue;
import sapp = sokol.app;
import sfetch = sokol.fetch;
import imgui = sokol.imgui;
import simgui = sokol.imgui;
import log = sokol.log;
import cimgui.cimgui;
import imgui;

enum MAX_FILE_SIZE = 1024 * 1024;

Expand Down Expand Up @@ -41,8 +41,8 @@ extern (C) void init() @safe @nogc nothrow
logger: {func: &log.slog_func}
};
sg.setup(gfx);
imgui.Desc imgui_desc = {0};
imgui.setup(imgui_desc);
simgui.Desc imgui_desc = {0};
simgui.setup(imgui_desc);

// ifndef emscripten
// dfmt off
Expand All @@ -66,14 +66,14 @@ extern (C) void frame() @trusted
{
sfetch.dowork;
}
imgui.FrameDesc imgui_desc = {
simgui.FrameDesc imgui_desc = {
width: sapp.width(),
height: sapp.height(),
delta_time: sapp.frameDuration(),
dpi_scale: sapp.dpiScale(),
};
// dfmt on
imgui.newFrame(imgui_desc);
simgui.newFrame(imgui_desc);

// /*=== UI CODE STARTS HERE ===*/
const ImVec2 window_pos = {10, 10};
Expand Down Expand Up @@ -105,14 +105,14 @@ extern (C) void frame() @trusted

sg.Pass pass = {swapchain: sgapp.swapchain};
sg.beginPass(pass);
imgui.render;
simgui.render;
sg.endPass;
sg.commit;
}

extern (C) void event(const(sapp.Event)* ev) @trusted @nogc nothrow
{
imgui.simgui_handle_event(ev);
simgui.simgui_handle_event(ev);
if (ev.type == sapp.EventType.Files_dropped)
{
version (Emscripten)
Expand Down Expand Up @@ -146,7 +146,7 @@ extern (C) void cleanup() @safe @nogc nothrow
sfetch.shutdown;
}
// dfmt on
imgui.shutdown;
simgui.shutdown;
sg.shutdown;
}

Expand Down
18 changes: 9 additions & 9 deletions src/examples/imgui.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ private:
import sg = sokol.gfx;
import sgapp = sokol.glue;
import sapp = sokol.app;
import imgui = sokol.imgui;
import simgui = sokol.imgui;
import log = sokol.log;
import cimgui.cimgui;
import imgui;

extern (C):
@safe:
Expand All @@ -39,19 +39,19 @@ void init() nothrow
logger: {func: &log.slog_func}
};
sg.setup(gfx);
imgui.Desc imgui_desc = {0};
imgui.setup(imgui_desc);
simgui.Desc imgui_desc = {0};
simgui.setup(imgui_desc);
}

void frame() @trusted
{
imgui.FrameDesc imgui_desc = {
simgui.FrameDesc imgui_desc = {
width: sapp.width(),
height: sapp.height(),
delta_time: sapp.frameDuration(),
dpi_scale: sapp.dpiScale(),
};
imgui.newFrame(imgui_desc);
simgui.newFrame(imgui_desc);

/*=== UI CODE STARTS HERE ===*/
const ImVec2 window_pos = {10, 10};
Expand All @@ -71,19 +71,19 @@ void frame() @trusted

sg.Pass pass = {action: state.pass_action, swapchain: sgapp.swapchain};
sg.beginPass(pass);
imgui.render;
simgui.render;
sg.endPass;
sg.commit;
}

void event(const(sapp.Event)* ev) @trusted nothrow
{
imgui.simgui_handle_event(ev);
simgui.simgui_handle_event(ev);
}

void cleanup() @safe nothrow
{
imgui.shutdown;
simgui.shutdown;
sg.shutdown;
}

Expand Down
1 change: 0 additions & 1 deletion src/cimgui/dcimgui.c → src/imgui/dcimgui.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Use importC to import the C header files.

#ifndef DCIMGUI_H
#define DCIMGUI_H
#pragma attribute(push, nogc, nothrow) // dmd-2.110.x feature
Expand Down
Loading

0 comments on commit 1e59e31

Please sign in to comment.