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

How to draw a vertical dividing line? #5448

Closed
Boglon333 opened this issue Jul 3, 2022 · 5 comments
Closed

How to draw a vertical dividing line? #5448

Boglon333 opened this issue Jul 3, 2022 · 5 comments

Comments

@Boglon333
Copy link

Version/Branch of Dear ImGui:

Version: 1.88
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Operating System: XXX

My Issue/Question:
I want to draw a vertical line that can divide a window as two part. It works like the function ImGui::Columns(). I have drawn a left window and a right window (the code is below) , but I need a vertical line. In picture two, when mouse clicks on the vertical line it turns dark blue, it also turns dark blue when mouse moves hover the line. In picture three and four, I can drag the vertical line from left to right or from right to left so that I will change the size of left window and right window. I think it works like the column in the table, but I can't fulfill my demands with ImGui::Columns() .

Screenshots/Video
picture oneAF4F55EB-6E23-40e9-B35C-56A3FC0F6E55picture two50520B8F-6722-4498-86B3-656C8BE01908picture threeA170C485-D4DB-4f2c-AC8D-BFDC97E457DA
picture fourAE620150-5AF4-46e2-A728-5080F49009A0

Standalone, minimal, complete and verifiable example: (see #2261)

ImGui::BeginChild("left window", ImVec2(200, 0), false);
...
ImGui::EndChild();
ImGui::BeginChild("right window", ImVec2(0, -ImGui::GetFrameHeightWithSpacing()),false);
...
ImGui::EndChild();
@rokups
Copy link
Contributor

rokups commented Jul 4, 2022

It is unclear what you are trying to achieve and why ImGui::Columns() does not fulfill your needs. To achieve similar thing you could use tables (ImGui::BeginTable()) without header row and outter borders. Depending on what you are trying to achieve, you may want to check out docking branch in case its that what you are trying to do.

@Boglon333
Copy link
Author

Oh, I'm sorry. Please ignore what I said earlier. Now I want to use ImDrawList* draw_list = ImGui::GetWindowDrawList(); draw_list->AddLine() to draw this vertical line, but how can I select this line like picture two. (In picture two, when mouse clicks on the vertical line it turns dark blue, it also turns dark blue when mouse moves hover the line.)
image

@rokups
Copy link
Contributor

rokups commented Jul 4, 2022

It looks like you want to create a custom widget. Look into ButtonBehavior() (include imgui_internal.h). This will allow line to behave like a button and give you some hints on it's state.

@ocornut
Copy link
Owner

ocornut commented Jul 4, 2022

@Boglon333 You should clarify your actual problems rather than focus on what you think is a possible workaround otherwise you are falling into XY Problem (https://xyproblem.info). You are not explaining why Tables or Columns are not working for you, you should focus on that.

Should you actually need a custom widget there is a SplitterBehavior() helper in imgui_internal (see #319)

@Boglon333
Copy link
Author

@ocornut @rokups Thank you very much, I will consider it again. So I'll close this problem.

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

3 participants