diff --git a/data/keyboards/geometry/compact.xml b/data/keyboards/geometry/compact.xml index 8ab5bae1..0b32961a 100644 --- a/data/keyboards/geometry/compact.xml +++ b/data/keyboards/geometry/compact.xml @@ -71,7 +71,7 @@
- + @@ -95,7 +95,7 @@ - + @@ -103,13 +103,13 @@
- + - + - + @@ -126,7 +126,7 @@ - + @@ -180,10 +180,10 @@ - + - - + + diff --git a/eek/eek-section.c b/eek/eek-section.c index 8b40d7f4..cf1a0d65 100644 --- a/eek/eek-section.c +++ b/eek/eek-section.c @@ -480,6 +480,38 @@ eek_section_create_key (EekSection *section, row); } +static void keysizer(EekElement *element, gpointer user_data) { + EekKey *key = EEK_KEY(element); + EekKeyboard *keyboard = EEK_KEYBOARD(user_data); + uint oref = eek_key_get_oref (key); + EekOutline *outline = eek_keyboard_get_outline (keyboard, oref); + if (outline && outline->num_points > 0) { + double minx = outline->points[0].x; + double maxx = minx; + double miny = outline->points[0].y; + double maxy = miny; + for (uint i = 1; i < outline->num_points; i++) { + EekPoint p = outline->points[i]; + if (p.x < minx) { + minx = p.x; + } else if (p.x > maxx) { + maxx = p.x; + } + + if (p.y < miny) { + miny = p.y; + } else if (p.y > maxy) { + maxy = p.y; + } + } + EekBounds key_bounds = {0}; + eek_element_get_bounds(element, &key_bounds); + key_bounds.height = maxy - miny; + key_bounds.width = maxx - minx; + eek_element_set_bounds(element, &key_bounds); + } +} + struct keys_info { uint count; double total_width; @@ -509,14 +541,15 @@ static void keyplacer(EekElement *element, gpointer user_data) { *current_offset += key_bounds.width + keyspacing; } -void eek_section_place_keys(EekSection *section) +void eek_section_place_keys(EekSection *section, EekKeyboard *keyboard) { + eek_container_foreach_child(EEK_CONTAINER(section), keysizer, keyboard); + struct keys_info keyinfo = {0}; eek_container_foreach_child(EEK_CONTAINER(section), keycounter, &keyinfo); EekBounds section_bounds = {0}; eek_element_get_bounds(EEK_ELEMENT(section), §ion_bounds); - // FIXME: find a way to center buttons double key_offset = (section_bounds.width - (keyinfo.total_width + (keyinfo.count - 1) * keyspacing)) / 2; eek_container_foreach_child(EEK_CONTAINER(section), keyplacer, &key_offset); diff --git a/eek/eek-section.h b/eek/eek-section.h index b15262d8..77694a49 100644 --- a/eek/eek-section.h +++ b/eek/eek-section.h @@ -127,7 +127,7 @@ EekKey *eek_section_create_key (EekSection *section, EekKey *eek_section_find_key_by_keycode (EekSection *section, guint keycode); -void eek_section_place_keys (EekSection *section); +void eek_section_place_keys (EekSection *section, EekKeyboard *keyboard); G_END_DECLS #endif /* EEK_SECTION_H */ diff --git a/eek/eek-xml-layout.c b/eek/eek-xml-layout.c index a11a0bdb..0dacd93c 100644 --- a/eek/eek-xml-layout.c +++ b/eek/eek-xml-layout.c @@ -510,8 +510,6 @@ geometry_end_element_callback (GMarkupParseContext *pcontext, g_slist_free1 (head); if (g_strcmp0 (element_name, "section") == 0) { - // Sections are rows now. Gather up all the keys and adjust their bounds. - eek_section_place_keys(data->section); data->section = NULL; data->num_rows = 0; return; @@ -1138,13 +1136,22 @@ eek_xml_keyboard_desc_free (EekXmlKeyboardDesc *desc) g_slice_free (EekXmlKeyboardDesc, desc); } +struct place_data { + double current_offset; + EekKeyboard *keyboard; +}; + static void section_placer(EekElement *element, gpointer user_data) { - double *current_offset = user_data; + struct place_data *data = user_data; + + // Sections are rows now. Gather up all the keys and adjust their bounds. + eek_section_place_keys(EEK_SECTION(element), EEK_KEYBOARD(data->keyboard)); + EekBounds section_bounds = {0}; eek_element_get_bounds(element, §ion_bounds); - section_bounds.y = *current_offset; + section_bounds.y = data->current_offset; eek_element_set_bounds(element, §ion_bounds); - *current_offset += section_bounds.height; + data->current_offset += section_bounds.height; } static void section_counter(EekElement *element, gpointer user_data) { @@ -1187,18 +1194,6 @@ parse_geometry (const gchar *path, EekKeyboard *keyboard, GError **error) return FALSE; } - /* Order rows */ - // TODO: do this only for rows without bounds - double current_offset = 0; - eek_container_foreach_child(EEK_CONTAINER(keyboard), section_placer, ¤t_offset); - - double total_height = 0; - eek_container_foreach_child(EEK_CONTAINER(keyboard), section_counter, &total_height); - EekBounds keyboard_bounds = {0}; - eek_element_get_bounds(EEK_ELEMENT(keyboard), &keyboard_bounds); - keyboard_bounds.height = total_height; - eek_element_set_bounds(EEK_ELEMENT(keyboard), &keyboard_bounds); - /* Resolve outline references. */ oref_hash = g_hash_table_new (g_str_hash, g_str_equal); g_hash_table_iter_init (&iter, data->oref_outline_hash); @@ -1218,6 +1213,22 @@ parse_geometry (const gchar *path, EekKeyboard *keyboard, GError **error) } g_hash_table_destroy (oref_hash); + /* Order rows */ + // This needs to be done after outlines, because outlines define key sizes + // TODO: do this only for rows without bounds + struct place_data placer_data = { + .current_offset = 0, + .keyboard = keyboard, + }; + eek_container_foreach_child(EEK_CONTAINER(keyboard), section_placer, &placer_data); + + double total_height = 0; + eek_container_foreach_child(EEK_CONTAINER(keyboard), section_counter, &total_height); + EekBounds keyboard_bounds = {0}; + eek_element_get_bounds(EEK_ELEMENT(keyboard), &keyboard_bounds); + keyboard_bounds.height = total_height; + eek_element_set_bounds(EEK_ELEMENT(keyboard), &keyboard_bounds); + geometry_parse_data_free (data); return TRUE; }