row: Moved button sizing closer to row
This commit is contained in:
@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
#include "eek-renderer.h"
|
#include "eek-renderer.h"
|
||||||
#include "eek-keyboard.h"
|
#include "eek-keyboard.h"
|
||||||
#include "eek-section.h"
|
|
||||||
#include "src/symbol.h"
|
#include "src/symbol.h"
|
||||||
|
|
||||||
#include "eek-gtk-keyboard.h"
|
#include "eek-gtk-keyboard.h"
|
||||||
|
|||||||
@ -30,7 +30,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <glib/gprintf.h>
|
#include <glib/gprintf.h>
|
||||||
|
|
||||||
#include "eek-section.h"
|
|
||||||
#include "eek-enumtypes.h"
|
#include "eek-enumtypes.h"
|
||||||
#include "eekboard/key-emitter.h"
|
#include "eekboard/key-emitter.h"
|
||||||
#include "keymap.h"
|
#include "keymap.h"
|
||||||
|
|||||||
@ -70,7 +70,7 @@ row_placer(gpointer item, gpointer user_data)
|
|||||||
squeek_row_set_bounds(row, row_bounds);
|
squeek_row_set_bounds(row, row_bounds);
|
||||||
|
|
||||||
// Gather up all the keys in a row and adjust their 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 = squeek_row_get_bounds(row);
|
||||||
row_bounds.y = data->current_offset;
|
row_bounds.y = data->current_offset;
|
||||||
|
|||||||
@ -24,7 +24,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
|
|
||||||
#include "eek-section.h"
|
|
||||||
#include "src/symbol.h"
|
#include "src/symbol.h"
|
||||||
|
|
||||||
#include "eek-renderer.h"
|
#include "eek-renderer.h"
|
||||||
|
|||||||
@ -54,17 +54,3 @@ EekBounds eek_get_outline_size(LevelKeyboard *keyboard, uint32_t oref) {
|
|||||||
EekBounds bounds = {0, 0, 0, 0};
|
EekBounds bounds = {0, 0, 0, 0};
|
||||||
return bounds;
|
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);
|
|
||||||
}
|
|
||||||
|
|||||||
@ -31,6 +31,4 @@
|
|||||||
#include "eek-keyboard.h"
|
#include "eek-keyboard.h"
|
||||||
#include "src/layout.h"
|
#include "src/layout.h"
|
||||||
|
|
||||||
void
|
|
||||||
eek_row_place_buttons(struct squeek_row *row, LevelKeyboard *keyboard);
|
|
||||||
#endif /* EEK_SECTION_H */
|
#endif /* EEK_SECTION_H */
|
||||||
|
|||||||
@ -28,7 +28,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "eek-keyboard.h"
|
#include "eek-keyboard.h"
|
||||||
#include "eek-section.h"
|
|
||||||
#include "src/keyboard.h"
|
#include "src/keyboard.h"
|
||||||
#include "src/symbol.h"
|
#include "src/symbol.h"
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,6 @@
|
|||||||
#define __EEK_H_INSIDE__ 1
|
#define __EEK_H_INSIDE__ 1
|
||||||
|
|
||||||
#include "eek-keyboard.h"
|
#include "eek-keyboard.h"
|
||||||
#include "eek-section.h"
|
|
||||||
#include "eek-layout.h"
|
#include "eek-layout.h"
|
||||||
#include "eek-keysym.h"
|
#include "eek-keysym.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);
|
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
|
#endif
|
||||||
|
|||||||
@ -274,30 +274,35 @@ pub mod c {
|
|||||||
|
|
||||||
const BUTTON_SPACING: f64 = 4.0;
|
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,
|
/// Places each button in order, starting from 0 on the left,
|
||||||
/// keeping the spacing.
|
/// keeping the spacing.
|
||||||
/// Sizes each button according to outline dimensions.
|
/// Sizes each button according to outline dimensions.
|
||||||
/// Returns the width and height of the resulting row.
|
/// Sets the row size correctly
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C"
|
pub extern "C"
|
||||||
fn squeek_row_place_keys(
|
fn squeek_row_place_buttons(
|
||||||
row: *mut ::layout::Row,
|
row: *mut ::layout::Row,
|
||||||
keyboard: *const LevelKeyboard,
|
keyboard: *const LevelKeyboard,
|
||||||
) -> Bounds {
|
) {
|
||||||
let row = unsafe { &mut *row };
|
let row = unsafe { &mut *row };
|
||||||
|
|
||||||
// Size buttons
|
// Size buttons
|
||||||
for mut button in &mut row.buttons {
|
let sizes = squeek_buttons_get_outlines(&row.buttons, keyboard);
|
||||||
button.bounds = Some(
|
|
||||||
unsafe { eek_get_outline_size(keyboard, button.oref.0) }
|
for (mut button, bounds) in &mut row.buttons.iter_mut().zip(sizes) {
|
||||||
);
|
button.bounds = Some(bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Place buttons
|
// 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(
|
let max_height = row.buttons.iter().map(
|
||||||
|button| FloatOrd(
|
|button| FloatOrd(
|
||||||
button.bounds.as_ref().unwrap().height
|
button.bounds.as_ref().unwrap().height
|
||||||
@ -312,7 +317,6 @@ pub mod c {
|
|||||||
acc + bounds.width + BUTTON_SPACING
|
acc + bounds.width + BUTTON_SPACING
|
||||||
});
|
});
|
||||||
|
|
||||||
// Total size
|
|
||||||
let total_width = match row.buttons.is_empty() {
|
let total_width = match row.buttons.is_empty() {
|
||||||
true => 0f64,
|
true => 0f64,
|
||||||
false => {
|
false => {
|
||||||
@ -322,12 +326,16 @@ pub mod c {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Bounds {
|
let old_row_bounds = row.bounds.as_ref().unwrap().clone();
|
||||||
x: 0f64,
|
row.bounds = Some(Bounds {
|
||||||
y: 0f64,
|
// 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,
|
width: total_width,
|
||||||
height: max_height,
|
height: max_height,
|
||||||
}
|
..old_row_bounds
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds a button sharing this state
|
/// Finds a button sharing this state
|
||||||
|
|||||||
Reference in New Issue
Block a user