The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Switch keyboard focus with tab key in name and description tab

These changes was commited to the Birdfont repository Tue, 31 Mar 2015 19:23:15 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Tue, 31 Mar 2015 19:23:15 +0000]

Updated Files

libbirdfont/Button.vala
libbirdfont/CheckBox.vala
libbirdfont/DescriptionDisplay.vala
libbirdfont/Dialog.vala
libbirdfont/KeyBindings.vala
libbirdfont/MoveTool.vala
libbirdfont/Renderer/TextArea.vala
libbirdfont/Widget.vala
--- a/libbirdfont/Button.vala +++ b/libbirdfont/Button.vala @@ -58,7 +58,7 @@ return label.get_width () + 2 * padding; } - public void button_press (uint button, double x, double y) { + public override void button_press (uint button, double x, double y) { if (is_over (x, y)) { action (); }
--- a/libbirdfont/CheckBox.vala +++ b/libbirdfont/CheckBox.vala @@ -25,6 +25,8 @@ public double w = 12 * MainWindow.units; public double h = 12 * MainWindow.units; + + bool has_focus = false; public Text label; @@ -61,7 +63,13 @@ cr.save (); cr.set_line_width (1); - Theme.color (cr, "Foreground 1"); + + if (has_focus) { + Theme.color (cr, "Highlighted 1"); + } else { + Theme.color (cr, "Foreground 1"); + } + draw_rounded_rectangle (cr, widget_x, widget_y + center_y, w, h - padding, padding); cr.stroke (); cr.restore (); @@ -88,7 +96,19 @@ label.draw (cr); } + public override void key_press (uint keyval) { + unichar c = (unichar) keyval; + + if (c == ' ') { + checked = !checked; + } + } + + public override void focus (bool focus) { + has_focus = focus; + } + } }
--- a/libbirdfont/DescriptionDisplay.vala +++ b/libbirdfont/DescriptionDisplay.vala @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Johan Mattsson + Copyright (C) 2014 2015 Johan Mattsson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -22,8 +22,10 @@ double scroll = 0; double content_height = 1; WidgetAllocation allocation; + Gee.ArrayList<Widget> focus_ring = new Gee.ArrayList<Widget> (); + int focus_index = 0; - TextArea? keyboard_focus = null; + Widget? keyboard_focus = null; TextArea postscript_name; TextArea name; @@ -74,6 +76,7 @@ font.touch (); }); widgets.add (postscript_name); + focus_ring.add (postscript_name); widgets.add (new Text (t_("Name"), label_size, label_margin)); name.margin_bottom = margin; @@ -83,7 +86,8 @@ font.touch (); }); widgets.add (name); - + focus_ring.add (name); + widgets.add (new Text (t_("Style"), label_size, label_margin)); style.margin_bottom = 1.5 * margin; style.set_text (font.subfamily); @@ -92,6 +96,7 @@ font.touch (); }); widgets.add (style); + focus_ring.add (style); bold = new CheckBox (t_("Bold"), label_size); bold.updated.connect ((c) => { @@ -100,6 +105,7 @@ }); bold.checked = font.bold; widgets.add (bold); + focus_ring.add (bold); italic = new CheckBox (t_("Italic"), label_size); italic.updated.connect ((c) => { @@ -109,6 +115,7 @@ italic.checked = font.italic; italic.margin_bottom = margin; widgets.add (italic); + focus_ring.add (italic); widgets.add (new Text (t_("Weight"), label_size, label_margin)); weight.margin_bottom = margin; @@ -118,6 +125,7 @@ font.touch (); }); widgets.add (weight); + focus_ring.add (weight); widgets.add (new Text (t_("Full Name (Name and Style)"), label_size, label_margin)); full_name.margin_bottom = margin; @@ -127,6 +135,7 @@ font.touch (); }); widgets.add (full_name); + focus_ring.add (full_name); widgets.add (new Text (t_("Unique Identifier"), label_size, label_margin)); unique_id.margin_bottom = margin; @@ -136,6 +145,7 @@ font.touch (); }); widgets.add (unique_id); + focus_ring.add (unique_id); widgets.add (new Text (t_("Version"), label_size, label_margin)); version.margin_bottom = margin; @@ -145,6 +155,7 @@ font.touch (); }); widgets.add (version); + focus_ring.add (version); widgets.add (new Text (t_("Description"), label_size, label_margin)); description.margin_bottom = margin; @@ -155,6 +166,7 @@ font.touch (); }); widgets.add (description); + focus_ring.add (description); widgets.add (new Text (t_("Copyright"), label_size, label_margin)); copyright.margin_bottom = margin; @@ -166,6 +178,9 @@ }); copyright.set_editable (!disable_copyright); widgets.add (copyright); + focus_ring.add (copyright); + + set_focus (postscript_name); } public static void set_copyright_editable (bool t) { @@ -228,19 +243,43 @@ } public override void key_press (uint keyval) { - TextArea focus; + Widget focus; + + if (keyval == Key.SHIFT_TAB) { + focus_previous (); + } else if (keyval == Key.TAB) { + focus_next (); + } else if (keyboard_focus != null) { + focus = (!) keyboard_focus; + focus.key_press (keyval); + } + + GlyphCanvas.redraw (); + } + + void focus_previous () { + focus_index--; - if (keyboard_focus == null) { - return; + if (focus_index < 0) { + focus_index = 0; } - focus = (!) keyboard_focus; - focus.key_press (keyval); + set_focus (focus_ring.get (focus_index)); + } + + void focus_next () { + focus_index++; + + if (focus_index >= focus_ring.size) { + focus_index = focus_ring.size - 1; + } + + set_focus (focus_ring.get (focus_index)); } public override void button_press (uint button, double x, double y) { - TextArea t; - TextArea old; + Widget t; + Widget old; CheckBox c; foreach (Widget w in widgets) { @@ -249,12 +288,11 @@ t = (TextArea) w; if (keyboard_focus != null && (!) keyboard_focus != t) { old = (!) keyboard_focus; - old.draw_carret = false; + old.focus (false); } - t.draw_carret = true; + set_focus (t); t.button_press (button, x, y); - keyboard_focus = t; } else if (w is CheckBox) { c = (CheckBox) w; c.set_checked (!c.checked); @@ -263,13 +301,32 @@ } GlyphCanvas.redraw (); + } + + public void set_focus (Widget w) { + Widget old; + + if (keyboard_focus != null && (!) keyboard_focus != w) { + old = (!) keyboard_focus; + old.focus (false); + } + + keyboard_focus = w; + w.focus (true); + + focus_index = focus_ring.index_of (w); + + if (!(0 <= focus_index < focus_ring.size)) { + focus_index = 0; + } } public override void button_release (int button, double x, double y) { - TextArea t; + Widget t; if (keyboard_focus != null) { t = (!) keyboard_focus; + set_focus (t); t.button_release (button, x, y); } @@ -277,7 +334,7 @@ } public override void motion_notify (double x, double y) { - TextArea t; + Widget t; if (keyboard_focus != null) { t = (!) keyboard_focus;
--- a/libbirdfont/Dialog.vala +++ b/libbirdfont/Dialog.vala @@ -33,12 +33,9 @@ public override double get_width () { return 0; - } - - public virtual void button_press (uint button, double x, double y) { } } }
--- a/libbirdfont/KeyBindings.vala +++ b/libbirdfont/KeyBindings.vala @@ -36,6 +36,7 @@ LOGO_RIGHT = 65516, CONTEXT_MENU = 65383, TAB = 65289, + SHIFT_TAB = 65056, DEL = 65535, NUM_PLUS = 65451, NUM_MINUS = 65453,
--- a/libbirdfont/MoveTool.vala +++ b/libbirdfont/MoveTool.vala @@ -61,7 +61,7 @@ }); key_press_action.connect ((self, keyval) => { - key_press (keyval); + key_down (keyval); }); draw_action.connect ((self, cr, glyph) => { @@ -75,7 +75,7 @@ } } - public void key_press (uint32 keyval) { + public void key_down (uint32 keyval) { Glyph g = MainWindow.get_current_glyph (); // delete selected paths
--- a/libbirdfont/Renderer/TextArea.vala +++ b/libbirdfont/Renderer/TextArea.vala @@ -70,6 +70,10 @@ width = min_width; height = min_height; editable = true; + } + + public override void focus (bool focus) { + draw_carret = focus; } public override double get_height () { @@ -114,7 +118,7 @@ } } - public void key_press (uint keyval) { + public override void key_press (uint keyval) { unichar c; TextUndoItem ui; @@ -994,7 +998,7 @@ } } - public void button_press (uint button, double x, double y) { + public override void button_press (uint button, double x, double y) { if (is_over (x, y)) { carret = get_carret_at (x, y); selection_end = carret.copy (); @@ -1002,12 +1006,12 @@ } } - public void button_release (uint button, double x, double y) { + public override void button_release (uint button, double x, double y) { update_selection = false; show_selection = selection_is_visible (); } - public bool motion (double x, double y) { + public override bool motion (double x, double y) { if (update_selection) { selection_end = get_carret_at (x, y); show_selection = selection_is_visible ();
--- a/libbirdfont/Widget.vala +++ b/libbirdfont/Widget.vala @@ -52,8 +52,24 @@ return (widget_y <= 0 <= widget_y + get_height ()) || (widget_y <= allocation.height <= widget_y + get_height ()) || (0 <= widget_y <= allocation.height); + } + + public virtual void key_press (uint keyval) { + } + + public virtual void focus (bool enter) { + } + + public virtual void button_press (uint button, double x, double y) { + } + + public virtual void button_release (uint button, double x, double y) { + } + + public virtual bool motion (double x, double y) { + return false; } } }