Browse Source

Implemented some code improvements on the IDE. Preparing work for tooltips.

Stan Hebben 6 years ago
parent
commit
f3a01ec07f
43 changed files with 475 additions and 220 deletions
  1. 5
    5
      DrawableGui/src/main/java/org/openzen/drawablegui/DButton.java
  2. 0
    3
      DrawableGui/src/main/java/org/openzen/drawablegui/DColorableIcon.java
  3. 1
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/DComponent.java
  4. 3
    4
      DrawableGui/src/main/java/org/openzen/drawablegui/DEmptyView.java
  5. 17
    16
      DrawableGui/src/main/java/org/openzen/drawablegui/DHorizontalLayout.java
  6. 5
    5
      DrawableGui/src/main/java/org/openzen/drawablegui/DInputField.java
  7. 5
    5
      DrawableGui/src/main/java/org/openzen/drawablegui/DLabel.java
  8. 12
    11
      DrawableGui/src/main/java/org/openzen/drawablegui/DSideLayout.java
  9. 11
    4
      DrawableGui/src/main/java/org/openzen/drawablegui/DSizing.java
  10. 122
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DTooltip.java
  11. 32
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DTooltipStyle.java
  12. 4
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DUIContext.java
  13. 19
    18
      DrawableGui/src/main/java/org/openzen/drawablegui/DVerticalLayout.java
  14. 65
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DCompositeBorder.java
  15. 4
    4
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DCustomWindowBorder.java
  16. 0
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DEmptyBorder.java
  17. 0
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DLineBorder.java
  18. 10
    10
      DrawableGui/src/main/java/org/openzen/drawablegui/form/DForm.java
  19. 0
    5
      DrawableGui/src/main/java/org/openzen/drawablegui/live/ImmutableLiveObject.java
  20. 0
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveObject.java
  21. 14
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/live/MutableLiveObject.java
  22. 1
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/live/SimpleLiveObject.java
  23. 8
    8
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollBar.java
  24. 7
    8
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java
  25. 0
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPaneStyle.java
  26. 2
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingDialog.java
  27. 3
    3
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingGraphicsContext.java
  28. 2
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingWindow.java
  29. 7
    9
      DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeView.java
  30. 2
    2
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectBar.java
  31. 4
    4
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java
  32. 3
    1
      IDE/src/main/java/org/openzen/zenscript/ide/ui/dialog/CreateSourceFileDialog.java
  33. 5
    5
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/IconButtonControl.java
  34. 4
    4
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/StatusBarView.java
  35. 7
    7
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedView.java
  36. 11
    11
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTab.java
  37. 6
    8
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTabClose.java
  38. 2
    2
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java
  39. 6
    7
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButton.java
  40. 1
    1
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarStyle.java
  41. 21
    24
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarView.java
  42. 6
    6
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/WindowActionButton.java
  43. 38
    9
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java

+ 5
- 5
DrawableGui/src/main/java/org/openzen/drawablegui/DButton.java View File

8
 import org.openzen.drawablegui.live.LiveBool;
8
 import org.openzen.drawablegui.live.LiveBool;
9
 import org.openzen.drawablegui.live.LiveObject;
9
 import org.openzen.drawablegui.live.LiveObject;
10
 import org.openzen.drawablegui.live.LiveString;
10
 import org.openzen.drawablegui.live.LiveString;
11
-import org.openzen.drawablegui.live.SimpleLiveObject;
11
+import org.openzen.drawablegui.live.MutableLiveObject;
12
 import org.openzen.drawablegui.style.DShadow;
12
 import org.openzen.drawablegui.style.DShadow;
13
 import org.openzen.drawablegui.style.DStyleClass;
13
 import org.openzen.drawablegui.style.DStyleClass;
14
 import org.openzen.drawablegui.style.DStylePath;
14
 import org.openzen.drawablegui.style.DStylePath;
20
 public class DButton implements DComponent {
20
 public class DButton implements DComponent {
21
 	private final DStyleClass styleClass;
21
 	private final DStyleClass styleClass;
22
 	private final LiveString label;
22
 	private final LiveString label;
23
-	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
23
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
24
 	private final LiveBool disabled;
24
 	private final LiveBool disabled;
25
 	private final Runnable action;
25
 	private final Runnable action;
26
 	
26
 	
48
 		this.style = new DButtonStyle(context.getStylesheets().get(context, path));
48
 		this.style = new DButtonStyle(context.getStylesheets().get(context, path));
49
 		fontMetrics = context.getFontMetrics(style.font);
49
 		fontMetrics = context.getFontMetrics(style.font);
50
 		
50
 		
51
-		dimensionPreferences.setValue(new DDimensionPreferences(
51
+		sizing.setValue(new DSizing(
52
 				style.paddingLeft + style.paddingRight + fontMetrics.getWidth(label.getValue()),
52
 				style.paddingLeft + style.paddingRight + fontMetrics.getWidth(label.getValue()),
53
 				style.paddingTop + style.paddingBottom + fontMetrics.getAscent() + fontMetrics.getDescent()));
53
 				style.paddingTop + style.paddingBottom + fontMetrics.getAscent() + fontMetrics.getDescent()));
54
 	}
54
 	}
55
 
55
 
56
 	@Override
56
 	@Override
57
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
58
-		return dimensionPreferences;
57
+	public LiveObject<DSizing> getSizing() {
58
+		return sizing;
59
 	}
59
 	}
60
 
60
 
61
 	@Override
61
 	@Override

+ 0
- 3
DrawableGui/src/main/java/org/openzen/drawablegui/DColorableIcon.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui;
6
 package org.openzen.drawablegui;
7
 
7
 
