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

Implement proper font support #76

Merged
merged 4 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ on:
env:
CARGO_TERM_COLOR: always
DEP_LV_CONFIG_PATH: /home/runner/work/lvgl-rs/lvgl-rs/examples/include
LVGL_INCLUDE: /usr/include,/usr/local/include
LVGL_LINK: SDL2

jobs:
build:
Expand Down
63 changes: 63 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.5.2] - 2021-03-06

### Added

- Expose RGB values from Color #29
- Make lvgl possible to compile to WASM using Emscripten #31 (complete example available at [lvgl-rs-wasm](https://github.com/rafaelcaricio/lvgl-rs-wasm) and [live](https://rafaelcaricio.github.io/lvgl-rs-wasm/) on the web)

### Changed

- Updated README:
- Added a hint to install SDL2 before running the demos on macOS #36
- Add system dependencies for compilation #41

### Fixed

- Fix documentation generation, now we will be visible in docs.rs website 🥳 #41
- Fix compiler error when running the examples #40

## [0.4.0] - 2020-06-19

### Changed

- Simplify examples by removing the use of threads

### Removed

- Removes the dependency on `alloc` crate

## [0.3.1] - 2020-06-14

### Changed

- Replace `string.c` with implementation in Rust

## [0.3.0] - 2020-06-14

### Added

