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

feat: Rethink parsing #785

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
75d6992
rethink parsing
Aiving Jul 13, 2024
852d3fd
change parsing api
Aiving Jul 15, 2024
b83476d
Merge branch 'main' into feat/rethink-parsing
Aiving Jul 15, 2024
3abffe9
Merge remote-tracking branch 'refs/remotes/origin/feat/rethink-parsin…
Aiving Jul 15, 2024
bf5cd55
feat: add `try_as_u8` function for `Token`
Aiving Jul 15, 2024
c953a5b
reduced number of modifications for PR files diff
Aiving Jul 15, 2024
f3a86be
Merge branch 'main' into feat/rethink-parsing
Aiving Jul 16, 2024
17bee71
fix rgba color parsing
Aiving Jul 16, 2024
33f151d
Merge branch 'feat/rethink-parsing' of https://github.com/Aiving/frey…
Aiving Jul 16, 2024
ad66c4a
Merge branch 'main' into feat/rethink-parsing
Aiving Jul 16, 2024
fd37282
Update crates/state/src/values/font.rs
Aiving Jul 16, 2024
08818aa
fix unicode character parsing
Aiving Jul 17, 2024
0ee85ba
change text-overflow parsing
Aiving Jul 17, 2024
168d95f
Merge branch 'main' into feat/rethink-parsing
Aiving Jul 17, 2024
017668c
Merge branch 'main' into feat/rethink-parsing
Aiving Aug 4, 2024
fc751ee
fixes
Aiving Aug 4, 2024
3dafc96
more fixes
Aiving Aug 4, 2024
424393d
Merge branch 'main' into feat/rethink-parsing
Aiving Aug 4, 2024
83a0276
Merge branch 'main' into feat/rethink-parsing
marc2332 Aug 18, 2024
1399586
Merge branch 'main' into feat/rethink-parsing
Aiving Sep 29, 2024
b50b78d
yoo
Aiving Sep 29, 2024
b88b19b
fix corner_radius.rs
Aiving Sep 29, 2024
3babf8c
Update style.rs
Aiving Sep 29, 2024
c3a630c
Update border.rs
Aiving Sep 29, 2024
32ec692
Update color.rs
Aiving Sep 29, 2024
a1dd2cb
add parse error messages
Aiving Sep 29, 2024
bee0ee5
fix rgb(a) parsing
Aiving Sep 29, 2024
873306f
fix text shadow parsing
Aiving Sep 29, 2024
6fed2d5
maybe fixed text shadow parsing
Aiving Sep 29, 2024
31aec74
fix hsl color parsing
Aiving Sep 29, 2024
49cf1ca
fix corner radius parsing
Aiving Sep 29, 2024
d6f3396
forgor to fmt
Aiving Sep 29, 2024
315ad4d
fix gradients angle parsing
Aiving Sep 29, 2024
9836be6
Merge branch 'main' into feat/rethink-parsing
Aiving Sep 29, 2024
c32dd2c
Merge branch 'main' into feat/rethink-parsing
Aiving Oct 16, 2024
e7caef3
implement new parse for text height
Aiving Oct 16, 2024
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: 1 addition & 1 deletion crates/components/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub fn Graph(props: GraphProps) -> Element {

paint.set_anti_alias(true);
paint.set_style(PaintStyle::Fill);
paint.set_color(Color::parse(&line.color).unwrap());
paint.set_color(Color::parse_value(&line.color).unwrap());
paint.set_stroke_width(3.0);

let mut previous_x = None;
Expand Down
2 changes: 1 addition & 1 deletion crates/devtools/src/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub fn BorderProperty(name: String, border: Border) -> Element {
text {
font_size: "15",
color: "rgb(252,181,172)",
"{border.width} {border.style:?} {border.alignment:?}"
"{border.width:?} {border.style:?} {border.alignment:?}"
}
}
rect {
Expand Down
6 changes: 3 additions & 3 deletions crates/hooks/src/use_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ pub struct AnimColor {
impl AnimColor {
pub fn new(origin: &str, destination: &str) -> Self {
Self {
origin: Color::parse(origin).unwrap(),
destination: Color::parse(destination).unwrap(),
origin: Color::parse_value(origin).unwrap(),
destination: Color::parse_value(destination).unwrap(),
time: Duration::default(),
ease: Ease::default(),
function: Function::default(),

value: Color::parse(origin).unwrap(),
value: Color::parse_value(origin).unwrap(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/hooks/tests/use_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub async fn animate_color() {

assert_eq!(
utils.root().get(0).style().background,
Fill::Color(Color::parse("rgb(50, 100, 200)").unwrap())
Fill::Color(Color::parse_value("rgb(50, 100, 200)").unwrap())
);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/renderer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<'a, T: Clone> LaunchConfig<'a, T> {

/// Specify the Window background color.
pub fn with_background(mut self, background: &str) -> Self {
self.window_config.background = Color::parse(background).unwrap_or(Color::WHITE);
self.window_config.background = Color::parse_value(background).unwrap_or(Color::WHITE);
self
}

Expand Down
18 changes: 14 additions & 4 deletions crates/state/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ use crate::{
CursorReference,
CustomAttributeValues,
HighlightMode,
Lexer,
Parse,
ParseAttribute,
ParseError,
Parser,
};

#[derive(Clone, Debug, PartialEq, Component)]
Expand Down Expand Up @@ -69,12 +71,16 @@ impl ParseAttribute for CursorState {
}
AttributeName::CursorColor => {
if let Some(value) = attr.value.as_text() {
self.color = Color::parse(value)?;
let mut parser = Parser::new(Lexer::parse(value));

self.color = Color::parse(&mut parser)?;
}
}
AttributeName::CursorMode => {
if let Some(value) = attr.value.as_text() {
self.mode = CursorMode::parse(value)?;
let mut parser = Parser::new(Lexer::parse(value));

self.mode = CursorMode::parse(&mut parser)?;
}
}
AttributeName::CursorId => {
Expand All @@ -91,12 +97,16 @@ impl ParseAttribute for CursorState {
}
AttributeName::HighlightColor => {
if let Some(value) = attr.value.as_text() {
self.highlight_color = Color::parse(value)?;
let mut parser = Parser::new(Lexer::parse(value));

self.highlight_color = Color::parse(&mut parser)?;
}
}
AttributeName::HighlightMode => {
if let Some(value) = attr.value.as_text() {
self.highlight_mode = HighlightMode::parse(value)?;
let mut parser = Parser::new(Lexer::parse(value));

self.highlight_mode = HighlightMode::parse(&mut parser)?;
}
}
AttributeName::CursorReference => {
Expand Down
94 changes: 48 additions & 46 deletions crates/state/src/font_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ use torin::torin::Torin;

use crate::{
CustomAttributeValues,
ExtSplit,
Lexer,
Parse,
ParseAttribute,
ParseError,
Parser,
TextOverflow,
Token,
};

#[derive(Debug, Clone, PartialEq, Component)]
Expand Down Expand Up @@ -105,28 +108,36 @@ impl ParseAttribute for FontStyleState {
fn parse_attribute(
&mut self,
attr: freya_native_core::prelude::OwnedAttributeView<CustomAttributeValues>,
) -> Result<(), crate::ParseError> {
) -> Result<(), ParseError> {
match attr.attribute {
AttributeName::Color => {
if let Some(value) = attr.value.as_text() {
// Make an exception for the "inherit" as in this case we don't want to pass
// a color at all but use the inherited one.
if value != "inherit" {
self.color = Color::parse(value)?;
let mut parser = Parser::new(Lexer::parse(value));

self.color = Color::parse(&mut parser)?;
}
}
}
AttributeName::TextShadow => {
if let Some(value) = attr.value.as_text() {
self.text_shadows = value
.split_excluding_group(',', '(', ')')
.map(|chunk| TextShadow::parse(chunk).unwrap_or_default())
.collect();
let mut parser = Parser::new(Lexer::parse(value));

let mut shadows = vec![TextShadow::parse(&mut parser)?];

while parser.try_consume(&Token::Comma) {
shadows.push(TextShadow::parse(&mut parser)?);
}

self.text_shadows = shadows;
}
}
AttributeName::FontFamily => {
if let Some(value) = attr.value.as_text() {
let families = value.split(',');

self.font_family = families
.into_iter()
.map(|f| f.trim().to_string())
Expand All @@ -149,84 +160,75 @@ impl ParseAttribute for FontStyleState {
}
AttributeName::TextAlign => {
if let Some(value) = attr.value.as_text() {
if let Ok(text_align) = TextAlign::parse(value) {
self.text_align = text_align;
}
let mut parser = Parser::new(Lexer::parse(value));

self.text_align = TextAlign::parse(&mut parser)?;
}
}
AttributeName::MaxLines => {
if let Some(value) = attr.value.as_text() {
if let Ok(max_lines) = value.parse() {
self.max_lines = Some(max_lines);
}
self.max_lines = Some(value.parse().map_err(|_| ParseError)?);
}
}
AttributeName::TextOverflow => {
let value = attr.value.as_text();
if let Some(value) = value {
if let Ok(text_overflow) = TextOverflow::parse(value) {
self.text_overflow = text_overflow;
}
if let Some(value) = attr.value.as_text() {
let mut parser = Parser::new(Lexer::parse(value));

self.text_overflow = TextOverflow::parse(&mut parser)?;
}
}
AttributeName::FontStyle => {
if let Some(value) = attr.value.as_text() {
if let Ok(font_slant) = Slant::parse(value) {
self.font_slant = font_slant;
}
let mut parser = Parser::new(Lexer::parse(value));

self.font_slant = Slant::parse(&mut parser)?;
}
}
AttributeName::FontWeight => {
if let Some(value) = attr.value.as_text() {
if let Ok(font_weight) = Weight::parse(value) {
self.font_weight = font_weight;
}
let mut parser = Parser::new(Lexer::parse(value));

self.font_weight = Weight::parse(&mut parser)?;
}
}
AttributeName::FontWidth => {
if let Some(value) = attr.value.as_text() {
if let Ok(font_width) = Width::parse(value) {
self.font_width = font_width;
}
let mut parser = Parser::new(Lexer::parse(value));

self.font_width = Width::parse(&mut parser)?;
}
}
AttributeName::Decoration => {
if let Some(value) = attr.value.as_text() {
if let Ok(decoration) = TextDecoration::parse(value) {
self.decoration.ty = decoration;
}
let mut parser = Parser::new(Lexer::parse(value));

self.decoration.ty = TextDecoration::parse(&mut parser)?;
}
}
AttributeName::DecorationStyle => {
if let Some(value) = attr.value.as_text() {
if let Ok(style) = TextDecorationStyle::parse(value) {
self.decoration.style = style;
}
let mut parser = Parser::new(Lexer::parse(value));

self.decoration.style = TextDecorationStyle::parse(&mut parser)?;
}
}
AttributeName::DecorationColor => {
if let Some(value) = attr.value.as_text() {
if let Ok(new_decoration_color) = Color::parse(value) {
self.decoration.color = new_decoration_color;
}
let mut parser = Parser::new(Lexer::parse(value));

self.decoration.color = Color::parse(&mut parser)?;
} else {
self.decoration.color = self.color;
}
}
AttributeName::WordSpacing => {
let value = attr.value.as_text();
if let Some(value) = value {
if let Ok(word_spacing) = value.parse() {
self.word_spacing = word_spacing;
}
if let Some(value) = attr.value.as_text() {
self.word_spacing = value.parse().map_err(|_| ParseError)?;
}
}
AttributeName::LetterSpacing => {
let value = attr.value.as_text();
if let Some(value) = value {
if let Ok(letter_spacing) = value.parse() {
self.letter_spacing = letter_spacing;
}
if let Some(value) = attr.value.as_text() {
self.letter_spacing = value.parse().map_err(|_| ParseError)?;
}
}
_ => {}
Expand Down
Loading