From fad9682201cf9289bba2adb66e6e07ed1cf78936 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Mon, 3 Mar 2025 14:58:03 +0100 Subject: [PATCH] fix(core): fix delizia set brightness setting [no changelog] (cherry picked from commit 55101b8013c8e7041f4209540e8787fdc6e66cb4) --- .../src/ui/layout_delizia/component/frame.rs | 7 +++- .../component/number_input_slider.rs | 38 ++++++------------- .../ui/layout_delizia/flow/set_brightness.rs | 22 ++++++++++- 3 files changed, 37 insertions(+), 30 deletions(-) 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 4bc2539bdf..0eee6ad6b5 100644 --- a/core/embed/rust/src/ui/layout_delizia/component/frame.rs +++ b/core/embed/rust/src/ui/layout_delizia/component/frame.rs @@ -89,7 +89,7 @@ pub struct Frame { header: Header, header_update_fn: Option, footer: Option>, - footer_update_fn: Option, + footer_update_fn: Option)>, swipe: SwipeConfig, horizontal_swipe: HorizontalSwipe, margin: usize, @@ -234,7 +234,10 @@ where self } - pub fn register_footer_update_fn(mut self, f: fn(&T, &mut EventCtx, &mut Footer)) -> Self { + pub fn register_footer_update_fn( + mut self, + f: fn(&T, &mut EventCtx, &mut Footer<'static>), + ) -> Self { self.footer_update_fn = Some(f); self } diff --git a/core/embed/rust/src/ui/layout_delizia/component/number_input_slider.rs b/core/embed/rust/src/ui/layout_delizia/component/number_input_slider.rs index ffa6161035..c520ff7f73 100644 --- a/core/embed/rust/src/ui/layout_delizia/component/number_input_slider.rs +++ b/core/embed/rust/src/ui/layout_delizia/component/number_input_slider.rs @@ -1,7 +1,6 @@ -use super::{theme, Footer}; +use super::theme; use crate::{ - strutil::{ShortString, TString}, - translations::TR, + strutil::ShortString, ui::{ component::{paginated::SinglePage, Component, Event, EventCtx}, constant::screen, @@ -18,7 +17,6 @@ pub enum NumberInputSliderDialogMsg { pub struct NumberInputSliderDialog { area: Rect, input: NumberInputSlider, - footer: Footer<'static>, min: u16, max: u16, val: u16, @@ -30,10 +28,6 @@ impl NumberInputSliderDialog { Self { area: Rect::zero(), input: NumberInputSlider::new(min, max, init_value), - footer: Footer::new::>( - TR::instructions__swipe_horizontally.into(), - Some(TR::setting__adjust.into()), - ), min, max, val: init_value, @@ -44,6 +38,14 @@ impl NumberInputSliderDialog { pub fn value(&self) -> u16 { self.input.value } + + pub fn init_value(&self) -> u16 { + self.init_val + } + + pub fn touching(&self) -> bool { + self.input.touching + } } const INPUT_AREA_HEIGHT: i16 = 91; @@ -54,12 +56,7 @@ impl Component for NumberInputSliderDialog { fn place(&mut self, bounds: Rect) -> Rect { self.area = bounds; - let whole_area = self.area.inset(Insets::bottom(theme::SPACING)); - let (remaining, footer_area) = whole_area.split_bottom(self.footer.height()); - self.footer.place(footer_area); - let content_area = remaining; - - let used_area = content_area + let used_area = bounds .inset(Insets::sides(theme::SPACING)) .inset(Insets::bottom(theme::SPACING)); @@ -77,18 +74,6 @@ impl Component for NumberInputSliderDialog { fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option { let msg_opt = self.input.event(ctx, event); - if self.val == self.init_val || self.input.touching { - self.footer - .update_instruction(ctx, TR::instructions__swipe_horizontally); - self.footer.update_description(ctx, TR::setting__adjust); - ctx.request_paint(); - } else { - self.footer - .update_instruction(ctx, TR::instructions__tap_to_continue); - self.footer.update_description(ctx, TR::setting__apply); - ctx.request_paint(); - } - msg_opt.map(|value| { self.val = value; Self::Msg::Changed(value) @@ -97,7 +82,6 @@ impl Component for NumberInputSliderDialog { fn render<'s>(&'s self, target: &mut impl Renderer<'s>) { self.input.render(target); - self.footer.render(target); } } 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 d25aea4ea6..c687befef6 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 @@ -6,12 +6,13 @@ use crate::{ translations::TR, trezorhal::display, ui::{ - component::{swipe_detect::SwipeSettings, FlowMsg}, + component::{swipe_detect::SwipeSettings, EventCtx, FlowMsg}, flow::{ base::{Decision, DecisionBuilder as _}, FlowController, SwipeFlow, }, geometry::Direction, + layout_delizia::component::Footer, }, }; @@ -63,6 +64,20 @@ impl FlowController for SetBrightness { static BRIGHTNESS: AtomicU8 = AtomicU8::new(0); +fn footer_update_fn( + content: &NumberInputSliderDialog, + ctx: &mut EventCtx, + footer: &mut Footer<'static>, +) { + if content.value() == content.init_value() || content.touching() { + footer.update_instruction(ctx, TR::instructions__swipe_horizontally); + footer.update_description(ctx, TR::setting__adjust); + } else { + footer.update_instruction(ctx, TR::instructions__tap_to_continue); + footer.update_description(ctx, TR::setting__apply); + } +} + pub fn new_set_brightness(brightness: Option) -> Result { let brightness = brightness.unwrap_or(theme::backlight::get_backlight_normal()); let content_slider = Frame::left_aligned( @@ -76,6 +91,11 @@ pub fn new_set_brightness(brightness: Option) -> Result { .with_subtitle(TR::homescreen__settings_subtitle.into()) .with_menu_button() .with_swipe(Direction::Up, SwipeSettings::default()) + .with_footer( + TR::instructions__swipe_horizontally.into(), + Some(TR::setting__adjust.into()), + ) + .register_footer_update_fn(footer_update_fn) .map(|msg| match msg { NumberInputSliderDialogMsg::Changed(n) => { display::backlight(n as _);