mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
ui-contract, ui-widgets menu: a menu row stands size.row.menu high (StyleCx::menu_row_height, grown as a control's height is; a small row stays a small control high); a compact row keeps its text line's height. Every size set gives size.row.menu the control's height, so no app's menus change. Trial
This commit is contained in:
1 parent
00e2d98224
commit
03fea7ac47
4 files changed
+37
-4
No files matched your search
@@ -405,6 +405,15 @@ impl<'a> StyleCx<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The height of a menu row at the ambient size: `size.row.menu` at the medium size, grown as a control's height
|
||||
/// is; a small row stands a small control high.
|
||||
pub fn menu_row_height(&self) -> f32 {
|
||||
match self.size {
|
||||
ControlSize::Sm => self.control().height,
|
||||
ControlSize::Md => grown(self.tokens, self.tokens.size.row.menu, self.line_ratio),
|
||||
}
|
||||
}
|
||||
|
||||
/// How the icon-only buttons of the scope show their glyph.
|
||||
pub fn glyph_role(&self) -> GlyphRole {
|
||||
self.glyphs
|
||||
|
||||
@@ -487,10 +487,8 @@ impl Component for MenuItem<'_> {
|
||||
// A row's content sits `space.pad.regular` in from the popup's own padding, so a label starts clear of the edge.
|
||||
let mut metrics = control.metrics();
|
||||
metrics.padding = Insets::new(tokens.space.pad.regular, tokens.space.pad.regular, metrics.padding.top, metrics.padding.bottom);
|
||||
if key.compact {
|
||||
// The text line sets the height, as in a classic menu: no control height floor.
|
||||
metrics.min_size.y = 0.0;
|
||||
}
|
||||
// The text line sets a compact row's height, as in a classic menu; any other row stands a menu row high.
|
||||
metrics.min_size.y = if key.compact { 0.0 } else { cx.menu_row_height() };
|
||||
MenuItemStyle {
|
||||
surface,
|
||||
metrics,
|
||||
|
||||
@@ -398,3 +398,28 @@ fn the_open_submenu_parent_keeps_the_accent_when_the_pointer_enters_its_child()
|
||||
assert_eq!(fills_in(&shapes, parent), accent, "the parent keeps its accent while its child is active at {scale}×");
|
||||
}
|
||||
}
|
||||
|
||||
/// A menu row stands `size.row.menu` high (VectorCraft's 29-point rows), and an app that sets only the control height
|
||||
/// keeps its rows a control high.
|
||||
#[trial]
|
||||
fn a_menu_row_stands_a_menu_row_high() {
|
||||
let row = |overrides: &[(&str, f32)]| {
|
||||
let mut sizes = craft_theme::AppSizes::default();
|
||||
for (path, value) in overrides {
|
||||
sizes.all.insert((*path).to_owned(), craft_theme::SizeValue::Number(*value));
|
||||
}
|
||||
let mut root = craft_ui::runtime::env::RootEnv::default();
|
||||
root.sizes = Arc::new(sizes);
|
||||
let mut fixture = Fixture::new(|ui| {
|
||||
Menu::inline("File").show(ui, |ui, _| {
|
||||
MenuItem::new("Open").show(ui);
|
||||
MenuItem::new("Save").show(ui);
|
||||
});
|
||||
});
|
||||
fixture.root(root).settle();
|
||||
fixture.by_label("Save").expect("the row is shown").rect.height()
|
||||
};
|
||||
let (standard, menu, control) = (row(&[]), row(&[("size.row.menu", 44.0)]), row(&[("size.control.md", 44.0)]));
|
||||
assert!(menu > standard + 10.0, "a taller menu row raises the row: {standard} then {menu}");
|
||||
assert!((control - menu).abs() < 0.5, "a row follows the control height when the app sets no menu row: {control} and {menu}");
|
||||
}
|
||||
@@ -1006,6 +1006,7 @@ A theme with its own shape replaces the radii or adds an offset to control, surf
|
||||
| `size.length.number.sm`, `size.length.number.md` | Number field and the number cell over a slider, one width per control size |
|
||||
| `size.length.track`, `size.length.short` | Value track, short field |
|
||||
| `size.row.text` | A row that shows text only: one body line and `space.gap.tight`; read-only display tables take it, lists the user picks from keep control-high rows |
|
||||
| `size.row.menu` | A menu row's height at the medium control size (`MenuItem`); follows an app's `size.control.md` unless the app sets it |
|
||||
| `size.dialog.least`, `size.dialog.wrap` | A dialog's content: the least width it opens at, and the line length its paragraphs wrap at (`LeastWidth::Dialog`, `WrapWidth::Dialog`); content that cannot wrap widens it past that |
|
||||
| `size.dialog.button`, `size.dialog.side_button` | Least width of a dialog's footer button and of a button in its column beside the body |
|
||||
| `size.hit.edge` | The band inside the edge of a canvas's view in which a tool that autoscrolls on hover scrolls the view (a Polygonal Lasso's rubber band), at most a quarter of the view's shorter side |
|
||||
|
||||
Reference in new issue
Block a user