Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix examples #183

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ fn main() -> Result<(), LvError> {

let mut screen_style = Style::default();
screen_style.set_bg_color(Color::from_rgb((0, 0, 0)));
screen.add_style(Part::Main, &mut screen_style)?;
screen.add_style(Part::Main, &mut screen_style);
// Create the button
let mut button = Btn::create(&mut screen)?;
button.set_align(Align::LeftMid, 30, 0)?;
button.set_size(180, 80)?;
button.set_align(Align::LeftMid, 30, 0);
button.set_size(180, 80);
let mut btn_lbl = Label::create(&mut button)?;
btn_lbl.set_text(CString::new("Click me!").unwrap().as_c_str())?;

let mut btn_state = false;

let mut anim = Animation::new(&mut button, Duration::from_secs(1), 0, 60, |obj, val| {
obj.set_align(Align::LeftMid, val, 0).unwrap()
obj.set_align(Align::LeftMid, val, 0)
})?;
anim.set_repeat_count(AnimRepeatCount::Infinite);
anim.start();
Expand Down
14 changes: 7 additions & 7 deletions examples/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ fn main() -> Result<(), LvError> {
let mut screen_style = Style::default();
screen_style.set_bg_color(Color::from_rgb((255, 255, 255)));
screen_style.set_radius(0);
screen.add_style(Part::Main, &mut screen_style)?;
screen.add_style(Part::Main, &mut screen_style);

// Create the arc object
let mut arc = Arc::create(&mut screen)?;
arc.set_size(150, 150)?;
arc.set_align(Align::Center, 0, 10)?;
arc.set_start_angle(135)?;
arc.set_end_angle(135)?;
arc.set_size(150, 150);
arc.set_align(Align::Center, 0, 10);
arc.set_start_angle(135);
arc.set_end_angle(135);

let mut loading_lbl = Label::create(&mut screen)?;
loading_lbl.set_text(CString::new("Loading...").unwrap().as_c_str())?;
loading_lbl.set_align(Align::OutTopMid, 0, 0)?;
loading_lbl.set_align(Align::OutTopMid, 0, 0);
//loading_lbl.set_label_align(LabelAlign::Center)?;

let mut loading_style = Style::default();
loading_style.set_text_color(Color::from_rgb((0, 0, 0)));
loading_lbl.add_style(Part::Main, &mut loading_style)?;
loading_lbl.add_style(Part::Main, &mut loading_style);

let mut angle = 0;
let mut forward = true;
Expand Down
21 changes: 12 additions & 9 deletions examples/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ fn main() -> Result<(), LvError> {
let mut screen_style = Style::default();
screen_style.set_bg_color(Color::from_rgb((255, 255, 255)));
screen_style.set_radius(0);
screen.add_style(Part::Main, &mut screen_style)?;
screen.add_style(Part::Main, &mut screen_style);

// Create the bar object
let mut bar = Bar::create(&mut screen)?;
bar.set_size(175, 20)?;
bar.set_align(Align::Center, 0, 10)?;
bar.set_size(175, 20);
bar.set_align(Align::Center, 0, 10);
bar.set_range(0, 100)?;
bar.on_event(|_b, _e| {
println!("Completed!");
Expand All @@ -47,24 +47,27 @@ fn main() -> Result<(), LvError> {
// Set the indicator style for the bar object
let mut ind_style = Style::default();
ind_style.set_bg_color(Color::from_rgb((100, 245, 100)));
bar.add_style(Part::Any, &mut ind_style)?;
bar.add_style(Part::Any, &mut ind_style);

let mut loading_lbl = Label::create(&mut screen)?;
loading_lbl.set_text(CString::new("Loading...").unwrap().as_c_str())?;
loading_lbl.set_align(Align::OutTopMid, 0, 0)?;
loading_lbl.set_align(Align::OutTopMid, 0, 0);

let mut loading_style = Style::default();
loading_style.set_text_color(Color::from_rgb((0, 0, 0)));
loading_lbl.add_style(Part::Main, &mut loading_style)?;
loading_lbl.add_style(Part::Main, &mut loading_style);

let mut i = 0;
'running: loop {
let start = Instant::now();
if i > 100 {
i = 0;
lvgl::event_send(&mut bar, Event::Clicked)?;
// Enabling this line gives the followong errors:
// - error[E0597]: `ind_style` does not live long enough when adding an style to the bar
C47D marked this conversation as resolved.
Show resolved Hide resolved
// - implementation of `Widget` is not general enough
C47D marked this conversation as resolved.
Show resolved Hide resolved
// lvgl::event_send(&mut bar, Event::Clicked);
}
bar.set_value(i, AnimationState::ON)?;
bar.set_value(i, AnimationState::ON);
i += 1;

lvgl::task_handler();
Expand All @@ -76,7 +79,7 @@ fn main() -> Result<(), LvError> {
_ => {}
}
}
sleep(Duration::from_millis(15));
sleep(Duration::from_millis(1500));
C47D marked this conversation as resolved.
Show resolved Hide resolved
lvgl::tick_inc(Instant::now().duration_since(start));
}

Expand Down
6 changes: 3 additions & 3 deletions examples/button_click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ fn main() -> Result<(), LvError> {

let mut screen_style = Style::default();
screen_style.set_bg_color(Color::from_rgb((0, 0, 0)));
screen.add_style(Part::Main, &mut screen_style)?;
screen.add_style(Part::Main, &mut screen_style);
// Create the button
let mut button = Btn::create(&mut screen)?;
button.set_align(Align::LeftMid, 30, 0)?;
button.set_size(180, 80)?;
button.set_align(Align::LeftMid, 30, 0);
button.set_size(180, 80);
let mut btn_lbl = Label::create(&mut button)?;
btn_lbl.set_text(CString::new("Click me!").unwrap().as_c_str())?;

Expand Down
Loading