refactor(core): optimize `SwipeConfig` memory
What changed, and why it matters
This commit is a straightforward internal code cleanup that reduces the memory used by swipe gesture settings. It replaces a flexible but bulky structure storing animation duration with a simple on/off-style enum that only supports the two durations actually used (normal 333 ms and immediate 0 ms). There is no user-visible behavior change and no security relevance.
No action required; treat as a normal non-security refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors SwipeSettings from a struct containing a Duration (8 bytes) into a zero-sized enum with Default and Immediate variants, shrinking SwipeConfig from 36 bytes to 5 bytes. All call sites are updated from SwipeSettings::default()/immediate() constructors to SwipeSettings::Default/Immediate enum variants. The duration() method now maps the enum to the previously hard-coded durations. The functional behavior is preserved exactly.
Changed components
core/embed/rust/src/ui/component/swipe_detect.rscore/embed/rust/src/ui/layout_delizia/component/frame.rscore/embed/rust/src/ui/layout_delizia/flow/*core/embed/rust/src/ui/layout_delizia/ui_firmware.rscore/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rsInspect captured patch +46 / −54
diff --git a/core/embed/rust/src/ui/component/swipe_detect.rs b/core/embed/rust/src/ui/component/swipe_detect.rs
index 875a6563..b2e2aa20 100644
--- a/core/embed/rust/src/ui/component/swipe_detect.rs
+++ b/core/embed/rust/src/ui/component/swipe_detect.rs
@@ -11,24 +11,16 @@ use crate::{
};
#[derive(Copy, Clone)]
-pub struct SwipeSettings {
- pub duration: Duration,
+pub enum SwipeSettings {
+ Default,
+ Immediate,
}
impl SwipeSettings {
- pub const fn new(duration: Duration) -> Self {
- Self { duration }
- }
-
- pub const fn default() -> Self {
- Self {
- duration: Duration::from_millis(333),
- }
- }
-
- pub const fn immediate() -> Self {
- Self {
- duration: Duration::from_millis(0),
+ fn duration(&self) -> Duration {
+ match self {
+ Self::Default => Duration::from_millis(333),
+ Self::Immediate => Duration::from_millis(0),
}
}
}
@@ -93,7 +85,7 @@ impl SwipeConfig {
}
pub fn duration(&self, dir: Direction) -> Option<Duration> {
- self[dir].as_ref().map(|s| s.duration)
+ self[dir].as_ref().map(|s| s.duration())
}
pub fn with_horizontal_pages(mut self) -> Self {
@@ -110,18 +102,18 @@ impl SwipeConfig {
match self.page_axis {
Some(Axis::Horizontal) => {
if pager.has_prev() {
- self.right = Some(SwipeSettings::default());
+ self.right = Some(SwipeSettings::Default);
}
if pager.has_next() {
- self.left = Some(SwipeSettings::default());
+ self.left = Some(SwipeSettings::Default);
}
}
Some(Axis::Vertical) => {
if pager.has_prev() {
- self.down = Some(SwipeSettings::default());
+ self.down = Some(SwipeSettings::Default);
}
if pager.has_next() {
- self.up = Some(SwipeSettings::default());
+ self.up = Some(SwipeSettings::Default);
}
}
_ => {}
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 a90f5921..15e05de2 100644
--- a/core/embed/rust/src/ui/layout_delizia/component/frame.rs
+++ b/core/embed/rust/src/ui/layout_delizia/component/frame.rs
@@ -213,7 +213,7 @@ where
use crate::translations::TR;
self.with_footer(TR::instructions__tap.into(), description)
- .with_swipe(Direction::Up, SwipeSettings::default())
+ .with_swipe(Direction::Up, SwipeSettings::Default)
}
#[cfg(feature = "translations")]
@@ -221,7 +221,7 @@ where
use crate::translations::TR;
self.with_footer(TR::instructions__tap_to_continue.into(), description)
- .with_swipe(Direction::Up, SwipeSettings::default())
+ .with_swipe(Direction::Up, SwipeSettings::Default)
}
#[inline(never)]
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 93d60839..4ca7e227 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
@@ -413,7 +413,7 @@ fn create_confirm(
let mut content_confirm = Frame::left_aligned(prompt_title, SwipeContent::new(prompt))
.with_footer(prompt_action, None)
- .with_swipe(Direction::Down, SwipeSettings::default());
+ .with_swipe(Direction::Down, SwipeSettings::Default);
if matches!(extra, ConfirmActionExtra::Menu(_)) {
content_confirm = content_confirm.with_menu_button();
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/confirm_fido.rs b/core/embed/rust/src/ui/layout_delizia/flow/confirm_fido.rs
index 71ae8c4e..2c83ab1c 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/confirm_fido.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/confirm_fido.rs
@@ -139,7 +139,7 @@ pub fn new_confirm_fido(
TR::instructions__swipe_down.into(),
)
.register_footer_update_fn(footer_update_fn)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.with_vertical_pages()
.map(super::util::map_to_choice);
@@ -163,7 +163,7 @@ pub fn new_confirm_fido(
let content_tap = Frame::left_aligned(title, PromptScreen::new_tap_to_confirm())
.with_menu_button()
.with_footer(TR::instructions__tap_to_confirm.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm);
let content_menu = Frame::left_aligned(
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/confirm_firmware_update.rs b/core/embed/rust/src/ui/layout_delizia/flow/confirm_firmware_update.rs
index 72144f2d..a8d72d99 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/confirm_firmware_update.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/confirm_firmware_update.rs
@@ -97,7 +97,7 @@ pub fn new_confirm_firmware_update(
)
.with_menu_button()
.with_footer(TR::instructions__hold_to_confirm.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm);
let mut res = SwipeFlow::new(&ConfirmFirmwareUpdate::Intro)?;
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/confirm_homescreen.rs b/core/embed/rust/src/ui/layout_delizia/flow/confirm_homescreen.rs
index 2d79a800..0b290761 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/confirm_homescreen.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/confirm_homescreen.rs
@@ -76,7 +76,7 @@ pub fn new_confirm_homescreen(
)
.with_menu_button()
.with_footer(TR::instructions__tap_to_confirm.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm);
let mut res = SwipeFlow::new(&ConfirmHomescreen::Homescreen)?;
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/confirm_output.rs b/core/embed/rust/src/ui/layout_delizia/flow/confirm_output.rs
index a1dfb351..e166d8a9 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/confirm_output.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/confirm_output.rs
@@ -277,7 +277,7 @@ pub fn new_confirm_output(
)
.with_menu_button()
.with_footer(TR::instructions__hold_to_sign.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm);
// FeeInfo
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/confirm_reset.rs b/core/embed/rust/src/ui/layout_delizia/flow/confirm_reset.rs
index 88d551bb..92a14411 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/confirm_reset.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/confirm_reset.rs
@@ -131,7 +131,7 @@ pub fn new_confirm_reset(recovery: bool) -> Result<SwipeFlow, error::Error> {
)
.with_menu_button()
.with_footer(TR::instructions__hold_to_confirm.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm)
.one_button_request(ButtonRequestCode::ResetDevice.with_name("confirm_setup_device"));
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/confirm_set_new_pin.rs b/core/embed/rust/src/ui/layout_delizia/flow/confirm_set_new_pin.rs
index 2e60c6aa..b7c5202d 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/confirm_set_new_pin.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/confirm_set_new_pin.rs
@@ -93,7 +93,7 @@ pub fn new_set_new_pin(
)
.with_cancel_button()
.with_footer(TR::instructions__tap_to_confirm.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm);
let mut res = SwipeFlow::new(&SetNewPin::Intro)?;
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/confirm_summary.rs b/core/embed/rust/src/ui/layout_delizia/flow/confirm_summary.rs
index d8184b90..fafdd5aa 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/confirm_summary.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/confirm_summary.rs
@@ -90,7 +90,7 @@ pub fn new_confirm_summary(
)
.with_menu_button()
.with_footer(TR::instructions__hold_to_sign.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm);
// ExtraInfo
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/continue_recovery_homepage.rs b/core/embed/rust/src/ui/layout_delizia/flow/continue_recovery_homepage.rs
index 252dc290..210db71c 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/continue_recovery_homepage.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/continue_recovery_homepage.rs
@@ -208,7 +208,7 @@ pub fn new_continue_recovery_homepage(
)
.with_cancel_button()
.with_footer(TR::instructions__tap_to_confirm.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm);
let res = if show_instructions {
@@ -253,7 +253,7 @@ pub fn new_continue_recovery_homepage(
TR::instructions__swipe_down.into(),
)
.register_footer_update_fn(footer_update_fn)
- .with_swipe(Direction::Up, SwipeSettings::default())
+ .with_swipe(Direction::Up, SwipeSettings::Default)
.with_vertical_pages()
.map_to_button_msg()
.repeated_button_request(ButtonRequest::new(
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/prompt_backup.rs b/core/embed/rust/src/ui/layout_delizia/flow/prompt_backup.rs
index d1b19992..64ad8dc6 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/prompt_backup.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/prompt_backup.rs
@@ -87,7 +87,7 @@ pub fn new_prompt_backup() -> Result<SwipeFlow, error::Error> {
)
.with_cancel_button()
.with_swipeup_footer(Some(TR::words__continue_anyway_question.into()))
- .with_swipe(Direction::Up, SwipeSettings::default())
+ .with_swipe(Direction::Up, SwipeSettings::Default)
.map_to_button_msg();
let content_skip_confirm = Frame::left_aligned(
@@ -96,7 +96,7 @@ pub fn new_prompt_backup() -> Result<SwipeFlow, error::Error> {
)
.with_cancel_button()
.with_footer(TR::instructions__tap_to_confirm.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm);
let mut res = SwipeFlow::new(&PromptBackup::Intro)?;
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/receive.rs b/core/embed/rust/src/ui/layout_delizia/flow/receive.rs
index bf3f5ee2..1f73f9bb 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/receive.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/receive.rs
@@ -123,7 +123,7 @@ pub fn new_receive(
let content_tap =
Frame::left_aligned(title, SwipeContent::new(PromptScreen::new_tap_to_confirm()))
.with_footer(TR::instructions__tap_to_confirm.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm);
// Menu
@@ -175,7 +175,7 @@ pub fn new_receive(
Frame::left_aligned(cancel_title.into(), PromptScreen::new_tap_to_cancel())
.with_cancel_button()
.with_footer(TR::instructions__tap_to_confirm.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm);
let mut res = SwipeFlow::new(&Receive::Content)?;
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/set_brightness.rs b/core/embed/rust/src/ui/layout_delizia/flow/set_brightness.rs
index de36f570..9229a517 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/set_brightness.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/set_brightness.rs
@@ -79,7 +79,7 @@ pub fn new_set_brightness(brightness: u8) -> Result<SwipeFlow, Error> {
)
.with_subtitle(TR::homescreen__settings_subtitle.into())
.with_cancel_button()
- .with_swipe(Direction::Up, SwipeSettings::default())
+ .with_swipe(Direction::Up, SwipeSettings::Default)
.with_footer(
TR::instructions__swipe_horizontally.into(),
Some(TR::setting__adjust.into()),
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/show_share_words.rs b/core/embed/rust/src/ui/layout_delizia/flow/show_share_words.rs
index e00889d4..1dcf92b8 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/show_share_words.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/show_share_words.rs
@@ -106,8 +106,8 @@ pub fn new_show_share_words(
title,
InternallySwipableContent::new(ShareWords::new(share_words_vec, subtitle)),
)
- .with_swipe(Direction::Up, SwipeSettings::default())
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Up, SwipeSettings::Default)
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.with_vertical_pages()
.with_subtitle(subtitle)
.register_header_update_fn(header_updating_func)
@@ -120,7 +120,7 @@ pub fn new_show_share_words(
SwipeContent::new(PromptScreen::new_hold_to_confirm()),
)
.with_footer(TR::instructions__hold_to_confirm.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(|_| Some(FlowMsg::Confirmed));
let content_check_backup_intro = Frame::left_aligned(
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/show_tutorial.rs b/core/embed/rust/src/ui/layout_delizia/flow/show_tutorial.rs
index 25b9d81d..86e06f6f 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/show_tutorial.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/show_tutorial.rs
@@ -94,7 +94,7 @@ pub fn new_show_tutorial() -> Result<SwipeFlow, error::Error> {
))),
)
.with_swipeup_footer(None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map_to_button_msg();
let content_step_menu = Frame::left_aligned(
@@ -107,7 +107,7 @@ pub fn new_show_tutorial() -> Result<SwipeFlow, error::Error> {
.with_menu_button()
.button_styled(theme::button_warning_low())
.with_swipeup_footer(None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map_to_button_msg();
let content_step_hold = Frame::left_aligned(
@@ -115,7 +115,7 @@ pub fn new_show_tutorial() -> Result<SwipeFlow, error::Error> {
SwipeContent::new(PromptScreen::new_hold_to_confirm()),
)
.with_footer(TR::instructions__hold_to_exit_tutorial.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm);
let content_step_done = Frame::left_aligned(
@@ -153,7 +153,7 @@ pub fn new_show_tutorial() -> Result<SwipeFlow, error::Error> {
SwipeContent::new(PromptScreen::new_hold_to_confirm_danger()),
)
.with_footer(TR::instructions__hold_to_exit_tutorial.into(), None)
- .with_swipe(Direction::Down, SwipeSettings::default())
+ .with_swipe(Direction::Down, SwipeSettings::Default)
.map(super::util::map_to_confirm);
let mut res = SwipeFlow::new(&ShowTutorial::StepWelcome)?;
diff --git a/core/embed/rust/src/ui/layout_delizia/flow/util.rs b/core/embed/rust/src/ui/layout_delizia/flow/util.rs
index f3999969..5f284048 100644
--- a/core/embed/rust/src/ui/layout_delizia/flow/util.rs
+++ b/core/embed/rust/src/ui/layout_delizia/flow/util.rs
@@ -268,15 +268,15 @@ impl ConfirmValue {
}
if self.swipe_up {
- frame = frame.with_swipe(Direction::Up, SwipeSettings::default());
+ frame = frame.with_swipe(Direction::Up, SwipeSettings::Default);
}
if self.swipe_down {
- frame = frame.with_swipe(Direction::Down, SwipeSettings::default());
+ frame = frame.with_swipe(Direction::Down, SwipeSettings::Default);
}
if self.swipe_right {
- frame = frame.with_swipe(Direction::Right, SwipeSettings::default());
+ frame = frame.with_swipe(Direction::Right, SwipeSettings::Default);
}
frame = frame.with_vertical_pages();
@@ -455,7 +455,7 @@ impl ShowInfoParams {
if self.cancel_button {
frame = frame
.with_cancel_button()
- .with_swipe(Direction::Right, SwipeSettings::immediate());
+ .with_swipe(Direction::Right, SwipeSettings::Immediate);
} else if self.menu_button {
frame = frame.with_menu_button()
}
@@ -464,11 +464,11 @@ impl ShowInfoParams {
}
if self.swipe_up {
- frame = frame.with_swipe(Direction::Up, SwipeSettings::default());
+ frame = frame.with_swipe(Direction::Up, SwipeSettings::Default);
}
if self.swipe_down {
- frame = frame.with_swipe(Direction::Down, SwipeSettings::default());
+ frame = frame.with_swipe(Direction::Down, SwipeSettings::Default);
}
frame = frame.with_vertical_pages();
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 e6ada129..dfcacfe3 100644
--- a/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs
+++ b/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs
@@ -1291,7 +1291,7 @@ impl FirmwareUI for UIDelizia {
SwipeContent::new(content).with_no_attach_anim(),
)
.with_footer(instruction, description)
- .with_swipe(Direction::Up, SwipeSettings::default())
+ .with_swipe(Direction::Up, SwipeSettings::Default)
.with_result_icon(theme::ICON_BULLET_CHECKMARK, theme::GREEN_LIGHT),
))?;
Ok(layout)
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rs
index 13fcb490..d0ed6cdd 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rs
@@ -54,8 +54,8 @@ impl<T: MenuItems> VerticalMenuScreen<T> {
offset_base: 0,
swipe: None,
swipe_config: SwipeConfig::new()
- .with_swipe(Direction::Up, SwipeSettings::default())
- .with_swipe(Direction::Down, SwipeSettings::default()),
+ .with_swipe(Direction::Up, SwipeSettings::Default)
+ .with_swipe(Direction::Down, SwipeSettings::Default),
}
}
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.