Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-259387

Buttons and sliders remain selected after clicking on them

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 23w04a, 23w06a, 23w07a, 1.19.4 Pre-release 2, 1.19.4 Release Candidate 1, 1.19.4, 23w12a, 23w13a, 23w14a, 23w16a, 1.20 Pre-release 1, 1.20 Pre-release 4, 1.20 Release Candidate 1, 1.20, 1.20.1, 1.20.2, 1.20.4, 23w51b, 24w05b, 24w09a, 24w10a, 24w14a, 24w20a, 1.21 Pre-Release 2, 1.21, 24w33a, 1.21.1
    • None
    • Confirmed
    • UI
    • Normal
    • Platform

      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 isXander 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.

        1. MC-259387 - Analysis.mp4
          3.99 MB
          [Mod] Avoma
        2. MC-259387 - Behavior in ≤ 1.19.3.png
          638 kB
          [Mod] Avoma
        3. MC-259387 - Behavior in ≥ 23w03a.png
          623 kB
          [Mod] Avoma
        4. resource pack menu.mp4
          4.17 MB
          mattp_12

            Unassigned Unassigned
            Avoma [Mod] Avoma
            Votes:
            38 Vote for this issue
            Watchers:
            19 Start watching this issue

              Created:
              Updated:
              CHK: