-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrstk_ext.rs
67 lines (58 loc) · 1.63 KB
/
rstk_ext.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
65
66
67
use rstk::*;
pub fn init_rstk_ext() {
rstk::tell_wish("chan configure stdin -encoding utf-8");
}
#[derive(Clone, Debug, Default)]
pub struct Style {
pub name: &'static str,
pub background: String,
pub foreground: String,
pub font_size: u64,
pub font_family: String,
pub font_weight: String,
}
impl Style {
pub fn update(&self) {
rstk::tell_wish(&format!(
"ttk::style layout {{{}}} [ttk::style layout {{{}}}];",
self.name, self.name
));
rstk::tell_wish(&format!(
"ttk::style config {} -background {{{}}} -foreground {{{}}} -font {{{} {} {}}};",
self.name,
self.background,
self.foreground,
self.font_family,
self.font_size,
self.font_weight
));
}
}
pub trait TkWidgetExt {
fn style(&self, _style: &Style);
}
impl<T: TkWidget> TkWidgetExt for T {
fn style(&self, style: &Style) {
rstk::tell_wish(&format!(
"{} configure -style {{{}}}",
self.id(),
style.name
));
}
}
pub trait TkTopLevelExt {
fn border(&self, _value: bool);
fn topmost(&self, _value: bool);
fn position(&self, _x: u64, _y: u64);
}
impl TkTopLevelExt for TkTopLevel {
fn border(&self, value: bool) {
rstk::tell_wish(&format!("wm overrideredirect {} {};", &self.id, !value));
}
fn topmost(&self, value: bool) {
rstk::tell_wish(&format!("wm attributes {} -topmost {};", &self.id, value));
}
fn position(&self, x: u64, y: u64) {
rstk::tell_wish(&format!("wm geometry {} +{}+{}", &self.id, x, y));
}
}