From c4b3a0aaaa312a9354e968274fd9ec65c7c39710 Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Fri, 16 Aug 2019 13:34:54 +0000 Subject: [PATCH] row: Moved button sizing closer to row --- eek/eek-gtk-keyboard.c | 1 - eek/eek-keyboard.c | 1 - eek/eek-layout.c | 2 +- eek/eek-renderer.c | 1 - eek/eek-section.c | 14 ------------ eek/eek-section.h | 2 -- eek/eek-xml-layout.c | 1 - eek/eek.h | 1 - src/layout.h | 2 +- src/layout.rs | 48 ++++++++++++++++++++++++------------------ 10 files changed, 30 insertions(+), 43 deletions(-) diff --git a/eek/eek-gtk-keyboard.c b/eek/eek-gtk-keyboard.c index 2c3e772f..053bf727 100644 --- a/eek/eek-gtk-keyboard.c +++ b/eek/eek-gtk-keyboard.c @@ -34,7 +34,6 @@ #include "eek-renderer.h" #include "eek-keyboard.h" -#include "eek-section.h" #include "src/symbol.h" #include "eek-gtk-keyboard.h" diff --git a/eek/eek-keyboard.c b/eek/eek-keyboard.c index 3743c922..0b57214e 100644 --- a/eek/eek-keyboard.c +++ b/eek/eek-keyboard.c @@ -30,7 +30,6 @@ #include "config.h" #include -#include "eek-section.h" #include "eek-enumtypes.h" #include "eekboard/key-emitter.h" #include "keymap.h" diff --git a/eek/eek-layout.c b/eek/eek-layout.c index ac70aa87..e83086d0 100644 --- a/eek/eek-layout.c +++ b/eek/eek-layout.c @@ -70,7 +70,7 @@ row_placer(gpointer item, gpointer user_data) squeek_row_set_bounds(row, row_bounds); // Gather up all the keys in a row and adjust their bounds. - eek_row_place_buttons(row, data->keyboard); + squeek_row_place_buttons(row, data->keyboard); row_bounds = squeek_row_get_bounds(row); row_bounds.y = data->current_offset; diff --git a/eek/eek-renderer.c b/eek/eek-renderer.c index cba96207..67cd3071 100644 --- a/eek/eek-renderer.c +++ b/eek/eek-renderer.c @@ -24,7 +24,6 @@ #include #include -#include "eek-section.h" #include "src/symbol.h" #include "eek-renderer.h" diff --git a/eek/eek-section.c b/eek/eek-section.c index a0533c70..d1dcf951 100644 --- a/eek/eek-section.c +++ b/eek/eek-section.c @@ -54,17 +54,3 @@ EekBounds eek_get_outline_size(LevelKeyboard *keyboard, uint32_t oref) { EekBounds bounds = {0, 0, 0, 0}; return bounds; } - -void -eek_row_place_buttons(struct squeek_row *row, LevelKeyboard *keyboard) -{ - EekBounds row_size = squeek_row_place_keys(row, keyboard); - EekBounds row_bounds = squeek_row_get_bounds(row); - // FIXME: do centering of each row based on keyboard dimensions, - // one level up the iterators - // now centering by comparing previous width to the new, calculated one - row_bounds.x = (row_bounds.width - row_size.width) / 2; - row_bounds.width = row_size.width; - row_bounds.height = row_size.height; - squeek_row_set_bounds(row, row_bounds); -} diff --git a/eek/eek-section.h b/eek/eek-section.h index 58460e4f..8d9076c7 100644 --- a/eek/eek-section.h +++ b/eek/eek-section.h @@ -31,6 +31,4 @@ #include "eek-keyboard.h" #include "src/layout.h" -void -eek_row_place_buttons(struct squeek_row *row, LevelKeyboard *keyboard); #endif /* EEK_SECTION_H */ diff --git a/eek/eek-xml-layout.c b/eek/eek-xml-layout.c index b45db93a..634a59b1 100644 --- a/eek/eek-xml-layout.c +++ b/eek/eek-xml-layout.c @@ -28,7 +28,6 @@ #include #include "eek-keyboard.h" -#include "eek-section.h" #include "src/keyboard.h" #include "src/symbol.h" diff --git a/eek/eek.h b/eek/eek.h index 1b788273..965f7a70 100644 --- a/eek/eek.h +++ b/eek/eek.h @@ -23,7 +23,6 @@ #define __EEK_H_INSIDE__ 1 #include "eek-keyboard.h" -#include "eek-section.h" #include "eek-layout.h" #include "eek-keysym.h" diff --git a/src/layout.h b/src/layout.h index 9ec625b3..3b46ae08 100644 --- a/src/layout.h +++ b/src/layout.h @@ -55,5 +55,5 @@ uint32_t *squeek_button_has_key(const struct squeek_button* button, void squeek_button_print(const struct squeek_button* button); -EekBounds squeek_row_place_keys(struct squeek_row *row, LevelKeyboard *keyboard); +void squeek_row_place_buttons(struct squeek_row *row, LevelKeyboard *keyboard); #endif diff --git a/src/layout.rs b/src/layout.rs index e4cc5c79..fbbedcbb 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -274,30 +274,35 @@ pub mod c { const BUTTON_SPACING: f64 = 4.0; + fn squeek_buttons_get_outlines( + buttons: &Vec>, + keyboard: *const LevelKeyboard, + ) -> Vec { + buttons.iter().map(|button| { + unsafe { eek_get_outline_size(keyboard, button.oref.0) } + }).collect() + } + /// Places each button in order, starting from 0 on the left, /// keeping the spacing. /// Sizes each button according to outline dimensions. - /// Returns the width and height of the resulting row. + /// Sets the row size correctly #[no_mangle] pub extern "C" - fn squeek_row_place_keys( + fn squeek_row_place_buttons( row: *mut ::layout::Row, keyboard: *const LevelKeyboard, - ) -> Bounds { + ) { let row = unsafe { &mut *row }; - + // Size buttons - for mut button in &mut row.buttons { - button.bounds = Some( - unsafe { eek_get_outline_size(keyboard, button.oref.0) } - ); + let sizes = squeek_buttons_get_outlines(&row.buttons, keyboard); + + for (mut button, bounds) in &mut row.buttons.iter_mut().zip(sizes) { + button.bounds = Some(bounds); } - + // Place buttons - let cumulative_width: f64 = row.buttons.iter().map( - |button| button.bounds.as_ref().unwrap().width - ).sum(); - let max_height = row.buttons.iter().map( |button| FloatOrd( button.bounds.as_ref().unwrap().height @@ -311,8 +316,7 @@ pub mod c { bounds.x = acc; acc + bounds.width + BUTTON_SPACING }); - - // Total size + let total_width = match row.buttons.is_empty() { true => 0f64, false => { @@ -321,13 +325,17 @@ pub mod c { bounds.x + bounds.width }, }; - - Bounds { - x: 0f64, - y: 0f64, + + let old_row_bounds = row.bounds.as_ref().unwrap().clone(); + row.bounds = Some(Bounds { + // FIXME: do centering of each row based on keyboard dimensions, + // one level up the iterators + // now centering by comparing previous width to the new, calculated one + x: (old_row_bounds.width - total_width) / 2f64, width: total_width, height: max_height, - } + ..old_row_bounds + }); } /// Finds a button sharing this state