Module cards

Source
Expand description

Borrowed menu/result cards in logical UI units, using the existing modal and atomic composition. Pass bounds inside a responsive viewport’s safe area; coordinates start at zero inside that safe area. Absolute task271 rectangles use a zero-inset responsive viewport. Fitted viewports scale logical units and are a caller choice. Fonts never shrink: title 24, body/stats/actions 18, padding 16, section gaps 12, action gaps 8 and action height 44.

Actions keep caller IDs/order/availability. The primary ID must be present, including when disabled; start/resume/retry and authoritative progression remain game-owned. finish_player/finish and paint happen after submission. A returned action can be queued until an actual simulation tick; cards never sample gameplay input or own a lifecycle. Controls-open gating stays in Ui.

Without scrolling, only a complete prefix of sections is submitted. Overflow paints CONTENT OMITTED and reports omitted sections/stat rows. To expose all copy, reuse task274’s pure ScrollState: set its extents from the layout, feed accepted/remapped scroll commands outside composition, then submit it. No new pointer/keyboard routing is installed. Do not enable a ScrollRegion alongside another UI input owner; its documented routing limits still apply. Scroll translation retains full line rectangles under the content/ancestor clips. Only intersecting lines are queued, so offscreen copy spends no UI vertex/text budget. Inspection describes those actual line commands, retaining UTF-8; bitmap glyph substitution/word wrapping follow WrappedText.

This executed native/headless recipe composes actual start, pause and results cards with one/three actions and a disabled action at 320x480 and wide. It exercises retained paint/inspection, not a GPU, browser or device playtest.

use ferravex_render::ui::{Ui, UiError, UiLabel, Viewport};
use ferravex_render::ui::cards::{CardAction, CardContent, CardLayout, CardSection};
use ferravex_render::ui::stats::StatRow;
use ferravex_render::input::host_frame;
let mut ui = Ui::new();
ui.set_inspection_enabled(true);
let rows = [StatRow { label: "TIME", value: "1:00.001", description: None }];
let sections = [CardSection::Body("Collect crystals. Return to the entrance."),
                CardSection::Stats(&rows)];
for width in [320., 960.] {
    for (title, primary, three) in [("CRYSTAL CAVERN", "START", false),
                                   ("PAUSED", "RESUME", true),
                                   ("EXPEDITION COMPLETE", "RETRY", true)] {
        let actions = [CardAction { id: 901, label: primary, enabled: true },
                       CardAction { id: 902, label: "CONTROLS", enabled: true },
                       CardAction { id: 903, label: "NEXT", enabled: false }];
        let viewport = Viewport::responsive([width, 480.], [8., 12., 8., 12.])?;
        let layout = CardLayout::new(viewport.bounds(), CardContent {
            title, sections: &sections, actions: &actions[..if three { 3 } else { 1 }],
            primary: 901, blocker: 900,
        })?;
        host_frame(0., width as u32, 480, || -> Result<(), UiError> {
            ui.begin(viewport);
            let report = ui.card(&layout, None)?;
            assert_eq!(report.omitted_sections, 0);
            ui.finish(true); // No simulation tick is required to render a menu.
            for action in &actions[..if three { 3 } else { 1 }] {
                let element = ui.inspect().unwrap().find(|e| e.id == Some(action.id)).unwrap();
                assert_eq!(element.label, UiLabel::Full(action.label));
                assert_eq!(element.bounds, layout.action_rect(action.id).unwrap());
                assert_eq!(element.visible_bounds, Some(element.bounds));
                assert_eq!(element.enabled, action.enabled);
            }
            assert!(!ui.activated(999));
            ui.paint();
            Ok(())
        })?;
    }
}

Scrolling and nested atomic submission use the same layout. Update scroll state outside the group; no wheel, pointer, gameplay edge or clock is read.

use ferravex_play::ui::scroll::ScrollState;
use ferravex_render::ui::{Ui, UiError, Viewport};
use ferravex_render::ui::cards::{CardAction, CardContent, CardLayout, CardSection};
let mut ui = Ui::new();
let viewport = Viewport::responsive([320., 480.], [0.; 4])?;
let copy = "Long briefing. Read before starting.\n".repeat(80);
let sections = [CardSection::Body(&copy)];
let actions = [CardAction { id: 1, label: "START", enabled: true }];
let layout = CardLayout::new(viewport.bounds(), CardContent {
    title: "BRIEFING", sections: &sections, actions: &actions, primary: 1, blocker: 2,
})?;
let mut scroll = ScrollState::new(layout.content_bounds().size[1], layout.content_extent())?;
scroll.page(false); // Feed an accepted remapped menu edge here.
ui.begin(viewport);
let report = ui.compose(|group| layout.submit(group, Some(&scroll)))?;
assert!(report.scrollable);
assert_eq!(report.omitted_sections, 0); // All source remains reachable.
assert_eq!(layout.action_rect(99), None);
ui.paint();
scroll.reset(); // On a new screen/session, caller decides reset semantics.
assert_eq!(scroll.offset(), 0.);

Structs§

CardAction
Stable caller identity and full single-line label; labels are never ellipsized.
CardContent
Borrowed content, not retained state. IDs must be unique, including blocker.
CardLayout
Immutable fixed-storage measured card. Rebuild on copy/bounds changes; no cache, allocation, input consumption or external mutation occurs in layout.
CardReport
Layout omission, independent of ancestor clips, occlusion and physical pixels.

Enums§

CardSection
Borrowed full sections. A non-scrolling overflow omits the entire section, including every value of a stats section, rather than cropping an essential value. Use scrolling when that omission is unsuitable for the game.

Constants§

MAX_CARD_ACTIONS
Actions per card; all must fit, including disabled actions.
MAX_CARD_BYTES
Combined UTF-8 bytes in title, sections/stat fields and action labels. Checked before measurement; stat rows are additionally capped at 64 total.
MAX_CARD_SECTIONS
Sections per card; checked before scanning source.