-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
How to Center Multiple Elements within a large Tabbed view #3546
Comments
You can't without calculating it yourself. |
Makes sense, I thought that might be the answer. Would be nice if there was a way to draw it in memory or off screen or to an image buffer or something first time around, calculate the width and height(could be other things that would be nice to calculate) then every other time I could refer to those numbers(or update as needed). Or even draw it in a place I know is blank, measure cursor position change, then delete it or draw a black rectangle over it. Is it possible for me to get the bottom right corner after I draw it? I'd be fine with getting the first corner from the cursor pos, then getting the new cursor position after and I now know the width and height. It'd be in the wrong place for a single frame, which isn't a big deal, maybe I even draw a black rectangle over it first frame after drawing. Just thinking it's going to be tricky to calculate if I start adding more and more items and don't want to recalculate for every font or worry about different OSs rendering differently or something. Thanks. |
I think we ought to create a layout/output mode where ItemSize/ItemAdd would return false but take measurements, so a multi-pass approach like the one you mention would be possible. (Not fully helping, but note that the size of items is fairly standardized. All framed widgets use FramePadding on each sides, and their base size is either based on contents (e.g. Button uses CalcTextSize(label)) either specified by user (e.g. Button optional arg) either can be retrieved with CalcItemWidth()).
Depending what your shape/contents is like, you could either
Similar idea used in #1236 |
Thank you, sounds like a great idea to me. Would love to see something like that in the future. For now, will estimate or just use upper left corner or something. Thanks ocornut! |
Version/Branch of Dear ImGui:
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_glfw.cpp + imgui_impl_glfw.cpp (or specify if using a custom engine/back-end)
Compiler: llvm through Visual Studio (if the question is related to building or platform specific features)
Operating System: Windows 10
My Issue/Question:
I'm trying to center multiple elements within a Tab Item. See screenshot. I would like to center the Text, InputText, and Button items, basically the whole group in the middle of the tab. I know I need to use SetCursorPos, but not sure how to get the size of the tabbed window or the size of the entire group so I can use that to calculate the new Cursor Pos. Ideally I'd like to center this both horizontally and vertically. Thanks.
Screenshots/Video
Standalone, minimal, complete and verifiable example: (see #2261)
The text was updated successfully, but these errors were encountered: