summaryrefslogtreecommitdiff
path: root/libcaribou
diff options
context:
space:
mode:
authorEitan Isaacson <eitan@monotonous.org>2011-06-15 15:05:30 -0700
committerEitan Isaacson <eitan@monotonous.org>2011-06-22 11:23:21 -0700
commit0fc37c5a73d96400ffe8997399224fa831c7009b (patch)
tree066eeb3b66ebaf7d0af394a822238b8f46513b2e /libcaribou
parentf735e635ed282a18814857371ccf1baa236e0d18 (diff)
downloadcaribou-0fc37c5a73d96400ffe8997399224fa831c7009b.tar.gz
abolish margin and use align
Diffstat (limited to 'libcaribou')
-rw-r--r--libcaribou/key-model.vala2
-rw-r--r--libcaribou/level-model.vala19
-rw-r--r--libcaribou/row-model.vala19
-rw-r--r--libcaribou/xml-deserializer.vala41
4 files changed, 32 insertions, 49 deletions
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<RowModel> ();
}
- 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<ColumnModel> ();
}
- 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;