Function zng_wgt::node::with_context_blend

source ·
pub fn with_context_blend(
    ctx: LocalContext,
    over: bool,
    child: impl UiNode,
) -> impl UiNode
Expand description

Helper for declaring widgets that are recontextualized to take in some of the context of an original parent.

See LocalContext::with_context_blend for more details about over. The returned node will delegate all node operations to inside the blend. The UiNode::with_context will delegate to the child widget context, but the ctx is not blended for this method, only for UiNodeOp methods.

§Warning

Properties, context vars and context locals are implemented with the assumption that all consumers have released the context on return, that is even if the context was shared with worker threads all work was block-waited. This node breaks this assumption, specially with over: true you may cause unexpected behavior if you don’t consider carefully what context is being captured and what context is being replaced.

As a general rule, only capture during init or update in NestGroup::CHILD, only wrap full widgets and only place the wrapped widget in a parent’s NestGroup::CHILD for a parent that has no special expectations about the child.

As an example of things that can go wrong, if you capture during layout, the LAYOUT context is captured and replaces over the actual layout context during all subsequent layouts in the actual parent.

§Panics

Panics during init if ctx is not from the same app as the init context.