mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 04:27:49 +00:00
A face painted faded reports no sub-node: a tab fading out has no access node
This commit is contained in:
@@ -210,28 +210,30 @@ impl PaintUi<'_> {
|
||||
/// colour through `StyleCx::host_ink` and its muted colour through `StyleCx::host_muted_ink`. It registers no id, senses nothing, opens no memory stage and
|
||||
/// fires nothing.
|
||||
pub fn face<C: Show>(&mut self, part: impl Into<PartRef>, face: C) {
|
||||
self.face_with(part.into(), face, self.text);
|
||||
self.face_with(part.into(), face, self.text, true);
|
||||
}
|
||||
|
||||
/// `face`, for a face on a fill the composite draws for that part alone (a plate over a picture): the face reads
|
||||
/// `ink` through `StyleCx::host_ink` instead of the composite's text colour.
|
||||
pub fn face_in<C: Show>(&mut self, part: impl Into<PartRef>, face: C, ink: &Stateful<StyleColor>) {
|
||||
self.face_with(part.into(), face, Some(ink));
|
||||
self.face_with(part.into(), face, Some(ink), true);
|
||||
}
|
||||
|
||||
/// [`face`](Self::face) painted `share` as opaque as it would be (1 paints as `face` does, 0 paints nothing): a
|
||||
/// component fading in or out as the one component that draws it. A share outside 0 to 1 is clamped and a
|
||||
/// non-finite one leaves the opacity as it was; fades stack with the opacity already in force.
|
||||
/// non-finite one leaves the opacity as it was; fades stack with the opacity already in force. A faded face is a
|
||||
/// look only: it reports no sub-node, so a component fading out has no node while it fades.
|
||||
pub fn face_faded<C: Show>(&mut self, part: impl Into<PartRef>, face: C, share: f32) {
|
||||
let kept = self.ui.opacity();
|
||||
if share.is_finite() {
|
||||
self.ui.set_opacity(kept * share.clamp(0.0, 1.0));
|
||||
}
|
||||
self.face_with(part.into(), face, self.text);
|
||||
self.face_with(part.into(), face, self.text, false);
|
||||
self.ui.set_opacity(kept);
|
||||
}
|
||||
|
||||
fn face_with<C: Show>(&mut self, part: PartRef, face: C, ink: Option<&Stateful<StyleColor>>) {
|
||||
/// Paints `face` for `part`; a `reported` face gives the part's sub-node its facts (`steps::report_parts`).
|
||||
fn face_with<C: Show>(&mut self, part: PartRef, face: C, ink: Option<&Stateful<StyleColor>>, reported: bool) {
|
||||
let Some(result) = self.results.get(&(part.key, part.index)) else {
|
||||
debug_assert!(false, "face for a part `parts` did not declare");
|
||||
return;
|
||||
@@ -253,7 +255,9 @@ impl PaintUi<'_> {
|
||||
if let Some(baseline) = record.baseline {
|
||||
own.baseline.get_or_insert(baseline);
|
||||
}
|
||||
own.faces.push(record);
|
||||
if reported {
|
||||
own.faces.push(record);
|
||||
}
|
||||
}
|
||||
|
||||
/// Reserves an empty shape at the end of the component's layer, clipped to `clip`, for shapes added later by code
|
||||
|
||||
@@ -37,11 +37,12 @@ impl Component for Chip {
|
||||
}
|
||||
}
|
||||
|
||||
/// One part painted with a `Chip` face; its own `access` declares no node for the part.
|
||||
/// One part painted with a `Chip` face, faded to `fade` when set; its own `access` declares no node for the part.
|
||||
#[derive(craft_ui::contract::Component)]
|
||||
struct Palette {
|
||||
#[common]
|
||||
common: Common,
|
||||
fade: Option<f32>,
|
||||
}
|
||||
|
||||
impl Component for Palette {
|
||||
@@ -62,7 +63,11 @@ impl Component for Palette {
|
||||
}
|
||||
|
||||
fn paint(&mut self, ui: &mut PaintUi<'_>, _: &Cx<'_, Self>) {
|
||||
ui.face(SWATCH, Chip { common: Common::new() }.label("Swatch"));
|
||||
let chip = Chip { common: Common::new() }.label("Swatch");
|
||||
match self.fade {
|
||||
Some(share) => ui.face_faded(SWATCH, chip, share),
|
||||
None => ui.face(SWATCH, chip),
|
||||
}
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> egui::Response {
|
||||
@@ -77,9 +82,23 @@ fn a_face_in_a_composite_reports_its_value_and_colour() {
|
||||
let root = Rc::new(Cell::new(Id::NULL));
|
||||
let shown = Rc::clone(&root);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
shown.set(Palette { common: Common::new() }.label("Palette").show(ui).id);
|
||||
shown.set(Palette { common: Common::new(), fade: None }.label("Palette").show(ui).id);
|
||||
});
|
||||
fixture.settle();
|
||||
let part = fixture.part(root.get(), SWATCH).unwrap_or_else(|| panic!("the face's part has a sub-node"));
|
||||
assert_eq!(fixture.tree().value_of(part.node), Some("Coral"), "the part's sub-node carries the value the face's access set");
|
||||
}
|
||||
|
||||
/// A face painted faded (a component fading out where it stood) is a look only: its part gets no sub-node and its
|
||||
/// name reaches no node. Guards `PaintUi::face_faded` reporting the face as `face` does.
|
||||
#[trial]
|
||||
fn a_faded_face_reports_no_sub_node() {
|
||||
let root = Rc::new(Cell::new(Id::NULL));
|
||||
let shown = Rc::clone(&root);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
shown.set(Palette { common: Common::new(), fade: Some(0.5) }.label("Palette").show(ui).id);
|
||||
});
|
||||
fixture.settle();
|
||||
assert!(fixture.part(root.get(), SWATCH).is_none(), "a faded face gives its part no sub-node");
|
||||
assert!(fixture.by_label("Swatch").is_none(), "no node carries the faded face's name");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user