Skip to content

Commit

Permalink
Merge pull request #98 from LedgerHQ/feat/merge_ui_sdk
Browse files Browse the repository at this point in the history
Feat/merge UI sdk
  • Loading branch information
yogh333 authored Dec 1, 2023
2 parents 27ad410 + d8b5657 commit 1f68134
Show file tree
Hide file tree
Showing 46 changed files with 148 additions and 219 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[workspace]
members = [
"ledger_device_sdk",
"ledger_device_ui_sdk",
"ledger_secure_sdk_sys",
"include_gif"
]
Expand Down
2 changes: 1 addition & 1 deletion include_gif/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "include_gif"
version = "1.0.0"
version = "1.0.1"
edition = "2021"
license.workspace = true
description = "procedural macro that packs a gif image into a byte representation"
Expand Down
10 changes: 7 additions & 3 deletions include_gif/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
extern crate proc_macro;

use proc_macro::TokenStream;
use std;
use std::fs::File;
use std::io::Write;
use syn;

#[proc_macro]
pub fn include_gif(input: TokenStream) -> TokenStream {
let filename = syn::parse_macro_input!(input as syn::LitStr);
let mut decoder = gif::DecodeOptions::new();
decoder.set_color_output(gif::ColorOutput::Indexed);
let file = File::open(filename.value()).unwrap();

let path = format!(
"{}/{}",
std::env::var("CARGO_MANIFEST_DIR").unwrap(),
filename.value()
);
let file = File::open(path).unwrap();
let mut decoder = decoder.read_info(file).unwrap();

let frame = decoder.read_next_frame().unwrap().unwrap().clone();
Expand Down
8 changes: 5 additions & 3 deletions ledger_device_sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ledger_device_sdk"
version = "1.0.1"
authors = ["yhql"]
version = "1.1.0"
authors = ["yhql", "yogh333"]
edition = "2021"
license.workspace = true
description = "Ledger device Rust SDK"
Expand All @@ -14,10 +14,12 @@ ledger_device_sdk = { path = ".", features = ["speculos"] }
testmacro = { git = "https://github.com/yhql/testmacro"}

[dependencies]
ledger_secure_sdk_sys = "1.0.1"
ledger_secure_sdk_sys = {path = "../ledger_secure_sdk_sys", version = "1.0.2"}
include_gif = {path = "../include_gif", version = "1.0.1"}
num-traits = { version = "0.2.14", default_features = false }
rand_core = { version = "0.6.3", default_features = false }
zeroize = { version = "1.6.0", default_features = false }
numtoa = "0.2.4"

[profile.release]
opt-level = 's'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ fn panic(_: &PanicInfo) -> ! {
}

use ledger_device_sdk::buttons::*;
use ledger_device_ui_sdk::layout::{Layout, Location, StringPlace};
use ledger_device_ui_sdk::ui;
use ledger_device_sdk::ui::gadgets;
use ledger_device_sdk::ui::layout::{Layout, Location, StringPlace};

fn wait_any() {
let mut buttons = ButtonsState::new();
loop {
match ui::get_event(&mut buttons) {
match gadgets::get_event(&mut buttons) {
Some(ButtonEvent::LeftButtonRelease)
| Some(ButtonEvent::RightButtonRelease)
| Some(ButtonEvent::BothButtonsRelease) => return,
Expand All @@ -25,34 +25,34 @@ fn wait_any() {

#[no_mangle]
extern "C" fn sample_main() {
ui::clear_screen();
ui::popup("Hello");
gadgets::clear_screen();
gadgets::popup("Hello");

ui::clear_screen();
gadgets::clear_screen();

["First", "Second"].place(Location::Middle, Layout::Centered, false);
wait_any();
ui::clear_screen();
gadgets::clear_screen();

["First Line", "Second Line", "Third Line"].place(Location::Middle, Layout::Centered, false);
wait_any();
ui::clear_screen();
gadgets::clear_screen();

["First Line", "Second Line", "Third Line", "Fourth"].place(
Location::Middle,
Layout::Centered,
false,
);
wait_any();
ui::clear_screen();
gadgets::clear_screen();

["Monero &", "Ethereum &", "Zcash &", "NanoPass"].place(
Location::Top,
Layout::LeftAligned,
false,
);
wait_any();
ui::clear_screen();
gadgets::clear_screen();

["Monero &", "Ethereum &", "Zcash &", "NanoPass"].place(
Location::Top,
Expand All @@ -62,20 +62,20 @@ extern "C" fn sample_main() {
wait_any();

let scrolled_message = "Arbitrary long text goes here, with numbers -1234567890";
ui::MessageScroller::new(scrolled_message).event_loop();
gadgets::MessageScroller::new(scrolled_message).event_loop();

loop {
match ui::Menu::new(&[&"Top0", &"Top1", &"Top2", &"Top3", &"Next"]).show() {
match gadgets::Menu::new(&[&"Top0", &"Top1", &"Top2", &"Top3", &"Next"]).show() {
0 => loop {
match ui::Menu::new(&[&"Top0_sub0", &"Back"]).show() {
0 => ui::popup("Top0_sub0_0"),
match gadgets::Menu::new(&[&"Top0_sub0", &"Back"]).show() {
0 => gadgets::popup("Top0_sub0_0"),
_ => break,
}
},
1 => loop {
match ui::Menu::new(&[&"Top1_sub0", &"Top1_sub1", &"Back"]).show() {
0 => ui::popup("Top1_sub0_0"),
1 => ui::popup("Top1_sub1_0"),
match gadgets::Menu::new(&[&"Top1_sub0", &"Top1_sub1", &"Back"]).show() {
0 => gadgets::popup("Top1_sub0_0"),
1 => gadgets::popup("Top1_sub1_0"),
_ => break,
}
},
Expand All @@ -86,18 +86,18 @@ extern "C" fn sample_main() {
}
}

let _ = ui::Validator::new("Confirm?").ask();
let _ = ui::MessageValidator::new(
let _ = gadgets::Validator::new("Confirm?").ask();
let _ = gadgets::MessageValidator::new(
&[&"Message Review"],
&[&"Confirm", &"message?"],
&[&"Cancel"],
)
.ask();

ui::clear_screen();
gadgets::clear_screen();

use ledger_device_ui_sdk::bagls::RectFull as Rect;
use ledger_device_ui_sdk::layout::Draw;
use ledger_device_sdk::ui::bagls::RectFull as Rect;
use ledger_device_sdk::ui::layout::Draw;

Rect::new()
.width(10)
Expand All @@ -116,17 +116,17 @@ extern "C" fn sample_main() {
.instant_display();
wait_any();

ui::clear_screen();
gadgets::clear_screen();

let checkmark = ledger_device_ui_sdk::bagls::CHECKMARK_ICON
let checkmark = ledger_device_sdk::ui::bagls::CHECKMARK_ICON
.set_x(0)
.set_y(4);
checkmark.instant_display();
ledger_device_ui_sdk::bagls::CROSS_ICON
ledger_device_sdk::ui::bagls::CROSS_ICON
.set_x(20)
.set_y(4)
.instant_display();
ledger_device_ui_sdk::bagls::COGGLE
ledger_device_sdk::ui::bagls::COGGLE_ICON
.set_x(40)
.set_y(4)
.instant_display();
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
2 changes: 2 additions & 0 deletions ledger_device_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![test_runner(testing::sdk_test_runner)]
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
#![feature(cfg_version)]

#[cfg(target_os = "nanox")]
pub mod ble;
Expand All @@ -20,6 +21,7 @@ pub mod seph;

pub mod testing;

pub mod ui;
pub mod uxapp;

use core::panic::PanicInfo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![no_std]
#![feature(cfg_version)]
#![cfg_attr(not(version("1.63")), feature(array_from_fn))]

pub mod bagls;
Expand All @@ -14,8 +12,8 @@ pub mod bitmaps;
pub mod fonts;
pub mod layout;

pub mod gadgets;
pub mod screen_util;
pub mod ui;

pub const PADDING: usize = 2;
pub const Y_PADDING: usize = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl RectFull {
}

const fn middle_y(glyph: &Glyph) -> i16 {
((crate::SCREEN_HEIGHT as u32 - glyph.height) / 2) as i16
((crate::ui::SCREEN_HEIGHT as u32 - glyph.height) / 2) as i16
}

pub struct Icon<'a> {
Expand Down Expand Up @@ -97,10 +97,10 @@ impl<'a> Icon<'a> {
}
}

use crate::bitmaps;
use crate::ui::bitmaps;

pub const OUTER_PADDING: usize = 2;
pub const SCREENW: i16 = (crate::SCREEN_WIDTH - OUTER_PADDING) as i16;
pub const SCREENW: i16 = (crate::ui::SCREEN_WIDTH - OUTER_PADDING) as i16;

pub const DOWN_ARROW: Icon =
Icon::from(&bitmaps::DOWN_ARROW).set_x(SCREENW - bitmaps::DOWN_ARROW.width as i16);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::Icon;
use crate::layout::{Draw, Layout, Location};
use crate::ui::layout::{Draw, Layout, Location};
use ledger_secure_sdk_sys;
use ledger_secure_sdk_sys::seph::SephTags;

Expand Down Expand Up @@ -379,19 +379,19 @@ impl<'a> SendToDisplay for Label<'a> {
};
let x = match self.layout {
Layout::RightAligned => self.layout.get_x(self.text.len() * 7),
Layout::Custom(x) => x as usize,
Layout::Custom(x) => x,
_ => 0,
};
let y = self.loc.get_y(self.dims.1 as usize) as i16;
let width = match self.layout {
Layout::Centered => crate::SCREEN_WIDTH,
Layout::Centered => crate::ui::SCREEN_WIDTH,
_ => self.text.len() * 6,
};
let alignment = match self.layout {
Layout::LeftAligned => 0 as u16,
Layout::LeftAligned => 0_u16,
Layout::Centered => BAGL_FONT_ALIGNMENT_CENTER as u16,
Layout::RightAligned => BAGL_FONT_ALIGNMENT_CENTER as u16,
Layout::Custom(_) => 0 as u16,
Layout::Custom(_) => 0_u16,
};
let baglcomp = BaglComponent {
type_: BaglTypes::LabelLine as u8,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::Icon;
use crate::fonts::OPEN_SANS;
use crate::layout::*;
use crate::ui::fonts::OPEN_SANS;
use crate::ui::layout::*;
use ledger_secure_sdk_sys;

pub struct Label<'a> {
Expand Down Expand Up @@ -63,13 +63,13 @@ impl Draw for Label<'_> {
total_width as u32,
c_height as u32,
false,
&crate::bitmaps::BLANK,
&crate::ui::bitmaps::BLANK,
)
}
}
}

use crate::bagls::RectFull;
use crate::ui::bagls::RectFull;

impl Draw for RectFull {
fn display(&self) {
Expand Down Expand Up @@ -139,7 +139,7 @@ impl<'a> Draw for Icon<'a> {
icon.width,
icon.height,
icon.inverted,
&crate::bitmaps::BLANK,
&crate::ui::bitmaps::BLANK,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::screen_util::draw;
use crate::ui::screen_util::draw;
use ledger_secure_sdk_sys;

pub struct Glyph<'a> {
Expand Down Expand Up @@ -32,7 +32,7 @@ impl<'a> Glyph<'a> {
}
}
pub fn draw(&self, x: i32, y: i32) {
draw(x, y, self.width, self.height, self.inverted, &self.bitmap);
draw(x, y, self.width, self.height, self.inverted, self.bitmap);
}
}

Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1f68134

Please sign in to comment.