The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Update drop down menu

These changes was commited to the Birdfont repository Sun, 19 Apr 2015 14:16:06 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sun, 19 Apr 2015 14:16:06 +0000]

Updated Files

icons/delete_menu_item.png
libbirdfont/DropMenu.vala
libbirdfont/MenuAction.vala
libbirdfont/OverViewItem.vala
diff --git icons/delete_menu_item.png(deleted)
--- a/icons/delete_menu_item.png +++ /dev/null @@ -1,3 +1,1 @@ - PNG -  - IHDRo&sBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<AIDAT-ʡ `E3APDɍ,+q ᳼tpZU0δÑ7Elx@1JTIENDB` +
--- a/libbirdfont/DropMenu.vala +++ b/libbirdfont/DropMenu.vala @@ -28,6 +28,7 @@ double x = -1; double y = -1; + double width = 0; double menu_x = -1; @@ -99,7 +100,7 @@ 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 @@ 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 @@ 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 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 @@ n = 0; foreach (MenuAction item in actions) { + item.width = width; + iy = y - 8 - n * item_height; ix = menu_x + 2;
--- a/libbirdfont/MenuAction.vala +++ b/libbirdfont/MenuAction.vala @@ -22,16 +22,14 @@ 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,38 +37,31 @@ } 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); } } }
--- a/libbirdfont/OverViewItem.vala +++ b/libbirdfont/OverViewItem.vala @@ -290,9 +290,9 @@ 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); } } }