update
This commit is contained in:
parent
1f5697326c
commit
c054f1e0b3
9 changed files with 699 additions and 5 deletions
|
|
@ -38,8 +38,10 @@ import :FontAtlas;
|
|||
// function body into your code and modify it. There is no override hook.
|
||||
|
||||
export namespace Crafter {
|
||||
// Aggregate for the two item buffers + the optional text-shaping deps.
|
||||
// Build one per frame in onBuild and pass it to component calls.
|
||||
// Aggregate for the standard item buffers + the optional text-shaping
|
||||
// deps. Build one per frame in onBuild and pass it to component calls.
|
||||
// Any pointer left null causes the corresponding component to be a no-op
|
||||
// (so a frame that doesn't draw images can leave `images` unset).
|
||||
struct UIBuffer {
|
||||
QuadItem* quads = nullptr;
|
||||
std::uint32_t* quadCount = nullptr;
|
||||
|
|
@ -49,6 +51,10 @@ export namespace Crafter {
|
|||
std::uint32_t* glyphCount = nullptr;
|
||||
std::uint32_t glyphCap = 0;
|
||||
|
||||
ImageItem* images = nullptr;
|
||||
std::uint32_t* imageCount = nullptr;
|
||||
std::uint32_t imageCap = 0;
|
||||
|
||||
FontAtlas* atlas = nullptr; // for text-emitting components
|
||||
UIRenderer* renderer = nullptr; // for ShapeText
|
||||
};
|
||||
|
|
@ -92,6 +98,9 @@ export namespace Crafter {
|
|||
float cornerRadius = 0;
|
||||
};
|
||||
|
||||
// Where the X coordinate sits relative to the emitted glyph run.
|
||||
enum class TextAlign : std::uint8_t { Left, Center, Right };
|
||||
|
||||
// ─── component functions ───────────────────────────────────────────
|
||||
|
||||
// Background quad (color depends on state) + centered label glyphs.
|
||||
|
|
@ -112,4 +121,22 @@ export namespace Crafter {
|
|||
// Background quad + a filled quad clipped to t01 of the inner width.
|
||||
void DrawProgressBar(UIBuffer& buf, Rect r, float t01,
|
||||
const ProgressColors& c);
|
||||
|
||||
// Single-line text emit. `(x, baselineY)` is the start position; horizontal
|
||||
// alignment shifts the run after shaping. Returns the advance width that
|
||||
// was written. No line-wrap, no kerning — same shaping rules as
|
||||
// UIRenderer::ShapeText (which this calls).
|
||||
float DrawText(UIBuffer& buf, std::string_view text,
|
||||
float x, float baselineY,
|
||||
Font& font, float fontSize,
|
||||
std::array<float, 4> color,
|
||||
TextAlign align = TextAlign::Left);
|
||||
|
||||
// Sampled image quad. The texture and sampler must already have heap
|
||||
// slots (UIRenderer::RegisterImage / RegisterSampler). `uv` is
|
||||
// {u0, v0, u1, v1} into the source texture; defaults to the full image.
|
||||
void DrawImage(UIBuffer& buf, Rect r,
|
||||
std::uint32_t textureSlot, std::uint32_t samplerSlot,
|
||||
std::array<float, 4> tint = {1, 1, 1, 1},
|
||||
std::array<float, 4> uv = {0, 0, 1, 1});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue