test_layout/
test_layout.rs1use river_layout_toolkit::{run, GeneratedLayout, Layout, Rectangle};
2use std::convert::Infallible;
3
4fn main() {
5 let layout = MyLayout {};
6 run(layout).unwrap();
7}
8
9struct MyLayout {
10 }
12
13impl Layout for MyLayout {
14 type Error = Infallible;
15
16 const NAMESPACE: &'static str = "test-layout";
17
18 fn user_cmd(
19 &mut self,
20 _cmd: String,
21 _tags: Option<u32>,
22 _output: &str,
23 ) -> Result<(), Self::Error> {
24 Ok(())
25 }
26
27 fn generate_layout(
28 &mut self,
29 view_count: u32,
30 usable_width: u32,
31 usable_height: u32,
32 _tags: u32,
33 _output: &str,
34 ) -> Result<GeneratedLayout, Self::Error> {
35 let mut layout = GeneratedLayout {
36 layout_name: "[]=".to_string(),
37 views: Vec::with_capacity(view_count as usize),
38 };
39 if view_count == 1 {
40 layout.views.push(Rectangle {
41 x: 0,
42 y: 0,
43 width: usable_width,
44 height: usable_height,
45 });
46 } else {
47 layout.views.push(Rectangle {
48 x: 0,
49 y: 0,
50 width: usable_width / 2,
51 height: usable_height,
52 });
53 for i in 0..(view_count - 1) {
54 layout.views.push(Rectangle {
55 x: (usable_width / 2) as i32,
56 y: (usable_height / (view_count - 1) * i) as i32,
57 width: usable_width / 2,
58 height: usable_height / (view_count - 1),
59 });
60 }
61 }
62 Ok(layout)
63 }
64}