Skip to content

Commit 718b9ab

Browse files
committed
Fixes for using upstream UI lib
1 parent 1d7a1a6 commit 718b9ab

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/prompts.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use core::str::from_utf8;
55

66
use nanos_sdk::buttons::*;
77
use nanos_ui::bagls::*;
8+
use nanos_ui::layout::*;
9+
use nanos_ui::ui::clear_screen;
810

911
#[derive(Clone, Debug)]
1012
pub struct PromptQueue {
@@ -116,45 +118,44 @@ impl PromptQueue {
116118
let mut buttons = Default::default();
117119

118120
loop {
121+
clear_screen();
119122
// Display
120123
let (current_title, current_body) = title_and_body;
121124
match state {
122125
PromptingState::Prompts => {
123-
Bagl::LABELLINE(LabelLine::new().pos(0, 10).text(current_title.as_str()))
124-
.display();
126+
current_title.as_str().place(Location::Top, Layout::Centered, false);
125127
#[cfg(target_os = "nanos")]
126128
{
127-
Bagl::LABELLINE(LabelLine::new().pos(0, 25).text(current_body.as_str()))
128-
.paint();
129+
current_body.as_str().place(Location::Custom(15), Layout::Centered, false);
129130
}
130131
#[cfg(not(target_os = "nanos"))]
131132
{
132133
let mut iter = current_body.as_bytes().chunks(16);
133134
if let Some(body) = iter.next().map(|s| from_utf8(s).ok()).flatten() {
134-
Bagl::LABELLINE(LabelLine::new().pos(0, 25).text(body)).paint()
135+
body.place(Location::Custom(16), Layout::Centered, false);
135136
};
136137
if let Some(body) = iter.next().map(|s| from_utf8(s).ok()).flatten() {
137-
Bagl::LABELLINE(LabelLine::new().pos(0, 40).text(body)).paint()
138+
body.place(Location::Custom(31), Layout::Centered, false);
138139
};
139140
if let Some(body) = iter.next().map(|s| from_utf8(s).ok()).flatten() {
140-
Bagl::LABELLINE(LabelLine::new().pos(0, 55).text(body)).paint()
141+
body.place(Location::Custom(46), Layout::Centered, false);
141142
};
142143
}
143144
if backward.prev != [0; HASH_LENGTH] {
144-
LEFT_ARROW.paint();
145+
LEFT_ARROW.instant_display();
145146
}
146-
RIGHT_ARROW.paint();
147+
RIGHT_ARROW.instant_display();
147148
}
148149
PromptingState::Confirm => {
149-
Bagl::ICON(Icon::new(Icons::CheckBadge).pos(18, 12)).display();
150-
Bagl::LABELLINE(LabelLine::new().text("Confirm").pos(0, 20)).paint();
151-
LEFT_ARROW.paint();
152-
RIGHT_ARROW.paint();
150+
CHECKMARK_ICON.set_x(18).display();
151+
"Confirm".place(Location::Middle, Layout::Centered, false);
152+
LEFT_ARROW.instant_display();
153+
RIGHT_ARROW.instant_display();
153154
}
154155
PromptingState::Cancel => {
155-
Bagl::ICON(Icon::new(Icons::CrossBadge).pos(18, 12)).display();
156-
Bagl::LABELLINE(LabelLine::new().text("Cancel").pos(0, 20)).paint();
157-
LEFT_ARROW.paint();
156+
CROSS_ICON.set_x(18).display();
157+
"Reject".place(Location::Middle, Layout::Centered, false);
158+
LEFT_ARROW.instant_display();
158159
}
159160
}
160161
// Handle buttons

0 commit comments

Comments
 (0)