The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Fix color in character set selection

These changes was commited to the Birdfont repository Sat, 09 May 2015 10:02:08 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sat, 09 May 2015 10:02:08 +0000]

Updated Files

libbirdfont/LanguageSelectionTab.vala
--- a/libbirdfont/LanguageSelectionTab.vala +++ b/libbirdfont/LanguageSelectionTab.vala @@ -16,14 +16,32 @@ namespace BirdFont { - public class LanguageSelectionTab : FontDisplay { - - int scroll = 0; - int visible_rows = 0; - WidgetAllocation allocation; + public class LanguageSelectionTab : Table { public LanguageSelectionTab () { - allocation = new WidgetAllocation (); + } + + public override Gee.ArrayList<Row> get_rows () { + Gee.ArrayList<Row> rows = new Gee.ArrayList<Row> (); + int i = 0; + + rows.add (new Row.headline (t_("Character Sets"))); + + foreach (string language in DefaultLanguages.names) { + Row r = new Row.columns_1 (language, i, false); + rows.add (r); + i++; + } + + return rows; + } + + public override void update_rows () { + redraw_area (0, 0, allocation.width, allocation.height); + } + + public override void selected_row (Row row, int column, bool delete_button) { + select_language (row.get_index ()); } void select_language (int row) { @@ -36,125 +54,16 @@ Preferences.set ("language", iso_code); tb.close_display (this); Toolbox.select_tool_by_name ("custom_character_set"); - } - - public override void button_release (int button, double ex, double ey) { - int r = (int) rint ((ey - 17) / 18.0); - if (button == 1 && 0 <= r < DefaultLanguages.codes.size) { - select_language (r + scroll); - } } - public override void draw (WidgetAllocation allocation, Context cr) { - int y = 20; - int s = 0; - bool color = (scroll % 2) == 0; - - this.allocation = allocation; - - visible_rows = (int) (allocation.height / 18.0); - - cr.save (); - Theme.color (cr, "Table Background 1"); - cr.rectangle (0, 0, allocation.width, allocation.height); - cr.fill (); - cr.restore (); - - cr.save (); - Theme.color (cr, "Table Background 2"); - cr.set_font_size (12); - - foreach (string language in DefaultLanguages.names) { - if (s++ >= scroll) { - draw_row (allocation, cr, language, color, y); - y += 18; - color = !color; - } - } - cr.restore (); - } - - private static void draw_row (WidgetAllocation allocation, Context cr, string language, bool color, double y) { - - if (color) { - cr.save (); - Theme.color (cr, "Table Background 2"); - cr.rectangle (0, y - 14, allocation.width, 18); - cr.fill (); - cr.restore (); - } - - cr.move_to (30, y); - cr.show_text (language); - } - public override string get_label () { return t_("Character Set"); } public override string get_name () { return "Character Set"; - } - - public override bool has_scrollbar () { - return true; - } - - public override void scroll_wheel_down (double x, double y) { - uint rows = DefaultLanguages.names.size; - scroll += 3; - - if (scroll + visible_rows > rows) { - scroll = (int) (rows - visible_rows); - } - - if (scroll < 0) { - scroll = 0; - } - - update_scrollbar (); - redraw_area (0, 0, allocation.width, allocation.height); - } - - public override void scroll_wheel_up (double x, double y) { - scroll -= 3; - - if (scroll < 0) { - scroll = 0; - } - - update_scrollbar (); - redraw_area (0, 0, allocation.width, allocation.height); - } - - public override void selected_canvas () { - update_scrollbar (); - redraw_area (0, 0, allocation.width, allocation.height); - } - - public override void update_scrollbar () { - uint rows = DefaultLanguages.names.size; - - if (rows == 0 || visible_rows == 0) { - MainWindow.set_scrollbar_size (0); - MainWindow.set_scrollbar_position (0); - } else { - MainWindow.set_scrollbar_size ((double) visible_rows / rows); - MainWindow.set_scrollbar_position ((double) scroll / rows); - } - } - - public override void scroll_to (double percent) { - uint rows = DefaultLanguages.names.size; - scroll = (int) (percent * rows); - - if (scroll > rows - visible_rows) { - scroll = (int) (rows - visible_rows); - } - - redraw_area (0, 0, allocation.width, allocation.height); } } }