Explorar el Código

More scalability fixes

Stan Hebben hace 6 años
padre
commit
39a526b42f

+ 28
- 11
DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeView.java Ver fichero

@@ -7,6 +7,7 @@ package org.openzen.drawablegui.tree;
7 7
 
8 8
 import java.util.ArrayList;
9 9
 import java.util.List;
10
+import org.openzen.drawablegui.DColorableIcon;
10 11
 import org.openzen.drawablegui.DColorableIconInstance;
11 12
 import org.openzen.drawablegui.DComponent;
12 13
 import org.openzen.drawablegui.DComponentContext;
@@ -124,7 +125,7 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
124 125
 		int rowIndex = yToRow(e.y);
125 126
 		if (rowIndex >= 0 && rowIndex < rows.size()) {
126 127
 			Row rowEntry = rows.get(rowIndex);
127
-			if (e.x >= rowEntry.x && e.x < (rowEntry.x + nodeOpenedIcon.getNominalWidth())) {
128
+			if (e.x >= rowEntry.x && e.x < (rowEntry.x + getIconWidth(nodeOpenedIcon))) {
128 129
 				if (!rowEntry.node.isLeaf())
129 130
 					rowEntry.node.isCollapsed().toggle();
130 131
 				return;
@@ -143,15 +144,15 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
143 144
 				int selectionY = bounds.y + style.padding + rowIndex * (style.rowSpacing + fontMetrics.getAscent() + fontMetrics.getDescent()) - style.selectedPaddingTop;
144 145
 				int selectionWidth = (int)(fontMetrics.getWidth(row.node.getTitle())
145 146
 						+ style.iconTextSpacing
146
-						+ row.icon.getNominalWidth()
147
+						+ getIconWidth(row.icon)
147 148
 						+ style.iconTextSpacing
148
-						+ row.node.getIcon().getNominalWidth()
149
+						+ getIconWidth(row.node.getIcon())
149 150
 						+ style.selectedPaddingLeft
150 151
 						+ style.selectedPaddingRight);
151 152
 				int selectionHeight = fontMetrics.getAscent() + fontMetrics.getDescent() + style.selectedPaddingTop + style.selectedPaddingBottom;
152 153
 				
153 154
 				if (row.node.isLeaf()) {
154
-					int delta = (int)(row.icon.getNominalWidth() + style.iconTextSpacing);
155
+					int delta = (int)(getIconWidth(row.icon) + style.iconTextSpacing);
155 156
 					selectionX += delta;
156 157
 					selectionWidth -= delta;
157 158
 				}
@@ -182,6 +183,22 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
182 183
 		return (y - bounds.y - style.padding) / (style.rowSpacing + fontMetrics.getAscent() + fontMetrics.getDescent());
183 184
 	}
184 185
 	
186
+	private float getIconWidth(DDrawable drawable) {
187
+		return drawable.getNominalWidth() * iconScale;
188
+	}
189
+	
190
+	private float getIconHeight(DDrawable drawable) {
191
+		return drawable.getNominalHeight() * iconScale; 
192
+	}
193
+	
194
+	private float getIconWidth(DColorableIcon icon) {
195
+		return icon.getNominalWidth() * iconScale;
196
+	}
197
+	
198
+	private float getIconHeight(DColorableIcon icon) {
199
+		return icon.getNominalHeight() * iconScale; 
200
+	}
201
+	
185 202
 	private void updateLayout() {
186 203
 		int oldRowCount = rows.size();
187 204
 		
@@ -265,7 +282,7 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
265 282
 					context.surface,
266 283
 					context.z + 2,
267 284
 					node.getIcon(),
268
-					DTransform2D.scaleAndTranslate(baseX + icon.getNominalWidth() + style.iconTextSpacing, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight(), iconScale),
285
+					DTransform2D.scaleAndTranslate(baseX + getIconWidth(icon) + style.iconTextSpacing, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - getIconHeight(icon), iconScale),
269 286
 					node == selectedNode ? style.selectedNodeTextColor : style.nodeTextColor);
270 287
 			
271 288
 			if (!node.isLeaf())
@@ -273,13 +290,13 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
273 290
 						context.surface, 
274 291
 						context.z + 2,
275 292
 						icon,
276
-						DTransform2D.scaleAndTranslate(baseX, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight(), iconScale));
293
+						DTransform2D.scaleAndTranslate(baseX, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - getIconHeight(icon), iconScale));
277 294
 			
278 295
 			text = context.drawText(
279 296
 					2,
280 297
 					style.font,
281 298
 					node == selectedNode ? style.selectedNodeTextColor : style.nodeTextColor,
282
-					baseX + style.iconTextSpacing + icon.getNominalWidth() + style.iconTextSpacing + node.getIcon().getNominalWidth(),
299
+					baseX + style.iconTextSpacing + getIconWidth(icon) + style.iconTextSpacing + getIconWidth(node.getIcon()),
283 300
 					baseY + fontMetrics.getAscent(),
284 301
 					node.getTitle());
285 302
 		}
@@ -291,15 +308,15 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
291 308
 			if (collapseIcon != null) {
292 309
 				collapseIcon.setTransform(DTransform2D.scaleAndTranslate(
293 310
 						baseX,
294
-						baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight(),
311
+						baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - getIconHeight(icon),
295 312
 						iconScale));
296 313
 			}
297 314
 			nodeIcon.setTransform(DTransform2D.scaleAndTranslate(
298
-					baseX + icon.getNominalWidth() + style.iconTextSpacing,
299
-					baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight(),
315
+					baseX + getIconWidth(icon) + style.iconTextSpacing,
316
+					baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - getIconHeight(icon),
300 317
 					iconScale));
301 318
 			text.setPosition(
302
-					baseX + style.iconTextSpacing + icon.getNominalWidth() + style.iconTextSpacing + node.getIcon().getNominalWidth(),
319
+					baseX + style.iconTextSpacing + getIconWidth(icon) + style.iconTextSpacing + getIconWidth(node.getIcon()),
303 320
 					baseY + fontMetrics.getAscent());
304 321
 		}
305 322
 

Loading…
Cancelar
Guardar