Skip to content
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
1,083 changes: 560 additions & 523 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ license = "MIT"
keywords = ["bevy", "tailwind", "css", "styled"]

[workspace]
members = ["macros", "macros/tests/*"]
members = ["macros", "macros/tests/runner", "macros/tests/pass"]

[dependencies]
bevy_tailwind_macro = { path = "macros" }
bevy = { version = "0.16.0", default-features = false, features = [
bevy = { version = "0.17.0-rc", default-features = false, features = [
"bevy_ui",
"bevy_text",
] }

[dev-dependencies]
bevy = { version = "0.16", default-features = false, features = [
bevy = { version = "0.17.0-rc", default-features = false, features = [
"bevy_ui",
"bevy_text",
"bevy_window",
Expand Down
2 changes: 1 addition & 1 deletion examples/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: [800., 600.].into(),
resolution: (800, 600).into(),
title: "Bevy CSS Grid Layout Example".to_string(),
..default()
}),
Expand Down
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test:
cargo insta test -p test_runner
review:
cargo insta review --workspace
126 changes: 112 additions & 14 deletions macros/src/border.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ impl ParseCtx {
pub fn parse_border_radius(&mut self, class: &str) -> ParseResult {
match class {
"rounded" => {
deny_picking_style!(self);
insert_computed_style!(
self,
border_radius,
Expand All @@ -21,7 +20,6 @@ impl ParseCtx {
)
}
"rounded-t" => {
deny_picking_style!(self);
insert_computed_style!(
self,
border_radius,
Expand All @@ -32,7 +30,6 @@ impl ParseCtx {
)
}
"rounded-r" => {
deny_picking_style!(self);
insert_computed_style!(
self,
border_radius,
Expand All @@ -43,7 +40,6 @@ impl ParseCtx {
)
}
"rounded-b" => {
deny_picking_style!(self);
insert_computed_style!(
self,
border_radius,
Expand All @@ -54,7 +50,6 @@ impl ParseCtx {
)
}
"rounded-l" => {
deny_picking_style!(self);
insert_computed_style!(
self,
border_radius,
Expand Down Expand Up @@ -174,26 +169,129 @@ impl ParseCtx {
}

pub fn parse_border_color(&mut self, class: &str) -> ParseResult {
if class == "border-color" {
insert_computed_style!(self, border_color, BorderColor, "0", 0);
}
match class {
"border-color" => {
insert_computed_style!(
self,
border_color,
[
(BorderColorTop, "top", 0),
(BorderColorRight, "right", 0),
(BorderColorBottom, "bottom", 0),
(BorderColorLeft, "left", 0)
]
);
}
"border-x-color" => {
insert_computed_style!(
self,
border_color,
[(BorderColorRight, "right", 1), (BorderColorLeft, "left", 1)]
);
}
"border-y-color" => {
insert_computed_style!(
self,
border_color,
[(BorderColorTop, "top", 1), (BorderColorBottom, "bottom", 1)]
);
}
"border-t-color" => {
insert_computed_style!(self, border_color, [(BorderColorTop, "top", 1)]);
}
"border-r-color" => {
insert_computed_style!(self, border_color, [(BorderColorRight, "right", 0)]);
}
"border-b-color" => {
insert_computed_style!(self, border_color, [(BorderColorBottom, "bottom", 0)]);
}
"border-l-color" => {
insert_computed_style!(self, border_color, [(BorderColorLeft, "left", 0)]);
}
_ => {}
};

if !class.starts_with("border-") {
return Ok(false);
}

macro_rules! insert_props {
($ctx:ident, $value:expr, $priority:literal, $props:expr) => {
for prop in $props {
$ctx.components.border_color.insert(
prop,
$value.clone(),
&$ctx.class_type,
$priority,
);
}

return Ok(true);
};
}

let class = &class["border-".len()..];

if class.starts_with("x-") {
let class = &class["x-".len()..];
if let Some(color) = Color::parse(class) {
deny_computed_style!(self);
insert_props!(self, color, 1, ["right", "left"]);
}
return Ok(false);
}

if class.starts_with("y-") {
let class = &class["y-".len()..];
if let Some(color) = Color::parse(class) {
deny_computed_style!(self);
insert_props!(self, color, 1, ["top", "bottom"]);
}
return Ok(false);
}

if class.starts_with("t-") {
let class = &class["t-".len()..];
if let Some(color) = Color::parse(class) {
deny_computed_style!(self);
insert_props!(self, color, 2, ["top"]);
}
return Ok(false);
}

if class.starts_with("r-") {
let class = &class["r-".len()..];
if let Some(color) = Color::parse(class) {
deny_computed_style!(self);
insert_props!(self, color, 2, ["right"]);
}
return Ok(false);
}

if class.starts_with("b-") {
let class = &class["b-".len()..];
if let Some(color) = Color::parse(class) {
deny_computed_style!(self);
insert_props!(self, color, 2, ["bottom"]);
}
return Ok(false);
}

if class.starts_with("l-") {
let class = &class["l-".len()..];
if let Some(color) = Color::parse(class) {
deny_computed_style!(self);
insert_props!(self, color, 2, ["left"]);
}
return Ok(false);
}

let Some(color) = Color::parse(class) else {
return Ok(false);
};

deny_computed_style!(self);
insert_picking_style!(self, BorderColor, color);
self.components
.border_color
.insert("0", color, &self.class_type, 0);

Ok(true)
insert_props!(self, color, 0, ["top", "right", "bottom", "left"]);
}
}

Expand Down
16 changes: 13 additions & 3 deletions macros/src/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ fn create_base_style(picking_styles: &PickingStyles, ctx: &mut QuoteCtx) -> Toke
#[rustfmt::skip]
insert_prop!(BorderLeft, bevy::ui::Border, node, &NodeProp::Border, "left");

insert_prop!(BorderColor, bevy::color::Color, border_color, "0");
insert_prop!(BorderColorTop, bevy::color::Color, border_color, "top");
insert_prop!(BorderColorRight, bevy::color::Color, border_color, "right");
#[rustfmt::skip]
insert_prop!(BorderColorBottom, bevy::color::Color, border_color, "bottom");
insert_prop!(BorderColorLeft, bevy::color::Color, border_color, "lef");

insert_prop!(OutlineWidth, bevy::ui::Val, outline, "width");

Expand Down Expand Up @@ -354,7 +358,10 @@ pub enum PickingStyleProp {
BorderRight,
BorderBottom,
BorderLeft,
BorderColor,
BorderColorTop,
BorderColorRight,
BorderColorBottom,
BorderColorLeft,
OutlineWidth,
OutlineColor,
OutlineOffset,
Expand Down Expand Up @@ -419,7 +426,10 @@ impl AsRef<str> for PickingStyleProp {
PickingStyleProp::BorderRight => "border_right",
PickingStyleProp::BorderBottom => "border_bottom",
PickingStyleProp::BorderLeft => "border_left",
PickingStyleProp::BorderColor => "border_color",
PickingStyleProp::BorderColorTop => "border_color_top",
PickingStyleProp::BorderColorRight => "border_color_right",
PickingStyleProp::BorderColorBottom => "border_color_bottom",
PickingStyleProp::BorderColorLeft => "border_color_left",
PickingStyleProp::OutlineWidth => "outline_width",
PickingStyleProp::OutlineColor => "outline_color",
PickingStyleProp::OutlineOffset => "outline_offset",
Expand Down
8 changes: 4 additions & 4 deletions macros/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ fn parse_text_align(ctx: &mut ParseCtx, class: &str) -> ParseResult {
let class = &class["text-".len()..];

let justify = match class {
"left" => quote! {bevy::text::JustifyText::Left},
"center" => quote! {bevy::text::JustifyText::Center},
"right" => quote! {bevy::text::JustifyText::Right},
"justify" => quote! {bevy::text::JustifyText::Justified},
"left" => quote! {bevy::text::Justify::Left},
"center" => quote! {bevy::text::Justify::Center},
"right" => quote! {bevy::text::Justify::Right},
"justify" => quote! {bevy::text::Justify::Justified},
_ => {
return Ok(false);
}
Expand Down
2 changes: 1 addition & 1 deletion macros/tests/pass/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
publish = false

[dependencies]
bevy = { version = "0.16", default-features = false, features = [
bevy = { version = "0.17.0-rc", default-features = false, features = [
"bevy_ui",
"bevy_text",
] }
Expand Down
62 changes: 61 additions & 1 deletion macros/tests/pass/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ fn test_all() {
tw!("text-center");
tw!("text-right");
tw!("text-justify");
tw!("text-align": JustifyText::Center);
tw!("text-align": Justify::Center);

// text color
tw!("text-transparent hover:text-transparent/50 focus:text-black");
Expand Down Expand Up @@ -575,6 +575,66 @@ fn test_all() {
tw!("border-gray-100/50");
tw!("border-color": Color::WHITE);

tw!("border-x-transparent hover:border-x-black focus:border-x-white");
tw!("border-x-transparent/50");
tw!("border-x-black");
tw!("border-x-black/50");
tw!("border-x-white");
tw!("border-x-white/50");
tw!("border-x-gray-100");
tw!("border-x-gray-100/50");
tw!("border-x-color": Color::WHITE, "hover:border-x-color": Color::WHITE, "focus:border-x-color": Color::WHITE);

tw!("border-y-transparent hover:border-y-black focus:border-y-white");
tw!("border-y-transparent/50");
tw!("border-y-black");
tw!("border-y-black/50");
tw!("border-y-white");
tw!("border-y-white/50");
tw!("border-y-gray-100");
tw!("border-y-gray-100/50");
tw!("border-y-color": Color::WHITE, "hover:border-y-color": Color::WHITE, "focus:border-y-color": Color::WHITE);

tw!("border-t-transparent hover:border-t-black focus:border-t-white");
tw!("border-t-transparent/50");
tw!("border-t-black");
tw!("border-t-black/50");
tw!("border-t-white");
tw!("border-t-white/50");
tw!("border-t-gray-100");
tw!("border-t-gray-100/50");
tw!("border-t-color": Color::WHITE, "hover:border-t-color": Color::WHITE, "focus:border-t-color": Color::WHITE);

tw!("border-r-transparent hover:border-r-black focus:border-r-white");
tw!("border-r-transparent/50");
tw!("border-r-black");
tw!("border-r-black/50");
tw!("border-r-white");
tw!("border-r-white/50");
tw!("border-r-gray-100");
tw!("border-r-gray-100/50");
tw!("border-r-color": Color::WHITE, "hover:border-r-color": Color::WHITE, "focus:border-r-color": Color::WHITE);

tw!("border-b-transparent hover:border-b-black focus:border-b-white");
tw!("border-b-transparent/50");
tw!("border-b-black");
tw!("border-b-black/50");
tw!("border-b-white");
tw!("border-b-white/50");
tw!("border-b-gray-100");
tw!("border-b-gray-100/50");
tw!("border-b-color": Color::WHITE, "hover:border-b-color": Color::WHITE, "focus:border-b-color": Color::WHITE);

tw!("border-l-transparent hover:border-t-black focus:border-t-white");
tw!("border-l-transparent/50");
tw!("border-l-black");
tw!("border-l-black/50");
tw!("border-l-white");
tw!("border-l-white/50");
tw!("border-l-gray-100");
tw!("border-l-gray-100/50");
tw!("border-t-color": Color::WHITE, "hover:border-l-color": Color::WHITE, "focus:border-l-color": Color::WHITE);

// outline width
tw!("outline-0 hover:outline-1 focus:outline-2");
tw!("outline": Val::Px(10.));
Expand Down
Loading