.
1 /*
2 Copyright (C) 2014 Johan Mattsson
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 3 of the
7 License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13 */
14 using Cairo;
15 using Math;
16
17 namespace BirdFont {
18
19 public class SpacingClassTab : Table {
20
21 public static int NEW_CLASS = -1;
22 Gee.ArrayList<Row> rows = new Gee.ArrayList<Row> ();
23
24 public SpacingClassTab () {
25 }
26
27 public override Gee.ArrayList<Row> get_rows () {
28 return rows;
29 }
30
31 public override void selected_row (Row row, int column, bool delete_button) {
32 Font font = BirdFont.get_current_font ();
33 SpacingData spacing = font.get_spacing ();
34
35 if (row.get_index () == -1) {
36 spacing.add_class ("?", "?");
37 TabContent.hide_text_input ();
38 update_rows ();
39 update_scrollbar ();
40 font.touch ();
41 } else if (spacing.classes.size != 0) {
42 if (delete_button) {
43 return_if_fail (0 <= row.get_index () < spacing.classes.size);
44 spacing.classes.remove_at (row.get_index ());
45 TabContent.hide_text_input ();
46 update_rows ();
47 update_scrollbar ();
48 font.touch ();
49 } else if (column == 0) {
50 if (!(0 <= row.get_index () < spacing.classes.size)) {
51 warning (@"Index: $(row.get_index ()) classes.size: $(spacing.classes.size)");
52 return;
53 }
54 spacing.classes.get (row.get_index ()).set_first ();
55 font.touch ();
56 } else if (column == 2) {
57 return_if_fail (0 <= row.get_index () < spacing.classes.size);
58 spacing.classes.get (row.get_index ()).set_next ();
59 font.touch ();
60 }
61 }
62 }
63
64 public override void update_rows () {
65 int i = 0;
66 SpacingData spacing = BirdFont.get_current_font ().get_spacing ();
67
68 rows.clear ();
69 rows.add (new Row (t_("New spacing class"), NEW_CLASS, false));
70
71 foreach (SpacingClass c in spacing.classes) {
72 rows.add (new Row.columns_3 (@"$(c.first)", "->", @"$(c.next)", i));
73 i++;
74 }
75
76 GlyphCanvas.redraw ();
77 }
78
79 public override string get_label () {
80 return t_("Spacing Classes");
81 }
82
83 public override string get_name () {
84 return "SpacingClasses";
85 }
86 }
87
88 }
89