raysan5 / raygui

A simple and easy-to-use immediate-mode gui library
zlib License
3.36k stars 289 forks source link

Portable window example error #321

Closed Filipp-Druan closed 1 year ago

Filipp-Druan commented 1 year ago

When I run the portable window example and try to drag the window, it start to twitching and flay away from under cursor. I would by happy to add a gif record, but I can't.

raysan5 commented 1 year ago

@Filipp-Druan It seems a platform-dependant issue, it works as expected on Windows and Linux with X-Window system, afaik.

What platform are you trying it?

Filipp-Druan commented 1 year ago

Manjaro Linux XFCE.

raysan5 commented 1 year ago

Manjaro Linux XFCE.

I'm afraid this issue could be related to XFCE desktop environment. There is not much I can do.

AnasASK commented 1 year ago

I noticed the same issue in Pop!_OS Gnome. So it is not only related to xfce.

Lecrapouille commented 11 months ago

I noticed the same issue with Debian 11, running with XFCE. I'll check at the code. Quick investigation: not an OS issue (reproduced on LXDE, Enlightment) !

portable_window.c:

        if (dragWindow)
        {
            windowPosition.x += (mousePosition.x - panOffset.x);
            windowPosition.y += (mousePosition.y - panOffset.y);

           // I added this
            printf("mousePosition: %f, %f. panOffset: %f, %f ==> windowPosition: %f, %f\n",
              mousePosition.x, mousePosition.y, panOffset.x, panOffset.y,
              windowPosition.x, windowPosition.y);

Just clicking on the windows and make a light move, will make the windows sliding while the mouse is pressed:

mousePosition: 195.000000, 7.000000. panOffset: 193.000000, 6.000000 ==> windowPosition: 714.000000, 310.000000
mousePosition: 195.000000, 7.000000. panOffset: 193.000000, 6.000000 ==> windowPosition: 716.000000, 311.000000
mousePosition: 195.000000, 7.000000. panOffset: 193.000000, 6.000000 ==> windowPosition: 718.000000, 312.000000
mousePosition: 195.000000, 7.000000. panOffset: 193.000000, 6.000000 ==> windowPosition: 720.000000, 313.000000
mousePosition: 195.000000, 7.000000. panOffset: 193.000000, 6.000000 ==> windowPosition: 722.000000, 314.000000

I tried to investigate on windowPosition += mousePosition - panOffset:

My attempt:

    Vector2 w;

    while (!exitWindow && !WindowShouldClose())    // Detect window close button or ESC key
    {
        mousePosition = GetMousePosition();
        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !dragWindow)
        {
            if (CheckCollisionPointRec(mousePosition, (Rectangle){ 0, 0, screenWidth, 20 }))
            {
                dragWindow = true;
                panOffset = mousePosition;
                w = GetWindowPosition();
            }
        }

        if (dragWindow)
        {
            windowPosition.x = w.x + (mousePosition.x - panOffset.x);
            windowPosition.y = w.y + (mousePosition.y - panOffset.y);
            SetWindowPosition((int)windowPosition.x, (int)windowPosition.y);
            if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) dragWindow = false;
        }

The sliding effect is gone but flickering effect is present since the windows seems moving slower than the mouse which finally escape. I guess this issue comes from the mouse position is "reseted" when the windows has moved because relative and never < 0. @raysan5 I think the are some remaining issues on the mouse management.

raysan5 commented 11 months ago

@Lecrapouille If the problem is on mouse, why does is work as expected on Windows?

Lecrapouille commented 11 months ago

@raysan5 I should try on Windows, but I'm noob with Windows. I do not know why on Windows it works, it should not work. When I tried to make my 1st example, I got issue with scrolling the list widget (I forget the name) it was the single widget I add: the scroll was also erratic (while with your example full of widget the scroll worked).