Last active
March 9, 2021 03:10
-
-
Save moebiussurfing/ce1f68bd50aa5323cff6975a26c8749b to your computer and use it in GitHub Desktop.
ImGui layout widgets filling width
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (ofxImGui::BeginWindow("TEST", mainSettings, flags)){ | |
ImGui::BeginGroup(); | |
{ | |
int numRows = 2; | |
int numWidgets = 3; | |
float spcx =ImGui::GetStyle().ItemSpacing.x; | |
float spcy =ImGui::GetStyle().ItemSpacing.y; | |
float maxWidth = ImGui::GetContentRegionAvail().x - spcx; | |
float maxHeight = ImGui::GetContentRegionAvail().y - spcy; | |
float mrw = maxWidth / numWidgets - spcx; | |
float mrh = maxHeight / numRows - spcy; | |
if (ImGui::Button("Button 1", ImVec2(mrw, mrh))) | |
{} | |
ImGui::SameLine(); | |
if (ImGui::Button("Button 2", ImVec2(mrw, mrh))) | |
{} | |
ImGui::SameLine(); | |
if (ImGui::Button("Button 3", ImVec2(mrw, mrh))) | |
{} | |
numWidgets = 8; | |
mrw = maxWidth / numWidgets - spcx; | |
for (int i = 0; i< numWidgets; i++) | |
{ | |
std::string n = "b"+ofToString(i); | |
if (ImGui::Button(n.c_str(), ImVec2(mrw, mrh))) | |
{} | |
if (i!=numWidgets-1) ImGui::SameLine(); | |
} | |
} | |
ImGui::EndGroup(); | |
} | |
ofxImGui::EndWindow(mainSettings); |
Author
moebiussurfing
commented
Mar 9, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment