From 000eb6a0fbde4687bfefe4c4e05a4f37ab686807 Mon Sep 17 00:00:00 2001 From: Marko Bencun Date: Thu, 18 May 2023 05:03:58 +0200 Subject: [PATCH] ui/components/menu: rename continue to finish The component could be at the end or in the middle of a workflow. "finish" just means that the component is done and the name does not assume if something comes after or not, whereas "continue" implies something should come after. --- src/rust/bitbox02-rust/src/workflow/menu.rs | 2 +- .../bitbox02-rust/src/workflow/mnemonic.rs | 4 +-- src/rust/bitbox02/src/ui/types.rs | 6 ++-- src/rust/bitbox02/src/ui/ui.rs | 28 ++++++++-------- src/rust/bitbox02/src/ui/ui_stub.rs | 4 +-- src/ui/components/menu.c | 32 +++++++++---------- src/ui/components/menu.h | 6 ++-- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/rust/bitbox02-rust/src/workflow/menu.rs b/src/rust/bitbox02-rust/src/workflow/menu.rs index fe46ec1fa7..1819309e40 100644 --- a/src/rust/bitbox02-rust/src/workflow/menu.rs +++ b/src/rust/bitbox02-rust/src/workflow/menu.rs @@ -28,7 +28,7 @@ pub async fn pick(words: &[&str], title: Option<&str>) -> Result Result<(), CancelError> { words, title: None, select_word_cb: None, - continue_on_last_cb: Some(Box::new(|| { + finish_on_last_cb: Some(Box::new(|| { set_result(&result, ()); })), cancel_cb: Some(Box::new(|| { @@ -57,7 +57,7 @@ pub async fn confirm_word(choices: &[&str], title: &str) -> Result TrinaryInputStringParams<'a> { } pub type SelectWordCb<'a> = Box; -pub type ContinueCancelCb<'a> = Box; +pub type FinishCancelCb<'a> = Box; pub struct MenuParams<'a> { pub words: &'a [&'a str], pub title: Option<&'a str>, pub select_word_cb: Option>, - pub continue_on_last_cb: Option>, - pub cancel_cb: Option>, + pub finish_on_last_cb: Option>, + pub cancel_cb: Option>, } pub type TrinaryChoiceCb<'a> = Box; diff --git a/src/rust/bitbox02/src/ui/ui.rs b/src/rust/bitbox02/src/ui/ui.rs index a812b2b453..6a194296c3 100644 --- a/src/rust/bitbox02/src/ui/ui.rs +++ b/src/rust/bitbox02/src/ui/ui.rs @@ -14,7 +14,7 @@ // limitations under the License. pub use super::types::{ - AcceptRejectCb, ConfirmParams, ContinueCancelCb, Font, MenuParams, SelectWordCb, TrinaryChoice, + AcceptRejectCb, ConfirmParams, FinishCancelCb, Font, MenuParams, SelectWordCb, TrinaryChoice, TrinaryChoiceCb, TrinaryInputStringParams, }; @@ -67,7 +67,7 @@ impl<'a> Drop for Component<'a> { pub fn trinary_input_string_create<'a, F>( params: &TrinaryInputStringParams, confirm_callback: F, - cancel_callback: Option>, + cancel_callback: Option>, ) -> Component<'a> where // Callback must outlive component. @@ -89,7 +89,7 @@ where } unsafe extern "C" fn c_cancel_callback(param: *mut c_void) { - let callback = param as *mut ContinueCancelCb; + let callback = param as *mut FinishCancelCb; (*callback)(); } @@ -117,7 +117,7 @@ where on_drop: Some(Box::new(move || unsafe { // Drop all callbacks. if !cancel_cb_param.is_null() { - drop(Box::from_raw(cancel_cb_param as *mut ContinueCancelCb)); + drop(Box::from_raw(cancel_cb_param as *mut FinishCancelCb)); } })), _p: PhantomData, @@ -234,8 +234,8 @@ pub fn menu_create(params: MenuParams<'_>) -> Component<'_> { (*callback)(word_idx); } - unsafe extern "C" fn c_continue_cancel_cb(param: *mut c_void) { - let callback = param as *mut ContinueCancelCb; + unsafe extern "C" fn c_finish_cancel_cb(param: *mut c_void) { + let callback = param as *mut FinishCancelCb; (*callback)(); } @@ -261,10 +261,10 @@ pub fn menu_create(params: MenuParams<'_>) -> Component<'_> { ), }; - let (continue_on_last_cb, continue_on_last_cb_param) = match params.continue_on_last_cb { + let (finish_on_last_cb, finish_on_last_cb_param) = match params.finish_on_last_cb { None => (None, core::ptr::null_mut()), Some(cb) => ( - Some(c_continue_cancel_cb as _), + Some(c_finish_cancel_cb as _), Box::into_raw(Box::new(cb)) as *mut c_void, ), }; @@ -272,7 +272,7 @@ pub fn menu_create(params: MenuParams<'_>) -> Component<'_> { let (cancel_cb, cancel_cb_param) = match params.cancel_cb { None => (None, core::ptr::null_mut()), Some(cb) => ( - Some(c_continue_cancel_cb as _), + Some(c_finish_cancel_cb as _), Box::into_raw(Box::new(cb)) as *mut c_void, ), }; @@ -289,8 +289,8 @@ pub fn menu_create(params: MenuParams<'_>) -> Component<'_> { title .as_ref() .map_or_else(|| core::ptr::null(), |title| title.as_ptr()), - continue_on_last_cb, - continue_on_last_cb_param, + finish_on_last_cb, + finish_on_last_cb_param, cancel_cb, cancel_cb_param, core::ptr::null_mut(), @@ -304,13 +304,13 @@ pub fn menu_create(params: MenuParams<'_>) -> Component<'_> { if !select_word_cb_param.is_null() { drop(Box::from_raw(select_word_cb_param as *mut SelectWordCb)); } - if !continue_on_last_cb_param.is_null() { + if !finish_on_last_cb_param.is_null() { drop(Box::from_raw( - continue_on_last_cb_param as *mut ContinueCancelCb, + finish_on_last_cb_param as *mut FinishCancelCb, )); } if !cancel_cb_param.is_null() { - drop(Box::from_raw(cancel_cb_param as *mut ContinueCancelCb)); + drop(Box::from_raw(cancel_cb_param as *mut FinishCancelCb)); } })), _p: PhantomData, diff --git a/src/rust/bitbox02/src/ui/ui_stub.rs b/src/rust/bitbox02/src/ui/ui_stub.rs index 4f1efbb7c7..69587852d7 100644 --- a/src/rust/bitbox02/src/ui/ui_stub.rs +++ b/src/rust/bitbox02/src/ui/ui_stub.rs @@ -15,7 +15,7 @@ //! Stubs for testing. pub use super::types::{ - AcceptRejectCb, ConfirmParams, ContinueCancelCb, Font, MenuParams, SelectWordCb, TrinaryChoice, + AcceptRejectCb, ConfirmParams, FinishCancelCb, Font, MenuParams, SelectWordCb, TrinaryChoice, TrinaryChoiceCb, TrinaryInputStringParams, }; @@ -50,7 +50,7 @@ impl<'a> Drop for Component<'a> { pub fn trinary_input_string_create<'a, F>( params: &TrinaryInputStringParams, mut confirm_callback: F, - _cancel_callback: Option>, + _cancel_callback: Option>, ) -> Component<'a> where F: FnMut(SafeInputString) + 'a, diff --git a/src/ui/components/menu.c b/src/ui/components/menu.c index 198c352e97..fab1df30b8 100644 --- a/src/ui/components/menu.c +++ b/src/ui/components/menu.c @@ -41,20 +41,20 @@ typedef struct { int32_t diff_to_middle; void (*select_word_cb)(uint8_t, void*); void* select_word_cb_param; - component_t* continue_on_last_button; - void (*continue_on_last_cb)(void*); - void* continue_on_last_cb_param; + component_t* finish_on_last_button; + void (*finish_on_last_cb)(void*); + void* finish_on_last_cb_param; void (*cancel_cb)(void*); void* cancel_cb_param; } menu_data_t; static const uint8_t part_width = 20; -static void _continue(component_t* component) +static void _finish(component_t* component) { menu_data_t* data = (menu_data_t*)component->parent->data; - if (data->continue_on_last_cb != NULL) { - data->continue_on_last_cb(data->continue_on_last_cb_param); + if (data->finish_on_last_cb != NULL) { + data->finish_on_last_cb(data->finish_on_last_cb_param); } } @@ -105,11 +105,11 @@ static void _update_positions(component_t* menu, int32_t velocity) _display_index(menu); } - if (data->index == data->length - 1 && data->continue_on_last_cb != NULL && - data->continue_on_last_button == NULL) { - data->continue_on_last_button = - button_create("Continue", top_slider, SCREEN_WIDTH - 23, _continue, menu); - ui_util_add_sub_component(menu, data->continue_on_last_button); + if (data->index == data->length - 1 && data->finish_on_last_cb != NULL && + data->finish_on_last_button == NULL) { + data->finish_on_last_button = + button_create("Continue", top_slider, SCREEN_WIDTH - 23, _finish, menu); + ui_util_add_sub_component(menu, data->finish_on_last_button); } } @@ -236,8 +236,8 @@ component_t* menu_create( void* select_word_cb_param, const uint8_t length, const char* title, - void (*continue_on_last_cb)(void*), - void* continue_on_last_cb_param, + void (*finish_on_last_cb)(void*), + void* finish_on_last_cb_param, void (*cancel_cb)(void*), void* cancel_cb_param, component_t* parent) @@ -271,9 +271,9 @@ component_t* menu_create( data->length = length; data->index = 0; data->show_index = !title; - data->continue_on_last_cb = continue_on_last_cb; - data->continue_on_last_cb_param = continue_on_last_cb_param; - data->continue_on_last_button = NULL; + data->finish_on_last_cb = finish_on_last_cb; + data->finish_on_last_cb_param = finish_on_last_cb_param; + data->finish_on_last_button = NULL; data->cancel_cb = cancel_cb; data->cancel_cb_param = cancel_cb_param; menu->data = data; diff --git a/src/ui/components/menu.h b/src/ui/components/menu.h index a685721675..e27714b232 100644 --- a/src/ui/components/menu.h +++ b/src/ui/components/menu.h @@ -28,7 +28,7 @@ * @param[in] title Title for the window. * If NULL, displays the index of the current word instead (starting at 1). * For no title, set this to "". - * @param[in] continue_on_last_cb If set, a checkmark appears when reaching the last word, calling + * @param[in] finish_on_last_cb If set, a checkmark appears when reaching the last word, calling * this callback. * @param[in] cancel_cb Called when the cancel button is pressed. * @param[in] parent The parent component. @@ -39,8 +39,8 @@ component_t* menu_create( void* select_word_cb_param, uint8_t length, const char* title, - void (*continue_on_last_cb)(void*), - void* continue_on_last_cb_param, + void (*finish_on_last_cb)(void*), + void* finish_on_last_cb_param, void (*cancel_cb)(void*), void* cancel_cb_param, component_t* parent);