Skip to content

Commit 3f0719e

Browse files
committed
ui: screens: make draw_border take a DisplayExclusive instead of Display
Currently draw_border does its own locking of the display, but most callees also lock the screen to draw UI elements or will do so soon when button legends are introduced. Make draw_border use the already locked display instead of doing its own locking. This is mostly an esthetic change, as the framebuffer backend is not at all concerned with the locking we do here and performance-wise it should not make a difference. Signed-off-by: Leonard Göhrs <[email protected]>
1 parent 3629d76 commit 3f0719e

File tree

7 files changed

+29
-31
lines changed

7 files changed

+29
-31
lines changed

src/ui/screens.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -134,31 +134,29 @@ pub(super) trait ActivatableScreen: Sync + Send {
134134

135135
/// Draw static screen border containing a title and an indicator for the
136136
/// position of the screen in the list of screens.
137-
fn draw_border(text: &str, screen: NormalScreen, display: &Display) {
138-
display.with_lock(|target| {
139-
Text::new(
140-
text,
141-
Point::new(8, 17),
142-
MonoTextStyle::new(&UI_TEXT_FONT, BinaryColor::On),
143-
)
137+
fn draw_border(target: &mut DisplayExclusive, text: &str, screen: NormalScreen) {
138+
Text::new(
139+
text,
140+
Point::new(8, 17),
141+
MonoTextStyle::new(&UI_TEXT_FONT, BinaryColor::On),
142+
)
143+
.draw(target)
144+
.unwrap();
145+
146+
Line::new(Point::new(0, 23), Point::new(240, 23))
147+
.into_styled(PrimitiveStyle::with_stroke(BinaryColor::On, 2))
144148
.draw(target)
145149
.unwrap();
146150

147-
Line::new(Point::new(0, 24), Point::new(240, 24))
148-
.into_styled(PrimitiveStyle::with_stroke(BinaryColor::On, 2))
149-
.draw(target)
150-
.unwrap();
151-
152-
let screen_idx = screen as i32;
153-
let num_screens = (NormalScreen::Uart as i32) + 1;
154-
let x_start = screen_idx * 240 / num_screens;
155-
let x_end = (screen_idx + 1) * 240 / num_screens;
156-
157-
Line::new(Point::new(x_start, 240), Point::new(x_end, 240))
158-
.into_styled(PrimitiveStyle::with_stroke(BinaryColor::On, 4))
159-
.draw(target)
160-
.unwrap();
161-
});
151+
let screen_idx = screen as i32;
152+
let num_screens = (NormalScreen::Uart as i32) + 1;
153+
let x_start = screen_idx * 240 / num_screens;
154+
let x_end = (screen_idx + 1) * 240 / num_screens;
155+
156+
Line::new(Point::new(x_start, 240), Point::new(x_end, 240))
157+
.into_styled(PrimitiveStyle::with_stroke(BinaryColor::On, 4))
158+
.draw(target)
159+
.unwrap();
162160
}
163161

164162
const fn row_anchor(row_num: u8) -> Point {

src/ui/screens/dig_out.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ impl ActivatableScreen for DigOutScreen {
6060
}
6161

6262
fn activate(&mut self, ui: &Ui, display: Display) -> Box<dyn ActiveScreen> {
63-
draw_border("Digital Out", SCREEN_TYPE, &display);
64-
6563
let ports = [
6664
(
6765
0,
@@ -81,6 +79,8 @@ impl ActivatableScreen for DigOutScreen {
8179
MonoTextStyle::new(&UI_TEXT_FONT, BinaryColor::On);
8280

8381
display.with_lock(|target| {
82+
draw_border(target, "Digital Out", SCREEN_TYPE);
83+
8484
for (idx, name, _, _) in ports {
8585
let anchor_name = row_anchor(idx * 4);
8686

src/ui/screens/iobus.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ impl ActivatableScreen for IoBusScreen {
5151
}
5252

5353
fn activate(&mut self, ui: &Ui, display: Display) -> Box<dyn ActiveScreen> {
54-
draw_border("IOBus", SCREEN_TYPE, &display);
55-
5654
let ui_text_style: MonoTextStyle<BinaryColor> =
5755
MonoTextStyle::new(&UI_TEXT_FONT, BinaryColor::On);
5856

5957
display.with_lock(|target| {
58+
draw_border(target, "IOBus", SCREEN_TYPE);
59+
6060
Text::new("CAN Status:", row_anchor(0), ui_text_style)
6161
.draw(target)
6262
.unwrap();

src/ui/screens/power.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl ActivatableScreen for PowerScreen {
5656
}
5757

5858
fn activate(&mut self, ui: &Ui, display: Display) -> Box<dyn ActiveScreen> {
59-
draw_border("DUT Power", SCREEN_TYPE, &display);
59+
display.with_lock(|target| draw_border(target, "DUT Power", SCREEN_TYPE));
6060

6161
let mut widgets = WidgetContainer::new(display);
6262

src/ui/screens/system.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl ActivatableScreen for SystemScreen {
7373
}
7474

7575
fn activate(&mut self, ui: &Ui, display: Display) -> Box<dyn ActiveScreen> {
76-
draw_border("System Status", SCREEN_TYPE, &display);
76+
display.with_lock(|target| draw_border(target, "System Status", SCREEN_TYPE));
7777

7878
let mut widgets = WidgetContainer::new(display);
7979
let highlighted = Topic::anonymous(Some(Action::Reboot));

src/ui/screens/uart.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl ActivatableScreen for UartScreen {
5151
}
5252

5353
fn activate(&mut self, ui: &Ui, display: Display) -> Box<dyn ActiveScreen> {
54-
draw_border("DUT UART", SCREEN_TYPE, &display);
54+
display.with_lock(|target| draw_border(target, "DUT UART", SCREEN_TYPE));
5555

5656
let mut widgets = WidgetContainer::new(display);
5757

src/ui/screens/usb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ impl ActivatableScreen for UsbScreen {
6161
}
6262

6363
fn activate(&mut self, ui: &Ui, display: Display) -> Box<dyn ActiveScreen> {
64-
draw_border("USB Host", SCREEN_TYPE, &display);
65-
6664
let ui_text_style: MonoTextStyle<BinaryColor> =
6765
MonoTextStyle::new(&UI_TEXT_FONT, BinaryColor::On);
6866

6967
display.with_lock(|target| {
68+
draw_border(target, "USB Host", SCREEN_TYPE);
69+
7070
Text::new("Total", row_anchor(0), ui_text_style)
7171
.draw(target)
7272
.unwrap();

0 commit comments

Comments
 (0)