mojira.dev
MC-259387

Buttons and sliders remain selected after clicking on them

The Bug:

Buttons and sliders remain selected after clicking on them.

This issue did not occur in 1.19.3. It first appeared in 23w03a.

Steps to Reproduce:

  1. Navigate to your video settings.

  2. Click on the "Graphics" button and then move your mouse cursor away from it.

  3. Take note as to whether or not buttons and sliders remain selected after clicking on them.

Observed Behavior:

Buttons and sliders remain selected.

Expected Behavior:

Buttons and sliders would not remain selected, just like how they didn't in 1.19.3.

Code Analysis:

Code analysis by @unknown can be found in the duplicate MC-261578:

ContainerEventHandler.java (Mojang mappings, 1.19.4)

@Override
default public boolean mouseClicked(double mouseX, double mouseY, int button) {
    for (GuiEventListener guiEventListener : this.children()) {
        if (!guiEventListener.mouseClicked(mouseX, mouseY, button)) continue;
        this.setFocused(guiEventListener);
        if (button == 0) {
            this.setDragging(true);
        }
        return true;
    }
    return false;
}

Here you can see this.setFocused(guiEventListener) is being invoked on every mouse click. Remember, both Screen and ObjectSelectionList.Entry both implement this interface.

This could be fixed with the following code:

@Override
default public boolean mouseClicked(double mouseX, double mouseY, int button) {
    for (GuiEventListener child : this.children()) {
        if (child.mouseClicked(mouseX, mouseY, button)) {
            if (button == InputConstants.MOUSE_BUTTON_LEFT)
                this.setDragging(true);
            return true;
        }
    }

    return false;
}

However, this would break dragging code as mouseDragged is only passed to the focused element. This could be solved by just iterating through the children like usual, as most mouseDragged implementation have a boolean to check if they are dragging anyway.

Linked issues

MC-296135 I clicked the difficulty changer button, and the borderof the button remained white Resolved MC-274485 Game Menu Buttons keep highlighted after I switch into a new menu Resolved MC-274165 After interacting, UI buttons stay highlighted Resolved MC-275709 Pressed button in Options menu freeze after clicking them, and staying highlighted Resolved MC-277676 Minecraft Widget "bug" Resolved

Attachments

Comments 11

Also appears to affect the Open Pack Folder button (23w06a).

Previously (1.19.3) the button would be deselected when moving the mouse away.

Can confirm: 23w13a.

Can confirm: 23w17a.

Can confirm in 1.20 Release Candidate 1.

1 more comments

also the reason i keep coming back is because this bug drives me crazy, and i wish it gets fixed before 1.20.2

Edit: 2 updates later and it still wasn't fixed

Can confirm in 24w05b.

can confirm in 24w45a

Avoma

(Unassigned)

Confirmed

Platform

Normal

UI

23w04a, 23w06a, 23w07a, 1.19.4 Pre-release 2, 1.19.4 Release Candidate 1, ..., 1.21, 1.21.1, 24w33a, 1.21.4, 1.21.5

Retrieved