refactor(core/delizia): use `u8` for header margin
What changed, and why it matters
This is a small internal code cleanup in the Trezor firmware's user-interface code. It changes a variable used for screen layout margin from a larger integer type (`usize`) to a smaller one (`u8`). The actual behavior is unchanged because the value is immediately converted to the same screen-coordinate type (`i16`) used before. There is no security-relevant change visible in the commit.
No security action needed. Treat as a normal code-quality refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the margin field in the Delizia UI layout from usize to u8, updating Frame, ConfirmActionOptions, and a constant CONFIRM_VALUE_INTRO_MARGIN. In frame_place, the u8 margin is converted to i16 via margin.into() before being passed to Insets::top(...) and Insets::bottom(...), which is equivalent to the previous margin as i16 casts. The change is purely type-narrowing and does not alter layout arithmetic or bounds checking.
Changed components
core/embed/rust/src/ui/layout_delizia/component/frame.rscore/embed/rust/src/ui/layout_delizia/flow/confirm_action.rscore/embed/rust/src/ui/layout_delizia/ui_firmware.rsInspect captured patch +10 / −8
diff --git a/core/embed/rust/src/ui/layout_delizia/component/frame.rs b/core/embed/rust/src/ui/layout_delizia/component/frame.rs
index 1fb77e71..c42dfba1 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/frame.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/frame.rs
@@ -92,7 +92,7 @@ pub struct Frame<T> {
footer_update_fn: Option<fn(&T, &mut EventCtx, &mut Footer<'static>)>,
swipe: SwipeConfig,
horizontal_swipe: HorizontalSwipe,
- margin: usize,
+ margin: u8,
#[cfg(feature = "ui_debug")]
has_menu: bool,
#[cfg(feature = "ui_debug")]
@@ -255,7 +255,7 @@ where
}
}
- pub fn with_margin(mut self, margin: usize) -> Self {
+ pub fn with_margin(mut self, margin: u8) -> Self {
self.margin = margin;
self
}
@@ -370,13 +370,15 @@ fn frame_place(
header: &mut Header,
footer: &mut Option<Footer>,
bounds: Rect,
- margin: usize,
+ margin: u8,
) -> Rect {
+ let margin: i16 = margin.into();
+
let header_area = header.place(bounds);
let mut content_area = bounds
.inset(Insets::top(header_area.height().max(TITLE_HEIGHT)))
.inset(Insets::top(theme::SPACING))
- .inset(Insets::top(margin as i16));
+ .inset(Insets::top(margin));
if let Some(footer) = footer {
// FIXME: spacer at the bottom might be applied also for usage without footer
@@ -384,7 +386,7 @@ fn frame_place(
content_area = content_area.inset(Insets::bottom(theme::SPACING));
let (remaining, footer_area) = content_area.split_bottom(footer.height());
footer.place(footer_area);
- content_area = remaining.inset(Insets::bottom(margin as i16));
+ content_area = remaining.inset(Insets::bottom(margin));
}
content_area
}
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/confirm_action.rs b/core/embed/rust/src/ui/layout_delizia/flow/confirm_action.rs
index e82c4af1..07351cbb 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/confirm_action.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/confirm_action.rs
@@ -76,7 +76,7 @@ pub struct ConfirmActionOptions {
pub swipe_up: bool,
pub page_limit: Option<u16>,
pub page_counter: bool,
- pub frame_margin: usize,
+ pub frame_margin: u8,
}
impl ConfirmActionOptions {
@@ -116,7 +116,7 @@ impl ConfirmActionOptions {
self
}
- pub fn with_frame_margin(mut self, frame_margin: usize) -> Self {
+ pub fn with_frame_margin(mut self, frame_margin: u8) -> Self {
self.frame_margin = frame_margin;
self
}
diff --git a/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs b/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs
index 19737a26..a4567758 100644
--- a/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs
+++ b/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs
@@ -166,7 +166,7 @@ impl FirmwareUI for UIDelizia {
hold: bool,
chunkify: bool,
) -> Result<Gc<LayoutObj>, Error> {
- const CONFIRM_VALUE_INTRO_MARGIN: usize = 24;
+ const CONFIRM_VALUE_INTRO_MARGIN: u8 = 24;
ConfirmValue::new(
title,
value.try_into()?,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.