Clone in a terminal:
Commit f3a8e6d
Johan Mattsson - 2014-11-16T09:13:15+00:00
f3a8e6d382552250b9e148ea2f558e75df0e8694johan.mattsson.m@gmail.com

Show key bindings in menu

Changed files (3)

Diff

diff --git a/libbirdfont/Menu.vala b/libbirdfont/Menu.valaindex e2b65d7..927a141 100644--- a/libbirdfont/Menu.vala+++ b/libbirdfont/Menu.vala@@ -588,13 +588,43 @@ public class Menu : GLib.Object { 		GlyphCanvas.redraw (); 	} 	+	public double layout_width () {+		Text key_binding = new Text ();+		double font_size = 17 * MainWindow.units;;+		double w;+		+		width = 0;+		foreach (MenuItem item in current_menu.items) {+			key_binding.set_text (item.get_key_bindings ());+			+			w = item.label.get_extent (font_size);+			w += key_binding.get_extent (font_size);+			w += 3 * height * MainWindow.units;+			+			if (w > width) {+				width = w;+			}+		}+		+		return width;+	}+	 	public void draw (WidgetAllocation allocation, Context cr) {-		double y = 0;-		double x = allocation.width - width;+		double y;+		double x; 		double label_x; 		double label_y; 		double font_size;+		Text key_binding;+		double binding_extent;+		+		width = layout_width (); 		+		key_binding = new Text ();+		+		x = allocation.width - width;+		y = 0;+		font_size = 17 * MainWindow.units; 		this.allocation = allocation; 		 		foreach (MenuItem item in current_menu.items) {@@ -607,10 +637,14 @@ public class Menu : GLib.Object { 			cr.save (); 			cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1); 			label_x = allocation.width - width + 0.7 * height * MainWindow.units;-			font_size = 17 * MainWindow.units; 			label_y = y + font_size - 1 * MainWindow.units; 			item.label.draw (cr, label_x, label_y, font_size);-						+			+			key_binding.set_text (item.get_key_bindings ());+			binding_extent = key_binding.get_extent (font_size);+			label_x = x + width - binding_extent - 0.6 * height * MainWindow.units;+			key_binding.draw (cr, label_x, label_y, font_size);+			 			y += height; 		} 	}diff --git a/libbirdfont/Renderer/Text.vala b/libbirdfont/Renderer/Text.valaindex 306a471..bc636c8 100644--- a/libbirdfont/Renderer/Text.vala+++ b/libbirdfont/Renderer/Text.vala@@ -22,7 +22,7 @@ public class Text { 	Font font { 		get { 			if (current_font == null) {-				File path = SearchPaths.find_file ("resources", "roboto.bf");+				File path = SearchPaths.find_file (null, "roboto.bf"); 				current_font = new Font (); 				if (!load_font ((!) path.get_path ())) { 					current_font =  new Font ();diff --git a/libbirdfont/SearchPaths.vala b/libbirdfont/SearchPaths.valaindex 1523362..8cdaf41 100644--- a/libbirdfont/SearchPaths.vala+++ b/libbirdfont/SearchPaths.vala@@ -31,7 +31,10 @@ public class SearchPaths {  		f = get_file (resources + "/", name); 		if (likely (f.query_exists ())) return f;-		++		f = get_file ("resources/", name);+		if (likely (f.query_exists ())) return f;+				 		f = get_file (resources + "/", name + "/"); 		if (likely (f.query_exists ())) return f; 

Contact

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