56 setInteractive(
false);
63 if (tex.id == t.id && tex.width == t.width && tex.height == t.height)
76 sourceRect_->x == r.x && sourceRect_->y == r.y &&
77 sourceRect_->width == r.width && sourceRect_->height == r.height)
93 const std::optional<Rect> &
getSourceRect() const noexcept {
return sourceRect_; }
126 if (src.width <= 0.0f || src.height <= 0.0f || dst.width <= 0.0f || dst.height <= 0.0f)
132 effective = (src.width <= dst.width && src.height <= dst.height)
144 const float scale = std::min(dst.width / src.width, dst.height / src.height);
145 const float w = src.width * scale;
146 const float h = src.height * scale;
148 dst.x + (dst.width - w) * 0.5f,
149 dst.y + (dst.height - h) * 0.5f,
152 return {src, outDst};
157 const float scale = std::max(dst.width / src.width, dst.height / src.height);
158 const float visW = dst.width / scale;
159 const float visH = dst.height / scale;
161 src.x + (src.width - visW) * 0.5f,
162 src.y + (src.height - visH) * 0.5f,
165 return {outSrc, dst};
170 const float drawW = std::min(src.width, dst.width);
171 const float drawH = std::min(src.height, dst.height);
173 src.x + (src.width - drawW) * 0.5f,
174 src.y + (src.height - drawH) * 0.5f,
178 dst.x + (dst.width - drawW) * 0.5f,
179 dst.y + (dst.height - drawH) * 0.5f,
182 return {outSrc, outDst};
195 auto *r = ctx ? ctx->renderer :
nullptr;
196 if (!r || !tex.valid() || rect.width <= 0.0f || rect.height <= 0.0f)
199 const Rect baseSrc = (sourceRect_ && sourceRect_->width > 0.0f && sourceRect_->height > 0.0f)
201 :
Rect{0.0f, 0.0f,
static_cast<float>(tex.width),
static_cast<float>(tex.height)};
204 r->drawTexture(tex, drawSrc, drawDst, style.tint.withAlpha(op));
209 std::optional<Rect> sourceRect_;
Centralized standard library includes used throughout ZenitUI.
The node class: tree structure, layout pass, style resolution, input dispatch, render orchestration,...
void invalidateLayerCache()
Mark any cached off-screen filter layer on this node and its ancestors as dirty so it is re-baked on ...
Definition Layout.hpp:979
void setStyleTag(const std::string &t)
Set the node's style tag.
UIContext * context() const
Return the UIContext this node is attached to, or nullptr if unmounted.
Definition Layout.hpp:899
CRTP base for components that want fluent builders and a static create() factory.
Definition Layout.hpp:1397
TLayout(Args &&...args)
Definition Layout.hpp:1401
A single-texture node supporting sub-rect cropping (sourceRect) and ObjectFit.
Definition ImageContainer.hpp:47
const std::optional< Rect > & getSourceRect() const noexcept
Current source sub-rectangle, or nullopt if using the full texture.
Definition ImageContainer.hpp:93
ImageContainer(TextureHandle tex={})
Construct with a texture.
Definition ImageContainer.hpp:53
void clearSourceRect()
Reset to drawing the full texture.
Definition ImageContainer.hpp:84
void setSourceRect(Rect r)
Set an explicit source sub-rectangle in texture pixels (for sprite sheets / cropping).
Definition ImageContainer.hpp:73
TextureHandle getTexture() const noexcept
Current texture handle.
Definition ImageContainer.hpp:70
static bool parseObjectFit(std::string_view s, ObjectFit &out) noexcept
Parse a fit keyword ("fill", "contain", "cover", "none", "scale-down").
Definition ImageContainer.hpp:108
void setObjectFit(ObjectFit fit)
Set how the texture fits inside the node rect (default: ObjectFit::Fill).
Definition ImageContainer.hpp:96
static std::pair< Rect, Rect > computeFitRects(Rect src, Rect dst, ObjectFit fit) noexcept
Compute the final (srcRect, dstRect) pair for src drawn into dst.
Definition ImageContainer.hpp:124
void setTexture(TextureHandle t)
Replace the texture.
Definition ImageContainer.hpp:61
void renderContent(float op, const ComputedStyle &style) override
Draw the node's content (text, images, custom geometry).
Definition ImageContainer.hpp:192
ObjectFit getObjectFit() const noexcept
Current fit mode.
Definition ImageContainer.hpp:105
LayoutType
Positioning strategy applied to a Layout node's direct children.
Definition UIEnums.hpp:29
@ Stack
Children overlap each other; Z-order controls paint order.
Definition UIEnums.hpp:30
Dense style: every property has a concrete value.
Definition Style.hpp:1036
Axis-aligned rectangle in screen coordinates.
Definition CoreTypes.hpp:46
Opaque handle to a GPU/software texture owned by the asset provider.
Definition CoreTypes.hpp:127