cadmus_core/view/
startup.rs1use super::{Bus, Event, Hub, Id, RenderQueue, View, ID_FEEDER};
2use crate::color::TEXT_NORMAL;
3use crate::context::Context;
4use crate::device::CURRENT_DEVICE;
5use crate::fl;
6use crate::font::{font_from_style, Fonts, DISPLAY_FONT_SIZE, DISPLAY_STYLE};
7use crate::framebuffer::Framebuffer;
8use crate::geom::Rectangle;
9
10pub struct StartupScreen {
15 id: Id,
16 rect: Rectangle,
17 children: Vec<Box<dyn View>>,
18}
19
20impl StartupScreen {
21 pub fn new(rect: Rectangle) -> StartupScreen {
22 StartupScreen {
23 id: ID_FEEDER.next(),
24 rect,
25 children: Vec::new(),
26 }
27 }
28}
29
30impl View for StartupScreen {
31 #[cfg_attr(feature = "otel", tracing::instrument(skip(self, _hub, _bus, _rq, _context), fields(event = ?_evt), ret(level=tracing::Level::TRACE)))]
32 fn handle_event(
33 &mut self,
34 _evt: &Event,
35 _hub: &Hub,
36 _bus: &mut Bus,
37 _rq: &mut RenderQueue,
38 _context: &mut Context,
39 ) -> bool {
40 true
41 }
42
43 #[cfg_attr(feature = "otel", tracing::instrument(skip(self, fb, fonts), fields(rect = ?rect)))]
44 fn render(&self, fb: &mut dyn Framebuffer, rect: Rectangle, fonts: &mut Fonts) {
45 let scheme = TEXT_NORMAL;
46
47 fb.draw_rectangle(&self.rect, scheme[0]);
48
49 let dpi = CURRENT_DEVICE.dpi;
50 let font = font_from_style(fonts, &DISPLAY_STYLE, dpi);
51 font.set_size(DISPLAY_FONT_SIZE / 2, dpi);
52 let padding = font.em() as i32;
53 let max_width = self.rect.width() as i32 - 3 * padding;
54
55 let label = fl!("startup-loading");
56
57 let mut plan = font.plan(label.as_str(), None, None);
58
59 if plan.width > max_width {
60 let scale = max_width as f32 / plan.width as f32;
61 let size = (scale * (DISPLAY_FONT_SIZE / 2) as f32) as u32;
62 font.set_size(size, dpi);
63 plan = font.plan(label, None, None);
64 }
65
66 let dx = (self.rect.width() as i32 - plan.width) / 2;
67 let dy = (self.rect.height() as i32 - font.ascender()) / 2;
68
69 font.render(fb, scheme[1], &plan, pt!(dx, dy));
70
71 let _ = rect;
72 }
73
74 fn might_rotate(&self) -> bool {
75 false
76 }
77
78 fn rect(&self) -> &Rectangle {
79 &self.rect
80 }
81
82 fn rect_mut(&mut self) -> &mut Rectangle {
83 &mut self.rect
84 }
85
86 fn children(&self) -> &Vec<Box<dyn View>> {
87 &self.children
88 }
89
90 fn children_mut(&mut self) -> &mut Vec<Box<dyn View>> {
91 &mut self.children
92 }
93
94 fn id(&self) -> Id {
95 self.id
96 }
97}