mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 03:17:43 +00:00
look-7a: Pad::Page, a full-window page's margin (two and a half roomy pads, 40 pt compact), as WordCraft's File pages stand off the window; trial and the Stack story's pad choice
This commit is contained in:
@@ -45,6 +45,7 @@ pub fn pad_of(tokens: &UiTokens, pad: Pad) -> f32 {
|
||||
Pad::Control => pads.control,
|
||||
Pad::Regular => pads.regular,
|
||||
Pad::Roomy => pads.roomy,
|
||||
Pad::Page => pads.roomy * 2.5,
|
||||
_ => 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +135,9 @@ pub enum Pad {
|
||||
Regular,
|
||||
/// `space.pad.roomy`.
|
||||
Roomy,
|
||||
/// A full-window page's margin around its content: two and a half roomy pads (40 pt in the compact set), as a
|
||||
/// File page's body stands off the window and its side menu.
|
||||
Page,
|
||||
}
|
||||
|
||||
/// The edges a container's padding tier applies to.
|
||||
|
||||
@@ -11,7 +11,7 @@ use egui::Ui;
|
||||
/// The gap and padding tier the Row and Stack stories edit.
|
||||
fn spacing(data: &mut StoryData, gap: Gap, gaps: &'static [(&'static str, Gap)]) -> (Gap, Pad) {
|
||||
let gap = *data.choice("gap", gap, gaps);
|
||||
let pad = *data.choice("pad", Pad::Regular, &[("None", Pad::None), ("Control", Pad::Control), ("Regular", Pad::Regular), ("Roomy", Pad::Roomy)]);
|
||||
let pad = *data.choice("pad", Pad::Regular, &[("None", Pad::None), ("Control", Pad::Control), ("Regular", Pad::Regular), ("Roomy", Pad::Roomy), ("Page", Pad::Page)]);
|
||||
(gap, pad)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! row there too.
|
||||
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{Gap, LeastWidth, Props as _, Scroll, Show as _, ShowContainer as _, Sizing, WrapWidth};
|
||||
use craft_ui::contract::{Gap, LeastWidth, Pad, Props as _, Scroll, Show as _, ShowContainer as _, Sizing, WrapWidth};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
@@ -85,6 +85,27 @@ fn a_side_menu_in_a_row_keeps_its_least_width() {
|
||||
assert!(menu.height() > 800.0, "the menu is as tall as the row: {menu:?}");
|
||||
}
|
||||
|
||||
/// A page's padding stands its content off the edges by two and a half roomy pads: a File page's margin.
|
||||
#[trial]
|
||||
fn a_pages_padding_is_two_and_a_half_roomy_pads() {
|
||||
let inset = |pad: Pad| {
|
||||
let seen = Rc::new(Cell::new(Vec2::ZERO));
|
||||
let out = Rc::clone(&seen);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let child = Cell::new(Rect::NOTHING);
|
||||
let shown = Stack::new().pad(pad).show(ui, |ui, _| child.set(Button::new("Home").show(ui).rect));
|
||||
if !ui.is_sizing_pass() {
|
||||
out.set(child.get().min - shown.output.rect.min);
|
||||
}
|
||||
});
|
||||
fixture.room(Vec2::new(800.0, 600.0)).settle();
|
||||
seen.get()
|
||||
};
|
||||
let (roomy, page) = (inset(Pad::Roomy), inset(Pad::Page));
|
||||
assert!(roomy.x > 0.0, "a roomy stack pads its content: {roomy:?}");
|
||||
assert!((page.x - roomy.x * 2.5).abs() < 0.6 && (page.y - roomy.y * 2.5).abs() < 0.6, "a page pads 2.5 roomy pads: {page:?} for {roomy:?}");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_stacks_wrap_width_breaks_a_long_paragraph_at_the_column() {
|
||||
let (plain, one_line) = shown(Stack::new, true);
|
||||
|
||||
Reference in New Issue
Block a user