protected override bool RenderSubtree() { if (!base.RenderSubtree()) { return(false); } var context = Node.FindNearestContext <IDrawableRenderContext>().Value; if (context == null) { return(false); } // create drawable var drawable = (Drawable = UseRef <T>()).Current; bool drawableCreated; if (drawable == null) { drawable = Drawable.Current = CreateDrawable(); drawableCreated = true; } else { drawableCreated = false; } drawable.Name = Key.ToString(); // add styling and events ApplyStyles(drawable); ApplyEvents(drawable); // render drawable var explicitDepth = UseRef(drawableCreated && drawable.Depth != 0).Current; context.Render(drawable, explicitDepth); // invoke ref callback if (drawableCreated) { Ref?.Invoke(drawable); } // schedule expiry on unmount UseEffect(() => () => { drawable.Expire(); Ref?.Invoke(null); }, null); return(true); }
/// <summary> /// Creates a new <see cref="ofTransform"/>. /// </summary> public ofTransform(ElementKey key = default, IEnumerable <ofElement> children = default, RefDelegate <ofTransform> @ref = default) : base(key, children, new Context()) { @ref?.Invoke(this); }