mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-25 07:48:10 +00:00
refactor(core): allow changing button font on R
By default, buttons have uppercased font. The addition is necessary to customize font on info buttons where we need normal font. [no changelog]
This commit is contained in:
parent
f9e55a215d
commit
f8fcb49ba6
@ -87,11 +87,6 @@ impl Button {
|
|||||||
self.content = ButtonContent::Text(text);
|
self.content = ButtonContent::Text(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Changing the style of the button.
|
|
||||||
pub fn set_style(&mut self, styles: ButtonStyleSheet) {
|
|
||||||
self.styles = styles;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setting the visual state of the button.
|
// Setting the visual state of the button.
|
||||||
fn set(&mut self, ctx: &mut EventCtx, state: State) {
|
fn set(&mut self, ctx: &mut EventCtx, state: State) {
|
||||||
if self.state != state {
|
if self.state != state {
|
||||||
@ -295,6 +290,7 @@ pub struct ButtonStyle {
|
|||||||
|
|
||||||
impl ButtonStyleSheet {
|
impl ButtonStyleSheet {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
font: Font,
|
||||||
normal_color: Color,
|
normal_color: Color,
|
||||||
active_color: Color,
|
active_color: Color,
|
||||||
with_outline: bool,
|
with_outline: bool,
|
||||||
@ -304,7 +300,7 @@ impl ButtonStyleSheet {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
normal: ButtonStyle {
|
normal: ButtonStyle {
|
||||||
font: theme::FONT_BUTTON,
|
font,
|
||||||
text_color: normal_color,
|
text_color: normal_color,
|
||||||
with_outline,
|
with_outline,
|
||||||
with_arms,
|
with_arms,
|
||||||
@ -312,7 +308,7 @@ impl ButtonStyleSheet {
|
|||||||
offset,
|
offset,
|
||||||
},
|
},
|
||||||
active: ButtonStyle {
|
active: ButtonStyle {
|
||||||
font: theme::FONT_BUTTON,
|
font,
|
||||||
text_color: active_color,
|
text_color: active_color,
|
||||||
with_outline,
|
with_outline,
|
||||||
with_arms,
|
with_arms,
|
||||||
@ -324,12 +320,14 @@ impl ButtonStyleSheet {
|
|||||||
|
|
||||||
// White text in normal mode.
|
// White text in normal mode.
|
||||||
pub fn default(
|
pub fn default(
|
||||||
|
font: Font,
|
||||||
with_outline: bool,
|
with_outline: bool,
|
||||||
with_arms: bool,
|
with_arms: bool,
|
||||||
fixed_width: Option<i16>,
|
fixed_width: Option<i16>,
|
||||||
offset: Offset,
|
offset: Offset,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new(
|
Self::new(
|
||||||
|
font,
|
||||||
theme::FG,
|
theme::FG,
|
||||||
theme::BG,
|
theme::BG,
|
||||||
with_outline,
|
with_outline,
|
||||||
@ -344,6 +342,7 @@ impl ButtonStyleSheet {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ButtonDetails {
|
pub struct ButtonDetails {
|
||||||
pub content: ButtonContent,
|
pub content: ButtonContent,
|
||||||
|
font: Font,
|
||||||
pub duration: Option<Duration>,
|
pub duration: Option<Duration>,
|
||||||
with_outline: bool,
|
with_outline: bool,
|
||||||
with_arms: bool,
|
with_arms: bool,
|
||||||
@ -357,6 +356,7 @@ impl ButtonDetails {
|
|||||||
pub fn text(text: TString<'static>) -> Self {
|
pub fn text(text: TString<'static>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
content: ButtonContent::Text(text),
|
content: ButtonContent::Text(text),
|
||||||
|
font: Font::NORMAL_UPPER,
|
||||||
duration: None,
|
duration: None,
|
||||||
with_outline: true,
|
with_outline: true,
|
||||||
with_arms: false,
|
with_arms: false,
|
||||||
@ -370,6 +370,7 @@ impl ButtonDetails {
|
|||||||
pub fn icon(icon: Icon) -> Self {
|
pub fn icon(icon: Icon) -> Self {
|
||||||
Self {
|
Self {
|
||||||
content: ButtonContent::Icon(icon),
|
content: ButtonContent::Icon(icon),
|
||||||
|
font: Font::NORMAL_UPPER,
|
||||||
duration: None,
|
duration: None,
|
||||||
with_outline: false,
|
with_outline: false,
|
||||||
with_arms: false,
|
with_arms: false,
|
||||||
@ -469,9 +470,16 @@ impl ButtonDetails {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specifying the font of the button.
|
||||||
|
pub fn with_font(mut self, font: Font) -> Self {
|
||||||
|
self.font = font;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Button style that should be applied.
|
/// Button style that should be applied.
|
||||||
pub fn style(&self) -> ButtonStyleSheet {
|
pub fn style(&self) -> ButtonStyleSheet {
|
||||||
ButtonStyleSheet::default(
|
ButtonStyleSheet::default(
|
||||||
|
self.font,
|
||||||
self.with_outline,
|
self.with_outline,
|
||||||
self.with_arms,
|
self.with_arms,
|
||||||
self.fixed_width,
|
self.fixed_width,
|
||||||
@ -539,7 +547,11 @@ impl ButtonLayout {
|
|||||||
Self::new(
|
Self::new(
|
||||||
Some(ButtonDetails::from_text_possible_icon(left)),
|
Some(ButtonDetails::from_text_possible_icon(left)),
|
||||||
Some(ButtonDetails::armed_text(middle)),
|
Some(ButtonDetails::armed_text(middle)),
|
||||||
Some(ButtonDetails::text("i".into()).with_fixed_width(theme::BUTTON_ICON_WIDTH)),
|
Some(
|
||||||
|
ButtonDetails::text("i".into())
|
||||||
|
.with_fixed_width(theme::BUTTON_ICON_WIDTH)
|
||||||
|
.with_font(Font::NORMAL),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,7 +560,11 @@ impl ButtonLayout {
|
|||||||
Self::new(
|
Self::new(
|
||||||
Some(ButtonDetails::cancel_icon()),
|
Some(ButtonDetails::cancel_icon()),
|
||||||
Some(ButtonDetails::armed_text(middle)),
|
Some(ButtonDetails::armed_text(middle)),
|
||||||
Some(ButtonDetails::text("i".into()).with_fixed_width(theme::BUTTON_ICON_WIDTH)),
|
Some(
|
||||||
|
ButtonDetails::text("i".into())
|
||||||
|
.with_fixed_width(theme::BUTTON_ICON_WIDTH)
|
||||||
|
.with_font(Font::NORMAL),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,7 +681,11 @@ impl ButtonLayout {
|
|||||||
Self::new(
|
Self::new(
|
||||||
Some(ButtonDetails::up_arrow_icon()),
|
Some(ButtonDetails::up_arrow_icon()),
|
||||||
Some(ButtonDetails::armed_text(text)),
|
Some(ButtonDetails::armed_text(text)),
|
||||||
Some(ButtonDetails::text("i".into()).with_fixed_width(theme::BUTTON_ICON_WIDTH)),
|
Some(
|
||||||
|
ButtonDetails::text("i".into())
|
||||||
|
.with_fixed_width(theme::BUTTON_ICON_WIDTH)
|
||||||
|
.with_font(Font::NORMAL),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user