-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Changing windows resolution scale messes up positioning? #341
Comments
@ItsVoltz Maybe giu.Align(...) is the thing you are looking for? |
I use align however is there a way to align two buttons in a row perfectly? when I try it just aligns the first one to the center then the second is off of the correctly centered button Here is how it looks when I try to align it: Code: g.Align(g.AlignCenter).To(
g.Row(
g.Button("Login").Size(136, 25).OnClick(cl.login),
g.Button("Exit").Size(136, 25).OnClick(cl.exit),
),
), |
@gucio321 We may need to calcuate the row width here? |
@ItsVoltz For now, you need to use giu.Dummy and calculate it's width based on the width of the two buttons. |
yep, @AllenDang It's a kind of bug in AlignmentSetter @ItsVoltz maybe try the following for now: g.Custom(func() { // centered buttons
width, _ := g.GetAvailableRegion()
spacing := GetItemSpacing()
buttonW := (width - spacing)/2
g.Row(
g.Button("Login").Size(buttonW, 25).OnClick(cl.login),
g.Button("Exit").Size(buttonW, 25).OnClick(cl.exit),
).Build()
}), |
…Layout added EXPERIMENTAL, public method GetWidgetWidth, which calculates a width of widget. (related with AllenDang#341)
…Layout added EXPERIMENTAL, public method GetWidgetWidth, which calculates a width of widget. (related with AllenDang#341)
See it works however not how I want as I don;t have the inputs span across the entire width: |
@ItsVoltz The PR is just merged, can you make sure you are running the newest code from master branch? |
I am |
@gucio321 Seems this issue still there. |
@ItsVoltz could you try |
That worked thank you!, all though I have come across a bug with clicks registering on these row aligned buttons, the first button works fine however clicks on the second one seem to work sometimes, |
Also, another bug is if you are using align unless I actually use a g.Dummy(0, 0) in a row with the widget it doesn't correctly align it is off some pixels. EDIT: nvm it is still off some that was my solution before however it does not seem to work anymore |
that's very strange, but right, I can reproduce. |
@AllenDang I got an idea, but it it may be reallly experimanetal:
what do you think about it? |
hmm, in the other comment of discussion on upstream issue, I can see this:
I'll investigate if it can be used more evectively. |
@AllenDang seems like ImDrawListSplitter isn't implemented in imgui-go yet. could you take a look on it (as I'm not a C guy, I can't sadly do it myself) |
@gucio321 Sure, let me do it. |
@gucio321 Frankly, I think we should hold And another thing I'm waiting for is |
Any idea on fix for the buttons in a row align |
well, the problem is more complex, than I thought. So, @ItsVoltz ofc there is a solution (something like I described in #340 ) - manually align your buttons. const button1W, button2W = 100, 80
// ...
giu.Custom(func() {
availableW, _ := giu.GetAvailableRegion()
spacingW, _ := giu.GetItemSpacing()
giu.Dummy(availableW-(button1W+button2W+spacingW), 0).Build()
giu.Row(
giu.Button("my first button").Size(button1W, 20),
giu.Button("my second button").Size(button2W, 20),
).Build()
}), |
@AllenDang as far as I understand
so It will not be so large refinement for giu - just minor edit for The other thing is that imgui-go currently misses |
@gucio321 Ok, I got cold these days, may need some time to implement ImDrawListSplitter... Sorry to the delay. |
well, I hope, that this code: {
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
ImDrawList* list = ImGui::GetWindowDrawList();
struct foo {
bool btn() { return ImGui::Button("btn",ImVec2{200,20}); };
} btn;
ImVec2 start = ImGui::GetCursorPos();
ImVec2 size;
list->ChannelsSplit(2);
list->ChannelsSetCurrent(0);
//ImGui::PushID("someotherid");
if (btn.btn() ) {
std::cout << "btn 1 (invisible) pressed\n";
};
size = ImGui::GetItemRectSize();
ImVec2 available = ImGui::GetContentRegionMax();
start.x = (available.x-size.x)/2;
//ImGui::PopID();
ImGui::SetCursorPos(start);
list->ChannelsSetCurrent(1);
if (ImGui::BeginChild("measure") ){
if (btn.btn()){
std::cout << "btn 1 pressed\n";
};
}
ImGui::EndChild();
list->ChannelsMerge();
ImGui::End();
} despite it doesn't work like I expected, in connection with PushDisabled will finally work and we'll have these bugs fixed (clicking bug from here and double-pasting from #340 ) |
wow, @AllenDang it seems to work without list splitter for now: {
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
//ImDrawList* list = ImGui::GetWindowDrawList();
struct button {
bool Build() { return ImGui::Button("btn",ImVec2{200,20}); };
} mybutton;
ImVec2 start = ImGui::GetCursorPos();
ImVec2 size;
//list->ChannelsSplit(2);
//list->ChannelsSetCurrent(0);
if (mybutton.Build() ) {
std::cout << "btn 1 (invisible) pressed\n";
};
size = ImGui::GetItemRectSize();
ImVec2 available = ImGui::GetContentRegionMax();
start.x = (available.x-size.x)/2;
ImGui::SetCursorPos(start);
//list->ChannelsSetCurrent(1);
if (ImGui::BeginChild("measure") ){
if (mybutton.Build()){
std::cout << "btn 1 pressed\n";
};
}
ImGui::EndChild();
//list->ChannelsMerge();
ImGui::End();
} I'll try to implement to go and tell you if it works. IMO the problem is with the rendering order. if we put our centered button in a child, it works. |
@gucio321 The best place to ask this question is raise an issue in imgui's issue list. |
@gucio321 After your implementation, it's not only Align but also a whole Flex-box like layout mechanism becomes possible. Keep going man! It's a huge step. |
I opened an issue in upstream: ocornut/imgui#4588 |
hmm, @AllenDang so it seems that there is no solution right now, So I'm going to try with ChildWidget until upstream issue gets fixed. // Here's some code anyone can copy and paste to reproduce your issue
{
ImGui::Begin("Hello, world!");
struct foo {
bool btn() { return ImGui::Button("btn",ImVec2{200,20}); };
} btn;
ImVec2 start = ImGui::GetCursorPos();
ImVec2 size;
ImGui::PushID("someotherid");
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0);
if (btn.btn() ) {
std::cout << "btn 1 (invisible) pressed\n";
};
ImGui::PopStyleVar();
ImGui::PopID();
size = ImGui::GetItemRectSize();
ImVec2 available = ImGui::GetContentRegionMax();
start.x = (available.x-size.x)/2;
ImGui::SetCursorPos(start);
if (ImGui::BeginChild("container")) {
if (btn.btn()){
std::cout << "btn 1 pressed\n";
}
}
ImGui::EndChild();
ImGui::End();
} the child widget is here invisible at all giu.Child().Layout(giu.Button("btn")) do you have any idea? PushStyle?... |
@gucio321 I just back to work, let me do some digging, will feedback to you soon. |
The original problem is fixed. I'm going to close this, but @ItsVoltz don't hesitate to open a new issue if you still experience any problems! |
With normal scaling
With 125% scaling:
However its the button positioning with the hardcoded buttonWidth for the two buttons together, is there a better way to dynamically align two buttons to center next to eachother?
The text was updated successfully, but these errors were encountered: