Add initial rich text example
This commit is contained in:
parent
119a570ee9
commit
4798c7ee1a
11 changed files with 854 additions and 595 deletions
32
src/attrs.rs
32
src/attrs.rs
|
|
@ -2,8 +2,28 @@
|
|||
|
||||
pub use fontdb::{Family, Stretch, Style, Weight};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct Color(pub u32);
|
||||
|
||||
impl Color {
|
||||
pub const fn rgb(r: u8, g: u8, b: u8) -> Self {
|
||||
Self::rgba(r, g, b, 0xFF)
|
||||
}
|
||||
|
||||
pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
|
||||
Self(
|
||||
((a as u32) << 24) |
|
||||
((r as u32) << 16) |
|
||||
((g as u32) << 8) |
|
||||
(b as u32)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct Attrs<'a> {
|
||||
//TODO: should this be an option?
|
||||
pub color_opt: Option<Color>,
|
||||
pub family: Family<'a>,
|
||||
pub monospaced: bool,
|
||||
pub stretch: Stretch,
|
||||
|
|
@ -14,6 +34,7 @@ pub struct Attrs<'a> {
|
|||
impl<'a> Attrs<'a> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
color_opt: None,
|
||||
family: Family::SansSerif,
|
||||
monospaced: false,
|
||||
stretch: Stretch::Normal,
|
||||
|
|
@ -22,6 +43,11 @@ impl<'a> Attrs<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn color(mut self, color: Color) -> Self {
|
||||
self.color_opt = Some(color);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn family(mut self, family: Family<'a>) -> Self {
|
||||
self.family = family;
|
||||
self
|
||||
|
|
@ -55,3 +81,9 @@ impl<'a> Attrs<'a> {
|
|||
(face.monospaced == self.monospaced || face.post_script_name.contains("Emoji"))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AttrsSpan<'a> {
|
||||
pub start: usize,
|
||||
pub end: usize,
|
||||
pub attrs: Attrs<'a>
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue