use kaolin::{
Kaolin, fixed, sizing,
style::{FlexStyle, TextStyle, border::Border, padding::Padding},
};
mod common;
use common::*;
#[test]
fn basic_border_rendering() {
let kaolin = Kaolin::new((800, 600), measure_text);
let mut commands = kaolin.draw::<()>(|k| {
k.styled(
FlexStyle::new()
.sizing(sizing!(fixed!(200.0), fixed!(100.0)))
.border(Border::new().width(5.0).color(TestColor::Red)),
|k| k,
)
});
let cmd = commands.next().unwrap();
match cmd {
kaolin::commands::RenderCommand::DrawRectangle { border, .. } => {
assert_eq!(border.width, 5.0);
assert_eq!(border.color, TestColor::Red);
}
_ => panic!("Expected DrawRectangle command"),
}
}
#[test]
fn corner_radius_rendering() {
let kaolin = Kaolin::new((800, 600), measure_text);
let mut commands = kaolin.draw::<()>(|k| {
k.styled(
FlexStyle::new()
.sizing(sizing!(fixed!(200.0), fixed!(100.0)))
.corner_radius(15.0),
|k| k,
)
});
let cmd = commands.next().unwrap();
match cmd {
kaolin::commands::RenderCommand::DrawRectangle { corner_radius, .. } => {
assert_eq!(corner_radius, 15.0);
}
_ => panic!("Expected DrawRectangle command"),
}
}
#[test]
fn background_color_rendering() {
let kaolin = Kaolin::new((800, 600), measure_text);
let mut commands = kaolin.draw::<()>(|k| {
k.styled(
FlexStyle::new()
.sizing(sizing!(fixed!(200.0), fixed!(100.0)))
.background_color(TestColor::Red),
|k| k,
)
});
let cmd = commands.next().unwrap();
match cmd {
kaolin::commands::RenderCommand::DrawRectangle { color, .. } => {
assert_eq!(color, TestColor::Red);
}
_ => panic!("Expected DrawRectangle command"),
}
}
#[test]
fn combined_styling_properties() {
let kaolin = Kaolin::new((800, 600), measure_text);
let mut commands = kaolin.draw::<()>(|k| {
k.styled(
FlexStyle::new()
.sizing(sizing!(fixed!(300.0), fixed!(200.0)))
.background_color(TestColor::Red)
.border(Border::new().width(3.0))
.corner_radius(10.0),
|k| k.text("Styled", TextStyle::new()),
)
});
let cmd = commands.next().unwrap();
match cmd {
kaolin::commands::RenderCommand::DrawRectangle {
color,
corner_radius,
border,
width,
height,
..
} => {
assert_eq!(color, TestColor::Red);
assert_eq!(corner_radius, 10.0);
assert_eq!(width, 300.0);
assert_eq!(height, 200.0);
assert_eq!(border.width, 3.0);
assert_eq!(border.color, TestColor::Black);
}
_ => panic!("Expected DrawRectangle command"),
}
}
#[test]
fn padding_with_styling() {
let kaolin = Kaolin::new((800, 600), measure_text);
let mut commands = kaolin.draw::<()>(|k| {
k.styled(
FlexStyle::new()
.sizing(sizing!(fixed!(200.0), fixed!(100.0)))
.padding(Padding::all(20.0))
.background_color(TestColor::Red),
|k| k.text("Padded", TextStyle::new()),
)
});
assert_size!(commands.next(), (200.0, 100.0)); assert_position!(commands.next(), (20.0, 20.0)); }
#[test]
fn asymmetric_padding() {
let kaolin = Kaolin::new((800, 600), measure_text);
let mut commands = kaolin.draw::<()>(|k| {
k.styled(
FlexStyle::new()
.sizing(sizing!(fixed!(400.0), fixed!(300.0)))
.padding(Padding::new(10.0, 20.0, 15.0, 25.0)), |k| k.text("Asymmetric", TextStyle::new()),
)
});
assert_size!(commands.next(), (400.0, 300.0)); assert_position!(commands.next(), (10.0, 15.0)); }
#[test]
fn padding_with_vertical_layout() {
let kaolin = Kaolin::new((800, 600), measure_text);
let mut commands = kaolin.draw::<()>(|k| {
k.styled(
FlexStyle::new()
.sizing(sizing!(fixed!(200.0), fixed!(300.0)))
.padding(Padding::all(30.0))
.layout(Layout::new().direction(Direction::TopToBottom)),
|k| {
k.text("First", TextStyle::new())
.text("Second", TextStyle::new())
},
)
});
assert_size!(commands.next(), (200.0, 300.0)); assert_position!(commands.next(), (30.0, 30.0)); assert_position!(commands.next(), (30.0, 50.0)); }
#[test]
fn styling_with_color_inheritance() {
let kaolin = Kaolin::new((800, 600), measure_text);
let mut commands = kaolin.draw::<()>(|k| {
k.styled(
FlexStyle::new()
.sizing(sizing!(fixed!(300.0), fixed!(200.0)))
.color(TestColor::Red)
.background_color(TestColor::Black)
.border(Border::new().width(2.0).color(TestColor::Red)),
|k| k.text("Styled Text", TextStyle::new()),
)
});
commands.next(); assert_color!(commands.next(), TestColor::Red); }
use kaolin::style::layout::{Direction, Layout};