sandbox_topmost.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. """
  2. // Example demonstrating the topMost window feature
  3. #include "hello_imgui/hello_imgui.h"
  4. #include "imgui.h"
  5. int main(int, char**)
  6. {
  7. HelloImGui::RunnerParams runnerParams;
  8. runnerParams.appWindowParams.windowTitle = "TopMost Window Demo";
  9. runnerParams.appWindowParams.windowGeometry.size = {400, 300};
  10. // Enable topMost - window will stay on top of other windows
  11. runnerParams.appWindowParams.topMost = false;
  12. runnerParams.callbacks.ShowGui = []() {
  13. ImGui::Text("This window should stay on top of other windows!");
  14. ImGui::Separator();
  15. // Allow toggling topMost at runtime
  16. auto& params = HelloImGui::GetRunnerParams()->appWindowParams;
  17. bool topMost = params.topMost;
  18. if (ImGui::Checkbox("Keep window on top", &topMost)) {
  19. params.topMost = topMost;
  20. }
  21. ImGui::TextWrapped(
  22. "Note: TopMost is only supported on desktop platforms "
  23. "(Windows, macOS, Linux). On mobile and web platforms, "
  24. "this setting is ignored."
  25. );
  26. };
  27. runnerParams.platformBackendType = HelloImGui::PlatformBackendType::Sdl;
  28. // runnerParams.platformBackendType = HelloImGui::PlatformBackendType::Glfw;
  29. HelloImGui::Run(runnerParams);
  30. return 0;
  31. }
  32. """
  33. from imgui_bundle import hello_imgui, imgui, immapp
  34. def show_gui():
  35. imgui.text("This window should stay on top of other windows!")
  36. imgui.separator()
  37. # Allow toggling topMost at runtime
  38. params = hello_imgui.get_runner_params().app_window_params
  39. top_most = params.top_most
  40. changed, top_most = imgui.checkbox("Keep window on top", top_most)
  41. if changed:
  42. params.top_most = top_most
  43. imgui.text_wrapped(
  44. "Note: TopMost is only supported on desktop platforms "
  45. "(Windows, macOS, Linux). On mobile and web platforms, "
  46. "this setting is ignored."
  47. )
  48. def main():
  49. # runner_params = hello_imgui.RunnerParams()
  50. # runner_params.app_window_params.window_title = "TopMost Window Demo"
  51. # runner_params.app_window_params.window_geometry.size = (400, 300)
  52. # runner_params.app_window_params.top_most = False
  53. # runner_params.callbacks.show_gui = show_gui
  54. # hello_imgui.run(runner_params)
  55. immapp.run(show_gui, top_most=True)
  56. if __name__ == "__main__":
  57. main()