Merge pull request #4589 from storytold/bb-epic-color-replacement-mx3tl41i

epic-color-replacement: craft-libs half
This commit is contained in:
David Mann authored and GitHub committed 2026-12-01 09:58:52 +01:00
commit 475f6feb71
2 files changed
+51 -5

No files matched your search

+6 -5
View File
@@ -373,8 +373,9 @@ pub struct BrushPresetPicker<'a, K: Value + Eq + Hash + MemoProps> {
/// Whether the picker takes input: off disables its field, its head and its popover. It is enabled by default.
#[prop]
enabled: bool,
/// App rows drawn under the head.
#[prop(name = "rows", boxed = "FnOnce(&mut Ui) + 'a")]
/// App rows drawn under the head. The head may draw them more than once in a pass (its measuring run, then the
/// visible one), so the callback keeps its captured values for each call.
#[prop(name = "rows", boxed = "FnMut(&mut Ui) + 'a")]
app_rows: Option<AppRows<'a>>,
/// Paints the brush's current tip on the chip, as the app's engine draws it (its falloff, angle and roundness, a
/// sampled tip's shape); without it the chip shows the picked preset's tip.
@@ -386,8 +387,8 @@ pub struct BrushPresetPicker<'a, K: Value + Eq + Hash + MemoProps> {
recent_source: Option<&'a PresetSource<'a, K>>,
}
/// The app's own rows of the picker's gear menu.
type AppRows<'a> = Box<dyn FnOnce(&mut Ui) + 'a>;
/// The app's rows under the picker's head.
type AppRows<'a> = Box<dyn FnMut(&mut Ui) + 'a>;
impl<'a, K: Value + Eq + Hash + MemoProps> BrushPresetPicker<'a, K> {
/// A picker named `label` over the presets of `source` (build each row with [`brush_row`](super::brush_row)),
@@ -474,7 +475,7 @@ impl<'a, K: Value + Eq + Hash + MemoProps> BrushPresetPicker<'a, K> {
for edits in sent {
(diameter, hardness, tip, out_of_range) = (edits.diameter, edits.hardness, edits.tip, edits.out_of_range);
}
if let Some(rows) = app_rows.take() {
if let Some(rows) = app_rows.as_mut() {
rows(ui);
}
};
+45
View File
@@ -461,3 +461,48 @@ fn show_recent_brushes_hides_the_row() {
assert!(!host.borrow().state.recent_row, "the box turned the row off");
assert!(fixture.by_label("Recent brushes").is_none(), "the row is gone");
}
/// App rows belong to the visible compact head, not only to its measuring run: they show and their controls edit the
/// app's values.
#[trial]
fn compact_app_rows_replay_measurement_and_commit_visible_values() {
use craft_ui::contract::Show as _;
use craft_ui::form::SliderField;
let host = Rc::new(RefCell::new((None::<u32>, BrushPickerState::new(), 25.0_f64)));
let calls = Rc::new(RefCell::new(Vec::<Vec<bool>>::new()));
let (held, seen) = (Rc::clone(&host), Rc::clone(&calls));
let mut fixture = Fixture::new(move |ui| {
let mut host = held.borrow_mut();
let (current, state, tolerance) = &mut *host;
let trace = Rc::new(RefCell::new(Vec::new()));
let record = Rc::clone(&trace);
// A captured owned label stays usable without consuming the callback's environment.
let label = String::from("Tolerance");
let rows = PresetSource::new((), PresetFns::new(|_, _| Vec::<PresetRow<u32>>::new()));
let _ = BrushPresetPicker::new("Compact brush", Bind::bound(current), &rows, Bind::bound(state), OPENED)
.compact(true)
.rows(move |ui| {
record.borrow_mut().push(ui.is_sizing_pass());
let _ = SliderField::new(label.clone(), Bind::bound(tolerance), 0.0..=100.0).step(1.0).show(ui);
})
.show(ui);
seen.borrow_mut().push(trace.borrow().clone());
});
fixture.room(Vec2::new(640.0, 760.0));
fixture.settle();
let field = fixture.by_role(Role::COMBO_BOX).first().copied().expect("the compact field shows");
fixture.click(&field);
fixture.settle();
assert!(fixture.by_label("Size").is_some(), "the built-in head is visible");
assert!(calls.borrow().iter().any(|trace| trace.contains(&true)), "the head was measured: {:?}", calls.borrow());
assert!(fixture.by_label("Tolerance").is_some(), "the app row survives the head's measuring run: {:?}", calls.borrow());
let slider = fixture
.by_role(Role::SLIDER)
.into_iter()
.find(|target| fixture.tree().name_of(target.node) == Some("Tolerance"))
.expect("the app row's slider is accessible");
fixture.click_at(slider.rect.left_center() + Vec2::new(slider.rect.width() * 0.8, 0.0));
fixture.settle();
assert!(host.borrow().2 > 50.0, "the visible control commits to the app's value: {}", host.borrow().2);
}