Skip to content

Commit b734972

Browse files
committed
Add names to screen layouts
1 parent 24b1cf5 commit b734972

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

screenlayouts/build.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub const HOST_SCREEN_HEIGHT: usize = 544;
1111
pub const GUEST_SCREEN_WIDTH: usize = 256;
1212
pub const GUEST_SCREEN_HEIGHT: usize = 192;
1313

14-
pub fn get_screen_layouts() -> Vec<[[f32; 9]; 4]> {
14+
pub fn get_screen_layouts() -> Vec<(&'static str, [[f32; 9]; 4])> {
1515
let mut layouts = Vec::new();
1616

1717
{
@@ -24,7 +24,7 @@ pub fn get_screen_layouts() -> Vec<[[f32; 9]; 4]> {
2424
* Matrix3::new_scaling(width_scale);
2525
let b_trans = Matrix3::new_translation(&Vector2::new(guest_width, 0.0));
2626

27-
layouts.push([mtx, b_trans * mtx]);
27+
layouts.push(("Side by side", [mtx, b_trans * mtx]));
2828
}
2929

3030
{
@@ -37,30 +37,30 @@ pub fn get_screen_layouts() -> Vec<[[f32; 9]; 4]> {
3737
* Matrix3::new_scaling(full_height_scale);
3838
let b_trans = Matrix3::new_translation(&Vector2::new(guest_height, 0.0));
3939

40-
layouts.push([mtx, b_trans * mtx]);
40+
layouts.push(("Rotate", [mtx, b_trans * mtx]));
4141
}
4242

4343
{
4444
let full_height_scale = HOST_SCREEN_HEIGHT as f32 / GUEST_SCREEN_HEIGHT as f32;
4545
let guest_top_width = GUEST_SCREEN_WIDTH as f32 * full_height_scale;
4646
let width_remaining_space = HOST_SCREEN_WIDTH as f32 - guest_top_width;
47-
let guest_bottom_scale = width_remaining_space / GUEST_SCREEN_WIDTH as f32;
48-
let guest_bottom_height = GUEST_SCREEN_HEIGHT as f32 * guest_bottom_scale;
49-
let height_remaining_space = HOST_SCREEN_HEIGHT as f32 - guest_bottom_height;
50-
let top_mtx = Matrix3::new_translation(&Vector2::new(guest_top_width / 2.0, HOST_SCREEN_HEIGHT as f32 / 2.0)) * Matrix3::new_scaling(full_height_scale);
51-
let bottom_mtx =
52-
Matrix3::new_translation(&Vector2::new(width_remaining_space / 2.0 + guest_top_width, guest_bottom_height / 2.0 + height_remaining_space / 2.0)) * Matrix3::new_scaling(guest_bottom_scale);
47+
let top_mtx = Matrix3::new_translation(&Vector2::new(guest_top_width / 2.0 + width_remaining_space / 2.0, HOST_SCREEN_HEIGHT as f32 / 2.0)) * Matrix3::new_scaling(full_height_scale);
5348

54-
layouts.push([top_mtx, bottom_mtx]);
49+
layouts.push(("Single", [top_mtx, Matrix3::new_translation(&Vector2::new(-(HOST_SCREEN_WIDTH as f32), -(HOST_SCREEN_HEIGHT as f32)))]));
5550
}
5651

5752
{
5853
let full_height_scale = HOST_SCREEN_HEIGHT as f32 / GUEST_SCREEN_HEIGHT as f32;
5954
let guest_top_width = GUEST_SCREEN_WIDTH as f32 * full_height_scale;
6055
let width_remaining_space = HOST_SCREEN_WIDTH as f32 - guest_top_width;
61-
let top_mtx = Matrix3::new_translation(&Vector2::new(guest_top_width / 2.0 + width_remaining_space / 2.0, HOST_SCREEN_HEIGHT as f32 / 2.0)) * Matrix3::new_scaling(full_height_scale);
56+
let guest_bottom_scale = width_remaining_space / GUEST_SCREEN_WIDTH as f32;
57+
let guest_bottom_height = GUEST_SCREEN_HEIGHT as f32 * guest_bottom_scale;
58+
let height_remaining_space = HOST_SCREEN_HEIGHT as f32 - guest_bottom_height;
59+
let top_mtx = Matrix3::new_translation(&Vector2::new(guest_top_width / 2.0, HOST_SCREEN_HEIGHT as f32 / 2.0)) * Matrix3::new_scaling(full_height_scale);
60+
let bottom_mtx =
61+
Matrix3::new_translation(&Vector2::new(width_remaining_space / 2.0 + guest_top_width, guest_bottom_height / 2.0 + height_remaining_space / 2.0)) * Matrix3::new_scaling(guest_bottom_scale);
6262

63-
layouts.push([top_mtx, Matrix3::new_translation(&Vector2::new(-(HOST_SCREEN_WIDTH as f32), -(HOST_SCREEN_HEIGHT as f32)))]);
63+
layouts.push(("Focus", [top_mtx, bottom_mtx]));
6464
}
6565

6666
{
@@ -71,14 +71,17 @@ pub fn get_screen_layouts() -> Vec<[[f32; 9]; 4]> {
7171
let bottom_mtx = Matrix3::new_translation(&Vector2::new((HOST_SCREEN_WIDTH - GUEST_SCREEN_WIDTH) as f32, (HOST_SCREEN_HEIGHT - GUEST_SCREEN_HEIGHT) as f32))
7272
* Matrix3::new_translation(&Vector2::new(GUEST_SCREEN_WIDTH as f32 / 2.0, GUEST_SCREEN_HEIGHT as f32 / 2.0));
7373

74-
layouts.push([top_mtx, bottom_mtx]);
74+
layouts.push(("Focus Overlap", [top_mtx, bottom_mtx]));
7575
}
7676

7777
layouts
7878
.iter()
79-
.map(|mtxs| {
79+
.map(|(name, mtxs)| {
8080
let flatten = |mtx: &Matrix3<f32>| [mtx[0], mtx[1], mtx[2], mtx[3], mtx[4], mtx[5], mtx[6], mtx[7], mtx[8]];
81-
[flatten(&mtxs[0]), flatten(&mtxs[1]), flatten(&mtxs[0].try_inverse().unwrap()), flatten(&mtxs[1].try_inverse().unwrap())]
81+
(
82+
*name,
83+
[flatten(&mtxs[0]), flatten(&mtxs[1]), flatten(&mtxs[0].try_inverse().unwrap()), flatten(&mtxs[1].try_inverse().unwrap())],
84+
)
8285
})
8386
.collect()
8487
}
@@ -87,14 +90,17 @@ pub fn main() {
8790
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
8891
let screen_layouts_file = out_path.join("screen_layouts.rs");
8992
let layouts = get_screen_layouts();
90-
let mut code = format!("pub const SCREEN_LAYOUTS: [[[f32; 9]; 4]; {}] = [\n", layouts.len());
91-
for layout in layouts {
92-
code += "\t[\n";
93-
code += &format!("\t\t{:?},\n", layout[0]);
94-
code += &format!("\t\t{:?},\n", layout[1]);
95-
code += &format!("\t\t{:?},\n", layout[2]);
96-
code += &format!("\t\t{:?},\n", layout[3]);
97-
code += "\t],\n";
93+
let mut code = format!("pub const SCREEN_LAYOUTS: [(&'static str, [[f32; 9]; 4]); {}] = [\n", layouts.len());
94+
for (name, mtxs) in layouts {
95+
code += "\t(\n";
96+
code += &format!("\t\t\"{name}\",\n");
97+
code += "\t\t[\n";
98+
code += &format!("\t\t\t{:?},\n", mtxs[0]);
99+
code += &format!("\t\t\t{:?},\n", mtxs[1]);
100+
code += &format!("\t\t\t{:?},\n", mtxs[2]);
101+
code += &format!("\t\t\t{:?},\n", mtxs[3]);
102+
code += "\t\t],\n";
103+
code += "\t),\n";
98104
}
99105
code += "];\n";
100106
File::create(screen_layouts_file).unwrap().write_all(code.as_bytes()).unwrap();

src/screen_layouts.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct ScreenLayout {
1414

1515
impl ScreenLayout {
1616
pub fn settings_value() -> SettingValue {
17-
SettingValue::List(0, (0..SCREEN_LAYOUTS.len()).map(|i| i.to_string()).collect())
17+
SettingValue::List(0, SCREEN_LAYOUTS.iter().map(|(name, _)| name.to_string()).collect())
1818
}
1919

2020
pub fn new(index: usize, swap: bool) -> Self {
@@ -24,8 +24,8 @@ impl ScreenLayout {
2424
[DISPLAY_WIDTH as f32 / 2.0, DISPLAY_HEIGHT as f32 / 2.0, 1.0],
2525
[-(DISPLAY_WIDTH as f32 / 2.0), DISPLAY_HEIGHT as f32 / 2.0, 1.0],
2626
];
27-
let a_mtx = &SCREEN_LAYOUTS[index][0];
28-
let b_mtx = &SCREEN_LAYOUTS[index][1];
27+
let a_mtx = &SCREEN_LAYOUTS[index].1[0];
28+
let b_mtx = &SCREEN_LAYOUTS[index].1[1];
2929
let mut screen_top = [[0.0; 3]; 4];
3030
let mut screen_bottom = [[0.0; 3]; 4];
3131
let overlap = unsafe {
@@ -103,7 +103,7 @@ impl ScreenLayout {
103103
}
104104

105105
pub fn get_bottom_inverse_mtx(&self) -> &[f32; 9] {
106-
&SCREEN_LAYOUTS[self.index][if self.swap { 2 } else { 3 }]
106+
&SCREEN_LAYOUTS[self.index].1[if self.swap { 2 } else { 3 }]
107107
}
108108

109109
pub fn normalize_touch_points(&self, x: i16, y: i16) -> (i16, i16) {

0 commit comments

Comments
 (0)