fix after cherrypicking rust bootloader onto TR branch

tychovrahe/rust_bootloader_/tr
tychovrahe 1 year ago
parent 03714a881f
commit f722ba840e

@ -6,6 +6,7 @@ pub mod empty;
pub mod image;
pub mod label;
pub mod map;
#[cfg(feature = "micropython")]
pub mod marquee;
pub mod maybe;
pub mod pad;
@ -21,6 +22,7 @@ pub use empty::Empty;
pub use image::Image;
pub use label::Label;
pub use map::Map;
#[cfg(feature = "micropython")]
pub use marquee::Marquee;
pub use maybe::Maybe;
pub use pad::Pad;

@ -1,5 +1,18 @@
use crate::ui::lerp::Lerp;
#[macro_export]
macro_rules! alpha {
($n: expr) => {
if ($n >= 1.0) {
256_u16
} else {
($n * 256.0) as u16
}
};
}
#[derive(Copy, Clone, PartialEq, Eq)]
pub struct Color(u16);
@ -16,11 +29,30 @@ impl Color {
}
pub const fn luminance(self) -> u32 {
((self.r() as u32 * 299) / 1000)
(self.r() as u32 * 299) / 1000
+ (self.g() as u32 * 587) / 1000
+ (self.b() as u32 * 114) / 1000
}
pub const fn rgba(bg: Color, r: u8, g: u8, b: u8, alpha: u16) -> Self {
let r_u16 = r as u16;
let g_u16 = g as u16;
let b_u16 = b as u16;
let r = ((256 - alpha) * bg.r() as u16 + alpha * r_u16) >> 8;
let g = ((256 - alpha) * bg.g() as u16 + alpha * g_u16) >> 8;
let b = ((256 - alpha) * bg.b() as u16 + alpha * b_u16) >> 8;
let r = (r & 0xF8) << 8;
let g = (g & 0xFC) << 3;
let b = (b & 0xF8) >> 3;
Self(r | g | b)
}
pub const fn alpha(bg: Color, alpha: u16) -> Self {
Self::rgba(bg, 0xFF, 0xFF, 0xFF, alpha)
}
pub const fn r(self) -> u8 {
(self.0 >> 8) as u8 & 0xF8
}

@ -145,6 +145,14 @@ impl Font {
display::text_baseline(self.into())
}
pub fn max_height(self) -> i16 {
display::text_max_height(self.into()) as i16
}
pub fn baseline(self) -> i16 {
display::text_baseline(self.into()) as i16
}
pub fn line_height(self) -> i16 {
constant::LINE_SPACE + self.text_height()
}

@ -301,7 +301,7 @@ impl<T: AsRef<str>> TextOverlay<T> {
let p_rel = Point::new(p.x - self.area.x0, p.y - self.area.y0);
for g in self.text.bytes().filter_map(|c| self.font.get_glyph(c)) {
for g in self.text.as_ref().bytes().filter_map(|c| self.font.get_glyph(c)) {
let top = self.max_height - self.baseline - g.bearing_y;
let char_area = Rect::new(
Point::new(tot_adv + g.bearing_x, top),

@ -4,6 +4,7 @@ pub mod macros;
pub mod animation;
pub mod component;
pub mod constant;
#[cfg(feature = "micropython")]
pub mod debug;
pub mod display;
pub mod event;

@ -589,7 +589,7 @@ impl IconText {
}
if use_text {
display::text(
display::text_left(
text_pos,
self.text,
style.font,

Loading…
Cancel
Save