浏览代码

Tweaked scrolling example code (#150)

ocornut 10 年之前
父节点
当前提交
0f9e2f8173
共有 1 个文件被更改,包括 13 次插入7 次删除
  1. 13 7
      imgui.cpp

+ 13 - 7
imgui.cpp

@@ -11508,7 +11508,7 @@ void ImGui::ShowTestWindow(bool* opened)
 
 
         if (ImGui::TreeNode("Scrolling"))
         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 bool track = true;
             static int track_line = 50, scroll_to_px = 200;
             static int track_line = 50, scroll_to_px = 200;
             ImGui::Checkbox("Track", &track);
             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");
             ImGui::SameLine(130); scroll_to |= ImGui::DragInt("##pos_y", &scroll_to_px, 1.00f, 0, 9999, "y = %.0f px");
             if (scroll_to) track = false;
             if (scroll_to) track = false;
 
 
-            for (int i = 0; i < 3; i++)
+            for (int i = 0; i < 5; i++)
             {
             {
                 if (i > 0) ImGui::SameLine();
                 if (i > 0) ImGui::SameLine();
                 ImGui::BeginGroup();
                 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)
                 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++)
                 for (int line = 0; line < 100; line++)
                 {
                 {
-                    ImGui::Text("Line %d", line);
                     if (track && line == track_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::EndChild();
                 ImGui::EndGroup();
                 ImGui::EndGroup();