mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-03 04:18:17 +00:00
refactor(core): use an enum
for Button
's radius/gradient
[no changelog]
This commit is contained in:
parent
a6f99a65b4
commit
0b4c44e32f
@ -27,6 +27,12 @@ pub enum ButtonMsg {
|
|||||||
LongPressed,
|
LongPressed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum RadiusOrGradient {
|
||||||
|
Radius(u8),
|
||||||
|
Gradient,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Button {
|
pub struct Button {
|
||||||
area: Rect,
|
area: Rect,
|
||||||
touch_expand: Insets,
|
touch_expand: Insets,
|
||||||
@ -34,12 +40,11 @@ pub struct Button {
|
|||||||
content_offset: Offset,
|
content_offset: Offset,
|
||||||
stylesheet: ButtonStyleSheet,
|
stylesheet: ButtonStyleSheet,
|
||||||
text_align: Alignment,
|
text_align: Alignment,
|
||||||
radius: Option<u8>,
|
radius_or_gradient: RadiusOrGradient,
|
||||||
state: State,
|
state: State,
|
||||||
long_press: Option<Duration>,
|
long_press: Option<Duration>,
|
||||||
long_timer: Timer,
|
long_timer: Timer,
|
||||||
haptic: bool,
|
haptic: bool,
|
||||||
gradient: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Button {
|
impl Button {
|
||||||
@ -69,12 +74,11 @@ impl Button {
|
|||||||
touch_expand: Insets::zero(),
|
touch_expand: Insets::zero(),
|
||||||
stylesheet: theme::button_default(),
|
stylesheet: theme::button_default(),
|
||||||
text_align: Alignment::Center,
|
text_align: Alignment::Center,
|
||||||
radius: None,
|
radius_or_gradient: RadiusOrGradient::None,
|
||||||
state: State::Initial,
|
state: State::Initial,
|
||||||
long_press: None,
|
long_press: None,
|
||||||
long_timer: Timer::new(),
|
long_timer: Timer::new(),
|
||||||
haptic: true,
|
haptic: true,
|
||||||
gradient: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,9 +174,7 @@ impl Button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_radius(mut self, radius: u8) -> Self {
|
pub fn with_radius(mut self, radius: u8) -> Self {
|
||||||
// Both radius and gradient not supported
|
self.radius_or_gradient = RadiusOrGradient::Radius(radius);
|
||||||
debug_assert!(!self.gradient);
|
|
||||||
self.radius = Some(radius);
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,9 +184,7 @@ impl Button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_gradient(mut self) -> Self {
|
pub fn with_gradient(mut self) -> Self {
|
||||||
// Using gradient with radius is not supported
|
self.radius_or_gradient = RadiusOrGradient::Gradient;
|
||||||
debug_assert!(self.radius.is_none());
|
|
||||||
self.gradient = true;
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,8 +377,8 @@ impl Button {
|
|||||||
style: &ButtonStyle,
|
style: &ButtonStyle,
|
||||||
alpha: u8,
|
alpha: u8,
|
||||||
) {
|
) {
|
||||||
match (self.radius, self.gradient) {
|
match self.radius_or_gradient {
|
||||||
(Some(radius), _) => {
|
RadiusOrGradient::Radius(radius) => {
|
||||||
shape::Bar::new(self.area)
|
shape::Bar::new(self.area)
|
||||||
.with_bg(style.background_color)
|
.with_bg(style.background_color)
|
||||||
.with_radius(radius as i16)
|
.with_radius(radius as i16)
|
||||||
@ -388,7 +388,7 @@ impl Button {
|
|||||||
.render(target);
|
.render(target);
|
||||||
}
|
}
|
||||||
// Gradient bar is rendered only in `normal` state, not `active` or `disabled`
|
// Gradient bar is rendered only in `normal` state, not `active` or `disabled`
|
||||||
(None, true) if self.state.is_normal() => {
|
RadiusOrGradient::Gradient if self.state.is_normal() => {
|
||||||
self.render_gradient_bar(target, style);
|
self.render_gradient_bar(target, style);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
Loading…
Reference in New Issue
Block a user