Bläddra i källkod

Fixed scrolling offset when using SetScrollY(), SetScrollFromPosY(), SetScrollHere() with menu bar.
Tests:
a) add SetScrollY(+20) after Begin("ImGui Demo") test with/without title/menu.
b) add ImGuiWindowFlags_MenuBar in BeginChild() in scrolling tracking demo.

ocornut 9 år sedan
förälder
incheckning
e215905765
1 ändrade filer med 4 tillägg och 7 borttagningar
  1. 4 7
      imgui.cpp

+ 4 - 7
imgui.cpp

@@ -131,11 +131,8 @@
             ImGui::NewFrame();
             ImGui::NewFrame();
 
 
             // 3) most of your application code here
             // 3) most of your application code here
-            ImGui::Begin("My window");
-            ImGui::Text("Hello, world.");
-            ImGui::End();
-            MyGameUpdate(); // may use ImGui functions
-            MyGameRender(); // may use ImGui functions
+            MyGameUpdate(); // may use any ImGui functions, e.g. ImGui::Begin("My window"); ImGui::Text("Hello, world!"); ImGui::End();
+            MyGameRender(); // may use any ImGui functions
 
 
             // 4) render & swap video buffers
             // 4) render & swap video buffers
             ImGui::Render();
             ImGui::Render();
@@ -4101,7 +4098,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
         if (window->ScrollTarget.y < FLT_MAX)
         if (window->ScrollTarget.y < FLT_MAX)
         {
         {
             float center_ratio = window->ScrollTargetCenterRatio.y;
             float center_ratio = window->ScrollTargetCenterRatio.y;
-            window->Scroll.y = window->ScrollTarget.y - ((1.0f - center_ratio) * window->TitleBarHeight()) - (center_ratio * window->SizeFull.y);
+            window->Scroll.y = window->ScrollTarget.y - ((1.0f - center_ratio) * (window->TitleBarHeight() + window->MenuBarHeight())) - (center_ratio * window->SizeFull.y);
             window->ScrollTarget.y = FLT_MAX;
             window->ScrollTarget.y = FLT_MAX;
         }
         }
         window->Scroll = ImMax(window->Scroll, ImVec2(0.0f, 0.0f));
         window->Scroll = ImMax(window->Scroll, ImVec2(0.0f, 0.0f));
@@ -5172,7 +5169,7 @@ void ImGui::SetScrollX(float scroll_x)
 void ImGui::SetScrollY(float scroll_y)
 void ImGui::SetScrollY(float scroll_y)
 {
 {
     ImGuiWindow* window = GetCurrentWindow();
     ImGuiWindow* window = GetCurrentWindow();
-    window->ScrollTarget.y = scroll_y + window->TitleBarHeight(); // title bar height canceled out when using ScrollTargetRelY
+    window->ScrollTarget.y = scroll_y + window->TitleBarHeight() + window->MenuBarHeight(); // title bar height canceled out when using ScrollTargetRelY
     window->ScrollTargetCenterRatio.y = 0.0f;
     window->ScrollTargetCenterRatio.y = 0.0f;
 }
 }