Skip to content

Instantly share code, notes, and snippets.

@moebiussurfing
Last active March 9, 2021 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moebiussurfing/ce1f68bd50aa5323cff6975a26c8749b to your computer and use it in GitHub Desktop.
Save moebiussurfing/ce1f68bd50aa5323cff6975a26c8749b to your computer and use it in GitHub Desktop.
ImGui layout widgets filling width
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);
@moebiussurfing
Copy link
Author

imgui

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment