mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 15:44:26 +00:00
Design lint: rail trials compare within a point, story strip sizes from IconicSizes, dead rail exemptions removed
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
use super::{FloatingGroup, WindowColumn};
|
||||
use crate::buttons::Button;
|
||||
use crate::contract::Show as _;
|
||||
use crate::docking::IconicSizes;
|
||||
use crate::menu::MenuItem;
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use craft_behavior::dock::DockEdge;
|
||||
@@ -10,6 +11,15 @@ use egui::{Pos2, Rect, Ui, Vec2};
|
||||
|
||||
const START: Rect = Rect { min: Pos2::new(40.0, 40.0), max: Pos2::new(280.0, 220.0) };
|
||||
|
||||
/// The icons a collapsed story column shows: three panels.
|
||||
const ICON_CELLS: f32 = 3.0;
|
||||
|
||||
/// The size of a collapsed column of `ICON_CELLS` icon cells.
|
||||
fn icon_strip(ui: &Ui) -> Vec2 {
|
||||
let sizes = IconicSizes::of(ui.ctx());
|
||||
Vec2::new(sizes.cell, sizes.cell * ICON_CELLS)
|
||||
}
|
||||
|
||||
#[story(FloatingGroup<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn floating_group(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let rect = *data.value("rect", START);
|
||||
@@ -32,8 +42,7 @@ fn floating_group(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
fn floating_dock_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let rect = *data.value("rect", START);
|
||||
let collapsed = *data.value("collapsed", false);
|
||||
// A strip of three icon cells, as an iconic column of three panels is.
|
||||
let column = if collapsed { WindowColumn::collapsed(DockEdge::Start, Vec2::new(40.0, 120.0)) } else { WindowColumn::expanded(DockEdge::Start) };
|
||||
let column = if collapsed { WindowColumn::collapsed(DockEdge::Start, icon_strip(ui)) } else { WindowColumn::expanded(DockEdge::Start) };
|
||||
let shown = FloatingGroup::new("Layers", rect).column(column).sized(crate::contract::Sizing::Fill).show_group(ui, |ui, _| {
|
||||
Button::new(if collapsed { "L" } else { "Add layer" }).show(ui);
|
||||
});
|
||||
@@ -50,7 +59,7 @@ fn floating_dock_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(FloatingGroup<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn floating_collapsed_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let rect = *data.value("rect", START);
|
||||
let column = WindowColumn::collapsed(DockEdge::End, Vec2::new(40.0, 120.0));
|
||||
let column = WindowColumn::collapsed(DockEdge::End, icon_strip(ui));
|
||||
let shown = FloatingGroup::new("Layers", rect).column(column).sized(crate::contract::Sizing::Fill).show_group(ui, |ui, _| {
|
||||
Button::new("L").show(ui);
|
||||
});
|
||||
|
||||
@@ -50,6 +50,7 @@ fn tool_rail(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let width = ToolRail::<u8>::dock_grid(ui.ctx(), slots.len() + 1).width(u16::from(columns));
|
||||
let out = ui
|
||||
.scope(|ui| {
|
||||
// design: allow[contract/memory](the story gives the rail the width of its chosen columns, as a dock column does)
|
||||
ui.set_max_width(width);
|
||||
ToolRail::new("Tools", &slots, &BRUSH, &last).hidden(&hidden).edit_toolbar("Edit Toolbar").show_rail(ui, |_, _| {})
|
||||
})
|
||||
|
||||
@@ -66,7 +66,7 @@ fn a_tool_rail_lays_out_the_most_whole_columns_its_width_holds() {
|
||||
let (fixture, _) = rail_in(grid.width(steps), 800.0);
|
||||
assert_eq!(columns_of(&fixture), usize::from(steps), "a width of {steps} steps shows {steps} columns");
|
||||
let rail = rect(&fixture, "Tools");
|
||||
assert!((rail.width() - grid.width(steps)).abs() < 1.0, "{steps} steps: the rail is as wide as its columns: {rail:?}");
|
||||
assert!(near(rail.width(), grid.width(steps)), "{steps} steps: the rail is as wide as its columns: {rail:?}");
|
||||
if steps > 1 {
|
||||
let (short, _) = rail_in(grid.width(steps) - 1.0, 800.0);
|
||||
assert_eq!(columns_of(&short), usize::from(steps) - 1, "a width short of {steps} steps shows one column fewer");
|
||||
@@ -86,13 +86,10 @@ fn a_tool_rail_measures_its_rows_plus_its_footer_at_a_width() {
|
||||
let (fixture, measured) = rail_in(grid.width(steps), 800.0);
|
||||
let (rail, foot, first) = (rect(&fixture, "Tools"), rect(&fixture, "Foot"), rect(&fixture, "Move"));
|
||||
let size = measured.get();
|
||||
assert!((size.y - rail.height()).abs() < 1.0, "{steps} steps: the measure ({size:?}) is the shown rail ({rail:?})");
|
||||
assert!((size.x - rail.width()).abs() < 1.0, "{steps} steps: the measure is as wide as the shown rail");
|
||||
assert!(near(size.y, rail.height()), "{steps} steps: the measure ({size:?}) is the shown rail ({rail:?})");
|
||||
assert!(near(size.x, rail.width()), "{steps} steps: the measure is as wide as the shown rail");
|
||||
let (top, bottom) = (first.top() - rail.top(), rail.bottom() - foot.bottom());
|
||||
assert!(
|
||||
(top - bottom).abs() < 1.0,
|
||||
"{steps} steps: the rows and the footer fill the rail between equal paddings ({top} above, {bottom} below)"
|
||||
);
|
||||
assert!(near(top, bottom), "{steps} steps: the rows and the footer fill the rail between equal paddings ({top} above, {bottom} below)");
|
||||
heights.push(size.y);
|
||||
}
|
||||
assert!(grows_with(heights[1], heights[0]), "one column is taller than two: {heights:?}");
|
||||
@@ -148,3 +145,7 @@ fn the_tool_rail_shows_its_buttons_icons_in_its_glyph_role() {
|
||||
assert!(tool.side > alone.side, "a tool rail icon ({}) is larger than a lone one ({})", tool.side, alone.side);
|
||||
assert!(tool.color.off.rest != tool.color.off.hover, "a tool rail icon rests quieter than under the pointer");
|
||||
}
|
||||
|
||||
fn near(a: f32, b: f32) -> bool {
|
||||
(a - b).abs() < 1.0
|
||||
}
|
||||
|
||||
@@ -3,11 +3,6 @@ paths = ["crates/behavior", "crates/ui", "crates/ui-contract", "crates/ui-widget
|
||||
include-tests = false
|
||||
deny-unused = true
|
||||
|
||||
[[exempt]]
|
||||
path = "crates/ui-panels/src/rails/tool/trials.rs"
|
||||
rules = ["literal-size"]
|
||||
reason = "trial rooms, not looks"
|
||||
|
||||
[[exempt]]
|
||||
path = "crates/ui-panels/src/docking/iconic/trials.rs"
|
||||
rules = ["literal-size"]
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
config_version = 1
|
||||
|
||||
[[exception]]
|
||||
name = "tool-rail-trial-rooms"
|
||||
kind = "exempt"
|
||||
rule = "literal-size"
|
||||
path = "crates/ui-panels/src/rails/tool/trials.rs"
|
||||
reason = "Trial rooms, not looks."
|
||||
count = 1
|
||||
Reference in New Issue
Block a user