mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-06 10:16:07 +00:00
fix(core): fix delizia set brightness setting
[no changelog]
This commit is contained in:
parent
f59deebfba
commit
55101b8013
@ -89,7 +89,7 @@ pub struct Frame<T> {
|
||||
header: Header,
|
||||
header_update_fn: Option<fn(&T, &mut EventCtx, &mut Header)>,
|
||||
footer: Option<Footer<'static>>,
|
||||
footer_update_fn: Option<fn(&T, &mut EventCtx, &mut Footer)>,
|
||||
footer_update_fn: Option<fn(&T, &mut EventCtx, &mut Footer<'static>)>,
|
||||
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
|
||||
}
|
||||
|
@ -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::<TString<'static>>(
|
||||
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<Self::Msg> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<u8>) -> Result<SwipeFlow, Error> {
|
||||
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<u8>) -> Result<SwipeFlow, Error> {
|
||||
.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 _);
|
||||
|
Loading…
Reference in New Issue
Block a user