mirror of
https://github.com/ocornut/imgui.git
synced 2024-12-01 02:37:24 +01:00
Fixed GetScrollMaxX(), GetScrollMaxY(). Tweak demo to display more data. Using functions in Begin(). (#1271)
This commit is contained in:
parent
6d60e0fc58
commit
233a6efeba
@ -4205,7 +4205,10 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
}
|
||||
window->Scroll = ImMax(window->Scroll, ImVec2(0.0f, 0.0f));
|
||||
if (!window->Collapsed && !window->SkipItems)
|
||||
window->Scroll = ImMin(window->Scroll, ImMax(ImVec2(0.0f, 0.0f), window->SizeContents - window->SizeFull + window->ScrollbarSizes));
|
||||
{
|
||||
window->Scroll.x = ImMin(window->Scroll.x, GetScrollMaxX());
|
||||
window->Scroll.y = ImMin(window->Scroll.y, GetScrollMaxY());
|
||||
}
|
||||
|
||||
// Modal window darkens what is behind them
|
||||
if ((flags & ImGuiWindowFlags_Modal) != 0 && window == GetFrontMostModalRootWindow())
|
||||
@ -5267,13 +5270,13 @@ float ImGui::GetScrollY()
|
||||
float ImGui::GetScrollMaxX()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindowRead();
|
||||
return window->SizeContents.x - window->SizeFull.x - window->ScrollbarSizes.x;
|
||||
return ImMax(0.0f, window->SizeContents.x - (window->SizeFull.x - window->ScrollbarSizes.x));
|
||||
}
|
||||
|
||||
float ImGui::GetScrollMaxY()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindowRead();
|
||||
return window->SizeContents.y - window->SizeFull.y - window->ScrollbarSizes.y;
|
||||
return ImMax(0.0f, window->SizeContents.y - (window->SizeFull.y - window->ScrollbarSizes.y));
|
||||
}
|
||||
|
||||
void ImGui::SetScrollX(float scroll_x)
|
||||
|
@ -1097,9 +1097,9 @@ void ImGui::ShowTestWindow(bool* p_open)
|
||||
static int track_line = 50, scroll_to_px = 200;
|
||||
ImGui::Checkbox("Track", &track);
|
||||
ImGui::PushItemWidth(100);
|
||||
ImGui::SameLine(130); track |= ImGui::DragInt("##line", &track_line, 0.25f, 0, 99, "Line %.0f");
|
||||
bool scroll_to = ImGui::Button("Scroll To");
|
||||
ImGui::SameLine(130); scroll_to |= ImGui::DragInt("##pos_y", &scroll_to_px, 1.00f, 0, 9999, "y = %.0f px");
|
||||
ImGui::SameLine(130); track |= ImGui::DragInt("##line", &track_line, 0.25f, 0, 99, "Line = %.0f");
|
||||
bool scroll_to = ImGui::Button("Scroll To Pos");
|
||||
ImGui::SameLine(130); scroll_to |= ImGui::DragInt("##pos_y", &scroll_to_px, 1.00f, 0, 9999, "Y = %.0f px");
|
||||
ImGui::PopItemWidth();
|
||||
if (scroll_to) track = false;
|
||||
|
||||
@ -1123,7 +1123,9 @@ void ImGui::ShowTestWindow(bool* p_open)
|
||||
ImGui::Text("Line %d", line);
|
||||
}
|
||||
}
|
||||
float scroll_y = ImGui::GetScrollY(), scroll_max_y = ImGui::GetScrollMaxY();
|
||||
ImGui::EndChild();
|
||||
ImGui::Text("%.0f/%0.f", scroll_y, scroll_max_y);
|
||||
ImGui::EndGroup();
|
||||
}
|
||||
ImGui::TreePop();
|
||||
@ -1158,12 +1160,14 @@ void ImGui::ShowTestWindow(bool* p_open)
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
float scroll_x = ImGui::GetScrollX(), scroll_max_x = ImGui::GetScrollMaxX();
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar(2);
|
||||
float scroll_x_delta = 0.0f;
|
||||
ImGui::SmallButton("<<"); if (ImGui::IsItemActive()) scroll_x_delta = -ImGui::GetIO().DeltaTime * 1000.0f;
|
||||
ImGui::SameLine(); ImGui::Text("Scroll from code"); ImGui::SameLine();
|
||||
ImGui::SmallButton(">>"); if (ImGui::IsItemActive()) scroll_x_delta = +ImGui::GetIO().DeltaTime * 1000.0f;
|
||||
ImGui::SmallButton("<<"); if (ImGui::IsItemActive()) scroll_x_delta = -ImGui::GetIO().DeltaTime * 1000.0f; ImGui::SameLine();
|
||||
ImGui::Text("Scroll from code"); ImGui::SameLine();
|
||||
ImGui::SmallButton(">>"); if (ImGui::IsItemActive()) scroll_x_delta = +ImGui::GetIO().DeltaTime * 1000.0f; ImGui::SameLine();
|
||||
ImGui::Text("%.0f/%.0f", scroll_x, scroll_max_x);
|
||||
if (scroll_x_delta != 0.0f)
|
||||
{
|
||||
ImGui::BeginChild("scrolling"); // Demonstrate a trick: you can use Begin to set yourself in the context of another window (here we are already out of your child window)
|
||||
|
Loading…
Reference in New Issue
Block a user