Skip to content

Commit

Permalink
Bindings: add ImVec2Like and ImVec4Like
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Nov 22, 2024
1 parent 18b1511 commit 3ad2441
Show file tree
Hide file tree
Showing 34 changed files with 488 additions and 410 deletions.
16 changes: 13 additions & 3 deletions bindings/imgui_bundle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from imgui_bundle._imgui_bundle import __bundle_submodules__ # type: ignore
from imgui_bundle._imgui_bundle import __version__, compilation_time
from typing import Union, Tuple, List


def has_submodule(submodule_name):
Expand All @@ -16,7 +17,7 @@ def has_submodule(submodule_name):
#
if has_submodule("imgui"):
from imgui_bundle._imgui_bundle import imgui as imgui
from imgui_bundle._imgui_bundle.imgui import ImVec2, ImVec4, ImColor, FLT_MIN, FLT_MAX # type: ignore # noqa: F401
from imgui_bundle._imgui_bundle.imgui import ImVec2, ImVec4, ImColor, FLT_MIN, FLT_MAX # noqa: F401
from imgui_bundle import imgui_pydantic as imgui_pydantic
from imgui_bundle.imgui_pydantic import (
ImVec4_Pydantic as ImVec4_Pydantic,
Expand All @@ -26,9 +27,17 @@ def has_submodule(submodule_name):
from imgui_bundle.im_col32 import IM_COL32 # noqa: F401, E402
from imgui_bundle import imgui_ctx as imgui_ctx # noqa: E402

ImVec2Like = Union[ImVec2, Tuple[int | float, int | float], List[int | float]]
ImVec4Like = Union[ImVec4, Tuple[int | float, int | float, int | float, int | float], List[int | float]]

imgui.ImVec2Like = ImVec2Like
imgui.ImVec4Like = ImVec4Like

__all__.extend([
"imgui",
"ImVec2",
"ImVec2Like",
"ImVec4Like",
"ImVec4",
"ImColor",
"FLT_MIN",
Expand Down Expand Up @@ -121,8 +130,9 @@ def has_submodule(submodule_name):
#
# Import Python submodules
#
from imgui_bundle import imgui_fig as imgui_fig
__all__.extend(["imgui_fig"])
if has_submodule("immvision"):
from imgui_bundle import imgui_fig as imgui_fig
__all__.extend(["imgui_fig"])


# Glfw setup:
Expand Down
2 changes: 1 addition & 1 deletion bindings/imgui_bundle/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ from .immapp import icons_fontawesome_6 as icons_fontawesome_6
from . import im_cool_bar as im_cool_bar
from . import nanovg as nanovg

from .imgui import ImVec2 as ImVec2, ImVec4 as ImVec4, ImColor as ImColor
from .imgui import ImVec2 as ImVec2, ImVec4 as ImVec4, ImColor as ImColor, ImVec2Like as ImVec2Like
from .imgui_pydantic import ImVec2_Pydantic as ImVec2_Pydantic, ImVec4_Pydantic as ImVec4_Pydantic, ImColor_Pydantic as ImColor_Pydantic
from .im_col32 import IM_COL32 as IM_COL32

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self):
"Hello, Dear ImGui\n"
"Unleash your creativity!\n",
True, # multiline
ImVec2(14.0, 3.0) # initial size (in em)
(14.0, 3.0) # initial size (in em)
)

class RocketState(Enum):
Expand Down Expand Up @@ -404,7 +404,7 @@ def gui_window_alternative_theme(app_state: AppState):
# Display a image of the haiku below with Japanese characters
# with an informative tooltip
haiku_image_height = hello_imgui.em_size(5.0)
hello_imgui.image_from_asset("images/haiku.png", ImVec2(0.0, haiku_image_height))
hello_imgui.image_from_asset("images/haiku.png", (0.0, haiku_image_height))
imgui.set_item_tooltip("""
Extract from Wikipedia
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -452,7 +452,7 @@ def gui_window_alternative_theme(app_state: AppState):

if imgui.tree_node("Text Display"):
imgui.text("Hello, world!")
imgui.text_colored(ImVec4(1.0, 0.5, 0.5, 1.0), "Some text")
imgui.text_colored((1.0, 0.5, 0.5, 1.0), "Some text")
imgui.text_disabled("Disabled text")
imgui.text_wrapped("This is a long text that will be wrapped in the window")
imgui.tree_pop()
Expand Down Expand Up @@ -784,7 +784,7 @@ def setup_my_theme():
hello_imgui.apply_tweaked_theme(tweaked_theme) # Note: you can also push/pop the theme in order to apply it only to a specific part of the Gui: hello_imgui.push_tweaked_theme(tweaked_theme) / hello_imgui.pop_tweaked_theme()
# Then apply further modifications to ImGui style
imgui.get_style().item_spacing = ImVec2(6, 4) # Reduce spacing between items ((8, 4) by default)
imgui.get_style().set_color_(imgui.Col_.text.value, ImVec4(0.8, 0.8, 0.85, 1.0)) # Change text color
imgui.get_style().set_color_(imgui.Col_.text.value, (0.8, 0.8, 0.85, 1.0)) # Change text color


##########################################################################
Expand Down
51 changes: 29 additions & 22 deletions bindings/imgui_bundle/hello_imgui.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ from imgui_bundle.imgui.internal import DockNodeFlags_, DockNodeFlags
from imgui_bundle.imgui import (
ImVec2,
ImVec4,
ImVec2Like,
ImVec4Like,
ImFontConfig,
ImFont,
ImTextureID,
Expand Down Expand Up @@ -214,7 +216,7 @@ def em_to_vec2(x: float, y: float) -> ImVec2:

# ImVec2 EmToVec2(ImVec2 v); /* original C++ signature */
@overload
def em_to_vec2(v: ImVec2) -> ImVec2:
def em_to_vec2(v: ImVec2Like) -> ImVec2:
pass

# float EmSize(); /* original C++ signature */
Expand All @@ -230,7 +232,7 @@ def em_size(nb_lines: float) -> float:
pass

# ImVec2 PixelsToEm(ImVec2 pixels); /* original C++ signature */
def pixels_to_em(pixels: ImVec2) -> ImVec2:
def pixels_to_em(pixels: ImVec2Like) -> ImVec2:
"""__HelloImGui::PixelToEm()__ converts a Vec2 in pixels coord to a Vec2 in em units"""
pass

Expand Down Expand Up @@ -515,7 +517,7 @@ def log_clear() -> None:

# void LogGui(ImVec2 size=ImVec2(0.f, 0.f)); /* original C++ signature */
# }
def log_gui(size: Optional[ImVec2] = None) -> None:
def log_gui(size: Optional[ImVec2Like] = None) -> None:
"""---
Python bindings defaults:
If size is None, then its default value will be: ImVec2(0., 0.)
Expand Down Expand Up @@ -552,11 +554,11 @@ def log_gui(size: Optional[ImVec2] = None) -> None:
# const ImVec4& border_col = ImVec4(0,0,0,0));
def image_from_asset(
asset_path: str,
size: Optional[ImVec2] = None,
uv0: Optional[ImVec2] = None,
uv1: Optional[ImVec2] = None,
tint_col: Optional[ImVec4] = None,
border_col: Optional[ImVec4] = None,
size: Optional[ImVec2Like] = None,
uv0: Optional[ImVec2Like] = None,
uv1: Optional[ImVec2Like] = None,
tint_col: Optional[ImVec4Like] = None,
border_col: Optional[ImVec4Like] = None,
) -> None:
"""`HelloImGui::ImageFromAsset(const char *assetPath, size, ...)`:
will display a static image from the assets.
Expand All @@ -578,12 +580,12 @@ def image_from_asset(
# const ImVec4& tint_col = ImVec4(1,1,1,1));
def image_button_from_asset(
asset_path: str,
size: Optional[ImVec2] = None,
uv0: Optional[ImVec2] = None,
uv1: Optional[ImVec2] = None,
size: Optional[ImVec2Like] = None,
uv0: Optional[ImVec2Like] = None,
uv1: Optional[ImVec2Like] = None,
frame_padding: int = -1,
bg_col: Optional[ImVec4] = None,
tint_col: Optional[ImVec4] = None,
bg_col: Optional[ImVec4Like] = None,
tint_col: Optional[ImVec4Like] = None,
) -> bool:
"""`bool HelloImGui::ImageButtonFromAsset(const char *assetPath, size, ...)`:
will display a button using an image from the assets.
Expand Down Expand Up @@ -623,7 +625,9 @@ class ImageAndSize:
size: ImVec2 = ImVec2(0.0, 0.0)
# ImageAndSize(ImTextureID textureId = ImTextureID(0), ImVec2 size = ImVec2(0.f, 0.f)); /* original C++ signature */
def __init__(
self, texture_id: Optional[ImTextureID] = None, size: Optional[ImVec2] = None
self,
texture_id: Optional[ImTextureID] = None,
size: Optional[ImVec2Like] = None,
) -> None:
"""Auto-generated default constructor with named params
---
Expand All @@ -639,7 +643,7 @@ def image_and_size_from_asset(asset_path: str) -> ImageAndSize:
pass

# ImVec2 ImageProportionalSize(const ImVec2& askedSize, const ImVec2& imageSize); /* original C++ signature */
def image_proportional_size(asked_size: ImVec2, image_size: ImVec2) -> ImVec2:
def image_proportional_size(asked_size: ImVec2Like, image_size: ImVec2Like) -> ImVec2:
"""`ImVec2 HelloImGui::ImageProportionalSize(askedSize, imageSize)`:
will return the displayed size of an image.
- if askedSize.x or askedSize.y is 0, then the corresponding dimension
Expand Down Expand Up @@ -1422,7 +1426,7 @@ class AppWindowParams:
borderless_movable: bool = True,
borderless_resizable: bool = True,
borderless_closable: bool = True,
borderless_highlight_color: Optional[ImVec4] = None,
borderless_highlight_color: Optional[ImVec4Like] = None,
edge_insets: Optional[EdgeInsets] = None,
handle_edge_insets: bool = True,
repaint_during_resize_gotcha_reentrant_repaint: bool = False,
Expand Down Expand Up @@ -1595,10 +1599,10 @@ class ImGuiWindowParams:
show_status_bar: bool = False,
show_status_fps: bool = True,
remember_status_bar_settings: bool = True,
full_screen_window_margin_top_left: Optional[ImVec2] = None,
full_screen_window_margin_bottom_right: Optional[ImVec2] = None,
full_screen_window_margin_top_left: Optional[ImVec2Like] = None,
full_screen_window_margin_bottom_right: Optional[ImVec2Like] = None,
tweaked_theme: Optional[ImGuiTweakedTheme] = None,
background_color: Optional[ImVec4] = None,
background_color: Optional[ImVec4Like] = None,
) -> None:
"""Auto-generated default constructor with named params
---
Expand Down Expand Up @@ -1735,8 +1739,8 @@ class EdgeToolbarOptions:
def __init__(
self,
size_em: float = 2.5,
window_padding_em: Optional[ImVec2] = None,
window_bg: Optional[ImVec4] = None,
window_padding_em: Optional[ImVec2Like] = None,
window_bg: Optional[ImVec4Like] = None,
) -> None:
"""Auto-generated default constructor with named params
---
Expand Down Expand Up @@ -3317,7 +3321,10 @@ class InputTextData:

# InputTextData(const std::string& text = "", bool multiline = false, ImVec2 size_em = ImVec2(0, 0)) : Text(text), Multiline(multiline), SizeEm(size_em) {} /* original C++ signature */
def __init__(
self, text: str = "", multiline: bool = False, size_em: Optional[ImVec2] = None
self,
text: str = "",
multiline: bool = False,
size_em: Optional[ImVec2Like] = None,
) -> None:
"""---
Python bindings defaults:
Expand Down
4 changes: 2 additions & 2 deletions bindings/imgui_bundle/im_cool_bar.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Python bindings for https://github.com/aiekick/ImCoolBar
# ruff: noqa: B008
import enum
from typing import Optional
from imgui_bundle.imgui import ImVec2, WindowFlags, WindowFlags_
from imgui_bundle.imgui import ImVec2, ImVec2Like, WindowFlags, WindowFlags_

ImCoolBarFlags = int
ImGuiWindowFlags = WindowFlags
Expand Down Expand Up @@ -54,7 +54,7 @@ class ImCoolBarConfig:
effect_strength: float = 0.5
def __init__(
self,
v_anchor: Optional[ImVec2] = None,
v_anchor: Optional[ImVec2Like] = None,
v_normal_size: float = 40.0,
v_hovered_size: float = 60.0,
v_anim_step: float = 0.15,
Expand Down
Loading

0 comments on commit 3ad2441

Please sign in to comment.