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

Child Windows: support the ImGuiWindowFlags_AlwaysAutoResize flag for ch... #160

Closed
wants to merge 1 commit into from

Conversation

adamdmoss
Copy link
Contributor

...ild windows.

This appears to do the right thing in my testing, and has no impact on paths where the flag is not set.

… child windows.

This appears to do the right thing in my testing, and has no impact on paths where the flag is not set.
@ocornut
Copy link
Owner

ocornut commented Mar 17, 2015

Thanks Adam.

The patch shouldn't introduce any problems but this looks inconsistent with the behaviour of ImGuiWindowFlags_AlwaysAutoResize for normal window. The flag is supposed to resize a window to the size of its content. Here it is being resized to fit the remaining space in the parent.

I am also curious as to how you are using this. A child window resizing to its content kind of defeat the point of a child window since it won't scroll.

I am aware of at least one thing that may be remotely related:
There's no way currently to easily package multiple widgets into one so you can easily use SameLine(), IsItemHovered() considering multiple widgets. So in effect a child window may be a workaronud to achieve this at the moment and perhaps you are using this for this purpose?

EDIT I am also not sure of the effect of the added test in Begin()

+ if (!(flags & ImGuiWindowFlags_AlwaysAutoResize))
+ {
+ window->SizeFull = size;
+ }

@ocornut
Copy link
Owner

ocornut commented Mar 17, 2015

My bad I had misinterpreted the change, so disregard my comments above. But this question still stands:

"I am also curious as to how you are using this. A child window resizing to its content kind of defeat the point of a child window since it won't scroll."

@adamdmoss
Copy link
Contributor Author

The patch does resize a (child) window to the size of its content, as with a normal window.
And yes, the use case you describe is basically what I use this for. :)

There IS a problem I've just spotted though. The child window does get a scrollbar (if it exceeds the display height, though this should really be the parent window height), or you can use the no-scrollbar flag and it does the right thing there too. But in both cases, the parent window's scroll area is definitely confused.

@adamdmoss adamdmoss closed this Mar 17, 2015
@ocornut
Copy link
Owner

ocornut commented Mar 17, 2015

I'll have to have a look at the cases you described because I'm not sure to understand.

Anyway if you are using it for the purpose of layout, I guess we need to add more complete layout features. Something like BeginGroup / EndGroup? (not sure of the name)

  • Where if you call something after EndGroup, e.g. SameLine, IsItemHovered it considers the whole group.
  • Start column position locked by BeginGroup (so you can layout thing vertically)
  • Should be able to recurse them obviously.
  • But it would stay in the same window (shared scrolling, keyboard tabbing, etc.) And we'd need to clarify what each is for.
    Etc.

But apart from the bad name ("group" probably not what we are looking for) the problem is that I need to tackle better layout features - also see #97 - as a whole, so a single pair of function calls may be too short-sighted at the moment.

@ocornut
Copy link
Owner

ocornut commented Mar 17, 2015

If the only thing you are using it for is to use SameLine between those childs I can possibly come up with functions to do it neatly, at the risk that the functions may be replaced later on.

@adamdmoss
Copy link
Contributor Author

Thanks, so really I want it for two things:

  1. Multiple groups of widgets laid out tightly horizontally with SameLine()
  2. Being able to measure the size of a resulting child window (i.e. the overall size of a group of widgets) for smarter layout. (for example, I have a [obviously stateful] function which will keep laying out items out horizontally until there is no room left for the next widget, in which case it'll move down vertically; this works fine for individual widgets but is infinitely more useful with groups of widgets).

@adamdmoss
Copy link
Contributor Author

The BeginGroup/EndGroup you describe, I think, would totally suit my desires (and more :)).

@ocornut
Copy link
Owner

ocornut commented Mar 17, 2015

OK it looks like I can add this regardless of the features discussed in topic 97.
You'll be able to use GetItemBoxMin/Max (I can add GetItemBoxSize as well).
Note that you may be better off just comparing GetCursorPos() to take account of padding.

@adamdmoss
Copy link
Contributor Author

That sounds great, I'm using GetItemBoxMin/Max for this already. (GetCursorPos() does sound wiser.)

@ocornut
Copy link
Owner

ocornut commented Mar 17, 2015

Working on this but it's raising another (tricky) issue with the vertical alignment of text blocks that I need to fix prior hand.

@adamdmoss
Copy link
Contributor Author

Cool - cheers.

ocornut added a commit that referenced this pull request Mar 17, 2015
…arious sizes. Added demos. Toward #160

Also fixed LabelText() height.
@ocornut
Copy link
Owner

ocornut commented Mar 17, 2015

Phew.. Added BeginGroup/EndGroup().
I also have renamed GetItemBoxMin/GetItemBoxMax to GetItemRectMin/GetItemRectMax.

groups

@adamdmoss
Copy link
Contributor Author

Works well - thanks!

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

Successfully merging this pull request may close these issues.

2 participants