use super::*;
impl Style {
#[must_use]
#[inline(always)]
pub fn layout_ref(&self) -> &LayoutStyle {
let Self { layout, .. } = self;
layout
}
#[must_use]
#[inline(always)]
pub fn paint_ref(&self) -> &PaintStyle {
let Self { paint, .. } = self;
paint
}
#[must_use]
#[inline(always)]
pub fn text_ref(&self) -> &TextStyle {
let Self { text, .. } = self;
text
}
#[inline(always)]
pub fn mutate_layout<F>(&mut self, update: F) -> &mut Self
where
F: FnOnce(&mut LayoutStyle),
{
update(self.get_mut_layout());
self
}
#[inline(always)]
pub fn mutate_paint<F>(&mut self, update: F) -> &mut Self
where
F: FnOnce(&mut PaintStyle),
{
update(self.get_mut_paint());
self
}
#[inline(always)]
pub fn mutate_text<F>(&mut self, update: F) -> &mut Self
where
F: FnOnce(&mut TextStyle),
{
update(self.get_mut_text());
self
}
#[inline(always)]
pub fn set_direction_in_place(&mut self, direction: FlexDirection) -> &mut Self {
let layout: &mut LayoutStyle = self.get_mut_layout();
if layout.get_display() != Display::None {
layout.set_display(Display::Flex);
}
layout.set_flex_direction(direction);
self
}
#[inline(always)]
pub fn set_row_in_place(&mut self) -> &mut Self {
self.set_direction_in_place(FlexDirection::Row)
}
#[inline(always)]
pub fn set_column_in_place(&mut self) -> &mut Self {
self.set_direction_in_place(FlexDirection::Column)
}
#[inline(always)]
pub fn set_grid_in_place(&mut self, columns: u16) -> &mut Self {
let layout: &mut LayoutStyle = self.get_mut_layout();
if layout.get_display() != Display::None {
layout.set_display(Display::Grid);
}
layout.set_grid_columns(columns.max(1));
self
}
#[inline(always)]
pub fn set_gap_in_place(&mut self, gap: f32) -> &mut Self {
let clamped: f32 = gap.max(0.0);
let layout: &mut LayoutStyle = self.get_mut_layout();
layout.set_row_gap(clamped);
layout.set_column_gap(clamped);
self
}
#[inline(always)]
pub fn set_background_in_place(&mut self, color: Color) -> &mut Self {
self.get_mut_paint().set_background(Some(color));
self
}
#[inline(always)]
pub fn set_border_in_place(&mut self, width: f32, color: Color) -> &mut Self {
self.get_mut_paint()
.set_border(Border::new(width.max(0.0), color));
self
}
#[inline(always)]
pub fn set_radius_in_place(&mut self, radius: f32) -> &mut Self {
self.get_mut_paint()
.set_radius(CornerRadius::all(radius.max(0.0)));
self
}
#[inline(always)]
pub fn set_opacity_in_place(&mut self, opacity: f32) -> &mut Self {
self.get_mut_paint().set_opacity(opacity.clamp(0.0, 1.0));
self
}
#[inline(always)]
pub fn set_color_in_place(&mut self, color: Color) -> &mut Self {
self.get_mut_text().set_color(color);
self
}
#[inline(always)]
pub fn set_font_size_in_place(&mut self, size: f32) -> &mut Self {
self.get_mut_text().set_font_size(size.max(6.0));
self
}
#[must_use]
#[inline(always)]
pub fn apply<T>(self, prop: T) -> Self
where
T: StyleApply,
{
prop.apply_to(self)
}
#[must_use]
#[inline(always)]
pub fn direction(mut self, direction: FlexDirection) -> Self {
let _: &mut Self = self.set_direction_in_place(direction);
self
}
#[must_use]
#[inline(always)]
pub fn display(mut self, display: Display) -> Self {
self.get_mut_layout().set_display(display);
self
}
#[must_use]
#[inline(always)]
pub fn position(mut self, position: Position) -> Self {
self.get_mut_layout().set_position(position);
self
}
#[must_use]
#[inline(always)]
pub fn row(mut self) -> Self {
let _: &mut Self = self.set_row_in_place();
self
}
#[must_use]
#[inline(always)]
pub fn column(mut self) -> Self {
let _: &mut Self = self.set_column_in_place();
self
}
#[must_use]
#[inline(always)]
pub fn grid(mut self, columns: u16) -> Self {
let _: &mut Self = self.set_grid_in_place(columns);
self
}
#[must_use]
#[inline(always)]
pub fn wrap(mut self, wrap: FlexWrap) -> Self {
self.get_mut_layout().set_flex_wrap(wrap);
self
}
#[must_use]
#[inline(always)]
pub fn justify(mut self, justify: JustifyContent) -> Self {
self.get_mut_layout().set_justify_content(justify);
self
}
#[must_use]
#[inline(always)]
pub fn align(mut self, align: AlignItems) -> Self {
self.get_mut_layout().set_align_items(align);
self
}
#[must_use]
#[inline(always)]
pub fn flex_grow(mut self, grow: f32) -> Self {
self.get_mut_layout().set_flex_grow(grow.max(0.0));
self
}
#[must_use]
#[inline(always)]
pub fn flex_shrink(mut self, shrink: f32) -> Self {
self.get_mut_layout().set_flex_shrink(shrink.max(0.0));
self
}
#[must_use]
#[inline(always)]
pub fn width(mut self, width: Length) -> Self {
self.get_mut_layout().set_width(width);
self
}
#[must_use]
#[inline(always)]
pub fn height(mut self, height: Length) -> Self {
self.get_mut_layout().set_height(height);
self
}
#[must_use]
#[inline(always)]
pub fn min_width(mut self, min_width: Length) -> Self {
self.get_mut_layout().set_min_width(min_width);
self
}
#[must_use]
#[inline(always)]
pub fn min_height(mut self, min_height: Length) -> Self {
self.get_mut_layout().set_min_height(min_height);
self
}
#[must_use]
#[inline(always)]
pub fn max_width(mut self, max_width: Length) -> Self {
self.get_mut_layout().set_max_width(max_width);
self
}
#[must_use]
#[inline(always)]
pub fn max_height(mut self, max_height: Length) -> Self {
self.get_mut_layout().set_max_height(max_height);
self
}
#[must_use]
#[inline(always)]
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]
#[inline(always)]
pub fn gap(mut self, gap: f32) -> Self {
let _: &mut Self = self.set_gap_in_place(gap);
self
}
#[must_use]
#[inline(always)]
pub fn padding(mut self, padding: Edges) -> Self {
self.get_mut_layout().set_padding(padding);
self
}
#[must_use]
#[inline(always)]
pub fn margin(mut self, margin: Edges) -> Self {
self.get_mut_layout().set_margin(margin);
self
}
#[must_use]
#[inline(always)]
pub fn overflow(mut self, overflow: Overflow) -> Self {
self.get_mut_layout().set_overflow(overflow);
self
}
#[must_use]
#[inline(always)]
pub fn z_index(mut self, z_index: i32) -> Self {
self.get_mut_layout().set_z_index(z_index);
self
}
#[must_use]
#[inline(always)]
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]
#[inline(always)]
pub fn background(mut self, color: Color) -> Self {
let _: &mut Self = self.set_background_in_place(color);
self
}
#[must_use]
#[inline(always)]
pub fn gradient(mut self, gradient: LinearGradient) -> Self {
self.get_mut_paint().set_gradient(Some(gradient));
self
}
#[must_use]
#[inline(always)]
pub fn border(mut self, width: f32, color: Color) -> Self {
let _: &mut Self = self.set_border_in_place(width, color);
self
}
#[must_use]
#[inline(always)]
pub fn radius(mut self, radius: f32) -> Self {
let _: &mut Self = self.set_radius_in_place(radius);
self
}
#[must_use]
#[inline(always)]
pub fn shadow(mut self, shadow: Shadow) -> Self {
self.get_mut_paint().set_shadow(Some(shadow));
self
}
#[must_use]
#[inline(always)]
pub fn focus_ring(mut self, ring: Border) -> Self {
self.get_mut_paint().set_focus_ring(Some(ring));
self
}
#[must_use]
#[inline(always)]
pub fn opacity(mut self, opacity: f32) -> Self {
let _: &mut Self = self.set_opacity_in_place(opacity);
self
}
#[must_use]
#[inline(always)]
pub fn cursor(mut self, cursor: CursorIcon) -> Self {
self.get_mut_paint().set_cursor(cursor);
self
}
#[must_use]
#[inline(always)]
pub fn pointer_events(mut self, pointer_events: PointerEvents) -> Self {
self.get_mut_paint().set_pointer_events(pointer_events);
self
}
#[must_use]
#[inline(always)]
pub fn color(mut self, color: Color) -> Self {
let _: &mut Self = self.set_color_in_place(color);
self
}
#[must_use]
#[inline(always)]
pub fn font_size(mut self, size: f32) -> Self {
let _: &mut Self = self.set_font_size_in_place(size);
self
}
#[must_use]
#[inline(always)]
pub fn font_weight(mut self, weight: FontWeight) -> Self {
self.get_mut_text().set_weight(weight);
self
}
#[must_use]
#[inline(always)]
pub fn font_family(mut self, family: FontFamily) -> Self {
self.get_mut_text().set_family(family);
self
}
#[must_use]
#[inline(always)]
pub fn italic(mut self, italic: bool) -> Self {
self.get_mut_text().set_italic(italic);
self
}
#[must_use]
#[inline(always)]
pub fn text_align(mut self, align: TextAlign) -> Self {
self.get_mut_text().set_align(align);
self
}
#[must_use]
#[inline(always)]
pub fn text_overflow(mut self, overflow: TextOverflow) -> Self {
self.get_mut_text().set_overflow(overflow);
self
}
#[must_use]
#[inline(always)]
pub fn text_select(mut self, mode: TextSelectMode) -> Self {
self.get_mut_text().set_text_select(Some(mode));
self
}
#[must_use]
#[inline(always)]
pub fn selectable(self, selectable: bool) -> Self {
let mode: TextSelectMode = if selectable {
TextSelectMode::SelectAndCopy
} else {
TextSelectMode::None
};
self.text_select(mode)
}
#[must_use]
#[inline(always)]
pub fn selection_color(mut self, color: Color) -> Self {
self.get_mut_text().set_selection_color(Some(color));
self
}
#[must_use]
#[inline(always)]
pub fn stop_scroll_propagation(mut self, stop: bool) -> Self {
self.get_mut_paint().set_stop_scroll_propagation(stop);
self
}
#[must_use]
#[inline(always)]
pub fn stop_event_propagation(mut self, stop: bool) -> Self {
self.get_mut_paint().set_stop_event_propagation(stop);
self
}
#[must_use]
pub fn merge_overrides(mut self, overrides: &Self) -> Self {
let def: Self = Self::default();
let ol: LayoutStyle = overrides.get_layout();
let dl: LayoutStyle = def.get_layout();
let ml: &mut LayoutStyle = self.get_mut_layout();
if ol.get_display() != dl.get_display() {
let _: &mut LayoutStyle = ml.set_display(ol.get_display());
}
if ol.get_position() != dl.get_position() {
let _: &mut LayoutStyle = ml.set_position(ol.get_position());
}
if ol.get_flex_direction() != dl.get_flex_direction() {
let _: &mut LayoutStyle = ml.set_flex_direction(ol.get_flex_direction());
}
if ol.get_flex_wrap() != dl.get_flex_wrap() {
let _: &mut LayoutStyle = ml.set_flex_wrap(ol.get_flex_wrap());
}
if ol.get_justify_content() != dl.get_justify_content() {
let _: &mut LayoutStyle = ml.set_justify_content(ol.get_justify_content());
}
if ol.get_align_items() != dl.get_align_items() {
let _: &mut LayoutStyle = ml.set_align_items(ol.get_align_items());
}
if ol.get_align_self() != dl.get_align_self() {
let _: &mut LayoutStyle = ml.set_align_self(ol.get_align_self());
}
if ol.get_overflow() != dl.get_overflow() {
let _: &mut LayoutStyle = ml.set_overflow(ol.get_overflow());
}
if ol.get_flex_basis() != dl.get_flex_basis() {
let _: &mut LayoutStyle = ml.set_flex_basis(ol.get_flex_basis());
}
if ol.get_width() != dl.get_width() {
let _: &mut LayoutStyle = ml.set_width(ol.get_width());
}
if ol.get_height() != dl.get_height() {
let _: &mut LayoutStyle = ml.set_height(ol.get_height());
}
if ol.get_min_width() != dl.get_min_width() {
let _: &mut LayoutStyle = ml.set_min_width(ol.get_min_width());
}
if ol.get_min_height() != dl.get_min_height() {
let _: &mut LayoutStyle = ml.set_min_height(ol.get_min_height());
}
if ol.get_max_width() != dl.get_max_width() {
let _: &mut LayoutStyle = ml.set_max_width(ol.get_max_width());
}
if ol.get_max_height() != dl.get_max_height() {
let _: &mut LayoutStyle = ml.set_max_height(ol.get_max_height());
}
if ol.get_flex_grow() != dl.get_flex_grow() {
let _: &mut LayoutStyle = ml.set_flex_grow(ol.get_flex_grow());
}
if ol.get_flex_shrink() != dl.get_flex_shrink() {
let _: &mut LayoutStyle = ml.set_flex_shrink(ol.get_flex_shrink());
}
if ol.get_margin() != dl.get_margin() {
let _: &mut LayoutStyle = ml.set_margin(ol.get_margin());
}
if ol.get_padding() != dl.get_padding() {
let _: &mut LayoutStyle = ml.set_padding(ol.get_padding());
}
if ol.get_row_gap() != dl.get_row_gap() {
let _: &mut LayoutStyle = ml.set_row_gap(ol.get_row_gap());
}
if ol.get_column_gap() != dl.get_column_gap() {
let _: &mut LayoutStyle = ml.set_column_gap(ol.get_column_gap());
}
if let Some(top) = ol.top_offset() {
let _: &mut LayoutStyle = ml.set_top(Some(top));
}
if let Some(right) = ol.right_offset() {
let _: &mut LayoutStyle = ml.set_right(Some(right));
}
if let Some(bottom) = ol.bottom_offset() {
let _: &mut LayoutStyle = ml.set_bottom(Some(bottom));
}
if let Some(left) = ol.left_offset() {
let _: &mut LayoutStyle = ml.set_left(Some(left));
}
if let Some(ratio) = ol.aspect_ratio_value() {
let _: &mut LayoutStyle = ml.set_aspect_ratio(Some(ratio));
}
if ol.get_z_index() != dl.get_z_index() {
let _: &mut LayoutStyle = ml.set_z_index(ol.get_z_index());
}
if ol.get_grid_columns() != dl.get_grid_columns() {
let _: &mut LayoutStyle = ml.set_grid_columns(ol.get_grid_columns());
}
let op: PaintStyle = overrides.get_paint();
let dp: PaintStyle = def.get_paint();
let mp: &mut PaintStyle = self.get_mut_paint();
if let Some(bg) = op.background_color() {
let _: &mut PaintStyle = mp.set_background(Some(bg));
}
if let Some(grad) = op.background_gradient() {
let _: &mut PaintStyle = mp.set_gradient(Some(grad));
}
if op.get_border() != dp.get_border() {
let _: &mut PaintStyle = mp.set_border(op.get_border());
}
if op.get_radius() != dp.get_radius() {
let _: &mut PaintStyle = mp.set_radius(op.get_radius());
}
if let Some(shadow) = op.box_shadow() {
let _: &mut PaintStyle = mp.set_shadow(Some(shadow));
}
if let Some(ring) = op.focus_ring_border() {
let _: &mut PaintStyle = mp.set_focus_ring(Some(ring));
}
if op.get_opacity() != dp.get_opacity() {
let _: &mut PaintStyle = mp.set_opacity(op.get_opacity());
}
if op.get_transform() != dp.get_transform() {
let _: &mut PaintStyle = mp.set_transform(op.get_transform());
}
if op.get_cursor() != dp.get_cursor() {
let _: &mut PaintStyle = mp.set_cursor(op.get_cursor());
}
if op.get_pointer_events() != dp.get_pointer_events() {
let _: &mut PaintStyle = mp.set_pointer_events(op.get_pointer_events());
}
if op.get_stop_scroll_propagation() != dp.get_stop_scroll_propagation() {
let _: &mut PaintStyle =
mp.set_stop_scroll_propagation(op.get_stop_scroll_propagation());
}
if op.get_stop_event_propagation() != dp.get_stop_event_propagation() {
let _: &mut PaintStyle = mp.set_stop_event_propagation(op.get_stop_event_propagation());
}
let ot: TextStyle = overrides.get_text();
let dt: TextStyle = def.get_text();
let mt: &mut TextStyle = self.get_mut_text();
if ot.get_family() != dt.get_family() {
let _: &mut TextStyle = mt.set_family(ot.get_family());
}
if ot.get_font_size() != dt.get_font_size() {
let _: &mut TextStyle = mt.set_font_size(ot.get_font_size());
}
if ot.get_weight() != dt.get_weight() {
let _: &mut TextStyle = mt.set_weight(ot.get_weight());
}
if ot.get_line_height() != dt.get_line_height() {
let _: &mut TextStyle = mt.set_line_height(ot.get_line_height());
}
if ot.get_letter_spacing() != dt.get_letter_spacing() {
let _: &mut TextStyle = mt.set_letter_spacing(ot.get_letter_spacing());
}
if ot.get_align() != dt.get_align() {
let _: &mut TextStyle = mt.set_align(ot.get_align());
}
if ot.get_overflow() != dt.get_overflow() {
let _: &mut TextStyle = mt.set_overflow(ot.get_overflow());
}
if ot.get_color() != dt.get_color() {
let _: &mut TextStyle = mt.set_color(ot.get_color());
}
if ot.get_italic() != dt.get_italic() {
let _: &mut TextStyle = mt.set_italic(ot.get_italic());
}
if ot.get_underline() != dt.get_underline() {
let _: &mut TextStyle = mt.set_underline(ot.get_underline());
}
if ot.get_strikethrough() != dt.get_strikethrough() {
let _: &mut TextStyle = mt.set_strikethrough(ot.get_strikethrough());
}
if let Some(mode) = ot.text_select_mode() {
let _: &mut TextStyle = mt.set_text_select(Some(mode));
}
if let Some(sel_color) = ot.selection_color() {
let _: &mut TextStyle = mt.set_selection_color(Some(sel_color));
}
self
}
#[must_use]
#[inline(always)]
pub fn with_overrides(self, overrides: Option<Self>) -> Self {
match overrides {
Some(extra) => self.merge_overrides(&extra),
None => self,
}
}
}
impl ResponsiveStyle {
#[must_use]
#[inline(always)]
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,
}
}
}
impl StyleApply for Display {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.display(self)
}
}
impl StyleApply for Position {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.position(self)
}
}
impl StyleApply for FlexDirection {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.direction(self)
}
}
impl StyleApply for FlexWrap {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.wrap(self)
}
}
impl StyleApply for JustifyContent {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.justify(self)
}
}
impl StyleApply for AlignItems {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.align(self)
}
}
impl StyleApply for Overflow {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.overflow(self)
}
}
impl StyleApply for CursorIcon {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.cursor(self)
}
}
impl StyleApply for PointerEvents {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.pointer_events(self)
}
}
impl StyleApply for FontWeight {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.font_weight(self)
}
}
impl StyleApply for FontFamily {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.font_family(self)
}
}
impl StyleApply for TextAlign {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.text_align(self)
}
}
impl StyleApply for TextOverflow {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.text_overflow(self)
}
}
impl StyleApply for Shadow {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.shadow(self)
}
}
impl StyleApply for LinearGradient {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
style.gradient(self)
}
}
impl StyleApply for CornerRadius {
#[inline(always)]
fn apply_to(self, style: Style) -> Style {
let mut out: Style = style;
out.get_mut_paint().set_radius(self);
out
}
}
impl StyleApply for Style {
#[inline(always)]
fn apply_to(self, _style: Style) -> Style {
self
}
}