Skip to content

Commit 076e9c0

Browse files
committed
chore: Use Rect instead of 4 variables
1 parent cb789e1 commit 076e9c0

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

backend/src/layout/mod.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,7 @@ impl Layout {
138138

139139
let mut row_i = 0;
140140
let mut col_i = 0;
141-
let mut x = 0.0;
142-
let mut y = 0.0;
143-
let mut w = 1.0;
144-
let mut h = 1.0;
141+
let mut physical = Rect::new(0.0, 0.0, 1.0, 1.0);
145142
let mut background_color = Rgb::new(0xcc, 0xcc, 0xcc);
146143

147144
for entry in &self.physical.0 {
@@ -150,10 +147,10 @@ impl Layout {
150147
match i {
151148
PhysicalKeyEnum::Meta(meta) => {
152149
debug!("Key metadata {:?}", meta);
153-
x += meta.x;
154-
y -= meta.y;
155-
w = meta.w.unwrap_or(w);
156-
h = meta.h.unwrap_or(h);
150+
physical.x += meta.x;
151+
physical.y -= meta.y;
152+
physical.w = meta.w.unwrap_or(physical.w);
153+
physical.h = meta.h.unwrap_or(physical.h);
157154
background_color = meta
158155
.c
159156
.as_ref()
@@ -167,23 +164,23 @@ impl Layout {
167164
keys.push(Key::new(
168165
self,
169166
(row_i as u8, col_i as u8),
170-
Rect::new(x, y, w, h),
167+
physical,
171168
name.clone(),
172169
background_color,
173170
));
174171

175-
x += w;
172+
physical.x += physical.w;
176173

177-
w = 1.0;
178-
h = 1.0;
174+
physical.w = 1.0;
175+
physical.h = 1.0;
179176

180177
col_i += 1;
181178
}
182179
}
183180
}
184181

185-
x = 0.0;
186-
y -= 1.0;
182+
physical.x = 0.0;
183+
physical.y -= 1.0;
187184

188185
col_i = 0;
189186
row_i += 1;

backend/src/rect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[derive(Clone, Debug)]
1+
#[derive(Copy, Clone, Debug)]
22
pub struct Rect {
33
pub x: f64,
44
pub y: f64,

0 commit comments

Comments
 (0)