From 0fc37c5a73d96400ffe8997399224fa831c7009b Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Wed, 15 Jun 2011 15:05:30 -0700 Subject: abolish margin and use align --- libcaribou/key-model.vala | 2 +- libcaribou/level-model.vala | 19 +++---------------- libcaribou/row-model.vala | 19 +++---------------- libcaribou/xml-deserializer.vala | 41 ++++++++++++++++++++++++---------------- 4 files changed, 32 insertions(+), 49 deletions(-) (limited to 'libcaribou') diff --git a/libcaribou/key-model.vala b/libcaribou/key-model.vala index da90c4f..7153bc6 100644 --- a/libcaribou/key-model.vala +++ b/libcaribou/key-model.vala @@ -2,7 +2,7 @@ using GLib; namespace Caribou { public class KeyModel : GLib.Object, IScannableItem, IKeyboardObject { - public double margin_left { get; set; default = 0.0; } + public string align { get; set; default = "center"; } public double width { get; set; default = 1.0; } public string toggle { get; set; default = ""; } diff --git a/libcaribou/level-model.vala b/libcaribou/level-model.vala index 0d209d3..981a3c0 100644 --- a/libcaribou/level-model.vala +++ b/libcaribou/level-model.vala @@ -12,22 +12,9 @@ namespace Caribou { rows = new Gee.ArrayList (); } - internal void add_key (int rownum, int colnum, KeyModel key) { - int rowindex = rownum; - RowModel row = null; - - if (rownum < 0) - rowindex = rows.size + rownum; - - if (rownum >= rows.size) { - row = new RowModel (); - row.key_activated.connect (on_key_activated); - rows.add(row); - } else { - row = rows[rowindex]; - } - - row.add_key (colnum, key); + internal void add_row (RowModel row) { + row.key_activated.connect (on_key_activated); + rows.add(row); } public RowModel[] get_rows () { diff --git a/libcaribou/row-model.vala b/libcaribou/row-model.vala index 7aac08e..fcc4713 100644 --- a/libcaribou/row-model.vala +++ b/libcaribou/row-model.vala @@ -9,22 +9,9 @@ namespace Caribou { columns = new Gee.ArrayList (); } - internal void add_key (int colnum, KeyModel key) { - int colindex = colnum; - ColumnModel column = null; - - if (colnum < 0) - colindex = columns.size + colnum; - - if (colnum >= columns.size) { - column = new ColumnModel (); - column.key_activated.connect ((k) => { key_activated (k); }); - columns.add(column); - } else { - column = columns[colindex]; - } - - column.add_key (key); + internal void add_column (ColumnModel column) { + column.key_activated.connect ((k) => { key_activated (k); }); + columns.add(column); } public ColumnModel[] get_columns () { diff --git a/libcaribou/xml-deserializer.vala b/libcaribou/xml-deserializer.vala index 4656f28..d56e22b 100644 --- a/libcaribou/xml-deserializer.vala +++ b/libcaribou/xml-deserializer.vala @@ -91,34 +91,40 @@ namespace Caribou { public static void load_rows (LevelModel level, Xml.Node* node) { assert (node->name == "level"); - int rownum = 0; for (Xml.Node* i = node->children; i != null; i = i->next) { if (i->type != ElementType.ELEMENT_NODE) continue; - int colnum = 0; + RowModel row = new RowModel (); + level.add_row (row); + for (Xml.Node* i2 = i->children; i2 != null; i2 = i2->next) { - if (i2->name == "key") - level.add_key (rownum, colnum, load_key(i2)); - else if (i2->name == "column") - load_column (level, rownum, colnum++, i2); + if (i2->type != ElementType.ELEMENT_NODE) + continue; + + if (i2->name == "key") { + load_column (row, i->get_prop ("align"), i); + break; + } + + load_column (row, i2->get_prop ("align"), i2); } - rownum++; } } - public static void load_column (LevelModel level, int row, int col, - Xml.Node* node) { - assert (node->name == "column"); + public static void load_column (RowModel row, string? align, Xml.Node* node) { + ColumnModel column = new ColumnModel (); + row.add_column (column); + for (Xml.Node* i = node->children; i != null; i = i->next) { if (i->type != ElementType.ELEMENT_NODE) continue; - - level.add_key (row, col, load_key (i)); + + column.add_key (load_key (i, align)); } } - public static KeyModel load_key (Xml.Node* node) { + public static KeyModel load_key (Xml.Node* node, string? align) { assert (node->name == "key"); string name = node->get_prop ("name"); @@ -126,11 +132,14 @@ namespace Caribou { KeyModel key = new KeyModel (name); + if (align != null) + key.align = align; + for (Attr* prop = node->properties; prop != null; prop = prop->next) { if (prop->name == "toggle") key.toggle = prop->children->content; - else if (prop->name == "margin-left") - key.margin_left = double.parse (prop->children->content); + else if (prop->name == "align") + key.align = prop->children->content; else if (prop->name == "width") key.width = double.parse (prop->children->content); } @@ -139,7 +148,7 @@ namespace Caribou { if (i->type != ElementType.ELEMENT_NODE) continue; - key.add_subkey (load_key (i)); + key.add_subkey (load_key (i, null)); } return key; -- cgit v1.2.1