Clone in a terminal:
Commit 0d76b49
Johan Mattsson - 2015-03-24T09:36:19+00:00
0d76b4932a1604da714a3a64712ff60acf43107bjohan.mattsson.m@gmail.com

New text rendering in table

Changed files (2)

Diff

diff --git a/libbirdfont/Row.vala b/libbirdfont/Row.valaindex e010aa0..458e135 100644--- a/libbirdfont/Row.vala+++ b/libbirdfont/Row.vala@@ -20,32 +20,34 @@ public class Row : GLib.Object {  	int index = 0; 	bool delete_button = true;-	public Gee.ArrayList<string> columns_labels = new Gee.ArrayList<string> ();+	public Gee.ArrayList<Text> column_text = new Gee.ArrayList<Text> (); 	GLib.Object? row_data = null; 	+	public static const int MAX_COLUMNS = 5;+	 	public int columns { 		get {-			return columns_labels.size;+			return column_text.size; 		} 	} 	 	public Row (string label, int index, bool delete_button = true) { 		this.index = index;-		columns_labels.add (label);+		column_text.add (new Text (label, 17 * MainWindow.units)); 		this.delete_button = delete_button; 	}  	public Row.columns_1 (string label, int index, bool delete_button = true) { 		this.index = index;-		columns_labels.add (label);+		column_text.add (new Text (label, 17 * MainWindow.units)); 		this.delete_button = delete_button; 	} 	 	public Row.columns_2 (string label0, string label1, int index, 		bool delete_button = true) { 			-		columns_labels.add (label0);-		columns_labels.add (label1);+		column_text.add (new Text (label0, 17 * MainWindow.units));+		column_text.add (new Text (label1, 17 * MainWindow.units)); 		this.index = index; 		this.delete_button = delete_button; 	}@@ -53,9 +55,9 @@ public class Row : GLib.Object { 	public Row.columns_3 (string label0, string label1, string label2, 		int index, bool delete_button = true) { 			-		columns_labels.add (label0);-		columns_labels.add (label1);-		columns_labels.add (label2);+		column_text.add (new Text (label0, 17 * MainWindow.units));+		column_text.add (new Text (label1, 17 * MainWindow.units));+		column_text.add (new Text (label2, 17 * MainWindow.units)); 		this.index = index; 		this.delete_button = delete_button; 	}@@ -63,10 +65,10 @@ public class Row : GLib.Object { 	public Row.columns_4 (string label0, string label1, string label2,  		string label3, int index, bool delete_button = true) { 			-		columns_labels.add (label0);-		columns_labels.add (label1);-		columns_labels.add (label2);-		columns_labels.add (label3);+		column_text.add (new Text (label0, 17 * MainWindow.units));+		column_text.add (new Text (label1, 17 * MainWindow.units));+		column_text.add (new Text (label2, 17 * MainWindow.units));+		column_text.add (new Text (label3, 17 * MainWindow.units)); 		this.index = index; 		this.delete_button = delete_button; 	}@@ -74,11 +76,11 @@ public class Row : GLib.Object { 	public Row.columns_5 (string label0, string label1, string label2, 		string label3, string label4, int index, bool delete_button = true) { 			-		columns_labels.add (label0);-		columns_labels.add (label1);-		columns_labels.add (label2);-		columns_labels.add (label3);-		columns_labels.add (label4);+		column_text.add (new Text (label0, 17 * MainWindow.units));+		column_text.add (new Text (label1, 17 * MainWindow.units));+		column_text.add (new Text (label2, 17 * MainWindow.units));+		column_text.add (new Text (label3, 17 * MainWindow.units));+		column_text.add (new Text (label4, 17 * MainWindow.units)); 		this.index = index; 		this.delete_button = delete_button; 	}@@ -99,9 +101,9 @@ public class Row : GLib.Object { 		return delete_button; 	} 	-	public string get_column (int i) {-		return_val_if_fail (0 <= i < columns, "".dup ());-		return columns_labels.get (i);+	public Text get_column (int i) {+		return_val_if_fail (0 <= i < columns, new Text ());+		return column_text.get (i); 	}  	public int get_index () {diff --git a/libbirdfont/Table.vala b/libbirdfont/Table.valaindex dfe163b..6fb0936 100644--- a/libbirdfont/Table.vala+++ b/libbirdfont/Table.vala@@ -23,6 +23,7 @@ public abstract class Table : FontDisplay { 	int scroll = 0; 	int visible_rows = 0; 	WidgetAllocation allocation = new WidgetAllocation ();+	Gee.ArrayList<int> column_width = new Gee.ArrayList<int> ();  	public abstract void update_rows (); 	public abstract Gee.ArrayList<Row> get_rows ();@@ -33,6 +34,8 @@ public abstract class Table : FontDisplay { 		int s = 0; 		bool color = (scroll + 1 % 2) == 0; 		+		layout ();+		 		if (allocation.width != this.allocation.width 				|| allocation.height != this.allocation.height) { 			this.allocation = allocation;@@ -55,7 +58,7 @@ public abstract class Table : FontDisplay { 		foreach (Row r in get_rows ()) { 			if (s++ >= scroll) { 				draw_row (allocation, cr, r, y, color, true);-				y += 18 * MainWindow.units;+				y += 23 * MainWindow.units; 				color = !color; 			} 		}@@ -63,11 +66,34 @@ public abstract class Table : FontDisplay { 		cr.restore (); 	}	 -	private static void draw_row (WidgetAllocation allocation, Context cr,+	private void layout () {+		int width;+		+		column_width.clear ();+		+		for (int i = 0; i <= Row.MAX_COLUMNS; i++) {+			column_width.add (0);+		}+		+		foreach (Row row in get_rows ()) {+			return_if_fail (row.columns <= column_width.size);+			+			for (int i = 0; i < row.columns; i++) {+				width = (int) row.get_column (i).get_sidebearing_extent ();+				if (column_width.get (i) < width) {+					column_width.set (i, width);+				}+			}+		}+	}++	private void draw_row (WidgetAllocation allocation, Context cr, 			Row row, double y, bool color, bool dark) { 		+		Text t; 		double margin;-	+		double x;+		 		if (color) { 			cr.save (); 			Theme.color (cr, "Background 6");@@ -88,13 +114,24 @@ public abstract class Table : FontDisplay { 			cr.restore (); 		} 		+		return_if_fail (row.columns <= column_width.size);+		+		x = 0;+		margin = (row.has_delete_button ()) ? 120 * MainWindow.units : 0; 		for (int i = 0; i < row.columns; i++) { 			cr.save (); 			Theme.color (cr, "Foreground 1");-			margin = (row.has_delete_button ()) ? 120 * MainWindow.units : 3* MainWindow.units;-			cr.move_to (margin + i * 120 * MainWindow.units, y);-			cr.set_font_size (12 * MainWindow.units);-			cr.show_text (row.get_column (i));+			+			x += margin;+			margin = 3 * MainWindow.units;+			+			t = row.get_column (i);+			t.widget_x = x;+			t.widget_y = y - 17 * MainWindow.units;+			t.draw (cr);+			+			x += column_width.get (i) + 10 * MainWindow.units; +			 			cr.restore (); 		} 	}@@ -116,6 +153,7 @@ public abstract class Table : FontDisplay { 				 				if (y - 10 * MainWindow.units <= ey * MainWindow.units <= y + 5 * MainWindow.units) { 					+					// FIXME: new layout 					if (r.has_delete_button ()) { 						colum = (int) ((ex - 120) / 120 * MainWindow.units); 					} else {

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112