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