Clone in a terminal:
Commit 7214094
Johan Mattsson - 2015-04-19T14:16:06+00:00
72140949e2f390a64a0ffff0d98a760258008c02johan.mattsson.m@gmail.com

Update drop down menu

Changed files (4)

Diff

diff --git a/icons/delete_menu_item.png b/icons/delete_menu_item.pngdeleted file mode 100644index b8744c9..0000000Binary files a/icons/delete_menu_item.png and /dev/null differdiff --git a/libbirdfont/DropMenu.vala b/libbirdfont/DropMenu.valaindex 076b7e2..2ce5f9d 100644--- a/libbirdfont/DropMenu.vala+++ b/libbirdfont/DropMenu.vala@@ -28,6 +28,7 @@ public class DropMenu : GLib.Object { 	 	double x = -1; 	double y = -1;+	double width = 0; 	 	double menu_x = -1; 	@@ -99,7 +100,7 @@ public class DropMenu : GLib.Object { 			return false; 		} 		-		return x - 5 < px < x + 12 + 5 && y - 5 < py < y + 12 + 5;+		return x - 12 < px <= x && y - 5 < py < y + 12 + 5; 	}  	public bool menu_item_action (double px, double py) {@@ -113,9 +114,9 @@ public class DropMenu : GLib.Object { 			 			if (action != null) { 				a = (!) action;-+				 				// action for the delete button-				if (a.has_delete_button && menu_x + 88 - 7 < px < menu_x + 88 + 13) { +				if (a.has_delete_button && menu_x + width - 13 < px <= menu_x + width) {  					index = 0; 					ma = actions.get (0); 					while (true) {@@ -164,7 +165,7 @@ public class DropMenu : GLib.Object { 				iy = y - 24 - n * item_height; 			} 	-			if (ix <= px <= ix + 100 && iy <= py <= iy + item_height) {+			if (ix <= px <= ix + width && iy <= py <= iy + item_height) { 				return item; 			} 			@@ -177,33 +178,31 @@ public class DropMenu : GLib.Object { 	public void set_position (double px, double py) { 		x = px; 		y = py;-		-		if (x - 100 + 19 < 0) {-			menu_x = 10;++		foreach (MenuAction item in actions) {+			if (item.text.get_sidebearing_extent () + 25 > width) {+				width = item.text.get_sidebearing_extent () + 25;+			}+		}+				+		if (x - width + 19 < 0) {+			menu_x = 30; 		} else {-			menu_x = x - 100 + 19;+			menu_x = x - width; 		} 	} 	 	public void draw_menu (Context cr) { 		double ix, iy; 		int n;-		Pattern gradient; 		 		if (likely (!menu_visible)) { 			return; 		} 		 		cr.save ();-		cr.set_source_rgba (177/255.0, 177/255.0, 177/255.0, 1);-		cr.set_line_width (0);-		-		gradient = new Pattern.linear (menu_x, y - 3 * item_height, menu_x, y);-		gradient.add_color_stop_rgb (0, 177/255.0, 177/255.0, 177/255.0);-		gradient.add_color_stop_rgb (1, 234/255.0, 234/255.0, 234/255.0);-		-		cr.set_source (gradient);-		cr.rectangle (menu_x, y - actions.size * item_height, 94, actions.size * item_height);+		Theme.color (cr, "Default Background");+		cr.rectangle (menu_x, y - actions.size * item_height, width, actions.size * item_height); 		 		cr.fill_preserve (); 		cr.stroke ();@@ -213,6 +212,8 @@ public class DropMenu : GLib.Object { 		 		n = 0; 		foreach (MenuAction item in actions) {+			item.width = width;+			 			iy = y - 8 - n * item_height; 			ix = menu_x + 2; 			diff --git a/libbirdfont/MenuAction.vala b/libbirdfont/MenuAction.valaindex 6823f18..761b603 100644--- a/libbirdfont/MenuAction.vala+++ b/libbirdfont/MenuAction.vala@@ -22,16 +22,14 @@ public class MenuAction : GLib.Object { 	public DropMenu? parent = null; 	public int index = -1; 	public bool has_delete_button = true;+	public double width = 100;+	public Text text; 	 	bool selected = false;-	static ImageSurface? delete_button = null; 	 	public MenuAction (string label) { 		this.label = label;-		-		if (delete_button == null) {-			delete_button = Icons.get_icon ("delete_menu_item.png");-		}+		text = new Text (label); 	} 	 	public void set_selected (bool s) {@@ -39,36 +37,29 @@ public class MenuAction : GLib.Object { 	} 	 	public virtual void draw (double x, double y, Context cr) {-		ImageSurface img;-		 		if (selected) { 			cr.save ();-			Theme.color (cr, "Selected Menu Item");-			cr.rectangle (x - 2, y - 12, 93, 15);+			Theme.color (cr, "Highlighted 1");+			cr.rectangle (x - 2, y - 12, width, 15); 			cr.fill_preserve (); 			cr.stroke (); 			cr.restore ();			 		} -		if (has_delete_button && delete_button != null) {-			img = (!) delete_button;+		if (has_delete_button) { 			cr.save ();-			cr.set_source_surface (img, x - img.get_width () / 2 + 82, y - img.get_height () / 2 - 5);-			cr.paint ();+			Theme.color (cr, "Foreground 1");+			cr.move_to (x + width - 10, y - 2);+			cr.line_to (x + width - 10 - 5, y - 2 - 5);+			cr.move_to (x + width - 10 - 5, y - 2);+			cr.line_to (x + width - 10, y - 2 - 5);+			cr.set_line_width (1);+			cr.stroke (); 			cr.restore (); 		} 		-		cr.save ();-		-		Theme.color (cr, "Foreground 1");-		-		cr.set_font_size (12);-		cr.select_font_face ("Cantarell", FontSlant.NORMAL, FontWeight.NORMAL);-		-		cr.move_to (x, y);--		cr.show_text (label);-		cr.restore ();+		Theme.text_color (text, "Foreground 1");+		text.draw_at_baseline (cr, x, y); 	} } diff --git a/libbirdfont/OverViewItem.vala b/libbirdfont/OverViewItem.valaindex 50a979b..0b28966 100644--- a/libbirdfont/OverViewItem.vala+++ b/libbirdfont/OverViewItem.vala@@ -290,7 +290,7 @@ public class OverViewItem : GLib.Object { 		g = (!) glyphs; 		menu = g.get_version_list ();		 		menu.draw_menu (cr);-		menu.set_position (x + width - 32, y + height - 16);+		menu.set_position (x + width - 21, y + height - 18); 	} } 

Contact

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