- New code generation for the safe bindings based on the [`syn`](https://docs.rs/syn/1.0.31/syn/index.html) crate. This uses `lvgl-codegen` directly, which implements code generation for known patterns. This avoids a lot of manual work to expose LVGL API as safe Rust API

### Changed

- Code generation is completely transparent to users
- The code in `lvgl-codegen` gets cleaner and intuitive to write, since now we are processing Rust code instead of C. C is completely abstracted at the `lvgl-sys`/`rust-bindgen` level

### Removed

- No (direct) dependency on `clang-rs`

[Unreleased]: https://github.com/rafaelcaricio/lvgl-rs/compare/0.5.2..HEAD
[0.5.2]: https://github.com/rafaelcaricio/lvgl-rs/compare/0.4.0..0.5.2
[0.4.0]: https://github.com/rafaelcaricio/lvgl-rs/compare/0.3.1..0.4.0
[0.3.1]: https://github.com/rafaelcaricio/lvgl-rs/compare/0.3.0..0.3.1
[0.3.0]: https://github.com/rafaelcaricio/lvgl-rs/releases/tag/0.3.0
5 changes: 5 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[build.env]
passthrough = ["DEP_LV_CONFIG_PATH", "LVGL_INCLUDE", "LVGL_LINK"]

# See https://github.com/rafaelcaricio/lvgl-rs/issues/78 for more details on
# the current status of `Cross` support.
# https://github.com/rafaelcaricio/lvgl-rs/issues/53 contains a way to get
# lvgl-rs building on armv7-unknown-linux-gnueabihf
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<h1 align="center"> LVGL - Open-source Embedded GUI Library in Rust</h1>

> This library is looking for a new maintainer. If you are intested in taking over the development, please open a
> ticket. I would like to find someone committed and with genuine interest to continue the work that I have started
> here. Initially, I will add the new maintainer as collaborator and after demonstrated interest, I will add
> as admin, etc. If you have forked and continued the development, please link your work this might speed up the
> process.


![Original LVGL demo image](lv_demo.png)

<p align="center">
Expand Down Expand Up @@ -112,9 +105,9 @@ List of LVGL features that impacts the library usage in general.
- [x] Events: You can listen and trigger events in widget objects.
- [x] Styles: You can set styles in any exposed object. We are still missing the possibility of defining global base styles.
- [x] Input Devices: Input devices supported by [`lv_drivers`](https://github.com/lvgl/lv_drivers)
can be used.
can be used, and custom handlers can be specified for [`embedded_graphics`](https://docs.rs/embedded-graphics/0.6.2/embedded_graphics/).
**Note:** [`lv_drivers`](https://github.com/lvgl/lv_drivers) support is currently experimental.
- [ ] Fonts
- [x] Fonts: All fonts built-in to LVGL can be used on nightly Rust if the `nightly` feature is enabled. Custom fonts can also be specified as TTF or encoded into a C file (see [the example `include`](https://github.com/rafaelcaricio/lvgl-rs/tree/master/examples/include)).
- [ ] Images
- [ ] File system
- [ ] Animations
Expand Down
1 change: 0 additions & 1 deletion examples/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::*;
use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window};
use lvgl;
use lvgl::widgets::Label;
use lvgl::{Display, DrawBuffer};
use std::cell::RefCell;

Expand Down
2 changes: 1 addition & 1 deletion examples/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use lvgl::style::Style;
use lvgl::widgets::{Arc, Label};
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part, Widget};
use lvgl_sys;
use std::thread::sleep;
use std::time::Duration;
use std::time::Instant;
use std::thread::sleep;

fn mem_info() -> lvgl_sys::lv_mem_monitor_t {
let mut info = lvgl_sys::lv_mem_monitor_t {
Expand Down
3 changes: 1 addition & 2 deletions examples/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use lvgl::style::Style;
use lvgl::widgets::{Bar, Label};
use lvgl::{Align, Animation, Color, Display, DrawBuffer, Event, LvError, Part, Widget};
use std::cell::RefCell;
use std::thread::sleep;
use std::time::Duration;
use std::time::Instant;
use std::thread::sleep;

fn main() -> Result<(), LvError> {
const HOR_RES: u32 = 240;
Expand Down Expand Up @@ -58,7 +58,6 @@ fn main() -> Result<(), LvError> {
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_label_align(LabelAlign::Center)?;

let mut loading_style = Style::default();
loading_style.set_text_color(Color::from_rgb((0, 0, 0)));
Expand Down
8 changes: 3 additions & 5 deletions examples/button_click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use embedded_graphics_simulator::{

use lvgl;
use lvgl::input_device::{
generic::InputDriver,
pointer::{Pointer, PointerInputData},
InputDriver,
};
use lvgl::style::Style;
use lvgl::widgets::{Btn, Label};
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part, Widget};
use std::thread::sleep;
use std::time::Duration;
use std::time::Instant;
use std::thread::sleep;

#[allow(unused_assignments)]
fn main() -> Result<(), LvError> {
Expand All @@ -39,8 +39,7 @@ fn main() -> Result<(), LvError> {
let mut latest_touch_status = PointerInputData::Touch(Point::new(0, 0)).released().once();

// Register a new input device that's capable of reading the current state of the input
let mut touch_screen = Pointer::new(|| latest_touch_status);
lvgl::indev_drv_register(&mut touch_screen)?;
let _touch_screen = Pointer::register(|| latest_touch_status, &display)?;

// Create screen and widgets
let mut screen = display.get_scr_act()?;
Expand All @@ -67,7 +66,6 @@ fn main() -> Result<(), LvError> {
btn_lbl.set_text(nt.as_c_str()).unwrap();
}
btn_state = !btn_state;
//btn.toggle().unwrap();
}
})?;

Expand Down
28 changes: 7 additions & 21 deletions examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use embedded_graphics_simulator::{
OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window,
};
use lvgl;
use lvgl::font::Font;
use lvgl::style::Style;
use lvgl::widgets::Label;
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part, TextAlign, Widget};
Expand All @@ -26,11 +27,6 @@ fn main() -> Result<(), LvError> {
// LVGL will render the graphics here first, and seed the rendered image to the
// display. The buffer size can be set freely.
let buffer = DrawBuffer::<{ (HOR_RES * VER_RES) as usize }>::new();
//
// const NUMBER_OF_DISPLAYS: usize = 1;
// static DISPLAY_REGISTRY: DisplayRegistry<NUMBER_OF_DISPLAYS> = DisplayRegistry::empty();
// // static DISPLAY_REGISTRY: SingleDisplayRegistry = DisplayRegistry::empty();
// let display = DISPLAY_REGISTRY.register_shared(&DRAW_BUFFER, shared_native_display.clone())?;

// Register your display update callback with LVGL. The closure you pass here will be called
// whenever LVGL has updates to be painted to the display.
Expand All @@ -52,9 +48,12 @@ fn main() -> Result<(), LvError> {
let mut style_time = Style::default();
style_time.set_text_color(Color::from_rgb((255, 255, 255)));
style_time.set_text_align(TextAlign::Center);
// Need to set font too

// See font module documentation for an explanation of the unsafe block
style_time.set_text_font(unsafe { Font::new_raw(lvgl_sys::noto_sans_numeric_80) });

time.add_style(Part::Main, &mut style_time)?;
time.set_align(Align::Center, 0, 100)?;
time.set_align(Align::Center, 0, 90)?;
time.set_width(240)?;
time.set_height(240)?;

Expand Down Expand Up @@ -89,28 +88,15 @@ fn main() -> Result<(), LvError> {
_ => {}
}
}
//println!("During run: {:?}", mem_info());
sleep(Duration::from_secs(1));
lvgl::tick_inc(Instant::now().duration_since(start));
}

//println!("Final part of demo app: {:?}", mem_info());
println!("Final part of demo app: {:?}", mem_info());

Ok(())
}

// Reference to native font for LVGL, defined in the file: "fonts_noto_sans_numeric_80.c"
// TODO: Create a macro for defining a safe wrapper for fonts.
// Maybe sometihng like:
//
// font_declare! {
// NotoSansNumeric80 = noto_sans_numeric_80;
// };
//
extern "C" {
pub static mut noto_sans_numeric_80: lvgl_sys::lv_font_t;
}

fn mem_info() -> lvgl_sys::lv_mem_monitor_t {
let mut info = lvgl_sys::lv_mem_monitor_t {
total_size: 0,
Expand Down
15 changes: 6 additions & 9 deletions examples/sdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
//#![allow(unused_variables)]
//#![allow(unreachable_code)]

use lvgl::LvResult;
use cstr_core::CString;
use lvgl::input_device::InputDriver;
use lvgl::lv_drv_disp_sdl;
use lvgl::lv_drv_input_pointer_sdl;
use lvgl::input_device::generic::InputDriver;
use lvgl::style::Style;
use lvgl::widgets::{Btn, Label};
use lvgl::LvResult;
use lvgl::{Align, Color, DrawBuffer, Part, Widget};
use std::thread::sleep;
use std::time::Duration;
use std::time::Instant;
use std::thread::sleep;
use cstr_core::CString;

fn main() -> LvResult<()> {
const HOR_RES: u32 = 240;
Expand All @@ -22,8 +22,7 @@ fn main() -> LvResult<()> {
lvgl::init();
let buffer = DrawBuffer::<{ (HOR_RES * VER_RES) as usize }>::new();
let display = lv_drv_disp_sdl!(buffer, HOR_RES, VER_RES)?;
let mut input = lv_drv_input_pointer_sdl!();
lvgl::indev_drv_register(&mut input)?;
let _input = lv_drv_input_pointer_sdl!(display)?;

// Create screen and widgets
let mut screen = display.get_scr_act()?;
Expand All @@ -50,15 +49,13 @@ fn main() -> LvResult<()> {
btn_lbl.set_text(nt.as_c_str()).unwrap();
}
btn_state = !btn_state;
//btn.toggle().unwrap();
}
})?;

loop {
let start = Instant::now();
lvgl::task_handler();
//println!("Loop");
sleep(Duration::from_millis(15));
lvgl::tick_inc(Instant::now().duration_since(start));
}
}
}
File renamed without changes.
Loading