mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-05 16:39:08 +00:00
fix(core): fix delizia set brightness setting
[no changelog]
(cherry picked from commit 55101b8013
)
This commit is contained in:
parent
5f94715ca7
commit
fad9682201
@ -89,7 +89,7 @@ pub struct Frame<T> {
|
|||||||
header: Header,
|
header: Header,
|
||||||
header_update_fn: Option<fn(&T, &mut EventCtx, &mut Header)>,
|
header_update_fn: Option<fn(&T, &mut EventCtx, &mut Header)>,
|
||||||
footer: Option<Footer<'static>>,
|
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,
|
swipe: SwipeConfig,
|
||||||
horizontal_swipe: HorizontalSwipe,
|
horizontal_swipe: HorizontalSwipe,
|
||||||
margin: usize,
|
margin: usize,
|
||||||
@ -234,7 +234,10 @@ where
|
|||||||
self
|
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.footer_update_fn = Some(f);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use super::{theme, Footer};
|
use super::theme;
|
||||||
use crate::{
|
use crate::{
|
||||||
strutil::{ShortString, TString},
|
strutil::ShortString,
|
||||||
translations::TR,
|
|
||||||
ui::{
|
ui::{
|
||||||
component::{paginated::SinglePage, Component, Event, EventCtx},
|
component::{paginated::SinglePage, Component, Event, EventCtx},
|
||||||
constant::screen,
|
constant::screen,
|
||||||
@ -18,7 +17,6 @@ pub enum NumberInputSliderDialogMsg {
|
|||||||
pub struct NumberInputSliderDialog {
|
pub struct NumberInputSliderDialog {
|
||||||
area: Rect,
|
area: Rect,
|
||||||
input: NumberInputSlider,
|
input: NumberInputSlider,
|
||||||
footer: Footer<'static>,
|
|
||||||
min: u16,
|
min: u16,
|
||||||
max: u16,
|
max: u16,
|
||||||
val: u16,
|
val: u16,
|
||||||
@ -30,10 +28,6 @@ impl NumberInputSliderDialog {
|
|||||||
Self {
|
Self {
|
||||||
area: Rect::zero(),
|
area: Rect::zero(),
|
||||||
input: NumberInputSlider::new(min, max, init_value),
|
input: NumberInputSlider::new(min, max, init_value),
|
||||||
footer: Footer::new::<TString<'static>>(
|
|
||||||
TR::instructions__swipe_horizontally.into(),
|
|
||||||
Some(TR::setting__adjust.into()),
|
|
||||||
),
|
|
||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
val: init_value,
|
val: init_value,
|
||||||
@ -44,6 +38,14 @@ impl NumberInputSliderDialog {
|
|||||||
pub fn value(&self) -> u16 {
|
pub fn value(&self) -> u16 {
|
||||||
self.input.value
|
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;
|
const INPUT_AREA_HEIGHT: i16 = 91;
|
||||||
@ -54,12 +56,7 @@ impl Component for NumberInputSliderDialog {
|
|||||||
fn place(&mut self, bounds: Rect) -> Rect {
|
fn place(&mut self, bounds: Rect) -> Rect {
|
||||||
self.area = bounds;
|
self.area = bounds;
|
||||||
|
|
||||||
let whole_area = self.area.inset(Insets::bottom(theme::SPACING));
|
let used_area = bounds
|
||||||
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
|
|
||||||
.inset(Insets::sides(theme::SPACING))
|
.inset(Insets::sides(theme::SPACING))
|
||||||
.inset(Insets::bottom(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> {
|
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
|
||||||
let msg_opt = self.input.event(ctx, event);
|
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| {
|
msg_opt.map(|value| {
|
||||||
self.val = value;
|
self.val = value;
|
||||||
Self::Msg::Changed(value)
|
Self::Msg::Changed(value)
|
||||||
@ -97,7 +82,6 @@ impl Component for NumberInputSliderDialog {
|
|||||||
|
|
||||||
fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
|
fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
|
||||||
self.input.render(target);
|
self.input.render(target);
|
||||||
self.footer.render(target);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,12 +6,13 @@ use crate::{
|
|||||||
translations::TR,
|
translations::TR,
|
||||||
trezorhal::display,
|
trezorhal::display,
|
||||||
ui::{
|
ui::{
|
||||||
component::{swipe_detect::SwipeSettings, FlowMsg},
|
component::{swipe_detect::SwipeSettings, EventCtx, FlowMsg},
|
||||||
flow::{
|
flow::{
|
||||||
base::{Decision, DecisionBuilder as _},
|
base::{Decision, DecisionBuilder as _},
|
||||||
FlowController, SwipeFlow,
|
FlowController, SwipeFlow,
|
||||||
},
|
},
|
||||||
geometry::Direction,
|
geometry::Direction,
|
||||||
|
layout_delizia::component::Footer,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -63,6 +64,20 @@ impl FlowController for SetBrightness {
|
|||||||
|
|
||||||
static BRIGHTNESS: AtomicU8 = AtomicU8::new(0);
|
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> {
|
pub fn new_set_brightness(brightness: Option<u8>) -> Result<SwipeFlow, Error> {
|
||||||
let brightness = brightness.unwrap_or(theme::backlight::get_backlight_normal());
|
let brightness = brightness.unwrap_or(theme::backlight::get_backlight_normal());
|
||||||
let content_slider = Frame::left_aligned(
|
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_subtitle(TR::homescreen__settings_subtitle.into())
|
||||||
.with_menu_button()
|
.with_menu_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()),
|
||||||
|
)
|
||||||
|
.register_footer_update_fn(footer_update_fn)
|
||||||
.map(|msg| match msg {
|
.map(|msg| match msg {
|
||||||
NumberInputSliderDialogMsg::Changed(n) => {
|
NumberInputSliderDialogMsg::Changed(n) => {
|
||||||
display::backlight(n as _);
|
display::backlight(n as _);
|
||||||
|
Loading…
Reference in New Issue
Block a user