mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Window rectangles: Changed WorkRect to cover the whole region including scrolling (toward obsolete ContentsRegionRect) + using full WindowPadding*1 padding.
Tweaked InnerClipRect. TreeNode, CollapsingHeader: Fixed highlight frame not covering horizontal area fully when using horizontal scrolling. (#2211, #2579) TabBar: Fixed BeginTabBar() within a window with horizontal scrolling from creating a feedback loop with the horizontal contents size. Columns: Fixed Columns() within a window with horizontal scrolling from not covering the full horizontal area (previously only worked with an explicit contents size). (#125) Demo: Added demo code to test contentsrect/workrect
This commit is contained in:
@ -17,9 +17,18 @@
|
||||
// In this demo code, we frequently we use 'static' variables inside functions. A static variable persist across calls, so it is
|
||||
// essentially like a global variable but declared inside the scope of the function. We do this as a way to gather code and data
|
||||
// in the same place, to make the demo source code faster to read, faster to write, and smaller in size.
|
||||
// It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be reentrant
|
||||
// or used in threads. This might be a pattern you will want to use in your code, but most of the real data you would be editing is
|
||||
// likely going to be stored outside your functions.
|
||||
// It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be
|
||||
// reentrant or used in multiple threads. This might be a pattern you will want to use in your code, but most of the real data
|
||||
// you would be editing is likely going to be stored outside your functions.
|
||||
|
||||
// The Demo code is this file is designed to be easy to copy-and-paste in into your application!
|
||||
// Because of this:
|
||||
// - We never omit the ImGui:: namespace when calling functions, even though most of our code is already in the same namespace.
|
||||
// - We try to declare static variables in the local scope, as close as possible to the code using them.
|
||||
// - We never use any of the helpers/facilities used internally by dear imgui, unless it has been exposed in the public API (imgui.h).
|
||||
// - We never use maths operators on ImVec2/ImVec4. For other imgui sources files, they are provided by imgui_internal.h w/ IMGUI_DEFINE_MATH_OPERATORS,
|
||||
// for your own sources file they are optional and require you either enable those, either provide your own via IM_VEC2_CLASS_EXTRA in imconfig.h.
|
||||
// Because we don't want to assume anything about your support of maths operators, we don't use them in imgui_demo.cpp.
|
||||
|
||||
/*
|
||||
|
||||
@ -2135,6 +2144,83 @@ static void ShowDemoWindowLayout()
|
||||
ImGui::SetScrollX(ImGui::GetScrollX() + scroll_x_delta);
|
||||
ImGui::EndChild();
|
||||
}
|
||||
ImGui::Spacing();
|
||||
|
||||
static bool show_horizontal_contents_size_demo_window = false;
|
||||
ImGui::Checkbox("Show Horizontal contents size demo window", &show_horizontal_contents_size_demo_window);
|
||||
|
||||
if (show_horizontal_contents_size_demo_window)
|
||||
{
|
||||
static bool show_h_scrollbar = true;
|
||||
static bool show_button = true;
|
||||
static bool show_tree_nodes = true;
|
||||
static bool show_columns = true;
|
||||
static bool show_tab_bar = true;
|
||||
static bool explicit_content_size = false;
|
||||
static float contents_size_x = 300.0f;
|
||||
if (explicit_content_size)
|
||||
ImGui::SetNextWindowContentSize(ImVec2(contents_size_x, 0.0f));
|
||||
ImGui::Begin("Horizontal contents size demo window", &show_horizontal_contents_size_demo_window, show_h_scrollbar ? ImGuiWindowFlags_HorizontalScrollbar : 0);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(2, 0));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2, 0));
|
||||
HelpMarker("Test of different widgets react and impact the work rectangle growing when horizontal scrolling is enabled.\n\nUse 'Metrics->Tools->Show windows rectangles' to visualize rectangles.");
|
||||
ImGui::Checkbox("H-scrollbar", &show_h_scrollbar);
|
||||
ImGui::Checkbox("Button", &show_button); // Will grow contents size (unless explicitly overwritten)
|
||||
ImGui::Checkbox("Tree nodes", &show_tree_nodes); // Will grow contents size and display highlight over full width
|
||||
ImGui::Checkbox("Columns", &show_columns); // Will use contents size
|
||||
ImGui::Checkbox("Tab bar", &show_tab_bar); // Will use contents size
|
||||
ImGui::Checkbox("Explicit content size", &explicit_content_size);
|
||||
if (explicit_content_size)
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(100);
|
||||
ImGui::DragFloat("##csx", &contents_size_x);
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(p, ImVec2(p.x + 10, p.y + 10), IM_COL32_WHITE);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(p.x + contents_size_x - 10, p.y), ImVec2(p.x + contents_size_x, p.y + 10), IM_COL32_WHITE);
|
||||
ImGui::Dummy(ImVec2(0, 10));
|
||||
}
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::Separator();
|
||||
if (show_button)
|
||||
{
|
||||
ImGui::Button("this is a 300-wide button", ImVec2(300, 0));
|
||||
}
|
||||
if (show_tree_nodes)
|
||||
{
|
||||
bool open = true;
|
||||
if (ImGui::TreeNode("this is a tree node"))
|
||||
{
|
||||
if (ImGui::TreeNode("another one of those tree node..."))
|
||||
{
|
||||
ImGui::Text("Some tree contents");
|
||||
ImGui::TreePop();
|
||||
}
|
||||
ImGui::TreePop();
|
||||
}
|
||||
ImGui::CollapsingHeader("CollapsingHeader", &open);
|
||||
}
|
||||
if (show_columns)
|
||||
{
|
||||
ImGui::Columns(4);
|
||||
for (int n = 0; n < 4; n++)
|
||||
{
|
||||
ImGui::Text("Width %.2f", ImGui::GetColumnWidth());
|
||||
ImGui::NextColumn();
|
||||
}
|
||||
ImGui::Columns(1);
|
||||
}
|
||||
if (show_tab_bar && ImGui::BeginTabBar("Hello"))
|
||||
{
|
||||
if (ImGui::BeginTabItem("OneOneOne")) { ImGui::EndTabItem(); }
|
||||
if (ImGui::BeginTabItem("TwoTwoTwo")) { ImGui::EndTabItem(); }
|
||||
if (ImGui::BeginTabItem("ThreeThreeThree")) { ImGui::EndTabItem(); }
|
||||
if (ImGui::BeginTabItem("FourFourFour")) { ImGui::EndTabItem(); }
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user