2 コミット 9a13a61dfb ... 3da66a54b0

作者 SHA1 メッセージ 日付
  therealbluepandabear 9a13a61dfb Fix wrong dimension for `StackLayout`. Rename `Coordinates` to `Coordinate` and `Dimensions` to `Dimension`. Make `StackLayout`'s `children` field public as it may be useful for those who wish to use this library. 1 年間 前
  thebluepandabear 3da66a54b0 Create README.md 1 年間 前

+ 158 - 0
README.md

@@ -0,0 +1,158 @@
+# DTui
+🚧 WIP 🚧 Terminal user interface library for D language
+
+# About
+DTui is a terminal user interface (TUI) library for D language that I am working on in my free time to help better understand D. 
+
+_Keep in mind:_
+
+1. The library's first version has not been released yet.
+
+2. Note that I am new to D so this is not a professional project.
+
+3. Output images are in the IntelliJ IDEA 'Run' window.
+
+# Controls
+
+### Tree
+
+#### Construction:
+
+```D
+void main() {
+  Canvas canvas = new Canvas();
+
+  Tree tree = new Tree(Node("A", Node("B1", Node("C1"), Node("C2")), Node("B2", Node("D1"), Node("D2")), Node("B3", Node("E1"), Node("E2"))));
+
+  canvas.updateCache(tree, Coordinate(0, 0));
+  canvas.drawCache();
+}
+```
+
+#### Output:
+
+![image](https://user-images.githubusercontent.com/50536495/206823364-8bac098d-4cb7-47c1-ae07-abb4f6cd9b17.png)
+
+### Chart
+
+#### Construction:
+
+```D
+void main() {
+  Canvas canvas = new Canvas();
+
+  Chart chart = new Chart(ChartType.column, [1, 4, 9, 2], 3, 1, Color.Red);
+
+  canvas.updateCache(chart, Coordinate(0, 0));
+  canvas.drawCache();
+}
+```
+
+#### Output:
+
+![image](https://user-images.githubusercontent.com/50536495/206823537-27aecc3e-4c4e-47bb-8356-b618a3cf97db.png)
+
+### Rect (with fill)
+
+#### Construction
+
+```D
+void main() {
+  Canvas canvas = new Canvas();
+
+  Rect rect = Rect.withFill(Dimensions(20, 10), Color.Orange);
+
+  canvas.updateCache(rect, Coordinate(0, 0));
+  canvas.drawCache();
+}
+```
+
+#### Output:
+
+![image](https://user-images.githubusercontent.com/50536495/206823643-c8144414-4400-4f2a-8a07-91c8e2af8eff.png)
+
+### Rect (with frame)
+
+#### Construction
+
+```D
+void main() {
+  Canvas canvas = new Canvas();
+
+  Rect rect = Rect.withFrame(Dimensions(20, 10), Color.Blue);
+
+  canvas.updateCache(rect, Coordinate(0, 0));
+  canvas.drawCache();
+}
+```
+
+#### Output
+
+![image](https://user-images.githubusercontent.com/50536495/206823766-0f3b8979-f5ea-4df1-b2dc-ed0bc5cc4714.png)
+
+### Table 
+
+#### Construction
+
+```D
+void main() {
+  Canvas canvas = new Canvas();
+
+  Table table = new Table(10, 5);
+
+  canvas.updateCache(table, Coordinate(0, 0));
+  canvas.drawCache();
+}
+```
+
+#### Output
+
+![image](https://user-images.githubusercontent.com/50536495/206823898-2a7a2b32-b8f9-4fa4-8360-e2b119dd7c27.png)
+
+### Label 
+
+#### Construction
+
+```D
+void main() {
+  Canvas canvas = new Canvas();
+
+  Label label = new Label(Rect.withFill(Dimension.block(30, 11), Color.Black), "Hello World!", Color.Orange);
+
+  canvas.updateCache(label, Coordinate(0, 0));
+  canvas.drawCache();
+}
+```
+
+#### Output
+
+![image](https://user-images.githubusercontent.com/50536495/206827254-a7ed9876-4bc3-4380-8983-9254f3bdc7f9.png)
+
+### StackLayout 
+
+#### Construction
+
+```D
+void main() {
+  Canvas canvas = new Canvas();
+
+  Rect rectr = Rect.withFill(Dimension(10, 10), Color.Blue);
+  Rect rectb = Rect.withFill(Dimension(10, 10), Color.Red);
+
+  StackLayout row = new StackLayout(StackLayoutType.row);
+
+  row.add(rectr, rectb, rectr, rectb, rectr);
+
+  canvas.updateCache(row, Coordinate(0, 0));
+  canvas.drawCache();
+}
+```
+
+#### Output
+
+![image](https://user-images.githubusercontent.com/50536495/206827160-86bd68b6-6ded-4559-991c-446a4bce8aee.png)
+
+
+
+
+

+ 15 - 27
source/app.d

@@ -5,8 +5,8 @@ import core.thread.osthread;
 import core.time;
 import std.random;
 import color;
-import coordinate;
-import dimension;
+import coordinates;
+import dimensions;
 import cell;
 import renderable.renderable;
 import renderable.rect;
@@ -23,38 +23,26 @@ import renderable.table;
 import renderable.tree;
 
 class Canvas {
-	Dimension dimension;
+	Dimensions dimensions;
 	Color backgroundColor;
 
-	private bool wrapContent = false;
 	private CellCacheContainer container;
 
-	this(Color backgroundColor = Color.terminal()) {
-		this.wrapContent = true;
-		this(Dimension(1, 1), backgroundColor);
-	}
-
-	this(Dimension dimension, Color backgroundColor = Color.terminal()) {
-		this.dimension = dimension;
+	this(Dimensions dimensions, Color backgroundColor = Color.terminal()) {
+		this.dimensions = dimensions;
 		this.backgroundColor = backgroundColor;
-
 		container = new CellCacheContainer();
 	}
 
-	void updateCache(Renderable renderable, Coordinate position) {
-		if (wrapContent) {
-			this.dimension.width += renderable.dimension.width;
-			this.dimension.height += renderable.dimension.height;
-		}
-
+	void updateCache(Renderable renderable, Coordinates position) {
 		container.updateCache(renderable, position);
 	}
 
 	void drawCache() {
 		Cell[] cellsDrawn;
 
-		for (int y = 0; y < dimension.height; ++y) {
-			for (int x = 0; x < dimension.width; ++x) {
+		for (int y = 0; y < dimensions.height; ++y) {
+			for (int x = 0; x < dimensions.width; ++x) {
 				bool cellFound = false;
 
 				foreach (cell; container.cache) {
@@ -90,15 +78,15 @@ class Canvas {
 	}
 }
 
-// some bugs with stacklayout spacing
 void main() {
-	Canvas canvas = new Canvas(Dimension(50, 50));
+	Canvas canvas = new Canvas(Dimensions(300, 300));
 
-	StackLayout column = new StackLayout(StackLayoutType.column, 1, Color.Blue);
-	column.add(Rect.withFill(Dimension(3, 3), Color.Red), 3);
+	StackLayout row = new StackLayout(StackLayoutType.row);
 
-	canvas.updateCache(column, Coordinate(0, 0));
-	canvas.drawCache();
+	row.add(new Tree(Node("Lmao", Node(), Node(Node(), Node(), Node(Node(Node(Node())))), Node(), Node())));
+	row.add(new Tree(Node("Lmao", Node(), Node(Node(), Node(), Node(Node(Node(Node())))), Node(), Node())));
 
-	writeln(column.dimension.height);
+	canvas.updateCache(row, Coordinates(0, 0));
+
+	canvas.drawCache();
 }

+ 2 - 2
source/cell.d

@@ -1,10 +1,10 @@
 module cell;
 
-import coordinate;
+import coordinates;
 import color;
 
 struct Cell {
-    Coordinate coordinates;
+    Coordinates coordinates;
     dchar content;
     Color contentColor;
     Color backgroundColor = Color.terminal();

+ 0 - 10
source/coordinate.d

@@ -1,10 +0,0 @@
-module coordinate;
-
-struct Coordinate {
-    int x;
-    int y;
-
-    static Coordinate block(int x, int y) {
-        return Coordinate(x * 2, y);
-    }
-}

+ 10 - 0
source/coordinates.d

@@ -0,0 +1,10 @@
+module coordinates;
+
+struct Coordinates {
+    int x;
+    int y;
+
+    static Coordinates block(int x, int y) {
+        return Coordinates(x * 2, y);
+    }
+}

+ 0 - 10
source/dimension.d

@@ -1,10 +0,0 @@
-module dimension;
-
-struct Dimension {
-    int width;
-    int height;
-
-    static Dimension block(int width, int height) {
-        return Dimension(width * 2, height);
-    }
-}

+ 10 - 0
source/dimensions.d

@@ -0,0 +1,10 @@
+module dimensions;
+
+struct Dimensions {
+    int width;
+    int height;
+
+    static Dimensions block(int width, int height) {
+        return Dimensions(width * 2, height);
+    }
+}

+ 2 - 2
source/renderable/cellcachecontainer.d

@@ -2,14 +2,14 @@ module renderable.cellcachecontainer;
 
 import cell;
 import renderable.renderable;
-import coordinate;
+import coordinates;
 import std.stdio;
 import std.algorithm;
 
 class CellCacheContainer {
     Cell[] cache;
 
-    void updateCache(Renderable renderable, Coordinate position) {
+    void updateCache(Renderable renderable, Coordinates position) {
         Cell[] renderedCells = renderable.render().dup;
 
         foreach (ref cell; renderedCells) {

+ 10 - 10
source/renderable/chart.d

@@ -2,10 +2,10 @@ module renderable.chart;
 
 import renderable.renderable;
 import color;
-import coordinate;
+import coordinates;
 import cell;
 import renderable.renderable;
-import dimension;
+import dimensions;
 import horizontaltextalignment;
 import verticaltextalignment;
 import renderable.rect;
@@ -26,12 +26,12 @@ class Chart : Renderable {
     private CellCacheContainer container;
 
     this(ChartType chartType, int[] data, int columnWidth, int columnSpace, Color chartColor = Color.White, Color backgroundColor = Color.terminal()) {
-        Dimension dimension = Dimension(data.maxElement, cast(int)((data.length * columnSpace) + (data.length * columnWidth) - columnSpace));
+        Dimensions dimensions = Dimensions(data.maxElement, cast(int)((data.length * columnSpace) + (data.length * columnWidth) - columnSpace));
 
         if (chartType == ChartType.bar) {
-            this.dimension = dimension;
+            this.dimensions = dimensions;
         } else {
-           this.dimension = Dimension(dimension.height, dimension.width);
+           this.dimensions = Dimensions(dimensions.height, dimensions.width);
         }
 
         this.chartType = chartType;
@@ -46,23 +46,23 @@ class Chart : Renderable {
 
     override Cell[] render() {
         foreach (indx, num; data) {
-            Rect rect = Rect.withFill(Dimension(columnWidth, num), chartColor);
+            Rect rect = Rect.withFill(Dimensions(columnWidth, num), chartColor);
 
             if (chartType == ChartType.bar) {
-                rect.dimension = Dimension(rect.dimension.height, rect.dimension.width);
+                rect.dimensions = Dimensions(rect.dimensions.height, rect.dimensions.width);
             }
 
-            Coordinate coordinates = Coordinate(0, cast(int)((indx * columnSpace) + (indx * columnWidth)));
+            Coordinates coordinates = Coordinates(0, cast(int)((indx * columnSpace) + (indx * columnWidth)));
 
             if (chartType == ChartType.bar) {
                 container.updateCache(rect, coordinates);
             } else {
-                container.updateCache(rect, Coordinate(coordinates.y, this.dimension.height - num));
+                container.updateCache(rect, Coordinates(coordinates.y, this.dimensions.height - num));
             }
         }
 
         if (backgroundColor != Color.terminal()) {
-            container.updateCache(Rect.withFill(Dimension(dimension.width, dimension.height), backgroundColor), Coordinate(0, 0));
+            container.updateCache(Rect.withFill(Dimensions(dimensions.width, dimensions.height), backgroundColor), Coordinates(0, 0));
         }
 
         return container.cache;

+ 0 - 0
source/renderable/label.d


この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません