xo-imgui: support dynamic vsync_enabled setting + demo in ex4

This commit is contained in:
Roland Conybeare 2025-11-12 13:33:20 -05:00
commit b4a8ecd7d6
5 changed files with 58 additions and 14 deletions

View file

@ -741,7 +741,7 @@ DrawState::draw_gc_state(const AppState & app_state,
/* TODO: does this reset coord space? */
ImRect alloc_rect;
{
ImGui::BeginChild("top pane", ImVec2(0, 105), ImGuiChildFlags_Border | ImGuiChildFlags_ResizeY);
ImGui::BeginChild("top pane", ImVec2(0, 200), ImGuiChildFlags_Border | ImGuiChildFlags_ResizeY);
alloc_rect = ImRect(canvas_rect.top_left() + ImGui::GetWindowContentRegionMin(),
canvas_rect.top_left() + ImGui::GetWindowContentRegionMax());
@ -817,7 +817,7 @@ DrawState::draw_gc_state(const AppState & app_state,
ImGui::EndChild();
}
ImGui::Text("placeholder text");
//ImGui::Text("placeholder text"); // appears below history_rect
/* BeginChild() again ? */

View file

@ -85,6 +85,8 @@ struct DrawState {
public:
/** when true display imgui demo window **/
bool show_demo_window_ = false;
/** whether vsync feature enabled (throttle to ~60 fps) **/
bool vsync_enabled_ = true;
draw_state_type state_type_ = draw_state_type::alloc;

View file

@ -80,7 +80,7 @@ namespace {
*p_f = 0.0f;
*p_counter = 0;
return [p_app_state, p_draw_state, p_f, p_counter](ImGuiContext * imgui_cx)
return [p_app_state, p_draw_state, p_f, p_counter](VulkanApp * vulkan_app, ImGuiContext * imgui_cx)
{
scope log(XO_DEBUG(false));
@ -108,6 +108,19 @@ namespace {
ImGui::End();
# endif
// 0. main menubar
if (ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("View")) {
bool x = vulkan_app->vsync_enabled_flag();
if (ImGui::MenuItem("vsync", nullptr, &x)) {
vulkan_app->update_vsync_enabled(x);
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
// 1. create a simple ImGui window
ImGui::Begin("Hello, Vulkan + SDL2!");
ImGui::Text("This is a minimal ImGui + Vulkan + SDL2 example!");