-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from LedgerHQ/y333/nbgl_spinner_integration
Update NBGL spinner: previous and new strings shall be stored to enab…
- Loading branch information
Showing
5 changed files
with
20 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
use super::*; | ||
extern crate alloc; | ||
use alloc::ffi::CString; | ||
|
||
/// A wrapper around the asynchronous NBGL nbgl_useCaseSpinner C API binding. | ||
/// Draws a spinner page with the given parameters. The spinner will "turn" automatically every | ||
/// 800 ms, provided the IO event loop is running to process TickerEvents. | ||
#[derive(Debug, Default)] | ||
pub struct NbglSpinner { | ||
text: CString, | ||
text: [CString; 2], | ||
write_idx: usize, | ||
read_idx: usize, | ||
} | ||
|
||
impl NbglSpinner { | ||
pub fn new() -> NbglSpinner { | ||
NbglSpinner { | ||
text: CString::new("").unwrap(), | ||
text: [CString::default(), CString::default()], | ||
write_idx: 0, | ||
read_idx: 0, | ||
} | ||
} | ||
|
||
pub fn text(self, text: &str) -> NbglSpinner { | ||
NbglSpinner { | ||
text: CString::new(text).unwrap(), | ||
} | ||
} | ||
|
||
pub fn show(&self) { | ||
/// Shows the spinner with the current text. | ||
/// Every call make the spinner "turn" to the next text. | ||
pub fn show(&mut self, text: &str) { | ||
self.text[self.write_idx] = CString::new(text).unwrap(); | ||
self.read_idx = self.write_idx; | ||
self.write_idx = (self.write_idx + 1) % 2; | ||
unsafe { | ||
nbgl_useCaseSpinner(self.text.as_ptr() as *const c_char); | ||
nbgl_useCaseSpinner(self.text[self.read_idx].as_ptr() as *const c_char); | ||
} | ||
} | ||
} |