use super::*;
impl Style {
#[must_use]
pub fn empty() -> Self {
Self::default()
}
#[must_use]
pub fn display(mut self, display: Display) -> Self {
self.get_mut_layout().set_display(display);
self
}
#[must_use]
pub fn position(mut self, position: Position) -> Self {
self.get_mut_layout().set_position(position);
self
}
#[must_use]
pub fn row(mut self) -> Self {
if self.get_layout().get_display() != Display::None {
self.get_mut_layout().set_display(Display::Flex);
}
self.get_mut_layout().set_flex_direction(FlexDirection::Row);
self
}
#[must_use]
pub fn column(mut self) -> Self {
if self.get_layout().get_display() != Display::None {
self.get_mut_layout().set_display(Display::Flex);
}
self.get_mut_layout()
.set_flex_direction(FlexDirection::Column);
self
}
#[must_use]
pub fn grid(mut self, columns: u16) -> Self {
if self.get_layout().get_display() != Display::None {
self.get_mut_layout().set_display(Display::Grid);
}
self.get_mut_layout().set_grid_columns(columns.max(1));
self
}
#[must_use]
pub fn wrap(mut self, wrap: FlexWrap) -> Self {
self.get_mut_layout().set_flex_wrap(wrap);
self
}
#[must_use]
pub fn justify(mut self, justify: JustifyContent) -> Self {
self.get_mut_layout().set_justify_content(justify);
self
}
#[must_use]
pub fn align(mut self, align: AlignItems) -> Self {
self.get_mut_layout().set_align_items(align);
self
}
#[must_use]
pub fn flex_grow(mut self, grow: f32) -> Self {
self.get_mut_layout().set_flex_grow(grow.max(0.0));
self
}
#[must_use]
pub fn flex_shrink(mut self, shrink: f32) -> Self {
self.get_mut_layout().set_flex_shrink(shrink.max(0.0));
self
}
#[must_use]
pub fn width(mut self, width: Length) -> Self {
self.get_mut_layout().set_width(width);
self
}
#[must_use]
pub fn height(mut self, height: Length) -> Self {
self.get_mut_layout().set_height(height);
self
}
#[must_use]
pub fn min_width(mut self, min_width: Length) -> Self {
self.get_mut_layout().set_min_width(min_width);
self
}
#[must_use]
pub fn min_height(mut self, min_height: Length) -> Self {
self.get_mut_layout().set_min_height(min_height);
self
}
#[must_use]
pub fn max_width(mut self, max_width: Length) -> Self {
self.get_mut_layout().set_max_width(max_width);
self
}
#[must_use]
pub fn max_height(mut self, max_height: Length) -> Self {
self.get_mut_layout().set_max_height(max_height);
self
}
#[must_use]
pub fn aspect_ratio(mut self, ratio: f32) -> Self {
if ratio > 0.0 && ratio.is_finite() {
self.get_mut_layout().set_aspect_ratio(Some(ratio));
}
self
}
#[must_use]
pub fn gap(mut self, gap: f32) -> Self {
let clamped: f32 = gap.max(0.0);
self.get_mut_layout().set_row_gap(clamped);
self.get_mut_layout().set_column_gap(clamped);
self
}
#[must_use]
pub fn padding(mut self, padding: Edges) -> Self {
self.get_mut_layout().set_padding(padding);
self
}
#[must_use]
pub fn margin(mut self, margin: Edges) -> Self {
self.get_mut_layout().set_margin(margin);
self
}
#[must_use]
pub fn overflow(mut self, overflow: Overflow) -> Self {
self.get_mut_layout().set_overflow(overflow);
self
}
#[must_use]
pub fn z_index(mut self, z_index: i32) -> Self {
self.get_mut_layout().set_z_index(z_index);
self
}
#[must_use]
pub fn inset(
mut self,
top: Option<f32>,
right: Option<f32>,
bottom: Option<f32>,
left: Option<f32>,
) -> Self {
self.get_mut_layout().set_top(top);
self.get_mut_layout().set_right(right);
self.get_mut_layout().set_bottom(bottom);
self.get_mut_layout().set_left(left);
self
}
#[must_use]
pub fn background(mut self, color: Color) -> Self {
self.get_mut_paint().set_background(Some(color));
self
}
#[must_use]
pub fn gradient(mut self, gradient: LinearGradient) -> Self {
self.get_mut_paint().set_gradient(Some(gradient));
self
}
#[must_use]
pub fn border(mut self, width: f32, color: Color) -> Self {
self.get_mut_paint()
.set_border(Border::new(width.max(0.0), color));
self
}
#[must_use]
pub fn radius(mut self, radius: f32) -> Self {
self.get_mut_paint()
.set_radius(CornerRadius::all(radius.max(0.0)));
self
}
#[must_use]
pub fn shadow(mut self, shadow: Shadow) -> Self {
self.get_mut_paint().set_shadow(Some(shadow));
self
}
#[must_use]
pub fn focus_ring(mut self, ring: Border) -> Self {
self.get_mut_paint().set_focus_ring(Some(ring));
self
}
#[must_use]
pub fn opacity(mut self, opacity: f32) -> Self {
self.get_mut_paint().set_opacity(opacity.clamp(0.0, 1.0));
self
}
#[must_use]
pub fn cursor(mut self, cursor: CursorIcon) -> Self {
self.get_mut_paint().set_cursor(cursor);
self
}
#[must_use]
pub fn pointer_events(mut self, pointer_events: PointerEvents) -> Self {
self.get_mut_paint().set_pointer_events(pointer_events);
self
}
#[must_use]
pub fn color(mut self, color: Color) -> Self {
self.get_mut_text().set_color(color);
self
}
#[must_use]
pub fn font_size(mut self, size: f32) -> Self {
self.get_mut_text().set_font_size(size.max(6.0));
self
}
#[must_use]
pub fn font_weight(mut self, weight: FontWeight) -> Self {
self.get_mut_text().set_weight(weight);
self
}
#[must_use]
pub fn font_family(mut self, family: FontFamily) -> Self {
self.get_mut_text().set_family(family);
self
}
#[must_use]
pub fn text_align(mut self, align: TextAlign) -> Self {
self.get_mut_text().set_align(align);
self
}
#[must_use]
pub fn text_overflow(mut self, overflow: TextOverflow) -> Self {
self.get_mut_text().set_overflow(overflow);
self
}
#[must_use]
pub fn stop_scroll_propagation(mut self, stop: bool) -> Self {
self.get_mut_paint().set_stop_scroll_propagation(stop);
self
}
#[must_use]
pub fn stop_event_propagation(mut self, stop: bool) -> Self {
self.get_mut_paint().set_stop_event_propagation(stop);
self
}
}
impl ResponsiveStyle {
#[must_use]
pub fn resolve(&self, breakpoint: Breakpoint) -> Style {
let Self {
base,
compact,
medium,
} = *self;
match breakpoint {
Breakpoint::Compact => compact.unwrap_or(base),
Breakpoint::Medium => medium.unwrap_or(base),
Breakpoint::Expanded => base,
}
}
}