From b8eb7752e72a8fa3a4f37b9081d0a1578f285208 Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Mon, 1 Jul 2019 09:31:42 +0000 Subject: [PATCH] layout: Using bigger keys --- data/keyboards/geometry/compact.xml | 9 ++++++ eek/eek-key.c | 2 +- eek/eek-keyboard.h | 2 ++ eek/eek-section.c | 46 ++++++++++++++++++++++++++++- eek/eek-section.h | 2 ++ eek/eek-types.h | 2 +- eek/eek-xml-layout.c | 34 +++++++++++++++++++-- 7 files changed, 92 insertions(+), 5 deletions(-) diff --git a/data/keyboards/geometry/compact.xml b/data/keyboards/geometry/compact.xml index c09df0e9..8ab5bae1 100644 --- a/data/keyboards/geometry/compact.xml +++ b/data/keyboards/geometry/compact.xml @@ -35,6 +35,9 @@ + +
+ @@ -64,6 +67,9 @@ +
+
+ @@ -93,6 +99,9 @@ +
+
+ diff --git a/eek/eek-key.c b/eek/eek-key.c index f58da112..a3cada98 100644 --- a/eek/eek-key.c +++ b/eek/eek-key.c @@ -66,7 +66,7 @@ struct _EekKeyPrivate EekSymbolMatrix *symbol_matrix; gint column; gint row; - gulong oref; + gulong oref; // UI outline reference gboolean is_pressed; gboolean is_locked; }; diff --git a/eek/eek-keyboard.h b/eek/eek-keyboard.h index 8759f077..afe72c27 100644 --- a/eek/eek-keyboard.h +++ b/eek/eek-keyboard.h @@ -48,6 +48,8 @@ typedef struct _EekKeyboardPrivate EekKeyboardPrivate; * * Contains the state of the physical keyboard. * + * Is also a graphical element... + * * The #EekKeyboard structure contains only private data and should * only be accessed using the provided API. */ diff --git a/eek/eek-section.c b/eek/eek-section.c index cec1fd99..8b40d7f4 100644 --- a/eek/eek-section.c +++ b/eek/eek-section.c @@ -129,7 +129,7 @@ static EekKey * eek_section_real_create_key (EekSection *self, guint keycode, gint column_index, - gint row_index) + guint row_index) { EekKey *key; gint num_rows; @@ -479,3 +479,47 @@ eek_section_create_key (EekSection *section, column, row); } + +struct keys_info { + uint count; + double total_width; + double biggest_height; +}; + +static void keycounter (EekElement *element, gpointer user_data) { + struct keys_info *data = user_data; + data->count++; + EekBounds key_bounds = {0}; + eek_element_get_bounds(element, &key_bounds); + data->total_width += key_bounds.width; + if (key_bounds.height > data->biggest_height) { + data->biggest_height = key_bounds.height; + } +} + +const double keyspacing = 2.0; + +static void keyplacer(EekElement *element, gpointer user_data) { + double *current_offset = user_data; + EekBounds key_bounds = {0}; + eek_element_get_bounds(element, &key_bounds); + key_bounds.x = *current_offset; + key_bounds.y = 0; + eek_element_set_bounds(element, &key_bounds); + *current_offset += key_bounds.width + keyspacing; +} + +void eek_section_place_keys(EekSection *section) +{ + 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); + + section_bounds.height = keyinfo.biggest_height; + eek_element_set_bounds(EEK_ELEMENT(section), §ion_bounds); +} diff --git a/eek/eek-section.h b/eek/eek-section.h index 6392cdb2..b15262d8 100644 --- a/eek/eek-section.h +++ b/eek/eek-section.h @@ -127,5 +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); + G_END_DECLS #endif /* EEK_SECTION_H */ diff --git a/eek/eek-types.h b/eek/eek-types.h index 5bf73aec..015b9a90 100644 --- a/eek/eek-types.h +++ b/eek/eek-types.h @@ -214,7 +214,7 @@ struct _EekOutline /*< public >*/ gdouble corner_radius; EekPoint *points; - gint num_points; + guint num_points; }; GType eek_outline_get_type (void) G_GNUC_CONST; diff --git a/eek/eek-xml-layout.c b/eek/eek-xml-layout.c index 454dd508..a11a0bdb 100644 --- a/eek/eek-xml-layout.c +++ b/eek/eek-xml-layout.c @@ -504,13 +504,14 @@ geometry_end_element_callback (GMarkupParseContext *pcontext, { GeometryParseData *data = user_data; GSList *head = data->element_stack; - gint i; g_free (head->data); data->element_stack = g_slist_next (data->element_stack); 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; @@ -536,7 +537,8 @@ geometry_end_element_callback (GMarkupParseContext *pcontext, outline->num_points = g_slist_length (data->points); outline->points = g_slice_alloc0 (sizeof (EekPoint) * outline->num_points); - for (head = data->points = g_slist_reverse (data->points), i = 0; + guint i; + for (i = 0, head = data->points = g_slist_reverse (data->points); head && i < outline->num_points; head = g_slist_next (head), i++) { memcpy (&outline->points[i], head->data, sizeof (EekPoint)); @@ -1136,6 +1138,22 @@ eek_xml_keyboard_desc_free (EekXmlKeyboardDesc *desc) g_slice_free (EekXmlKeyboardDesc, desc); } +static void section_placer(EekElement *element, gpointer user_data) { + double *current_offset = user_data; + EekBounds section_bounds = {0}; + eek_element_get_bounds(element, §ion_bounds); + section_bounds.y = *current_offset; + eek_element_set_bounds(element, §ion_bounds); + *current_offset += section_bounds.height; +} + +static void section_counter(EekElement *element, gpointer user_data) { + double *total_height = user_data; + EekBounds section_bounds = {0}; + eek_element_get_bounds(element, §ion_bounds); + *total_height += section_bounds.height + 2.0; +} + static gboolean parse_geometry (const gchar *path, EekKeyboard *keyboard, GError **error) { @@ -1169,6 +1187,18 @@ 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);