layout: Using bigger keys
This commit is contained in:
		@ -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;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -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.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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 */
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user