From 51c8b8f6cb8d8e15996e031c07be177bfd53fd1a Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Sun, 31 Dec 2023 00:12:03 +0100 Subject: [PATCH] Update hello_imgui (branch refactor_backends) --- bindings/imgui_bundle/hello_imgui.pyi | 786 +++++++++--------- .../bindings/hello_imgui_amalgamation.h | 505 ++++++----- .../bindings/pybind_hello_imgui.cpp | 288 +++---- external/hello_imgui/hello_imgui | 2 +- 4 files changed, 779 insertions(+), 802 deletions(-) diff --git a/bindings/imgui_bundle/hello_imgui.pyi b/bindings/imgui_bundle/hello_imgui.pyi index 353947b8..cef2f8d0 100644 --- a/bindings/imgui_bundle/hello_imgui.pyi +++ b/bindings/imgui_bundle/hello_imgui.pyi @@ -66,6 +66,112 @@ def EmptyEventCallback() -> AnyEventCallback: # hello_imgui.h // # ////////////////////////////////////////////////////////////////////////////////////////////////////////////// +# * +# @@md#Dpi +# +# Special care must be taken in order to correctly handle screen with high DPI (for example, almost all recent laptops screens). +# Otherwise, widgets might be misplaced or too small, and font rendering might be blurry or too small. +# +#### How to position widgets on a window in a Dpi independent way +# +# Using ImVec2 with fixed values is *almost always a bad idea* if you intend your application to be used on high DPI screens. +# Instead you can: +# * either multiply those values by ImGui::GetFontSize() +# * or use `HelloImGui::EmToVec2(x, y)` which will do this multiplication for you. Em stand for the `em` measurements, +# as used in CSS: 1em simply correspond to the current font height. +# +# +#### How to load fonts for a crisp font rendering and a correct size +# +# HelloImGui provides `HelloImGui::DpiFontLoadingFactor()` which corresponds to: +# `DpiWindowSizeFactor() * 1. / ImGui::GetIO().FontGlobalScale` +# where DpiWindowSizeFactor() is equal to `CurrentScreenPixelPerInch / 96` under windows and linux, 1 under macOS +# +# ==> When loading fonts, multiply their size by this factor! +# +#### More details on DPI handling with different OS and backends +# +# Let's consider screen whose physical pixel resolution is 3600x2000, but which will displayed with a scaling factor of 200%, +# so that widgets do not look too small on it. +# +# The way it is handled depends on the OS: +# - On MacOS, the screen will be seen as having a resolution of 1800x1000, and the OS handles the resizing by itself. +# - On Linux, and on Windows if the application is DPI aware, the screen will be seen as having a resolution of 3600x2000. +# - On Windows if the application is not DPI aware, the screen will be seen as having a resolution of 1800x1000 +# +# By default, if using the glfw backend, applications will be Dpi aware under windows. +# Sdl applications are normally not Dpi aware. However HelloImGui makes them Dpi aware when using the sdl backend. +# +# +#### HelloImGui Dpi aware C++ API +# +# `HelloImGui::EmSize()` (C++) and `hello_imgui.em_size()` (Python) return the visible font size on the screen. +# For reproducible results, even on HighDPI screens, always scale your widgets and windows relatively to this size. +# It is somewhat comparable to the [em CSS Unit](https://lyty.dev/css/css-unit.html). +# +# `HelloImGui::EmToVec2(x, y)` (C++) and `hello_imgui.em_to_vec2(x,y)` (Python) return an ImVec2 that you can use +# to size or place your widgets in a DPI independent way. +# +# `HelloImGui::EmSize(nbLines)` (C++) and `hello_imgui.em_size(nb_lines)` (Python) return a size corresponding to nbLines text lines +# +# `HelloImGui::DpiFontLoadingFactor()` (C++) and `hello_imgui.dpi_font_loading_factor()` (Python) return a factor by +# which you shall multiply your font sizes when loading fonts manually with _ImGui::GetIO().Fonts->AddFont..._ +# HelloImGui::LoadFontTTF does this by default. +# +# `HelloImGui::ImGuiDefaultFontGlobalScale()` (C++) and `hello_imgui.imgui_default_font_global_scale()` (Python) returns the +# default value that should be stored inside `ImGui::GetIO().FontGlobalScale`. +# Under windows and linux, this is always 1: no rescaling should be done by ImGui. Under macOS and emscripten, +# this can be < 1 (for example it will be 0.5 if the dpi scaling is 200%) +# @@md +# + +# float EmSize(); /* original C++ signature */ +@overload +def em_size() -> float: + """__HelloImGui::EmSize()__ returns the visible font size on the screen. For good results on HighDPI screens, always scale your + widgets and windows relatively to this size. + It is somewhat comparable to the [em CSS Unit](https://lyty.dev/css/css-unit.html). + EmSize() = ImGui::GetFontSize() + """ + pass + +# float EmSize(float nbLines); /* original C++ signature */ +@overload +def em_size(nb_lines: float) -> float: + """__HelloImGui::EmSize(nbLines)__ returns a size corresponding to nbLines text lines""" + pass + +# __HelloImGui::EmToVec2()__ returns an ImVec2 that you can use to size or place your widgets in a DPI independent way +# ImVec2 EmToVec2(float x, float y); /* original C++ signature */ +@overload +def em_to_vec2(x: float, y: float) -> ImVec2: + pass + +# ImVec2 EmToVec2(ImVec2 v); /* original C++ signature */ +@overload +def em_to_vec2(v: ImVec2) -> ImVec2: + pass + +# float DpiFontLoadingFactor(); /* original C++ signature */ +def dpi_font_loading_factor() -> float: + """Multiply font sizes by this factor when loading fonts manually with ImGui::GetIO().Fonts->AddFont... + (HelloImGui::LoadFontTTF does this by default) + """ + pass + +# float DpiWindowSizeFactor(); /* original C++ signature */ +def dpi_window_size_factor() -> float: + """DpiWindowSizeFactor() is the factor by which window size should be multiplied to get a similar visible size on different OSes. + It returns ApplicationScreenPixelPerInch / 96 under windows and linux. Under macOS, it will return 1. + """ + pass + +# float ImGuiDefaultFontGlobalScale(); /* original C++ signature */ +# } +def imgui_default_font_global_scale() -> float: + """returns the default value that should be stored inside `ImGui::GetIO().FontGlobalScale`""" + pass + # * # @@md#AssetsStructure # @@ -182,6 +288,33 @@ def override_assets_folder(folder: str) -> None: # hello_imgui/hello_imgui_error.h included by hello_imgui.h // # ////////////////////////////////////////////////////////////////////////////////////////////////////////////// +# //////////////////////////////////////////////////////////////////////////////////////////////////////////////// +# hello_imgui/hello_imgui_logger.h included by hello_imgui.h // +# ////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class LogLevel(enum.Enum): + # Debug, /* original C++ signature */ + debug = enum.auto() # (= 0) + # Info, /* original C++ signature */ + info = enum.auto() # (= 1) + # Warning, /* original C++ signature */ + warning = enum.auto() # (= 2) + # Error /* original C++ signature */ + # } + error = enum.auto() # (= 3) + +# void Log(LogLevel level, char const* const format, ...); /* original C++ signature */ +def log(level: LogLevel, format: str) -> None: + pass + +# void LogClear(); /* original C++ signature */ +def log_clear() -> None: + pass + +# void LogGui(ImVec2 size=ImVec2(0.f, 0.f)); /* original C++ signature */ +# } +def log_gui(size: ImVec2 = ImVec2(0.0, 0.0)) -> None: + pass + # //////////////////////////////////////////////////////////////////////////////////////////////////////////////// # hello_imgui/icons_font_awesome.h included by hello_imgui.h // # ////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -192,10 +325,6 @@ def override_assets_folder(folder: str) -> None: # https://github.com/FortAwesome/Font-Awesome/blob/master/webfonts/fa-solid-900.ttf, # https://github.com/FortAwesome/Font-Awesome/blob/master/webfonts/fa-regular-400.ttf, -# //////////////////////////////////////////////////////////////////////////////////////////////////////////////// -# hello_imgui/image_gl.h included by hello_imgui.h // -# ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - # //////////////////////////////////////////////////////////////////////////////////////////////////////////////// # hello_imgui/image_from_asset.h included by hello_imgui.h // # ////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -206,6 +335,12 @@ def override_assets_folder(folder: str) -> None: # * `HelloImGui::ImageFromAsset(const char *assetPath, size, ...)`: will display a static image from the assets. # * `bool HelloImGui::ImageButtonFromAsset(const char *assetPath, size, ...)`: will display a button using an image from the assets. # * `ImTextureID HelloImGui::ImTextureIdFromAsset(const char *assetPath)`: will return a texture ID for an image loaded from the assets. +# * `ImVec2 HelloImGui::ImageSizeFromAsset(const char *assetPath)`: will return the size of an image loaded from the assets. +# * `ImVec2 HelloImGui::ImageProportionalSize(const ImVec2& askedSize, const ImVec2& imageSize)`: +# Will return the displayed size of an image. +# if askedSize.x or askedSize.y is 0, then the corresponding dimension will be computed from the image size, keeping the aspect ratio. +# if askedSize.x>0 and askedSize.y> 0, then the image will be scaled to fit exactly the askedSize, thus potentially changing the aspect ratio. +# Note: this function is used internally by ImageFromAsset and ImageButtonFromAsset, so you don't need to call it directly. # # Images are loaded when first displayed, and then cached (they will be freed just before the application exits). # @@ -223,8 +358,6 @@ def override_assets_folder(folder: str) -> None: # HelloImGui::ImageFromAsset("my_image.jpg"); # ``` # -# *Note: HelloImGui::ImageFromAsset only works with OpenGL backends. It will throw an exception on other backends* -# # @@md # @@ -255,7 +388,184 @@ def image_button_from_asset( def im_texture_id_from_asset(asset_path: str) -> ImTextureID: pass +# ImVec2 ImageSizeFromAsset(const char *assetPath); /* original C++ signature */ +def image_size_from_asset(asset_path: str) -> ImVec2: + pass + +# ImVec2 ImageProportionalSize(const ImVec2& askedSize, const ImVec2& imageSize); /* original C++ signature */ +def image_proportional_size(asked_size: ImVec2, image_size: ImVec2) -> ImVec2: + pass + +# //////////////////////////////////////////////////////////////////////////////////////////////////////////////// +# hello_imgui.h continued // +# ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +# #include "hello_imgui/image_gl_deprecated.h" + # //////////////////////////////////////////////////////////////////////////////////////////////////////////////// +# hello_imgui/imgui_theme.h included by hello_imgui.h // +# ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +# +# Theme tweak utilities for ImGui. +# Reuse and adaptation of imgui_theme.h and imgui_theme.cpp file is granted for other projects, +# provided the origin of those files is stated in the copied version +# Some themes were adapted by themes posted by ImGui users at https://github.com/ocornut/imgui/issues/707 +# + +class ImGuiTheme_(enum.Enum): + # ImGuiTheme_ImGuiColorsClassic = 0, /* original C++ signature */ + imgui_colors_classic = enum.auto() # (= 0) + # ImGuiTheme_ImGuiColorsDark, /* original C++ signature */ + imgui_colors_dark = enum.auto() # (= 1) + # ImGuiTheme_ImGuiColorsLight, /* original C++ signature */ + imgui_colors_light = enum.auto() # (= 2) + # ImGuiTheme_MaterialFlat, /* original C++ signature */ + material_flat = enum.auto() # (= 3) + # ImGuiTheme_PhotoshopStyle, /* original C++ signature */ + photoshop_style = enum.auto() # (= 4) + # ImGuiTheme_GrayVariations, /* original C++ signature */ + gray_variations = enum.auto() # (= 5) + # ImGuiTheme_GrayVariations_Darker, /* original C++ signature */ + gray_variations_darker = enum.auto() # (= 6) + # ImGuiTheme_MicrosoftStyle, /* original C++ signature */ + microsoft_style = enum.auto() # (= 7) + # ImGuiTheme_Cherry, /* original C++ signature */ + cherry = enum.auto() # (= 8) + # ImGuiTheme_Darcula, /* original C++ signature */ + darcula = enum.auto() # (= 9) + # ImGuiTheme_DarculaDarker, /* original C++ signature */ + darcula_darker = enum.auto() # (= 10) + # ImGuiTheme_LightRounded, /* original C++ signature */ + light_rounded = enum.auto() # (= 11) + # ImGuiTheme_SoDark_AccentBlue, /* original C++ signature */ + so_dark_accent_blue = enum.auto() # (= 12) + # ImGuiTheme_SoDark_AccentYellow, /* original C++ signature */ + so_dark_accent_yellow = enum.auto() # (= 13) + # ImGuiTheme_SoDark_AccentRed, /* original C++ signature */ + so_dark_accent_red = enum.auto() # (= 14) + # ImGuiTheme_BlackIsBlack, /* original C++ signature */ + black_is_black = enum.auto() # (= 15) + # ImGuiTheme_WhiteIsWhite, /* original C++ signature */ + white_is_white = enum.auto() # (= 16) + # ImGuiTheme_Count /* original C++ signature */ + # } + count = enum.auto() # (= 17) + +# const char* ImGuiTheme_Name(ImGuiTheme_ theme); /* original C++ signature */ +def imgui_theme_name(theme: ImGuiTheme_) -> str: + pass + +# ImGuiTheme_ ImGuiTheme_FromName(const char* themeName); /* original C++ signature */ +def imgui_theme_from_name(theme_name: str) -> ImGuiTheme_: + pass + +# ImGuiStyle ThemeToStyle(ImGuiTheme_ theme); /* original C++ signature */ +def theme_to_style(theme: ImGuiTheme_) -> ImGuiStyle: + pass + +# void ApplyTheme(ImGuiTheme_ theme); /* original C++ signature */ +def apply_theme(theme: ImGuiTheme_) -> None: + pass + +class ImGuiThemeTweaks: + # float Rounding = -1.f; /* original C++ signature */ + # Common rounding for widgets. If < 0, this is ignored. + rounding: float = -1.0 + # float RoundingScrollbarRatio = 4.f; /* original C++ signature */ + # If rounding is applied, scrollbar rounding needs to be adjusted to be visually pleasing in conjunction with other widgets roundings. Only applied if Rounding > 0.) + rounding_scrollbar_ratio: float = 4.0 + # float AlphaMultiplier = -1.f; /* original C++ signature */ + # Change the alpha that will be applied to windows, popups, etc. If < 0, this is ignored. + alpha_multiplier: float = -1.0 + + # float Hue = -1.f; /* original C++ signature */ + # + # HSV Color tweaks + # + # Change the hue of all widgets (gray widgets will remain gray, since their saturation is zero). If < 0, this is ignored. + hue: float = -1.0 + # float SaturationMultiplier = -1.f; /* original C++ signature */ + # Multiply the saturation of all widgets (gray widgets will remain gray, since their saturation is zero). If < 0, this is ignored. + saturation_multiplier: float = -1.0 + # float ValueMultiplierFront = -1.f; /* original C++ signature */ + # Multiply the value (luminance) of all front widgets. If < 0, this is ignored. + value_multiplier_front: float = -1.0 + # float ValueMultiplierBg = -1.f; /* original C++ signature */ + # Multiply the value (luminance) of all backgrounds. If < 0, this is ignored. + value_multiplier_bg: float = -1.0 + # float ValueMultiplierText = -1.f; /* original C++ signature */ + # Multiply the value (luminance) of text. If < 0, this is ignored. + value_multiplier_text: float = -1.0 + # float ValueMultiplierFrameBg = -1.f; /* original C++ signature */ + # Multiply the value (luminance) of FrameBg. If < 0, this is ignored. + # (Background of checkbox, radio button, plot, slider, text input) + value_multiplier_frame_bg: float = -1.0 + + # ImGuiThemeTweaks() {} /* original C++ signature */ + def __init__(self) -> None: + pass + +class ImGuiTweakedTheme: + # ImGuiTheme_ Theme = ImGuiTheme_DarculaDarker; /* original C++ signature */ + theme: ImGuiTheme_ = ImGuiTheme_.darcula_darker + # ImGuiThemeTweaks Tweaks = ImGuiThemeTweaks(); /* original C++ signature */ + tweaks: ImGuiThemeTweaks = ImGuiThemeTweaks() + # ImGuiTweakedTheme(ImGuiTheme_ Theme = ImGuiTheme_DarculaDarker, ImGuiThemeTweaks Tweaks = ImGuiThemeTweaks()); /* original C++ signature */ + def __init__( + self, + theme: ImGuiTheme_ = ImGuiTheme_.darcula_darker, + tweaks: ImGuiThemeTweaks = ImGuiThemeTweaks(), + ) -> None: + """Auto-generated default constructor with named params""" + pass + +# ImGuiStyle TweakedThemeThemeToStyle(const ImGuiTweakedTheme& tweaked_theme); /* original C++ signature */ +def tweaked_theme_theme_to_style(tweaked_theme: ImGuiTweakedTheme) -> ImGuiStyle: + pass + +# void ApplyTweakedTheme(const ImGuiTweakedTheme& tweaked_theme); /* original C++ signature */ +def apply_tweaked_theme(tweaked_theme: ImGuiTweakedTheme) -> None: + pass + +# bool ShowThemeTweakGui(ImGuiTweakedTheme *tweaked_theme); /* original C++ signature */ +def show_theme_tweak_gui(tweaked_theme: ImGuiTweakedTheme) -> bool: + """Show the theme selection listbox, the theme tweak widgets, as well as ImGui::ShowStyleEditor. Returns True if modified (Warning, when using ShowStyleEditor, no info about modification is transmitted)""" + pass + +# Some tweakable themes +# ImGuiStyle SoDark(float hue); /* original C++ signature */ +def so_dark(hue: float) -> ImGuiStyle: + pass + +# ImGuiStyle ShadesOfGray(float rounding=0.f, float value_multiplier_front=1.f, float value_multiplier_bg=1.f); /* original C++ signature */ +def shades_of_gray( + rounding: float = 0.0, + value_multiplier_front: float = 1.0, + value_multiplier_bg: float = 1.0, +) -> ImGuiStyle: + pass + +# ImGuiStyle Darcula( /* original C++ signature */ +# float rounding=1.f, +# float hue=-1.f, +# float saturation_multiplier=1.f, +# float value_multiplier_front=1.f, +# float value_multiplier_bg=1.f, +# float alpha_bg_transparency=1.f +# ); +def darcula( + rounding: float = 1.0, + hue: float = -1.0, + saturation_multiplier: float = 1.0, + value_multiplier_front: float = 1.0, + value_multiplier_bg: float = 1.0, + alpha_bg_transparency: float = 1.0, +) -> ImGuiStyle: + pass + +# namespace ImGuiTheme +# ////////////////////////////////////////////////////////////////////////////////////////////////////////////// # hello_imgui/runner_params.h included by hello_imgui.h // # ////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -482,260 +792,94 @@ class WindowGeometry: ) -> None: """Auto-generated default constructor with named params""" pass - -class EdgeInsets: - """If there is a notch on the iPhone, you should not display inside these insets""" - - # double top = 0.; /* original C++ signature */ - top: float = 0.0 # Typically around 47 - # double left = 0.; /* original C++ signature */ - left: float = 0.0 # Typically 0 - # double bottom = 0.; /* original C++ signature */ - bottom: float = 0.0 # Typically around 34 - # double right = 0.; /* original C++ signature */ - right: float = 0.0 # Typically 0 - # EdgeInsets(double top = 0., double left = 0., double bottom = 0., double right = 0.); /* original C++ signature */ - def __init__( - self, - top: float = 0.0, - left: float = 0.0, - bottom: float = 0.0, - right: float = 0.0, - ) -> None: - """Auto-generated default constructor with named params""" - pass - -class AppWindowParams: - """* - @@md#AppWindowParams - - __AppWindowParams__ is a struct that defines the application window display params. - See [doc_src/hello_imgui_diagram.png](https://raw.githubusercontent.com/pthom/hello_imgui/master/src/hello_imgui/doc_src/hello_imgui_diagram.png) - for details. - - Members: - * `windowTitle`: _string, default=""_. Title of the application window - * `windowGeometry`: _WindowGeometry_ - Enables to precisely set the window geometry (position, monitor, size, full screen, fake full screen, etc.) - _Note: on a mobile device, the application will always be full screen._ - * `restorePreviousGeometry`: _bool, default=false_. - If True, then save & restore windowGeometry from last run (the geometry will be written in imgui_app_window.ini) - * `borderless`: _bool, default = false_. Should the window have borders. This is taken into account at - creation. - * `resizable`: _bool, default = false_. Should the window have borders. This is taken into account at - creation. - * `hidden`: _bool, default = false_. Should the window be hidden. This is taken into account dynamically (you - can show/hide the window with this). Full screen windows cannot be hidden.@@md - * `edgeInsets`: _EdgeInsets_. iOS only, out values filled by HelloImGui: - if there is a notch on the iPhone, you should not display inside these insets. - HelloImGui handles this automatically, if handleEdgeInsets is True and - if runnerParams.imGuiWindowParams.defaultImGuiWindowType is not NoDefaultWindow. - (warning, these values are updated only after a few frames, they are typically 0 for the first 4 frames) - * `handleEdgeInsets`: _bool, default = true_. iOS only, if True, HelloImGui will handle the edgeInsets. - * - """ - - # std::string windowTitle; /* original C++ signature */ - window_title: str - - # WindowGeometry windowGeometry; /* original C++ signature */ - window_geometry: WindowGeometry - - # bool restorePreviousGeometry = false; /* original C++ signature */ - # if True, then save & restore from last run - restore_previous_geometry: bool = False - - # bool borderless = false; /* original C++ signature */ - borderless: bool = False - # bool resizable = true; /* original C++ signature */ - resizable: bool = True - # bool hidden = false; /* original C++ signature */ - hidden: bool = False - - # EdgeInsets edgeInsets; /* original C++ signature */ - edge_insets: EdgeInsets - # bool handleEdgeInsets = true; /* original C++ signature */ - handle_edge_insets: bool = True - # AppWindowParams(std::string windowTitle = std::string(), WindowGeometry windowGeometry = WindowGeometry(), bool restorePreviousGeometry = false, bool borderless = false, bool resizable = true, bool hidden = false, EdgeInsets edgeInsets = EdgeInsets(), bool handleEdgeInsets = true); /* original C++ signature */ - def __init__( - self, - window_title: str = "", - window_geometry: WindowGeometry = WindowGeometry(), - restore_previous_geometry: bool = False, - borderless: bool = False, - resizable: bool = True, - hidden: bool = False, - edge_insets: EdgeInsets = EdgeInsets(), - handle_edge_insets: bool = True, - ) -> None: - """Auto-generated default constructor with named params""" - pass - -# //////////////////////////////////////////////////////////////////////////////////////////////////////////////// -# hello_imgui/imgui_theme.h included by hello_imgui/imgui_window_params.h // -# ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -# -# Theme tweak utilities for ImGui. -# Reuse and adaptation of imgui_theme.h and imgui_theme.cpp file is granted for other projects, -# provided the origin of those files is stated in the copied version -# Some themes were adapted by themes posted by ImGui users at https://github.com/ocornut/imgui/issues/707 -# - -class ImGuiTheme_(enum.Enum): - # ImGuiTheme_ImGuiColorsClassic = 0, /* original C++ signature */ - imgui_colors_classic = enum.auto() # (= 0) - # ImGuiTheme_ImGuiColorsDark, /* original C++ signature */ - imgui_colors_dark = enum.auto() # (= 1) - # ImGuiTheme_ImGuiColorsLight, /* original C++ signature */ - imgui_colors_light = enum.auto() # (= 2) - # ImGuiTheme_MaterialFlat, /* original C++ signature */ - material_flat = enum.auto() # (= 3) - # ImGuiTheme_PhotoshopStyle, /* original C++ signature */ - photoshop_style = enum.auto() # (= 4) - # ImGuiTheme_GrayVariations, /* original C++ signature */ - gray_variations = enum.auto() # (= 5) - # ImGuiTheme_GrayVariations_Darker, /* original C++ signature */ - gray_variations_darker = enum.auto() # (= 6) - # ImGuiTheme_MicrosoftStyle, /* original C++ signature */ - microsoft_style = enum.auto() # (= 7) - # ImGuiTheme_Cherry, /* original C++ signature */ - cherry = enum.auto() # (= 8) - # ImGuiTheme_Darcula, /* original C++ signature */ - darcula = enum.auto() # (= 9) - # ImGuiTheme_DarculaDarker, /* original C++ signature */ - darcula_darker = enum.auto() # (= 10) - # ImGuiTheme_LightRounded, /* original C++ signature */ - light_rounded = enum.auto() # (= 11) - # ImGuiTheme_SoDark_AccentBlue, /* original C++ signature */ - so_dark_accent_blue = enum.auto() # (= 12) - # ImGuiTheme_SoDark_AccentYellow, /* original C++ signature */ - so_dark_accent_yellow = enum.auto() # (= 13) - # ImGuiTheme_SoDark_AccentRed, /* original C++ signature */ - so_dark_accent_red = enum.auto() # (= 14) - # ImGuiTheme_BlackIsBlack, /* original C++ signature */ - black_is_black = enum.auto() # (= 15) - # ImGuiTheme_WhiteIsWhite, /* original C++ signature */ - white_is_white = enum.auto() # (= 16) - # ImGuiTheme_Count /* original C++ signature */ - # } - count = enum.auto() # (= 17) - -# const char* ImGuiTheme_Name(ImGuiTheme_ theme); /* original C++ signature */ -def imgui_theme_name(theme: ImGuiTheme_) -> str: - pass - -# ImGuiTheme_ ImGuiTheme_FromName(const char* themeName); /* original C++ signature */ -def imgui_theme_from_name(theme_name: str) -> ImGuiTheme_: - pass - -# ImGuiStyle ThemeToStyle(ImGuiTheme_ theme); /* original C++ signature */ -def theme_to_style(theme: ImGuiTheme_) -> ImGuiStyle: - pass - -# void ApplyTheme(ImGuiTheme_ theme); /* original C++ signature */ -def apply_theme(theme: ImGuiTheme_) -> None: - pass - -class ImGuiThemeTweaks: - # float Rounding = -1.f; /* original C++ signature */ - # Common rounding for widgets. If < 0, this is ignored. - rounding: float = -1.0 - # float RoundingScrollbarRatio = 4.f; /* original C++ signature */ - # If rounding is applied, scrollbar rounding needs to be adjusted to be visually pleasing in conjunction with other widgets roundings. Only applied if Rounding > 0.) - rounding_scrollbar_ratio: float = 4.0 - # float AlphaMultiplier = -1.f; /* original C++ signature */ - # Change the alpha that will be applied to windows, popups, etc. If < 0, this is ignored. - alpha_multiplier: float = -1.0 - - # float Hue = -1.f; /* original C++ signature */ - # - # HSV Color tweaks - # - # Change the hue of all widgets (gray widgets will remain gray, since their saturation is zero). If < 0, this is ignored. - hue: float = -1.0 - # float SaturationMultiplier = -1.f; /* original C++ signature */ - # Multiply the saturation of all widgets (gray widgets will remain gray, since their saturation is zero). If < 0, this is ignored. - saturation_multiplier: float = -1.0 - # float ValueMultiplierFront = -1.f; /* original C++ signature */ - # Multiply the value (luminance) of all front widgets. If < 0, this is ignored. - value_multiplier_front: float = -1.0 - # float ValueMultiplierBg = -1.f; /* original C++ signature */ - # Multiply the value (luminance) of all backgrounds. If < 0, this is ignored. - value_multiplier_bg: float = -1.0 - # float ValueMultiplierText = -1.f; /* original C++ signature */ - # Multiply the value (luminance) of text. If < 0, this is ignored. - value_multiplier_text: float = -1.0 - # float ValueMultiplierFrameBg = -1.f; /* original C++ signature */ - # Multiply the value (luminance) of FrameBg. If < 0, this is ignored. - # (Background of checkbox, radio button, plot, slider, text input) - value_multiplier_frame_bg: float = -1.0 - - # ImGuiThemeTweaks() {} /* original C++ signature */ - def __init__(self) -> None: - pass - -class ImGuiTweakedTheme: - # ImGuiTheme_ Theme = ImGuiTheme_DarculaDarker; /* original C++ signature */ - theme: ImGuiTheme_ = ImGuiTheme_.darcula_darker - # ImGuiThemeTweaks Tweaks = ImGuiThemeTweaks(); /* original C++ signature */ - tweaks: ImGuiThemeTweaks = ImGuiThemeTweaks() - # ImGuiTweakedTheme(ImGuiTheme_ Theme = ImGuiTheme_DarculaDarker, ImGuiThemeTweaks Tweaks = ImGuiThemeTweaks()); /* original C++ signature */ + +class EdgeInsets: + """If there is a notch on the iPhone, you should not display inside these insets""" + + # double top = 0.; /* original C++ signature */ + top: float = 0.0 # Typically around 47 + # double left = 0.; /* original C++ signature */ + left: float = 0.0 # Typically 0 + # double bottom = 0.; /* original C++ signature */ + bottom: float = 0.0 # Typically around 34 + # double right = 0.; /* original C++ signature */ + right: float = 0.0 # Typically 0 + # EdgeInsets(double top = 0., double left = 0., double bottom = 0., double right = 0.); /* original C++ signature */ def __init__( self, - theme: ImGuiTheme_ = ImGuiTheme_.darcula_darker, - tweaks: ImGuiThemeTweaks = ImGuiThemeTweaks(), + top: float = 0.0, + left: float = 0.0, + bottom: float = 0.0, + right: float = 0.0, ) -> None: """Auto-generated default constructor with named params""" pass -# ImGuiStyle TweakedThemeThemeToStyle(const ImGuiTweakedTheme& tweaked_theme); /* original C++ signature */ -def tweaked_theme_theme_to_style(tweaked_theme: ImGuiTweakedTheme) -> ImGuiStyle: - pass +class AppWindowParams: + """* + @@md#AppWindowParams -# void ApplyTweakedTheme(const ImGuiTweakedTheme& tweaked_theme); /* original C++ signature */ -def apply_tweaked_theme(tweaked_theme: ImGuiTweakedTheme) -> None: - pass + __AppWindowParams__ is a struct that defines the application window display params. + See [doc_src/hello_imgui_diagram.png](https://raw.githubusercontent.com/pthom/hello_imgui/master/src/hello_imgui/doc_src/hello_imgui_diagram.png) + for details. -# bool ShowThemeTweakGui(ImGuiTweakedTheme *tweaked_theme); /* original C++ signature */ -def show_theme_tweak_gui(tweaked_theme: ImGuiTweakedTheme) -> bool: - """Show the theme selection listbox, the theme tweak widgets, as well as ImGui::ShowStyleEditor. Returns True if modified (Warning, when using ShowStyleEditor, no info about modification is transmitted)""" - pass + Members: + * `windowTitle`: _string, default=""_. Title of the application window + * `windowGeometry`: _WindowGeometry_ + Enables to precisely set the window geometry (position, monitor, size, full screen, fake full screen, etc.) + _Note: on a mobile device, the application will always be full screen._ + * `restorePreviousGeometry`: _bool, default=false_. + If True, then save & restore windowGeometry from last run (the geometry will be written in imgui_app_window.ini) + * `borderless`: _bool, default = false_. Should the window have borders. This is taken into account at + creation. + * `resizable`: _bool, default = false_. Should the window have borders. This is taken into account at + creation. + * `hidden`: _bool, default = false_. Should the window be hidden. This is taken into account dynamically (you + can show/hide the window with this). Full screen windows cannot be hidden.@@md + * `edgeInsets`: _EdgeInsets_. iOS only, out values filled by HelloImGui: + if there is a notch on the iPhone, you should not display inside these insets. + HelloImGui handles this automatically, if handleEdgeInsets is True and + if runnerParams.imGuiWindowParams.defaultImGuiWindowType is not NoDefaultWindow. + (warning, these values are updated only after a few frames, they are typically 0 for the first 4 frames) + * `handleEdgeInsets`: _bool, default = true_. iOS only, if True, HelloImGui will handle the edgeInsets. + * + """ -# Some tweakable themes -# ImGuiStyle SoDark(float hue); /* original C++ signature */ -def so_dark(hue: float) -> ImGuiStyle: - pass + # std::string windowTitle; /* original C++ signature */ + window_title: str -# ImGuiStyle ShadesOfGray(float rounding=0.f, float value_multiplier_front=1.f, float value_multiplier_bg=1.f); /* original C++ signature */ -def shades_of_gray( - rounding: float = 0.0, - value_multiplier_front: float = 1.0, - value_multiplier_bg: float = 1.0, -) -> ImGuiStyle: - pass + # WindowGeometry windowGeometry; /* original C++ signature */ + window_geometry: WindowGeometry -# ImGuiStyle Darcula( /* original C++ signature */ -# float rounding=1.f, -# float hue=-1.f, -# float saturation_multiplier=1.f, -# float value_multiplier_front=1.f, -# float value_multiplier_bg=1.f, -# float alpha_bg_transparency=1.f -# ); -def darcula( - rounding: float = 1.0, - hue: float = -1.0, - saturation_multiplier: float = 1.0, - value_multiplier_front: float = 1.0, - value_multiplier_bg: float = 1.0, - alpha_bg_transparency: float = 1.0, -) -> ImGuiStyle: - pass + # bool restorePreviousGeometry = false; /* original C++ signature */ + # if True, then save & restore from last run + restore_previous_geometry: bool = False -# //////////////////////////////////////////////////////////////////////////////////////////////////////////////// -# hello_imgui/imgui_window_params.h continued // -# ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + # bool borderless = false; /* original C++ signature */ + borderless: bool = False + # bool resizable = true; /* original C++ signature */ + resizable: bool = True + # bool hidden = false; /* original C++ signature */ + hidden: bool = False + + # EdgeInsets edgeInsets; /* original C++ signature */ + edge_insets: EdgeInsets + # bool handleEdgeInsets = true; /* original C++ signature */ + handle_edge_insets: bool = True + # AppWindowParams(std::string windowTitle = std::string(), WindowGeometry windowGeometry = WindowGeometry(), bool restorePreviousGeometry = false, bool borderless = false, bool resizable = true, bool hidden = false, EdgeInsets edgeInsets = EdgeInsets(), bool handleEdgeInsets = true); /* original C++ signature */ + def __init__( + self, + window_title: str = "", + window_geometry: WindowGeometry = WindowGeometry(), + restore_previous_geometry: bool = False, + borderless: bool = False, + resizable: bool = True, + hidden: bool = False, + edge_insets: EdgeInsets = EdgeInsets(), + handle_edge_insets: bool = True, + ) -> None: + """Auto-generated default constructor with named params""" + pass class DefaultImGuiWindowType(enum.Enum): """* @@ -1535,9 +1679,11 @@ class BackendPointers: * `sdlGlContext`: _void *, default=nullptr_. Pointer to SDL's GlContext (of type `SDL_GLContext`). Only filled if the backend is SDL (or emscripten + sdl) - Note: If using the Metal or Vulkan rendering backend, you can find some interesting pointers inside - `src/hello_imgui/internal/backend_impls/rendering_metal.h` and `src/hello_imgui/internal/backend_impls/rendering_vulkan.h`. - + Note: If using the Metal, Vulkan or DirectX rendering backend, you can find some interesting pointers inside + `src/hello_imgui/internal/backend_impls/rendering_metal.h` + `src/hello_imgui/internal/backend_impls/rendering_vulkan.h` + `src/hello_imgui/internal/backend_impls/rendering_dx11.h` + `src/hello_imgui/internal/backend_impls/rendering_dx12.h` @@md """ @@ -1849,144 +1995,8 @@ class SimpleRunnerParams: """Auto-generated default constructor with named params""" pass -# //////////////////////////////////////////////////////////////////////////////////////////////////////////////// -# hello_imgui/hello_imgui_logger.h included by hello_imgui.h // -# ////////////////////////////////////////////////////////////////////////////////////////////////////////////// -class LogLevel(enum.Enum): - # Debug, /* original C++ signature */ - debug = enum.auto() # (= 0) - # Info, /* original C++ signature */ - info = enum.auto() # (= 1) - # Warning, /* original C++ signature */ - warning = enum.auto() # (= 2) - # Error /* original C++ signature */ - # } - error = enum.auto() # (= 3) - -# void Log(LogLevel level, char const* const format, ...); /* original C++ signature */ -def log(level: LogLevel, format: str) -> None: - pass - -# void LogClear(); /* original C++ signature */ -def log_clear() -> None: - pass - -# void LogGui(ImVec2 size=ImVec2(0.f, 0.f)); /* original C++ signature */ -# } -def log_gui(size: ImVec2 = ImVec2(0.0, 0.0)) -> None: - pass - -# //////////////////////////////////////////////////////////////////////////////////////////////////////////////// -# hello_imgui/dpi_aware.h included by hello_imgui.h // +# namespace HelloImGui # ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -# * -# @@md#Dpi -# -# Special care must be taken in order to correctly handle screen with high DPI (for example, almost all recent laptops screens). -# Otherwise, widgets might be misplaced or too small, and font rendering might be blurry or too small. -# -#### How to position widgets on a window in a Dpi independent way -# -# Using ImVec2 with fixed values is *almost always a bad idea* if you intend your application to be used on high DPI screens. -# Instead you can: -# * either multiply those values by ImGui::GetFontSize() -# * or use `HelloImGui::EmToVec2(x, y)` which will do this multiplication for you. Em stand for the `em` measurements, -# as used in CSS: 1em simply correspond to the current font height. -# -# -#### How to load fonts for a crisp font rendering and a correct size -# -# HelloImGui provides `HelloImGui::DpiFontLoadingFactor()` which corresponds to: -# `DpiWindowSizeFactor() * 1. / ImGui::GetIO().FontGlobalScale` -# where DpiWindowSizeFactor() is equal to `CurrentScreenPixelPerInch / 96` under windows and linux, 1 under macOS -# -# ==> When loading fonts, multiply their size by this factor! -# -#### More details on DPI handling with different OS and backends -# -# Let's consider screen whose physical pixel resolution is 3600x2000, but which will displayed with a scaling factor of 200%, -# so that widgets do not look too small on it. -# -# The way it is handled depends on the OS: -# - On MacOS, the screen will be seen as having a resolution of 1800x1000, and the OS handles the resizing by itself. -# - On Linux, and on Windows if the application is DPI aware, the screen will be seen as having a resolution of 3600x2000. -# - On Windows if the application is not DPI aware, the screen will be seen as having a resolution of 1800x1000 -# -# By default, if using the glfw backend, applications will be Dpi aware under windows. -# Sdl applications are normally not Dpi aware. However HelloImGui makes them Dpi aware when using the sdl backend. -# -# -#### HelloImGui Dpi aware C++ API -# -# `HelloImGui::EmSize()` (C++) and `hello_imgui.em_size()` (Python) return the visible font size on the screen. -# For reproducible results, even on HighDPI screens, always scale your widgets and windows relatively to this size. -# It is somewhat comparable to the [em CSS Unit](https://lyty.dev/css/css-unit.html). -# -# `HelloImGui::EmToVec2(x, y)` (C++) and `hello_imgui.em_to_vec2(x,y)` (Python) return an ImVec2 that you can use -# to size or place your widgets in a DPI independent way. -# -# `HelloImGui::EmSize(nbLines)` (C++) and `hello_imgui.em_size(nb_lines)` (Python) return a size corresponding to nbLines text lines -# -# `HelloImGui::DpiFontLoadingFactor()` (C++) and `hello_imgui.dpi_font_loading_factor()` (Python) return a factor by -# which you shall multiply your font sizes when loading fonts manually with _ImGui::GetIO().Fonts->AddFont..._ -# HelloImGui::LoadFontTTF does this by default. -# -# `HelloImGui::ImGuiDefaultFontGlobalScale()` (C++) and `hello_imgui.imgui_default_font_global_scale()` (Python) returns the -# default value that should be stored inside `ImGui::GetIO().FontGlobalScale`. -# Under windows and linux, this is always 1: no rescaling should be done by ImGui. Under macOS and emscripten, -# this can be < 1 (for example it will be 0.5 if the dpi scaling is 200%) -# @@md -# - -# float EmSize(); /* original C++ signature */ -@overload -def em_size() -> float: - """__HelloImGui::EmSize()__ returns the visible font size on the screen. For good results on HighDPI screens, always scale your - widgets and windows relatively to this size. - It is somewhat comparable to the [em CSS Unit](https://lyty.dev/css/css-unit.html). - EmSize() = ImGui::GetFontSize() - """ - pass - -# float EmSize(float nbLines); /* original C++ signature */ -@overload -def em_size(nb_lines: float) -> float: - """__HelloImGui::EmSize(nbLines)__ returns a size corresponding to nbLines text lines""" - pass - -# __HelloImGui::EmToVec2()__ returns an ImVec2 that you can use to size or place your widgets in a DPI independent way -# ImVec2 EmToVec2(float x, float y); /* original C++ signature */ -@overload -def em_to_vec2(x: float, y: float) -> ImVec2: - pass - -# ImVec2 EmToVec2(ImVec2 v); /* original C++ signature */ -@overload -def em_to_vec2(v: ImVec2) -> ImVec2: - pass - -# float DpiFontLoadingFactor(); /* original C++ signature */ -def dpi_font_loading_factor() -> float: - """Multiply font sizes by this factor when loading fonts manually with ImGui::GetIO().Fonts->AddFont... - (HelloImGui::LoadFontTTF does this by default) - """ - pass - -# float DpiWindowSizeFactor(); /* original C++ signature */ -def dpi_window_size_factor() -> float: - """DpiWindowSizeFactor() is the factor by which window size should be multiplied to get a similar visible size on different OSes. - It returns ApplicationScreenPixelPerInch / 96 under windows and linux. Under macOS, it will return 1. - """ - pass - -# float ImGuiDefaultFontGlobalScale(); /* original C++ signature */ -# } -def imgui_default_font_global_scale() -> float: - """returns the default value that should be stored inside `ImGui::GetIO().FontGlobalScale`""" - pass - -# //////////////////////////////////////////////////////////////////////////////////////////////////////////////// # hello_imgui.h continued // # ////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/external/hello_imgui/bindings/hello_imgui_amalgamation.h b/external/hello_imgui/bindings/hello_imgui_amalgamation.h index 874b4c5f..2079a9a1 100644 --- a/external/hello_imgui/bindings/hello_imgui_amalgamation.h +++ b/external/hello_imgui/bindings/hello_imgui_amalgamation.h @@ -10,6 +10,96 @@ #endif +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// hello_imgui/dpi_aware.h included by hello_imgui.h // +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#include "imgui.h" + +/** +@@md#Dpi + +Special care must be taken in order to correctly handle screen with high DPI (for example, almost all recent laptops screens). +Otherwise, widgets might be misplaced or too small, and font rendering might be blurry or too small. + +### How to position widgets on a window in a Dpi independent way + +Using ImVec2 with fixed values is *almost always a bad idea* if you intend your application to be used on high DPI screens. +Instead you can: +* either multiply those values by ImGui::GetFontSize() +* or use `HelloImGui::EmToVec2(x, y)` which will do this multiplication for you. Em stand for the `em` measurements, + as used in CSS: 1em simply correspond to the current font height. + + +### How to load fonts for a crisp font rendering and a correct size + +HelloImGui provides `HelloImGui::DpiFontLoadingFactor()` which corresponds to: + `DpiWindowSizeFactor() * 1.f / ImGui::GetIO().FontGlobalScale` + where DpiWindowSizeFactor() is equal to `CurrentScreenPixelPerInch / 96` under windows and linux, 1 under macOS + +==> When loading fonts, multiply their size by this factor! + +### More details on DPI handling with different OS and backends + +Let's consider screen whose physical pixel resolution is 3600x2000, but which will displayed with a scaling factor of 200%, + so that widgets do not look too small on it. + +The way it is handled depends on the OS: +- On MacOS, the screen will be seen as having a resolution of 1800x1000, and the OS handles the resizing by itself. +- On Linux, and on Windows if the application is DPI aware, the screen will be seen as having a resolution of 3600x2000. +- On Windows if the application is not DPI aware, the screen will be seen as having a resolution of 1800x1000 + +By default, if using the glfw backend, applications will be Dpi aware under windows. +Sdl applications are normally not Dpi aware. However HelloImGui makes them Dpi aware when using the sdl backend. + + +### HelloImGui Dpi aware C++ API + +`HelloImGui::EmSize()` (C++) and `hello_imgui.em_size()` (Python) return the visible font size on the screen. +For reproducible results, even on HighDPI screens, always scale your widgets and windows relatively to this size. + It is somewhat comparable to the [em CSS Unit](https://lyty.dev/css/css-unit.html). + +`HelloImGui::EmToVec2(x, y)` (C++) and `hello_imgui.em_to_vec2(x,y)` (Python) return an ImVec2 that you can use + to size or place your widgets in a DPI independent way. + +`HelloImGui::EmSize(nbLines)` (C++) and `hello_imgui.em_size(nb_lines)` (Python) return a size corresponding to nbLines text lines + +`HelloImGui::DpiFontLoadingFactor()` (C++) and `hello_imgui.dpi_font_loading_factor()` (Python) return a factor by + which you shall multiply your font sizes when loading fonts manually with _ImGui::GetIO().Fonts->AddFont..._ + HelloImGui::LoadFontTTF does this by default. + +`HelloImGui::ImGuiDefaultFontGlobalScale()` (C++) and `hello_imgui.imgui_default_font_global_scale()` (Python) returns the + default value that should be stored inside `ImGui::GetIO().FontGlobalScale`. + Under windows and linux, this is always 1: no rescaling should be done by ImGui. Under macOS and emscripten, + this can be < 1 (for example it will be 0.5 if the dpi scaling is 200%) +@@md +*/ + +namespace HelloImGui +{ + // __HelloImGui::EmSize()__ returns the visible font size on the screen. For good results on HighDPI screens, always scale your + // widgets and windows relatively to this size. + // It is somewhat comparable to the [em CSS Unit](https://lyty.dev/css/css-unit.html). + // EmSize() = ImGui::GetFontSize() + float EmSize(); + + // __HelloImGui::EmSize(nbLines)__ returns a size corresponding to nbLines text lines + float EmSize(float nbLines); + + // __HelloImGui::EmToVec2()__ returns an ImVec2 that you can use to size or place your widgets in a DPI independent way + ImVec2 EmToVec2(float x, float y); + ImVec2 EmToVec2(ImVec2 v); + + // Multiply font sizes by this factor when loading fonts manually with ImGui::GetIO().Fonts->AddFont... + // (HelloImGui::LoadFontTTF does this by default) + float DpiFontLoadingFactor(); + + // DpiWindowSizeFactor() is the factor by which window size should be multiplied to get a similar visible size on different OSes. + // It returns ApplicationScreenPixelPerInch / 96 under windows and linux. Under macOS, it will return 1. + float DpiWindowSizeFactor(); + + // returns the default value that should be stored inside `ImGui::GetIO().FontGlobalScale` + float ImGuiDefaultFontGlobalScale(); +} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // hello_imgui/hello_imgui_assets.h included by hello_imgui.h // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -105,7 +195,6 @@ void overrideAssetsFolder(const char* folder); // synonym ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include -#include "imgui.h" #define HIMG_ERROR(msg) \ @@ -139,6 +228,35 @@ void overrideAssetsFolder(const char* folder); // synonym #define HIMG_LOG_POINTER(value) {} #endif +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// hello_imgui/hello_imgui_logger.h included by hello_imgui.h // +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/** +@@md#HelloImGui::Log + +HelloImGui provides a simple Log utility that is able to collect message and display them with a specific widget. + +* __HelloImGui::Log(LogLevel level, char const* const format, ... )__ will log a message (printf like format) +* __HelloImGui::LogClear()__ will clear the Log list +* __HelloImGui::LogGui()__ will display the Log widget + +@@md +*/ +namespace HelloImGui +{ + enum class LogLevel + { + Debug, + Info, + Warning, + Error + }; + + void Log(LogLevel level, char const* const format, ...); + void LogClear(); + void LogGui(ImVec2 size=ImVec2(0.f, 0.f)); +} + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // hello_imgui/icons_font_awesome.h included by hello_imgui.h // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1111,54 +1229,6 @@ void overrideAssetsFolder(const char* folder); // synonym #define ICON_FA_CHEVRON_UP "\xEF\x81\xB7" #define ICON_FA_HAND_SPOCK "\xEF\x89\x99" #define ICON_FA_HAND_POINT_UP "\xEF\x82\xA6" -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// hello_imgui/image_gl.h included by hello_imgui.h // -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef HELLOIMGUI_HAS_OPENGL -#include - -/** -@@md#HelloImGui::ImageGl - - Image loading utilities, based on stb_image. They work *only with OpenGL backends*. - - * `ImageGl::ImageGlPtr FactorImage(const char *assetPath)`: will load an image from an asset - and return a unique_ptr, which you can display with the Draw() or DrawButton() methods. - * `ImageGl::Draw(...)` and `ImageGl::DrawButton(...)` will draw the image. They have the same - behavior as ImGui::Image (except that the size can be inferred from the loaded image size) - - _Note: Since ImageGl is not copiable, it has a private constructor; and you should use it via ImageGlPtr_ - ```cpp - using ImageGlPtr = std::unique_ptr; - ``` - -@@md -*/ -namespace HelloImGui -{ -struct ImageGl; -using ImageGlPtr = std::unique_ptr; - -struct ImageGl -{ -private: - ImageGl(const char *assetPath); -public: - static ImageGlPtr FactorImage(const char *assetPath); - ~ImageGl(); - - void Draw(const ImVec2& size = ImVec2(0, 0), const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0)); - bool DrawButton(const ImVec2& size = ImVec2(0, 0), const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding - - ImVec2 imageSize; - ImTextureID imTextureId; -}; - - -} -#endif // #ifdef HELLOIMGUI_HAS_OPENGL - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // hello_imgui/image_from_asset.h included by hello_imgui.h // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1169,6 +1239,12 @@ struct ImageGl * `HelloImGui::ImageFromAsset(const char *assetPath, size, ...)`: will display a static image from the assets. * `bool HelloImGui::ImageButtonFromAsset(const char *assetPath, size, ...)`: will display a button using an image from the assets. * `ImTextureID HelloImGui::ImTextureIdFromAsset(const char *assetPath)`: will return a texture ID for an image loaded from the assets. +* `ImVec2 HelloImGui::ImageSizeFromAsset(const char *assetPath)`: will return the size of an image loaded from the assets. +* `ImVec2 HelloImGui::ImageProportionalSize(const ImVec2& askedSize, const ImVec2& imageSize)`: + Will return the displayed size of an image. + if askedSize.x or askedSize.y is 0, then the corresponding dimension will be computed from the image size, keeping the aspect ratio. + if askedSize.x>0 and askedSize.y> 0, then the image will be scaled to fit exactly the askedSize, thus potentially changing the aspect ratio. + Note: this function is used internally by ImageFromAsset and ImageButtonFromAsset, so you don't need to call it directly. Images are loaded when first displayed, and then cached (they will be freed just before the application exits). @@ -1186,8 +1262,6 @@ then, you can display "my_image.jpg", using: HelloImGui::ImageFromAsset("my_image.jpg"); ``` -*Note: HelloImGui::ImageFromAsset only works with OpenGL backends. It will throw an exception on other backends* - @@md */ @@ -1196,6 +1270,8 @@ namespace HelloImGui void ImageFromAsset(const char *assetPath, const ImVec2& size = ImVec2(0, 0), const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0)); bool ImageButtonFromAsset(const char *assetPath, const ImVec2& size = ImVec2(0, 0), const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); ImTextureID ImTextureIdFromAsset(const char *assetPath); + ImVec2 ImageSizeFromAsset(const char *assetPath); + ImVec2 ImageProportionalSize(const ImVec2& askedSize, const ImVec2& imageSize); namespace internal { @@ -1203,6 +1279,107 @@ namespace HelloImGui } } +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// hello_imgui.h continued // +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// #include "hello_imgui/image_gl_deprecated.h" + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// hello_imgui/imgui_theme.h included by hello_imgui.h // +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// +// Theme tweak utilities for ImGui. +// Reuse and adaptation of imgui_theme.h and imgui_theme.cpp file is granted for other projects, +// provided the origin of those files is stated in the copied version +// Some themes were adapted by themes posted by ImGui users at https://github.com/ocornut/imgui/issues/707 +// + +namespace ImGuiTheme +{ + enum ImGuiTheme_ + { + ImGuiTheme_ImGuiColorsClassic = 0, + ImGuiTheme_ImGuiColorsDark, + ImGuiTheme_ImGuiColorsLight, + ImGuiTheme_MaterialFlat, + ImGuiTheme_PhotoshopStyle, + ImGuiTheme_GrayVariations, + ImGuiTheme_GrayVariations_Darker, + ImGuiTheme_MicrosoftStyle, + ImGuiTheme_Cherry, + ImGuiTheme_Darcula, + ImGuiTheme_DarculaDarker, + ImGuiTheme_LightRounded, + ImGuiTheme_SoDark_AccentBlue, + ImGuiTheme_SoDark_AccentYellow, + ImGuiTheme_SoDark_AccentRed, + ImGuiTheme_BlackIsBlack, + ImGuiTheme_WhiteIsWhite, + ImGuiTheme_Count + }; + const char* ImGuiTheme_Name(ImGuiTheme_ theme); + ImGuiTheme_ ImGuiTheme_FromName(const char* themeName); + ImGuiStyle ThemeToStyle(ImGuiTheme_ theme); + void ApplyTheme(ImGuiTheme_ theme); + + + struct ImGuiThemeTweaks + { + // Common rounding for widgets. If < 0, this is ignored. + float Rounding = -1.f; + // If rounding is applied, scrollbar rounding needs to be adjusted to be visually pleasing in conjunction with other widgets roundings. Only applied if Rounding > 0.f) + float RoundingScrollbarRatio = 4.f; + // Change the alpha that will be applied to windows, popups, etc. If < 0, this is ignored. + float AlphaMultiplier = -1.f; + + // + // HSV Color tweaks + // + // Change the hue of all widgets (gray widgets will remain gray, since their saturation is zero). If < 0, this is ignored. + float Hue = -1.f; + // Multiply the saturation of all widgets (gray widgets will remain gray, since their saturation is zero). If < 0, this is ignored. + float SaturationMultiplier = -1.f; + // Multiply the value (luminance) of all front widgets. If < 0, this is ignored. + float ValueMultiplierFront = -1.f; + // Multiply the value (luminance) of all backgrounds. If < 0, this is ignored. + float ValueMultiplierBg = -1.f; + // Multiply the value (luminance) of text. If < 0, this is ignored. + float ValueMultiplierText = -1.f; + // Multiply the value (luminance) of FrameBg. If < 0, this is ignored. + // (Background of checkbox, radio button, plot, slider, text input) + float ValueMultiplierFrameBg = -1.f; + + ImGuiThemeTweaks() {} + }; + + struct ImGuiTweakedTheme + { + ImGuiTheme_ Theme = ImGuiTheme_DarculaDarker; + ImGuiThemeTweaks Tweaks = ImGuiThemeTweaks(); + }; + + ImGuiStyle TweakedThemeThemeToStyle(const ImGuiTweakedTheme& tweaked_theme); + void ApplyTweakedTheme(const ImGuiTweakedTheme& tweaked_theme); + + // Show the theme selection listbox, the theme tweak widgets, as well as ImGui::ShowStyleEditor. Returns true if modified (Warning, when using ShowStyleEditor, no info about modification is transmitted) + bool ShowThemeTweakGui(ImGuiTweakedTheme *tweaked_theme); + + // Some tweakable themes + ImGuiStyle SoDark(float hue); + ImGuiStyle ShadesOfGray(float rounding=0.f, float value_multiplier_front=1.f, float value_multiplier_bg=1.f); + ImGuiStyle Darcula( + float rounding=1.f, + float hue=-1.f, + float saturation_multiplier=1.f, + float value_multiplier_front=1.f, + float value_multiplier_bg=1.f, + float alpha_bg_transparency=1.f + ); + + +} // namespace ImGuiTheme ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // hello_imgui/runner_params.h included by hello_imgui.h // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1457,106 +1634,6 @@ struct AppWindowParams ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// hello_imgui/imgui_theme.h included by hello_imgui/imgui_window_params.h // -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// -// Theme tweak utilities for ImGui. -// Reuse and adaptation of imgui_theme.h and imgui_theme.cpp file is granted for other projects, -// provided the origin of those files is stated in the copied version -// Some themes were adapted by themes posted by ImGui users at https://github.com/ocornut/imgui/issues/707 -// - -namespace ImGuiTheme -{ - enum ImGuiTheme_ - { - ImGuiTheme_ImGuiColorsClassic = 0, - ImGuiTheme_ImGuiColorsDark, - ImGuiTheme_ImGuiColorsLight, - ImGuiTheme_MaterialFlat, - ImGuiTheme_PhotoshopStyle, - ImGuiTheme_GrayVariations, - ImGuiTheme_GrayVariations_Darker, - ImGuiTheme_MicrosoftStyle, - ImGuiTheme_Cherry, - ImGuiTheme_Darcula, - ImGuiTheme_DarculaDarker, - ImGuiTheme_LightRounded, - ImGuiTheme_SoDark_AccentBlue, - ImGuiTheme_SoDark_AccentYellow, - ImGuiTheme_SoDark_AccentRed, - ImGuiTheme_BlackIsBlack, - ImGuiTheme_WhiteIsWhite, - ImGuiTheme_Count - }; - const char* ImGuiTheme_Name(ImGuiTheme_ theme); - ImGuiTheme_ ImGuiTheme_FromName(const char* themeName); - ImGuiStyle ThemeToStyle(ImGuiTheme_ theme); - void ApplyTheme(ImGuiTheme_ theme); - - - struct ImGuiThemeTweaks - { - // Common rounding for widgets. If < 0, this is ignored. - float Rounding = -1.f; - // If rounding is applied, scrollbar rounding needs to be adjusted to be visually pleasing in conjunction with other widgets roundings. Only applied if Rounding > 0.f) - float RoundingScrollbarRatio = 4.f; - // Change the alpha that will be applied to windows, popups, etc. If < 0, this is ignored. - float AlphaMultiplier = -1.f; - - // - // HSV Color tweaks - // - // Change the hue of all widgets (gray widgets will remain gray, since their saturation is zero). If < 0, this is ignored. - float Hue = -1.f; - // Multiply the saturation of all widgets (gray widgets will remain gray, since their saturation is zero). If < 0, this is ignored. - float SaturationMultiplier = -1.f; - // Multiply the value (luminance) of all front widgets. If < 0, this is ignored. - float ValueMultiplierFront = -1.f; - // Multiply the value (luminance) of all backgrounds. If < 0, this is ignored. - float ValueMultiplierBg = -1.f; - // Multiply the value (luminance) of text. If < 0, this is ignored. - float ValueMultiplierText = -1.f; - // Multiply the value (luminance) of FrameBg. If < 0, this is ignored. - // (Background of checkbox, radio button, plot, slider, text input) - float ValueMultiplierFrameBg = -1.f; - - ImGuiThemeTweaks() {} - }; - - struct ImGuiTweakedTheme - { - ImGuiTheme_ Theme = ImGuiTheme_DarculaDarker; - ImGuiThemeTweaks Tweaks = ImGuiThemeTweaks(); - }; - - ImGuiStyle TweakedThemeThemeToStyle(const ImGuiTweakedTheme& tweaked_theme); - void ApplyTweakedTheme(const ImGuiTweakedTheme& tweaked_theme); - - // Show the theme selection listbox, the theme tweak widgets, as well as ImGui::ShowStyleEditor. Returns true if modified (Warning, when using ShowStyleEditor, no info about modification is transmitted) - bool ShowThemeTweakGui(ImGuiTweakedTheme *tweaked_theme); - - // Some tweakable themes - ImGuiStyle SoDark(float hue); - ImGuiStyle ShadesOfGray(float rounding=0.f, float value_multiplier_front=1.f, float value_multiplier_bg=1.f); - ImGuiStyle Darcula( - float rounding=1.f, - float hue=-1.f, - float saturation_multiplier=1.f, - float value_multiplier_front=1.f, - float value_multiplier_bg=1.f, - float alpha_bg_transparency=1.f - ); - - -} // namespace ImGuiTheme - - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// hello_imgui/imgui_window_params.h continued // -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// namespace HelloImGui { @@ -2211,9 +2288,11 @@ your application behavior using the selected backend. * `sdlGlContext`: _void *, default=nullptr_. Pointer to SDL's GlContext (of type `SDL_GLContext`). Only filled if the backend is SDL (or emscripten + sdl) -Note: If using the Metal or Vulkan rendering backend, you can find some interesting pointers inside - `src/hello_imgui/internal/backend_impls/rendering_metal.h` and `src/hello_imgui/internal/backend_impls/rendering_vulkan.h`. - +Note: If using the Metal, Vulkan or DirectX rendering backend, you can find some interesting pointers inside + `src/hello_imgui/internal/backend_impls/rendering_metal.h` + `src/hello_imgui/internal/backend_impls/rendering_vulkan.h` + `src/hello_imgui/internal/backend_impls/rendering_dx11.h` + `src/hello_imgui/internal/backend_impls/rendering_dx12.h` @@md */ struct BackendPointers @@ -2443,124 +2522,6 @@ struct SimpleRunnerParams } // namespace HelloImGui ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// hello_imgui/hello_imgui_logger.h included by hello_imgui.h // -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/** -@@md#HelloImGui::Log - -HelloImGui provides a simple Log utility that is able to collect message and display them with a specific widget. - -* __HelloImGui::Log(LogLevel level, char const* const format, ... )__ will log a message (printf like format) -* __HelloImGui::LogClear()__ will clear the Log list -* __HelloImGui::LogGui()__ will display the Log widget - -@@md -*/ -namespace HelloImGui -{ - enum class LogLevel - { - Debug, - Info, - Warning, - Error - }; - - void Log(LogLevel level, char const* const format, ...); - void LogClear(); - void LogGui(ImVec2 size=ImVec2(0.f, 0.f)); -} - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// hello_imgui/dpi_aware.h included by hello_imgui.h // -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -/** -@@md#Dpi - -Special care must be taken in order to correctly handle screen with high DPI (for example, almost all recent laptops screens). -Otherwise, widgets might be misplaced or too small, and font rendering might be blurry or too small. - -### How to position widgets on a window in a Dpi independent way - -Using ImVec2 with fixed values is *almost always a bad idea* if you intend your application to be used on high DPI screens. -Instead you can: -* either multiply those values by ImGui::GetFontSize() -* or use `HelloImGui::EmToVec2(x, y)` which will do this multiplication for you. Em stand for the `em` measurements, - as used in CSS: 1em simply correspond to the current font height. - - -### How to load fonts for a crisp font rendering and a correct size - -HelloImGui provides `HelloImGui::DpiFontLoadingFactor()` which corresponds to: - `DpiWindowSizeFactor() * 1.f / ImGui::GetIO().FontGlobalScale` - where DpiWindowSizeFactor() is equal to `CurrentScreenPixelPerInch / 96` under windows and linux, 1 under macOS - -==> When loading fonts, multiply their size by this factor! - -### More details on DPI handling with different OS and backends - -Let's consider screen whose physical pixel resolution is 3600x2000, but which will displayed with a scaling factor of 200%, - so that widgets do not look too small on it. - -The way it is handled depends on the OS: -- On MacOS, the screen will be seen as having a resolution of 1800x1000, and the OS handles the resizing by itself. -- On Linux, and on Windows if the application is DPI aware, the screen will be seen as having a resolution of 3600x2000. -- On Windows if the application is not DPI aware, the screen will be seen as having a resolution of 1800x1000 - -By default, if using the glfw backend, applications will be Dpi aware under windows. -Sdl applications are normally not Dpi aware. However HelloImGui makes them Dpi aware when using the sdl backend. - - -### HelloImGui Dpi aware C++ API - -`HelloImGui::EmSize()` (C++) and `hello_imgui.em_size()` (Python) return the visible font size on the screen. -For reproducible results, even on HighDPI screens, always scale your widgets and windows relatively to this size. - It is somewhat comparable to the [em CSS Unit](https://lyty.dev/css/css-unit.html). - -`HelloImGui::EmToVec2(x, y)` (C++) and `hello_imgui.em_to_vec2(x,y)` (Python) return an ImVec2 that you can use - to size or place your widgets in a DPI independent way. - -`HelloImGui::EmSize(nbLines)` (C++) and `hello_imgui.em_size(nb_lines)` (Python) return a size corresponding to nbLines text lines - -`HelloImGui::DpiFontLoadingFactor()` (C++) and `hello_imgui.dpi_font_loading_factor()` (Python) return a factor by - which you shall multiply your font sizes when loading fonts manually with _ImGui::GetIO().Fonts->AddFont..._ - HelloImGui::LoadFontTTF does this by default. - -`HelloImGui::ImGuiDefaultFontGlobalScale()` (C++) and `hello_imgui.imgui_default_font_global_scale()` (Python) returns the - default value that should be stored inside `ImGui::GetIO().FontGlobalScale`. - Under windows and linux, this is always 1: no rescaling should be done by ImGui. Under macOS and emscripten, - this can be < 1 (for example it will be 0.5 if the dpi scaling is 200%) -@@md -*/ - -namespace HelloImGui -{ - // __HelloImGui::EmSize()__ returns the visible font size on the screen. For good results on HighDPI screens, always scale your - // widgets and windows relatively to this size. - // It is somewhat comparable to the [em CSS Unit](https://lyty.dev/css/css-unit.html). - // EmSize() = ImGui::GetFontSize() - float EmSize(); - - // __HelloImGui::EmSize(nbLines)__ returns a size corresponding to nbLines text lines - float EmSize(float nbLines); - - // __HelloImGui::EmToVec2()__ returns an ImVec2 that you can use to size or place your widgets in a DPI independent way - ImVec2 EmToVec2(float x, float y); - ImVec2 EmToVec2(ImVec2 v); - - // Multiply font sizes by this factor when loading fonts manually with ImGui::GetIO().Fonts->AddFont... - // (HelloImGui::LoadFontTTF does this by default) - float DpiFontLoadingFactor(); - - // DpiWindowSizeFactor() is the factor by which window size should be multiplied to get a similar visible size on different OSes. - // It returns ApplicationScreenPixelPerInch / 96 under windows and linux. Under macOS, it will return 1. - float DpiWindowSizeFactor(); - - // returns the default value that should be stored inside `ImGui::GetIO().FontGlobalScale` - float ImGuiDefaultFontGlobalScale(); -} -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // hello_imgui.h continued // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/external/hello_imgui/bindings/pybind_hello_imgui.cpp b/external/hello_imgui/bindings/pybind_hello_imgui.cpp index d7d52467..4be85d29 100644 --- a/external/hello_imgui/bindings/pybind_hello_imgui.cpp +++ b/external/hello_imgui/bindings/pybind_hello_imgui.cpp @@ -64,6 +64,30 @@ void py_init_module_hello_imgui(py::module& m) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! AUTOGENERATED CODE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // // Autogenerated code below! Do not edit! //////////////////// //////////////////// + m.def("em_size", + py::overload_cast<>(HelloImGui::EmSize), " __HelloImGui::EmSize()__ returns the visible font size on the screen. For good results on HighDPI screens, always scale your\n widgets and windows relatively to this size.\n It is somewhat comparable to the [em CSS Unit](https://lyty.dev/css/css-unit.html).\n EmSize() = ImGui::GetFontSize()"); + + m.def("em_size", + py::overload_cast(HelloImGui::EmSize), + py::arg("nb_lines"), + "__HelloImGui::EmSize(nbLines)__ returns a size corresponding to nbLines text lines"); + + m.def("em_to_vec2", + py::overload_cast(HelloImGui::EmToVec2), py::arg("x"), py::arg("y")); + + m.def("em_to_vec2", + py::overload_cast(HelloImGui::EmToVec2), py::arg("v")); + + m.def("dpi_font_loading_factor", + HelloImGui::DpiFontLoadingFactor, " Multiply font sizes by this factor when loading fonts manually with ImGui::GetIO().Fonts->AddFont...\n (HelloImGui::LoadFontTTF does this by default)"); + + m.def("dpi_window_size_factor", + HelloImGui::DpiWindowSizeFactor, " DpiWindowSizeFactor() is the factor by which window size should be multiplied to get a similar visible size on different OSes.\n It returns ApplicationScreenPixelPerInch / 96 under windows and linux. Under macOS, it will return 1."); + + m.def("imgui_default_font_global_scale", + HelloImGui::ImGuiDefaultFontGlobalScale, "returns the default value that should be stored inside `ImGui::GetIO().FontGlobalScale`"); + + auto pyClassAssetFileData = py::class_ (m, "AssetFileData", "*\n@@md#LoadAssetFileData\n\n* `AssetFileData LoadAssetFileData(const char *assetPath)` will load an entire asset file into memory.\n This works on all platforms, including android.\n ```cpp\n struct AssetFileData\n {\n None * data = None;\n size_t dataSize = 0;\n };\n ```\n* `FreeAssetFileData(AssetFileData * assetFileData)` will free the memory.\n Note: \"ImGui::GetIO().Fonts->AddFontFromMemoryTTF\" takes ownership of the data\n and will free the memory for you.\n\n@@md\n*") @@ -112,6 +136,31 @@ void py_init_module_hello_imgui(py::module& m) "synonym"); + py::enum_(m, "LogLevel", py::arithmetic(), "") + .value("debug", HelloImGui::LogLevel::Debug, "") + .value("info", HelloImGui::LogLevel::Info, "") + .value("warning", HelloImGui::LogLevel::Warning, "") + .value("error", HelloImGui::LogLevel::Error, ""); + + + m.def("log", + [](HelloImGui::LogLevel level, const char * const format) + { + auto Log_adapt_variadic_format = [](HelloImGui::LogLevel level, const char * const format) + { + HelloImGui::Log(level, "%s", format); + }; + + Log_adapt_variadic_format(level, format); + }, py::arg("level"), py::arg("format")); + + m.def("log_clear", + HelloImGui::LogClear); + + m.def("log_gui", + HelloImGui::LogGui, py::arg("size") = ImVec2(0.f, 0.f)); + + m.def("image_from_asset", HelloImGui::ImageFromAsset, py::arg("asset_path"), py::arg("size") = ImVec2(0, 0), py::arg("uv0") = ImVec2(0, 0), py::arg("uv1") = ImVec2(1,1), py::arg("tint_col") = ImVec4(1,1,1,1), py::arg("border_col") = ImVec4(0,0,0,0)); @@ -121,6 +170,103 @@ void py_init_module_hello_imgui(py::module& m) m.def("im_texture_id_from_asset", HelloImGui::ImTextureIdFromAsset, py::arg("asset_path")); + m.def("image_size_from_asset", + HelloImGui::ImageSizeFromAsset, py::arg("asset_path")); + + m.def("image_proportional_size", + HelloImGui::ImageProportionalSize, py::arg("asked_size"), py::arg("image_size")); + + + py::enum_(m, "ImGuiTheme_", py::arithmetic(), "") + .value("imgui_colors_classic", ImGuiTheme::ImGuiTheme_ImGuiColorsClassic, "") + .value("imgui_colors_dark", ImGuiTheme::ImGuiTheme_ImGuiColorsDark, "") + .value("imgui_colors_light", ImGuiTheme::ImGuiTheme_ImGuiColorsLight, "") + .value("material_flat", ImGuiTheme::ImGuiTheme_MaterialFlat, "") + .value("photoshop_style", ImGuiTheme::ImGuiTheme_PhotoshopStyle, "") + .value("gray_variations", ImGuiTheme::ImGuiTheme_GrayVariations, "") + .value("gray_variations_darker", ImGuiTheme::ImGuiTheme_GrayVariations_Darker, "") + .value("microsoft_style", ImGuiTheme::ImGuiTheme_MicrosoftStyle, "") + .value("cherry", ImGuiTheme::ImGuiTheme_Cherry, "") + .value("darcula", ImGuiTheme::ImGuiTheme_Darcula, "") + .value("darcula_darker", ImGuiTheme::ImGuiTheme_DarculaDarker, "") + .value("light_rounded", ImGuiTheme::ImGuiTheme_LightRounded, "") + .value("so_dark_accent_blue", ImGuiTheme::ImGuiTheme_SoDark_AccentBlue, "") + .value("so_dark_accent_yellow", ImGuiTheme::ImGuiTheme_SoDark_AccentYellow, "") + .value("so_dark_accent_red", ImGuiTheme::ImGuiTheme_SoDark_AccentRed, "") + .value("black_is_black", ImGuiTheme::ImGuiTheme_BlackIsBlack, "") + .value("white_is_white", ImGuiTheme::ImGuiTheme_WhiteIsWhite, "") + .value("count", ImGuiTheme::ImGuiTheme_Count, ""); + + + m.def("imgui_theme_name", + ImGuiTheme::ImGuiTheme_Name, + py::arg("theme"), + pybind11::return_value_policy::reference); + + m.def("imgui_theme_from_name", + ImGuiTheme::ImGuiTheme_FromName, py::arg("theme_name")); + + m.def("theme_to_style", + ImGuiTheme::ThemeToStyle, py::arg("theme")); + + m.def("apply_theme", + ImGuiTheme::ApplyTheme, py::arg("theme")); + + + auto pyClassImGuiThemeTweaks = + py::class_ + (m, "ImGuiThemeTweaks", "") + .def_readwrite("rounding", &ImGuiThemeTweaks::Rounding, "Common rounding for widgets. If < 0, this is ignored.") + .def_readwrite("rounding_scrollbar_ratio", &ImGuiThemeTweaks::RoundingScrollbarRatio, "If rounding is applied, scrollbar rounding needs to be adjusted to be visually pleasing in conjunction with other widgets roundings. Only applied if Rounding > 0.)") + .def_readwrite("alpha_multiplier", &ImGuiThemeTweaks::AlphaMultiplier, "Change the alpha that will be applied to windows, popups, etc. If < 0, this is ignored.") + .def_readwrite("hue", &ImGuiThemeTweaks::Hue, "\n HSV Color tweaks\n\n Change the hue of all widgets (gray widgets will remain gray, since their saturation is zero). If < 0, this is ignored.") + .def_readwrite("saturation_multiplier", &ImGuiThemeTweaks::SaturationMultiplier, "Multiply the saturation of all widgets (gray widgets will remain gray, since their saturation is zero). If < 0, this is ignored.") + .def_readwrite("value_multiplier_front", &ImGuiThemeTweaks::ValueMultiplierFront, "Multiply the value (luminance) of all front widgets. If < 0, this is ignored.") + .def_readwrite("value_multiplier_bg", &ImGuiThemeTweaks::ValueMultiplierBg, "Multiply the value (luminance) of all backgrounds. If < 0, this is ignored.") + .def_readwrite("value_multiplier_text", &ImGuiThemeTweaks::ValueMultiplierText, "Multiply the value (luminance) of text. If < 0, this is ignored.") + .def_readwrite("value_multiplier_frame_bg", &ImGuiThemeTweaks::ValueMultiplierFrameBg, " Multiply the value (luminance) of FrameBg. If < 0, this is ignored.\n (Background of checkbox, radio button, plot, slider, text input)") + .def(py::init<>()) + ; + + + auto pyClassImGuiTweakedTheme = + py::class_ + (m, "ImGuiTweakedTheme", "") + .def(py::init<>([]( + ImGuiTheme::ImGuiTheme_ Theme = ImGuiTheme::ImGuiTheme_DarculaDarker, ImGuiThemeTweaks Tweaks = ImGuiThemeTweaks()) + { + auto r = std::make_unique(); + r->Theme = Theme; + r->Tweaks = Tweaks; + return r; + }) + , py::arg("theme") = ImGuiTheme::ImGuiTheme_DarculaDarker, py::arg("tweaks") = ImGuiThemeTweaks() + ) + .def_readwrite("theme", &ImGuiTweakedTheme::Theme, "") + .def_readwrite("tweaks", &ImGuiTweakedTheme::Tweaks, "") + ; + + + m.def("tweaked_theme_theme_to_style", + ImGuiTheme::TweakedThemeThemeToStyle, py::arg("tweaked_theme")); + + m.def("apply_tweaked_theme", + ImGuiTheme::ApplyTweakedTheme, py::arg("tweaked_theme")); + + m.def("show_theme_tweak_gui", + ImGuiTheme::ShowThemeTweakGui, + py::arg("tweaked_theme"), + "Show the theme selection listbox, the theme tweak widgets, as well as ImGui::ShowStyleEditor. Returns True if modified (Warning, when using ShowStyleEditor, no info about modification is transmitted)"); + + m.def("so_dark", + ImGuiTheme::SoDark, py::arg("hue")); + + m.def("shades_of_gray", + ImGuiTheme::ShadesOfGray, py::arg("rounding") = 0.f, py::arg("value_multiplier_front") = 1.f, py::arg("value_multiplier_bg") = 1.f); + + m.def("darcula", + ImGuiTheme::Darcula, py::arg("rounding") = 1.f, py::arg("hue") = -1.f, py::arg("saturation_multiplier") = 1.f, py::arg("value_multiplier_front") = 1.f, py::arg("value_multiplier_bg") = 1.f, py::arg("alpha_bg_transparency") = 1.f); + auto pyClassScreenBounds = py::class_ @@ -264,97 +410,6 @@ void py_init_module_hello_imgui(py::module& m) ; - py::enum_(m, "ImGuiTheme_", py::arithmetic(), "") - .value("imgui_colors_classic", ImGuiTheme::ImGuiTheme_ImGuiColorsClassic, "") - .value("imgui_colors_dark", ImGuiTheme::ImGuiTheme_ImGuiColorsDark, "") - .value("imgui_colors_light", ImGuiTheme::ImGuiTheme_ImGuiColorsLight, "") - .value("material_flat", ImGuiTheme::ImGuiTheme_MaterialFlat, "") - .value("photoshop_style", ImGuiTheme::ImGuiTheme_PhotoshopStyle, "") - .value("gray_variations", ImGuiTheme::ImGuiTheme_GrayVariations, "") - .value("gray_variations_darker", ImGuiTheme::ImGuiTheme_GrayVariations_Darker, "") - .value("microsoft_style", ImGuiTheme::ImGuiTheme_MicrosoftStyle, "") - .value("cherry", ImGuiTheme::ImGuiTheme_Cherry, "") - .value("darcula", ImGuiTheme::ImGuiTheme_Darcula, "") - .value("darcula_darker", ImGuiTheme::ImGuiTheme_DarculaDarker, "") - .value("light_rounded", ImGuiTheme::ImGuiTheme_LightRounded, "") - .value("so_dark_accent_blue", ImGuiTheme::ImGuiTheme_SoDark_AccentBlue, "") - .value("so_dark_accent_yellow", ImGuiTheme::ImGuiTheme_SoDark_AccentYellow, "") - .value("so_dark_accent_red", ImGuiTheme::ImGuiTheme_SoDark_AccentRed, "") - .value("black_is_black", ImGuiTheme::ImGuiTheme_BlackIsBlack, "") - .value("white_is_white", ImGuiTheme::ImGuiTheme_WhiteIsWhite, "") - .value("count", ImGuiTheme::ImGuiTheme_Count, ""); - - - m.def("imgui_theme_name", - ImGuiTheme::ImGuiTheme_Name, - py::arg("theme"), - pybind11::return_value_policy::reference); - - m.def("imgui_theme_from_name", - ImGuiTheme::ImGuiTheme_FromName, py::arg("theme_name")); - - m.def("theme_to_style", - ImGuiTheme::ThemeToStyle, py::arg("theme")); - - m.def("apply_theme", - ImGuiTheme::ApplyTheme, py::arg("theme")); - - - auto pyClassImGuiThemeTweaks = - py::class_ - (m, "ImGuiThemeTweaks", "") - .def_readwrite("rounding", &ImGuiThemeTweaks::Rounding, "Common rounding for widgets. If < 0, this is ignored.") - .def_readwrite("rounding_scrollbar_ratio", &ImGuiThemeTweaks::RoundingScrollbarRatio, "If rounding is applied, scrollbar rounding needs to be adjusted to be visually pleasing in conjunction with other widgets roundings. Only applied if Rounding > 0.)") - .def_readwrite("alpha_multiplier", &ImGuiThemeTweaks::AlphaMultiplier, "Change the alpha that will be applied to windows, popups, etc. If < 0, this is ignored.") - .def_readwrite("hue", &ImGuiThemeTweaks::Hue, "\n HSV Color tweaks\n\n Change the hue of all widgets (gray widgets will remain gray, since their saturation is zero). If < 0, this is ignored.") - .def_readwrite("saturation_multiplier", &ImGuiThemeTweaks::SaturationMultiplier, "Multiply the saturation of all widgets (gray widgets will remain gray, since their saturation is zero). If < 0, this is ignored.") - .def_readwrite("value_multiplier_front", &ImGuiThemeTweaks::ValueMultiplierFront, "Multiply the value (luminance) of all front widgets. If < 0, this is ignored.") - .def_readwrite("value_multiplier_bg", &ImGuiThemeTweaks::ValueMultiplierBg, "Multiply the value (luminance) of all backgrounds. If < 0, this is ignored.") - .def_readwrite("value_multiplier_text", &ImGuiThemeTweaks::ValueMultiplierText, "Multiply the value (luminance) of text. If < 0, this is ignored.") - .def_readwrite("value_multiplier_frame_bg", &ImGuiThemeTweaks::ValueMultiplierFrameBg, " Multiply the value (luminance) of FrameBg. If < 0, this is ignored.\n (Background of checkbox, radio button, plot, slider, text input)") - .def(py::init<>()) - ; - - - auto pyClassImGuiTweakedTheme = - py::class_ - (m, "ImGuiTweakedTheme", "") - .def(py::init<>([]( - ImGuiTheme::ImGuiTheme_ Theme = ImGuiTheme::ImGuiTheme_DarculaDarker, ImGuiThemeTweaks Tweaks = ImGuiThemeTweaks()) - { - auto r = std::make_unique(); - r->Theme = Theme; - r->Tweaks = Tweaks; - return r; - }) - , py::arg("theme") = ImGuiTheme::ImGuiTheme_DarculaDarker, py::arg("tweaks") = ImGuiThemeTweaks() - ) - .def_readwrite("theme", &ImGuiTweakedTheme::Theme, "") - .def_readwrite("tweaks", &ImGuiTweakedTheme::Tweaks, "") - ; - - - m.def("tweaked_theme_theme_to_style", - ImGuiTheme::TweakedThemeThemeToStyle, py::arg("tweaked_theme")); - - m.def("apply_tweaked_theme", - ImGuiTheme::ApplyTweakedTheme, py::arg("tweaked_theme")); - - m.def("show_theme_tweak_gui", - ImGuiTheme::ShowThemeTweakGui, - py::arg("tweaked_theme"), - "Show the theme selection listbox, the theme tweak widgets, as well as ImGui::ShowStyleEditor. Returns True if modified (Warning, when using ShowStyleEditor, no info about modification is transmitted)"); - - m.def("so_dark", - ImGuiTheme::SoDark, py::arg("hue")); - - m.def("shades_of_gray", - ImGuiTheme::ShadesOfGray, py::arg("rounding") = 0.f, py::arg("value_multiplier_front") = 1.f, py::arg("value_multiplier_bg") = 1.f); - - m.def("darcula", - ImGuiTheme::Darcula, py::arg("rounding") = 1.f, py::arg("hue") = -1.f, py::arg("saturation_multiplier") = 1.f, py::arg("value_multiplier_front") = 1.f, py::arg("value_multiplier_bg") = 1.f, py::arg("alpha_bg_transparency") = 1.f); - - py::enum_(m, "DefaultImGuiWindowType", py::arithmetic(), "*\n@@md#DefaultImGuiWindowType\n\n__DefaultImGuiWindowType__ is an enum class that defines whether or not a full screen background window is provided.\n\n Values:\n * _ProvideFullScreenWindow_: a full window is provided in the background\n * _ProvideFullScreenDockSpace_: a full screen dockspace is provided in the background\n * _NoDefaultWindow_: No default window is provided (except for ImGui's default \"debug\" window)\n\n@@md\n") .value("provide_full_screen_window", HelloImGui::DefaultImGuiWindowType::ProvideFullScreenWindow, "") .value("provide_full_screen_dock_space", HelloImGui::DefaultImGuiWindowType::ProvideFullScreenDockSpace, "") @@ -576,7 +631,7 @@ void py_init_module_hello_imgui(py::module& m) auto pyClassBackendPointers = py::class_ - (m, "BackendPointers", "*\n @@md#BackendPointers\n\n**BackendPointers** is a struct that contains optional pointers to the backend implementations (for SDL and GLFW).\n\nThese pointers will be filled when the application starts, and you can use them to customize\nyour application behavior using the selected backend.\n\n Members:\n* `glfwWindow`: _void *, default=nullptr_. Pointer to the main GLFW window (of type `GLFWwindow*`).\n Only filled if the backend is GLFW.\n* `sdlWindow`: _void *, default=nullptr_. Pointer to the main SDL window (of type `SDL_Window*`).\n Only filled if the backend is SDL (or emscripten + sdl)\n* `sdlGlContext`: _void *, default=nullptr_. Pointer to SDL's GlContext (of type `SDL_GLContext`).\n Only filled if the backend is SDL (or emscripten + sdl)\n\nNote: If using the Metal or Vulkan rendering backend, you can find some interesting pointers inside\n `src/hello_imgui/internal/backend_impls/rendering_metal.h` and `src/hello_imgui/internal/backend_impls/rendering_vulkan.h`.\n\n@@md\n") + (m, "BackendPointers", "*\n @@md#BackendPointers\n\n**BackendPointers** is a struct that contains optional pointers to the backend implementations (for SDL and GLFW).\n\nThese pointers will be filled when the application starts, and you can use them to customize\nyour application behavior using the selected backend.\n\n Members:\n* `glfwWindow`: _void *, default=nullptr_. Pointer to the main GLFW window (of type `GLFWwindow*`).\n Only filled if the backend is GLFW.\n* `sdlWindow`: _void *, default=nullptr_. Pointer to the main SDL window (of type `SDL_Window*`).\n Only filled if the backend is SDL (or emscripten + sdl)\n* `sdlGlContext`: _void *, default=nullptr_. Pointer to SDL's GlContext (of type `SDL_GLContext`).\n Only filled if the backend is SDL (or emscripten + sdl)\n\nNote: If using the Metal, Vulkan or DirectX rendering backend, you can find some interesting pointers inside\n `src/hello_imgui/internal/backend_impls/rendering_metal.h`\n `src/hello_imgui/internal/backend_impls/rendering_vulkan.h`\n `src/hello_imgui/internal/backend_impls/rendering_dx11.h`\n `src/hello_imgui/internal/backend_impls/rendering_dx12.h`\n@@md\n") .def(py::init<>()) // implicit default constructor .def_readwrite("glfw_window", &BackendPointers::glfwWindow, "") .def_readwrite("sdl_window", &BackendPointers::sdlWindow, "") @@ -701,55 +756,6 @@ void py_init_module_hello_imgui(py::module& m) ; - py::enum_(m, "LogLevel", py::arithmetic(), "") - .value("debug", HelloImGui::LogLevel::Debug, "") - .value("info", HelloImGui::LogLevel::Info, "") - .value("warning", HelloImGui::LogLevel::Warning, "") - .value("error", HelloImGui::LogLevel::Error, ""); - - - m.def("log", - [](HelloImGui::LogLevel level, const char * const format) - { - auto Log_adapt_variadic_format = [](HelloImGui::LogLevel level, const char * const format) - { - HelloImGui::Log(level, "%s", format); - }; - - Log_adapt_variadic_format(level, format); - }, py::arg("level"), py::arg("format")); - - m.def("log_clear", - HelloImGui::LogClear); - - m.def("log_gui", - HelloImGui::LogGui, py::arg("size") = ImVec2(0.f, 0.f)); - - - m.def("em_size", - py::overload_cast<>(HelloImGui::EmSize), " __HelloImGui::EmSize()__ returns the visible font size on the screen. For good results on HighDPI screens, always scale your\n widgets and windows relatively to this size.\n It is somewhat comparable to the [em CSS Unit](https://lyty.dev/css/css-unit.html).\n EmSize() = ImGui::GetFontSize()"); - - m.def("em_size", - py::overload_cast(HelloImGui::EmSize), - py::arg("nb_lines"), - "__HelloImGui::EmSize(nbLines)__ returns a size corresponding to nbLines text lines"); - - m.def("em_to_vec2", - py::overload_cast(HelloImGui::EmToVec2), py::arg("x"), py::arg("y")); - - m.def("em_to_vec2", - py::overload_cast(HelloImGui::EmToVec2), py::arg("v")); - - m.def("dpi_font_loading_factor", - HelloImGui::DpiFontLoadingFactor, " Multiply font sizes by this factor when loading fonts manually with ImGui::GetIO().Fonts->AddFont...\n (HelloImGui::LoadFontTTF does this by default)"); - - m.def("dpi_window_size_factor", - HelloImGui::DpiWindowSizeFactor, " DpiWindowSizeFactor() is the factor by which window size should be multiplied to get a similar visible size on different OSes.\n It returns ApplicationScreenPixelPerInch / 96 under windows and linux. Under macOS, it will return 1."); - - m.def("imgui_default_font_global_scale", - HelloImGui::ImGuiDefaultFontGlobalScale, "returns the default value that should be stored inside `ImGui::GetIO().FontGlobalScale`"); - - m.def("run", py::overload_cast(HelloImGui::Run), py::arg("runner_params"), diff --git a/external/hello_imgui/hello_imgui b/external/hello_imgui/hello_imgui index e45065d1..0752fb43 160000 --- a/external/hello_imgui/hello_imgui +++ b/external/hello_imgui/hello_imgui @@ -1 +1 @@ -Subproject commit e45065d1753814f028d903ffa14131563fd4094d +Subproject commit 0752fb4373c92d2c19776449741aa6e3553c183a