mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 12:21:08 +01:00
Panels: rows wrap in a panel at its narrowest width
At the narrowest panel width (220 pt), rows of side-by-side controls ran past the panel's edge in Stroke (the Profile list and the two flip buttons), Attributes (Fill Rule, Image Map with Browser, and the URL field after them), Variables (the footer's buttons), Properties (the Align buttons and More Align options), Magic Wand (Tolerance, in French) and Document Info (a label and its value, in German). These rows now wrap onto a new line when the panel is too narrow for them, as the Arrowheads row already does. A wider panel keeps each row on one line. The tests float each panel at the narrowest width in the whole window and check that the named controls stay inside it, and that the Stroke panel's Profile row stays on one line at 360 pt.
This commit is contained in:
1 parent
2a5dbc479f
commit
2b075e5a9a
8 files changed
+104
-8
No files matched your search
@@ -306,7 +306,7 @@ fn bar_items(buttons: impl Iterator<Item = Button>) -> BarItems {
|
||||
/// Align panel's Align To says (the key object while there is one), as its own buttons do (#789),
|
||||
/// and the selected artboards with the Artboard tool chosen.
|
||||
pub(crate) fn align_buttons(_app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Row::new().wrap(true).show(ui, |ui, _| {
|
||||
for (icon, b) in align_icons() {
|
||||
command_button(ui, bar_glyph(b).unwrap_or(icon), b);
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
});
|
||||
if !part_hidden(app, OPTIONS_KEY) {
|
||||
Divider::horizontal().show(ui);
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Row::new().wrap(true).show(ui, |ui, _| {
|
||||
let center = [("dc-center-hide", tl!("Don't Show Center"), false), ("dc-center-show", tl!("Show Center"), true)];
|
||||
acts.extend(pair(ui, tl!("Show Center"), has, info.show_center, center).map(|v| ("attributes.set", json!({ "showCenter": v }))));
|
||||
let dir = [("dc-dir-off", tl!("Reverse Path Direction Off"), false), ("dc-dir-on", tl!("Reverse Path Direction On"), true)];
|
||||
@@ -170,7 +170,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let maps = ImageMap::ALL.map(|m| Entry::new(m, m.label()));
|
||||
let name = side_name(tl!("Image Map:"));
|
||||
Field::new(name.clone()).show(ui, |ui, _| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Row::new().wrap(true).show(ui, |ui, _| {
|
||||
let pick = Select::new(name.clone(), Bind::given(or_mixed(info.image_map)), &maps).enabled(has).show(ui);
|
||||
acts.extend(pick.events.committed().map(|m| ("attributes.set", json!({ "imageMap": m }))));
|
||||
let browser = Button::new(tl!("Browser")).enabled(url.is_some()).tooltip(tl!("Open the URL in the web browser")).show(ui);
|
||||
|
||||
@@ -33,7 +33,7 @@ pub struct DocInfoView {
|
||||
/// A `label: value` row. `label` is shown as given: translate an interface label first, a name
|
||||
/// stays as it is.
|
||||
pub(crate) fn row(ui: &mut Ui, label: &str, value: String) {
|
||||
Row::new().fill_width().align(RowAlign::SpaceBetween).show(ui, |ui, _| {
|
||||
Row::new().fill_width().align(RowAlign::SpaceBetween).wrap(true).show(ui, |ui, _| {
|
||||
Text::new(label.to_string()).shade(Shade::Muted).show(ui);
|
||||
// The value can be selected and copied (#8432).
|
||||
SelectableText::new(label.to_string(), &value).show(ui);
|
||||
|
||||
@@ -39,7 +39,7 @@ fn tolerance(o: &Value, key: &str) -> NumberField<'static> {
|
||||
/// checkbox is on.
|
||||
fn row(app: &mut VectorcraftApp, ui: &mut Ui, o: &Value, label: &'static str, flag: &str, tol: Option<(&str, &dyn Fn() -> NumberField<'static>)>) {
|
||||
let on = o[flag].as_bool().unwrap_or(false);
|
||||
Row::new().fill_width().align(RowAlign::SpaceBetween).show(ui, |ui, _| {
|
||||
Row::new().fill_width().align(RowAlign::SpaceBetween).wrap(true).show(ui, |ui, _| {
|
||||
if let Some(now) = Checkbox::new(Bind::given(on)).label(label).id_salt(flag).show(ui).value().copied() {
|
||||
app.run("magicWand.set", json!({ flag: now })).ok();
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui, first: Option<&Node>, n_sel: usiz
|
||||
}
|
||||
appearance_section::appearance_section(app, ui);
|
||||
section(tl!("Align")).show(ui, |ui, _| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Row::new().wrap(true).show(ui, |ui, _| {
|
||||
super::align::align_buttons(app, ui);
|
||||
// The rest (Distribute Objects, Distribute Spacing, Align To) is the Align panel's.
|
||||
more_options(ui, "align", tl!("More Align options"));
|
||||
|
||||
@@ -391,7 +391,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
arrow_rows(app, ui, st.as_ref());
|
||||
ui.separator();
|
||||
Field::new(tl!("Profile")).show(ui, |ui, _| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Row::new().wrap(true).show(ui, |ui, _| {
|
||||
profile_select(app, ui);
|
||||
flip_buttons(app, ui, st.as_ref());
|
||||
});
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
//! Headless frames of panel rows that the framework lays out: controls side by side stay inside the panel's width.
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use super::tests_appearance::app_with_rect;
|
||||
use super::*;
|
||||
use crate::i18n::Lang;
|
||||
use crate::panel_docking::PANEL_MIN_WIDTH;
|
||||
use crate::tests::panel_harness::{Panel, ROOM};
|
||||
|
||||
@@ -27,6 +30,99 @@ fn the_color_themes_hex_row_stays_inside_a_narrow_panel() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Panel `panel` floated `width` wide in the whole app window, drawn in `lang`: the rect of its body, and the rects of
|
||||
/// the controls named each of `names` (catalog strings, shown in `lang`).
|
||||
fn floated(panel: &str, lang: &str, width: f32, names: &[&str]) -> (egui::Rect, Vec<(String, Vec<egui::Rect>)>) {
|
||||
use egui::accesskit::Role;
|
||||
const AT: f32 = 520.0;
|
||||
let mut app = app_with_rect();
|
||||
app.session.prefs.interface_language = lang.into();
|
||||
app.run("window.panel", json!({ "panel": panel })).unwrap();
|
||||
app.run("window.panel.float", json!({ "panel": panel, "x": AT, "y": 120, "width": width, "height": 700 })).unwrap();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.enable_accesskit();
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1440.0, 900.0));
|
||||
let mut nodes = Vec::new();
|
||||
for at in 1..=8 {
|
||||
let input = egui::RawInput { time: Some(f64::from(at) * 0.1), screen_rect: Some(screen), ..Default::default() };
|
||||
let out = crate::testing::app_frame(&mut app, &ctx, input);
|
||||
nodes = out.platform_output.accesskit_update.map_or_else(Vec::new, |update| update.nodes);
|
||||
}
|
||||
// The frames set the language from the preference; the names are looked up in it before English is put back.
|
||||
let shown: Vec<&str> = names.iter().map(|name| crate::i18n::t(name)).collect();
|
||||
crate::i18n::set_current(Lang::EN);
|
||||
let rect = |node: &egui::accesskit::Node| {
|
||||
node.bounds().map(|b| egui::Rect::from_min_max(egui::pos2(b.x0 as f32, b.y0 as f32), egui::pos2(b.x1 as f32, b.y1 as f32)))
|
||||
};
|
||||
// The floating panel's body: the tab panel at the left edge the float asked for.
|
||||
let body = nodes
|
||||
.iter()
|
||||
.filter(|(_, n)| n.role() == Role::TabPanel)
|
||||
.find_map(|(_, n)| rect(n).filter(|r| (r.left() - AT).abs() < 1.0))
|
||||
.unwrap_or_else(|| panic!("{panel} does not float at x {AT}"));
|
||||
let controls = shown
|
||||
.into_iter()
|
||||
.map(|name| {
|
||||
let found: Vec<egui::Rect> = nodes.iter().filter(|(_, n)| n.label().is_some_and(|l| l == name)).filter_map(|(_, n)| rect(n)).collect();
|
||||
assert!(!found.is_empty(), "{panel} shows no {name:?}");
|
||||
(name.to_owned(), found)
|
||||
})
|
||||
.collect();
|
||||
(body, controls)
|
||||
}
|
||||
|
||||
/// The controls named `names` (catalog strings, shown in `lang`) that reach past either side of panel `panel`,
|
||||
/// floated at the narrowest panel width in the whole app window, each with its rect.
|
||||
fn past_a_narrow_panel(panel: &str, lang: &str, names: &[&str]) -> Vec<String> {
|
||||
let (body, controls) = floated(panel, lang, PANEL_MIN_WIDTH, names);
|
||||
let outside = |r: &egui::Rect| r.left() < body.left() - 0.5 || r.right() > body.right() + 0.5;
|
||||
controls.iter().flat_map(|(name, found)| found.iter().filter(|r| outside(r)).map(move |r| format!("{name} at {r:?}"))).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_profile_row_stays_on_one_line_in_a_wide_stroke_panel() {
|
||||
let (_, controls) = floated("stroke", "en", 360.0, &["Profile", "Flip Along", "Flip Across"]);
|
||||
// The field, its caption, the list and the two buttons share one line, so their middles are level.
|
||||
let middles: Vec<f32> = controls.iter().flat_map(|(_, found)| found.iter().map(|r| r.center().y)).collect();
|
||||
assert!(middles.windows(2).all(|m| (m[0] - m[1]).abs() < 1.0), "{controls:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_profile_row_wraps_in_a_narrow_stroke_panel() {
|
||||
let past = past_a_narrow_panel("stroke", "en", &["Profile", "Flip Along", "Flip Across"]);
|
||||
assert!(past.is_empty(), "past the panel: {past:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_attributes_rows_wrap_in_a_narrow_panel() {
|
||||
let past = past_a_narrow_panel("attributes", "en", &["Fill Rule", "Image Map", "Browser", "URL"]);
|
||||
assert!(past.is_empty(), "past the panel: {past:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_variables_footer_wraps_in_a_narrow_panel() {
|
||||
let past = past_a_narrow_panel("variables", "en", &["Delete Variable", "Lock Variables"]);
|
||||
assert!(past.is_empty(), "past the panel: {past:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_align_row_wraps_in_a_narrow_properties_panel() {
|
||||
let past = past_a_narrow_panel("properties", "en", &["Vertical Align Bottom", "More Align options"]);
|
||||
assert!(past.is_empty(), "past the panel: {past:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_document_info_rows_wrap_in_a_narrow_panel_in_german() {
|
||||
let past = past_a_narrow_panel("docInfo", "de", &["Flattener Preset"]);
|
||||
assert!(past.is_empty(), "past the panel: {past:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_magic_wand_rows_wrap_in_a_narrow_panel_in_french() {
|
||||
let past = past_a_narrow_panel("magicWand", "fr", &["Tolerance:"]);
|
||||
assert!(past.is_empty(), "past the panel: {past:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_color_wheel_box_and_its_strip_stay_inside_the_panel() {
|
||||
let mut app = app_with_rect();
|
||||
|
||||
@@ -558,7 +558,7 @@ fn footer(ui: &mut Ui, states: &RowStates) -> Option<&'static str> {
|
||||
FooterBar::body().show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
for row in FOOTER {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Row::new().wrap(true).show(ui, |ui, _| {
|
||||
for &(icon, id) in row {
|
||||
let name = title(id, states.locked);
|
||||
let button = IconButton::new(IconId::new(icon)).label(name).tooltip(name).enabled(states.enabled(id));
|
||||
|
||||
Reference in new issue
Block a user