8
-import org.openzen.drawablegui.DCanvas;
9
-import org.openzen.drawablegui.DTransform2D;
10
-
11
 /**
8
 /**
12
  *
9
  *
13
  * @author Hoofdgebruiker
10
  * @author Hoofdgebruiker

+ 1
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/DComponent.java View File

16
 public interface DComponent extends Closeable {
16
 public interface DComponent extends Closeable {
17
 	void setContext(DStylePath parent, DUIContext context);
17
 	void setContext(DStylePath parent, DUIContext context);
18
 	
18
 	
19
-	LiveObject<DDimensionPreferences> getDimensionPreferences();
19
+	LiveObject<DSizing> getSizing();
20
 	
20
 	
21
 	DIRectangle getBounds();
21
 	DIRectangle getBounds();
22
 	
22
 	

+ 3
- 4
DrawableGui/src/main/java/org/openzen/drawablegui/DEmptyView.java View File

16
 public class DEmptyView implements DComponent {
16
 public class DEmptyView implements DComponent {
17
 	public static final DEmptyView INSTANCE = new DEmptyView();
17
 	public static final DEmptyView INSTANCE = new DEmptyView();
18
 	
18
 	
19
-	private static final LiveObject<DDimensionPreferences> DIMENSION = new ImmutableLiveObject(new DDimensionPreferences(0, 0));
20
-	private static final DIRectangle NO_BOUNDS = new DIRectangle(0, 0, 0, 0);
19
+	private static final LiveObject<DSizing> DIMENSION = new ImmutableLiveObject(DSizing.EMPTY);
21
 	
20
 	
22
 	private DEmptyView() {}
21
 	private DEmptyView() {}
23
 
22
 
27
 	}
26
 	}
28
 	
27
 	
29
 	@Override
28
 	@Override
30
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
29
+	public LiveObject<DSizing> getSizing() {
31
 		return DIMENSION;
30
 		return DIMENSION;
32
 	}
31
 	}
33
 	
32
 	
34
 	@Override
33
 	@Override
35
 	public DIRectangle getBounds() {
34
 	public DIRectangle getBounds() {
36
-		return NO_BOUNDS;
35
+		return DIRectangle.EMPTY;
37
 	}
36
 	}
38
 
37
 
39
 	@Override
38
 	@Override

+ 17
- 16
DrawableGui/src/main/java/org/openzen/drawablegui/DHorizontalLayout.java View File

9
 import java.util.function.Predicate;
9
 import java.util.function.Predicate;
10
 import org.openzen.drawablegui.listeners.ListenerHandle;
10
 import org.openzen.drawablegui.listeners.ListenerHandle;
11
 import org.openzen.drawablegui.live.LiveObject;
11
 import org.openzen.drawablegui.live.LiveObject;
12
+import org.openzen.drawablegui.live.MutableLiveObject;
12
 import org.openzen.drawablegui.live.SimpleLiveObject;
13
 import org.openzen.drawablegui.live.SimpleLiveObject;
13
 import org.openzen.drawablegui.style.DStyleClass;
14
 import org.openzen.drawablegui.style.DStyleClass;
14
 import org.openzen.drawablegui.style.DStylePath;
15
 import org.openzen.drawablegui.style.DStylePath;
21
 	private final DStyleClass styleClass;
22
 	private final DStyleClass styleClass;
22
 	private final Alignment alignment;
23
 	private final Alignment alignment;
23
 	private final Element[] components;
24
 	private final Element[] components;
24
-	private final ListenerHandle<LiveObject.Listener<DDimensionPreferences>>[] componentSizeListeners;
25
-	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
25
+	private final ListenerHandle<LiveObject.Listener<DSizing>>[] componentSizeListeners;
26
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
26
 	
27
 	
27
 	private DUIContext context;
28
 	private DUIContext context;
28
 	private DHorizontalLayoutStyle style;
29
 	private DHorizontalLayoutStyle style;
40
 		totalShrink = 0;
41
 		totalShrink = 0;
41
 		
42
 		
42
 		for (int i = 0; i < componentSizeListeners.length; i++) {
43
 		for (int i = 0; i < componentSizeListeners.length; i++) {
43
-			componentSizeListeners[i] = components[i].component.getDimensionPreferences().addListener((oldValue, newValue) -> updateDimensionPreferences());
44
+			componentSizeListeners[i] = components[i].component.getSizing().addListener((oldValue, newValue) -> updateDimensionPreferences());
44
 			
45
 			
45
 			totalGrow += components[i].grow;
46
 			totalGrow += components[i].grow;
46
 			totalShrink += components[i].shrink;
47
 			totalShrink += components[i].shrink;
76
 	}
77
 	}
77
 
78
 
78
 	@Override
79
 	@Override
79
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
80
-		return dimensionPreferences;
80
+	public LiveObject<DSizing> getSizing() {
81
+		return sizing;
81
 	}
82
 	}
82
 
83
 
83
 	@Override
84
 	@Override
147
 		if (bounds == null || context == null)
148
 		if (bounds == null || context == null)
148
 			return;
149
 			return;
149
 		
150
 		
150
-		DDimensionPreferences myPreferences = dimensionPreferences.getValue();
151
+		DSizing myPreferences = sizing.getValue();
151
 		if (bounds.width < myPreferences.preferredWidth) {
152
 		if (bounds.width < myPreferences.preferredWidth) {
152
 			layoutShrinked();
153
 			layoutShrinked();
153
 		} else {
154
 		} else {
156
 	}
157
 	}
157
 	
158
 	
158
 	private void layoutShrinked() {
159
 	private void layoutShrinked() {
159
-		DDimensionPreferences myPreferences = dimensionPreferences.getValue();
160
+		DSizing myPreferences = sizing.getValue();
160
 		if (totalShrink == 0) {
161
 		if (totalShrink == 0) {
161
 			// now what?
162
 			// now what?
162
 			// shrink proportionally, we have to shrink...
163
 			// shrink proportionally, we have to shrink...
165
 			
166
 			
166
 			for (int i = 0; i < components.length; i++) {
167
 			for (int i = 0; i < components.length; i++) {
167
 				Element element = components[i];
168
 				Element element = components[i];
168
-				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
169
+				DSizing preferences = element.component.getSizing().getValue();
169
 				int newX = x + preferences.preferredWidth;
170
 				int newX = x + preferences.preferredWidth;
170
 				float idealUnspacedX = newX * scale;
171
 				float idealUnspacedX = newX * scale;
171
 				int idealX = (int)(idealUnspacedX + 0.5f + i * style.spacing);
172
 				int idealX = (int)(idealUnspacedX + 0.5f + i * style.spacing);
177
 			float deltaScaled = delta / totalShrink;
178
 			float deltaScaled = delta / totalShrink;
178
 			int x = 0;
179
 			int x = 0;
179
 			for (Element element : components) {
180
 			for (Element element : components) {
180
-				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
181
+				DSizing preferences = element.component.getSizing().getValue();
181
 				float scaledSize = preferences.preferredWidth + deltaScaled * element.shrink;
182
 				float scaledSize = preferences.preferredWidth + deltaScaled * element.shrink;
182
 				float idealUnspacedX = x + scaledSize;
183
 				float idealUnspacedX = x + scaledSize;
183
 				int newX = (int)(idealUnspacedX + 0.5f);
184
 				int newX = (int)(idealUnspacedX + 0.5f);
189
 	
190
 	
190
 	private void layoutGrown() {
191
 	private void layoutGrown() {
191
 		// resize according to grow values
192
 		// resize according to grow values
192
-		DDimensionPreferences myPreferences = dimensionPreferences.getValue();
193
+		DSizing myPreferences = sizing.getValue();
193
 		
194
 		
194
 		if (totalGrow == 0) {
195
 		if (totalGrow == 0) {
195
 			int deltaX = (int)(myPreferences.preferredWidth - bounds.width);
196
 			int deltaX = (int)(myPreferences.preferredWidth - bounds.width);
196
 			int x = bounds.x + (int)(deltaX * alignment.align);
197
 			int x = bounds.x + (int)(deltaX * alignment.align);
197
 			for (Element element : components) {
198
 			for (Element element : components) {
198
-				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
199
+				DSizing preferences = element.component.getSizing().getValue();
199
 				int newX = x + preferences.preferredWidth;
200
 				int newX = x + preferences.preferredWidth;
200
 				layout(element, x, newX - x);
201
 				layout(element, x, newX - x);
201
 				x = newX + style.spacing;
202
 				x = newX + style.spacing;
205
 			float deltaScaled = delta / totalGrow;
206
 			float deltaScaled = delta / totalGrow;
206
 			int x = 0;
207
 			int x = 0;
207
 			for (Element element : components) {
208
 			for (Element element : components) {
208
-				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
209
+				DSizing preferences = element.component.getSizing().getValue();
209
 				float scaledSize = preferences.preferredWidth + deltaScaled * element.grow;
210
 				float scaledSize = preferences.preferredWidth + deltaScaled * element.grow;
210
 				float idealUnspacedX = x + scaledSize;
211
 				float idealUnspacedX = x + scaledSize;
211
 				int newX = (int)(idealUnspacedX + 0.5f);
212
 				int newX = (int)(idealUnspacedX + 0.5f);
216
 	}
217
 	}
217
 	
218
 	
218
 	private void layout(Element element, int x, int width) {
219
 	private void layout(Element element, int x, int width) {
219
-		DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
220
+		DSizing preferences = element.component.getSizing().getValue();
220
 		int height;
221
 		int height;
221
 		int y;
222
 		int y;
222
 		switch (element.alignment) {
223
 		switch (element.alignment) {
249
 		int maximumWidth = -style.spacing;
250
 		int maximumWidth = -style.spacing;
250
 		int maximumHeight = Integer.MAX_VALUE;
251
 		int maximumHeight = Integer.MAX_VALUE;
251
 		for (Element element : components) {
252
 		for (Element element : components) {
252
-			DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
253
+			DSizing preferences = element.component.getSizing().getValue();
253
 			preferredWidth += preferences.preferredWidth + style.spacing;
254
 			preferredWidth += preferences.preferredWidth + style.spacing;
254
 			preferredHeight = Math.max(preferredHeight, preferences.preferredHeight);
255
 			preferredHeight = Math.max(preferredHeight, preferences.preferredHeight);
255
 			
256
 			
260
 			maximumHeight = Math.min(maximumHeight, preferences.maximumHeight);
261
 			maximumHeight = Math.min(maximumHeight, preferences.maximumHeight);
261
 		}
262
 		}
262
 		
263
 		
263
-		DDimensionPreferences preferences = new DDimensionPreferences(
264
+		DSizing preferences = new DSizing(
264
 				minimumWidth + style.paddingLeft + style.paddingRight,
265
 				minimumWidth + style.paddingLeft + style.paddingRight,
265
 				minimumHeight + style.paddingTop + style.paddingBottom,
266
 				minimumHeight + style.paddingTop + style.paddingBottom,
266
 				preferredWidth + style.paddingLeft + style.paddingRight,
267
 				preferredWidth + style.paddingLeft + style.paddingRight,
267
 				preferredHeight + style.paddingTop + style.paddingBottom,
268
 				preferredHeight + style.paddingTop + style.paddingBottom,
268
 				maximumWidth + style.paddingLeft + style.paddingRight,
269
 				maximumWidth + style.paddingLeft + style.paddingRight,
269
 				maximumHeight + style.paddingTop + style.paddingBottom);
270
 				maximumHeight + style.paddingTop + style.paddingBottom);
270
-		dimensionPreferences.setValue(preferences);
271
+		sizing.setValue(preferences);
271
 	}
272
 	}
272
 }
273
 }

+ 5
- 5
DrawableGui/src/main/java/org/openzen/drawablegui/DInputField.java View File

8
 import org.openzen.drawablegui.listeners.ListenerHandle;
8
 import org.openzen.drawablegui.listeners.ListenerHandle;
9
 import org.openzen.drawablegui.live.LiveObject;
9
 import org.openzen.drawablegui.live.LiveObject;
10
 import org.openzen.drawablegui.live.LiveString;
10
 import org.openzen.drawablegui.live.LiveString;
11
+import org.openzen.drawablegui.live.MutableLiveObject;
11
 import org.openzen.drawablegui.live.MutableLiveString;
12
 import org.openzen.drawablegui.live.MutableLiveString;
12
-import org.openzen.drawablegui.live.SimpleLiveObject;
13
 import org.openzen.drawablegui.style.DDimension;
13
 import org.openzen.drawablegui.style.DDimension;
14
 import org.openzen.drawablegui.style.DStyleClass;
14
 import org.openzen.drawablegui.style.DStyleClass;
15
 import org.openzen.drawablegui.style.DStylePath;
15
 import org.openzen.drawablegui.style.DStylePath;
23
 	private final ListenerHandle<LiveString.Listener> valueListener;
23
 	private final ListenerHandle<LiveString.Listener> valueListener;
24
 	
24
 	
25
 	private final DStyleClass styleClass;
25
 	private final DStyleClass styleClass;
26
-	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
26
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
27
 	private DIRectangle bounds = DIRectangle.EMPTY;
27
 	private DIRectangle bounds = DIRectangle.EMPTY;
28
 	private final DDimension preferredWidth;
28
 	private final DDimension preferredWidth;
29
 	
29
 	
70
 		DStylePath path = parent.getChild("input", styleClass);
70
 		DStylePath path = parent.getChild("input", styleClass);
71
 		style = new DInputFieldStyle(context.getStylesheets().get(context, path));
71
 		style = new DInputFieldStyle(context.getStylesheets().get(context, path));
72
 		fontMetrics = context.getFontMetrics(style.font);
72
 		fontMetrics = context.getFontMetrics(style.font);
73
-		dimensionPreferences.setValue(new DDimensionPreferences(
73
+		sizing.setValue(new DSizing(
74
 				preferredWidth.evalInt(context) + style.paddingLeft + style.paddingRight + 2 * style.borderWidth,
74
 				preferredWidth.evalInt(context) + style.paddingLeft + style.paddingRight + 2 * style.borderWidth,
75
 				fontMetrics.getAscent() + fontMetrics.getDescent() + style.paddingTop + style.paddingBottom + 2 * style.borderWidth));
75
 				fontMetrics.getAscent() + fontMetrics.getDescent() + style.paddingTop + style.paddingBottom + 2 * style.borderWidth));
76
 		
76
 		
85
 	}
85
 	}
86
 
86
 
87
 	@Override
87
 	@Override
88
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
89
-		return dimensionPreferences;
88
+	public LiveObject<DSizing> getSizing() {
89
+		return sizing;
90
 	}
90
 	}
91
 
91
 
92
 	@Override
92
 	@Override

+ 5
- 5
DrawableGui/src/main/java/org/openzen/drawablegui/DLabel.java View File

8
 import org.openzen.drawablegui.listeners.ListenerHandle;
8
 import org.openzen.drawablegui.listeners.ListenerHandle;
9
 import org.openzen.drawablegui.live.LiveObject;
9
 import org.openzen.drawablegui.live.LiveObject;
10
 import org.openzen.drawablegui.live.LiveString;
10
 import org.openzen.drawablegui.live.LiveString;
11
-import org.openzen.drawablegui.live.SimpleLiveObject;
11
+import org.openzen.drawablegui.live.MutableLiveObject;
12
 import org.openzen.drawablegui.style.DStyleClass;
12
 import org.openzen.drawablegui.style.DStyleClass;
13
 import org.openzen.drawablegui.style.DStylePath;
13
 import org.openzen.drawablegui.style.DStylePath;
14
 
14
 
19
 public class DLabel implements DComponent {
19
 public class DLabel implements DComponent {
20
 	private final LiveString label;
20
 	private final LiveString label;
21
 	private final DStyleClass styleClass;
21
 	private final DStyleClass styleClass;
22
-	private final LiveObject<DDimensionPreferences> preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
22
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
23
 	private final ListenerHandle<LiveString.Listener> labelListener;
23
 	private final ListenerHandle<LiveString.Listener> labelListener;
24
 	
24
 	
25
 	private DUIContext context;
25
 	private DUIContext context;
46
 	}
46
 	}
47
 
47
 
48
 	@Override
48
 	@Override
49
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
50
-		return preferences;
49
+	public LiveObject<DSizing> getSizing() {
50
+		return sizing;
51
 	}
51
 	}
52
 
52
 
53
 	@Override
53
 	@Override
82
 	}
82
 	}
83
 	
83
 	
84
 	private void calculateDimension() {
84
 	private void calculateDimension() {
85
-		preferences.setValue(new DDimensionPreferences(
85
+		sizing.setValue(new DSizing(
86
 			style.border.getPaddingLeft() + fontMetrics.getWidth(label.getValue()) + style.border.getPaddingRight(),
86
 			style.border.getPaddingLeft() + fontMetrics.getWidth(label.getValue()) + style.border.getPaddingRight(),
87
 			style.border.getPaddingTop() + fontMetrics.getAscent() + fontMetrics.getDescent() + style.border.getPaddingTop()));
87
 			style.border.getPaddingTop() + fontMetrics.getAscent() + fontMetrics.getDescent() + style.border.getPaddingTop()));
88
 	}
88
 	}

+ 12
- 11
DrawableGui/src/main/java/org/openzen/drawablegui/DSideLayout.java View File

12
 import java.util.function.Predicate;
12
 import java.util.function.Predicate;
13
 import org.openzen.drawablegui.listeners.ListenerHandle;
13
 import org.openzen.drawablegui.listeners.ListenerHandle;
14
 import org.openzen.drawablegui.live.LiveObject;
14
 import org.openzen.drawablegui.live.LiveObject;
15
+import org.openzen.drawablegui.live.MutableLiveObject;
15
 import org.openzen.drawablegui.live.SimpleLiveObject;
16
 import org.openzen.drawablegui.live.SimpleLiveObject;
16
 import org.openzen.drawablegui.style.DStyleClass;
17
 import org.openzen.drawablegui.style.DStyleClass;
17
 import org.openzen.drawablegui.style.DStylePath;
18
 import org.openzen.drawablegui.style.DStylePath;
25
 	
26
 	
26
 	private DComponent main;
27
 	private DComponent main;
27
 	private final List<SideComponent> sides = new ArrayList<>();
28
 	private final List<SideComponent> sides = new ArrayList<>();
28
-	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
29
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
29
 	
30
 	
30
 	private DStylePath path;
31
 	private DStylePath path;
31
 	private DUIContext context;
32
 	private DUIContext context;
83
 	}
84
 	}
84
 
85
 
85
 	@Override
86
 	@Override
86
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
87
-		return dimensionPreferences;
87
+	public LiveObject<DSizing> getSizing() {
88
+		return sizing;
88
 	}
89
 	}
89
 
90
 
90
 	@Override
91
 	@Override
97
 		int bottom = bounds.y + bounds.height;
98
 		int bottom = bounds.y + bounds.height;
98
 		for (int i = sides.size() - 1; i >= 0; i--) {
99
 		for (int i = sides.size() - 1; i >= 0; i--) {
99
 			SideComponent side = sides.get(i);
100
 			SideComponent side = sides.get(i);
100
-			DDimensionPreferences preferences = side.component.getDimensionPreferences().getValue();
101
+			DSizing preferences = side.component.getSizing().getValue();
101
 			
102
 			
102
 			switch (side.side) {
103
 			switch (side.side) {
103
 				case TOP: {
104
 				case TOP: {
175
 	}
176
 	}
176
 	
177
 	
177
 	private void recalculateSize() {
178
 	private void recalculateSize() {
178
-		DDimensionPreferences mainPreferences = main.getDimensionPreferences().getValue();
179
+		DSizing mainPreferences = main.getSizing().getValue();
179
 		int minimumWidth = mainPreferences.minimumWidth;
180
 		int minimumWidth = mainPreferences.minimumWidth;
180
 		int minimumHeight = mainPreferences.minimumHeight;
181
 		int minimumHeight = mainPreferences.minimumHeight;
181
 		int preferredWidth = mainPreferences.preferredWidth;
182
 		int preferredWidth = mainPreferences.preferredWidth;
184
 		int maximumHeight = mainPreferences.maximumHeight;
185
 		int maximumHeight = mainPreferences.maximumHeight;
185
 		
186
 		
186
 		for (SideComponent side : sides) {
187
 		for (SideComponent side : sides) {
187
-			DDimensionPreferences sidePreferences = side.component.getDimensionPreferences().getValue();
188
+			DSizing sidePreferences = side.component.getSizing().getValue();
188
 			switch (side.side) {
189
 			switch (side.side) {
189
 				case LEFT:
190
 				case LEFT:
190
 				case RIGHT:
191
 				case RIGHT:
207
 			}
208
 			}
208
 		}
209
 		}
209
 		
210
 		
210
-		dimensionPreferences.setValue(new DDimensionPreferences(
211
+		sizing.setValue(new DSizing(
211
 				minimumWidth,
212
 				minimumWidth,
212
 				minimumHeight,
213
 				minimumHeight,
213
 				preferredWidth,
214
 				preferredWidth,
241
 			side.close();
242
 			side.close();
242
 	}
243
 	}
243
 	
244
 	
244
-	public class SideComponent implements Closeable, LiveObject.Listener<DDimensionPreferences> {
245
+	public class SideComponent implements Closeable, LiveObject.Listener<DSizing> {
245
 		public final Side side;
246
 		public final Side side;
246
 		public final DComponent component;
247
 		public final DComponent component;
247
-		public final ListenerHandle<LiveObject.Listener<DDimensionPreferences>> listenerHandle;
248
+		public final ListenerHandle<LiveObject.Listener<DSizing>> listenerHandle;
248
 
249
 
249
 		public SideComponent(Side side, DComponent component) {
250
 		public SideComponent(Side side, DComponent component) {
250
 			this.side = side;
251
 			this.side = side;
251
 			this.component = component;
252
 			this.component = component;
252
-			listenerHandle = component.getDimensionPreferences().addListener(this);
253
+			listenerHandle = component.getSizing().addListener(this);
253
 		}
254
 		}
254
 		
255
 		
255
 		@Override
256
 		@Override
258
 		}
259
 		}
259
 
260
 
260
 		@Override
261
 		@Override
261
-		public void onUpdated(DDimensionPreferences oldValue, DDimensionPreferences newValue) {
262
+		public void onUpdated(DSizing oldValue, DSizing newValue) {
262
 			recalculateSize();
263
 			recalculateSize();
263
 		}
264
 		}
264
 	}
265
 	}

DrawableGui/src/main/java/org/openzen/drawablegui/DDimensionPreferences.java → DrawableGui/src/main/java/org/openzen/drawablegui/DSizing.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui;
6
 package org.openzen.drawablegui;
7
 
7
 
8
+import org.openzen.drawablegui.live.MutableLiveObject;
9
+import org.openzen.drawablegui.live.SimpleLiveObject;
10
+
8
 /**
11
 /**
9
  *
12
  *
10
  * @author Hoofdgebruiker
13
  * @author Hoofdgebruiker
11
  */
14
  */
