#Scroll with left mouse button without selection

1 messages · Page 1 of 1 (latest)

hallow vector
#

I made a scroller (ScrollContainer that holds a VBoxContainer) with textures to press and select an option. Each texture has the code below connected to gui_input signal. My problem is that you can't press and drag up to see more options without causing a selection of one of the options. I wonder if there is a way to check if the mouse is being dragged or if its position changed from when it was pressed and when it was released.

public void OnSelect(InputEvent @event)
{
    if (@event is InputEventMouseButton mouseEvent)
    {
        // Only when mouse is pressed; not released
        if (!mouseEvent.Pressed || mouseEvent.ButtonIndex != MouseButton.Left) return;

        EmitSignal(SignalName.PromotionSelected, (int)PieceType);
    }
}
hallow vector
#

A <@&486235350839197726>'s help would be great

hallow vector
#
if (@event is InputEventMouseButton mouseEvent)
{
    // Only when mouse is pressed; not released
    if (mouseEvent.Pressed && mouseEvent.ButtonIndex is MouseButton.Left)
    {
        initialMousePos = mouseEvent.GlobalPosition;
    }

    if (!mouseEvent.Pressed && initialMousePos == mouseEvent.GlobalPosition)
    {
        EmitSignal(SignalName.PromotionSelected, (int)PieceType);
    }
}

will this work? Or is there a better way?

merry sphinx
#

please put your code into a code block as this is very hard to read. Surround your code portion with 3 backticks
```
<code here>
```