Ver código fonte

- IDE: put the create package & create source file buttons in more logical places

- IDE: improve styleability
Stan Hebben 6 anos atrás
pai
commit
64e4aad20c
28 arquivos alterados com 467 adições e 94 exclusões
  1. 17
    15
      DrawableGui/src/main/java/org/openzen/drawablegui/DHorizontalLayout.java
  2. 6
    10
      DrawableGui/src/main/java/org/openzen/drawablegui/DHorizontalLayoutStyle.java
  3. 0
    4
      DrawableGui/src/main/java/org/openzen/drawablegui/DSimpleTooltip.java
  4. 0
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/DSimpleTooltipComponent.java
  5. 19
    18
      DrawableGui/src/main/java/org/openzen/drawablegui/DVerticalLayout.java
  6. 6
    10
      DrawableGui/src/main/java/org/openzen/drawablegui/DVerticalLayoutStyle.java
  7. 8
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DBorder.java
  8. 4
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DPaddedBorder.java
  9. 22
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DBorderElement.java
  10. 23
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DColorElement.java
  11. 6
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DDimension.java
  12. 6
    7
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DEmptyStyleDefinition.java
  13. 23
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DEmptyStylesheet.java
  14. 1
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DEmptyStylesheets.java
  15. 23
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DFontElement.java
  16. 21
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DShadowElement.java
  17. 84
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DSimpleStylesheet.java
  18. 9
    3
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DStyleClass.java
  19. 3
    5
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DStyleDefinition.java
  20. 37
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DStyleElement.java
  21. 4
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DStylePath.java
  22. 12
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DStylePathRoot.java
  23. 16
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DStylesheet.java
  24. 56
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DStylesheetBuilder.java
  25. 0
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java
  26. 4
    12
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java
  27. 1
    3
      IDE/src/main/java/org/openzen/zenscript/ide/ui/dialog/CreatePackageDialog.java
  28. 56
    3
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java

+ 17
- 15
DrawableGui/src/main/java/org/openzen/drawablegui/DHorizontalLayout.java Ver arquivo

@@ -10,7 +10,6 @@ import java.util.function.Predicate;
10 10
 import org.openzen.drawablegui.listeners.ListenerHandle;
11 11
 import org.openzen.drawablegui.live.LiveObject;
12 12
 import org.openzen.drawablegui.live.MutableLiveObject;
13
-import org.openzen.drawablegui.live.SimpleLiveObject;
14 13
 import org.openzen.drawablegui.style.DStyleClass;
15 14
 import org.openzen.drawablegui.style.DStylePath;
16 15
 
@@ -99,6 +98,7 @@ public class DHorizontalLayout extends BaseComponentGroup {
99 98
 
100 99
 	@Override
101 100
 	public void paint(DCanvas canvas) {
101
+		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
102 102
 		for (Element element : components) {
103 103
 			element.component.paint(canvas);
104 104
 		}
@@ -222,21 +222,21 @@ public class DHorizontalLayout extends BaseComponentGroup {
222 222
 		int y;
223 223
 		switch (element.alignment) {
224 224
 			case BOTTOM:
225
-				height = Math.min(preferences.preferredHeight, bounds.height - style.paddingTop - style.paddingBottom);
226
-				y = bounds.y + style.paddingTop;
225
+				height = Math.min(preferences.preferredHeight, bounds.height - style.border.getPaddingVertical());
226
+				y = bounds.y + style.border.getPaddingTop();
227 227
 				break;
228 228
 			case MIDDLE:
229
-				height = Math.min(preferences.preferredHeight, bounds.height - style.paddingTop - style.paddingBottom);
230
-				y = bounds.y + style.paddingTop + (bounds.height - style.paddingTop - style.paddingBottom - height) / 2;
229
+				height = Math.min(preferences.preferredHeight, bounds.height - style.border.getPaddingVertical());
230
+				y = bounds.y + style.border.getPaddingTop() + (bounds.height - style.border.getPaddingVertical() - height) / 2;
231 231
 				break;
232 232
 			case TOP:
233
-				height = Math.min(preferences.preferredHeight, bounds.height - style.paddingTop - style.paddingBottom);
234
-				y = bounds.y + bounds.height - style.paddingBottom - height;
233
+				height = Math.min(preferences.preferredHeight, bounds.height - style.border.getPaddingVertical());
234
+				y = bounds.y + bounds.height - style.border.getPaddingBottom() - height;
235 235
 				break;
236 236
 			case STRETCH:
237 237
 			default:
238
-				height = bounds.height - style.paddingTop - style.paddingBottom;
239
-				y = bounds.y + style.paddingTop;
238
+				height = bounds.height - style.border.getPaddingVertical();
239
+				y = bounds.y + style.border.getPaddingTop();
240 240
 				break;
241 241
 		}
242 242
 		element.component.setBounds(new DIRectangle(x, y, width, height));
@@ -261,13 +261,15 @@ public class DHorizontalLayout extends BaseComponentGroup {
261 261
 			maximumHeight = Math.min(maximumHeight, preferences.maximumHeight);
262 262
 		}
263 263
 		
264
+		int paddingHorizontal = style.border.getPaddingHorizontal();
265
+		int paddingVertical = style.border.getPaddingVertical();
264 266
 		DSizing preferences = new DSizing(
265
-				minimumWidth + style.paddingLeft + style.paddingRight,
266
-				minimumHeight + style.paddingTop + style.paddingBottom,
267
-				preferredWidth + style.paddingLeft + style.paddingRight,
268
-				preferredHeight + style.paddingTop + style.paddingBottom,
269
-				maximumWidth + style.paddingLeft + style.paddingRight,
270
-				maximumHeight + style.paddingTop + style.paddingBottom);
267
+				minimumWidth + paddingHorizontal,
268
+				minimumHeight + paddingVertical,
269
+				preferredWidth + paddingHorizontal,
270
+				preferredHeight + paddingVertical,
271
+				maximumWidth + paddingHorizontal,
272
+				maximumHeight + paddingVertical);
271 273
 		sizing.setValue(preferences);
272 274
 	}
273 275
 }

+ 6
- 10
DrawableGui/src/main/java/org/openzen/drawablegui/DHorizontalLayoutStyle.java Ver arquivo

@@ -5,6 +5,8 @@
5 5
  */
6 6
 package org.openzen.drawablegui;
7 7
 
8
+import org.openzen.drawablegui.border.DBorder;
9
+import org.openzen.drawablegui.border.DPaddedBorder;
8 10
 import org.openzen.drawablegui.style.DDpDimension;
9 11
 import org.openzen.drawablegui.style.DStyleDefinition;
10 12
 
@@ -14,18 +16,12 @@ import org.openzen.drawablegui.style.DStyleDefinition;
14 16
  */
15 17
 public class DHorizontalLayoutStyle {
16 18
 	public final int spacing;
17
-	
18
-	public final int paddingTop;
19
-	public final int paddingLeft;
20
-	public final int paddingRight;
21
-	public final int paddingBottom;
19
+	public final DBorder border;
20
+	public final int backgroundColor;
22 21
 	
23 22
 	public DHorizontalLayoutStyle(DStyleDefinition style) {
24 23
 		spacing = style.getDimension("spacing", new DDpDimension(8));
25
-		
26
-		paddingTop = style.getDimension("paddingTop", new DDpDimension(8));
27
-		paddingLeft = style.getDimension("paddingLeft", new DDpDimension(8));
28
-		paddingRight = style.getDimension("paddingRight", new DDpDimension(8));
29
-		paddingBottom = style.getDimension("paddingBottom", new DDpDimension(8));
24
+		border = style.getBorder("border", context -> new DPaddedBorder(context.dp(8)));
25
+		backgroundColor = style.getColor("backgroundColor", 0);
30 26
 	}
31 27
 }

+ 0
- 4
DrawableGui/src/main/java/org/openzen/drawablegui/DSimpleTooltip.java Ver arquivo

@@ -57,8 +57,6 @@ public class DSimpleTooltip {
57 57
 	}
58 58
 	
59 59
 	private void show() {
60
-		System.out.println("Show tooltip");
61
-		
62 60
 		DSimpleTooltipComponent view = new DSimpleTooltipComponent(styleClass, tooltip);
63 61
 		window = context.openView(enterMouseX, enterMouseY + context.dp(8), DAnchor.TOP_LEFT, view);
64 62
 		
@@ -69,8 +67,6 @@ public class DSimpleTooltip {
69 67
 	}
70 68
 	
71 69
 	private void hide() {
72
-		System.out.println("Hide tooltip");
73
-		
74 70
 		if (window != null) {
75 71
 			window.close();
76 72
 			window = null;

+ 0
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/DSimpleTooltipComponent.java Ver arquivo

@@ -78,7 +78,6 @@ public class DSimpleTooltipComponent implements DComponent {
78 78
 	
79 79
 	@Override
80 80
 	public void paint(DCanvas canvas) {
81
-		System.out.println("Actually paint tooltip");
82 81
 		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
83 82
 		style.border.paint(canvas, bounds);
84 83
 		canvas.drawText(

+ 19
- 18
DrawableGui/src/main/java/org/openzen/drawablegui/DVerticalLayout.java Ver arquivo

@@ -26,7 +26,7 @@ public class DVerticalLayout extends BaseComponentGroup {
26 26
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
27 27
 	
28 28
 	private DUIContext context;
29
-	private DHorizontalLayoutStyle style;
29
+	private DVerticalLayoutStyle style;
30 30
 	private DIRectangle bounds;
31 31
 	private float totalGrow;
32 32
 	private float totalShrink;
@@ -68,12 +68,10 @@ public class DVerticalLayout extends BaseComponentGroup {
68 68
 		this.context = context;
69 69
 		
70 70
 		DStylePath path = parent.getChild("verticalLayout", styleClass);
71
-		style = new DHorizontalLayoutStyle(context.getStylesheets().get(context, path));
71
+		style = new DVerticalLayoutStyle(context.getStylesheets().get(context, path));
72 72
 		
73 73
 		for (Element element : components)
74 74
 			element.component.setContext(parent, context);
75
-		
76
-		layout();
77 75
 	}
78 76
 
79 77
 	@Override
@@ -99,6 +97,7 @@ public class DVerticalLayout extends BaseComponentGroup {
99 97
 
100 98
 	@Override
101 99
 	public void paint(DCanvas canvas) {
100
+		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
102 101
 		for (Element element : components) {
103 102
 			element.component.paint(canvas);
104 103
 		}
@@ -222,21 +221,21 @@ public class DVerticalLayout extends BaseComponentGroup {
222 221
 		int width;
223 222
 		switch (element.alignment) {
224 223
 			case LEFT:
225
-				width = Math.min(preferences.preferredWidth, bounds.width - style.paddingLeft - style.paddingRight);
226
-				x = bounds.x + style.paddingLeft;
224
+				width = Math.min(preferences.preferredWidth, bounds.width - style.border.getPaddingHorizontal());
225
+				x = bounds.x + style.border.getPaddingLeft();
227 226
 				break;
228 227
 			case CENTER:
229
-				width = Math.min(preferences.preferredWidth, bounds.width - style.paddingLeft - style.paddingRight);
230
-				x = bounds.x + style.paddingLeft + (bounds.width - style.paddingLeft - style.paddingRight - width) / 2;
228
+				width = Math.min(preferences.preferredWidth, bounds.width - style.border.getPaddingHorizontal());
229
+				x = bounds.x + style.border.getPaddingLeft() + (bounds.width - style.border.getPaddingHorizontal() - width) / 2;
231 230
 				break;
232 231
 			case RIGHT:
233
-				width = Math.min(preferences.preferredWidth, bounds.width - style.paddingLeft - style.paddingRight);
234
-				x = bounds.x + bounds.width - style.paddingLeft - width;
232
+				width = Math.min(preferences.preferredWidth, bounds.width - style.border.getPaddingHorizontal());
233
+				x = bounds.x + bounds.width - style.border.getPaddingLeft() - width;
235 234
 				break;
236 235
 			case STRETCH:
237 236
 			default:
238
-				width = bounds.width - style.paddingLeft - style.paddingRight;
239
-				x = bounds.x + style.paddingLeft;
237
+				width = bounds.width - style.border.getPaddingHorizontal();
238
+				x = bounds.x + style.border.getPaddingLeft();
240 239
 				break;
241 240
 		}
242 241
 		element.component.setBounds(new DIRectangle(x, y, width, height));
@@ -262,13 +261,15 @@ public class DVerticalLayout extends BaseComponentGroup {
262 261
 			maximumHeight += preferences.maximumHeight + style.spacing;
263 262
 		}
264 263
 		
264
+		int paddingHorizontal = style.border.getPaddingHorizontal();
265
+		int paddingVertical = style.border.getPaddingVertical();
265 266
 		DSizing preferences = new DSizing(
266
-				minimumWidth + style.paddingLeft + style.paddingRight,
267
-				minimumHeight + style.paddingTop + style.paddingBottom,
268
-				preferredWidth + style.paddingLeft + style.paddingRight,
269
-				preferredHeight + style.paddingTop + style.paddingBottom,
270
-				maximumWidth + style.paddingLeft + style.paddingRight,
271
-				maximumHeight + style.paddingTop + style.paddingBottom);
267
+				minimumWidth + paddingHorizontal,
268
+				minimumHeight + paddingVertical,
269
+				preferredWidth + paddingHorizontal,
270
+				preferredHeight + paddingVertical,
271
+				maximumWidth + paddingHorizontal,
272
+				maximumHeight + paddingVertical);
272 273
 		sizing.setValue(preferences);
273 274
 	}
274 275
 }

+ 6
- 10
DrawableGui/src/main/java/org/openzen/drawablegui/DVerticalLayoutStyle.java Ver arquivo

@@ -5,6 +5,8 @@
5 5
  */
6 6
 package org.openzen.drawablegui;
7 7
 
8
+import org.openzen.drawablegui.border.DBorder;
9
+import org.openzen.drawablegui.border.DPaddedBorder;
8 10
 import org.openzen.drawablegui.style.DDpDimension;
9 11
 import org.openzen.drawablegui.style.DStyleDefinition;
10 12
 
@@ -14,18 +16,12 @@ import org.openzen.drawablegui.style.DStyleDefinition;
14 16
  */
15 17
 public class DVerticalLayoutStyle {
16 18
 	public final int spacing;
17
-	
18
-	public final int paddingTop;
19
-	public final int paddingLeft;
20
-	public final int paddingRight;
21
-	public final int paddingBottom;
19
+	public final DBorder border;
20
+	public final int backgroundColor;
22 21
 	
23 22
 	public DVerticalLayoutStyle(DStyleDefinition style) {
24 23
 		spacing = style.getDimension("spacing", new DDpDimension(8));
25
-		
26
-		paddingTop = style.getDimension("paddingTop", new DDpDimension(8));
27
-		paddingLeft = style.getDimension("paddingLeft", new DDpDimension(8));
28
-		paddingRight = style.getDimension("paddingRight", new DDpDimension(8));
29
-		paddingBottom = style.getDimension("paddingBottom", new DDpDimension(8));
24
+		border = style.getBorder("border", context -> new DPaddedBorder(context.dp(8)));
25
+		backgroundColor = style.getColor("backgroundColor", 0);
30 26
 	}
31 27
 }

+ 8
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/border/DBorder.java Ver arquivo

@@ -22,4 +22,12 @@ public interface DBorder {
22 22
 	public int getPaddingTop();
23 23
 	
24 24
 	public int getPaddingBottom();
25
+	
26
+	default int getPaddingHorizontal() {
27
+		return getPaddingLeft() + getPaddingRight();
28
+	}
29
+	
30
+	default int getPaddingVertical() {
31
+		return getPaddingTop() + getPaddingBottom();
32
+	}
25 33
 }

+ 4
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/border/DPaddedBorder.java Ver arquivo

@@ -24,6 +24,10 @@ public class DPaddedBorder implements DBorder {
24 24
 		this.right = right;
25 25
 		this.bottom = bottom;
26 26
 	}
27
+	
28
+	public DPaddedBorder(int size) {
29
+		this(size, size, size, size);
30
+	}
27 31
 
28 32
 	@Override
29 33
 	public void paint(DCanvas canvas, DIRectangle bounds) {

+ 22
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DBorderElement.java Ver arquivo

@@ -0,0 +1,22 @@
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.style;
7
+
8
+import org.openzen.drawablegui.DUIContext;
9
+import org.openzen.drawablegui.border.DBorder;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public interface DBorderElement extends DStyleElement {
16
+	DBorder eval(DUIContext context);
17
+	
18
+	@Override
19
+	default DBorderElement asBorder() {
20
+		return this;
21
+	}
22
+}

+ 23
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DColorElement.java Ver arquivo

@@ -0,0 +1,23 @@
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.style;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class DColorElement implements DStyleElement {
13
+	private final int color;
14
+	
15
+	public DColorElement(int color) {
16
+		this.color = color;
17
+	}
18
+	
19
+	@Override
20
+	public int asColor() {
21
+		return color;
22
+	}
23
+}

+ 6
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/style/DDimension.java Ver arquivo

@@ -11,10 +11,15 @@ import org.openzen.drawablegui.DUIContext;
11 11
  *
12 12
  * @author Hoofdgebruiker
13 13
  */
14
-public interface DDimension {
14
+public interface DDimension extends DStyleElement {
15 15
 	float eval(DUIContext context);
16 16
 	
17 17
 	default int evalInt(DUIContext context) {
18 18
 		return (int)(eval(context) + 0.5f);
19 19
 	}
20
+	
21
+	@Override
22
+	default DDimension asDimension() {
23
+		return this;
24
+	}
20 25
 }

+ 6
- 7
DrawableGui/src/main/java/org/openzen/drawablegui/style/DEmptyStyleDefinition.java Ver arquivo

@@ -5,7 +5,6 @@
5 5
  */
6 6
 package org.openzen.drawablegui.style;
7 7
 
8
-import java.util.function.Function;
9 8
 import org.openzen.drawablegui.DFont;
10 9
 import org.openzen.drawablegui.DUIContext;
11 10
 import org.openzen.drawablegui.border.DBorder;
@@ -37,17 +36,17 @@ public class DEmptyStyleDefinition implements DStyleDefinition {
37 36
 	}
38 37
 
39 38
 	@Override
40
-	public DShadow getShadow(String name, Function<DUIContext, DShadow> defaultValue) {
41
-		return defaultValue.apply(context);
39
+	public DShadow getShadow(String name, DShadowElement defaultValue) {
40
+		return defaultValue.eval(context);
42 41
 	}
43 42
 
44 43
 	@Override
45
-	public DFont getFont(String name, Function<DUIContext, DFont> defaultValue) {
46
-		return defaultValue.apply(context);
44
+	public DFont getFont(String name, DFontElement defaultValue) {
45
+		return defaultValue.eval(context);
47 46
 	}
48 47
 
49 48
 	@Override
50
-	public DBorder getBorder(String name, Function<DUIContext, DBorder> defaultValue) {
51
-		return defaultValue.apply(context);
49
+	public DBorder getBorder(String name, DBorderElement defaultValue) {
50
+		return defaultValue.eval(context);
52 51
 	}
53 52
 }

+ 23
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DEmptyStylesheet.java Ver arquivo

@@ -0,0 +1,23 @@
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.style;
7
+
8
+import org.openzen.drawablegui.DUIContext;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class DEmptyStylesheet implements DStylesheet {
15
+	public static final DEmptyStylesheet INSTANCE = new DEmptyStylesheet();
16
+	
17
+	private DEmptyStylesheet() {}
18
+
19
+	@Override
20
+	public DStyleDefinition getInstance(DUIContext context) {
21
+		return new DEmptyStyleDefinition(context);
22
+	}
23
+}

+ 1
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/style/DEmptyStylesheets.java Ver arquivo

@@ -16,6 +16,6 @@ public class DEmptyStylesheets implements DStyleSheets {
16 16
 
17 17
 	@Override
18 18
 	public DStyleDefinition get(DUIContext context, DStylePath path) {
19
-		return new DEmptyStyleDefinition(context);
19
+		return path.getInline(context);
20 20
 	}
21 21
 }

+ 23
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DFontElement.java Ver arquivo

@@ -0,0 +1,23 @@
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.style;
7
+
8
+import org.openzen.drawablegui.DFont;
9
+import org.openzen.drawablegui.DUIContext;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+@FunctionalInterface
16
+public interface DFontElement extends DStyleElement {
17
+	DFont eval(DUIContext context);
18
+	
19
+	@Override
20
+	default DFontElement asFont() {
21
+		return this;
22
+	}
23
+}

+ 21
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DShadowElement.java Ver arquivo

@@ -0,0 +1,21 @@
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.style;
7
+
8
+import org.openzen.drawablegui.DUIContext;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public interface DShadowElement extends DStyleElement {
15
+	DShadow eval(DUIContext context);
16
+	
17
+	@Override
18
+	default DShadowElement asShadow() {
19
+		return this;
20
+	}
21
+}

+ 84
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DSimpleStylesheet.java Ver arquivo

@@ -0,0 +1,84 @@
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.style;
7
+
8
+import java.util.Map;
9
+import org.openzen.drawablegui.DFont;
10
+import org.openzen.drawablegui.DUIContext;
11
+import org.openzen.drawablegui.border.DBorder;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class DSimpleStylesheet implements DStylesheet {
18
+	private final Map<String, DStyleElement> elements;
19
+	
20
+	public DSimpleStylesheet(Map<String, DStyleElement> elements) {
21
+		this.elements = elements;
22
+	}
23
+
24
+	@Override
25
+	public DStyleDefinition getInstance(DUIContext context) {
26
+		return new Instance(context);
27
+	}
28
+	
29
+	private class Instance implements DStyleDefinition {
30
+		private final DUIContext context;
31
+		
32
+		private Instance(DUIContext context) {
33
+			this.context = context;
34
+		}
35
+
36
+		@Override
37
+		public int getDimension(String name, DDimension defaultValue) {
38
+			if (!elements.containsKey(name))
39
+				return defaultValue.evalInt(context);
40
+			
41
+			return elements.get(name).asDimension().evalInt(context);
42
+		}
43
+
44
+		@Override
45
+		public float getFloatDimension(String name, DDimension defaultValue) {
46
+			if (!elements.containsKey(name))
47
+				return defaultValue.eval(context);
48
+			
49
+			return elements.get(name).asDimension().eval(context);
50
+		}
51
+
52
+		@Override
53
+		public int getColor(String name, int defaultValue) {
54
+			if (!elements.containsKey(name))
55
+				return defaultValue;
56
+			
57
+			return elements.get(name).asColor();
58
+		}
59
+
60
+		@Override
61
+		public DShadow getShadow(String name, DShadowElement defaultValue) {
62
+			if (!elements.containsKey(name))
63
+				return defaultValue.eval(context);
64
+			
65
+			return elements.get(name).asShadow().eval(context);
66
+		}
67
+
68
+		@Override
69
+		public DFont getFont(String name, DFontElement defaultValue) {
70
+			if (!elements.containsKey(name))
71
+				return defaultValue.eval(context);
72
+			
73
+			return elements.get(name).asFont().eval(context);
74
+		}
75
+
76
+		@Override
77
+		public DBorder getBorder(String name, DBorderElement defaultValue) {
78
+			if (!elements.containsKey(name))
79
+				return defaultValue.eval(context);
80
+			
81
+			return elements.get(name).asBorder().eval(context);
82
+		}
83
+	}
84
+}

+ 9
- 3
DrawableGui/src/main/java/org/openzen/drawablegui/style/DStyleClass.java Ver arquivo

@@ -11,17 +11,23 @@ package org.openzen.drawablegui.style;
11 11
  */
12 12
 public class DStyleClass {
13 13
 	private static final String[] NO_CLASSES = new String[0];
14
-	public static final DStyleClass EMPTY = new DStyleClass(null, NO_CLASSES);
14
+	public static final DStyleClass EMPTY = new DStyleClass(null, NO_CLASSES, DEmptyStylesheet.INSTANCE);
15 15
 	
16 16
 	public static DStyleClass forId(String id) {
17
-		return new DStyleClass(id, NO_CLASSES);
17
+		return new DStyleClass(id, NO_CLASSES, DEmptyStylesheet.INSTANCE);
18
+	}
19
+	
20
+	public static DStyleClass inline(DStylesheet stylesheet) {
21
+		return new DStyleClass(null, NO_CLASSES, stylesheet);
18 22
 	}
19 23
 	
20 24
 	public final String id;
21 25
 	public final String[] classes;
26
+	public final DStylesheet inline;
22 27
 	
23
-	public DStyleClass(String id, String[] classes) {
28
+	public DStyleClass(String id, String[] classes, DStylesheet inline) {
24 29
 		this.id = id;
25 30
 		this.classes = classes;
31
+		this.inline = inline;
26 32
 	}
27 33
 }

+ 3
- 5
DrawableGui/src/main/java/org/openzen/drawablegui/style/DStyleDefinition.java Ver arquivo

@@ -5,9 +5,7 @@
5 5
  */
6 6
 package org.openzen.drawablegui.style;
7 7
 
8
-import java.util.function.Function;
9 8
 import org.openzen.drawablegui.DFont;
10
-import org.openzen.drawablegui.DUIContext;
11 9
 import org.openzen.drawablegui.border.DBorder;
12 10
 
13 11
 /**
@@ -21,9 +19,9 @@ public interface DStyleDefinition {
21 19
 	
22 20
 	public int getColor(String name, int defaultValue);
23 21
 	
24
-	public DShadow getShadow(String name, Function<DUIContext, DShadow> defaultValue);
22
+	public DShadow getShadow(String name, DShadowElement defaultValue);
25 23
 	
26
-	public DFont getFont(String name, Function<DUIContext, DFont> defaultValue);
24
+	public DFont getFont(String name, DFontElement defaultValue);
27 25
 	
28
-	public DBorder getBorder(String name, Function<DUIContext, DBorder> defaultValue);
26
+	public DBorder getBorder(String name, DBorderElement defaultValue);
29 27
 }

+ 37
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DStyleElement.java Ver arquivo

@@ -0,0 +1,37 @@
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.style;
7
+
8
+import java.util.function.Function;
9
+import org.openzen.drawablegui.DFont;
10
+import org.openzen.drawablegui.DUIContext;
11
+import org.openzen.drawablegui.border.DBorder;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public interface DStyleElement {
18
+	default DDimension asDimension() {
19
+		throw new RuntimeException("Not a dimension!");
20
+	}
21
+	
22
+	default int asColor() {
23
+		throw new RuntimeException("Not a color!");
24
+	}
25
+	
26
+	default DFontElement asFont() {
27
+		throw new RuntimeException("Not a font!");
28
+	}
29
+	
30
+	default DBorderElement asBorder() {
31
+		throw new RuntimeException("Not a border!");
32
+	}
33
+	
34
+	default DShadowElement asShadow() {
35
+		throw new RuntimeException("Not a shadow!");
36
+	}
37
+}

+ 4
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DStylePath.java Ver arquivo

@@ -5,10 +5,14 @@
5 5
  */
6 6
 package org.openzen.drawablegui.style;
7 7
 
8
+import org.openzen.drawablegui.DUIContext;
9
+
8 10
 /**
9 11
  *
10 12
  * @author Hoofdgebruiker
11 13
  */
12 14
 public interface DStylePath {
13 15
 	public DStylePath getChild(String element, DStyleClass styleClass);
16
+	
17
+	public DStyleDefinition getInline(DUIContext context);
14 18
 }

+ 12
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DStylePathRoot.java Ver arquivo

@@ -5,6 +5,8 @@
5 5
  */
6 6
 package org.openzen.drawablegui.style;
7 7
 
8
+import org.openzen.drawablegui.DUIContext;
9
+
8 10
 /**
9 11
  *
10 12
  * @author Hoofdgebruiker
@@ -19,6 +21,11 @@ public class DStylePathRoot implements DStylePath {
19 21
 		return new DStyleChildElement(this, element, styleClass);
20 22
 	}
21 23
 	
24
+	@Override
25
+	public DStyleDefinition getInline(DUIContext context) {
26
+		return new DEmptyStyleDefinition(context);
27
+	}
28
+	
22 29
 	private static class DStyleChildElement implements DStylePath {
23 30
 		private final DStylePath parent;
24 31
 		private final String element;
@@ -34,5 +41,10 @@ public class DStylePathRoot implements DStylePath {
34 41
 		public DStylePath getChild(String element, DStyleClass styleClass) {
35 42
 			return new DStyleChildElement(this, element, styleClass);
36 43
 		}
44
+
45
+		@Override
46
+		public DStyleDefinition getInline(DUIContext context) {
47
+			return styleClass.inline.getInstance(context);
48
+		}
37 49
 	}
38 50
 }

+ 16
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DStylesheet.java Ver arquivo

@@ -0,0 +1,16 @@
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.style;
7
+
8
+import org.openzen.drawablegui.DUIContext;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public interface DStylesheet {
15
+	DStyleDefinition getInstance(DUIContext context);
16
+}

+ 56
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DStylesheetBuilder.java Ver arquivo

@@ -0,0 +1,56 @@
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.style;
7
+
8
+import java.util.HashMap;
9
+import java.util.Map;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class DStylesheetBuilder {
16
+	private final Map<String, DStyleElement> elements = new HashMap<>();
17
+	
18
+	public DStylesheetBuilder dimensionDp(String name, float value) {
19
+		elements.put(name, new DDpDimension(value));
20
+		return this;
21
+	}
22
+	
23
+	public DStylesheetBuilder dimensionPx(String name, float value) {
24
+		elements.put(name, new DPxDimension(value));
25
+		return this;
26
+	}
27
+	
28
+	public DStylesheetBuilder dimensionSp(String name, float value) {
29
+		elements.put(name, new DSpDimension(value));
30
+		return this;
31
+	}
32
+	
33
+	public DStylesheetBuilder color(String name, int value) {
34
+		elements.put(name, new DColorElement(value));
35
+		return this;
36
+	}
37
+	
38
+	public DStylesheetBuilder font(String name, DFontElement font) {
39
+		elements.put(name, font);
40
+		return this;
41
+	}
42
+	
43
+	public DStylesheetBuilder shadow(String name, DShadowElement shadow) {
44
+		elements.put(name, shadow);
45
+		return this;
46
+	}
47
+	
48
+	public DStylesheetBuilder border(String name, DBorderElement border) {
49
+		elements.put(name, border);
50
+		return this;
51
+	}
52
+	
53
+	public DStylesheet build() {
54
+		return new DSimpleStylesheet(elements);
55
+	}
56
+}

+ 0
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java Ver arquivo

@@ -77,7 +77,6 @@ public final class SwingRoot extends Component implements ComponentListener, Mou
77 77
 			firstPaint = false;
78 78
 			component.setContext(DStylePathRoot.INSTANCE, context);
79 79
 			component.setBounds(new DIRectangle(0, 0, getWidth(), getHeight()));
80
-			System.out.println("Painting with size " + getWidth() + " x " + getHeight());
81 80
 		}
82 81
 		
83 82
 		Rectangle clipBounds = g.getClipBounds();

+ 4
- 12
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java Ver arquivo

@@ -38,10 +38,10 @@ public class IDEWindow {
38 38
 	
39 39
 	public IDEAspectToolbar projectToolbar;
40 40
 	
41
-	private final MutableLiveObject<IDEModule> contextModule = new SimpleLiveObject<>(null);
42
-	private final MutableLiveObject<IDEPackage> contextPackage = new SimpleLiveObject<>(null);
43
-	private final MutableLiveObject<IDESourceFile> contextFile = new SimpleLiveObject<>(null);
44
-	private final LiveBool addContentDisabled = new LivePredicateBool(contextPackage, pkg -> pkg == null);
41
+	public final MutableLiveObject<IDEModule> contextModule = new SimpleLiveObject<>(null);
42
+	public final MutableLiveObject<IDEPackage> contextPackage = new SimpleLiveObject<>(null);
43
+	public final MutableLiveObject<IDESourceFile> contextFile = new SimpleLiveObject<>(null);
44
+	public final LiveBool addContentDisabled = new LivePredicateBool(contextPackage, pkg -> pkg == null);
45 45
 	
46 46
 	public IDEWindow(DevelopmentHost host) {
47 47
 		this.host = host;
@@ -67,14 +67,6 @@ public class IDEWindow {
67 67
 	
68 68
 	private void init() {
69 69
 		projectToolbar = new IDEAspectToolbar(0, ShadedProjectIcon.PURPLE, "Project", "Project management");
70
-		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.BLUE, AddBoxIcon.GRAY, addContentDisabled, new ImmutableLiveString("Create package"), e -> {
71
-			CreatePackageDialog dialog = new CreatePackageDialog(this, contextModule.getValue(), contextPackage.getValue());
72
-			dialog.open(e.window);
73
-		}));
74
-		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.ORANGE, AddBoxIcon.GRAY, addContentDisabled, new ImmutableLiveString("Create source file"), e -> {
75
-			CreateSourceFileDialog dialog = new CreateSourceFileDialog(this, contextModule.getValue(), contextPackage.getValue());
76
-			dialog.open(e.window);
77
-		}));
78 70
 		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, SettingsIcon.PURPLE, new ImmutableLiveString("Project settings"), e -> {
79 71
 			
80 72
 		}));

+ 1
- 3
IDE/src/main/java/org/openzen/zenscript/ide/ui/dialog/CreatePackageDialog.java Ver arquivo

@@ -30,7 +30,6 @@ import org.openzen.zenscript.ide.ui.IDEWindow;
30 30
  * @author Hoofdgebruiker
31 31
  */
32 32
 public class CreatePackageDialog {
33
-	private final IDEWindow ideWindow;
34 33
 	private final IDEModule module;
35 34
 	private final IDEPackage pkg;
36 35
 	
@@ -41,8 +40,7 @@ public class CreatePackageDialog {
41 40
 	
42 41
 	private DUIWindow window;
43 42
 	
44
-	public CreatePackageDialog(IDEWindow ideWindow, IDEModule module, IDEPackage pkg) {
45
-		this.ideWindow = ideWindow;
43
+	public CreatePackageDialog(IDEModule module, IDEPackage pkg) {
46 44
 		this.module = module;
47 45
 		this.pkg = pkg;
48 46
 		

+ 56
- 3
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java Ver arquivo

@@ -7,17 +7,25 @@ package org.openzen.zenscript.ide.ui.view;
7 7
 
8 8
 import org.openzen.drawablegui.DSizing;
9 9
 import org.openzen.drawablegui.DEmptyView;
10
+import org.openzen.drawablegui.DHorizontalLayout;
10 11
 import org.openzen.drawablegui.scroll.DScrollPane;
11 12
 import org.openzen.drawablegui.DSideLayout;
13
+import org.openzen.drawablegui.DVerticalLayout;
14
+import org.openzen.drawablegui.border.DEmptyBorder;
15
+import org.openzen.drawablegui.live.ImmutableLiveString;
12 16
 import org.openzen.drawablegui.live.LiveString;
13 17
 import org.openzen.drawablegui.live.SimpleLiveString;
14 18
 import org.openzen.drawablegui.style.DStyleClass;
19
+import org.openzen.drawablegui.style.DStylesheetBuilder;
15 20
 import org.openzen.drawablegui.tree.DTreeView;
16 21
 import org.openzen.drawablegui.tree.DTreeViewStyle;
17 22
 import org.openzen.zenscript.ide.host.DevelopmentHost;
18 23
 import org.openzen.zenscript.ide.host.IDESourceFile;
19 24
 import org.openzen.zenscript.ide.ui.IDEDockWindow;
20 25
 import org.openzen.zenscript.ide.ui.IDEWindow;
26
+import org.openzen.zenscript.ide.ui.dialog.CreatePackageDialog;
27
+import org.openzen.zenscript.ide.ui.dialog.CreateSourceFileDialog;
28
+import org.openzen.zenscript.ide.ui.icons.AddBoxIcon;
21 29
 import org.openzen.zenscript.ide.ui.view.aspectbar.AspectBarView;
22 30
 import org.openzen.zenscript.ide.ui.view.editor.SourceEditor;
23 31
 import org.openzen.zenscript.ide.ui.view.project.RootTreeNode;
@@ -35,10 +43,55 @@ public final class WindowView extends DSideLayout {
35 43
 		super(DStyleClass.EMPTY, DEmptyView.INSTANCE);
36 44
 		this.window = window;
37 45
 		
38
-		DTreeView projectView = new DTreeView(DTreeViewStyle.DEFAULT, new RootTreeNode(window, host), false);
39
-		projectView.getSizing().setValue(new DSizing(500, 500));
46
+		DStyleClass minimalButtonPadding = DStyleClass.inline(new DStylesheetBuilder()
47
+				.dimensionDp("margin", 3)
48
+				.dimensionDp("padding", 0)
49
+				.build());
50
+		
51
+		IconButtonControl addPackageButton = new IconButtonControl(
52
+				minimalButtonPadding,
53
+				AddBoxIcon.BLUE,
54
+				AddBoxIcon.GRAY,
55
+				window.addContentDisabled,
56
+				new ImmutableLiveString("Create package"),
57
+				e -> {
58
+					CreatePackageDialog dialog = new CreatePackageDialog(window.contextModule.getValue(), window.contextPackage.getValue());
59
+					dialog.open(e.window);
60
+				});
61
+		IconButtonControl addFileButton = new IconButtonControl(
62
+				minimalButtonPadding,
63
+				AddBoxIcon.ORANGE,
64
+				AddBoxIcon.GRAY,
65
+				window.addContentDisabled,
66
+				new ImmutableLiveString("Create source file"),
67
+				e -> {
68
+					CreateSourceFileDialog dialog = new CreateSourceFileDialog(window, window.contextModule.getValue(), window.contextPackage.getValue());
69
+					dialog.open(e.window);
70
+				});
71
+		
72
+		DHorizontalLayout toolbar = new DHorizontalLayout(
73
+				DStyleClass.inline(new DStylesheetBuilder()
74
+						.border("border", context -> DEmptyBorder.INSTANCE)
75
+						.dimensionPx("spacing", 0)
76
+						.color("backgroundColor", 0xFFFFFFFF)
77
+						.build()),
78
+				DHorizontalLayout.Alignment.LEFT,
79
+				new DHorizontalLayout.Element(addPackageButton, 0, 0, DHorizontalLayout.ElementAlignment.TOP),
80
+				new DHorizontalLayout.Element(addFileButton, 0, 0, DHorizontalLayout.ElementAlignment.TOP));
81
+		DTreeView projectTree = new DTreeView(DTreeViewStyle.DEFAULT, new RootTreeNode(window, host), false);
82
+		projectTree.getSizing().setValue(new DSizing(500, 500));
83
+		
84
+		DVerticalLayout projectView = new DVerticalLayout(
85
+				DStyleClass.inline(new DStylesheetBuilder()
86
+						.border("border", context -> DEmptyBorder.INSTANCE)
87
+						.dimensionPx("spacing", 0)
88
+						.build()),
89
+				DVerticalLayout.Alignment.TOP,
90
+				new DVerticalLayout.Element(toolbar, 0, 0, DVerticalLayout.ElementAlignment.STRETCH),
91
+				new DVerticalLayout.Element(new DScrollPane(DStyleClass.forId("projectView"), projectTree), 1, 1, DVerticalLayout.ElementAlignment.STRETCH));
92
+		
40 93
 		setMain(tabs = new TabbedView(DStyleClass.EMPTY));
41
-		add(Side.LEFT, new DScrollPane(DStyleClass.forId("projectView"), projectView));
94
+		add(Side.LEFT,projectView);
42 95
 		add(Side.BOTTOM, new StatusBarView(DStyleClass.EMPTY, status));
43 96
 		add(Side.TOP, new AspectBarView(DStyleClass.EMPTY, window.aspectBar));
44 97
 		

Carregando…
Cancelar
Salvar