mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 18:25:34 +01:00
Merge pull request #10101 from dotCooCoo/fix/doc-info-image-trace-shared-layout
Panels: Document Info rows and Image Trace Create use the shared row and check box layouts
This commit is contained in:
3 files changed
+21
-17
No files matched your search
@@ -35,14 +35,9 @@ pub struct DocInfoView {
|
||||
/// the second or third click of a double or triple click.
|
||||
pub(crate) fn row(ui: &mut Ui, label: &str, value: &str) -> bool {
|
||||
let mut clicked = false;
|
||||
// A row whose label and value fit on one line keeps the value at its end. A wrapping row places its children as
|
||||
// `Start` does, so the row wraps only when the two do not fit, as in a narrow panel or a longer translation.
|
||||
let width = |text: &str| {
|
||||
let font = egui::TextStyle::Body.resolve(ui.style());
|
||||
ui.painter().layout_no_wrap(text.to_string(), font, egui::Color32::WHITE).size().x
|
||||
};
|
||||
let fits = width(label) + width(value) + 2.0 * ui.spacing().item_spacing.x <= ui.available_width();
|
||||
Row::new().fill_width().align(RowAlign::SpaceBetween).wrap(!fits).show(ui, |ui, _| {
|
||||
// A row whose label and value fit on one line keeps the value at its end; otherwise the value wraps under the
|
||||
// label, as in a narrow panel or a longer translation.
|
||||
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, and a click copies all of it (#8432). A drag selects
|
||||
// and a Shift-click extends the selection, so neither copies. A value wider than the panel
|
||||
|
||||
@@ -10,7 +10,7 @@ use craft::color_ui::ui::{ColorPopover, PickedColor};
|
||||
use craft::theme::Srgba;
|
||||
use craft::ui::buttons::ToggleButton;
|
||||
use craft::ui::choice::{Checkbox, Segmented};
|
||||
use craft::ui::contract::{Bind, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::form::{Field, FieldGroup, SliderField, SliderFieldLayout};
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::pickers::Select;
|
||||
@@ -271,14 +271,7 @@ pub(crate) fn advanced_rows(ui: &mut Ui, params: &mut Value, _data: &RowsData, _
|
||||
Row::new().show(ui, |ui, _| {
|
||||
let mut hit = None;
|
||||
for (key, on, other, label) in [("fills", fills, strokes, tl!("Fills")), ("strokes", strokes, fills, tl!("Strokes"))] {
|
||||
// Inside the Create field a check box's own label is not drawn, so each box takes a field of
|
||||
// its own with the label after it.
|
||||
let enabled = !on || other;
|
||||
let mut value = on;
|
||||
Field::new(label).layout(FieldLayout::After).enabled(enabled).show(ui, |ui, _| {
|
||||
Checkbox::new(Bind::bound(&mut value)).enabled(enabled).show(ui);
|
||||
});
|
||||
if value != on {
|
||||
if check(ui, label, on, !on || other) {
|
||||
hit = Some(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,22 @@ fn a_long_document_info_value_wraps_inside_a_narrow_panel() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_document_info_value_that_does_not_fit_beside_its_label_moves_under_it() {
|
||||
let name = "A document name long enough to run past a narrow panel";
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()));
|
||||
run(&mut app, "file.new", json!({"width": 200, "height": 200, "name": name}));
|
||||
let mut panel = Panel::new(app, doc_info::show);
|
||||
panel.room(egui::vec2(160.0, ROOM.y));
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
let label = one(&panel, "Name");
|
||||
let value = run_starting(&panel, "A document");
|
||||
assert!(value.top() >= label.bottom() - 0.5, "the value {value:?} stands beside its label {label:?}, not under it");
|
||||
// A row that wraps starts each line at the start edge.
|
||||
assert!((value.left() - label.left()).abs() < 1.0, "the value {value:?} does not start under its label {label:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn info_paints_stand_a_section_apart_from_the_numbers() {
|
||||
let mut app = app_with_rect();
|
||||
|
||||
Reference in new issue
Block a user