Skip to content

Commit e353f7d

Browse files
committed
Use enum to set the page to be displayed
1 parent 4e47ade commit e353f7d

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

ledger_device_sdk/src/nbgl/nbgl_home_and_settings.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ const INFO_FIELDS: [*const c_char; 2] = [
3838
"Developer\0".as_ptr() as *const c_char,
3939
];
4040

41+
pub enum PageIndex {
42+
Settings(u8),
43+
Home,
44+
}
45+
4146
/// Used to display the home screen of the application, with an optional glyph,
4247
/// information fields, and settings switches.
4348
pub struct NbglHomeAndSettings {
@@ -50,7 +55,7 @@ pub struct NbglHomeAndSettings {
5055
generic_contents: nbgl_genericContents_t,
5156
info_list: nbgl_contentInfoList_t,
5257
icon: nbgl_icon_details_t,
53-
start_page: u8,
58+
start_page: PageIndex,
5459
}
5560

5661
impl SyncNBGL for NbglHomeAndSettings {}
@@ -77,7 +82,7 @@ impl<'a> NbglHomeAndSettings {
7782
generic_contents: nbgl_genericContents_t::default(),
7883
info_list: nbgl_contentInfoList_t::default(),
7984
icon: nbgl_icon_details_t::default(),
80-
start_page: INIT_HOME_PAGE as u8,
85+
start_page: PageIndex::Home,
8186
}
8287
}
8388

@@ -129,7 +134,7 @@ impl<'a> NbglHomeAndSettings {
129134
}
130135
}
131136

132-
pub fn set_page(self, page: u8) -> NbglHomeAndSettings {
137+
pub fn set_page(self, page: PageIndex) -> NbglHomeAndSettings {
133138
NbglHomeAndSettings {
134139
start_page: page,
135140
..self
@@ -195,7 +200,10 @@ impl<'a> NbglHomeAndSettings {
195200
self.app_name.as_ptr() as *const c_char,
196201
&self.icon as *const nbgl_icon_details_t,
197202
core::ptr::null(),
198-
self.start_page,
203+
match self.start_page {
204+
PageIndex::Home => INIT_HOME_PAGE as u8,
205+
PageIndex::Settings(idx) => idx,
206+
},
199207
&self.generic_contents as *const nbgl_genericContents_t,
200208
&self.info_list as *const nbgl_contentInfoList_t,
201209
core::ptr::null(),
@@ -272,7 +280,10 @@ impl<'a> NbglHomeAndSettings {
272280
self.app_name.as_ptr() as *const c_char,
273281
&self.icon as *const nbgl_icon_details_t,
274282
core::ptr::null(),
275-
self.start_page,
283+
match self.start_page {
284+
PageIndex::Home => INIT_HOME_PAGE as u8,
285+
PageIndex::Settings(idx) => idx,
286+
},
276287
&self.generic_contents as *const nbgl_genericContents_t,
277288
&self.info_list as *const nbgl_contentInfoList_t,
278289
core::ptr::null(),

0 commit comments

Comments
 (0)