Refactor ruin_app, add some README files, minor usability in reactivity

This commit is contained in:
2026-03-25 22:32:11 -04:00
parent 5f67c06083
commit 341d07d82f
28 changed files with 2782 additions and 2118 deletions

View File

@@ -257,6 +257,7 @@ pub fn layout_snapshot_with_cache(
}
}
#[allow(clippy::too_many_arguments)]
fn layout_element(
element: &Element,
rect: Rect,
@@ -797,6 +798,7 @@ struct MeasuredChild {
is_flex: bool,
}
#[allow(clippy::too_many_arguments)]
fn layout_container_children(
element: &Element,
content: Rect,
@@ -996,8 +998,13 @@ fn intrinsic_container_content_size(
.height
.map(|h| h + vertical_insets(child_insets))
.unwrap_or(content_size.height);
let child_size =
intrinsic_size(child, UiSize::new(offered_w, offered_h), text_system, perf_stats, layout_cache);
let child_size = intrinsic_size(
child,
UiSize::new(offered_w, offered_h),
text_system,
perf_stats,
layout_cache,
);
// child_size is always outer; accumulate directly.
width = width.max(child_size.width);
if !skip_main {
@@ -1030,8 +1037,13 @@ fn intrinsic_container_content_size(
.height
.map(|h| h + vertical_insets(child_insets))
.unwrap_or(content_size.height);
let child_size =
intrinsic_size(child, UiSize::new(offered_w, offered_h), text_system, perf_stats, layout_cache);
let child_size = intrinsic_size(
child,
UiSize::new(offered_w, offered_h),
text_system,
perf_stats,
layout_cache,
);
// child_size.width is outer; use directly as the fixed main contribution.
let child_main = child_size.width;
fixed_main += child_main;

View File

@@ -80,6 +80,9 @@ impl Color {
/// safe to reserve as a sentinel. No user-facing API sets this value directly.
pub const SENTINEL: Self = Self::rgba(0, 0, 0, 0);
pub const BLACK: Self = Self::rgb(0, 0, 0);
pub const WHITE: Self = Self::rgb(255, 255, 255);
pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
Self { r, g, b, a }
}
@@ -219,6 +222,7 @@ impl Deref for PreparedText {
impl PreparedText {
/// Construct a `PreparedText` from shaped data. Called by `TextSystem::prepare_spans`.
#[allow(clippy::too_many_arguments)]
pub(crate) fn from_layout(
element_id: Option<ElementId>,
text: String,
@@ -623,10 +627,18 @@ impl DisplayItem {
/// Return a copy of this item with all positions shifted by `offset`.
pub fn translated(&self, offset: Point) -> Self {
fn translate_rect(r: Rect, o: Point) -> Rect {
Rect::new(r.origin.x + o.x, r.origin.y + o.y, r.size.width, r.size.height)
Rect::new(
r.origin.x + o.x,
r.origin.y + o.y,
r.size.width,
r.size.height,
)
}
match self {
Self::Quad(q) => Self::Quad(Quad { rect: translate_rect(q.rect, offset), ..*q }),
Self::Quad(q) => Self::Quad(Quad {
rect: translate_rect(q.rect, offset),
..*q
}),
Self::RoundedRect(r) => Self::RoundedRect(RoundedRect {
rect: translate_rect(r.rect, offset),
..*r
@@ -838,8 +850,8 @@ mod tests {
#[test]
fn prepared_text_vertical_offset_moves_between_lines() {
use std::sync::Arc;
use super::{PreparedTextLine, TextLayoutData};
use std::sync::Arc;
let mut text = PreparedText::monospace(
"abcdwxyz",
@@ -873,7 +885,11 @@ mod tests {
}
}
let orig_size = text.layout.size;
text.layout = Arc::new(TextLayoutData { lines, glyphs, size: orig_size });
text.layout = Arc::new(TextLayoutData {
lines,
glyphs,
size: orig_size,
});
assert_eq!(text.vertical_offset(2, 1), Some(6));
assert_eq!(text.vertical_offset(6, -1), Some(2));
@@ -892,8 +908,12 @@ mod tests {
let target_line = &text.lines[1];
// Lines store LOCAL coords; add text.origin to get absolute window coords for the query.
let y = text.origin.y + target_line.rect.origin.y + target_line.rect.size.height * 0.5;
let start = text.byte_offset_for_position(Point::new(text.origin.x + target_line.rect.origin.x, y));
let end = text.byte_offset_for_position(Point::new(text.origin.x + target_line.rect.origin.x + 16.0, y));
let start =
text.byte_offset_for_position(Point::new(text.origin.x + target_line.rect.origin.x, y));
let end = text.byte_offset_for_position(Point::new(
text.origin.x + target_line.rect.origin.x + 16.0,
y,
));
let rects = text.selection_rects(start, end);
assert_eq!(rects.len(), 1);