Tweaked scrolling example code (#150)
This commit is contained in:
parent
42efc29def
commit
0f9e2f8173
20
imgui.cpp
20
imgui.cpp
@ -11508,7 +11508,7 @@ void ImGui::ShowTestWindow(bool* opened)
|
||||
|
||||
if (ImGui::TreeNode("Scrolling"))
|
||||
{
|
||||
ImGui::TextWrapped("Use SetScrollFromPos() or SetScrollFromCursorPos() to scroll to a given position.");
|
||||
ImGui::TextWrapped("Use SetScrollHere() or SetScrollFromPosY() to scroll to a given position.");
|
||||
static bool track = true;
|
||||
static int track_line = 50, scroll_to_px = 200;
|
||||
ImGui::Checkbox("Track", &track);
|
||||
@ -11517,19 +11517,25 @@ void ImGui::ShowTestWindow(bool* opened)
|
||||
ImGui::SameLine(130); scroll_to |= ImGui::DragInt("##pos_y", &scroll_to_px, 1.00f, 0, 9999, "y = %.0f px");
|
||||
if (scroll_to) track = false;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
if (i > 0) ImGui::SameLine();
|
||||
ImGui::BeginGroup();
|
||||
ImGui::Text(i == 0 ? "Top" : i == 1 ? "Center" : "Bottom");
|
||||
ImGui::BeginChild(ImGui::GetID((void *)i), ImVec2(ImGui::GetWindowWidth() * 0.25f, 200.0f), true);
|
||||
ImGui::Text("%s", i == 0 ? "Top" : i == 1 ? "25%" : i == 2 ? "Center" : i == 3 ? "75%" : "Bottom");
|
||||
ImGui::BeginChild(ImGui::GetID((void *)i), ImVec2(ImGui::GetWindowWidth() * 0.17f, 200.0f), true);
|
||||
if (scroll_to)
|
||||
ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y + scroll_to_px, i * 0.50f);
|
||||
ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y + scroll_to_px, i * 0.25f);
|
||||
for (int line = 0; line < 100; line++)
|
||||
{
|
||||
ImGui::Text("Line %d", line);
|
||||
if (track && line == track_line)
|
||||
ImGui::SetScrollHere(i * 0.50f); // 0.0f:top, 0.5f:center, 1.0f:bottom
|
||||
{
|
||||
ImGui::TextColored(ImColor(255,255,0), "Line %d", line);
|
||||
ImGui::SetScrollHere(i * 0.25f); // 0.0f:top, 0.5f:center, 1.0f:bottom
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::Text("Line %d", line);
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::EndGroup();
|
||||
|
Loading…
Reference in New Issue
Block a user