use super::*;
impl EuvPageContainer {
#[must_use]
pub fn child(mut self, node: NodeId) -> Self {
self.get_mut_children().push(node);
self
}
}
#[component]
impl EuvPageContainer {
fn render(&self) -> NodeId {
let Self { children, .. } = self;
let container_st: Style = style! {
Width(Length::Percent(100.0))
MaxWidth(Length::Px(1120.0))
Padding(Edges::all(SPACE_XL))
Gap(SPACE_LG)
}
.with_overrides(self.get_style());
let root: NodeId = view! {
column {
style: container_st
}
};
if !children.is_empty() {
let mut ctx: Context = current_context();
ctx.append_many(root, children);
}
root
}
}
impl EuvPanel {
#[must_use]
pub fn child(mut self, node: NodeId) -> Self {
self.get_mut_children().push(node);
self
}
}
#[component]
impl EuvPanel {
fn render(&self) -> NodeId {
let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
let theme_palette: ThemePalette = tokens.get_palette();
let geometry: ThemeGeometry = tokens.get_geometry();
let surface: SurfaceColors = theme_palette.surface(SurfaceRole::Muted);
let Self {
title, children, ..
} = self;
let column_tertiary_style: Style = style! {
Width(Length::Percent(100.0))
Padding(Edges::all(SPACE_MD))
Gap(SPACE_SM)
Background(surface.get_bg())
Border::new(geometry.get_border_width(), surface.get_border())
Radius(geometry.get_radius_md())
Overflow::Hidden
};
let text_quaternary_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(14.0)
FontWeight::SemiBold
TextColor(surface.get_fg())
};
let root: NodeId = view! {
column {
style: column_tertiary_style
if !title.is_empty() {
text {
style: text_quaternary_style
{ title.as_str() }
}
}
}
};
if !children.is_empty() {
let mut ctx: Context = current_context();
ctx.append_many(root, children);
}
root
}
}
impl EuvSpace {
#[must_use]
pub fn row(gap: f32) -> Self {
Self::new(false).style(style! {
Gap(gap)
})
}
#[must_use]
pub fn column(gap: f32) -> Self {
Self::new(true).style(style! {
Gap(gap)
})
}
#[must_use]
pub fn child(mut self, node: NodeId) -> Self {
self.get_mut_children().push(node);
self
}
}
#[component]
impl EuvSpace {
fn render(&self) -> NodeId {
let mut base: Style = Style::default();
if self.get_vertical() {
base.get_mut_layout()
.set_flex_direction(FlexDirection::Column);
} else {
base.get_mut_layout()
.set_flex_direction(FlexDirection::Row)
.set_flex_wrap(FlexWrap::Wrap)
.set_align_items(AlignItems::Center);
}
let Self { children, .. } = self;
let space_st: Style = style! {
base
Gap(SPACE_SM)
}
.with_overrides(self.get_style());
let root: NodeId = view! {
view {
style: space_st
}
};
if !children.is_empty() {
let mut ctx: Context = current_context();
ctx.append_many(root, children);
}
root
}
}
impl EuvGrid {
#[must_use]
pub fn child(mut self, node: NodeId) -> Self {
self.get_mut_children().push(node);
self
}
}
#[component]
impl EuvGrid {
fn render(&self) -> NodeId {
let Self { children, .. } = self;
let grid_st: Style = style! {
GridColumns(2)
Width(Length::Percent(100.0))
Gap(SPACE_MD)
}
.with_overrides(self.get_style());
let root: NodeId = view! {
grid {
style: grid_st
}
};
if !children.is_empty() {
let mut ctx: Context = current_context();
ctx.append_many(root, children);
}
root
}
}
impl EuvScrollArea {
#[must_use]
pub fn child(mut self, node: NodeId) -> Self {
self.get_mut_children().push(node);
self
}
}
#[component]
impl EuvScrollArea {
fn render(&self) -> NodeId {
let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
let theme_palette: ThemePalette = tokens.get_palette();
let geometry: ThemeGeometry = tokens.get_geometry();
let surface: SurfaceColors = theme_palette.surface(SurfaceRole::Card);
let Self { children, .. } = self;
let mut scroll_st: Style = Style::default();
let _: &mut LayoutStyle = scroll_st
.get_mut_layout()
.set_flex_direction(FlexDirection::Column);
let area_st: Style = style! {
scroll_st
Width(Length::Percent(100.0))
Height(Length::Px(240.0))
Padding(Edges::all(SPACE_SM))
Gap(SPACE_SM)
Background(surface.get_bg())
Border::new(geometry.get_border_width(), surface.get_border())
Radius(geometry.get_radius_md())
}
.with_overrides(self.get_style());
let root: NodeId = view! {
scroll {
style: area_st
}
};
let mut ctx: Context = current_context();
let scene_clamp: SceneHandle = ctx.get_scene().clone();
ctx.on_scroll(root, move |_: &UiEvent| {
scene_clamp.with_write(
|tree: &mut SceneTree| {
if let Some(cur) = tree.get_node(root).map(|scene_node: &SceneNode| {
scene_node.get_layout_box().get_scroll_offset()
}) && cur.get_x().abs() > 0.01
{
tree.set_scroll_offset(root, Point::new(0.0, cur.get_y()));
}
},
(),
);
});
if !children.is_empty() {
ctx.append_many(root, children);
}
root
}
}
#[component]
impl EuvSplitter {
fn render(&self) -> NodeId {
let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
let theme_palette: ThemePalette = tokens.get_palette();
let ratio: f32 = self.get_ratio_percent().clamp(15.0, 85.0);
let primary: NodeId = self.get_primary();
let secondary: NodeId = self.get_secondary();
let row_sixth_style: Style = style! {
Width(Length::Percent(100.0))
};
let column_style: Style = style! {
Width(Length::Percent(ratio))
Padding(Edges::all(SPACE_SM))
Overflow::Hidden
};
let view_style: Style = style! {
Width(Length::Px(4.0))
FlexShrink(0.0)
Radius(RADIUS_PILL)
Background(theme_palette.get_border())
};
let column_secondary_style: Style = style! {
FlexGrow(1.0)
MinWidth(Length::Px(0.0))
Padding(Edges::all(SPACE_SM))
Overflow::Hidden
};
view! {
row {
style: row_sixth_style
column {
style: column_style
{ primary }
}
view {
style: view_style
}
column {
style: column_secondary_style
{ secondary }
}
}
}
}
}
impl EuvNavbar {
#[must_use]
pub fn action(mut self, node: NodeId) -> Self {
self.get_mut_actions().push(node);
self
}
}
#[component]
impl EuvNavbar {
fn render(&self) -> NodeId {
let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
let theme_palette: ThemePalette = tokens.get_palette();
let geometry: ThemeGeometry = tokens.get_geometry();
let surface: SurfaceColors = theme_palette.surface(SurfaceRole::Card);
let Self { brand, actions, .. } = self;
let mut actions_row: NodeId = NodeId::default();
let row_quaternary_style: Style = style! {
Width(Length::Percent(100.0))
Height(Length::Px(MOBILE_HEADER_HEIGHT))
Padding(Edges::symmetric(0.0, SPACE_LG))
JustifyContent::SpaceBetween
AlignItems::Center
Gap(SPACE_SM)
Background(surface.get_bg())
Border::new(geometry.get_border_width(), surface.get_border())
Overflow::Hidden
};
let text_tertiary_style: Style = style! {
FlexShrink(1.0)
MinWidth(Length::Px(0.0))
FontSize(16.0)
FontWeight::Bold
TextColor(surface.get_fg())
TextOverflow::Ellipsis
};
let row_fifth_style: Style = style! {
FlexShrink(0.0)
AlignItems::Center
Gap(SPACE_SM)
};
let root: NodeId = view! {
row {
style: row_quaternary_style
text {
style: text_tertiary_style
{ brand.as_str() }
}
row {
node_ref: actions_row
style: row_fifth_style
}
}
};
if !actions.is_empty() {
let mut ctx: Context = current_context();
ctx.append_many(actions_row, actions);
}
root
}
}
impl EuvFooter {
#[must_use]
pub fn surface_colors(palette: ThemePalette) -> SurfaceColors {
let surface: SurfaceColors = palette.surface(SurfaceRole::Muted);
let fg: Color =
palette.readable_foreground_with(palette.get_muted_foreground(), surface.get_bg());
SurfaceColors::new(surface.get_bg(), fg, surface.get_border())
}
}
#[component]
impl EuvFooter {
fn render(&self) -> NodeId {
let ctx: Context = current_context();
let base_tokens: ThemeTokens = self.get_tokens();
let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let geometry: ThemeGeometry = init_tok.get_geometry();
let surface: SurfaceColors = Self::surface_colors(init_tok.get_palette());
let Self { text, .. } = self;
let mut label_node: NodeId = NodeId::default();
let row_tertiary_style: Style = style! {
Width(Length::Percent(100.0))
MinHeight(Length::Px(geometry.get_control_md()))
Padding(Edges::symmetric(SPACE_MD, SPACE_LG))
JustifyContent::Center
AlignItems::Center
Background(surface.get_bg())
Border::new(geometry.get_border_width(), surface.get_border())
Overflow::Hidden
};
let text_secondary_style: Style = style! {
MaxWidth(Length::Percent(100.0))
FontSize(12.0)
TextColor(surface.get_fg())
TextAlign::Center
};
let root: NodeId = view! {
row {
style: row_tertiary_style
text {
node_ref: label_node
style: text_secondary_style
{ text.as_str() }
}
}
};
let handle: SceneHandle = ctx.get_scene().clone();
let prev_key: Cell<ThemeKey> = Cell::new(init_tok.key());
let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
Effect::new(move || {
let tok: ThemeTokens = use_live_tokens(base_tokens);
let old_key: ThemeKey = prev_key.replace(tok.key());
if old_key == tok.key() {
return;
}
let live_s: SurfaceColors = Self::surface_colors(tok.get_palette());
let live_g: ThemeGeometry = tok.get_geometry();
handle.with_write(
|tree: &mut SceneTree| {
if let Some(item_count) = tree.get_node_mut(root) {
let _: &mut PaintStyle = item_count
.get_mut_style()
.get_mut_paint()
.set_background(Some(live_s.get_bg()))
.set_border(Border::new(
live_g.get_border_width(),
live_s.get_border(),
));
tree.mark_dirty(root, DIRTY_PAINT);
}
if let Some(node_entry) = tree.get_node_mut(label_node) {
let _: &mut TextStyle = node_entry
.get_mut_style()
.get_mut_text()
.set_color(live_s.get_fg());
tree.mark_dirty(label_node, DIRTY_PAINT);
}
},
(),
);
})
});
ctx.get_scene().with_write(
|tree: &mut SceneTree| {
mark_theme_owned(tree, &[root, label_node]);
tree.attach_scope(root, scope);
},
(),
);
root
}
}
impl EuvButtonGroup {
#[must_use]
pub fn wrap_fill(mut self, enabled: bool) -> Self {
self.set_wrap_fill(enabled);
self
}
}
#[component]
impl EuvButtonGroup {
fn render(&self) -> NodeId {
let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
let theme_palette: ThemePalette = tokens.get_palette();
let geometry: ThemeGeometry = tokens.get_geometry();
let surface: SurfaceColors = theme_palette.surface(SurfaceRole::Muted);
let wrap_fill: bool = self.get_wrap_fill();
let outer_radius: f32 = geometry.get_radius_lg();
let inner_radius: f32 = concentric_radius(outer_radius, CONTROL_INSET);
let Self { children, .. } = self;
let row_secondary_style: Style = style! {
Width(if wrap_fill { Length::Percent(100.0) } else { Length::Auto })
FlexWrap::Wrap
AlignItems::Center
Gap(CONTROL_INSET)
Padding(Edges::all(CONTROL_INSET))
Background(surface.get_bg())
Border::new(geometry.get_border_width(), surface.get_border())
Radius(outer_radius)
Overflow::Hidden
};
let root: NodeId = view! {
row {
style: row_secondary_style
}
};
if !children.is_empty() {
let mut ctx: Context = current_context();
ctx.get_scene().with_write(
|tree: &mut SceneTree| {
for cid in children.iter().copied() {
let label_len: usize = if wrap_fill {
tree.get_node(cid)
.map(|scene_node: &SceneNode| {
let direct: usize = match scene_node.get_kind() {
NodeKind::Text(blend_factor) => {
blend_factor.chars().count()
}
_ => 0,
};
let child_max: usize = tree
.children_iter(cid)
.filter_map(|sub: NodeId| tree.get_node(sub))
.map(|sub_n: &SceneNode| match sub_n.get_kind() {
NodeKind::Text(time_step) => time_step.chars().count(),
_ => 0,
})
.max()
.unwrap_or(0);
direct.max(child_max)
})
.unwrap_or(0)
} else {
0
};
if let Some(item_count) = tree.get_node_mut(cid) {
let cur_r: f32 =
item_count.style_ref().get_paint().get_radius().max_radius();
if cur_r < RADIUS_PILL {
let _: &mut PaintStyle = item_count
.get_mut_style()
.get_mut_paint()
.set_radius(CornerRadius::all(inner_radius));
if let Some(mut hover_p) = item_count.hover_paint() {
let _: &mut PaintStyle =
hover_p.set_radius(CornerRadius::all(inner_radius));
let _: &mut SceneNode =
item_count.set_hover_style(Some(hover_p));
}
}
if wrap_fill {
let lay: &mut LayoutStyle =
item_count.get_mut_style().get_mut_layout();
let fixed_w: bool = !matches!(lay.get_width(), Length::Auto);
if !fixed_w {
let _: &mut LayoutStyle =
lay.set_flex_grow(1.0).set_flex_shrink(1.0);
if matches!(lay.get_min_width(), Length::Auto) {
let min_w: f32 =
((label_len as f32) * 7.2 + 24.0).clamp(76.0, 210.0);
let _: &mut LayoutStyle =
lay.set_min_width(Length::Px(min_w));
}
}
}
}
}
},
(),
);
ctx.append_many(root, children);
}
root
}
}
impl EuvToggle {
#[must_use]
pub fn state_colors(palette: ThemePalette, pressed: bool, hovered: bool) -> SurfaceColors {
if pressed {
palette.interaction_colors(InteractionRole::SolidPrimary, true, hovered, false)
} else {
palette.interaction_colors(InteractionRole::OutlineSurface, false, hovered, false)
}
}
}
#[component]
impl EuvToggle {
fn render(&self) -> NodeId {
let mut ctx: Context = current_context();
let base_tokens: ThemeTokens = self.get_tokens();
let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let theme_palette: ThemePalette = init_tok.get_palette();
let geometry: ThemeGeometry = init_tok.get_geometry();
let pressed: Signal<bool> = self.get_pressed();
let hovered: Signal<bool> = Signal::new(false);
let init_on: bool = pressed.get_untracked();
let init_surface: SurfaceColors = Self::state_colors(theme_palette, init_on, false);
let Self { label, .. } = self;
let label_owned: String = label.clone();
let a11y_label: String = label_owned.clone();
let mut label_node: NodeId = NodeId::default();
let on_toggle = move |_: &UiEvent| {
let _: bool = pressed.set(!pressed.get_untracked());
};
let row_style: Style = style! {
Height(Length::Px(geometry.get_control_sm()))
JustifyContent::Center
AlignItems::Center
Padding(Edges::symmetric(0.0, SPACE_MD))
Background(init_surface.get_bg())
Border::new(geometry.get_border_width().max(0.0), init_surface.get_border())
Radius(geometry.get_radius_sm())
Overflow::Hidden
CursorIcon::Pointer
};
let text_style: Style = style! {
FontSize(13.0)
FontWeight::Medium
TextColor(init_surface.get_fg())
TextAlign::Center
TextOverflow::Ellipsis
};
let root: NodeId = view! {
row {
style: row_style
on_click: on_toggle
text {
node_ref: label_node
style: text_style
{ label_owned }
}
}
};
ctx.on_hover(root, move |ui_event: &UiEvent| match ui_event.get_kind() {
UiEventKind::PointerEnter => {
let _: bool = hovered.set_if_changed(true);
}
UiEventKind::PointerLeave => {
let _: bool = hovered.set_if_changed(false);
}
_ => {}
});
let handle: SceneHandle = ctx.get_scene().clone();
let app_state_sig: Signal<AppState> = ctx.get_app_state();
let prev_state: Cell<(bool, bool, ThemeKey)> = Cell::new((init_on, false, init_tok.key()));
let a11y_fallback: String = a11y_label.clone();
let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
let _: Effect = Effect::new(move || {
if app_state_sig.get() != AppState::Active {
let _: bool = hovered.set_if_changed(false);
}
});
Effect::new(move || {
let is_on: bool = pressed.get();
let is_hovered: bool = hovered.get();
let tok: ThemeTokens = use_live_tokens(base_tokens);
let (old_on, old_h, old_key): (bool, bool, ThemeKey) =
prev_state.replace((is_on, is_hovered, tok.key()));
if old_on == is_on && old_h == is_hovered && old_key == tok.key() {
return;
}
let live_p: ThemePalette = tok.get_palette();
let live_g: ThemeGeometry = tok.get_geometry();
let surface: SurfaceColors = Self::state_colors(live_p, is_on, is_hovered);
let hover_surface: SurfaceColors = Self::state_colors(live_p, is_on, true);
handle.with_write(
|tree: &mut SceneTree| {
if let Some(item_count) = tree.get_node_mut(root) {
let paint: &mut PaintStyle = item_count.get_mut_style().get_mut_paint();
let _: &mut PaintStyle = paint
.set_background(Some(surface.get_bg()))
.set_border(Border::new(
live_g.get_border_width().max(0.0),
surface.get_border(),
))
.set_focus_ring(None);
let mut hover_paint: PaintStyle = *paint;
let _: &mut PaintStyle = hover_paint
.set_background(Some(hover_surface.get_bg()))
.set_border(Border::new(
live_g.get_border_width().max(0.0),
hover_surface.get_border(),
));
let _: &mut SceneNode = item_count.set_hover_style(Some(hover_paint));
if let Some(a11y) = item_count.get_mut_a11y().as_mut() {
let _: &mut A11yProps = a11y.set_checked(Some(is_on));
} else {
let mut a11y: A11yProps =
A11yProps::new(A11yRole::Button, a11y_fallback.clone());
let _: &mut A11yProps = a11y.set_checked(Some(is_on));
let _: &mut SceneNode = item_count.set_a11y(Some(a11y));
}
tree.mark_dirty(root, DIRTY_PAINT);
}
if let Some(node_entry) = tree.get_node_mut(label_node) {
let _: &mut TextStyle = node_entry
.get_mut_style()
.get_mut_text()
.set_color(surface.get_fg());
tree.mark_dirty(label_node, DIRTY_PAINT);
}
},
(),
);
})
});
ctx.get_scene().with_write(
|tree: &mut SceneTree| {
if let Some(normal_vec) = tree.get_node_mut(root) {
let mut a11y: A11yProps = A11yProps::new(A11yRole::Button, a11y_label);
let _: &mut A11yProps = a11y.set_checked(Some(init_on));
let _: &mut SceneNode = normal_vec.set_a11y(Some(a11y));
let _: &mut InteractionState =
normal_vec.get_mut_interaction().set_focusable(true);
let hover_s: SurfaceColors = Self::state_colors(theme_palette, init_on, true);
let mut hover_paint: PaintStyle = normal_vec.style_ref().get_paint();
let _: &mut PaintStyle = hover_paint
.set_background(Some(hover_s.get_bg()))
.set_border(Border::new(
geometry.get_border_width().max(0.0),
hover_s.get_border(),
));
let _: &mut SceneNode = normal_vec.set_hover_style(Some(hover_paint));
}
mark_theme_owned(tree, &[root, label_node]);
tree.attach_scope(root, scope);
},
(),
);
root
}
}