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.
This commit is contained in:
ocornut 2016-07-16 18:12:41 +02:00
parent 4961b2ea18
commit e215905765

View File

@ -131,11 +131,8 @@
ImGui::NewFrame();
// 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
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)
{
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->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)
{
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;
}