layout: Drop trailing whitespace
Otherwise sane editor setup is basically impossible since we want to trim that by default (and not manually like here) in the future.
This commit is contained in:
@ -1,17 +1,17 @@
|
|||||||
/*!
|
/*!
|
||||||
* Layout-related data.
|
* Layout-related data.
|
||||||
*
|
*
|
||||||
* The `View` contains `Row`s and each `Row` contains `Button`s.
|
* The `View` contains `Row`s and each `Row` contains `Button`s.
|
||||||
* They carry data relevant to their positioning only,
|
* They carry data relevant to their positioning only,
|
||||||
* except the Button, which also carries some data
|
* except the Button, which also carries some data
|
||||||
* about its appearance and function.
|
* about its appearance and function.
|
||||||
*
|
*
|
||||||
* The layout is determined bottom-up, by measuring `Button` sizes,
|
* The layout is determined bottom-up, by measuring `Button` sizes,
|
||||||
* deriving `Row` sizes from them, and then centering them within the `View`.
|
* deriving `Row` sizes from them, and then centering them within the `View`.
|
||||||
*
|
*
|
||||||
* That makes the `View` position immutable,
|
* That makes the `View` position immutable,
|
||||||
* and therefore different than the other positions.
|
* and therefore different than the other positions.
|
||||||
*
|
*
|
||||||
* Note that it might be a better idea
|
* Note that it might be a better idea
|
||||||
* to make `View` position depend on its contents,
|
* to make `View` position depend on its contents,
|
||||||
* and let the renderer scale and center it within the widget.
|
* and let the renderer scale and center it within the widget.
|
||||||
@ -64,7 +64,7 @@ pub mod c {
|
|||||||
pub x: f64,
|
pub x: f64,
|
||||||
pub y: f64,
|
pub y: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Add for Point {
|
impl Add for Point {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
fn add(self, other: Self) -> Self {
|
fn add(self, other: Self) -> Self {
|
||||||
@ -81,7 +81,7 @@ pub mod c {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sub<&Point> for Point {
|
impl Sub<&Point> for Point {
|
||||||
type Output = Point;
|
type Output = Point;
|
||||||
fn sub(self, other: &Point) -> Point {
|
fn sub(self, other: &Point) -> Point {
|
||||||
@ -152,14 +152,14 @@ pub mod c {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is constructed only in C, no need for warnings
|
// This is constructed only in C, no need for warnings
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct LevelKeyboard(*const c_void);
|
pub struct LevelKeyboard(*const c_void);
|
||||||
|
|
||||||
// The following defined in Rust. TODO: wrap naked pointers to Rust data inside RefCells to prevent multiple writers
|
// The following defined in Rust. TODO: wrap naked pointers to Rust data inside RefCells to prevent multiple writers
|
||||||
|
|
||||||
/// Positions the layout contents within the available space.
|
/// Positions the layout contents within the available space.
|
||||||
/// The origin of the transformation is the point inside the margins.
|
/// The origin of the transformation is the point inside the margins.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@ -271,7 +271,7 @@ pub mod c {
|
|||||||
|
|
||||||
let state = layout.find_button_by_position(point)
|
let state = layout.find_button_by_position(point)
|
||||||
.map(|place| place.button.state.clone());
|
.map(|place| place.button.state.clone());
|
||||||
|
|
||||||
if let Some(state) = state {
|
if let Some(state) = state {
|
||||||
seat::handle_press_key(
|
seat::handle_press_key(
|
||||||
layout,
|
layout,
|
||||||
@ -311,7 +311,7 @@ pub mod c {
|
|||||||
let point = ui_backend.widget_to_layout.forward(
|
let point = ui_backend.widget_to_layout.forward(
|
||||||
Point { x: x_widget, y: y_widget }
|
Point { x: x_widget, y: y_widget }
|
||||||
);
|
);
|
||||||
|
|
||||||
let pressed = layout.pressed_keys.clone();
|
let pressed = layout.pressed_keys.clone();
|
||||||
let button_info = {
|
let button_info = {
|
||||||
let place = layout.find_button_by_position(point);
|
let place = layout.find_button_by_position(point);
|
||||||
@ -370,11 +370,11 @@ pub mod c {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn near(a: f64, b: f64) -> bool {
|
fn near(a: f64, b: f64) -> bool {
|
||||||
(a - b).abs() < ((a + b) * 0.001f64).abs()
|
(a - b).abs() < ((a + b) * 0.001f64).abs()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn transform_back() {
|
fn transform_back() {
|
||||||
let transform = Transformation {
|
let transform = Transformation {
|
||||||
@ -413,7 +413,7 @@ pub enum Label {
|
|||||||
/// The graphical representation of a button
|
/// The graphical representation of a button
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Button {
|
pub struct Button {
|
||||||
/// ID string, e.g. for CSS
|
/// ID string, e.g. for CSS
|
||||||
pub name: CString,
|
pub name: CString,
|
||||||
/// Label to display to the user
|
/// Label to display to the user
|
||||||
pub label: Label,
|
pub label: Label,
|
||||||
@ -573,11 +573,11 @@ impl View {
|
|||||||
offset: &row.0 + c::Point { x: button.0, y: 0.0 },
|
offset: &row.0 + c::Point { x: button.0, y: 0.0 },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_size(&self) -> Size {
|
pub fn get_size(&self) -> Size {
|
||||||
self.size.clone()
|
self.size.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns positioned rows, with appropriate x offsets (centered)
|
/// Returns positioned rows, with appropriate x offsets (centered)
|
||||||
pub fn get_rows(&self) -> &Vec<(c::Point, Row)> {
|
pub fn get_rows(&self) -> &Vec<(c::Point, Row)> {
|
||||||
&self.rows
|
&self.rows
|
||||||
@ -731,7 +731,7 @@ impl Layout {
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn calculate_transformation(
|
pub fn calculate_transformation(
|
||||||
&self,
|
&self,
|
||||||
available: Size,
|
available: Size,
|
||||||
@ -770,7 +770,7 @@ impl Layout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_view_transition(
|
fn apply_view_transition(
|
||||||
&mut self,
|
&mut self,
|
||||||
action: &Action,
|
action: &Action,
|
||||||
@ -812,7 +812,7 @@ impl Layout {
|
|||||||
///
|
///
|
||||||
/// Although the state is not defined at the keys
|
/// Although the state is not defined at the keys
|
||||||
/// (it's in the relationship between view and action),
|
/// (it's in the relationship between view and action),
|
||||||
/// keys go through the following stages when clicked repeatedly:
|
/// keys go through the following stages when clicked repeatedly:
|
||||||
/// unlocked+unlatched -> locked+latched -> locked+unlatched
|
/// unlocked+unlatched -> locked+latched -> locked+unlatched
|
||||||
/// -> unlocked+unlatched
|
/// -> unlocked+unlatched
|
||||||
fn process_action_for_view<'a>(
|
fn process_action_for_view<'a>(
|
||||||
@ -906,7 +906,7 @@ mod procedures {
|
|||||||
})
|
})
|
||||||
}).collect()
|
}).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -1113,7 +1113,7 @@ mod test {
|
|||||||
state: state,
|
state: state,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn latch_lock_unlock() {
|
fn latch_lock_unlock() {
|
||||||
let action = Action::LockView {
|
let action = Action::LockView {
|
||||||
@ -1152,7 +1152,7 @@ mod test {
|
|||||||
latches: true,
|
latches: true,
|
||||||
looks_locked_from: vec![],
|
looks_locked_from: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let submit = Action::Erase;
|
let submit = Action::Erase;
|
||||||
|
|
||||||
let view = View::new(vec![(
|
let view = View::new(vec![(
|
||||||
@ -1194,7 +1194,7 @@ mod test {
|
|||||||
"base".into() => (c::Point { x: 0.0, y: 0.0 }, view.clone()),
|
"base".into() => (c::Point { x: 0.0, y: 0.0 }, view.clone()),
|
||||||
"locked".into() => (c::Point { x: 0.0, y: 0.0 }, view),
|
"locked".into() => (c::Point { x: 0.0, y: 0.0 }, view),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Basic cycle
|
// Basic cycle
|
||||||
layout.apply_view_transition(&switch);
|
layout.apply_view_transition(&switch);
|
||||||
@ -1220,14 +1220,14 @@ mod test {
|
|||||||
latches: true,
|
latches: true,
|
||||||
looks_locked_from: vec![],
|
looks_locked_from: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let unswitch = Action::LockView {
|
let unswitch = Action::LockView {
|
||||||
lock: "locked".into(),
|
lock: "locked".into(),
|
||||||
unlock: "unlocked".into(),
|
unlock: "unlocked".into(),
|
||||||
latches: false,
|
latches: false,
|
||||||
looks_locked_from: vec![],
|
looks_locked_from: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let submit = Action::Erase;
|
let submit = Action::Erase;
|
||||||
|
|
||||||
let view = View::new(vec![(
|
let view = View::new(vec![(
|
||||||
@ -1286,14 +1286,14 @@ mod test {
|
|||||||
latches: true,
|
latches: true,
|
||||||
looks_locked_from: vec![],
|
looks_locked_from: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let switch_again = Action::LockView {
|
let switch_again = Action::LockView {
|
||||||
lock: "ĄĘ".into(),
|
lock: "ĄĘ".into(),
|
||||||
unlock: "locked".into(),
|
unlock: "locked".into(),
|
||||||
latches: true,
|
latches: true,
|
||||||
looks_locked_from: vec![],
|
looks_locked_from: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let submit = Action::Erase;
|
let submit = Action::Erase;
|
||||||
|
|
||||||
let view = View::new(vec![(
|
let view = View::new(vec![(
|
||||||
|
|||||||
Reference in New Issue
Block a user