Giter VIP home page Giter VIP logo

Comments (6)

GamingMinds-DanielC avatar GamingMinds-DanielC commented on August 16, 2024 2

You set the content size for the parent window, but give the horizontal scroll bar to the child window which doesn't have a content size specified. Even though the child is embedded into the parent, that are two different windows that you are mixing up.

Btw, just drawing through a draw list doesn't add "content" of which the window logic is aware of. You could also submit a dummy item (f.e. with ImGui::Dummy()) for that purpose.

from imgui.

ocornut avatar ocornut commented on August 16, 2024 1

Daniel is right, but it is also confusing why the only contents of your window is a child window and nothing else (maybe it's due to stripping down the code to reproduce the repro?). If the only content is another window it seems like the nested child may be extraneous.

from imgui.

kotturtech avatar kotturtech commented on August 16, 2024 1

True!
Removing the child and adding ImGuiWindowFlags_HorizontalScrollbar to the parent window did the trick, thanks!
Btw, what I've used as a workaround is to use ImGui::SetCursorPos({20000.0,20000.0}); - Which also solved the problem, but I'm not sure whether the position of the cursor is expressed in pixels, or as a caret position within the window.
In any case, my mistake, after the clarification things work as expected and the issue may be closed.
Thanks everyone!

from imgui.

kotturtech avatar kotturtech commented on August 16, 2024

Interestingly enough, if I change the window and child creation part to the following:

ImGui::SetNextWindowContentSize(ImVec2(25000.0f, 0.0f));
    ImGui::Begin("Scroll Window", NULL);
    ImGui::BeginChild("Child",
                      ImVec2(ImGui::GetContentRegionAvail().x,
                             ImGui::GetContentRegionAvail().y),
                      false, ImGuiWindowFlags_AlwaysHorizontalScrollbar);

The horizontal scroll bar does appear, but still doesn't behave the same as the vertical scroller - It will just be non-functional.
Hope that would help identifying the root cause of the issue

from imgui.

ocornut avatar ocornut commented on August 16, 2024

Btw, what I've used as a workaround is to use ImGui::SetCursorPos({20000.0,20000.0}); - Which also solved the problem, but I'm not sure whether the position of the cursor is expressed in pixels, or as a caret position within the window.

Positions with SetCursorPos() are relatives to upper-left position of window, aka this is a pretty rubbish scheme which I would like to get rid of in v2.0, but nevertheless it is almost never a good idea to use SetCursorPos() with a constant/absolute value.
By calling Dummy({20000,20000}) after Begin() you would state the window has that much of contents and its scrollbar needs to take account of that + padding, which should be the same as calling SetNextWindowContentSize({20000.0f,20000.0f}) before Begin(). All values are currently in pixels.

Quite importantly, however, since 1.89 it is technically obsolete to use SetCursorPos() without an item to extent windows boundaries. See the Breaking Changes explanation of v1.89, but ErrorCheckUsingSetCursorPosToExtendParentBoundaries() if IMGUI_DISABLE_OBSOLETE_FUNCTIONS is not set currently emulate the old behavior.

from imgui.

ocornut avatar ocornut commented on August 16, 2024

Quite importantly, however, since 1.89 it is technically obsolete to use SetCursorPos() without an item to extent windows boundaries. See the Breaking Changes explanation of v1.89, but ErrorCheckUsingSetCursorPosToExtendParentBoundaries() if IMGUI_DISABLE_OBSOLETE_FUNCTIONS is not set currently emulate the old behavior.

For reference, pasting the contents of ErrorCheckUsingSetCursorPosToExtendParentBoundaries() here:

// Until 1.89 (IMGUI_VERSION_NUM < 18814) it was legal to use SetCursorPos() to extend the boundary of a parent (e.g. window or table cell)
// This is causing issues and ambiguity and we need to retire that.
// See https://github.com/ocornut/imgui/issues/5548 for more details.
// [Scenario 1]
//  Previously this would make the window content size ~200x200:
//    Begin(...) + SetCursorScreenPos(GetCursorScreenPos() + ImVec2(200,200)) + End();  // NOT OK
//  Instead, please submit an item:
//    Begin(...) + SetCursorScreenPos(GetCursorScreenPos() + ImVec2(200,200)) + Dummy(ImVec2(0,0)) + End(); // OK
//  Alternative:
//    Begin(...) + Dummy(ImVec2(200,200)) + End(); // OK
// [Scenario 2]
//  For reference this is one of the issue what we aim to fix with this change:
//    BeginGroup() + SomeItem("foobar") + SetCursorScreenPos(GetCursorScreenPos()) + EndGroup()
//  The previous logic made SetCursorScreenPos(GetCursorScreenPos()) have a side-effect! It would erroneously incorporate ItemSpacing.y after the item into content size, making the group taller!
//  While this code is a little twisted, no-one would expect SetXXX(GetXXX()) to have a side-effect. Using vertical alignment patterns could trigger this issue.
void ImGui::ErrorCheckUsingSetCursorPosToExtendParentBoundaries()
{
    ImGuiContext& g = *GImGui;
    ImGuiWindow* window = g.CurrentWindow;
    IM_ASSERT(window->DC.IsSetPos);
    window->DC.IsSetPos = false;
#ifdef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
    if (window->DC.CursorPos.x <= window->DC.CursorMaxPos.x && window->DC.CursorPos.y <= window->DC.CursorMaxPos.y)
        return;
    if (window->SkipItems)
        return;
    IM_ASSERT(0 && "Code uses SetCursorPos()/SetCursorScreenPos() to extend window/parent boundaries. Please submit an item e.g. Dummy() to validate extent.");
#else
    window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos);
#endif
}

It is expected that near the end of this year (two years after 1.89.0) the #else block is removed and replaced by the other block.

from imgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.