Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imgui.internal.splitter_behavior incorrect #89

Closed
dcnieho opened this issue Mar 1, 2023 · 3 comments
Closed

imgui.internal.splitter_behavior incorrect #89

dcnieho opened this issue Mar 1, 2023 · 3 comments

Comments

@dcnieho
Copy link
Contributor

dcnieho commented Mar 1, 2023

\imgui_bundle\imgui\internal.pyi line 6023. The C++ signature is:

IMGUI_API bool          SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend = 0.0f, float hover_visibility_delay = 0.0f, ImU32 bg_col = 0);

But the python signature

def splitter_behavior(
    bb: ImRect,
    id_: ID,
    axis: Axis,
    size1: np.ndarray,
    size2: np.ndarray,
    min_size2: float,
    hover_extend: float = 0.0,
    hover_visibility_delay: float = 0.0,
    bg_col: ImU32 = 0,
) -> bool

is missing min_size1.

Also, the call to `` is wrong:

ImGui::SplitterBehavior(bb, id, axis, static_cast<float *>(size1_from_pyarray), static_cast<float *>(size2_from_pyarray), static_cast<float>(size2_count), min_size2, hover_extend, hover_visibility_delay, bg_col);

there shouldn't be static_cast<float>(size2_count)

The more appropriate signature here may be:

def splitter_behavior(
    bb: ImRect,
    id_: ID,
    axis: Axis,
    size1: float,
    size2: float,
    min_size1: float,
    min_size2: float,
    hover_extend: float = 0.0,
    hover_visibility_delay: float = 0.0,
    bg_col: ImU32 = 0,
) -> bool, float, float

using _adapt_modifiable_immutable_to_return to return the modified values of size1 and size2

@dcnieho
Copy link
Contributor Author

dcnieho commented Mar 1, 2023

The context for this is that i am trying to implement the splitter from ocornut/imgui#319 (comment)

What i have got now is

def splitter(split_vertically, thickness, size1, size2, min_size1, min_size2, splitter_long_axis_size = -1.0):
    g = imgui.get_current_context()
    window = g.current_window
    id = window.get_id("##Splitter")
    cp = window.dc.cursor_pos
    off= imgui.ImVec2(size1, 0.) if split_vertically else imgui.ImVec2(0., size1)
    sz = imgui.internal.calc_item_size(imgui.ImVec2(thickness, splitter_long_axis_size) if split_vertically else imgui.ImVec2(splitter_long_axis_size, thickness), 0., 0.)
    bb = imgui.internal.ImRect(cp[0]+off[0],cp[1]+off[1], cp[0]+off[0]+sz[0],cp[1]+off[1]+sz[1])
    np_size1 = np.array([size1],dtype='float32')
    np_size2 = np.array([size2],dtype='float32')
    retval = imgui.internal.splitter_behavior(bb, id, imgui.internal.Axis.x if split_vertically else imgui.internal.Axis.y, np_size1, np_size2, min_size1, 4., .04)#min_size2, 4., 0.04)
    return retval, np_size1[0], np_size2[0]

@pthom pthom closed this as completed in d39eca0 Mar 1, 2023
@pthom
Copy link
Owner

pthom commented Mar 1, 2023

Hi,

Thanks for pointing this out. This was due to a misconfiguration in the generator. It was fixed in d39eca0

The culprit is this option:
https://github.com/pthom/srcmlcpp/blob/main/packages/litgen/options.py#L226-L243

Which is heavily used in ImPlot bindings, as well as some imgui bindings for plotting functions.

@dcnieho
Copy link
Contributor Author

dcnieho commented Mar 1, 2023

Nice work! Glad that was so easy to fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants