Kaynağa Gözat

- Fixed scaling (hopefully) on different DPI devices

- Fixed some minor ui issues
Stan Hebben 6 yıl önce
ebeveyn
işleme
dd47b2621c

+ 2
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/DInputField.java Dosyayı Görüntüle

@@ -96,7 +96,7 @@ public class DInputField implements DComponent {
96 96
 		
97 97
 		if (cursor != null)
98 98
 			cursor.close();
99
-		cursor = parent.fillRect(2, DIRectangle.EMPTY, cursorBlink ? style.cursorColor : 0);
99
+		cursor = parent.fillRect(3, DIRectangle.EMPTY, cursorBlink ? style.cursorColor : 0);
100 100
 		
101 101
 		if (selection != null)
102 102
 			selection.close();
@@ -152,6 +152,7 @@ public class DInputField implements DComponent {
152 152
 		text.setPosition(
153 153
 				bounds.x + style.margin.left + style.border.getPaddingLeft(),
154 154
 				bounds.y + style.margin.top + style.border.getPaddingTop() + fontMetrics.getAscent());
155
+		
155 156
 		style.border.update(context, bounds);
156 157
 	}
157 158
 	

+ 22
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DScalableSize.java Dosyayı Görüntüle

@@ -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;
7
+
8
+import org.openzen.drawablegui.style.DDimension;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class DScalableSize {
15
+	public final DDimension width;
16
+	public final DDimension height;
17
+	
18
+	public DScalableSize(DDimension width, DDimension height) {
19
+		this.width = width;
20
+		this.height = height;
21
+	}
22
+}

+ 4
- 4
DrawableGui/src/main/java/org/openzen/drawablegui/form/DFormStyle.java Dosyayı Görüntüle

@@ -28,10 +28,10 @@ public class DFormStyle {
28 28
 	public final int minimumFieldSize;
29 29
 	
30 30
 	public DFormStyle(DStyleDefinition style) {
31
-		paddingLeft = style.getDimension("paddingLeft", new DDpDimension(16));
32
-		paddingTop = style.getDimension("paddingTop", new DDpDimension(16));
33
-		paddingRight = style.getDimension("paddingRight", new DDpDimension(16));
34
-		paddingBottom = style.getDimension("paddingBottom", new DDpDimension(16));
31
+		paddingLeft = style.getDimension("paddingLeft", DPxDimension.ZERO);
32
+		paddingTop = style.getDimension("paddingTop", DPxDimension.ZERO);
33
+		paddingRight = style.getDimension("paddingRight", DPxDimension.ZERO);
34
+		paddingBottom = style.getDimension("paddingBottom", DPxDimension.ZERO);
35 35
 		spacing = style.getDimension("spacing", new DDpDimension(8));
36 36
 		
37 37
 		labelColor = style.getColor("labelColor", 0xFF000000);

+ 2
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/layout/DLinearLayout.java Dosyayı Görüntüle

@@ -244,7 +244,7 @@ public class DLinearLayout extends BaseComponentGroup {
244 244
 				DSizing preferences = element.component.getSizing().getValue();
245 245
 				int newX = x + preferences.preferredWidth;
246 246
 				layoutHorizontal(element, x, newX - x);
247
-				x = newX;
247
+				x = newX + style.spacing;
248 248
 			}
249 249
 		} else {
250 250
 			float deltaScaled = delta / totalGrow;
@@ -269,7 +269,7 @@ public class DLinearLayout extends BaseComponentGroup {
269 269
 				DSizing preferences = element.component.getSizing().getValue();
270 270
 				int newY = y + preferences.preferredHeight;
271 271
 				layoutVertical(element, y, newY - y);
272
-				y = newY;
272
+				y = newY + style.spacing;
273 273
 			}
274 274
 		} else {
275 275
 			float deltaScaled = delta / totalGrow;

+ 10
- 3
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java Dosyayı Görüntüle

@@ -10,6 +10,7 @@ import org.openzen.drawablegui.DComponentContext;
10 10
 import org.openzen.drawablegui.DSizing;
11 11
 import org.openzen.drawablegui.DIRectangle;
12 12
 import org.openzen.drawablegui.DMouseEvent;
13
+import org.openzen.drawablegui.DScalableSize;
13 14
 import org.openzen.drawablegui.DTransform2D;
14 15
 import org.openzen.drawablegui.listeners.ListenerHandle;
15 16
 import org.openzen.drawablegui.live.LiveInt;
@@ -17,6 +18,7 @@ import org.openzen.drawablegui.live.LiveObject;
17 18
 import org.openzen.drawablegui.live.SimpleLiveInt;
18 19
 import org.openzen.drawablegui.draw.DDrawnShape;
19 20
 import org.openzen.drawablegui.draw.DSubSurface;
21
+import org.openzen.drawablegui.live.SimpleLiveObject;
20 22
 import org.openzen.drawablegui.style.DStyleClass;
21 23
 
22 24
 /**
@@ -37,7 +39,8 @@ public class DScrollPane implements DComponent, DScrollContext {
37 39
 	private final LiveInt offsetX;
38 40
 	private final LiveInt offsetY;
39 41
 	
40
-	private final LiveObject<DSizing> sizing;
42
+	private final SimpleLiveObject<DSizing> sizing = new SimpleLiveObject<>(DSizing.EMPTY);
43
+	private final LiveObject<DScalableSize> size;
41 44
 	
42 45
 	private final ListenerHandle<LiveInt.Listener> contentsHeightListener;
43 46
 	private final ListenerHandle<LiveInt.Listener> offsetXListener;
@@ -48,8 +51,8 @@ public class DScrollPane implements DComponent, DScrollContext {
48 51
 	
49 52
 	private DSubSurface subSurface;
50 53
 	
51
-	public DScrollPane(DStyleClass styleClass, DComponent contents, LiveObject<DSizing> sizing) {
52
-		this.sizing = sizing;
54
+	public DScrollPane(DStyleClass styleClass, DComponent contents, LiveObject<DScalableSize> size) {
55
+		this.size = size;
53 56
 		this.styleClass = styleClass;
54 57
 		this.contents = contents;
55 58
 		
@@ -81,6 +84,10 @@ public class DScrollPane implements DComponent, DScrollContext {
81 84
 		DComponentContext newContext = new DComponentContext(this, context.path, 0, subSurface);
82 85
 		contents.mount(newContext);
83 86
 		scrollBar.mount(context);
87
+		
88
+		sizing.setValue(new DSizing(
89
+				size.getValue().width.evalInt(parent.getUIContext()),
90
+				size.getValue().height.evalInt(parent.getUIContext())));
84 91
 	}
85 92
 	
86 93
 	@Override

+ 1
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingDrawnRectangle.java Dosyayı Görüntüle

@@ -53,5 +53,6 @@ public class SwingDrawnRectangle extends SwingDrawnElement implements DDrawnRect
53 53
 	public void paint(Graphics2D g, DIRectangle clip) {
54 54
 		g.setColor(awtColor);
55 55
 		g.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
56
+		g.fillRect(clip.x, clip.y, 3, 3);
56 57
 	}
57 58
 }

+ 1
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java Dosyayı Görüntüle

@@ -88,6 +88,7 @@ public final class SwingRoot extends Component implements ComponentListener, Mou
88 88
 		Rectangle clipBounds = g.getClipBounds();
89 89
 		DIRectangle clipBounds2 = clipBounds == null ? null : new DIRectangle(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
90 90
 		Graphics2D g2d = (Graphics2D) g;
91
+		//System.out.println("Transform: " + g2d.getTransform().getTranslateX() + ", " + g2d.getTransform().getTranslateY());
91 92
 		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
92 93
 		g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
93 94
 		surface.paint(g2d, clipBounds2);

+ 8
- 2
IDE/src/main/java/org/openzen/zenscript/ide/ui/dialog/CreateSourceFileDialog.java Dosyayı Görüntüle

@@ -23,7 +23,9 @@ import org.openzen.drawablegui.live.ImmutableLiveBool;
23 23
 import org.openzen.drawablegui.live.ImmutableLiveString;
24 24
 import org.openzen.drawablegui.live.SimpleLiveString;
25 25
 import org.openzen.drawablegui.style.DDpDimension;
26
+import org.openzen.drawablegui.style.DSimpleStylesheet;
26 27
 import org.openzen.drawablegui.style.DStyleClass;
28
+import org.openzen.drawablegui.style.DStylesheetBuilder;
27 29
 import org.openzen.zenscript.ide.host.IDEModule;
28 30
 import org.openzen.zenscript.ide.host.IDEPackage;
29 31
 import org.openzen.zenscript.ide.host.IDESourceFile;
@@ -64,14 +66,18 @@ public class CreateSourceFileDialog {
64 66
 		DButton ok = new DButton(DStyleClass.EMPTY, new SimpleLiveString("Create"), ImmutableLiveBool.FALSE, this::ok);
65 67
 		DButton cancel = new DButton(DStyleClass.EMPTY, new SimpleLiveString("Cancel"), ImmutableLiveBool.FALSE, this::cancel);
66 68
 		DLinearLayout buttons = new DLinearLayout(
67
-				DStyleClass.EMPTY,
69
+				DStyleClass.inline(new DStylesheetBuilder()
70
+					.dimensionDp("spacing", 8)
71
+					.build()),
68 72
 				Orientation.HORIZONTAL,
69 73
 				Alignment.RIGHT,
70 74
 				new Element(cancel, 0, 0, ElementAlignment.TOP),
71 75
 				new Element(ok, 0, 0, ElementAlignment.TOP));
72 76
 
73 77
 		root = new DLinearLayout(
74
-				DStyleClass.EMPTY,
78
+				DStyleClass.inline(new DStylesheetBuilder()
79
+						.marginDp("margin", 16)
80
+						.build()),
75 81
 				Orientation.VERTICAL,
76 82
 				Alignment.MIDDLE,
77 83
 				new Element(form, 1, 1, ElementAlignment.CENTER),

+ 6
- 7
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java Dosyayı Görüntüle

@@ -6,16 +6,15 @@
6 6
 package org.openzen.zenscript.ide.ui.view;
7 7
 
8 8
 import org.openzen.drawablegui.DEmptyView;
9
+import org.openzen.drawablegui.DScalableSize;
9 10
 import org.openzen.drawablegui.DSizing;
10 11
 import org.openzen.drawablegui.border.DLineBorder;
11 12
 import org.openzen.drawablegui.scroll.DScrollPane;
12 13
 import org.openzen.drawablegui.layout.DSideLayout;
13
-import org.openzen.drawablegui.live.LiveArrayList;
14 14
 import org.openzen.drawablegui.live.LiveString;
15
-import org.openzen.drawablegui.live.MutableLiveList;
16
-import org.openzen.drawablegui.live.SimpleLiveInt;
17 15
 import org.openzen.drawablegui.live.SimpleLiveObject;
18 16
 import org.openzen.drawablegui.live.SimpleLiveString;
17
+import org.openzen.drawablegui.style.DDpDimension;
19 18
 import org.openzen.drawablegui.style.DShadow;
20 19
 import org.openzen.drawablegui.style.DStyleClass;
21 20
 import org.openzen.drawablegui.style.DStylesheetBuilder;
@@ -25,7 +24,6 @@ import org.openzen.zenscript.ide.ui.IDEDockWindow;
25 24
 import org.openzen.zenscript.ide.ui.IDEWindow;
26 25
 import org.openzen.zenscript.ide.ui.view.aspectbar.AspectBarView;
27 26
 import org.openzen.zenscript.ide.ui.view.editor.SourceEditor;
28
-import org.openzen.zenscript.ide.ui.view.output.OutputLine;
29 27
 import org.openzen.zenscript.ide.ui.view.output.OutputView;
30 28
 import org.openzen.zenscript.ide.ui.view.project.ProjectBrowser;
31 29
 
@@ -49,12 +47,12 @@ public final class WindowView extends DSideLayout {
49 47
 		
50 48
 		OutputView output = new OutputView(DStyleClass.EMPTY, window.output);
51 49
 		
50
+		DScalableSize outputSize = new DScalableSize(new DDpDimension(250), new DDpDimension(250));
52 51
 		DScrollPane scrollOutput = new DScrollPane(DStyleClass.inline(new DStylesheetBuilder()
53
-							//.border("border", context -> new DLineBorder(0xFF888888, 1))
54 52
 							.marginDp("margin", 3)
55 53
 							.color("backgroundColor", 0xFFFFFFFF)
56 54
 							.shadow("shadow", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()))
57
-							.build()), output, new SimpleLiveObject<>(new DSizing(400, 400)));
55
+							.build()), output, new SimpleLiveObject<>(outputSize));
58 56
 		
59 57
 		setMain(tabs = new TabbedView(DStyleClass.inline(new DStylesheetBuilder()
60 58
 				.marginDp("margin", 3)
@@ -71,13 +69,14 @@ public final class WindowView extends DSideLayout {
71 69
 		@Override
72 70
 		public void onOpen(IDESourceFile sourceFile) {
73 71
 			SourceEditor editor = new SourceEditor(DStyleClass.EMPTY, window, sourceFile);
72
+			DScalableSize size = new DScalableSize(new DDpDimension(280), new DDpDimension(280));
74 73
 			TabbedViewComponent tab = new TabbedViewComponent(
75 74
 					sourceFile.getName(),
76 75
 					null,
77 76
 					new DScrollPane(DStyleClass.inline(new DStylesheetBuilder()
78 77
 							.border("border", context -> new DLineBorder(0xFF888888, 1))
79 78
 							//.shadow("shadow", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()))
80
-							.build()), editor, new SimpleLiveObject<>(new DSizing(500, 500))),
79
+							.build()), editor, new SimpleLiveObject<>(size)),
81 80
 					editor.isUpdated());
82 81
 			tabs.tabs.add(tab);
83 82
 			tabs.currentTab.setValue(tab);

+ 5
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/ProjectBrowser.java Dosyayı Görüntüle

@@ -9,6 +9,7 @@ import org.openzen.drawablegui.DComponent;
9 9
 import org.openzen.drawablegui.DFont;
10 10
 import org.openzen.drawablegui.DFontFamily;
11 11
 import org.openzen.drawablegui.DLabel;
12
+import org.openzen.drawablegui.DScalableSize;
12 13
 import org.openzen.drawablegui.DSizing;
13 14
 import org.openzen.drawablegui.border.DEmptyBorder;
14 15
 import org.openzen.drawablegui.border.DPaddedBorder;
@@ -24,6 +25,7 @@ import org.openzen.drawablegui.live.MutableLiveObject;
24 25
 import org.openzen.drawablegui.live.SimpleLiveObject;
25 26
 import org.openzen.drawablegui.live.SimpleLiveString;
26 27
 import org.openzen.drawablegui.scroll.DScrollPane;
28
+import org.openzen.drawablegui.style.DDpDimension;
27 29
 import org.openzen.drawablegui.style.DRoundedRectangleShape;
28 30
 import org.openzen.drawablegui.style.DShadow;
29 31
 import org.openzen.drawablegui.style.DStyleClass;
@@ -107,6 +109,8 @@ public class ProjectBrowser {
107 109
 				ExpandedArrow.INSTANCE,
108 110
 				CollapsedArrow.INSTANCE,
109 111
 				new RootTreeNode(this, host), false);
112
+		
113
+		DScalableSize treeSize = new DScalableSize(new DDpDimension(280), new DDpDimension(280));
110 114
 		DScrollPane treeScrollPane = new DScrollPane(
111 115
 				DStyleClass.inline("projectView", new DStylesheetBuilder()
112 116
 						.shape("shape", context -> new DRoundedRectangleShape(0, 0, context.dp(2), context.dp(2)))
@@ -114,7 +118,7 @@ public class ProjectBrowser {
114 118
 						.shadow("shadow", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()))
115 119
 						.build()),
116 120
 				projectTree,
117
-				new SimpleLiveObject<>(new DSizing(500, 500)));
121
+				new SimpleLiveObject<>(treeSize));
118 122
 		
119 123
 		view = new DLinearLayout(
120 124
 				DStyleClass.inline(new DStylesheetBuilder()

Loading…
İptal
Kaydet