Style primitives

This commit is contained in:
2026-03-21 03:08:19 -04:00
parent c70f42704c
commit a70a08297e
7 changed files with 1306 additions and 178 deletions

View File

@@ -4,12 +4,12 @@ use std::time::{Duration, Instant};
use ruin_runtime::{TimeoutHandle, clear_timeout, set_timeout};
use ruin_ui::{
Color, CursorIcon, DisplayItem, Edges, Element, ElementId, ImageFit, ImageResource,
InteractionTree, KeyboardEvent, KeyboardEventKind, KeyboardKey, LayoutSnapshot, PlatformEvent,
PointerButton, PointerEvent, PointerEventKind, PointerRouter, PreparedText, Quad,
RoutedPointerEventKind, SceneSnapshot, TextAlign, TextFontFamily, TextSelectionStyle, TextSpan,
TextSpanSlant, TextSpanWeight, TextStyle, TextSystem, TextWrap, UiSize, WindowController,
WindowSpec, WindowUpdate, layout_snapshot_with_text_system,
BoxShadow, BoxShadowKind, Color, CursorIcon, DisplayItem, Edges, Element, ElementId, ImageFit,
ImageResource, InteractionTree, KeyboardEvent, KeyboardEventKind, KeyboardKey, LayoutSnapshot,
PlatformEvent, PointerButton, PointerEvent, PointerEventKind, PointerRouter, PreparedText,
Quad, RoutedPointerEventKind, SceneSnapshot, TextAlign, TextFontFamily, TextSelectionStyle,
TextSpan, TextSpanSlant, TextSpanWeight, TextStyle, TextSystem, TextWrap, UiSize,
WindowController, WindowSpec, WindowUpdate, layout_snapshot_with_text_system,
};
use ruin_ui_platform_wayland::start_wayland_ui;
use tracing_subscriber::layer::SubscriberExt;
@@ -1475,6 +1475,10 @@ fn build_document_tree(
.padding(Edges::all(gutter))
.gap(gutter * 0.45)
.background(card_background(NEXT_CARD_ID, hovered_card))
.border(2.0, card_border_color(NEXT_CARD_ID, hovered_card))
.corner_radius(gutter * 0.6)
.shadow(card_key_shadow(NEXT_CARD_ID, hovered_card))
.shadow(card_ambient_shadow(NEXT_CARD_ID, hovered_card))
.children([
Element::paragraph(
"Next direction",
@@ -1669,3 +1673,44 @@ fn card_title_color(id: ElementId, hovered_card: Option<ElementId>) -> Color {
}
Color::rgb(0xF4, 0xF7, 0xFF)
}
fn card_border_color(id: ElementId, hovered_card: Option<ElementId>) -> Color {
if hovered_card == Some(id) {
return Color::rgb(0xF5, 0xD0, 0x74);
}
match id {
NEXT_CARD_ID => Color::rgba(0x8B, 0x99, 0xAD, 0x78),
_ => Color::rgba(0x00, 0x00, 0x00, 0x00),
}
}
fn card_key_shadow(id: ElementId, hovered_card: Option<ElementId>) -> BoxShadow {
let hovered = hovered_card == Some(id);
BoxShadow::new(
ruin_ui::Point::new(0.0, if hovered { 16.0 } else { 12.0 }),
if hovered { 28.0 } else { 22.0 },
if hovered { -4.0 } else { -6.0 },
if hovered {
Color::rgba(0x04, 0x07, 0x0D, 0xC4)
} else {
Color::rgba(0x04, 0x07, 0x0D, 0x96)
},
BoxShadowKind::Outer,
)
}
fn card_ambient_shadow(id: ElementId, hovered_card: Option<ElementId>) -> BoxShadow {
let hovered = hovered_card == Some(id);
BoxShadow::new(
ruin_ui::Point::new(0.0, if hovered { 4.0 } else { 2.0 }),
if hovered { 10.0 } else { 8.0 },
0.0,
if hovered {
Color::rgba(0x0C, 0x16, 0x27, 0x88)
} else {
Color::rgba(0x0C, 0x16, 0x27, 0x62)
},
BoxShadowKind::Outer,
)
}