row: Moved button sizing closer to row

This commit is contained in:
Dorota Czaplejewicz
2019-08-16 13:34:54 +00:00
parent de9c93610b
commit c4b3a0aaaa
10 changed files with 30 additions and 43 deletions

View File

@ -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"

View File

@ -30,7 +30,6 @@
#include "config.h"
#include <glib/gprintf.h>
#include "eek-section.h"
#include "eek-enumtypes.h"
#include "eekboard/key-emitter.h"
#include "keymap.h"

View File

@ -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;

View File

@ -24,7 +24,6 @@
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "eek-section.h"
#include "src/symbol.h"
#include "eek-renderer.h"

View File

@ -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);
}

View File

@ -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 */

View File

@ -28,7 +28,6 @@
#include <string.h>
#include "eek-keyboard.h"
#include "eek-section.h"
#include "src/keyboard.h"
#include "src/symbol.h"

View File

@ -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"

View File

@ -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

View File

@ -274,30 +274,35 @@ pub mod c {
const BUTTON_SPACING: f64 = 4.0;
fn squeek_buttons_get_outlines(
buttons: &Vec<Box<Button>>,
keyboard: *const LevelKeyboard,
) -> Vec<Bounds> {
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