mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Scrolling, Nav: Fixed programmatic scroll leading to a slightly incorrect scroll offset when the window has decorations or a menu-bar (broken in 1.71). This was mostly noticeable when a keyboard/gamepad movement led to scrolling the view, or using e.g. SetScrollHereY() function. Fix/amend a0994d74
.
This commit is contained in:
@ -2066,8 +2066,14 @@ static void ShowDemoWindowLayout()
|
||||
|
||||
static int track_item = 50;
|
||||
static bool enable_track = true;
|
||||
static bool enable_extra_decorations = false;
|
||||
static float scroll_to_off_px = 0.0f;
|
||||
static float scroll_to_pos_px = 200.0f;
|
||||
|
||||
ImGui::Checkbox("Decoration", &enable_extra_decorations);
|
||||
ImGui::SameLine();
|
||||
HelpMarker("We expose this for testing because scrolling sometimes had issues with window decoration such as menu-bars.");
|
||||
|
||||
ImGui::Checkbox("Track", &enable_track);
|
||||
ImGui::PushItemWidth(100);
|
||||
ImGui::SameLine(140); enable_track |= ImGui::DragInt("##item", &track_item, 0.25f, 0, 99, "Item = %d");
|
||||
@ -2076,7 +2082,7 @@ static void ShowDemoWindowLayout()
|
||||
ImGui::SameLine(140); scroll_to_off |= ImGui::DragFloat("##off", &scroll_to_off_px, 1.00f, 0, 9999, "+%.0f px");
|
||||
|
||||
bool scroll_to_pos = ImGui::Button("Scroll To Pos");
|
||||
ImGui::SameLine(140); scroll_to_pos |= ImGui::DragFloat("##pos", &scroll_to_pos_px, 1.00f, 0, 9999, "X/Y = %.0f px");
|
||||
ImGui::SameLine(140); scroll_to_pos |= ImGui::DragFloat("##pos", &scroll_to_pos_px, 1.00f, -10, 9999, "X/Y = %.0f px");
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
if (scroll_to_off || scroll_to_pos)
|
||||
@ -2094,7 +2100,13 @@ static void ShowDemoWindowLayout()
|
||||
const char* names[] = { "Top", "25%", "Center", "75%", "Bottom" };
|
||||
ImGui::TextUnformatted(names[i]);
|
||||
|
||||
ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(child_w, 200.0f), true, ImGuiWindowFlags_None);
|
||||
ImGuiWindowFlags child_flags = enable_extra_decorations ? ImGuiWindowFlags_MenuBar : 0;
|
||||
ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(child_w, 200.0f), true, child_flags);
|
||||
if (ImGui::BeginMenuBar())
|
||||
{
|
||||
ImGui::TextUnformatted("abc");
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
if (scroll_to_off)
|
||||
ImGui::SetScrollY(scroll_to_off_px);
|
||||
if (scroll_to_pos)
|
||||
@ -2126,7 +2138,8 @@ static void ShowDemoWindowLayout()
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
float child_height = ImGui::GetTextLineHeight() + style.ScrollbarSize + style.WindowPadding.y * 2.0f;
|
||||
ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(-100, child_height), true, ImGuiWindowFlags_HorizontalScrollbar);
|
||||
ImGuiWindowFlags child_flags = ImGuiWindowFlags_HorizontalScrollbar | (enable_extra_decorations ? ImGuiWindowFlags_AlwaysVerticalScrollbar : 0);
|
||||
ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(-100, child_height), true, child_flags);
|
||||
if (scroll_to_off)
|
||||
ImGui::SetScrollX(scroll_to_off_px);
|
||||
if (scroll_to_pos)
|
||||
|
Reference in New Issue
Block a user