12
-public class DDimensionPreferences {
13
-	public static final DDimensionPreferences EMPTY = new DDimensionPreferences(0, 0);
15
+public class DSizing {
16
+	public static MutableLiveObject<DSizing> create() {
17
+		return new SimpleLiveObject<>(DSizing.EMPTY);
18
+	}
19
+	
20
+	public static final DSizing EMPTY = new DSizing(0, 0);
14
 	
21
 	
15
 	public final int minimumWidth;
22
 	public final int minimumWidth;
16
 	public final int minimumHeight;
23
 	public final int minimumHeight;
19
 	public final int maximumWidth;
26
 	public final int maximumWidth;
20
 	public final int maximumHeight;
27
 	public final int maximumHeight;
21
 	
28
 	
22
-	public DDimensionPreferences(int preferredWidth, int preferredHeight) {
29
+	public DSizing(int preferredWidth, int preferredHeight) {
23
 		this.minimumWidth = 0;
30
 		this.minimumWidth = 0;
24
 		this.minimumHeight = 0;
31
 		this.minimumHeight = 0;
25
 		this.preferredWidth = preferredWidth;
32
 		this.preferredWidth = preferredWidth;
28
 		this.maximumHeight = 1000000;
35
 		this.maximumHeight = 1000000;
29
 	}
36
 	}
30
 	
37
 	
31
-	public DDimensionPreferences(int minimumWidth, int minimumHeight, int preferredWidth, int preferredHeight, int maximumWidth, int maximumHeight) {
38
+	public DSizing(int minimumWidth, int minimumHeight, int preferredWidth, int preferredHeight, int maximumWidth, int maximumHeight) {
32
 		this.minimumWidth = minimumWidth;
39
 		this.minimumWidth = minimumWidth;
33
 		this.minimumHeight = minimumHeight;
40
 		this.minimumHeight = minimumHeight;
34
 		this.preferredWidth = preferredWidth;
41
 		this.preferredWidth = preferredWidth;

+ 122
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DTooltip.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+import org.openzen.drawablegui.listeners.ListenerHandle;
9
+import org.openzen.drawablegui.live.LiveObject;
10
+import org.openzen.drawablegui.live.LiveString;
11
+import org.openzen.drawablegui.live.MutableLiveObject;
12
+import org.openzen.drawablegui.style.DStyleClass;
13
+import org.openzen.drawablegui.style.DStylePath;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class DTooltip implements DComponent {
20
+	private final DStyleClass styleClass;
21
+	private final LiveString tooltip;
22
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
23
+	private final ListenerHandle<LiveString.Listener> tooltipListener;
24
+	
25
+	private DUIContext context;
26
+	private DIRectangle bounds;
27
+	private DFontMetrics fontMetrics;
28
+	private DTooltipStyle style;
29
+	private boolean visible = false;
30
+	private DTimerHandle timerHandle = null;
31
+	
32
+	public DTooltip(DStyleClass styleClass, LiveString tooltip) {
33
+		this.styleClass = styleClass;
34
+		this.tooltip = tooltip;
35
+		tooltipListener = tooltip.addListener(this::onTooltipChanged);
36
+	}
37
+	
38
+	private void onTooltipChanged(String oldValue, String newValue) {
39
+		if (context == null)
40
+			return;
41
+		
42
+		sizing.setValue(new DSizing(
43
+				style.border.getPaddingLeft() + fontMetrics.getWidth(newValue) + style.border.getPaddingRight(),
44
+				style.border.getPaddingTop() + fontMetrics.getAscent() + fontMetrics.getDescent() + style.border.getPaddingBottom()));
45
+	}
46
+	
47
+	public void onTargetMouseEnter(DMouseEvent e) {
48
+		if (timerHandle != null)
49
+			timerHandle.close();
50
+		
51
+		timerHandle = context.setTimer(1000, this::show);
52
+		setBounds(new DIRectangle(e.x, e.y, sizing.getValue().preferredWidth, sizing.getValue().preferredHeight));
53
+	}
54
+	
55
+	public void onTargetMouseExit(DMouseEvent e) {
56
+		if (timerHandle != null) {
57
+			timerHandle.close();
58
+			timerHandle = null;
59
+		}
60
+		
61
+		hide();
62
+	}
63
+	
64
+	private void show() {
65
+		visible = true;
66
+		context.repaint(bounds);
67
+		
68
+		if (timerHandle != null) {
69
+			timerHandle.close();
70
+			timerHandle = null;
71
+		}
72
+	}
73
+	
74
+	private void hide() {
75
+		visible = false;
76
+		context.repaint(bounds);
77
+	}
78
+	
79
+	@Override
80
+	public void setContext(DStylePath parent, DUIContext context) {
81
+		this.context = context;
82
+		
83
+		DStylePath path = parent.getChild("tooltip", styleClass);
84
+		style = new DTooltipStyle(context.getStylesheets().get(context, path));
85
+		fontMetrics = context.getFontMetrics(style.font);
86
+	}
87
+
88
+	@Override
89
+	public LiveObject<DSizing> getSizing() {
90
+		return sizing;
91
+	}
92
+
93
+	@Override
94
+	public DIRectangle getBounds() {
95
+		return bounds;
96
+	}
97
+
98
+	@Override
99
+	public int getBaselineY() {
100
+		return style.border.getPaddingTop() + fontMetrics.getAscent();
101
+	}
102
+
103
+	@Override
104
+	public void setBounds(DIRectangle bounds) {
105
+		this.bounds = bounds;
106
+	}
107
+
108
+	@Override
109
+	public void paint(DCanvas canvas) {
110
+		if (!visible)
111
+			return;
112
+		
113
+		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
114
+		style.border.paint(canvas, bounds);
115
+		canvas.drawText(style.font, style.textColor, bounds.x + style.border.getPaddingLeft(), style.border.getPaddingTop(), tooltip.getValue());
116
+	}
117
+
118
+	@Override
119
+	public void close() {
120
+		tooltipListener.close();
121
+	}
122
+}

+ 32
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DTooltipStyle.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+import org.openzen.drawablegui.border.DBorder;
9
+import org.openzen.drawablegui.border.DCompositeBorder;
10
+import org.openzen.drawablegui.border.DLineBorder;
11
+import org.openzen.drawablegui.border.DPaddedBorder;
12
+import org.openzen.drawablegui.style.DStyleDefinition;
13
+
14
+/**
15
+ *
16
+ * @author Hoofdgebruiker
17
+ */
18
+public class DTooltipStyle {
19
+	public final DBorder border;
20
+	public final DFont font;
21
+	public final int backgroundColor;
22
+	public final int textColor;
23
+	
24
+	public DTooltipStyle(DStyleDefinition style) {
25
+		border = style.getBorder("border", context -> new DCompositeBorder(
26
+				new DLineBorder(0xFF, 1),
27
+				new DPaddedBorder(context.dp(4), context.dp(4), context.dp(4), context.dp(4))));
28
+		font = style.getFont("font", context -> new DFont(DFontFamily.UI, false, false, false, context.sp(12)));
29
+		backgroundColor = style.getColor("backgroundColor", 0xFFFFFFE1);
30
+		textColor = style.getColor("textColor", 0xFF000000);
31
+	}
32
+}

+ 4
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DUIContext.java View File

44
 		return (int)(dp * getScale());
44
 		return (int)(dp * getScale());
45
 	}
45
 	}
46
 	
46
 	
47
+	default int sp(float sp) {
48
+		return (int)(sp * getTextScale());
49
+	}
50
+	
47
 	enum Cursor {
51
 	enum Cursor {
48
 		NORMAL,
52
 		NORMAL,
49
 		HAND,
53
 		HAND,

+ 19
- 18
DrawableGui/src/main/java/org/openzen/drawablegui/DVerticalLayout.java View File

9
 import java.util.function.Predicate;
9
 import java.util.function.Predicate;
10
 import org.openzen.drawablegui.listeners.ListenerHandle;
10
 import org.openzen.drawablegui.listeners.ListenerHandle;
11
 import org.openzen.drawablegui.live.LiveObject;
11
 import org.openzen.drawablegui.live.LiveObject;
12
+import org.openzen.drawablegui.live.MutableLiveObject;
12
 import org.openzen.drawablegui.live.SimpleLiveObject;
13
 import org.openzen.drawablegui.live.SimpleLiveObject;
13
 import org.openzen.drawablegui.style.DStyleClass;
14
 import org.openzen.drawablegui.style.DStyleClass;
14
 import org.openzen.drawablegui.style.DStylePath;
15
 import org.openzen.drawablegui.style.DStylePath;
21
 	private final DStyleClass styleClass;
22
 	private final DStyleClass styleClass;
22
 	private final Alignment alignment;
23
 	private final Alignment alignment;
23
 	private final Element[] components;
24
 	private final Element[] components;
24
-	private final ListenerHandle<LiveObject.Listener<DDimensionPreferences>>[] componentSizeListeners;
25
-	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
25
+	private final ListenerHandle<LiveObject.Listener<DSizing>>[] componentSizeListeners;
26
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
26
 	
27
 	
27
 	private DUIContext context;
28
 	private DUIContext context;
28
 	private DHorizontalLayoutStyle style;
29
 	private DHorizontalLayoutStyle style;
40
 		totalShrink = 0;
41
 		totalShrink = 0;
41
 		
42
 		
42
 		for (int i = 0; i < componentSizeListeners.length; i++) {
43
 		for (int i = 0; i < componentSizeListeners.length; i++) {
43
-			componentSizeListeners[i] = components[i].component.getDimensionPreferences().addListener((oldValue, newValue) -> updateDimensionPreferences());
44
+			componentSizeListeners[i] = components[i].component.getSizing().addListener((oldValue, newValue) -> updateDimensionPreferences());
44
 			
45
 			
45
 			totalGrow += components[i].grow;
46
 			totalGrow += components[i].grow;
46
 			totalShrink += components[i].shrink;
47
 			totalShrink += components[i].shrink;
76
 	}
77
 	}
77
 
78
 
78
 	@Override
79
 	@Override
79
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
80
-		return dimensionPreferences;
80
+	public LiveObject<DSizing> getSizing() {
81
+		return sizing;
81
 	}
82
 	}
82
 
83
 
83
 	@Override
84
 	@Override
105
 
106
 
106
 	@Override
107
 	@Override
107
 	public void close() {
108
 	public void close() {
108
-		for (int i = 0; i < componentSizeListeners.length; i++) {
109
-			componentSizeListeners[i].close();
109
+		for (ListenerHandle<LiveObject.Listener<DSizing>> listener : componentSizeListeners) {
110
+			listener.close();
110
 		}
111
 		}
111
 	}
112
 	}
112
 	
113
 	
147
 		if (bounds == null || context == null)
148
 		if (bounds == null || context == null)
148
 			return;
149
 			return;
149
 		
150
 		
150
-		DDimensionPreferences myPreferences = dimensionPreferences.getValue();
151
+		DSizing myPreferences = sizing.getValue();
151
 		if (bounds.height < myPreferences.preferredHeight) {
152
 		if (bounds.height < myPreferences.preferredHeight) {
152
 			layoutShrinked();
153
 			layoutShrinked();
153
 		} else {
154
 		} else {
156
 	}
157
 	}
157
 	
158
 	
158
 	private void layoutShrinked() {
159
 	private void layoutShrinked() {
159
-		DDimensionPreferences myPreferences = dimensionPreferences.getValue();
160
+		DSizing myPreferences = sizing.getValue();
160
 		if (totalShrink == 0) {
161
 		if (totalShrink == 0) {
161
 			// now what?
162
 			// now what?
162
 			// shrink proportionally, we have to shrink...
163
 			// shrink proportionally, we have to shrink...
165
 			
166
 			
166
 			for (int i = 0; i < components.length; i++) {
167
 			for (int i = 0; i < components.length; i++) {
167
 				Element element = components[i];
168
 				Element element = components[i];
168
-				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
169
+				DSizing preferences = element.component.getSizing().getValue();
169
 				int newY = y + preferences.preferredHeight;
170
 				int newY = y + preferences.preferredHeight;
170
 				float idealUnspacedY = newY * scale;
171
 				float idealUnspacedY = newY * scale;
171
 				int idealY = (int)(idealUnspacedY + 0.5f + i * style.spacing);
172
 				int idealY = (int)(idealUnspacedY + 0.5f + i * style.spacing);
177
 			float deltaScaled = delta / totalShrink;
178
 			float deltaScaled = delta / totalShrink;
178
 			int y = bounds.y;
179
 			int y = bounds.y;
179
 			for (Element element : components) {
180
 			for (Element element : components) {
180
-				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
181
+				DSizing preferences = element.component.getSizing().getValue();
181
 				float scaledSize = preferences.preferredHeight + deltaScaled * element.shrink;
182
 				float scaledSize = preferences.preferredHeight + deltaScaled * element.shrink;
182
 				float idealUnspacedY = y + scaledSize;
183
 				float idealUnspacedY = y + scaledSize;
183
 				int newY = (int)(idealUnspacedY + 0.5f);
184
 				int newY = (int)(idealUnspacedY + 0.5f);
189
 	
190
 	
190
 	private void layoutGrown() {
191
 	private void layoutGrown() {
191
 		// resize according to grow values
192
 		// resize according to grow values
192
-		DDimensionPreferences myPreferences = dimensionPreferences.getValue();
193
+		DSizing myPreferences = sizing.getValue();
193
 		
194
 		
194
 		if (totalGrow == 0) {
195
 		if (totalGrow == 0) {
195
 			int deltaY = (int)(myPreferences.preferredHeight - bounds.height);
196
 			int deltaY = (int)(myPreferences.preferredHeight - bounds.height);
196
 			int y = bounds.y + (int)(deltaY * alignment.align);
197
 			int y = bounds.y + (int)(deltaY * alignment.align);
197
 			for (Element element : components) {
198
 			for (Element element : components) {
198
-				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
199
+				DSizing preferences = element.component.getSizing().getValue();
199
 				int newY = y + preferences.preferredHeight;
200
 				int newY = y + preferences.preferredHeight;
200
 				layout(element, y, newY - y);
201
 				layout(element, y, newY - y);
201
 				y = newY;
202
 				y = newY;
205
 			float deltaScaled = delta / totalGrow;
206
 			float deltaScaled = delta / totalGrow;
206
 			int y = bounds.y;
207
 			int y = bounds.y;
207
 			for (Element element : components) {
208
 			for (Element element : components) {
208
-				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
209
+				DSizing preferences = element.component.getSizing().getValue();
209
 				float scaledSize = preferences.preferredHeight + deltaScaled * element.grow;
210
 				float scaledSize = preferences.preferredHeight + deltaScaled * element.grow;
210
 				float idealUnspacedY = y + scaledSize;
211
 				float idealUnspacedY = y + scaledSize;
211
 				int newY = (int)(idealUnspacedY + 0.5f);
212
 				int newY = (int)(idealUnspacedY + 0.5f);
216
 	}
217
 	}
217
 	
218
 	
218
 	private void layout(Element element, int y, int height) {
219
 	private void layout(Element element, int y, int height) {
219
-		DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
220
+		DSizing preferences = element.component.getSizing().getValue();
220
 		int x;
221
 		int x;
221
 		int width;
222
 		int width;
222
 		switch (element.alignment) {
223
 		switch (element.alignment) {
250
 		int maximumHeight = -style.spacing;
251
 		int maximumHeight = -style.spacing;
251
 		
252
 		
252
 		for (Element element : components) {
253
 		for (Element element : components) {
253
-			DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
254
+			DSizing preferences = element.component.getSizing().getValue();
254
 			preferredWidth = Math.max(preferredWidth, preferences.preferredWidth);
255
 			preferredWidth = Math.max(preferredWidth, preferences.preferredWidth);
255
 			preferredHeight += preferences.preferredHeight + style.spacing;
256
 			preferredHeight += preferences.preferredHeight + style.spacing;
256
 			
257
 			
261
 			maximumHeight += preferences.maximumHeight + style.spacing;
262
 			maximumHeight += preferences.maximumHeight + style.spacing;
262
 		}
263
 		}
263
 		
264
 		
264
-		DDimensionPreferences preferences = new DDimensionPreferences(
265
+		DSizing preferences = new DSizing(
265
 				minimumWidth + style.paddingLeft + style.paddingRight,
266
 				minimumWidth + style.paddingLeft + style.paddingRight,
266
 				minimumHeight + style.paddingTop + style.paddingBottom,
267
 				minimumHeight + style.paddingTop + style.paddingBottom,
267
 				preferredWidth + style.paddingLeft + style.paddingRight,
268
 				preferredWidth + style.paddingLeft + style.paddingRight,
268
 				preferredHeight + style.paddingTop + style.paddingBottom,
269
 				preferredHeight + style.paddingTop + style.paddingBottom,
269
 				maximumWidth + style.paddingLeft + style.paddingRight,
270
 				maximumWidth + style.paddingLeft + style.paddingRight,
270
 				maximumHeight + style.paddingTop + style.paddingBottom);
271
 				maximumHeight + style.paddingTop + style.paddingBottom);
271
-		dimensionPreferences.setValue(preferences);
272
+		sizing.setValue(preferences);
272
 	}
273
 	}
273
 }
274
 }

+ 65
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/border/DCompositeBorder.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.border;
7
+
8
+import org.openzen.drawablegui.DCanvas;
9
+import org.openzen.drawablegui.DIRectangle;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class DCompositeBorder implements DBorder {
16
+	private final DBorder[] borders;
17
+	
18
+	public DCompositeBorder(DBorder... borders) {
19
+		this.borders = borders;
20
+	}
21
+
22
+	@Override
23
+	public void paint(DCanvas canvas, DIRectangle bounds) {
24
+		for (DBorder border : borders) {
25
+			border.paint(canvas, bounds);
26
+			bounds = new DIRectangle(
27
+					bounds.x + border.getPaddingLeft(),
28
+					bounds.y + border.getPaddingTop(),
29
+					bounds.width - border.getPaddingLeft() - border.getPaddingRight(),
30
+					bounds.height - border.getPaddingTop() - border.getPaddingBottom());
31
+		}
32
+	}
33
+
34
+	@Override
35
+	public int getPaddingLeft() {
36
+		int total = 0;
37
+		for (DBorder border : borders)
38
+			total += border.getPaddingLeft();
39
+		return total;
40
+	}
41
+
42
+	@Override
43
+	public int getPaddingRight() {
44
+		int total = 0;
45
+		for (DBorder border : borders)
46
+			total += border.getPaddingRight();
47
+		return total;
48
+	}
49
+
50
+	@Override
51
+	public int getPaddingTop() {
52
+		int total = 0;
53
+		for (DBorder border : borders)
54
+			total += border.getPaddingTop();
55
+		return total;
56
+	}
57
+
58
+	@Override
59
+	public int getPaddingBottom() {
60
+		int total = 0;
61
+		for (DBorder border : borders)
62
+			total += border.getPaddingBottom();
63
+		return total;
64
+	}
65
+}

+ 4
- 4
DrawableGui/src/main/java/org/openzen/drawablegui/border/DCustomWindowBorder.java View File

7
 
7
 
8
 import org.openzen.drawablegui.DCanvas;
8
 import org.openzen.drawablegui.DCanvas;
9
 import org.openzen.drawablegui.DComponent;
9
 import org.openzen.drawablegui.DComponent;
10
-import org.openzen.drawablegui.DDimensionPreferences;
10
+import org.openzen.drawablegui.DSizing;
11
 import org.openzen.drawablegui.DMouseEvent;
11
 import org.openzen.drawablegui.DMouseEvent;
12
 import org.openzen.drawablegui.DPath;
12
 import org.openzen.drawablegui.DPath;
13
 import org.openzen.drawablegui.DTransform2D;
13
 import org.openzen.drawablegui.DTransform2D;
28
 public class DCustomWindowBorder implements DComponent {
28
 public class DCustomWindowBorder implements DComponent {
29
 	private final DStyleClass styleClass;
29
 	private final DStyleClass styleClass;
30
 	private final DComponent content;
30
 	private final DComponent content;
31
-	private final LiveObject<DDimensionPreferences> preferences = new ImmutableLiveObject<>(DDimensionPreferences.EMPTY);
31
+	private final LiveObject<DSizing> sizing = new ImmutableLiveObject<>(DSizing.EMPTY);
32
 	
32
 	
33
 	private DUIContext context;
33
 	private DUIContext context;
34
 	private DCustomWindowBorderStyle style;
34
 	private DCustomWindowBorderStyle style;
64
 	}
64
 	}
65
 
65
 
66
 	@Override
66
 	@Override
67
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
68
-		return preferences;
67
+	public LiveObject<DSizing> getSizing() {
68
+		return sizing;
69
 	}
69
 	}
70
 
70
 
71
 	@Override
71
 	@Override

+ 0
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/border/DEmptyBorder.java View File

7
 
7
 
8
 import org.openzen.drawablegui.DCanvas;
8
 import org.openzen.drawablegui.DCanvas;
9
 import org.openzen.drawablegui.DIRectangle;
9
 import org.openzen.drawablegui.DIRectangle;
10
-import org.openzen.drawablegui.DUIContext;
11
 
10
 
12
 /**
11
 /**
13
  *
12
  *

+ 0
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/border/DLineBorder.java View File

8
 import org.openzen.drawablegui.DCanvas;
8
 import org.openzen.drawablegui.DCanvas;
9
 import org.openzen.drawablegui.DTransform2D;
9
 import org.openzen.drawablegui.DTransform2D;
10
 import org.openzen.drawablegui.DIRectangle;
10
 import org.openzen.drawablegui.DIRectangle;
11
-import org.openzen.drawablegui.DUIContext;
12
 
11
 
13
 /**
12
 /**
14
  *
13
  *

+ 10
- 10
DrawableGui/src/main/java/org/openzen/drawablegui/form/DForm.java View File

10
 import org.openzen.drawablegui.BaseComponentGroup;
10
 import org.openzen.drawablegui.BaseComponentGroup;
11
 import org.openzen.drawablegui.DCanvas;
11
 import org.openzen.drawablegui.DCanvas;
12
 import org.openzen.drawablegui.DComponent;
12
 import org.openzen.drawablegui.DComponent;
13
-import org.openzen.drawablegui.DDimensionPreferences;
13
+import org.openzen.drawablegui.DSizing;
14
 import org.openzen.drawablegui.DFontMetrics;
14
 import org.openzen.drawablegui.DFontMetrics;
15
 import org.openzen.drawablegui.DIRectangle;
15
 import org.openzen.drawablegui.DIRectangle;
16
 import org.openzen.drawablegui.DUIContext;
16
 import org.openzen.drawablegui.DUIContext;
17
 import org.openzen.drawablegui.live.LiveObject;
17
 import org.openzen.drawablegui.live.LiveObject;
18
-import org.openzen.drawablegui.live.SimpleLiveObject;
18
+import org.openzen.drawablegui.live.MutableLiveObject;
19
 import org.openzen.drawablegui.style.DStyleClass;
19
 import org.openzen.drawablegui.style.DStyleClass;
20
 import org.openzen.drawablegui.style.DStylePath;
20
 import org.openzen.drawablegui.style.DStylePath;
21
 
21
 
26
 public class DForm extends BaseComponentGroup {
26
 public class DForm extends BaseComponentGroup {
27
 	private final DFormComponent[] components;
27
 	private final DFormComponent[] components;
28
 	private final DStyleClass styleClass;
28
 	private final DStyleClass styleClass;
29
-	private final LiveObject<DDimensionPreferences> preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
29
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
30
 	
30
 	
31
 	private DIRectangle bounds;
31
 	private DIRectangle bounds;
32
 	private DUIContext context;
32
 	private DUIContext context;
56
 		
56
 		
57
 		for (DFormComponent component : components) {
57
 		for (DFormComponent component : components) {
58
 			maxLabelWidth = Math.max(maxLabelWidth, fontMetrics.getWidth(component.label));
58
 			maxLabelWidth = Math.max(maxLabelWidth, fontMetrics.getWidth(component.label));
59
-			int componentWidth = component.component.getDimensionPreferences().getValue().preferredWidth;
59
+			int componentWidth = component.component.getSizing().getValue().preferredWidth;
60
 			maxFieldWidth = Math.max(maxFieldWidth, componentWidth);
60
 			maxFieldWidth = Math.max(maxFieldWidth, componentWidth);
61
 		}
61
 		}
62
 		
62
 		
63
 		for (DFormComponent component : components) {
63
 		for (DFormComponent component : components) {
64
-			height += component.component.getDimensionPreferences().getValue().preferredHeight;
64
+			height += component.component.getSizing().getValue().preferredHeight;
65
 			height += style.spacing;
65
 			height += style.spacing;
66
 		}
66
 		}
67
 		
67
 		
68
 		this.maxFieldWidth = maxFieldWidth;
68
 		this.maxFieldWidth = maxFieldWidth;
69
 		this.maxLabelWidth = maxLabelWidth;
69
 		this.maxLabelWidth = maxLabelWidth;
70
-		preferences.setValue(new DDimensionPreferences(maxLabelWidth + maxFieldWidth + style.paddingLeft + style.paddingRight + style.spacing, height));
70
+		sizing.setValue(new DSizing(maxLabelWidth + maxFieldWidth + style.paddingLeft + style.paddingRight + style.spacing, height));
71
 		
71
 		
72
 		if (bounds != null)
72
 		if (bounds != null)
73
 			layout();
73
 			layout();
74
 	}
74
 	}
75
 
75
 
76
 	@Override
76
 	@Override
77
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
78
-		return preferences;
77
+	public LiveObject<DSizing> getSizing() {
78
+		return sizing;
79
 	}
79
 	}
80
 
80
 
81
 	@Override
81
 	@Override
108
 			canvas.drawText(style.labelFont, style.labelColor, x, y + baseline, component.label);
108
 			canvas.drawText(style.labelFont, style.labelColor, x, y + baseline, component.label);
109
 			component.component.paint(canvas);
109
 			component.component.paint(canvas);
110
 			
110
 			
111
-			y += component.component.getDimensionPreferences().getValue().preferredHeight + style.spacing;
111
+			y += component.component.getSizing().getValue().preferredHeight + style.spacing;
112
 		}
112
 		}
113
 	}
113
 	}
114
 
114
 
122
 		int y = bounds.y + style.paddingBottom;
122
 		int y = bounds.y + style.paddingBottom;
123
 		
123
 		
124
 		for (DFormComponent component : components) {
124
 		for (DFormComponent component : components) {
125
-			int preferredHeight = component.component.getDimensionPreferences().getValue().preferredHeight;
125
+			int preferredHeight = component.component.getSizing().getValue().preferredHeight;
126
 			DIRectangle componentBounds = new DIRectangle(x + maxLabelWidth, y, bounds.width - maxLabelWidth - style.paddingLeft - style.paddingRight - style.spacing, preferredHeight);
126
 			DIRectangle componentBounds = new DIRectangle(x + maxLabelWidth, y, bounds.width - maxLabelWidth - style.paddingLeft - style.paddingRight - style.spacing, preferredHeight);
127
 			component.component.setBounds(componentBounds);
127
 			component.component.setBounds(componentBounds);
128
 			
128
 			

+ 0
- 5
DrawableGui/src/main/java/org/openzen/drawablegui/live/ImmutableLiveObject.java View File

24
 		return value;
24
 		return value;
25
 	}
25
 	}
26
 
26
 
27
-	@Override
28
-	public void setValue(T value) {
29
-		throw new UnsupportedOperationException("Immutable value");
30
-	}
31
-
32
 	@Override
27
 	@Override
33
 	public ListenerHandle<Listener<T>> addListener(Listener<T> listener) {
28
 	public ListenerHandle<Listener<T>> addListener(Listener<T> listener) {
34
 		return new DummyListenerHandle<>(listener);
29
 		return new DummyListenerHandle<>(listener);

+ 0
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveObject.java View File

14
 public interface LiveObject<T> {
14
 public interface LiveObject<T> {
15
 	public T getValue();
15
 	public T getValue();
16
 	
16
 	
17
-	public void setValue(T value);
18
-	
19
 	public ListenerHandle<Listener<T>> addListener(Listener<T> listener);
17
 	public ListenerHandle<Listener<T>> addListener(Listener<T> listener);
20
 	
18
 	
21
 	public interface Listener<T> {
19
 	public interface Listener<T> {

+ 14
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/live/MutableLiveObject.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.live;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface MutableLiveObject<T> extends LiveObject<T> {
13
+	public void setValue(T value);
14
+}

+ 1
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/live/SimpleLiveObject.java View File

12
  *
12
  *
13
  * @author Hoofdgebruiker
13
  * @author Hoofdgebruiker
14
  */
14
  */
15
-public class SimpleLiveObject<T> implements LiveObject<T> {
15
+public class SimpleLiveObject<T> implements MutableLiveObject<T> {
16
 	private final ListenerList<Listener<T>> listeners = new ListenerList<>();
16
 	private final ListenerList<Listener<T>> listeners = new ListenerList<>();
17
 	private T value;
17
 	private T value;
18
 	
18
 	

+ 8
- 8
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollBar.java View File

7
 
7
 
8
 import org.openzen.drawablegui.DCanvas;
8
 import org.openzen.drawablegui.DCanvas;
9
 import org.openzen.drawablegui.DComponent;
9
 import org.openzen.drawablegui.DComponent;
10
-import org.openzen.drawablegui.DDimensionPreferences;
10
+import org.openzen.drawablegui.DSizing;
11
 import org.openzen.drawablegui.DMouseEvent;
11
 import org.openzen.drawablegui.DMouseEvent;
12
 import org.openzen.drawablegui.DIRectangle;
12
 import org.openzen.drawablegui.DIRectangle;
13
 import org.openzen.drawablegui.listeners.ListenerHandle;
13
 import org.openzen.drawablegui.listeners.ListenerHandle;
14
 import org.openzen.drawablegui.live.LiveInt;
14
 import org.openzen.drawablegui.live.LiveInt;
15
 import org.openzen.drawablegui.live.LiveObject;
15
 import org.openzen.drawablegui.live.LiveObject;
16
-import org.openzen.drawablegui.live.SimpleLiveObject;
17
 import org.openzen.drawablegui.DUIContext;
16
 import org.openzen.drawablegui.DUIContext;
17
+import org.openzen.drawablegui.live.MutableLiveObject;
18
 import org.openzen.drawablegui.style.DStyleClass;
18
 import org.openzen.drawablegui.style.DStyleClass;
19
 import org.openzen.drawablegui.style.DStylePath;
19
 import org.openzen.drawablegui.style.DStylePath;
20
 
20
 
23
  * @author Hoofdgebruiker
23
  * @author Hoofdgebruiker
24
  */
24
  */
25
 public class DScrollBar implements DComponent {
25
 public class DScrollBar implements DComponent {
26
-	private final LiveObject<DDimensionPreferences> preferences;
26
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
27
 	
27
 	
28
 	private final DStyleClass styleClass;
28
 	private final DStyleClass styleClass;
29
 	private final LiveInt targetHeight;
29
 	private final LiveInt targetHeight;
47
 		this.styleClass = styleClass;
47
 		this.styleClass = styleClass;
48
 		this.targetHeight = targetHeight;
48
 		this.targetHeight = targetHeight;
49
 		this.offset = offset;
49
 		this.offset = offset;
50
-		this.preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
51
 		
50
 		
52
 		targetHeightListener = targetHeight.addListener(new ScrollListener());
51
 		targetHeightListener = targetHeight.addListener(new ScrollListener());
53
 		offsetListener = offset.addListener(new ScrollListener());
52
 		offsetListener = offset.addListener(new ScrollListener());
57
 	public void setContext(DStylePath parent, DUIContext context) {
56
 	public void setContext(DStylePath parent, DUIContext context) {
58
 		this.context = context;
57
 		this.context = context;
59
 		this.style = new DScrollBarStyle(context.getStylesheets().get(context, parent.getChild("scrollbar", styleClass)));
58
 		this.style = new DScrollBarStyle(context.getStylesheets().get(context, parent.getChild("scrollbar", styleClass)));
60
-		preferences.setValue(new DDimensionPreferences(style.width, 0));
59
+		sizing.setValue(new DSizing(style.width, 0));
61
 	}
60
 	}
62
 
61
 
63
 	@Override
62
 	@Override
64
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
65
-		return preferences;
63
+	public LiveObject<DSizing> getSizing() {
64
+		return sizing;
66
 	}
65
 	}
67
 
66
 
68
 	@Override
67
 	@Override
138
 
137
 
139
 	@Override
138
 	@Override
140
 	public void close() {
139
 	public void close() {
141
-		// nothing to clean up
140
+		targetHeightListener.close();
141
+		offsetListener.close();
142
 	}
142
 	}
143
 	
143
 	
144
 	private void checkHover(DMouseEvent e) {
144
 	private void checkHover(DMouseEvent e) {

+ 7
- 8
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java View File

9
 import org.openzen.drawablegui.DCanvas;
9
 import org.openzen.drawablegui.DCanvas;
10
 import org.openzen.drawablegui.DClipboard;
10
 import org.openzen.drawablegui.DClipboard;
11
 import org.openzen.drawablegui.DComponent;
11
 import org.openzen.drawablegui.DComponent;
12
-import org.openzen.drawablegui.DDimensionPreferences;
12
+import org.openzen.drawablegui.DSizing;
13
 import org.openzen.drawablegui.DFont;
13
 import org.openzen.drawablegui.DFont;
14
 import org.openzen.drawablegui.DFontMetrics;
14
 import org.openzen.drawablegui.DFontMetrics;
15
 import org.openzen.drawablegui.DIRectangle;
15
 import org.openzen.drawablegui.DIRectangle;
61
 		offsetXListener = offsetX.addListener(new ScrollListener());
61
 		offsetXListener = offsetX.addListener(new ScrollListener());
62
 		offsetYListener = offsetY.addListener(new ScrollListener());
62
 		offsetYListener = offsetY.addListener(new ScrollListener());
63
 		
63
 		
64
-		contents.getDimensionPreferences().addListener((oldPreferences, newPreferences) -> {
64
+		contents.getSizing().addListener((oldPreferences, newPreferences) -> {
65
 			if (bounds == null)
65
 			if (bounds == null)
66
 				return;
66
 				return;
67
 			
67
 			
94
 	}
94
 	}
95
 
95
 
96
 	@Override
96
 	@Override
97
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
98
-		return contents.getDimensionPreferences(); // TODO: derived preferences
97
+	public LiveObject<DSizing> getSizing() {
98
+		return contents.getSizing(); // TODO: derived preferences
99
 	}
99
 	}
100
 
100
 
101
 	@Override
101
 	@Override
115
 		if (this.context == null)
115
 		if (this.context == null)
116
 			return;
116
 			return;
117
 		
117
 		
118
-		int height = Math.max(
119
-				bounds.height - style.border.getPaddingTop() - style.border.getPaddingBottom(),
120
-				contents.getDimensionPreferences().getValue().preferredHeight);
121
-		int scrollBarWidth = scrollBar.getDimensionPreferences().getValue().preferredWidth;
118
+		int height = Math.max(bounds.height - style.border.getPaddingTop() - style.border.getPaddingBottom(),
119
+				contents.getSizing().getValue().preferredHeight);
120
+		int scrollBarWidth = scrollBar.getSizing().getValue().preferredWidth;
122
 		scrollBar.setBounds(new DIRectangle(
121
 		scrollBar.setBounds(new DIRectangle(
123
 				bounds.x + bounds.width - scrollBarWidth - style.border.getPaddingRight(),
122
 				bounds.x + bounds.width - scrollBarWidth - style.border.getPaddingRight(),
124
 				bounds.y + style.border.getPaddingTop(),
123
 				bounds.y + style.border.getPaddingTop(),

+ 0
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPaneStyle.java View File

7
 
7
 
8
 import org.openzen.drawablegui.border.DBorder;
8
 import org.openzen.drawablegui.border.DBorder;
9
 import org.openzen.drawablegui.border.DLineBorder;
9
 import org.openzen.drawablegui.border.DLineBorder;
10
-import org.openzen.drawablegui.DUIContext;
11
 import org.openzen.drawablegui.style.DStyleDefinition;
10
 import org.openzen.drawablegui.style.DStyleDefinition;
12
 
11
 
13
 /**
12
 /**

+ 2
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingDialog.java View File

13
 import javax.swing.JDialog;
13
 import javax.swing.JDialog;
14
 import javax.swing.JFrame;
14
 import javax.swing.JFrame;
15
 import org.openzen.drawablegui.DComponent;
15
 import org.openzen.drawablegui.DComponent;
16
-import org.openzen.drawablegui.DDimensionPreferences;
16
+import org.openzen.drawablegui.DSizing;
17
 import org.openzen.drawablegui.DIRectangle;
17
 import org.openzen.drawablegui.DIRectangle;
18
 import org.openzen.drawablegui.DUIContext;
18
 import org.openzen.drawablegui.DUIContext;
19
 import org.openzen.drawablegui.DUIWindow;
19
 import org.openzen.drawablegui.DUIWindow;
125
 		SwingDialog result = new SwingDialog(this, title, component, false);
125
 		SwingDialog result = new SwingDialog(this, title, component, false);
126
 		result.setResizable(false);
126
 		result.setResizable(false);
127
 		
127
 		
128
-		DDimensionPreferences size = component.getDimensionPreferences().getValue();
128
+		DSizing size = component.getSizing().getValue();
129
 		result.setLocation(
129
 		result.setLocation(
130
 				getX() + (getWidth() - size.preferredWidth) / 2,
130
 				getX() + (getWidth() - size.preferredWidth) / 2,
131
 				getY() + (getHeight() - size.preferredHeight) / 2);
131
 				getY() + (getHeight() - size.preferredHeight) / 2);

+ 3
- 3
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingGraphicsContext.java View File

15
 import org.openzen.drawablegui.DAnchor;
15
 import org.openzen.drawablegui.DAnchor;
16
 import org.openzen.drawablegui.DClipboard;
16
 import org.openzen.drawablegui.DClipboard;
17
 import org.openzen.drawablegui.DComponent;
17
 import org.openzen.drawablegui.DComponent;
18
-import org.openzen.drawablegui.DDimensionPreferences;
18
+import org.openzen.drawablegui.DSizing;
19
 import org.openzen.drawablegui.DPath;
19
 import org.openzen.drawablegui.DPath;
20
 import org.openzen.drawablegui.DFont;
20
 import org.openzen.drawablegui.DFont;
21
 import org.openzen.drawablegui.DFontMetrics;
21
 import org.openzen.drawablegui.DFontMetrics;
155
 		windowContext.graphics = this.graphics; // help a little...
155
 		windowContext.graphics = this.graphics; // help a little...
156
 		
156
 		
157
 		root.setContext(DStylePathRoot.INSTANCE, windowContext);
157
 		root.setContext(DStylePathRoot.INSTANCE, windowContext);
158
-		DDimensionPreferences dimension = root.getDimensionPreferences().getValue();
158
+		DSizing dimension = root.getSizing().getValue();
159
 		int tx = (int)(x - anchor.alignX * dimension.preferredWidth);
159
 		int tx = (int)(x - anchor.alignX * dimension.preferredWidth);
160
 		int ty = (int)(y - anchor.alignY * dimension.preferredHeight);
160
 		int ty = (int)(y - anchor.alignY * dimension.preferredHeight);
161
 		
161
 		
175
 		windowContext.graphics = this.graphics; // help a little...
175
 		windowContext.graphics = this.graphics; // help a little...
176
 		
176
 		
177
 		root.setContext(DStylePathRoot.INSTANCE, windowContext);
177
 		root.setContext(DStylePathRoot.INSTANCE, windowContext);
178
-		DDimensionPreferences dimension = root.getDimensionPreferences().getValue();
178
+		DSizing dimension = root.getSizing().getValue();
179
 		int tx = (int)(x - anchor.alignX * dimension.preferredWidth);
179
 		int tx = (int)(x - anchor.alignX * dimension.preferredWidth);
180
 		int ty = (int)(y - anchor.alignY * dimension.preferredHeight);
180
 		int ty = (int)(y - anchor.alignY * dimension.preferredHeight);
181
 		
181
 		

+ 2
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingWindow.java View File

12
 import java.awt.event.WindowStateListener;
12
 import java.awt.event.WindowStateListener;
13
 import javax.swing.JFrame;
13
 import javax.swing.JFrame;
14
 import org.openzen.drawablegui.DComponent;
14
 import org.openzen.drawablegui.DComponent;
15
-import org.openzen.drawablegui.DDimensionPreferences;
15
+import org.openzen.drawablegui.DSizing;
16
 import org.openzen.drawablegui.DIRectangle;
16
 import org.openzen.drawablegui.DIRectangle;
17
 import org.openzen.drawablegui.DUIContext;
17
 import org.openzen.drawablegui.DUIContext;
18
 import org.openzen.drawablegui.DUIWindow;
18
 import org.openzen.drawablegui.DUIWindow;
106
 		SwingWindow result = new SwingWindow(title, component, false);
106
 		SwingWindow result = new SwingWindow(title, component, false);
107
 		result.setResizable(false);
107
 		result.setResizable(false);
108
 		
108
 		
109
-		DDimensionPreferences size = component.getDimensionPreferences().getValue();
109
+		DSizing size = component.getSizing().getValue();
110
 		result.setLocation(
110
 		result.setLocation(
111
 				getX() + (getWidth() - size.preferredWidth) / 2,
111
 				getX() + (getWidth() - size.preferredWidth) / 2,
112
 				getY() + (getHeight() - size.preferredHeight) / 2);
112
 				getY() + (getHeight() - size.preferredHeight) / 2);

+ 7
- 9
DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeView.java View File

10
 import java.util.List;
10
 import java.util.List;
11
 import org.openzen.drawablegui.DCanvas;
11
 import org.openzen.drawablegui.DCanvas;
12
 import org.openzen.drawablegui.DComponent;
12
 import org.openzen.drawablegui.DComponent;
13
-import org.openzen.drawablegui.DDimensionPreferences;
13
+import org.openzen.drawablegui.DSizing;
14
 import org.openzen.drawablegui.DDrawable;
14
 import org.openzen.drawablegui.DDrawable;
15
 import org.openzen.drawablegui.DFontMetrics;
15
 import org.openzen.drawablegui.DFontMetrics;
16
 import org.openzen.drawablegui.DMouseEvent;
16
 import org.openzen.drawablegui.DMouseEvent;
18
 import org.openzen.drawablegui.DIRectangle;
18
 import org.openzen.drawablegui.DIRectangle;
19
 import org.openzen.drawablegui.listeners.ListenerHandle;
19
 import org.openzen.drawablegui.listeners.ListenerHandle;
20
 import org.openzen.drawablegui.live.LiveBool;
20
 import org.openzen.drawablegui.live.LiveBool;
21
-import org.openzen.drawablegui.live.LiveObject;
22
-import org.openzen.drawablegui.live.SimpleLiveObject;
23
 import org.openzen.drawablegui.DUIContext;
21
 import org.openzen.drawablegui.DUIContext;
24
 import org.openzen.drawablegui.live.LiveList;
22
 import org.openzen.drawablegui.live.LiveList;
23
+import org.openzen.drawablegui.live.MutableLiveObject;
25
 import org.openzen.drawablegui.style.DStylePath;
24
 import org.openzen.drawablegui.style.DStylePath;
26
 
25
 
27
 /**
26
 /**
29
  * @author Hoofdgebruiker
28
  * @author Hoofdgebruiker
30
  */
29
  */
31
 public class DTreeView<N extends DTreeNode<N>> implements DComponent {
30
 public class DTreeView<N extends DTreeNode<N>> implements DComponent {
32
-	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
31
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
33
 	private DIRectangle bounds;
32
 	private DIRectangle bounds;
34
 	
33
 	
35
 	private int selectedRow = -1;
34
 	private int selectedRow = -1;
60
 	}
59
 	}
61
 
60
 
62
 	@Override
61
 	@Override
63
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
64
-		return dimensionPreferences;
62
+	public MutableLiveObject<DSizing> getSizing() {
63
+		return sizing;
65
 	}
64
 	}
66
 	
65
 	
67
 	@Override
66
 	@Override
188
 		}
187
 		}
189
 		
188
 		
190
 		if (rows.size() != oldRowCount) {
189
 		if (rows.size() != oldRowCount) {
191
-			DDimensionPreferences preferences = dimensionPreferences.getValue();
192
-			dimensionPreferences.setValue(
193
-					new DDimensionPreferences(
190
+			DSizing preferences = sizing.getValue();
191
+			sizing.setValue(new DSizing(
194
 							preferences.minimumWidth,
192
 							preferences.minimumWidth,
195
 							preferences.minimumHeight,
193
 							preferences.minimumHeight,
196
 							preferences.preferredWidth,
194
 							preferences.preferredWidth,

+ 2
- 2
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectBar.java View File

6
 package org.openzen.zenscript.ide.ui;
6
 package org.openzen.zenscript.ide.ui;
7
 
7
 
8
 import org.openzen.drawablegui.live.LiveArrayList;
8
 import org.openzen.drawablegui.live.LiveArrayList;
9
-import org.openzen.drawablegui.live.LiveObject;
10
 import org.openzen.drawablegui.live.MutableLiveList;
9
 import org.openzen.drawablegui.live.MutableLiveList;
10
+import org.openzen.drawablegui.live.MutableLiveObject;
11
 import org.openzen.drawablegui.live.SimpleLiveObject;
11
 import org.openzen.drawablegui.live.SimpleLiveObject;
12
 
12
 
13
 /**
13
 /**
16
  */
16
  */
17
 public class IDEAspectBar {
17
 public class IDEAspectBar {
18
 	public final MutableLiveList<IDEAspectToolbar> toolbars = new LiveArrayList<>();
18
 	public final MutableLiveList<IDEAspectToolbar> toolbars = new LiveArrayList<>();
19
-	public final LiveObject<IDEAspectToolbar> active = new SimpleLiveObject<>(null);
19
+	public final MutableLiveObject<IDEAspectToolbar> active = new SimpleLiveObject<>(null);
20
 }
20
 }

+ 4
- 4
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java View File

6
 package org.openzen.zenscript.ide.ui;
6
 package org.openzen.zenscript.ide.ui;
7
 
7
 
8
 import org.openzen.drawablegui.live.LiveBool;
8
 import org.openzen.drawablegui.live.LiveBool;
9
-import org.openzen.drawablegui.live.LiveObject;
10
 import org.openzen.drawablegui.live.LivePredicateBool;
9
 import org.openzen.drawablegui.live.LivePredicateBool;
10
+import org.openzen.drawablegui.live.MutableLiveObject;
11
 import org.openzen.drawablegui.live.SimpleLiveObject;
11
 import org.openzen.drawablegui.live.SimpleLiveObject;
12
 import org.openzen.drawablegui.style.DStyleClass;
12
 import org.openzen.drawablegui.style.DStyleClass;
13
 import org.openzen.zenscript.ide.host.DevelopmentHost;
13
 import org.openzen.zenscript.ide.host.DevelopmentHost;
37
 	
37
 	
38
 	public IDEAspectToolbar projectToolbar;
38
 	public IDEAspectToolbar projectToolbar;
39
 	
39
 	
40
-	private final LiveObject<IDEModule> contextModule = new SimpleLiveObject<>(null);
41
-	private final LiveObject<IDEPackage> contextPackage = new SimpleLiveObject<>(null);
42
-	private final LiveObject<IDESourceFile> contextFile = new SimpleLiveObject<>(null);
40
+	private final MutableLiveObject<IDEModule> contextModule = new SimpleLiveObject<>(null);
41
+	private final MutableLiveObject<IDEPackage> contextPackage = new SimpleLiveObject<>(null);
42
+	private final MutableLiveObject<IDESourceFile> contextFile = new SimpleLiveObject<>(null);
43
 	private final LiveBool addContentDisabled = new LivePredicateBool(contextPackage, pkg -> pkg == null);
43
 	private final LiveBool addContentDisabled = new LivePredicateBool(contextPackage, pkg -> pkg == null);
44
 	
44
 	
45
 	public IDEWindow(DevelopmentHost host) {
45
 	public IDEWindow(DevelopmentHost host) {

+ 3
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/dialog/CreateSourceFileDialog.java View File

23
 import org.openzen.drawablegui.style.DStyleClass;
23
 import org.openzen.drawablegui.style.DStyleClass;
24
 import org.openzen.zenscript.ide.host.IDEModule;
24
 import org.openzen.zenscript.ide.host.IDEModule;
25
 import org.openzen.zenscript.ide.host.IDEPackage;
25
 import org.openzen.zenscript.ide.host.IDEPackage;
26
+import org.openzen.zenscript.ide.host.IDESourceFile;
26
 import org.openzen.zenscript.ide.ui.IDEWindow;
27
 import org.openzen.zenscript.ide.ui.IDEWindow;
27
 
28
 
28
 /**
29
 /**
84
 	
85
 	
85
 	private void ok() {
86
 	private void ok() {
86
 		window.close();
87
 		window.close();
87
-		pkg.createSourceFile(name.getValue() + ".zs");
88
+		IDESourceFile file = pkg.createSourceFile(name.getValue() + ".zs");
89
+		ideWindow.open(file);
88
 	}
90
 	}
89
 }
91
 }

+ 5
- 5
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/IconButtonControl.java View File

8
 import java.util.function.Consumer;
8
 import java.util.function.Consumer;
9
 import org.openzen.drawablegui.DCanvas;
9
 import org.openzen.drawablegui.DCanvas;
10
 import org.openzen.drawablegui.DComponent;
10
 import org.openzen.drawablegui.DComponent;
11
-import org.openzen.drawablegui.DDimensionPreferences;
11
+import org.openzen.drawablegui.DSizing;
12
 import org.openzen.drawablegui.DDrawable;
12
 import org.openzen.drawablegui.DDrawable;
13
 import org.openzen.drawablegui.DMouseEvent;
13
 import org.openzen.drawablegui.DMouseEvent;
14
 import org.openzen.drawablegui.DPath;
14
 import org.openzen.drawablegui.DPath;
19
 import org.openzen.drawablegui.live.ImmutableLiveBool;
19
 import org.openzen.drawablegui.live.ImmutableLiveBool;
20
 import org.openzen.drawablegui.live.LiveBool;
20
 import org.openzen.drawablegui.live.LiveBool;
21
 import org.openzen.drawablegui.live.LiveObject;
21
 import org.openzen.drawablegui.live.LiveObject;
22
-import org.openzen.drawablegui.live.SimpleLiveObject;
22
+import org.openzen.drawablegui.live.MutableLiveObject;
23
 import org.openzen.drawablegui.style.DStyleClass;
23
 import org.openzen.drawablegui.style.DStyleClass;
24
 import org.openzen.drawablegui.style.DStylePath;
24
 import org.openzen.drawablegui.style.DStylePath;
25
 
25
 
38
 	private DUIContext context;
38
 	private DUIContext context;
39
 	private IconButtonControlStyle style;
39
 	private IconButtonControlStyle style;
40
 	private DIRectangle bounds;
40
 	private DIRectangle bounds;
41
-	private final LiveObject<DDimensionPreferences> preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
41
+	private final MutableLiveObject<DSizing> preferences = DSizing.create();
42
 	private boolean hover;
42
 	private boolean hover;
43
 	private boolean press;
43
 	private boolean press;
44
 	private DPath shape;
44
 	private DPath shape;
66
 		int iconHeight = (int)(icon.getNominalWidth() * context.getScale() + 0.5f);
66
 		int iconHeight = (int)(icon.getNominalWidth() * context.getScale() + 0.5f);
67
 		int width = iconWidth + 2 * style.padding + 2 * style.margin;
67
 		int width = iconWidth + 2 * style.padding + 2 * style.margin;
68
 		int height = iconHeight + 2 * style.padding + 2 * style.margin;
68
 		int height = iconHeight + 2 * style.padding + 2 * style.margin;
69
-		preferences.setValue(new DDimensionPreferences(width, height));
69
+		preferences.setValue(new DSizing(width, height));
70
 		
70
 		
71
 		if (bounds != null)
71
 		if (bounds != null)
72
 			setBounds(bounds);
72
 			setBounds(bounds);
73
 	}
73
 	}
74
 
74
 
75
 	@Override
75
 	@Override
76
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
76
+	public LiveObject<DSizing> getSizing() {
77
 		return preferences;
77
 		return preferences;
78
 	}
78
 	}
79
 
79
 

+ 4
- 4
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/StatusBarView.java View File

7
 
7
 
8
 import org.openzen.drawablegui.DCanvas;
8
 import org.openzen.drawablegui.DCanvas;
9
 import org.openzen.drawablegui.DComponent;
9
 import org.openzen.drawablegui.DComponent;
10
-import org.openzen.drawablegui.DDimensionPreferences;
10
+import org.openzen.drawablegui.DSizing;
11
 import org.openzen.drawablegui.DFontMetrics;
11
 import org.openzen.drawablegui.DFontMetrics;
12
 import org.openzen.drawablegui.DIRectangle;
12
 import org.openzen.drawablegui.DIRectangle;
13
 import org.openzen.drawablegui.live.LiveObject;
13
 import org.openzen.drawablegui.live.LiveObject;
22
  * @author Hoofdgebruiker
22
  * @author Hoofdgebruiker
23
  */
23
  */
24
 public class StatusBarView implements DComponent {
24
 public class StatusBarView implements DComponent {
25
-	private final SimpleLiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(new DDimensionPreferences(0, 0));
25
+	private final SimpleLiveObject<DSizing> dimensionPreferences = new SimpleLiveObject<>(new DSizing(0, 0));
26
 	
26
 	
27
 	private final DStyleClass styleClass;
27
 	private final DStyleClass styleClass;
28
 	private final LiveString content;
28
 	private final LiveString content;
44
 		style = new StatusBarStyle(context.getStylesheets().get(context, path));
44
 		style = new StatusBarStyle(context.getStylesheets().get(context, path));
45
 		fontMetrics = context.getFontMetrics(style.font);
45
 		fontMetrics = context.getFontMetrics(style.font);
46
 		
46
 		
47
-		dimensionPreferences.setValue(new DDimensionPreferences(0, style.paddingTop + fontMetrics.getAscent() + fontMetrics.getDescent() + style.paddingBottom));
47
+		dimensionPreferences.setValue(new DSizing(0, style.paddingTop + fontMetrics.getAscent() + fontMetrics.getDescent() + style.paddingBottom));
48
 	}
48
 	}
49
 	
49
 	
50
 	@Override
50
 	@Override
51
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
51
+	public LiveObject<DSizing> getSizing() {
52
 		return dimensionPreferences;
52
 		return dimensionPreferences;
53
 	}
53
 	}
54
 	
54
 	

+ 7
- 7
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedView.java View File

10
 import org.openzen.drawablegui.BaseComponentGroup;
10
 import org.openzen.drawablegui.BaseComponentGroup;
11
 import org.openzen.drawablegui.DCanvas;
11
 import org.openzen.drawablegui.DCanvas;
12
 import org.openzen.drawablegui.DComponent;
12
 import org.openzen.drawablegui.DComponent;
13
-import org.openzen.drawablegui.DDimensionPreferences;
13
+import org.openzen.drawablegui.DSizing;
14
 import org.openzen.drawablegui.DFontMetrics;
14
 import org.openzen.drawablegui.DFontMetrics;
15
 import org.openzen.drawablegui.DIRectangle;
15
 import org.openzen.drawablegui.DIRectangle;
16
 import org.openzen.drawablegui.DUIContext;
16
 import org.openzen.drawablegui.DUIContext;
17
-import org.openzen.drawablegui.live.ImmutableLiveObject;
18
 import org.openzen.drawablegui.live.LiveArrayList;
17
 import org.openzen.drawablegui.live.LiveArrayList;
19
 import org.openzen.drawablegui.live.LiveList;
18
 import org.openzen.drawablegui.live.LiveList;
20
 import org.openzen.drawablegui.live.LiveMappedList;
19
 import org.openzen.drawablegui.live.LiveMappedList;
21
 import org.openzen.drawablegui.live.LiveObject;
20
 import org.openzen.drawablegui.live.LiveObject;
22
 import org.openzen.drawablegui.live.MutableLiveList;
21
 import org.openzen.drawablegui.live.MutableLiveList;
22
+import org.openzen.drawablegui.live.MutableLiveObject;
23
 import org.openzen.drawablegui.live.SimpleLiveObject;
23
 import org.openzen.drawablegui.live.SimpleLiveObject;
24
 import org.openzen.drawablegui.style.DStyleClass;
24
 import org.openzen.drawablegui.style.DStyleClass;
25
 import org.openzen.drawablegui.style.DStylePath;
25
 import org.openzen.drawablegui.style.DStylePath;
31
 public class TabbedView extends BaseComponentGroup {
31
 public class TabbedView extends BaseComponentGroup {
32
 	private final DStyleClass styleClass;
32
 	private final DStyleClass styleClass;
33
 	public final MutableLiveList<TabbedViewComponent> tabs = new LiveArrayList<>();
33
 	public final MutableLiveList<TabbedViewComponent> tabs = new LiveArrayList<>();
34
-	private final LiveObject<DDimensionPreferences> preferences = new ImmutableLiveObject<>(DDimensionPreferences.EMPTY);
35
-	public final LiveObject<TabbedViewComponent> currentTab = new SimpleLiveObject<>(null);
34
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
35
+	public final MutableLiveObject<TabbedViewComponent> currentTab = new SimpleLiveObject<>(null);
36
 	
36
 	
37
 	private DUIContext context;
37
 	private DUIContext context;
38
 	private DStylePath path;
38
 	private DStylePath path;
82
 	}
82
 	}
83
 
83
 
84
 	@Override
84
 	@Override
85
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
86
-		return preferences;
85
+	public LiveObject<DSizing> getSizing() {
86
+		return sizing;
87
 	}
87
 	}
88
 
88
 
89
 	@Override
89
 	@Override
141
 		
141
 		
142
 		int x = bounds.x + style.tabBarSpacingLeft;
142
 		int x = bounds.x + style.tabBarSpacingLeft;
143
 		for (DComponent tab : tabComponents) {
143
 		for (DComponent tab : tabComponents) {
144
-			DDimensionPreferences preferences = tab.getDimensionPreferences().getValue();
144
+			DSizing preferences = tab.getSizing().getValue();
145
 			tab.setBounds(new DIRectangle(
145
 			tab.setBounds(new DIRectangle(
146
 					x, bounds.y + totalTabHeight - preferences.preferredHeight, preferences.preferredWidth, preferences.preferredHeight));
146
 					x, bounds.y + totalTabHeight - preferences.preferredHeight, preferences.preferredWidth, preferences.preferredHeight));
147
 			
147
 			

+ 11
- 11
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTab.java View File

7
 
7
 
8
 import org.openzen.drawablegui.DCanvas;
8
 import org.openzen.drawablegui.DCanvas;
9
 import org.openzen.drawablegui.DComponent;
9
 import org.openzen.drawablegui.DComponent;
10
-import org.openzen.drawablegui.DDimensionPreferences;
10
+import org.openzen.drawablegui.DSizing;
11
 import org.openzen.drawablegui.DFontMetrics;
11
 import org.openzen.drawablegui.DFontMetrics;
12
 import org.openzen.drawablegui.DIRectangle;
12
 import org.openzen.drawablegui.DIRectangle;
13
 import org.openzen.drawablegui.DMouseEvent;
13
 import org.openzen.drawablegui.DMouseEvent;
15
 import org.openzen.drawablegui.DTransform2D;
15
 import org.openzen.drawablegui.DTransform2D;
16
 import org.openzen.drawablegui.DUIContext;
16
 import org.openzen.drawablegui.DUIContext;
17
 import org.openzen.drawablegui.live.LiveObject;
17
 import org.openzen.drawablegui.live.LiveObject;
18
-import org.openzen.drawablegui.live.SimpleLiveObject;
18
+import org.openzen.drawablegui.live.MutableLiveObject;
19
 import org.openzen.drawablegui.style.DStyleClass;
19
 import org.openzen.drawablegui.style.DStyleClass;
20
 import org.openzen.drawablegui.style.DStylePath;
20
 import org.openzen.drawablegui.style.DStylePath;
21
 
21
 
25
  */
25
  */
26
 public class TabbedViewTab implements DComponent {
26
 public class TabbedViewTab implements DComponent {
27
 	private final TabbedViewComponent tab;
27
 	private final TabbedViewComponent tab;
28
-	private final LiveObject<DDimensionPreferences> preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
29
-	private final LiveObject<TabbedViewComponent> currentTab;
28
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
29
+	private final MutableLiveObject<TabbedViewComponent> currentTab;
30
 	
30
 	
31
 	private final TabbedView parent;
31
 	private final TabbedView parent;
32
 	public final TabbedViewTabClose closeButton;
32
 	public final TabbedViewTabClose closeButton;
40
 	private boolean hover;
40
 	private boolean hover;
41
 	private boolean press;
41
 	private boolean press;
42
 	
42
 	
43
-	public TabbedViewTab(TabbedView parent, LiveObject<TabbedViewComponent> currentTab, TabbedViewComponent tab) {
43
+	public TabbedViewTab(TabbedView parent, MutableLiveObject<TabbedViewComponent> currentTab, TabbedViewComponent tab) {
44
 		this.parent = parent;
44
 		this.parent = parent;
45
 		this.currentTab = currentTab;
45
 		this.currentTab = currentTab;
46
 		this.tab = tab;
46
 		this.tab = tab;
60
 		closeButton.setContext(path, context);
60
 		closeButton.setContext(path, context);
61
 		
61
 		
62
 		textWidth = fontMetrics.getWidth(tab.title);
62
 		textWidth = fontMetrics.getWidth(tab.title);
63
-		preferences.setValue(new DDimensionPreferences(
63
+		sizing.setValue(new DSizing(
64
 				style.paddingLeft + textWidth + style.paddingRight
64
 				style.paddingLeft + textWidth + style.paddingRight
65
 						+ style.closeIconPadding
65
 						+ style.closeIconPadding
66
-						+ closeButton.getDimensionPreferences().getValue().preferredWidth,
66
+						+ closeButton.getSizing().getValue().preferredWidth,
67
 				style.paddingTop + fontMetrics.getAscent() + fontMetrics.getDescent()
67
 				style.paddingTop + fontMetrics.getAscent() + fontMetrics.getDescent()
68
 						+ style.paddingBottom));
68
 						+ style.paddingBottom));
69
 	}
69
 	}
70
 
70
 
71
 	@Override
71
 	@Override
72
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
73
-		return preferences;
72
+	public LiveObject<DSizing> getSizing() {
73
+		return sizing;
74
 	}
74
 	}
75
 
75
 
76
 	@Override
76
 	@Override
87
 	public void setBounds(DIRectangle bounds) {
87
 	public void setBounds(DIRectangle bounds) {
88
 		this.bounds = bounds;
88
 		this.bounds = bounds;
89
 		
89
 		
90
-		DDimensionPreferences close = closeButton.getDimensionPreferences().getValue();
90
+		DSizing close = closeButton.getSizing().getValue();
91
 		closeButton.setBounds(new DIRectangle(
91
 		closeButton.setBounds(new DIRectangle(
92
 				bounds.x + bounds.width - close.preferredWidth - style.paddingRight,
92
 				bounds.x + bounds.width - close.preferredWidth - style.paddingRight,
93
 				bounds.y + (bounds.height - close.preferredHeight) / 2,
93
 				bounds.y + (bounds.height - close.preferredHeight) / 2,
98
 	@Override
98
 	@Override
99
 	public void paint(DCanvas canvas) {
99
 	public void paint(DCanvas canvas) {
100
 		int width = style.paddingLeft + textWidth + style.paddingRight
100
 		int width = style.paddingLeft + textWidth + style.paddingRight
101
-				+ closeButton.getDimensionPreferences().getValue().preferredWidth + style.closeIconPadding;
101
+				+ closeButton.getSizing().getValue().preferredWidth + style.closeIconPadding;
102
 
102
 
103
 		int color = style.tabColorNormal;
103
 		int color = style.tabColorNormal;
104
 		if (currentTab.getValue() == tab)
104
 		if (currentTab.getValue() == tab)

+ 6
- 8
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTabClose.java View File

8
 import org.openzen.drawablegui.DCanvas;
8
 import org.openzen.drawablegui.DCanvas;
9
 import org.openzen.drawablegui.DColorableIcon;
9
 import org.openzen.drawablegui.DColorableIcon;
10
 import org.openzen.drawablegui.DComponent;
10
 import org.openzen.drawablegui.DComponent;
11
-import org.openzen.drawablegui.DDimensionPreferences;
12
-import org.openzen.drawablegui.DDrawable;
11
+import org.openzen.drawablegui.DSizing;
13
 import org.openzen.drawablegui.DIRectangle;
12
 import org.openzen.drawablegui.DIRectangle;
14
 import org.openzen.drawablegui.DMouseEvent;
13
 import org.openzen.drawablegui.DMouseEvent;
15
 import org.openzen.drawablegui.DTransform2D;
14
 import org.openzen.drawablegui.DTransform2D;
16
 import org.openzen.drawablegui.DUIContext;
15
 import org.openzen.drawablegui.DUIContext;
17
 import org.openzen.drawablegui.live.LiveObject;
16
 import org.openzen.drawablegui.live.LiveObject;
18
-import org.openzen.drawablegui.live.SimpleLiveObject;
17
+import org.openzen.drawablegui.live.MutableLiveObject;
19
 import org.openzen.drawablegui.style.DStyleClass;
18
 import org.openzen.drawablegui.style.DStyleClass;
20
 import org.openzen.drawablegui.style.DStylePath;
19
 import org.openzen.drawablegui.style.DStylePath;
21
-import org.openzen.zenscript.ide.ui.icons.ColoredIcon;
22
 import org.openzen.zenscript.ide.ui.icons.ScalableCloseIcon;
20
 import org.openzen.zenscript.ide.ui.icons.ScalableCloseIcon;
23
 
21
 
24
 /**
22
 /**
27
  */
25
  */
28
 public class TabbedViewTabClose implements DComponent {
26
 public class TabbedViewTabClose implements DComponent {
29
 	private final TabbedViewTab tab;
27
 	private final TabbedViewTab tab;
30
-	private final LiveObject<DDimensionPreferences> preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
28
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
31
 	
29
 	
32
 	private DUIContext context;
30
 	private DUIContext context;
33
 	private DIRectangle bounds;
31
 	private DIRectangle bounds;
47
 		
45
 		
48
 		DStylePath path = parent.getChild("tabClose", DStyleClass.EMPTY);
46
 		DStylePath path = parent.getChild("tabClose", DStyleClass.EMPTY);
49
 		style = new TabbedViewTabCloseStyle(context.getStylesheets().get(context, path));
47
 		style = new TabbedViewTabCloseStyle(context.getStylesheets().get(context, path));
50
-		preferences.setValue(new DDimensionPreferences(style.size, style.size));
48
+		sizing.setValue(new DSizing(style.size, style.size));
51
 		icon = new ScalableCloseIcon(style.size / 24);
49
 		icon = new ScalableCloseIcon(style.size / 24);
52
 	}
50
 	}
53
 
51
 
54
 	@Override
52
 	@Override
55
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
56
-		return preferences;
53
+	public LiveObject<DSizing> getSizing() {
54
+		return sizing;
57
 	}
55
 	}
58
 
56
 
59
 	@Override
57
 	@Override

+ 2
- 2
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.ui.view;
6
 package org.openzen.zenscript.ide.ui.view;
7
 
7
 
8
-import org.openzen.drawablegui.DDimensionPreferences;
8
+import org.openzen.drawablegui.DSizing;
9
 import org.openzen.drawablegui.DEmptyView;
9
 import org.openzen.drawablegui.DEmptyView;
10
 import org.openzen.drawablegui.scroll.DScrollPane;
10
 import org.openzen.drawablegui.scroll.DScrollPane;
11
 import org.openzen.drawablegui.DSideLayout;
11
 import org.openzen.drawablegui.DSideLayout;
36
 		this.window = window;
36
 		this.window = window;
37
 		
37
 		
38
 		DTreeView projectView = new DTreeView(DTreeViewStyle.DEFAULT, new RootTreeNode(window, host), false);
38
 		DTreeView projectView = new DTreeView(DTreeViewStyle.DEFAULT, new RootTreeNode(window, host), false);
39
-		projectView.getDimensionPreferences().setValue(new DDimensionPreferences(500, 500));
39
+		projectView.getSizing().setValue(new DSizing(500, 500));
40
 		setMain(tabs = new TabbedView(DStyleClass.EMPTY));
40
 		setMain(tabs = new TabbedView(DStyleClass.EMPTY));
41
 		add(Side.LEFT, new DScrollPane(DStyleClass.forId("projectView"), projectView));
41
 		add(Side.LEFT, new DScrollPane(DStyleClass.forId("projectView"), projectView));
42
 		add(Side.BOTTOM, new StatusBarView(DStyleClass.EMPTY, status));
42
 		add(Side.BOTTOM, new StatusBarView(DStyleClass.EMPTY, status));

+ 6
- 7
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButton.java View File

8
 import java.util.function.Consumer;
8
 import java.util.function.Consumer;
9
 import org.openzen.drawablegui.DCanvas;
9
 import org.openzen.drawablegui.DCanvas;
10
 import org.openzen.drawablegui.DComponent;
10
 import org.openzen.drawablegui.DComponent;
11
-import org.openzen.drawablegui.DDimensionPreferences;
11
+import org.openzen.drawablegui.DSizing;
12
 import org.openzen.drawablegui.DDrawable;
12
 import org.openzen.drawablegui.DDrawable;
13
 import org.openzen.drawablegui.DMouseEvent;
13
 import org.openzen.drawablegui.DMouseEvent;
14
 import org.openzen.drawablegui.DPath;
14
 import org.openzen.drawablegui.DPath;
18
 import org.openzen.drawablegui.listeners.ListenerHandle;
18
 import org.openzen.drawablegui.listeners.ListenerHandle;
19
 import org.openzen.drawablegui.live.LiveBool;
19
 import org.openzen.drawablegui.live.LiveBool;
20
 import org.openzen.drawablegui.live.LiveObject;
20
 import org.openzen.drawablegui.live.LiveObject;
21
-import org.openzen.drawablegui.live.SimpleLiveObject;
21
+import org.openzen.drawablegui.live.MutableLiveObject;
22
 import org.openzen.drawablegui.style.DShadow;
22
 import org.openzen.drawablegui.style.DShadow;
23
 import org.openzen.drawablegui.style.DStyleClass;
23
 import org.openzen.drawablegui.style.DStyleClass;
24
 import org.openzen.drawablegui.style.DStylePath;
24
 import org.openzen.drawablegui.style.DStylePath;
28
  * @author Hoofdgebruiker
28
  * @author Hoofdgebruiker
29
  */
29
  */
30
 public class AspectBarSelectorButton implements DComponent {
30
 public class AspectBarSelectorButton implements DComponent {
31
-	
32
 	public final LiveBool active;
31
 	public final LiveBool active;
33
 	
32
 	
34
 	private final DStyleClass styleClass;
33
 	private final DStyleClass styleClass;
35
 	private final DDrawable icon;
34
 	private final DDrawable icon;
36
-	private final LiveObject<DDimensionPreferences> preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
35
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
37
 	private final Consumer<DMouseEvent> onClick;
36
 	private final Consumer<DMouseEvent> onClick;
38
 	private DUIContext context;
37
 	private DUIContext context;
39
 	private AspectBarSelectorButtonStyle style;
38
 	private AspectBarSelectorButtonStyle style;
58
 		this.context = context;
57
 		this.context = context;
59
 		DStylePath path = parent.getChild("selectorbutton", styleClass);
58
 		DStylePath path = parent.getChild("selectorbutton", styleClass);
60
 		style = new AspectBarSelectorButtonStyle(context.getStylesheets().get(context, path));
59
 		style = new AspectBarSelectorButtonStyle(context.getStylesheets().get(context, path));
61
-		preferences.setValue(new DDimensionPreferences(style.width, style.height));
60
+		sizing.setValue(new DSizing(style.width, style.height));
62
 		shape = DPath.roundedRectangle(
61
 		shape = DPath.roundedRectangle(
63
 				0,
62
 				0,
64
 				0,
63
 				0,
68
 	}
67
 	}
69
 
68
 
70
 	@Override
69
 	@Override
71
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
72
-		return preferences;
70
+	public LiveObject<DSizing> getSizing() {
71
+		return sizing;
73
 	}
72
 	}
74
 
73
 
75
 	@Override
74
 	@Override

+ 1
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarStyle.java View File

40
 	public final DShadow windowControlShadow;
40
 	public final DShadow windowControlShadow;
41
 	
41
 	
42
 	public AspectBarStyle(DStyleDefinition style) {
42
 	public AspectBarStyle(DStyleDefinition style) {
43
-		height = style.getDimension("height", new DDpDimension(32));
43
+		height = style.getDimension("height", new DDpDimension(38));
44
 		aspectSelectorPaddingLeft = style.getDimension("aspectSelectorPaddingLeft", new DDpDimension(4));
44
 		aspectSelectorPaddingLeft = style.getDimension("aspectSelectorPaddingLeft", new DDpDimension(4));
45
 		aspectSelectorToToolbarSpacing = style.getDimension("aspectSelectorToToolbarSpacing", new DDpDimension(16));
45
 		aspectSelectorToToolbarSpacing = style.getDimension("aspectSelectorToToolbarSpacing", new DDpDimension(16));
46
 		toolbarTitleToControlsSpacing = style.getDimension("toolbarTitleToControlsSpacing", new DDpDimension(8));
46
 		toolbarTitleToControlsSpacing = style.getDimension("toolbarTitleToControlsSpacing", new DDpDimension(8));

+ 21
- 24
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarView.java View File

12
 import org.openzen.drawablegui.BaseComponentGroup;
12
 import org.openzen.drawablegui.BaseComponentGroup;
13
 import org.openzen.drawablegui.DCanvas;
13
 import org.openzen.drawablegui.DCanvas;
14
 import org.openzen.drawablegui.DComponent;
14
 import org.openzen.drawablegui.DComponent;
15
-import org.openzen.drawablegui.DDimensionPreferences;
15
+import org.openzen.drawablegui.DSizing;
16
 import org.openzen.drawablegui.DFontMetrics;
16
 import org.openzen.drawablegui.DFontMetrics;
17
 import org.openzen.drawablegui.DPath;
17
 import org.openzen.drawablegui.DPath;
18
 import org.openzen.drawablegui.DTransform2D;
18
 import org.openzen.drawablegui.DTransform2D;
19
 import org.openzen.drawablegui.DIRectangle;
19
 import org.openzen.drawablegui.DIRectangle;
20
 import org.openzen.drawablegui.live.LiveObject;
20
 import org.openzen.drawablegui.live.LiveObject;
21
-import org.openzen.drawablegui.live.SimpleLiveObject;
22
 import org.openzen.zenscript.ide.ui.IDEAspectBar;
21
 import org.openzen.zenscript.ide.ui.IDEAspectBar;
23
 import org.openzen.zenscript.ide.ui.IDEAspectToolbar;
22
 import org.openzen.zenscript.ide.ui.IDEAspectToolbar;
24
 import org.openzen.drawablegui.DUIContext;
23
 import org.openzen.drawablegui.DUIContext;
28
 import org.openzen.drawablegui.live.LiveList;
27
 import org.openzen.drawablegui.live.LiveList;
29
 import org.openzen.drawablegui.live.LiveMappedList;
28
 import org.openzen.drawablegui.live.LiveMappedList;
30
 import org.openzen.drawablegui.live.LivePredicateBool;
29
 import org.openzen.drawablegui.live.LivePredicateBool;
30
+import org.openzen.drawablegui.live.MutableLiveObject;
31
 import org.openzen.drawablegui.style.DStyleClass;
31
 import org.openzen.drawablegui.style.DStyleClass;
32
 import org.openzen.drawablegui.style.DStylePath;
32
 import org.openzen.drawablegui.style.DStylePath;
33
 import org.openzen.zenscript.ide.ui.IDEAspectBarControl;
33
 import org.openzen.zenscript.ide.ui.IDEAspectBarControl;
40
  * @author Hoofdgebruiker
40
  * @author Hoofdgebruiker
41
  */
41
  */
42
 public class AspectBarView extends BaseComponentGroup {
42
 public class AspectBarView extends BaseComponentGroup {
43
-	private final SimpleLiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(new DDimensionPreferences(0, 64));
43
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
44
 	private final DStyleClass styleClass;
44
 	private final DStyleClass styleClass;
45
 	private final IDEAspectBar aspectBar;
45
 	private final IDEAspectBar aspectBar;
46
-	private final List<IDEAspectToolbar> contextBars = new ArrayList<>();
47
 	
46
 	
48
 	private DIRectangle bounds;
47
 	private DIRectangle bounds;
49
 	private DUIContext context;
48
 	private DUIContext context;
64
 	private WindowActionButton maximizeRestore;
63
 	private WindowActionButton maximizeRestore;
65
 	private WindowActionButton close;
64
 	private WindowActionButton close;
66
 	
65
 	
67
-	private final ListenerHandle<LiveObject.Listener<DDimensionPreferences>> minimizeRelayout;
68
-	private final ListenerHandle<LiveObject.Listener<DDimensionPreferences>> maximizeRestoreRelayout;
69
-	private final ListenerHandle<LiveObject.Listener<DDimensionPreferences>> closeRelayout;
66
+	private final ListenerHandle<LiveObject.Listener<DSizing>> minimizeRelayout;
67
+	private final ListenerHandle<LiveObject.Listener<DSizing>> maximizeRestoreRelayout;
68
+	private final ListenerHandle<LiveObject.Listener<DSizing>> closeRelayout;
70
 	
69
 	
71
 	public AspectBarView(DStyleClass styleClass, IDEAspectBar aspectBar) {
70
 	public AspectBarView(DStyleClass styleClass, IDEAspectBar aspectBar) {
72
 		this.styleClass = styleClass;
71
 		this.styleClass = styleClass;
76
 		listener = aspectBar.toolbars.addListener(new ToolbarListListener());
75
 		listener = aspectBar.toolbars.addListener(new ToolbarListListener());
77
 		
76
 		
78
 		minimize = new WindowActionButton(scale -> new ScalableMinimizeIcon(scale), e -> context.getWindow().minimize());
77
 		minimize = new WindowActionButton(scale -> new ScalableMinimizeIcon(scale), e -> context.getWindow().minimize());
79
-		minimizeRelayout = minimize.getDimensionPreferences().addListener((a, b) -> layout());
78
+		minimizeRelayout = minimize.getSizing().addListener((a, b) -> layout());
80
 		maximizeRestore = new WindowActionButton(ScalableMaximizeIcon::new, e -> {
79
 		maximizeRestore = new WindowActionButton(ScalableMaximizeIcon::new, e -> {
81
 			if (context.getWindow().getWindowState().getValue() == DUIWindow.State.MAXIMIZED)
80
 			if (context.getWindow().getWindowState().getValue() == DUIWindow.State.MAXIMIZED)
82
 				context.getWindow().restore();
81
 				context.getWindow().restore();
83
 			else
82
 			else
84
 				context.getWindow().maximize();
83
 				context.getWindow().maximize();
85
 		});
84
 		});
86
-		maximizeRestoreRelayout = maximizeRestore.getDimensionPreferences().addListener((a, b) -> layout());
85
+		maximizeRestoreRelayout = maximizeRestore.getSizing().addListener((a, b) -> layout());
87
 		close = new WindowActionButton(scale -> new ScalableCloseIcon(scale), e -> context.getWindow().close());
86
 		close = new WindowActionButton(scale -> new ScalableCloseIcon(scale), e -> context.getWindow().close());
88
-		closeRelayout = close.getDimensionPreferences().addListener((a, b) -> layout());
87
+		closeRelayout = close.getSizing().addListener((a, b) -> layout());
89
 		
88
 		
90
 		selectorButtons = new LiveMappedList<>(
89
 		selectorButtons = new LiveMappedList<>(
91
 				aspectBar.toolbars,
90
 				aspectBar.toolbars,
111
 		activeToolbarTitleFontMetrics = context.getFontMetrics(style.activeToolbarTitleFont);
110
 		activeToolbarTitleFontMetrics = context.getFontMetrics(style.activeToolbarTitleFont);
112
 		showWindowControls = !context.getWindow().hasTitleBar();
111
 		showWindowControls = !context.getWindow().hasTitleBar();
113
 		
112
 		
113
+		sizing.setValue(new DSizing(0, style.height));
114
+		
114
 		for (DComponent selectorButton : selectorButtons)
115
 		for (DComponent selectorButton : selectorButtons)
115
 			selectorButton.setContext(path, context);
116
 			selectorButton.setContext(path, context);
116
 		
117
 		
117
-		if (bounds != null) {
118
-			layout();
119
-			aspectBar.active.setValue(aspectBar.active.getValue());
120
-		}
121
-		
122
 		if (activeToolbarComponents != null)
118
 		if (activeToolbarComponents != null)
123
 			for (DComponent component : activeToolbarComponents)
119
 			for (DComponent component : activeToolbarComponents)
124
 				component.setContext(path, context);
120
 				component.setContext(path, context);
129
 	}
125
 	}
130
 	
126
 	
131
 	@Override
127
 	@Override
132
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
133
-		return dimensionPreferences;
128
+	public LiveObject<DSizing> getSizing() {
129
+		return sizing;
134
 	}
130
 	}
135
 	
131
 	
136
 	@Override
132
 	@Override
231
 		layoutActiveToolbarComponents();
227
 		layoutActiveToolbarComponents();
232
 		
228
 		
233
 		int x = bounds.x + bounds.width;
229
 		int x = bounds.x + bounds.width;
234
-		DDimensionPreferences closeSize = close.getDimensionPreferences().getValue();
235
-		DDimensionPreferences maximizeRestoreSize = maximizeRestore.getDimensionPreferences().getValue();
236
-		DDimensionPreferences minimizeSize = minimize.getDimensionPreferences().getValue();
230
+		DSizing closeSize = close.getSizing().getValue();
231
+		DSizing maximizeRestoreSize = maximizeRestore.getSizing().getValue();
232
+		DSizing minimizeSize = minimize.getSizing().getValue();
237
 		
233
 		
238
 		x -= closeSize.preferredWidth;
234
 		x -= closeSize.preferredWidth;
239
 		close.setBounds(new DIRectangle(x, bounds.y, closeSize.preferredWidth, closeSize.preferredHeight));
235
 		close.setBounds(new DIRectangle(x, bounds.y, closeSize.preferredWidth, closeSize.preferredHeight));
253
 		int x = bounds.x + style.aspectSelectorPaddingLeft;
249
 		int x = bounds.x + style.aspectSelectorPaddingLeft;
254
 		
250
 		
255
 		for (DComponent component : selectorButtons) {
251
 		for (DComponent component : selectorButtons) {
256
-			int width = component.getDimensionPreferences().getValue().preferredWidth;
257
-			int height = component.getDimensionPreferences().getValue().preferredHeight;
252
+			int width = component.getSizing().getValue().preferredWidth;
253
+			int height = component.getSizing().getValue().preferredHeight;
258
 			int y = bounds.y + (bounds.height - style.aspectSelectorBottomSize - height) / 2;
254
 			int y = bounds.y + (bounds.height - style.aspectSelectorBottomSize - height) / 2;
259
 			component.setBounds(new DIRectangle(x, y, width, height));
255
 			component.setBounds(new DIRectangle(x, y, width, height));
260
 			
256
 			
265
 	}
261
 	}
266
 	
262
 	
267
 	private void layoutActiveToolbarComponents() {
263
 	private void layoutActiveToolbarComponents() {
268
-		if (bounds == null)
264
+		if (bounds == null || bounds.height < (style.aspectBarPaddingTop + style.controlPaddingTop + style.controlPaddingBottom))
269
 			return;
265
 			return;
270
 		
266
 		
271
 		int x = aspectSelectorEndX
267
 		int x = aspectSelectorEndX
275
 		
271
 		
276
 		int y = style.aspectBarPaddingTop + style.controlPaddingTop;
272
 		int y = style.aspectBarPaddingTop + style.controlPaddingTop;
277
 		int height = bounds.height - y - style.controlPaddingBottom;
273
 		int height = bounds.height - y - style.controlPaddingBottom;
274
+		
278
 		for (DComponent toolbarComponent : activeToolbarComponents) {
275
 		for (DComponent toolbarComponent : activeToolbarComponents) {
279
-			int width = toolbarComponent.getDimensionPreferences().getValue().preferredWidth;
276
+			int width = toolbarComponent.getSizing().getValue().preferredWidth;
280
 			toolbarComponent.setBounds(
277
 			toolbarComponent.setBounds(
281
 					new DIRectangle(x, bounds.y + y, width, height));
278
 					new DIRectangle(x, bounds.y + y, width, height));
282
 			x += width;
279
 			x += width;

+ 6
- 6
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/WindowActionButton.java View File

10
 import org.openzen.drawablegui.DCanvas;
10
 import org.openzen.drawablegui.DCanvas;
11
 import org.openzen.drawablegui.DColorableIcon;
11
 import org.openzen.drawablegui.DColorableIcon;
12
 import org.openzen.drawablegui.DComponent;
12
 import org.openzen.drawablegui.DComponent;
13
-import org.openzen.drawablegui.DDimensionPreferences;
13
+import org.openzen.drawablegui.DSizing;
14
 import org.openzen.drawablegui.DMouseEvent;
14
 import org.openzen.drawablegui.DMouseEvent;
15
 import org.openzen.drawablegui.DTransform2D;
15
 import org.openzen.drawablegui.DTransform2D;
16
 import org.openzen.drawablegui.DUIContext;
16
 import org.openzen.drawablegui.DUIContext;
18
 import org.openzen.drawablegui.listeners.ListenerHandle;
18
 import org.openzen.drawablegui.listeners.ListenerHandle;
19
 import org.openzen.drawablegui.live.LiveBool;
19
 import org.openzen.drawablegui.live.LiveBool;
20
 import org.openzen.drawablegui.live.LiveObject;
20
 import org.openzen.drawablegui.live.LiveObject;
21
-import org.openzen.drawablegui.live.SimpleLiveObject;
21
+import org.openzen.drawablegui.live.MutableLiveObject;
22
 import org.openzen.drawablegui.style.DStylePath;
22
 import org.openzen.drawablegui.style.DStylePath;
23
 import org.openzen.zenscript.ide.ui.icons.ScalableCloseIcon;
23
 import org.openzen.zenscript.ide.ui.icons.ScalableCloseIcon;
24
 
24
 
27
  * @author Hoofdgebruiker
27
  * @author Hoofdgebruiker
28
  */
28
  */
29
 public class WindowActionButton implements DComponent {
29
 public class WindowActionButton implements DComponent {
30
-	private final SimpleLiveObject<DDimensionPreferences> preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
30
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
31
 	
31
 	
32
 	private final Function<Float, DColorableIcon> scalableIcon;
32
 	private final Function<Float, DColorableIcon> scalableIcon;
33
 	private final Consumer<DMouseEvent> action;
33
 	private final Consumer<DMouseEvent> action;
54
 		windowFocusedListener = windowFocused.addListener((a, b) -> repaint());
54
 		windowFocusedListener = windowFocused.addListener((a, b) -> repaint());
55
 		
55
 		
56
 		icon = scalableIcon == null ? null : scalableIcon.apply(context.getScale());
56
 		icon = scalableIcon == null ? null : scalableIcon.apply(context.getScale());
57
-		preferences.setValue(new DDimensionPreferences(
57
+		sizing.setValue(new DSizing(
58
 				(int)(48 * context.getScale()),
58
 				(int)(48 * context.getScale()),
59
 				(int)(24 * context.getScale())));
59
 				(int)(24 * context.getScale())));
60
 	}
60
 	}
61
 
61
 
62
 	@Override
62
 	@Override
63
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
64
-		return preferences;
63
+	public LiveObject<DSizing> getSizing() {
64
+		return sizing;
65
 	}
65
 	}
66
 
66
 
67
 	@Override
67
 	@Override

+ 38
- 9
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java View File

8
 import java.io.IOException;
8
 import java.io.IOException;
9
 import org.openzen.drawablegui.DCanvas;
9
 import org.openzen.drawablegui.DCanvas;
10
 import org.openzen.drawablegui.DComponent;
10
 import org.openzen.drawablegui.DComponent;
11
-import org.openzen.drawablegui.DDimensionPreferences;
11
+import org.openzen.drawablegui.DSizing;
12
 import org.openzen.drawablegui.DFont;
12
 import org.openzen.drawablegui.DFont;
13
 import org.openzen.drawablegui.DFontFamily;
13
 import org.openzen.drawablegui.DFontFamily;
14
 import org.openzen.drawablegui.DFontMetrics;
14
 import org.openzen.drawablegui.DFontMetrics;
29
 import org.openzen.zenscript.lexer.ZSTokenParser;
29
 import org.openzen.zenscript.lexer.ZSTokenParser;
30
 import org.openzen.zenscript.lexer.ZSTokenType;
30
 import org.openzen.zenscript.lexer.ZSTokenType;
31
 import org.openzen.drawablegui.DUIContext;
31
 import org.openzen.drawablegui.DUIContext;
32
+import org.openzen.drawablegui.live.MutableLiveObject;
32
 import org.openzen.drawablegui.live.SimpleLiveBool;
33
 import org.openzen.drawablegui.live.SimpleLiveBool;
33
 import org.openzen.drawablegui.style.DStyleClass;
34
 import org.openzen.drawablegui.style.DStyleClass;
34
 import org.openzen.drawablegui.style.DStylePath;
35
 import org.openzen.drawablegui.style.DStylePath;
44
 public class SourceEditor implements DComponent {
45
 public class SourceEditor implements DComponent {
45
 	private final DStyleClass styleClass;
46
 	private final DStyleClass styleClass;
46
 	private final DFont font = new DFont(DFontFamily.CODE, false, false, false, 24);
47
 	private final DFont font = new DFont(DFontFamily.CODE, false, false, false, 24);
47
-	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(new DDimensionPreferences(0, 0));
48
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
48
 	private final String tab = "    ";
49
 	private final String tab = "    ";
49
 	private final IDESourceFile sourceFile;
50
 	private final IDESourceFile sourceFile;
50
 	private final TokenModel tokens;
51
 	private final TokenModel tokens;
124
 		fullLineHeight = textLineHeight + fontMetrics.getLeading() + style.extraLineSpacing;
125
 		fullLineHeight = textLineHeight + fontMetrics.getLeading() + style.extraLineSpacing;
125
 		selectionLineHeight = textLineHeight + style.selectionPaddingTop + style.selectionPaddingBottom;
126
 		selectionLineHeight = textLineHeight + style.selectionPaddingTop + style.selectionPaddingBottom;
126
 		
127
 		
127
-		dimensionPreferences.setValue(new DDimensionPreferences(0, fullLineHeight * tokens.getLineCount()));
128
+		sizing.setValue(new DSizing(0, fullLineHeight * tokens.getLineCount()));
128
 		
129
 		
129
 		if (blinkTimer != null)
130
 		if (blinkTimer != null)
130
 			blinkTimer.close();
131
 			blinkTimer.close();
132
 	}
133
 	}
133
 
134
 
134
 	@Override
135
 	@Override
135
-	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
136
-		return dimensionPreferences;
136
+	public LiveObject<DSizing> getSizing() {
137
+		return sizing;
137
 	}
138
 	}
138
 
139
 
139
 	@Override
140
 	@Override
464
 		if (deleteSelection())
465
 		if (deleteSelection())
465
 			return;
466
 			return;
466
 		
467
 		
468
+		if (cursorEnd.line > 0) {
469
+			String indent = tokens.getLine(cursorEnd.line - 1).getIndent(); // TODO: get nominal indent for current scope
470
+			if (cursorEnd.offset == indent.length()) {
471
+				// remove entire indent
472
+				SourcePosition deleteFrom = new SourcePosition(tokens, cursorEnd.line - 1, tokens.getLine(cursorEnd.line - 1).length());
473
+				tokens.delete(deleteFrom, cursorEnd);
474
+				unchanged.setValue(false);
475
+				setCursor(deleteFrom, deleteFrom);
476
+				return;
477
+			}
478
+		}
479
+		
467
 		if (cursorEnd.offset == 0) {
480
 		if (cursorEnd.offset == 0) {
468
 			if (cursorEnd.line == 0)
481
 			if (cursorEnd.line == 0)
469
 				return;
482
 				return;
489
 	private void type(String value) {
502
 	private void type(String value) {
490
 		deleteSelection();
503
 		deleteSelection();
491
 		
504
 		
492
-		tokens.insert(cursorEnd, value);
493
-		SourcePosition position = new SourcePosition(tokens, cursorEnd.line, cursorEnd.offset + value.length());
494
-		setCursor(position, position);
505
+		if (value.equals("{")) {
506
+			String indent = tokens.getLine(cursorEnd.line).getIndent();
507
+			tokens.insert(cursorEnd, "{\n" + indent + "\t\n" + indent + "}");
508
+			
509
+			SourcePosition position = new SourcePosition(tokens, cursorEnd.line + 1, indent.length() + 1);
510
+			setCursor(position, position);
511
+		} else if (value.equals(";")) {
512
+			String indent = tokens.getLine(cursorEnd.line).getIndent();
513
+			tokens.insert(cursorEnd, ";\n" + indent);
514
+			
515
+			SourcePosition position = new SourcePosition(tokens, cursorEnd.line + 1, indent.length());
516
+			setCursor(position, position);
517
+		} else {
518
+			tokens.insert(cursorEnd, value);
519
+			
520
+			SourcePosition position = new SourcePosition(tokens, cursorEnd.line, cursorEnd.offset + value.length());
521
+			setCursor(position, position);
522
+		}
523
+		
495
 		unchanged.setValue(false);
524
 		unchanged.setValue(false);
496
 	}
525
 	}
497
 	
526
 	
620
 	}
649
 	}
621
 	
650
 	
622
 	private void onLinesUpdated() {
651
 	private void onLinesUpdated() {
623
-		dimensionPreferences.setValue(new DDimensionPreferences(0, fullLineHeight * tokens.getLineCount()));
652
+		sizing.setValue(new DSizing(0, fullLineHeight * tokens.getLineCount()));
624
 		
653
 		
625
 		if (bounds != null)
654
 		if (bounds != null)
626
 			context.repaint(bounds);
655
 			context.repaint(bounds);

Loading…
Cancel
Save