@@ -25,6 +25,7 @@ public final class StringDropdownComponent extends Component
2525 private static final ClickGui GUI = WurstClient .INSTANCE .getGui ();
2626 private static final Font TR = WurstClient .MC .font ;
2727 private static final int ARROW_SIZE = 11 ;
28+ private static final int LABEL_HEIGHT = 11 ;
2829
2930 private final StringDropdownSetting setting ;
3031 private StringDropdownPopup popup ;
@@ -40,11 +41,16 @@ public StringDropdownComponent(StringDropdownSetting setting)
4041 public void handleMouseClick (double mouseX , double mouseY , int mouseButton ,
4142 MouseButtonEvent context )
4243 {
43- int popupWidth = computePopupWidth ();
44+ double localX = mouseX - getX ();
45+ double localY = mouseY - getY ();
46+ if (localX < 0 || localX >= getWidth ())
47+ return ;
4448
45- if (mouseX < getX () + getWidth () - popupWidth - ARROW_SIZE - 4 )
49+ if (localY < LABEL_HEIGHT )
4650 return ;
4751
52+ int popupWidth = computePopupWidth ();
53+
4854 switch (mouseButton )
4955 {
5056 case GLFW .GLFW_MOUSE_BUTTON_LEFT :
@@ -87,35 +93,36 @@ public void render(GuiGraphics context, int mouseX, int mouseY,
8793 int popupWidth = computePopupWidth ();
8894 int x1 = getX ();
8995 int x2 = x1 + getWidth ();
90- int x3 = x2 - ARROW_SIZE ;
91- int x4 = x3 - popupWidth - 4 ;
92- int y1 = getY () ;
93- int y2 = y1 + getHeight () ;
96+ int boxY1 = getY () + LABEL_HEIGHT ;
97+ int boxY2 = boxY1 + ARROW_SIZE ;
98+ int arrowX1 = x2 - ARROW_SIZE ;
99+ int arrowX2 = x2 ;
94100
95101 boolean hovering = isHovering (mouseX , mouseY );
96- boolean hText = hovering && mouseX < x4 ;
97- boolean hBox = hovering && mouseX >= x4 ;
102+ boolean hText = hovering && mouseY < boxY1 ;
103+ boolean hBox = hovering && mouseY >= boxY1 ;
98104
99105 if (hText )
100106 GUI .setTooltip (setting .getWrappedDescription (200 ));
101107
102- context .fill (x1 , y1 , x4 , y2 , getFillColor (false ));
103- context .fill (x4 , y1 , x2 , y2 , getFillColor (hBox ));
108+ context .fill (x1 , getY (), x2 , boxY1 , getFillColor (false ));
109+ context .fill (x1 , boxY1 , x2 , boxY2 , getFillColor (hBox ));
104110
105111 context .guiRenderState .up ();
106112
107113 int outlineColor = RenderUtils .toIntColor (GUI .getAcColor (), 0.5F );
108- RenderUtils .drawBorder2D (context , x4 , y1 , x2 , y2 , outlineColor );
109- RenderUtils .drawLine2D (context , x3 , y1 , x3 , y2 , outlineColor );
114+ RenderUtils .drawBorder2D (context , x1 , boxY1 , x2 , boxY2 , outlineColor );
115+ RenderUtils .drawLine2D (context , arrowX1 , boxY1 , arrowX1 , boxY2 ,
116+ outlineColor );
110117
111- ClickGuiIcons .drawMinimizeArrow (context , x3 , y1 + 0.5F , x2 , y2 - 0.5F ,
112- hBox , !isPopupOpen ());
118+ ClickGuiIcons .drawMinimizeArrow (context , arrowX1 , boxY1 + 0.5F , arrowX2 ,
119+ boxY2 - 0.5F , hBox , !isPopupOpen ());
113120
114121 String name = setting .getName ();
115122 String value = setting .getSelected ();
116123 int txtColor = GUI .getTxtColor ();
117- context .drawString (TR , name , x1 , y1 + 2 , txtColor , false );
118- context .drawString (TR , value , x4 + 2 , y1 + 2 , txtColor , false );
124+ context .drawString (TR , name , x1 , getY () + 2 , txtColor , false );
125+ context .drawString (TR , value , x1 + 2 , boxY1 + 2 , txtColor , false );
119126 }
120127
121128 private int computePopupWidth ()
@@ -134,12 +141,14 @@ private int getFillColor(boolean hovering)
134141 public int getDefaultWidth ()
135142 {
136143 int popupWidth = computePopupWidth ();
137- return TR .width (setting .getName ()) + popupWidth + ARROW_SIZE + 6 ;
144+ int boxWidth = popupWidth + ARROW_SIZE + 6 ;
145+ int labelWidth = TR .width (setting .getName ()) + 4 ;
146+ return Math .max (labelWidth , boxWidth );
138147 }
139148
140149 @ Override
141150 public int getDefaultHeight ()
142151 {
143- return ARROW_SIZE ;
152+ return LABEL_HEIGHT + ARROW_SIZE ;
144153 }
145154}
0 commit comments