Skip to content

Commit

Permalink
Merge pull request #598 from Sharktheone/rendering/text-decoration
Browse files Browse the repository at this point in the history
implement text decoration
  • Loading branch information
Sharktheone authored Sep 15, 2024
2 parents 5e31a98 + 1e3b493 commit 98453ff
Show file tree
Hide file tree
Showing 8 changed files with 1,695 additions and 1,326 deletions.
2 changes: 2 additions & 0 deletions crates/gosub_css3/src/stylesheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ impl CssValue {
value.trim_end_matches("rem").parse::<f32>().unwrap() * 16.0
} else if value.ends_with("em") {
value.trim_end_matches("em").parse::<f32>().unwrap() * 16.0
} else if value.ends_with("__qem") {
value.trim_end_matches("__qem").parse::<f32>().unwrap() * 16.0
} else {
0.0
}
Expand Down
50 changes: 49 additions & 1 deletion crates/gosub_render_backend/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,36 @@ pub trait HasTextLayout<L: Layouter> {
fn set_text_layout(&mut self, layout: L::TextLayout);
}

pub trait CssProperty: Debug {
pub trait CssProperty: Debug + Sized {
type Value: CssValue;

fn compute_value(&mut self);

fn unit_to_px(&self) -> f32;

fn as_string(&self) -> Option<&str>;
fn as_percentage(&self) -> Option<f32>;
fn as_unit(&self) -> Option<(f32, &str)>;
fn as_color(&self) -> Option<(f32, f32, f32, f32)>;

fn parse_color(&self) -> Option<(f32, f32, f32, f32)>;

fn as_number(&self) -> Option<f32>;
fn as_list(&self) -> Option<Vec<Self::Value>>;

fn is_none(&self) -> bool;
}

pub trait CssValue: Sized {
fn unit_to_px(&self) -> f32;

fn as_string(&self) -> Option<&str>;
fn as_percentage(&self) -> Option<f32>;
fn as_unit(&self) -> Option<(f32, &str)>;
fn as_color(&self) -> Option<(f32, f32, f32, f32)>;
fn as_number(&self) -> Option<f32>;
fn as_list(&self) -> Option<Vec<Self>>;

fn is_none(&self) -> bool;
}

Expand All @@ -164,4 +185,31 @@ pub trait TextLayout {
fn font_size(&self) -> f32;

fn coords(&self) -> &[i16];

fn decorations(&self) -> &Decoration;
}

#[derive(Debug, Clone, Default)]
pub struct Decoration {
pub underline: bool,
pub overline: bool,
pub line_through: bool,

pub color: (f32, f32, f32, f32),
pub style: DecorationStyle,
pub width: f32,

pub underline_offset: f32,

pub x_offset: f32,
}

#[derive(Debug, Clone, Default)]
pub enum DecorationStyle {
#[default]
Solid,
Double,
Dotted,
Dashed,
Wavy,
}
2 changes: 1 addition & 1 deletion crates/gosub_renderer/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where
rect: bg,
transform: None,
radius: None,
brush: Brush::color(Color::BLACK),
brush: Brush::color(Color::WHITE),
brush_transform: None,
border: None,
};
Expand Down
Loading

0 comments on commit 98453ff

Please sign in to comment.