|
@@ -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;
|
|
@@ -20,7 +21,6 @@ import org.openzen.drawablegui.DDrawableInstance;
|
20
|
21
|
import org.openzen.drawablegui.Destructible;
|
21
|
22
|
import org.openzen.drawablegui.listeners.ListenerHandle;
|
22
|
23
|
import org.openzen.drawablegui.live.LiveBool;
|
23
|
|
-import org.openzen.drawablegui.draw.DDrawSurface;
|
24
|
24
|
import org.openzen.drawablegui.draw.DDrawnRectangle;
|
25
|
25
|
import org.openzen.drawablegui.draw.DDrawnText;
|
26
|
26
|
import org.openzen.drawablegui.live.LiveList;
|
|
@@ -38,6 +38,7 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
|
38
|
38
|
|
39
|
39
|
private DComponentContext context;
|
40
|
40
|
private DIRectangle bounds = DIRectangle.EMPTY;
|
|
41
|
+ private float iconScale;
|
41
|
42
|
|
42
|
43
|
private int selectedRow = -1;
|
43
|
44
|
private N selectedNode = null;
|
|
@@ -76,6 +77,7 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
|
76
|
77
|
context = parent.getChildContext("tree", styleClass);
|
77
|
78
|
style = context.getStyle(DTreeViewStyle::new);
|
78
|
79
|
fontMetrics = context.getFontMetrics(style.font);
|
|
80
|
+ iconScale = context.getUIContext().getScale() / 1.75f;
|
79
|
81
|
|
80
|
82
|
background = context.fillRect(0, DIRectangle.EMPTY, style.backgroundColor);
|
81
|
83
|
selectedBackground = context.fillRect(1, DIRectangle.EMPTY, 0);
|
|
@@ -123,7 +125,7 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
|
123
|
125
|
int rowIndex = yToRow(e.y);
|
124
|
126
|
if (rowIndex >= 0 && rowIndex < rows.size()) {
|
125
|
127
|
Row rowEntry = rows.get(rowIndex);
|
126
|
|
- if (e.x >= rowEntry.x && e.x < (rowEntry.x + nodeOpenedIcon.getNominalWidth())) {
|
|
128
|
+ if (e.x >= rowEntry.x && e.x < (rowEntry.x + getIconWidth(nodeOpenedIcon))) {
|
127
|
129
|
if (!rowEntry.node.isLeaf())
|
128
|
130
|
rowEntry.node.isCollapsed().toggle();
|
129
|
131
|
return;
|
|
@@ -142,15 +144,15 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
|
142
|
144
|
int selectionY = bounds.y + style.padding + rowIndex * (style.rowSpacing + fontMetrics.getAscent() + fontMetrics.getDescent()) - style.selectedPaddingTop;
|
143
|
145
|
int selectionWidth = (int)(fontMetrics.getWidth(row.node.getTitle())
|
144
|
146
|
+ style.iconTextSpacing
|
145
|
|
- + row.icon.getNominalWidth()
|
|
147
|
+ + getIconWidth(row.icon)
|
146
|
148
|
+ style.iconTextSpacing
|
147
|
|
- + row.node.getIcon().getNominalWidth()
|
|
149
|
+ + getIconWidth(row.node.getIcon())
|
148
|
150
|
+ style.selectedPaddingLeft
|
149
|
151
|
+ style.selectedPaddingRight);
|
150
|
152
|
int selectionHeight = fontMetrics.getAscent() + fontMetrics.getDescent() + style.selectedPaddingTop + style.selectedPaddingBottom;
|
151
|
153
|
|
152
|
154
|
if (row.node.isLeaf()) {
|
153
|
|
- int delta = (int)(row.icon.getNominalWidth() + style.iconTextSpacing);
|
|
155
|
+ int delta = (int)(getIconWidth(row.icon) + style.iconTextSpacing);
|
154
|
156
|
selectionX += delta;
|
155
|
157
|
selectionWidth -= delta;
|
156
|
158
|
}
|
|
@@ -181,6 +183,22 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
|
181
|
183
|
return (y - bounds.y - style.padding) / (style.rowSpacing + fontMetrics.getAscent() + fontMetrics.getDescent());
|
182
|
184
|
}
|
183
|
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
|
+
|
184
|
202
|
private void updateLayout() {
|
185
|
203
|
int oldRowCount = rows.size();
|
186
|
204
|
|
|
@@ -264,7 +282,7 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
|
264
|
282
|
context.surface,
|
265
|
283
|
context.z + 2,
|
266
|
284
|
node.getIcon(),
|
267
|
|
- DTransform2D.translate(baseX + icon.getNominalWidth() + style.iconTextSpacing, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight()),
|
|
285
|
+ DTransform2D.scaleAndTranslate(baseX + getIconWidth(icon) + style.iconTextSpacing, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - getIconHeight(icon), iconScale),
|
268
|
286
|
node == selectedNode ? style.selectedNodeTextColor : style.nodeTextColor);
|
269
|
287
|
|
270
|
288
|
if (!node.isLeaf())
|
|
@@ -272,13 +290,13 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
|
272
|
290
|
context.surface,
|
273
|
291
|
context.z + 2,
|
274
|
292
|
icon,
|
275
|
|
- DTransform2D.translate(baseX, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight()));
|
|
293
|
+ DTransform2D.scaleAndTranslate(baseX, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - getIconHeight(icon), iconScale));
|
276
|
294
|
|
277
|
295
|
text = context.drawText(
|
278
|
296
|
2,
|
279
|
297
|
style.font,
|
280
|
298
|
node == selectedNode ? style.selectedNodeTextColor : style.nodeTextColor,
|
281
|
|
- baseX + style.iconTextSpacing + icon.getNominalWidth() + style.iconTextSpacing + node.getIcon().getNominalWidth(),
|
|
299
|
+ baseX + style.iconTextSpacing + getIconWidth(icon) + style.iconTextSpacing + getIconWidth(node.getIcon()),
|
282
|
300
|
baseY + fontMetrics.getAscent(),
|
283
|
301
|
node.getTitle());
|
284
|
302
|
}
|
|
@@ -288,15 +306,17 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
|
288
|
306
|
int baseY = (int)(bounds.y + style.padding + index * (fontMetrics.getAscent() + fontMetrics.getDescent() + style.rowSpacing));
|
289
|
307
|
|
290
|
308
|
if (collapseIcon != null) {
|
291
|
|
- collapseIcon.setTransform(DTransform2D.translate(
|
|
309
|
+ collapseIcon.setTransform(DTransform2D.scaleAndTranslate(
|
292
|
310
|
baseX,
|
293
|
|
- baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight()));
|
|
311
|
+ baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - getIconHeight(icon),
|
|
312
|
+ iconScale));
|
294
|
313
|
}
|
295
|
|
- nodeIcon.setTransform(DTransform2D.translate(
|
296
|
|
- baseX + icon.getNominalWidth() + style.iconTextSpacing,
|
297
|
|
- baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight()));
|
|
314
|
+ nodeIcon.setTransform(DTransform2D.scaleAndTranslate(
|
|
315
|
+ baseX + getIconWidth(icon) + style.iconTextSpacing,
|
|
316
|
+ baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - getIconHeight(icon),
|
|
317
|
+ iconScale));
|
298
|
318
|
text.setPosition(
|
299
|
|
- baseX + style.iconTextSpacing + icon.getNominalWidth() + style.iconTextSpacing + node.getIcon().getNominalWidth(),
|
|
319
|
+ baseX + style.iconTextSpacing + getIconWidth(icon) + style.iconTextSpacing + getIconWidth(node.getIcon()),
|
300
|
320
|
baseY + fontMetrics.getAscent());
|
301
|
321
|
}
|
302
|
322
|
|