-
-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DROP feat(core/ui): sending button requests from rust
this is supposed to go into main via #3714
- Loading branch information
Showing
16 changed files
with
361 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::strutil::TString; | ||
use num_traits::FromPrimitive; | ||
|
||
// ButtonRequestType from messages-common.proto | ||
// Eventually this should be generated | ||
#[derive(Clone, Copy, FromPrimitive)] | ||
#[repr(u16)] | ||
pub enum ButtonRequestCode { | ||
Other = 1, | ||
FeeOverThreshold = 2, | ||
ConfirmOutput = 3, | ||
ResetDevice = 4, | ||
ConfirmWord = 5, | ||
WipeDevice = 6, | ||
ProtectCall = 7, | ||
SignTx = 8, | ||
FirmwareCheck = 9, | ||
Address = 10, | ||
PublicKey = 11, | ||
MnemonicWordCount = 12, | ||
MnemonicInput = 13, | ||
UnknownDerivationPath = 15, | ||
RecoveryHomepage = 16, | ||
Success = 17, | ||
Warning = 18, | ||
PassphraseEntry = 19, | ||
PinEntry = 20, | ||
} | ||
|
||
impl ButtonRequestCode { | ||
pub fn num(&self) -> u16 { | ||
*self as u16 | ||
} | ||
|
||
pub fn with_type(self, br_type: &'static str) -> ButtonRequest { | ||
ButtonRequest::new(self, br_type.into()) | ||
} | ||
|
||
pub fn from(i: u16) -> Self { | ||
unwrap!(Self::from_u16(i)) | ||
} | ||
} | ||
|
||
const MAX_TYPE_LEN: usize = 32; | ||
|
||
#[derive(Clone)] | ||
pub struct ButtonRequest { | ||
pub code: ButtonRequestCode, | ||
pub br_type: TString<'static>, | ||
} | ||
|
||
impl ButtonRequest { | ||
pub fn new(code: ButtonRequestCode, br_type: TString<'static>) -> Self { | ||
ButtonRequest { code, br_type } | ||
} | ||
|
||
pub fn from_tstring(code: u16, br_type: TString<'static>) -> Self { | ||
ButtonRequest::new(ButtonRequestCode::from(code), br_type) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::ui::{ | ||
button_request::ButtonRequest, | ||
component::{Component, Event, EventCtx}, | ||
geometry::Rect, | ||
}; | ||
|
||
/// Component that sends a ButtonRequest after receiving Event::Attach. The | ||
/// request is only sent once. | ||
#[derive(Clone)] | ||
pub struct OneButtonRequest<T> { | ||
button_request: Option<ButtonRequest>, | ||
pub inner: T, | ||
} | ||
|
||
impl<T> OneButtonRequest<T> { | ||
pub fn new(button_request: ButtonRequest, inner: T) -> Self { | ||
Self { | ||
button_request: Some(button_request), | ||
inner, | ||
} | ||
} | ||
} | ||
|
||
impl<T: Component> Component for OneButtonRequest<T> { | ||
type Msg = T::Msg; | ||
|
||
fn place(&mut self, bounds: Rect) -> Rect { | ||
self.inner.place(bounds) | ||
} | ||
|
||
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> { | ||
if matches!(event, Event::Attach) { | ||
if let Some(button_request) = self.button_request.take() { | ||
ctx.send_button_request(button_request.code, button_request.br_type) | ||
} | ||
} | ||
self.inner.event(ctx, event) | ||
} | ||
|
||
fn paint(&mut self) { | ||
self.inner.paint() | ||
} | ||
|
||
fn render<'s>(&'s self, target: &mut impl crate::ui::shape::Renderer<'s>) { | ||
self.inner.render(target) | ||
} | ||
} | ||
|
||
#[cfg(feature = "ui_debug")] | ||
impl<T: crate::trace::Trace> crate::trace::Trace for OneButtonRequest<T> { | ||
fn trace(&self, t: &mut dyn crate::trace::Tracer) { | ||
self.inner.trace(t) | ||
} | ||
} | ||
|
||
pub trait ButtonRequestExt { | ||
fn one_button_request(self, br: ButtonRequest) -> OneButtonRequest<Self> | ||
where | ||
Self: Sized, | ||
{ | ||
OneButtonRequest::new(br, self) | ||
} | ||
} | ||
|
||
impl<T: Component> ButtonRequestExt for T {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.