ui_sketch.dhover×731all
/**
A compile-only sketch of the `sparkles:ui` authoring API agreed in UI-Q1–Q6.

Nothing here lays out or paints. The builder records nodes, text and messages
in the frame's tables so the demo can show *what the API means*: which order
things are built in, which `env` a deferred composite sees, and how a message
finds its way to `update`. Every name is a proposal.

The tables are `sparkles:base` building blocks, each picked by what its spec
says it is for; `struct Ui` says why each one fits.
*/
module 
(module) ui_sketch

A compile-only sketch of the sparkles:ui authoring API agreed in UI-Q1–Q6.

Nothing here lays out or paints. The builder records nodes, text and messages in the frame's tables so the demo can show what the API means: which order things are built in, which env a deferred composite sees, and how a message finds its way to update. Every name is a proposal.

The tables are sparkles:base building blocks, each picked by what its spec says it is for; struct Ui says why each one fits.

ui_sketch
;
import
(package) core
core
.
(module) core.interpolation

This module provides definitions to support D's interpolated expression sequence literal, sometimes called string interpolation.

string str;
int num;
// the compiler uses this module to implement the
// i"..." literal used here.
auto a = i"$​(str) has $​(num) items.";

The variable a is a sequence of expressions:

a[0] == InterpolationHeader()
a[$-1] == InterpolationFooter()

First and last, you see the header and footer, to clearly indicate where interpolation begins and ends. Note that there may be nested interpolated sequences too, each with their own header and footer. Think of them as a set of balanced parenthesis around the contents.

Inside, you will find three general categories of content: InterpolatedLiteral!"string" for string expressions, InterpolatedExpression!"code" for code expressions, and then the values themselves as their own type.

In the example:

auto a = i"$​(str) has $​(num) items.";

We will find:

a[0] == InterpolationHeader()
a[1] == InterpolatedExpression!"str"
a[2] == str
a[3] == InterpolatedLiteral!" has ";
a[4] == InterpolatedExpression!"num";
a[5] == num
a[6] == InterpolatedLiteral!" items.";
a[7] == InterpolationFooter()
a.length == 8;

You can see the correspondence with the original input: when you write $​(expression), the string of the expression is passed as InterpolatedExpression!ThatString, (excluding any parenthesis around the expression), and everything else is passed as InterpolatedLiteral!str, in the same sequence as they appeared in the source.

After an InterpolatedExpression!..., you will find the actual value(s) in the tuple. (If the expression expanded to multiple values - for example, if it was itself a tuple, there will be multiple values for a single expression.)

Library functions should NOT attempt to mixin the code from an InterpolatedExpression themselves. Doing so will fail, since it is coming from a different scope anyway. The string is provided to you only for informational purposes and as a sentinel to separate things the user wrote.

Your code should be able to handle an empty code string in InterpolatedExpression or even an entirely missing InterpolatedExpression, in case an implementation decides to not emit these.

The toString members on these return null, except for the InterpolatedLiteral, which returns the literal string. This is to ease processing by generic functions like std.stdio.write or std.conv.text, making them effectively transparently skipped.

To extract the string from an InterpolatedLiteral, you can use an is expression or the .toString method.

To extract the string from a InterpolatedExpression, you can use an is expression or the .expression member.

None of these structures have runtime state.

@historyAdded in dmd 2.10x frontend, released in late 2023.
interpolation
:
(struct) core.interpolation.InterpolationFooter

ditto

InterpolationFooter
,
(struct) core.interpolation.InterpolationHeader

Sentinel values to indicate the beginning and end of an interpolated expression sequence.

Note that these can nest, so while processing a sequence, it may be helpful to keep a nesting count if that knowledge is important to your application.

InterpolationHeader
;
import
(package) core
core
.
(module) core.lifetime
lifetime
:
(alias template) ui_sketch.emplace = core.lifetime.emplace(T)(T* chunk)

Given a pointer chunk to uninitialized memory (but already typed as T), constructs an object of non-class type T at that address. If T is a class, initializes the class reference to null.

@returnsA pointer to the newly constructed object (which is the same as chunk).
emplace
;
import
(package) std
std
.
(package) std.algorithm
algorithm
.
(module) std.algorithm.searching

This is a submodule of std.algorithm. It contains generic searching algorithms.

Function Name Description
all all!"a > 0"([1, 2, 3, 4]) returns true because all elements are positive
any any!"a > 0"([1, 2, -3, -4]) returns true because at least one element is positive
balancedParens balancedParens("((1 + 1) / 2)", '(', ')') returns true because the string has balanced parentheses.
boyerMooreFinder find("hello world", boyerMooreFinder("or")) returns "orld" using the Boyer-Moore algorithm.
canFind canFind("hello world", "or") returns true.
count Counts all elements or elements matching a predicate, specific element or sub-range.

count([1, 2, 1]) returns 3, count([1, 2, 1], 1) returns 2 and count!"a < 0"([1, -3, 0]) returns 1. | | countUntil | countUntil(a, b) returns the number of steps taken in a to reach b; for example, countUntil("hello!", "o") returns 4. | | commonPrefix | commonPrefix("parakeet", "parachute") returns "para". | | endsWith | endsWith("rocks", "ks") returns true. | | extrema | extrema([2, 1, 3, 5, 4]) returns [1, 5]. | | find | find("hello world", "or") returns "orld" using linear search. (For binary search refer to SortedRange.) | | findAdjacent | findAdjacent([1, 2, 3, 3, 4]) returns the subrange starting with two equal adjacent elements, i.e. [3, 3, 4]. | | findAmong | findAmong("abcd", "qcx") returns "cd" because 'c' is among "qcx". | | findSkip | If a = "abcde", then findSkip(a, "x") returns false and leaves a unchanged, whereas findSkip(a, "c") advances a to "de" and returns true. | | findSplit | findSplit("abcdefg", "de") returns a tuple of three ranges "abc", "de", and "fg". | | findSplitAfter | findSplitAfter("abcdefg", "de") returns a tuple of two ranges "abcde" and "fg". | | findSplitBefore | findSplitBefore("abcdefg", "de") returns a tuple of two ranges "abc" and "defg". | | minCount | minCount([2, 1, 1, 4, 1]) returns tuple(1, 3). | | maxCount | maxCount([2, 4, 1, 4, 1]) returns tuple(4, 2). | | minElement | Selects the minimal element of a range. minElement([3, 4, 1, 2]) returns 1. | | maxElement | Selects the maximal element of a range. maxElement([3, 4, 1, 2]) returns 4. | | minIndex | Index of the minimal element of a range. minIndex([3, 4, 1, 2]) returns 2. | | maxIndex | Index of the maximal element of a range. maxIndex([3, 4, 1, 2]) returns 1. | | minPos | minPos([2, 3, 1, 3, 4, 1]) returns the subrange [1, 3, 4, 1], i.e., positions the range at the first occurrence of its minimal element. | | maxPos | maxPos([2, 3, 1, 3, 4, 1]) returns the subrange [4, 1], i.e., positions the range at the first occurrence of its maximal element. | | skipOver | Assume a = "blah". Then skipOver(a, "bi") leaves a unchanged and returns false, whereas skipOver(a, "bl") advances a to refer to "ah" and returns true. | | startsWith | startsWith("hello, world", "hello") returns true. | | until | Lazily iterates a range until a specific value is found. |

Source

std/algorithm/searching.d

@copyrightAndrei Alexandrescu 2008-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu
searching
:
(alias template) ui_sketch.all = std.algorithm.searching.all(alias pred = "a")

Checks if all of the elements satisfy pred.

all
;
import
(package) std
std
.
(package) std.experimental
experimental
.
(package) std.experimental.allocator
allocator
.
(package) std.experimental.allocator.building_blocks
building_blocks
.
(module) std.experimental.allocator.building_blocks.region

Source

std/experimental/allocator/building_blocks/region.d

region
:
(alias struct) ui_sketch.InSituRegion = std.experimental.allocator.building_blocks.region.InSituRegion(ulong size, ulong minAlign = platformAlignment)

InSituRegion is a convenient region that carries its storage within itself (in the form of a statically-sized array).

The first template argument is the size of the region and the second is the needed alignment. Depending on the alignment requested and platform details, the actual available storage may be smaller than the compile-time parameter. To make sure that at least n bytes are available in the region, use ``InSituRegion!(n + a - 1, a).

Given that the most frequent use of InSituRegion is as a stack allocator, it allocates starting at the end on systems where stack grows downwards, such that hot memory is used first.

InSituRegion
;
import
(package) std
std
.
(module) std.traits

Templates which extract information about types and symbols at compile time.

Category Templates
Symbol Name traits fullyQualifiedName mangledName moduleName packageName
Function traits isFunction arity functionAttributes hasFunctionAttributes functionLinkage FunctionTypeOf isSafe isUnsafe isFinal ParameterDefaults ParameterIdentifierTuple ParameterStorageClassTuple Parameters ReturnType SetFunctionAttributes variadicFunctionStyle
Aggregate Type traits BaseClassesTuple BaseTypeTuple classInstanceAlignment EnumMembers FieldNameTuple Fields hasAliasing hasElaborateAssign hasElaborateCopyConstructor hasElaborateDestructor hasElaborateMove hasIndirections hasMember hasStaticMember hasNested hasUnsharedAliasing InterfacesTuple isInnerClass isNested MemberFunctionsTuple RepresentationTypeTuple TemplateArgsOf TemplateOf TransitiveBaseTypeTuple
Type Conversion CommonType AllImplicitConversionTargets ImplicitConversionTargets CopyTypeQualifiers CopyConstness isAssignable isCovariantWith isImplicitlyConvertible isQualifierConvertible
Type Constructors InoutOf ConstOf SharedOf SharedInoutOf SharedConstOf SharedConstInoutOf ImmutableOf QualifierOf
Categories of types allSameType ifTestable isType isAggregateType isArray isAssociativeArray isAutodecodableString isBasicType isBoolean isBuiltinType isCopyable isDynamicArray isEqualityComparable isFloatingPoint isIntegral isNarrowString isConvertibleToString isNumeric isOrderingComparable isPointer isScalarType isSigned isSIMDVector isSomeChar isSomeString isStaticArray isUnsigned
Type behaviours isAbstractClass isAbstractFunction isCallable isDelegate isExpressions isFinalClass isFinalFunction isFunctionPointer isInstanceOf isIterable isMutable isSomeFunction isTypeTuple
General Types ForeachType KeyType Largest mostNegative OriginalType PointerTarget Signed Unconst Unshared Unqual Unsigned ValueType Promoted
Misc lvalueOf rvalueOf Select select
User-Defined Attributes hasUDA getUDAs getSymbolsByUDA

Source

std/traits.d

@copyrightCopyright The D Language Foundation 2005 - 2009.@licenseBoost License 1.0.@authorsWalter Bright, Tomasz Stachowiak (isExpressions), Andrei Alexandrescu, Shin Fujishiro, Robert Clipsham, David Nadlinger, Kenji Hara, Shoichi Kato
traits
:
(alias template) ui_sketch.Parameters = std.traits.Parameters(alias func) if (isCallable!func)

Get, as a tuple, the types of the parameters to a function, a pointer to function, a delegate, a struct with an opCall, a pointer to a struct with an opCall, or a class with an opCall.

Parameters
,
(alias template) ui_sketch.ReturnType = std.traits.ReturnType(alias func) if (isCallable!func)

Get the type of the return value from a function, a pointer to function, a delegate, a struct with an opCall, a pointer to a struct with an opCall, or a class with an opCall. Please note that ref is not part of a type, but the attribute of the function (see template functionAttributes).

To reduce template instantiations, consider instead using typeof(() { return func(args); } ()) if the argument types are known or static if (is(typeof(func) Ret == return)) if only that basic test is needed.

ReturnType
;
import
(package) sparkles
sparkles
.
(package) sparkles.base
base
.
(module) sparkles.base.buffer

A @nogc container with Small Buffer Optimization (SBO).

Provides an append-only buffer that stores small amounts of data inline (avoiding heap allocation) and automatically switches to heap storage when capacity is exceeded.

Primary use case: appending elements in a temporary scope where GC allocation is not desired.

buffer
:
(alias struct) ui_sketch.BoundedSink = sparkles.base.buffer.BoundedSink(T)

A bounded output range over storage someone else owns.

Handed out by tryWrite and valid only inside it, so a partially written destination is never observable: either the whole write fits, or nothing is kept. Overflow is recorded rather than thrown, which is what lets the entire sparkles.base.text.writers family compose inside one attempt.

BoundedSink
,
(alias template) ui_sketch.HeapBuffer = sparkles.base.buffer.HeapBuffer(T, Storage extra = Storage.none) if (!(extra & ~Storage.unique))

A buffer with no inline array: the elements always live on the heap.

For a sequence whose typical size makes an inline array dead weight — the struct costs one slice regardless of how much it holds. Size it up front with reserve; there is no N to raise.

HeapBuffer
,
(alias template) ui_sketch.InlineBuffer = sparkles.base.buffer.InlineBuffer(T, ulong N, Storage extra = Storage.none) if (!(extra & ~Storage.unique))

A buffer that never allocates: the elements live in the inline T[N] and nowhere else.

The policy with a guarantee no other has. Because there is no union, a slice of the storage is provably a reference to the enclosing frame, so -dip1000 rejects returning one from a @safe function — the property CString is built on. It also has no destructor, so it is plain data: copyable, comparable, and usable as a field in an aggregate that must stay POD.

It is deliberately not an output range: put promises to accept what it is given, and this cannot. Write into it with tryWrite.

Pass Storage.unique as extra for the move-only form, which is what prevents an accidental copy of a large one.

InlineBuffer
,
(enum) sparkles.base.buffer.Storage

What storage a buffer may use, and whether it may be copied.

The bits are capabilities, so the combination is the policy: inline alone never allocates, heap alone carries no inline array, and both together is the small-buffer optimization. ``Storage.none is the empty set — the neutral default for an alias's extra parameter — but a buffer with neither storage bit has nowhere to put anything and fails Buffer's constraint.

Storage
,
(alias template) ui_sketch.UniqueBuffer = sparkles.base.buffer.UniqueBuffer(T, ulong N = max(size_t(1), (T[]).sizeof / T.sizeof))

Small-buffer optimization with a sole owner: inline while the elements fit, heap when they do not, and copying is disabled.

Disabling copies is what removes the reference count from the grow path — there is no second owner to consult. Hand a finished one to the shared world with toShared, which consumes it and transfers any heap block without reallocating.

UniqueBuffer
;
import
(package) sparkles
sparkles
.
(package) sparkles.base
base
.
(package) sparkles.base.pool
pool
.
(module) sparkles.base.pool.text_pool

Variable-length text behind generational ids.

TextPool generalises DqlEngine.intern (sparkles.dql.engine): text is appended to one inline byte arena and addressed by a TextSpan. The difference is that callers never hold the span. They hold an id — a Handle into a pool of spans — so the arena can reset when it empties and compact when it fragments without invalidating anything a caller kept.

The price is that text is read only inside a borrow (withText). While any borrow is open the pool does not move bytes, so the slice a callback receives stays valid for exactly as long as the callback runs.

See docs/specs/base/pool.md §5 (POOL12–POOL18, POOL22).

text_pool
:
(alias struct) ui_sketch.TextPool = sparkles.base.pool.text_pool.TextPool(Tag, ulong slots, ulong bytes, ulong maxText = bytes, Reuse reuse = Reuse.lifo) if (slots > 0 && (bytes > 0) && (bytes < (uint).max) && (maxText > 0) && (maxText <= bytes))

A fixed-capacity store of up to slots texts sharing bytes bytes.

@paramTag distinguishes this pool's ids (Handle!Tag) from other handles@paramslots the most texts live at once@parambytes the arena's size, shared by all live texts@parammaxText the most bytes one text keeps; longer input is cut at a UTF-8 boundary and flagged (POOL12). Arena pressure never truncates (POOL13).@paramreuse which freed id slot is issued next
TextPool
;
import
(package) sparkles
sparkles
.
(package) sparkles.base
base
.
(package) sparkles.base.text
text
.
(module) sparkles.base.text.enums

Enum ↔ text/value conversion.

Format-agnostic primitives for an enum's two serialized forms:

  • enumMemberName — a value's member name, recased per a CaseStyle.

  • enumMemberNameOr — the same, for an enum whose members are not distinctly valued, and for a value that may not be a declared member at all.

  • enumCommonPrefix — the prefix every member name shares, so a C-derived enum can be rendered without it.

  • enumFromValue — a membership-checked underlying value back to the enum.

Enums that come from C are why the last three exist. A .h translated by ImportC routinely declares several members with the same value — an extension enumerator promoted to core keeps its old spelling as an alias — and every member repeats the type's name as a prefix, because C has no enum scope. The final switch in enumMemberName rejects the first outright (duplicate case labels), and nothing here would strip the second.

The module is unopinionated — it applies no per-member name override (that is a policy concern for a layer such as @WireName in sparkles:wired). The inverse name direction is readEnumString (sparkles.base.text.readers); the output-range writers are writeEnumMemberName / writeEnumValue (sparkles.base.text.writers).

enums
:
(alias template) ui_sketch.enumMemberName = sparkles.base.text.enums.enumMemberName(CaseStyle style = CaseStyle.original, E)(in E value) if (is(E == enum))

The name of the declared member equal to value, recased per style as a compile-time string literal (so the call allocates nothing).

value must be a declared member of E. The generated final switch rejects a duplicate-valued enum at compile time (duplicate case labels) and asserts on a value that is not a declared member.

enumMemberName
;
import
(package) sparkles
sparkles
.
(package) sparkles.base
base
.
(package) sparkles.base.text
text
.
(module) sparkles.base.text.writers

@nogc-compatible text writing utilities for output ranges.

Provides functions for writing integers, floats, escaped characters/strings, and ANSI escape sequences to output ranges without GC allocation.

writers
:
(alias template) ui_sketch.writeText = sparkles.base.text.writers.writeText(Writer, Args...)(ref Writer w, InterpolationHeader, Args args, InterpolationFooter)

Writes an interpolated sequence to an output range, verbatim.

SharedBuffer!(char, 128) buf;
buf.writeText(i"pid $(pid) exited with $(status)");

Plain, not styled. Literals are copied through and interpolated values go via writeValue; nothing is parsed. That is the difference from sparkles.base.styled_template.writeStyled, which reads {red …} as markup — and the reason to reach for this one whenever the text is not a style template. Interpolating a value that may contain a brace (a file path, a user's input) through the styled writer silently eats it as a style block; here a brace is a brace.

The @nogc half of the pair. std.conv.text already renders an interpolated sequence to a string, so use that where a GC allocation is fine; this is for the paths where it is not, and it inherits Writer's attributes the way every template in this module does.

writeText
;
// ── forced named arguments (docs/guidelines/idioms/forced-named-arguments) ── private struct
(struct) ui_sketch.NamedOnly
NamedOnly
{}
// ── nodes, text, messages ────────────────────────────────────────────────── /// A handle to a node this frame built (UI-Q2: children are erased handles). struct
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
{ uint
(field) uint ui_sketch.Node.index
index
= uint.
(constant) uint uint.max = 4294967295u
max
;
/// An empty child. It keeps its slot, so the siblings after it keep their /// identity whether or not it is shown (UI-Q2 identity rule 1). enum
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
(constant) ui_sketch.Node ui_sketch.Node.none = Node(4294967294u)

An empty child. It keeps its slot, so the siblings after it keep their identity whether or not it is shown (UI-Q2 identity rule 1).

none
=
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
(uint.
(constant) uint uint.max = 4294967295u
max
- 1);
bool
bool ui_sketch.Node.isNone() const pure nothrow @nogc @safe
isNone
() const @safe pure nothrow @nogc =>
(field) uint ui_sketch.Node.index
index
==
(constant) ui_sketch.Node ui_sketch.Node.none = Node(4294967294u)

An empty child. It keeps its slot, so the siblings after it keep their identity whether or not it is shown (UI-Q2 identity rule 1).

none
.
(field) uint ui_sketch.Node.index
index
;
} enum
(enum) ui_sketch.Slot
Slot
: ubyte {
(enum value) ui_sketch.Slot.code = cast(ubyte)0u
code
,
(enum value) ui_sketch.Slot.heading = 1
heading
,
(enum value) ui_sketch.Slot.dim = 2
dim
}
enum
(enum) ui_sketch.Density
Density
: ubyte {
(enum value) ui_sketch.Density.comfortable = cast(ubyte)0u
comfortable
,
(enum value) ui_sketch.Density.compact = 1
compact
}
enum
(enum) ui_sketch.Layout
Layout
: ubyte {
(enum value) ui_sketch.Layout.wide = cast(ubyte)0u
wide
,
(enum value) ui_sketch.Layout.touch = 1
touch
}
/// Context that changes *what gets built* (UI-Q6). Appearance context /// (`disabled`, `scheme`, …) is an inherited node property instead. struct
(struct) ui_sketch.Env

Context that changes what gets built (UI-Q6). Appearance context (disabled, scheme, …) is an inherited node property instead.

Env
{
(enum) ui_sketch.Layout
Layout
(field) ui_sketch.Layout ui_sketch.Env.layout
layout
;
(enum) ui_sketch.Density
Density
(field) ui_sketch.Density ui_sketch.Env.density
density
;
/// This env with `density` replaced, as an override for a subtree.
(struct) ui_sketch.EnvOverride

An env a node sets for the deferred composites below it.

EnvOverride
ui_sketch.EnvOverride ui_sketch.Env.withDensity(ui_sketch.Density d) const pure nothrow @nogc @safe

This env with density replaced, as an override for a subtree.

withDensity
(
(enum) ui_sketch.Density
Density
(parameter) ui_sketch.Density d
d
) const @safe pure nothrow @nogc
=>
(struct) ui_sketch.EnvOverride

An env a node sets for the deferred composites below it.

EnvOverride
(active: true, env:
(struct) ui_sketch.Env

Context that changes what gets built (UI-Q6). Appearance context (disabled, scheme, …) is an inherited node property instead.

Env
(layout:
(field) ui_sketch.Layout ui_sketch.Env.layout
layout
, density:
(parameter) ui_sketch.Density d
d
));
} /// An env a node sets for the deferred composites below it. struct
(struct) ui_sketch.EnvOverride

An env a node sets for the deferred composites below it.

EnvOverride
{ bool
(field) bool ui_sketch.EnvOverride.active
active
;
(struct) ui_sketch.Env

Context that changes what gets built (UI-Q6). Appearance context (disabled, scheme, …) is an inherited node property instead.

Env
(field) ui_sketch.Env ui_sketch.EnvOverride.env
env
;
} /// The tag that keeps frame-text ids apart from every other `Handle` (POOL2). private struct
(struct) ui_sketch.FrameText

The tag that keeps frame-text ids apart from every other Handle (POOL2).

FrameText
{}
/// The frame's text: at most 512 live texts sharing 4 KiB. private alias
(alias) ui_sketch.FrameTextPool = sparkles.base.pool.text_pool.TextPool!(FrameText, 512LU, 4096LU, 4096LU, Reuse.lifo)

The frame's text: at most 512 live texts sharing 4 KiB.

FrameTextPool
=
(struct) sparkles.base.pool.text_pool.TextPool!(ui_sketch.FrameText, 512LU, 4096LU, 4096LU, Reuse.lifo)

A fixed-capacity store of up to slots texts sharing bytes bytes.

@paramTag distinguishes this pool's ids (Handle!Tag) from other handles@paramslots the most texts live at once@parambytes the arena's size, shared by all live texts@parammaxText the most bytes one text keeps; longer input is cut at a UTF-8 boundary and flagged (POOL12). Arena pressure never truncates (POOL13).@paramreuse which freed id slot is issued next
TextPool
!(
(struct) ui_sketch.FrameText

The tag that keeps frame-text ids apart from every other Handle (POOL2).

FrameText
, 512, 4096);
/// Text interned into the frame: a generational id into its `TextPool`. /// `TextId.init` is no text, and never resolves (POOL1). alias
(alias) ui_sketch.TextId = sparkles.base.pool.handle.Handle!(FrameText)

Text interned into the frame: a generational id into its TextPool. ``TextId.init is no text, and never resolves (POOL1).

TextId
=
(alias) ui_sketch.FrameTextPool = sparkles.base.pool.text_pool.TextPool!(FrameText, 512LU, 4096LU, 4096LU, Reuse.lifo)

The frame's text: at most 512 live texts sharing 4 KiB.

FrameTextPool
.
(alias) sparkles.base.pool.text_pool.TextPool!(ui_sketch.FrameText, 512LU, 4096LU, 4096LU, Reuse.lifo).Id = sparkles.base.pool.handle.Handle!(FrameText)

This pool's id type.

Id
;
/// An erased message (UI-Q4): an index into the frame's message table. struct
(struct) ui_sketch.MsgRef

An erased message (UI-Q4): an index into the frame's message table.

MsgRef
{ uint
(field) uint ui_sketch.MsgRef.index
index
= uint.
(constant) uint uint.max = 4294967295u
max
;
bool
bool ui_sketch.MsgRef.isSet() const pure nothrow @nogc @safe
isSet
() const @safe pure nothrow @nogc =>
(field) uint ui_sketch.MsgRef.index
index
!= uint.
(constant) uint uint.max = 4294967295u
max
;
} private ulong
ulong ui_sketch.fnv(string s) pure nothrow @nogc @safe
fnv
(
(alias) object.string = string
string
(parameter) string s
s
) @safe pure nothrow @nogc
{ ulong
(local variable) ulong h
h
= 0xcbf29ce484222325;
foreach (
(parameter) immutable(char) c
c
;
(parameter) string s
s
)
{
(local variable) ulong h
h
^=
(local variable) immutable(char) c
c
;
(local variable) ulong h
h
*= 0x100000001b3;
} return
(local variable) ulong h
h
;
} /// A type's identity for the message check, computed at compile time. enum ulong
(constant) ulong ui_sketch.typeKey(T) = fnv(T.mangleof)

A type's identity for the message check, computed at compile time.

typeKey
(T) = fnv(T.mangleof);
private enum
(enum) ui_sketch.Kind
Kind
: ubyte
{
(enum value) ui_sketch.Kind.column = cast(ubyte)0u
column
,
(enum value) ui_sketch.Kind.row = 1
row
,
(enum value) ui_sketch.Kind.label = 2
label
,
(enum value) ui_sketch.Kind.toggle = 3
toggle
,
(enum value) ui_sketch.Kind.numberField = 4
numberField
,
(enum value) ui_sketch.Kind.keyValue = 5
keyValue
,
(enum value) ui_sketch.Kind.fragment = 6
fragment
,
(enum value) ui_sketch.Kind.deferred = 7
deferred
,
(enum value) ui_sketch.Kind.mapMsg = 8
mapMsg
} private alias
(alias) ui_sketch.DeferredThunk = ui_sketch.Node function(ref ui_sketch.Ui, scope const(void)[] args) pure nothrow @nogc @safe
DeferredThunk
= Node function(ref
(struct) ui_sketch.Ui

The frame's builder: write-only while building, except env (UI-Q2, UI-Q6).

Each table is the sparkles:base building block its lifetime calls for:

  • Nodes, child lists and messages are appended in build order and die together when the frame does, so they are buffers, not pools. They are HeapBuffer!(T, Storage.unique): an inline array of records would make Ui too large to live on its owner's stack, reserve and clear(releaseStorage: false) keep one block across frames (BUF11, BUF15), and unique matches Ui's own move-only identity, which keeps the refcount off the grow path (BUF7).

  • A message is not a pool handle. A Handle earns its generation when single occupants are removed while ids to them are outstanding (POOL3); a MsgRef is never held apart from the node that carries it, and the whole table is dropped at once. What does outlive a frame is the hit id an event lands on, and that is the node's key (UI-Q2), not a slot in this table.

  • Text is a TextPool (POOL12–POOL18): components keep ids, never offsets, so the arena can reset and compact under them, and a read is a borrow (POOL14) — see textIs and dump.

  • ui.text formats into an InlineBuffer: a hard bound whose overflow is reported, written only through tryWrite (WRT1, WRT3). Its slices live for the frame, which is what the IES form promises.

  • Arguments and constant messages are bump-allocated from an InSituRegion, the allocator guide's per-frame arena whose storage is the struct itself (allocators §5, §11): one pointer bump each, freed all at once by deallocateAll.

Ui
, scope const(void)[]
(parameter) const(void)[] args
args
) @safe pure nothrow @nogc;
private alias
(alias) ui_sketch.ApplyThunk = void function(scope const(void)* from, scope void* to) @system
ApplyThunk
= void function(scope const(void)*
(parameter) const(void)* from
from
, scope void*
(parameter) void* to
to
) @system;
private struct
(struct) ui_sketch.MapRec
MapRec
{ ulong
(field) ulong ui_sketch.MapRec.from
from
,
(field) ulong ui_sketch.MapRec.to
to
;
(alias) ui_sketch.ApplyThunk = void function(scope const(void)* from, scope void* to) @system
ApplyThunk
(field) void function(scope const(void)* from, scope void* to) @system ui_sketch.MapRec.apply
apply
;
} private struct
(struct) ui_sketch.NodeRec
NodeRec
{
(enum) ui_sketch.Kind
Kind
(field) ui_sketch.Kind ui_sketch.NodeRec.kind
kind
;
uint
(field) uint ui_sketch.NodeRec.parent
parent
= uint.
(constant) uint uint.max = 4294967295u
max
;
uint
(field) uint ui_sketch.NodeRec.childStart
childStart
,
(field) uint ui_sketch.NodeRec.childCount
childCount
;
(alias) ui_sketch.TextId = sparkles.base.pool.handle.Handle!(FrameText)

Text interned into the frame: a generational id into its TextPool. ``TextId.init is no text, and never resolves (POOL1).

TextId
(field) sparkles.base.pool.handle.Handle!(FrameText) ui_sketch.NodeRec.text
text
,
(field) sparkles.base.pool.handle.Handle!(FrameText) ui_sketch.NodeRec.text2
text2
;
(struct) ui_sketch.MsgRef

An erased message (UI-Q4): an index into the frame's message table.

MsgRef
(field) ui_sketch.MsgRef ui_sketch.NodeRec.msg
msg
;
(enum) ui_sketch.Slot
Slot
(field) ui_sketch.Slot ui_sketch.NodeRec.slot
slot
;
int
(field) int ui_sketch.NodeRec.gap
gap
,
(field) int ui_sketch.NodeRec.value
value
;
bool
(field) bool ui_sketch.NodeRec.on
on
,
(field) bool ui_sketch.NodeRec.disabled
disabled
;
ulong
(field) ulong ui_sketch.NodeRec.key
key
;
(struct) ui_sketch.EnvOverride

An env a node sets for the deferred composites below it.

EnvOverride
(field) ui_sketch.EnvOverride ui_sketch.NodeRec.env
env
;
(alias) ui_sketch.DeferredThunk = ui_sketch.Node function(ref ui_sketch.Ui, scope const(void)[] args) pure nothrow @nogc @safe
DeferredThunk
(field) ui_sketch.Node function(ref ui_sketch.Ui, scope const(void)[] args) pure nothrow @nogc @safe ui_sketch.NodeRec.thunk
thunk
; // `deferred`: builds the subtree from the stored arguments
const(void)[]
(field) const(void)[] ui_sketch.NodeRec.args
args
; // `deferred`: the composite's bytes in the argument arena
(struct) ui_sketch.MapRec
MapRec
(field) ui_sketch.MapRec ui_sketch.NodeRec.map
map
; // `mapMsg`
(enum) ui_sketch.Density
Density
(field) ui_sketch.Density ui_sketch.NodeRec.builtWith
builtWith
; // `deferred`: the env it was built under (for the demo's dump)
} private struct
(struct) ui_sketch.MsgRec
MsgRec
{ ulong
(field) ulong ui_sketch.MsgRec.typeKey
typeKey
; // the message's type, or the payload lambda's result type
const(void)[]
(field) const(void)[] ui_sketch.MsgRec.value
value
; // its bytes in the argument arena (a constant message)
(alias) ui_sketch.ApplyThunk = void function(scope const(void)* from, scope void* to) @system
ApplyThunk
(field) void function(scope const(void)* from, scope void* to) @system ui_sketch.MsgRec.payload
payload
; // `on!fn`: turns a component's payload into the message
ulong
(field) ulong ui_sketch.MsgRec.payloadKey
payloadKey
;
} /** The frame's builder: write-only while building, except `env` (UI-Q2, UI-Q6). Each table is the `sparkles:base` building block its lifetime calls for: $(UL $(LI Nodes, child lists and messages are appended in build order and die together when the frame does, so they are buffers, not pools. They are `HeapBuffer!(T, Storage.unique)`: an inline array of records would make `Ui` too large to live on its owner's stack, `reserve` and `clear(releaseStorage: false)` keep one block across frames (`BUF11`, `BUF15`), and `unique` matches `Ui`'s own move-only identity, which keeps the refcount off the grow path (`BUF7`).) $(LI A message is not a pool handle. A `Handle` earns its generation when single occupants are removed while ids to them are outstanding (POOL3); a `MsgRef` is never held apart from the node that carries it, and the whole table is dropped at once. What does outlive a frame is the hit id an event lands on, and that is the node's key (UI-Q2), not a slot in this table.) $(LI Text is a `TextPool` (POOL12–POOL18): components keep ids, never offsets, so the arena can reset and compact under them, and a read is a borrow (POOL14) — see `textIs` and `dump`.) $(LI `ui.text` formats into an `InlineBuffer`: a hard bound whose overflow is reported, written only through `tryWrite` (`WRT1`, `WRT3`). Its slices live for the frame, which is what the IES form promises.) $(LI Arguments and constant messages are bump-allocated from an `InSituRegion`, the allocator guide's per-frame arena whose storage is the struct itself (allocators §5, §11): one pointer bump each, freed all at once by `deallocateAll`.) ) */ struct
(struct) ui_sketch.Ui

The frame's builder: write-only while building, except env (UI-Q2, UI-Q6).

Each table is the sparkles:base building block its lifetime calls for:

  • Nodes, child lists and messages are appended in build order and die together when the frame does, so they are buffers, not pools. They are HeapBuffer!(T, Storage.unique): an inline array of records would make Ui too large to live on its owner's stack, reserve and clear(releaseStorage: false) keep one block across frames (BUF11, BUF15), and unique matches Ui's own move-only identity, which keeps the refcount off the grow path (BUF7).

  • A message is not a pool handle. A Handle earns its generation when single occupants are removed while ids to them are outstanding (POOL3); a MsgRef is never held apart from the node that carries it, and the whole table is dropped at once. What does outlive a frame is the hit id an event lands on, and that is the node's key (UI-Q2), not a slot in this table.

  • Text is a TextPool (POOL12–POOL18): components keep ids, never offsets, so the arena can reset and compact under them, and a read is a borrow (POOL14) — see textIs and dump.

  • ui.text formats into an InlineBuffer: a hard bound whose overflow is reported, written only through tryWrite (WRT1, WRT3). Its slices live for the frame, which is what the IES form promises.

  • Arguments and constant messages are bump-allocated from an InSituRegion, the allocator guide's per-frame arena whose storage is the struct itself (allocators §5, §11): one pointer bump each, freed all at once by deallocateAll.

Ui
{ private
(alias) sparkles.base.buffer.HeapBuffer!(ui_sketch.NodeRec, Storage.unique) = sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u)

A buffer with no inline array: the elements always live on the heap.

For a sequence whose typical size makes an inline array dead weight — the struct costs one slice regardless of how much it holds. Size it up front with reserve; there is no N to raise.

HeapBuffer
!(
(struct) ui_sketch.NodeRec
NodeRec
,
(enum) sparkles.base.buffer.Storage

What storage a buffer may use, and whether it may be copied.

The bits are capabilities, so the combination is the policy: inline alone never allocates, heap alone carries no inline array, and both together is the small-buffer optimization. ``Storage.none is the empty set — the neutral default for an alias's extra parameter — but a buffer with neither storage bit has nowhere to put anything and fails Buffer's constraint.

Storage
.
(enum value) sparkles.base.buffer.Storage.unique = cast(ubyte)4u

move-only: copying is disabled, so the grow path is refcount-free

unique
)
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
;
private
(alias) sparkles.base.buffer.HeapBuffer!(ui_sketch.Node, Storage.unique) = sparkles.base.buffer.Buffer!(Node, 0LU, cast(Storage)cast(ubyte)6u)

A buffer with no inline array: the elements always live on the heap.

For a sequence whose typical size makes an inline array dead weight — the struct costs one slice regardless of how much it holds. Size it up front with reserve; there is no N to raise.

HeapBuffer
!(
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
,
(enum) sparkles.base.buffer.Storage

What storage a buffer may use, and whether it may be copied.

The bits are capabilities, so the combination is the policy: inline alone never allocates, heap alone carries no inline array, and both together is the small-buffer optimization. ``Storage.none is the empty set — the neutral default for an alias's extra parameter — but a buffer with neither storage bit has nowhere to put anything and fails Buffer's constraint.

Storage
.
(enum value) sparkles.base.buffer.Storage.unique = cast(ubyte)4u

move-only: copying is disabled, so the grow path is refcount-free

unique
)
(field) sparkles.base.buffer.Buffer!(Node, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.kids
kids
;
private
(alias) sparkles.base.buffer.HeapBuffer!(ui_sketch.MsgRec, Storage.unique) = sparkles.base.buffer.Buffer!(MsgRec, 0LU, cast(Storage)cast(ubyte)6u)

A buffer with no inline array: the elements always live on the heap.

For a sequence whose typical size makes an inline array dead weight — the struct costs one slice regardless of how much it holds. Size it up front with reserve; there is no N to raise.

HeapBuffer
!(
(struct) ui_sketch.MsgRec
MsgRec
,
(enum) sparkles.base.buffer.Storage

What storage a buffer may use, and whether it may be copied.

The bits are capabilities, so the combination is the policy: inline alone never allocates, heap alone carries no inline array, and both together is the small-buffer optimization. ``Storage.none is the empty set — the neutral default for an alias's extra parameter — but a buffer with neither storage bit has nowhere to put anything and fails Buffer's constraint.

Storage
.
(enum value) sparkles.base.buffer.Storage.unique = cast(ubyte)4u

move-only: copying is disabled, so the grow path is refcount-free

unique
)
(field) sparkles.base.buffer.Buffer!(MsgRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.msgs
msgs
;
private
(alias) ui_sketch.FrameTextPool = sparkles.base.pool.text_pool.TextPool!(FrameText, 512LU, 4096LU, 4096LU, Reuse.lifo)

The frame's text: at most 512 live texts sharing 4 KiB.

FrameTextPool
(field) sparkles.base.pool.text_pool.TextPool!(FrameText, 512LU, 4096LU, 4096LU, Reuse.lifo) ui_sketch.Ui.texts
texts
;
private
(alias) sparkles.base.buffer.InlineBuffer!(char, 1024LU, Storage.none) = sparkles.base.buffer.Buffer!(char, 1024LU, Storage.inline)

A buffer that never allocates: the elements live in the inline T[N] and nowhere else.

The policy with a guarantee no other has. Because there is no union, a slice of the storage is provably a reference to the enclosing frame, so -dip1000 rejects returning one from a @safe function — the property CString is built on. It also has no destructor, so it is plain data: copyable, comparable, and usable as a field in an aggregate that must stay POD.

It is deliberately not an output range: put promises to accept what it is given, and this cannot. Write into it with tryWrite.

Pass Storage.unique as extra for the move-only form, which is what prevents an accidental copy of a large one.

InlineBuffer
!(char, 1024)
(field) sparkles.base.buffer.Buffer!(char, 1024LU, Storage.inline) ui_sketch.Ui.scratch
scratch
;
private
(struct) std.experimental.allocator.building_blocks.region.InSituRegion!(4096LU, 16LU)

InSituRegion is a convenient region that carries its storage within itself (in the form of a statically-sized array).

The first template argument is the size of the region and the second is the needed alignment. Depending on the alignment requested and platform details, the actual available storage may be smaller than the compile-time parameter. To make sure that at least n bytes are available in the region, use ``InSituRegion!(n + a - 1, a).

Given that the most frequent use of InSituRegion is as a stack allocator, it allocates starting at the end on systems where stack grows downwards, such that hot memory is used first.

Examples

// 128KB region, allocated to x86's cache line
InSituRegion!(128 * 1024, 16) r1;
auto a1 = r1.allocate(101);
assert(a1.length == 101);

// 128KB region, with fallback to the garbage collector.
import std.experimental.allocator.building_blocks.fallback_allocator
    : FallbackAllocator;
import std.experimental.allocator.building_blocks.free_list
    : FreeList;
import std.experimental.allocator.building_blocks.bitmapped_block
    : BitmappedBlock;
import std.experimental.allocator.gc_allocator : GCAllocator;
FallbackAllocator!(InSituRegion!(128 * 1024), GCAllocator) r2;
const a2 = r2.allocate(102);
assert(a2.length == 102);

// Reap with GC fallback.
InSituRegion!(128 * 1024, 8) tmp3;
FallbackAllocator!(BitmappedBlock!(64, 8), GCAllocator) r3;
r3.primary = BitmappedBlock!(64, 8)(cast(ubyte[]) (tmp3.allocateAll()));
const a3 = r3.allocate(103);
assert(a3.length == 103);

// Reap/GC with a freelist for small objects up to 16 bytes.
InSituRegion!(128 * 1024, 64) tmp4;
FreeList!(FallbackAllocator!(BitmappedBlock!(64, 64), GCAllocator), 0, 16) r4;
r4.parent.primary = BitmappedBlock!(64, 64)(cast(ubyte[]) (tmp4.allocateAll()));
const a4 = r4.allocate(104);
assert(a4.length == 104);
InSituRegion
!4096
(field) std.experimental.allocator.building_blocks.region.InSituRegion!(4096LU, 16LU) ui_sketch.Ui.argArena
argArena
;
private
(struct) ui_sketch.Env

Context that changes what gets built (UI-Q6). Appearance context (disabled, scheme, …) is an inherited node property instead.

Env
(field) ui_sketch.Env ui_sketch.Ui.currentEnv
currentEnv
;
private ulong
(field) ulong ui_sketch.Ui.appMsgKey
appMsgKey
;
@disable this(this); /// Structural context, as resolved from this node's ancestors.
(struct) ui_sketch.Env

Context that changes what gets built (UI-Q6). Appearance context (disabled, scheme, …) is an inherited node property instead.

Env
ui_sketch.Env ui_sketch.Ui.env() const pure nothrow @nogc @safe

Structural context, as resolved from this node's ancestors.

env
() const @safe pure nothrow @nogc =>
(field) ui_sketch.Env ui_sketch.Ui.currentEnv
currentEnv
;
/// The app's message type (`runApp!(view, update, Msg)` in the real host). void
void expectMsg(Msg)()

The app's message type (runApp!(view, update, Msg) in the real host).

expectMsg
(Msg)() { appMsgKey =
(template instance) typeKey!Msg
typeKey
!Msg; }
/** Formats an IES into the frame and returns a slice that lives for the frame (UI-Q2.1: a scratch buffer reset each frame; components intern it). */ const(char)[]
const(char)[] text(Args...)(InterpolationHeader header, Args args, InterpolationFooter footer) return

Formats an IES into the frame and returns a slice that lives for the frame (UI-Q2.1: a scratch buffer reset each frame; components intern it).

text
(Args...)(
(unresolved type) InterpolationHeader
InterpolationHeader
(parameter) InterpolationHeader header
header
, Args
(parameter) Args args
args
,
(unresolved type) InterpolationFooter
InterpolationFooter
(parameter) InterpolationFooter footer
footer
) return
{ const
_error_ start
start
= scratch.
scratch.length
length
;
const
_error_ fits
fits
= scratch.tryWrite((scope ref BoundedSink!char
(parameter) BoundedSink!char w
w
) {
w.
w.writeText
writeText
(header, args, footer);
}); assert(fits, "the frame's text scratch is full"); return scratch[start .. scratch.length]; } // ── the frame ────────────────────────────────────────────────────────── /// Builds `root` and every composite placed below it, top-down. Node
Node frame(C)(C root, Env env)

Builds root and every composite placed below it, top-down.

frame
(C)(C
(parameter) C root
root
,
(unresolved type) Env
Env
(parameter) Env env
env
)
{ const
_error_ r
r
= this.
this.place
place
(root);
expand(r.
r.index
index
, env);
return r; } /** Checks every message against the type expected where it sits: the app's `Msg` at the root, changed by each `mapMsg` on the way down. `on` cannot check this itself, because a subtree is built before the `mapMsg` that wraps it, so only a walk from the root knows what a message is expected to be. */ bool
bool ui_sketch.Ui.messagesTypeCheck(ui_sketch.Node root) const pure nothrow @nogc @safe

Checks every message against the type expected where it sits: the app's Msg at the root, changed by each mapMsg on the way down. on cannot check this itself, because a subtree is built before the mapMsg that wraps it, so only a walk from the root knows what a message is expected to be.

messagesTypeCheck
(
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
(parameter) ui_sketch.Node root
root
) const @safe pure nothrow @nogc
=>
bool ui_sketch.Ui.checkUnder(uint n, ulong expected) const pure nothrow @nogc @safe
checkUnder
(
(parameter) ui_sketch.Node root
root
.
(field) uint ui_sketch.Node.index
index
,
(field) ulong ui_sketch.Ui.appMsgKey
appMsgKey
);
/** Delivers the message `target` sends, as the app's `Msg`: decoded from the table (with `payload` for `on!fn` messages), then mapped by every `mapMsg` between `target` and the root. The real host does this against the last frame's table, when an event lands on `target`'s hit id. */ void
void dispatch(Msg)(Node target, scope void delegate(Msg) @safe deliver, int payload = 0)

Delivers the message target sends, as the app's Msg: decoded from the table (with payload for on!fn messages), then mapped by every mapMsg between target and the root. The real host does this against the last frame's table, when an event lands on target's hit id.

dispatch
(Msg)(
(unresolved type) Node
Node
(parameter) Node target
target
, scope void delegate(Msg) @safe
(parameter) void delegate(Msg) @safe deliver
deliver
, int
(parameter) int payload
payload
= 0)
{ align(16) ubyte[256]
_error_ a
a
,
_error_ b
b
;
const
_error_ m
m
= msgs[nodes[target.
target.index
index
].
nodes[target.index].msg
msg
.
nodes[target.index].msg.index
index
];
ulong
_error_ key
key
= m.
m.typeKey
typeKey
;
if (m.
m.payload
payload
!is null)
{ assert(m.
m.payloadKey
payloadKey
==
(template instance) typeKey!int
typeKey
!int, "the payload is not an `int`");
(() @trusted => m.
m.payload
payload
(&payload, &a[0]))();
} else a[0 .. m.value.length] = cast(const(ubyte)[]) m.
m.value
value
;
for (uint
_error_ n
n
= nodes[target.
target.index
index
].
nodes[target.index].parent
parent
; n != uint.max; n = nodes[n].parent)
if (nodes[n].
nodes[n].kind
kind
== Kind.
Kind.mapMsg
mapMsg
)
{ assert(nodes[n].
nodes[n].map
map
.
nodes[n].map.from
from
== key, "a message reached a mapMsg of another type");
(() @trusted => nodes[n].
nodes[n].map
map
.
nodes[n].map.apply
apply
(&a[0], &b[0]))();
a = b; key = nodes[n].
nodes[n].map
map
.
nodes[n].map.to
to
;
} assert(key ==
(template instance) typeKey!Msg
typeKey
!Msg, "the message is not the app's Msg");
deliver((() @trusted => *cast(Msg*) &a[0])()); } /// The first node of `kind` whose text is `text` (the demo's stand-in for /// hit testing), searching from `from` on. Not `const` only because /// reading text opens a borrow (`TextPool.withText` is not `const`).
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
ui_sketch.Node ui_sketch.Ui.find(string kind, scope const(char)[] text, uint from = 0u) pure nothrow @nogc @safe

The first node of kind whose text is text (the demo's stand-in for hit testing), searching from from on. Not const only because reading text opens a borrow (TextPool.withText is not const).

find
(
(alias) object.string = string
string
(parameter) string kind
kind
, scope const(char)[]
(parameter) const(char)[] text
text
, uint
(parameter) uint from
from
= 0) @safe pure nothrow @nogc
{ foreach (
(local variable) uint i
i
;
(parameter) uint from
from
.. cast(uint)
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
.
ulong sparkles.base.buffer.Buffer!(ui_sketch.NodeRec, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safe

Returns the number of elements in the buffer.

length
)
if (
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(local variable) uint i
i
].
(field) ui_sketch.Kind ui_sketch.NodeRec.kind
kind
.
string sparkles.base.text.enums.enumMemberName!(CaseStyle.original, ui_sketch.Kind)(in ui_sketch.Kind value) pure nothrow @nogc @safe

The name of the declared member equal to value, recased per style as a compile-time string literal (so the call allocates nothing).

value must be a declared member of E. The generated final switch rejects a duplicate-valued enum at compile time (duplicate case labels) and asserts on a value that is not a declared member.

enumMemberName
==
(parameter) string kind
kind
&&
bool ui_sketch.Ui.textIs(ui_sketch.Node n, scope const(char)[] text) pure nothrow @nogc @safe

Whether n holds text, compared inside a borrow: the pool lends its bytes only to a callback (POOL14). A node with no text holds "".

textIs
(
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
(
(local variable) uint i
i
),
(parameter) const(char)[] text
text
))
return
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
(
(local variable) uint i
i
);
return
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
.
(constant) ui_sketch.Node ui_sketch.Node.init = Node(4294967295u)
init
;
} /// Writes the tree, indented, with each deferred node's build env. void
void dump(W)(Node n, scope W write, uint depth = 0)

Writes the tree, indented, with each deferred node's build env.

dump
(W)(
(unresolved type) Node
Node
(parameter) Node n
n
, scope W
(parameter) W write
write
, uint
(parameter) uint depth
depth
= 0)
{ if (n.
n.isNone
isNone
)
return write(depth, "none"); const
_error_ r
r
= nodes[n.
n.index
index
];
UniqueBuffer!(char, 128)
_error_ line
line
;
line.
line.writeText
writeText
(i"$(r.kind.enumMemberName)");
texts.
texts.withText
withText
(r.
r.text
text
, (scope const(char)[]
(parameter) const(char)[] text
text
) {
line.
line.writeText
writeText
(i` "$(text)"`);
}); if (r.
r.kind
kind
== Kind.
Kind.deferred
deferred
)
line.
line.writeText
writeText
(i" (built under density $(r.builtWith.enumMemberName))");
if (r.
r.disabled
disabled
)
line.
line.writeText
writeText
(i" disabled");
if (r.
r.env
env
.
r.env.active
active
)
line.
line.writeText
writeText
(i" env:$(r.env.env.density.enumMemberName)");
if (r.
r.msg
msg
.
r.msg.isSet
isSet
)
line.
line.writeText
writeText
(i" [msg]");
if (r.
r.key
key
)
line.
line.writeText
writeText
(i" key");
write(depth, line[].idup); foreach (
(parameter) c
c
; childrenOf(r))
dump(c, write, depth + 1); } // ── building, for the primitives and combinators in this module ──────── /// `s` interned into the frame's text pool, or `TextId.init` for no text. private
(alias) ui_sketch.TextId = sparkles.base.pool.handle.Handle!(FrameText)

Text interned into the frame: a generational id into its TextPool. ``TextId.init is no text, and never resolves (POOL1).

TextId
sparkles.base.pool.handle.Handle!(FrameText) ui_sketch.Ui.intern(scope const(char)[] s) pure nothrow @nogc @safe

s interned into the frame's text pool, or TextId.init for no text.

intern
(scope const(char)[]
(parameter) const(char)[] s
s
) @safe pure nothrow @nogc
=>
(parameter) const(char)[] s
s
.
(field) ulong const(char)[].length
length
?
(field) sparkles.base.pool.text_pool.TextPool!(FrameText, 512LU, 4096LU, 4096LU, Reuse.lifo) ui_sketch.Ui.texts
texts
.
sparkles.base.expected.Expected!(Handle!(FrameText), PoolError, NoGcHook) sparkles.base.pool.text_pool.TextPool!(ui_sketch.FrameText, 512LU, 4096LU, 4096LU, Reuse.lifo).intern(scope const(char)[] text) pure nothrow @nogc @safe

Stores text and returns its id (POOL12, POOL13, POOL16).

At most maxText bytes are kept, cut so the kept prefix never ends inside a multi-byte sequence, and the id records that it was truncated. When the arena cannot hold the text, the pool compacts if that frees enough room and nothing is borrowed; otherwise it returns PoolError.full and changes nothing. text may alias the arena itself (re-interning a borrowed slice): the pool then does not compact during this call.

intern
(
(parameter) const(char)[] s
s
).
inout(sparkles.base.pool.handle.Handle!(FrameText)) sparkles.base.expected.Expected!(sparkles.base.pool.handle.Handle!(FrameText), sparkles.base.pool.handle.PoolError, sparkles.base.text.errors.NoGcHook).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
:
(struct) sparkles.base.pool.handle.Handle!(FrameText)
TextId
.
(constant) sparkles.base.pool.handle.Handle!(FrameText) sparkles.base.pool.handle.Handle!(FrameText).init = Handle(0u, 0u)
init
;
/** Copies `value`'s bytes into the frame's argument arena, where they live until the frame ends. The copy is the one operation `@safe` cannot check: the bytes escape `value`'s scope (see `place` for why that is sound). Phobos' `InSituRegion.allocate` also infers `@system` (its lazy `BorrowedRegion` constructor reads `store.ptr`), so it sits inside the same block. */ private const(void)[]
const(void)[] keep(T)(ref scope const T value)

Copies value's bytes into the frame's argument arena, where they live until the frame ends. The copy is the one operation @safe cannot check: the bytes escape value's scope (see place for why that is sound). Phobos' InSituRegion.allocate also infers @system (its lazy BorrowedRegion constructor reads store.ptr), so it sits inside the same block.

keep
(T)(scope ref const T
(parameter) T value
value
)
{ const
_error_ block
block
= () @trusted {
auto
_error_ b
b
= argArena.allocate(T.sizeof);
if (b !is null) b[] = (cast(const(void)*) &value)[0 .. T.sizeof]; return b; }(); assert(block !is null, "the frame's argument arena is full"); return block; } private
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
ui_sketch.Node ui_sketch.Ui.add(ui_sketch.NodeRec rec, scope const(ui_sketch.Node)[] children) pure nothrow @nogc @safe
add
(
(struct) ui_sketch.NodeRec
NodeRec
(parameter) ui_sketch.NodeRec rec
rec
, scope const(
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
)[]
(parameter) const(ui_sketch.Node)[] children
children
) @safe pure nothrow @nogc
{ const
(local variable) const(ui_sketch.Node) self
self
=
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
(cast(uint)
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
.
ulong sparkles.base.buffer.Buffer!(ui_sketch.NodeRec, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safe

Returns the number of elements in the buffer.

length
);
(parameter) ui_sketch.NodeRec rec
rec
.
(field) uint ui_sketch.NodeRec.childStart
childStart
= cast(uint)
(field) sparkles.base.buffer.Buffer!(Node, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.kids
kids
.
ulong sparkles.base.buffer.Buffer!(ui_sketch.Node, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safe

Returns the number of elements in the buffer.

length
;
(parameter) ui_sketch.NodeRec rec
rec
.
(field) uint ui_sketch.NodeRec.childCount
childCount
= cast(uint)
(parameter) const(ui_sketch.Node)[] children
children
.
(field) ulong const(ui_sketch.Node)[].length
length
;
(field) sparkles.base.buffer.Buffer!(Node, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.kids
kids
~=
void sparkles.base.buffer.Buffer!(ui_sketch.Node, 0LU, cast(Storage)cast(ubyte)6u).opOpAssign!"~"(scope const(ui_sketch.Node)[] elements) pure nothrow @nogc scope @safe

Appends elements from a slice using ~= operator.

Output range interface: appends a single element.

children
;
foreach (
(parameter) const(ui_sketch.Node) c
c
;
(parameter) const(ui_sketch.Node)[] children
children
)
if (!
(local variable) const(ui_sketch.Node) c
c
.
bool ui_sketch.Node.isNone() const pure nothrow @nogc @safe
isNone
)
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(local variable) const(ui_sketch.Node) c
c
.
(field) uint ui_sketch.Node.index
index
].
(field) uint ui_sketch.NodeRec.parent
parent
=
(local variable) const(ui_sketch.Node) self
self
.
(field) uint ui_sketch.Node.index
index
;
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
~=
void sparkles.base.buffer.Buffer!(ui_sketch.NodeRec, 0LU, cast(Storage)cast(ubyte)6u).opOpAssign!"~"(ui_sketch.NodeRec element) pure nothrow @nogc scope @safe

Appends a single element using ~= operator.

Output range interface: appends a single element.

rec
;
return
(local variable) const(ui_sketch.Node) self
self
;
} private
(struct) ui_sketch.MsgRef

An erased message (UI-Q4): an index into the frame's message table.

MsgRef
ui_sketch.MsgRef ui_sketch.Ui.addMsg(ui_sketch.MsgRec rec) pure nothrow @nogc @safe
addMsg
(
(struct) ui_sketch.MsgRec
MsgRec
(parameter) ui_sketch.MsgRec rec
rec
) @safe pure nothrow @nogc
{ const
(local variable) const(ui_sketch.MsgRef) self
self
=
(struct) ui_sketch.MsgRef

An erased message (UI-Q4): an index into the frame's message table.

MsgRef
(cast(uint)
(field) sparkles.base.buffer.Buffer!(MsgRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.msgs
msgs
.
ulong sparkles.base.buffer.Buffer!(ui_sketch.MsgRec, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safe

Returns the number of elements in the buffer.

length
);
(field) sparkles.base.buffer.Buffer!(MsgRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.msgs
msgs
~=
void sparkles.base.buffer.Buffer!(ui_sketch.MsgRec, 0LU, cast(Storage)cast(ubyte)6u).opOpAssign!"~"(ui_sketch.MsgRec element) pure nothrow @nogc scope @safe

Appends a single element using ~= operator.

Output range interface: appends a single element.

rec
;
return
(local variable) const(ui_sketch.MsgRef) self
self
;
} /// Records the key a `mapKeyed` row is identified by (UI-Q2). private void
void ui_sketch.Ui.setKey(ui_sketch.Node n, ulong key) pure nothrow @nogc @safe

Records the key a mapKeyed row is identified by (UI-Q2).

setKey
(
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
(parameter) ui_sketch.Node n
n
, ulong
(parameter) ulong key
key
) @safe pure nothrow @nogc {
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(parameter) ui_sketch.Node n
n
.
(field) uint ui_sketch.Node.index
index
].
(field) ulong ui_sketch.NodeRec.key
key
=
(parameter) ulong key
key
; }
// ── walking ──────────────────────────────────────────────────────────── /// `rec`'s children. Only for walks that build nothing: a build appends /// to `kids`, which may move the block under this slice. private const(
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
)[]
const(ui_sketch.Node)[] ui_sketch.Ui.childrenOf(in ui_sketch.NodeRec rec) const pure nothrow @nogc return @safe

rec's children. Only for walks that build nothing: a build appends to kids, which may move the block under this slice.

childrenOf
(in
(struct) ui_sketch.NodeRec
NodeRec
(parameter) const(ui_sketch.NodeRec) rec
rec
) const return @safe pure nothrow @nogc
=>
(field) sparkles.base.buffer.Buffer!(Node, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.kids
kids
[
(parameter) const(ui_sketch.NodeRec) rec
rec
.
(field) uint ui_sketch.NodeRec.childStart
childStart
..
(parameter) const(ui_sketch.NodeRec) rec
rec
.
(field) uint ui_sketch.NodeRec.childStart
childStart
+
(parameter) const(ui_sketch.NodeRec) rec
rec
.
(field) uint ui_sketch.NodeRec.childCount
childCount
];
/// Whether `n` holds `text`, compared inside a borrow: the pool lends its /// bytes only to a callback (POOL14). A node with no text holds "". private bool
bool ui_sketch.Ui.textIs(ui_sketch.Node n, scope const(char)[] text) pure nothrow @nogc @safe

Whether n holds text, compared inside a borrow: the pool lends its bytes only to a callback (POOL14). A node with no text holds "".

textIs
(
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
(parameter) ui_sketch.Node n
n
, scope const(char)[]
(parameter) const(char)[] text
text
) @safe pure nothrow @nogc
{ bool
(local variable) bool same
same
=
(parameter) const(char)[] text
text
.
(field) ulong const(char)[].length
length
== 0;
(field) sparkles.base.pool.text_pool.TextPool!(FrameText, 512LU, 4096LU, 4096LU, Reuse.lifo) ui_sketch.Ui.texts
texts
.
sparkles.base.expected.Expected!(Handle!(FrameText), PoolError, NoGcHook) sparkles.base.pool.text_pool.TextPool!(ui_sketch.FrameText, 512LU, 4096LU, 4096LU, Reuse.lifo).withText!(void delegate(scope const(char)[]) pure nothrow @nogc @safe)(in sparkles.base.pool.handle.Handle!(FrameText) id, scope void delegate(scope const(char)[]) pure nothrow @nogc @safe fn) pure nothrow @nogc @safe

Calls fn`(text, truncated)` — or fn(text) — with the text id names, or returns why it cannot (POOL14). The slice is valid until fn returns and may not escape it: no byte moves while it runs, even if fn interns or releases other texts.

withText
(
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(parameter) ui_sketch.Node n
n
.
(field) uint ui_sketch.Node.index
index
].
(field) sparkles.base.pool.handle.Handle!(FrameText) ui_sketch.NodeRec.text
text
, (scope const(char)[]
(parameter) const(char)[] held
held
) {
(local variable) bool same
same
=
(parameter) const(char)[] held
held
==
(parameter) const(char)[] text
text
;
}); return
(local variable) bool same
same
;
} private void
void ui_sketch.Ui.expand(uint n, ui_sketch.Env env) pure nothrow @nogc @safe
expand
(uint
(parameter) uint n
n
,
(struct) ui_sketch.Env

Context that changes what gets built (UI-Q6). Appearance context (disabled, scheme, …) is an inherited node property instead.

Env
(parameter) ui_sketch.Env env
env
) @safe pure nothrow @nogc
{ if (
(parameter) uint n
n
>=
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
.
(constant) ui_sketch.Node ui_sketch.Node.none = Node(4294967294u)

An empty child. It keeps its slot, so the siblings after it keep their identity whether or not it is shown (UI-Q2 identity rule 1).

none
.
(field) uint ui_sketch.Node.index
index
)
return; if (
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(parameter) uint n
n
].
(field) ui_sketch.EnvOverride ui_sketch.NodeRec.env
env
.
(field) bool ui_sketch.EnvOverride.active
active
)
(parameter) ui_sketch.Env env
env
=
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(parameter) uint n
n
].
(field) ui_sketch.EnvOverride ui_sketch.NodeRec.env
env
.
(field) ui_sketch.Env ui_sketch.EnvOverride.env
env
;
if (
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(parameter) uint n
n
].
(field) ui_sketch.Kind ui_sketch.NodeRec.kind
kind
==
(enum) ui_sketch.Kind
Kind
.
(enum value) ui_sketch.Kind.deferred = 7
deferred
&&
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(parameter) uint n
n
].
(field) uint ui_sketch.NodeRec.childCount
childCount
== 0)
{
(field) ui_sketch.Env ui_sketch.Ui.currentEnv
currentEnv
=
(parameter) ui_sketch.Env env
env
;
const
(local variable) const(ui_sketch.Node) built
built
=
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(parameter) uint n
n
].
(field) ui_sketch.Node function(ref ui_sketch.Ui, scope const(void)[] args) pure nothrow @nogc @safe ui_sketch.NodeRec.thunk
thunk
(this,
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(parameter) uint n
n
].
(field) const(void)[] ui_sketch.NodeRec.args
args
);
ref
(local variable) ui_sketch.NodeRec rec
rec
=
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(parameter) uint n
n
]; // taken after the thunk, which may move the table
(local variable) ui_sketch.NodeRec rec
rec
.
(field) ui_sketch.Density ui_sketch.NodeRec.builtWith
builtWith
=
(parameter) ui_sketch.Env env
env
.
(field) ui_sketch.Density ui_sketch.Env.density
density
;
(local variable) ui_sketch.NodeRec rec
rec
.
(field) uint ui_sketch.NodeRec.childStart
childStart
= cast(uint)
(field) sparkles.base.buffer.Buffer!(Node, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.kids
kids
.
ulong sparkles.base.buffer.Buffer!(ui_sketch.Node, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safe

Returns the number of elements in the buffer.

length
;
(local variable) ui_sketch.NodeRec rec
rec
.
(field) uint ui_sketch.NodeRec.childCount
childCount
= 1;
(field) sparkles.base.buffer.Buffer!(Node, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.kids
kids
~=
void sparkles.base.buffer.Buffer!(ui_sketch.Node, 0LU, cast(Storage)cast(ubyte)6u).opOpAssign!"~"(ui_sketch.Node element) pure nothrow @nogc scope @safe

Appends a single element using ~= operator.

Output range interface: appends a single element.

built
;
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(local variable) const(ui_sketch.Node) built
built
.
(field) uint ui_sketch.Node.index
index
].
(field) uint ui_sketch.NodeRec.parent
parent
=
(parameter) uint n
n
;
} // By index, not `childrenOf`: a thunk below appends to `kids`. foreach (
(local variable) uint i
i
; 0 ..
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(parameter) uint n
n
].
(field) uint ui_sketch.NodeRec.childCount
childCount
)
void ui_sketch.Ui.expand(uint n, ui_sketch.Env env) pure nothrow @nogc @safe
expand
(
(field) sparkles.base.buffer.Buffer!(Node, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.kids
kids
[
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(parameter) uint n
n
].
(field) uint ui_sketch.NodeRec.childStart
childStart
+
(local variable) uint i
i
].
(field) uint ui_sketch.Node.index
index
,
(parameter) ui_sketch.Env env
env
);
} private bool
bool ui_sketch.Ui.checkUnder(uint n, ulong expected) const pure nothrow @nogc @safe
checkUnder
(uint
(parameter) uint n
n
, ulong
(parameter) ulong expected
expected
) const @safe pure nothrow @nogc
{ if (
(parameter) uint n
n
>=
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
.
(constant) ui_sketch.Node ui_sketch.Node.none = Node(4294967294u)

An empty child. It keeps its slot, so the siblings after it keep their identity whether or not it is shown (UI-Q2 identity rule 1).

none
.
(field) uint ui_sketch.Node.index
index
)
return true; ref
(local variable) const(ui_sketch.NodeRec) rec
rec
=
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.nodes
nodes
[
(parameter) uint n
n
];
if (
(local variable) const(ui_sketch.NodeRec) rec
rec
.
(field) ui_sketch.Kind ui_sketch.NodeRec.kind
kind
==
(enum) ui_sketch.Kind
Kind
.
(enum value) ui_sketch.Kind.mapMsg = 8
mapMsg
)
{ if (
(local variable) const(ui_sketch.NodeRec) rec
rec
.
(field) ui_sketch.MapRec ui_sketch.NodeRec.map
map
.
(field) ulong ui_sketch.MapRec.to
to
!=
(parameter) ulong expected
expected
)
return false;
(parameter) ulong expected
expected
=
(local variable) const(ui_sketch.NodeRec) rec
rec
.
(field) ui_sketch.MapRec ui_sketch.NodeRec.map
map
.
(field) ulong ui_sketch.MapRec.from
from
;
} if (
(local variable) const(ui_sketch.NodeRec) rec
rec
.
(field) ui_sketch.MsgRef ui_sketch.NodeRec.msg
msg
.
bool ui_sketch.MsgRef.isSet() const pure nothrow @nogc @safe
isSet
&&
(field) sparkles.base.buffer.Buffer!(MsgRec, 0LU, cast(Storage)cast(ubyte)6u) ui_sketch.Ui.msgs
msgs
[
(local variable) const(ui_sketch.NodeRec) rec
rec
.
(field) ui_sketch.MsgRef ui_sketch.NodeRec.msg
msg
.
(field) uint ui_sketch.MsgRef.index
index
].
(field) ulong ui_sketch.MsgRec.typeKey
typeKey
!=
(parameter) ulong expected
expected
)
return false; return
const(ui_sketch.Node)[] ui_sketch.Ui.childrenOf(in ui_sketch.NodeRec rec) const pure nothrow @nogc return @safe

rec's children. Only for walks that build nothing: a build appends to kids, which may move the block under this slice.

childrenOf
(
(local variable) const(ui_sketch.NodeRec) rec
rec
).
bool ui_sketch.Ui.checkUnder.all!(const(ui_sketch.Node)[])(const(ui_sketch.Node)[] range) pure nothrow @nogc @safe

Checks if all of the elements satisfy pred.

Returns true if and only if the input range range is empty or all values found in range satisfy the predicate pred. Performs (at most) O(range.length) evaluations of pred.

Examples

assert( all!"a & 1"([1, 3, 5, 7, 9]));
assert(!all!"a & 1"([1, 2, 3, 5, 7, 9]));

all can also be used without a predicate, if its items can be evaluated to true or false in a conditional statement. This can be a convenient way to quickly evaluate that all of the elements of a range are true.

int[3] vals = [5, 3, 18];
assert( all(vals[]));
all
!(c => checkUnder(c.index, expected));
} } // ── primitives: eager, every attribute named (UI-Q2) ─────────────────────── /// A vertical stack. `disabled` is inherited by its subtree at layout time; /// `env` reaches only the deferred composites placed below it (UI-Q6).
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
ui_sketch.Node ui_sketch.Column(ref ui_sketch.Ui ui, ui_sketch.NamedOnly _ = NamedOnly(), int gap = 0, bool disabled = false, ui_sketch.EnvOverride env = EnvOverride(false, Env(Layout.wide, Density.comfortable)), scope const(ui_sketch.Node)[] children = null) pure nothrow @nogc @safe

A vertical stack. disabled is inherited by its subtree at layout time; env reaches only the deferred composites placed below it (UI-Q6).

Column
(ref
(struct) ui_sketch.Ui

The frame's builder: write-only while building, except env (UI-Q2, UI-Q6).

Each table is the sparkles:base building block its lifetime calls for:

  • Nodes, child lists and messages are appended in build order and die together when the frame does, so they are buffers, not pools. They are HeapBuffer!(T, Storage.unique): an inline array of records would make Ui too large to live on its owner's stack, reserve and clear(releaseStorage: false) keep one block across frames (BUF11, BUF15), and unique matches Ui's own move-only identity, which keeps the refcount off the grow path (BUF7).

  • A message is not a pool handle. A Handle earns its generation when single occupants are removed while ids to them are outstanding (POOL3); a MsgRef is never held apart from the node that carries it, and the whole table is dropped at once. What does outlive a frame is the hit id an event lands on, and that is the node's key (UI-Q2), not a slot in this table.

  • Text is a TextPool (POOL12–POOL18): components keep ids, never offsets, so the arena can reset and compact under them, and a read is a borrow (POOL14) — see textIs and dump.

  • ui.text formats into an InlineBuffer: a hard bound whose overflow is reported, written only through tryWrite (WRT1, WRT3). Its slices live for the frame, which is what the IES form promises.

  • Arguments and constant messages are bump-allocated from an InSituRegion, the allocator guide's per-frame arena whose storage is the struct itself (allocators §5, §11): one pointer bump each, freed all at once by deallocateAll.

Ui
(parameter) ui_sketch.Ui ui
ui
,
(struct) ui_sketch.NamedOnly
NamedOnly
(parameter) ui_sketch.NamedOnly _
_
=
(struct) ui_sketch.NamedOnly
NamedOnly
.
(constant) ui_sketch.NamedOnly ui_sketch.NamedOnly.init = NamedOnly()
init
, int
(parameter) int gap
gap
= 0, bool
(parameter) bool disabled
disabled
= false,
(struct) ui_sketch.EnvOverride

An env a node sets for the deferred composites below it.

EnvOverride
(parameter) ui_sketch.EnvOverride env
env
=
(struct) ui_sketch.EnvOverride

An env a node sets for the deferred composites below it.

EnvOverride
.
(constant) ui_sketch.EnvOverride ui_sketch.EnvOverride.init = EnvOverride(false, Env(Layout.wide, Density.comfortable))
init
, scope const(
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
)[]
(parameter) const(ui_sketch.Node)[] children
children
= null)
@safe pure nothrow @nogc =>
(parameter) ui_sketch.Ui ui
ui
.
ui_sketch.Node ui_sketch.Ui.add(ui_sketch.NodeRec rec, scope const(ui_sketch.Node)[] children) pure nothrow @nogc @safe
add
(
(struct) ui_sketch.NodeRec
NodeRec
(kind:
(enum) ui_sketch.Kind
Kind
.
(enum value) ui_sketch.Kind.column = cast(ubyte)0u
column
, gap:
(parameter) int gap
gap
, disabled:
(parameter) bool disabled
disabled
, env:
(parameter) ui_sketch.EnvOverride env
env
),
(parameter) const(ui_sketch.Node)[] children
children
);
/// A horizontal stack.
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
ui_sketch.Node ui_sketch.Row(ref ui_sketch.Ui ui, ui_sketch.NamedOnly _ = NamedOnly(), int gap = 0, scope const(ui_sketch.Node)[] children = null) pure nothrow @nogc @safe

A horizontal stack.

Row
(ref
(struct) ui_sketch.Ui

The frame's builder: write-only while building, except env (UI-Q2, UI-Q6).

Each table is the sparkles:base building block its lifetime calls for:

  • Nodes, child lists and messages are appended in build order and die together when the frame does, so they are buffers, not pools. They are HeapBuffer!(T, Storage.unique): an inline array of records would make Ui too large to live on its owner's stack, reserve and clear(releaseStorage: false) keep one block across frames (BUF11, BUF15), and unique matches Ui's own move-only identity, which keeps the refcount off the grow path (BUF7).

  • A message is not a pool handle. A Handle earns its generation when single occupants are removed while ids to them are outstanding (POOL3); a MsgRef is never held apart from the node that carries it, and the whole table is dropped at once. What does outlive a frame is the hit id an event lands on, and that is the node's key (UI-Q2), not a slot in this table.

  • Text is a TextPool (POOL12–POOL18): components keep ids, never offsets, so the arena can reset and compact under them, and a read is a borrow (POOL14) — see textIs and dump.

  • ui.text formats into an InlineBuffer: a hard bound whose overflow is reported, written only through tryWrite (WRT1, WRT3). Its slices live for the frame, which is what the IES form promises.

  • Arguments and constant messages are bump-allocated from an InSituRegion, the allocator guide's per-frame arena whose storage is the struct itself (allocators §5, §11): one pointer bump each, freed all at once by deallocateAll.

Ui
(parameter) ui_sketch.Ui ui
ui
,
(struct) ui_sketch.NamedOnly
NamedOnly
(parameter) ui_sketch.NamedOnly _
_
=
(struct) ui_sketch.NamedOnly
NamedOnly
.
(constant) ui_sketch.NamedOnly ui_sketch.NamedOnly.init = NamedOnly()
init
, int
(parameter) int gap
gap
= 0,
scope const(
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
)[]
(parameter) const(ui_sketch.Node)[] children
children
= null) @safe pure nothrow @nogc
=>
(parameter) ui_sketch.Ui ui
ui
.
ui_sketch.Node ui_sketch.Ui.add(ui_sketch.NodeRec rec, scope const(ui_sketch.Node)[] children) pure nothrow @nogc @safe
add
(
(struct) ui_sketch.NodeRec
NodeRec
(kind:
(enum) ui_sketch.Kind
Kind
.
(enum value) ui_sketch.Kind.row = 1
row
, gap:
(parameter) int gap
gap
),
(parameter) const(ui_sketch.Node)[] children
children
);
/// One run of text.
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
ui_sketch.Node ui_sketch.Label(ref ui_sketch.Ui ui, ui_sketch.NamedOnly _ = NamedOnly(), ui_sketch.Slot slot = Slot.code, scope const(char)[] text = null) pure nothrow @nogc @safe

One run of text.

Label
(ref
(struct) ui_sketch.Ui

The frame's builder: write-only while building, except env (UI-Q2, UI-Q6).

Each table is the sparkles:base building block its lifetime calls for:

  • Nodes, child lists and messages are appended in build order and die together when the frame does, so they are buffers, not pools. They are HeapBuffer!(T, Storage.unique): an inline array of records would make Ui too large to live on its owner's stack, reserve and clear(releaseStorage: false) keep one block across frames (BUF11, BUF15), and unique matches Ui's own move-only identity, which keeps the refcount off the grow path (BUF7).

  • A message is not a pool handle. A Handle earns its generation when single occupants are removed while ids to them are outstanding (POOL3); a MsgRef is never held apart from the node that carries it, and the whole table is dropped at once. What does outlive a frame is the hit id an event lands on, and that is the node's key (UI-Q2), not a slot in this table.

  • Text is a TextPool (POOL12–POOL18): components keep ids, never offsets, so the arena can reset and compact under them, and a read is a borrow (POOL14) — see textIs and dump.

  • ui.text formats into an InlineBuffer: a hard bound whose overflow is reported, written only through tryWrite (WRT1, WRT3). Its slices live for the frame, which is what the IES form promises.

  • Arguments and constant messages are bump-allocated from an InSituRegion, the allocator guide's per-frame arena whose storage is the struct itself (allocators §5, §11): one pointer bump each, freed all at once by deallocateAll.

Ui
(parameter) ui_sketch.Ui ui
ui
,
(struct) ui_sketch.NamedOnly
NamedOnly
(parameter) ui_sketch.NamedOnly _
_
=
(struct) ui_sketch.NamedOnly
NamedOnly
.
(constant) ui_sketch.NamedOnly ui_sketch.NamedOnly.init = NamedOnly()
init
,
(enum) ui_sketch.Slot
Slot
(parameter) ui_sketch.Slot slot
slot
=
(enum) ui_sketch.Slot
Slot
.
(enum value) ui_sketch.Slot.code = cast(ubyte)0u
code
,
scope const(char)[]
(parameter) const(char)[] text
text
= null) @safe pure nothrow @nogc
=>
(parameter) ui_sketch.Ui ui
ui
.
ui_sketch.Node ui_sketch.Ui.add(ui_sketch.NodeRec rec, scope const(ui_sketch.Node)[] children) pure nothrow @nogc @safe
add
(
(struct) ui_sketch.NodeRec
NodeRec
(kind:
(enum) ui_sketch.Kind
Kind
.
(enum value) ui_sketch.Kind.label = 2
label
, slot:
(parameter) ui_sketch.Slot slot
slot
, text:
(parameter) ui_sketch.Ui ui
ui
.
sparkles.base.pool.handle.Handle!(FrameText) ui_sketch.Ui.intern(scope const(char)[] s) pure nothrow @nogc @safe

s interned into the frame's text pool, or TextId.init for no text.

intern
(
(parameter) const(char)[] text
text
)), null);
/// A switch; `onPress` is whatever message the caller wants on a press.
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
ui_sketch.Node ui_sketch.Toggle(ref ui_sketch.Ui ui, ui_sketch.NamedOnly _ = NamedOnly(), bool on = false, scope const(char)[] label = null, ui_sketch.MsgRef onPress = MsgRef(4294967295u)) pure nothrow @nogc @safe

A switch; onPress is whatever message the caller wants on a press.

Toggle
(ref
(struct) ui_sketch.Ui

The frame's builder: write-only while building, except env (UI-Q2, UI-Q6).

Each table is the sparkles:base building block its lifetime calls for:

  • Nodes, child lists and messages are appended in build order and die together when the frame does, so they are buffers, not pools. They are HeapBuffer!(T, Storage.unique): an inline array of records would make Ui too large to live on its owner's stack, reserve and clear(releaseStorage: false) keep one block across frames (BUF11, BUF15), and unique matches Ui's own move-only identity, which keeps the refcount off the grow path (BUF7).

  • A message is not a pool handle. A Handle earns its generation when single occupants are removed while ids to them are outstanding (POOL3); a MsgRef is never held apart from the node that carries it, and the whole table is dropped at once. What does outlive a frame is the hit id an event lands on, and that is the node's key (UI-Q2), not a slot in this table.

  • Text is a TextPool (POOL12–POOL18): components keep ids, never offsets, so the arena can reset and compact under them, and a read is a borrow (POOL14) — see textIs and dump.

  • ui.text formats into an InlineBuffer: a hard bound whose overflow is reported, written only through tryWrite (WRT1, WRT3). Its slices live for the frame, which is what the IES form promises.

  • Arguments and constant messages are bump-allocated from an InSituRegion, the allocator guide's per-frame arena whose storage is the struct itself (allocators §5, §11): one pointer bump each, freed all at once by deallocateAll.

Ui
(parameter) ui_sketch.Ui ui
ui
,
(struct) ui_sketch.NamedOnly
NamedOnly
(parameter) ui_sketch.NamedOnly _
_
=
(struct) ui_sketch.NamedOnly
NamedOnly
.
(constant) ui_sketch.NamedOnly ui_sketch.NamedOnly.init = NamedOnly()
init
, bool
(parameter) bool on
on
= false,
scope const(char)[]
(parameter) const(char)[] label
label
= null,
(struct) ui_sketch.MsgRef

An erased message (UI-Q4): an index into the frame's message table.

MsgRef
(parameter) ui_sketch.MsgRef onPress
onPress
=
(struct) ui_sketch.MsgRef

An erased message (UI-Q4): an index into the frame's message table.

MsgRef
.
(constant) ui_sketch.MsgRef ui_sketch.MsgRef.init = MsgRef(4294967295u)
init
) @safe pure nothrow @nogc
=>
(parameter) ui_sketch.Ui ui
ui
.
ui_sketch.Node ui_sketch.Ui.add(ui_sketch.NodeRec rec, scope const(ui_sketch.Node)[] children) pure nothrow @nogc @safe
add
(
(struct) ui_sketch.NodeRec
NodeRec
(kind:
(enum) ui_sketch.Kind
Kind
.
(enum value) ui_sketch.Kind.toggle = 3
toggle
, on:
(parameter) bool on
on
, text:
(parameter) ui_sketch.Ui ui
ui
.
sparkles.base.pool.handle.Handle!(FrameText) ui_sketch.Ui.intern(scope const(char)[] s) pure nothrow @nogc @safe

s interned into the frame's text pool, or TextId.init for no text.

intern
(
(parameter) const(char)[] label
label
), msg:
(parameter) ui_sketch.MsgRef onPress
onPress
), null);
/// A number field; `onChange` carries the new value as an `int` payload.
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
ui_sketch.Node ui_sketch.NumberField(ref ui_sketch.Ui ui, ui_sketch.NamedOnly _ = NamedOnly(), int value = 0, scope const(char)[] unit = null, ui_sketch.MsgRef onChange = MsgRef(4294967295u)) pure nothrow @nogc @safe

A number field; onChange carries the new value as an int payload.

NumberField
(ref
(struct) ui_sketch.Ui

The frame's builder: write-only while building, except env (UI-Q2, UI-Q6).

Each table is the sparkles:base building block its lifetime calls for:

  • Nodes, child lists and messages are appended in build order and die together when the frame does, so they are buffers, not pools. They are HeapBuffer!(T, Storage.unique): an inline array of records would make Ui too large to live on its owner's stack, reserve and clear(releaseStorage: false) keep one block across frames (BUF11, BUF15), and unique matches Ui's own move-only identity, which keeps the refcount off the grow path (BUF7).

  • A message is not a pool handle. A Handle earns its generation when single occupants are removed while ids to them are outstanding (POOL3); a MsgRef is never held apart from the node that carries it, and the whole table is dropped at once. What does outlive a frame is the hit id an event lands on, and that is the node's key (UI-Q2), not a slot in this table.

  • Text is a TextPool (POOL12–POOL18): components keep ids, never offsets, so the arena can reset and compact under them, and a read is a borrow (POOL14) — see textIs and dump.

  • ui.text formats into an InlineBuffer: a hard bound whose overflow is reported, written only through tryWrite (WRT1, WRT3). Its slices live for the frame, which is what the IES form promises.

  • Arguments and constant messages are bump-allocated from an InSituRegion, the allocator guide's per-frame arena whose storage is the struct itself (allocators §5, §11): one pointer bump each, freed all at once by deallocateAll.

Ui
(parameter) ui_sketch.Ui ui
ui
,
(struct) ui_sketch.NamedOnly
NamedOnly
(parameter) ui_sketch.NamedOnly _
_
=
(struct) ui_sketch.NamedOnly
NamedOnly
.
(constant) ui_sketch.NamedOnly ui_sketch.NamedOnly.init = NamedOnly()
init
, int
(parameter) int value
value
= 0,
scope const(char)[]
(parameter) const(char)[] unit
unit
= null,
(struct) ui_sketch.MsgRef

An erased message (UI-Q4): an index into the frame's message table.

MsgRef
(parameter) ui_sketch.MsgRef onChange
onChange
=
(struct) ui_sketch.MsgRef

An erased message (UI-Q4): an index into the frame's message table.

MsgRef
.
(constant) ui_sketch.MsgRef ui_sketch.MsgRef.init = MsgRef(4294967295u)
init
) @safe pure nothrow @nogc
=>
(parameter) ui_sketch.Ui ui
ui
.
ui_sketch.Node ui_sketch.Ui.add(ui_sketch.NodeRec rec, scope const(ui_sketch.Node)[] children) pure nothrow @nogc @safe
add
(
(struct) ui_sketch.NodeRec
NodeRec
(kind:
(enum) ui_sketch.Kind
Kind
.
(enum value) ui_sketch.Kind.numberField = 4
numberField
, value:
(parameter) int value
value
, text:
(parameter) ui_sketch.Ui ui
ui
.
sparkles.base.pool.handle.Handle!(FrameText) ui_sketch.Ui.intern(scope const(char)[] s) pure nothrow @nogc @safe

s interned into the frame's text pool, or TextId.init for no text.

intern
(
(parameter) const(char)[] unit
unit
),
msg:
(parameter) ui_sketch.MsgRef onChange
onChange
), null);
/// A name and its value; pressing it sends `onPress`.
(struct) ui_sketch.Node

A handle to a node this frame built (UI-Q2: children are erased handles).

Node
ui_sketch.Node ui_sketch.KeyValue(ref ui_sketch.Ui ui, ui_sketch.NamedOnly _ = NamedOnly(), scope const(char)[] name = null, scope const(char)[] value = null, ui_sketch.MsgRef onPress = MsgRef(4294967295u)) pure nothrow @nogc @safe

A name and its value; pressing it sends onPress.

KeyValue
(ref
(struct) ui_sketch.Ui

The frame's builder: write-only while building, except env (UI-Q2, UI-Q6).

Each table is the sparkles:base building block its lifetime calls for:

  • Nodes, child lists and messages are appended in build order and die together when the frame does, so they are buffers, not pools. They are HeapBuffer!(T, Storage.unique): an inline array of records would make Ui too large to live on its owner's stack, reserve and clear(releaseStorage: false) keep one block across frames (BUF11, BUF15), and unique matches Ui's own move-only identity, which keeps the refcount off the grow path (BUF7).

  • A message is not a pool handle. A Handle earns its generation when single occupants are removed while ids to them are outstanding (POOL3); a MsgRef is never held apart from the node that carries it, and the whole table is dropped at once. What does outlive a frame is the hit id an event lands on, and that is the node's key (UI-Q2), not a slot in this table.

  • Text is a TextPool (POOL12–POOL18): components keep ids, never offsets, so the arena can reset and compact under them, and a read is a borrow (POOL14) — see textIs and dump.

  • ui.text formats into an InlineBuffer: a hard bound whose overflow is reported, written only through tryWrite (WRT1, WRT3). Its slices live for the frame, which is what the IES form promises.

  • Arguments and constant messages are bump-allocated from an InSituRegion, the allocator guide's per-frame arena whose storage is the struct itself (allocators §5, §11): one pointer bump each, freed all at once by deallocateAll.

Ui
(parameter) ui_sketch.Ui ui
ui
,
(struct) ui_sketch.NamedOnly
NamedOnly
(parameter) ui_sketch.NamedOnly _
_
=
(struct) ui_sketch.NamedOnly
NamedOnly
.
(constant) ui_sketch.NamedOnly ui_sketch.NamedOnly.init = NamedOnly()
init
, scope const(char)[]
(parameter) const(char)[] name
name
= null,
scope const(char)[]
(parameter) const(char)[] value
value
= null,
(struct) ui_sketch.MsgRef

An erased message (UI-Q4): an index into the frame's message table.

MsgRef
(parameter) ui_sketch.MsgRef onPress
onPress
=
(struct) ui_sketch.MsgRef

An erased message (UI-Q4): an index into the frame's message table.

MsgRef
.
(constant) ui_sketch.MsgRef ui_sketch.MsgRef.init = MsgRef(4294967295u)
init
) @safe pure nothrow @nogc
=>
(parameter) ui_sketch.Ui ui
ui
.
ui_sketch.Node ui_sketch.Ui.add(ui_sketch.NodeRec rec, scope const(ui_sketch.Node)[] children) pure nothrow @nogc @safe
add
(
(struct) ui_sketch.NodeRec
NodeRec
(kind:
(enum) ui_sketch.Kind
Kind
.
(enum value) ui_sketch.Kind.keyValue = 5
keyValue
, text:
(parameter) ui_sketch.Ui ui
ui
.
sparkles.base.pool.handle.Handle!(FrameText) ui_sketch.Ui.intern(scope const(char)[] s) pure nothrow @nogc @safe

s interned into the frame's text pool, or TextId.init for no text.

intern
(
(parameter) const(char)[] name
name
), text2:
(parameter) ui_sketch.Ui ui
ui
.
sparkles.base.pool.handle.Handle!(FrameText) ui_sketch.Ui.intern(scope const(char)[] s) pure nothrow @nogc @safe

s interned into the frame's text pool, or TextId.init for no text.

intern
(
(parameter) const(char)[] value
value
),
msg:
(parameter) ui_sketch.MsgRef onPress
onPress
), null);
// ── lists: keys are mandatory (UI-Q2) ────────────────────────────────────── /// A range bound to the builder. It offers `mapKeyed` and `mapByIndex`, and no /// plain `map`: it is not an input range, so Phobos' `map` does not apply. struct
(struct) ui_sketch.UiRange(R)

A range bound to the builder. It offers mapKeyed and mapByIndex, and no plain map: it is not an input range, so Phobos' map does not apply.

UiRange
(R)
{ private R
_error_ range
range
;
private
(unresolved type) Ui
Ui
*
_error_ ui
ui
;
} /// ditto auto
auto toUi(R)(R r, return ref Ui ui)

A range bound to the builder. It offers mapKeyed and mapByIndex, and no plain map: it is not an input range, so Phobos' map does not apply.

toUi
(R)(R
(parameter) R r
r
, return ref
(unresolved type) Ui
Ui
(parameter) Ui ui
ui
) =>
(template instance) UiRange!R
UiRange
!R(r, &ui);
/// One fragment node holding a keyed run of rows. Node
Node mapKeyed(alias key, alias row, R)(UiRange!R r)

One fragment node holding a keyed run of rows.

mapKeyed
(alias key, alias row, R)(UiRange!R
(parameter) UiRange!R r
r
)
{ // The default buffer: rows stay inline up to 16, then spill to the heap. UniqueBuffer!(
(unresolved type) Node
Node
, 16)
_error_ rows
rows
;
foreach (ref
(parameter) e
e
; r.
r.range
range
)
{ const
_error_ node
node
= row(e);
r.
r.ui
ui
.
r.ui.setKey
setKey
(node, hashOf(key(e)));
rows ~= node; } return r.
r.ui
ui
.
r.ui.add
add
(NodeRec(kind: Kind.
Kind.fragment
fragment
), rows[]);
} /// ditto, opting into position as the key (static or append-only lists). Node
Node mapByIndex(alias row, R)(UiRange!R r)

ditto, opting into position as the key (static or append-only lists).

mapByIndex
(alias row, R)(UiRange!R
(parameter) UiRange!R r
r
)
{ UniqueBuffer!(
(unresolved type) Node
Node
, 16)
_error_ rows
rows
;
foreach (ref
(parameter) e
e
; r.
r.range
range
)
rows ~= row(e); return r.
r.ui
ui
.
r.ui.add
add
(NodeRec(kind: Kind.
Kind.fragment
fragment
), rows[]);
} // ── messages (UI-Q4) ─────────────────────────────────────────────────────── /// A constant message, copied into the frame's table. MsgRef
MsgRef on(M)(ref Ui ui, M value)

A constant message, copied into the frame's table.

on
(M)(ref
(unresolved type) Ui
Ui
(parameter) Ui ui
ui
, M
(parameter) M value
value
)
{ static assert(__traits(isPOD, M), "a message is plain data: it is copied as bytes"); return ui.
ui.addMsg
addMsg
(MsgRec(typeKey:
(template instance) typeKey!M
typeKey
!M, value: ui.
ui.keep
keep
(value)));
} /// A message built from a component's payload. `fn` may not capture: its /// thunk is a function pointer, so a capturing lambda has no frame to reach. MsgRef
MsgRef on(alias fn)(ref Ui ui)

A message built from a component's payload. fn may not capture: its thunk is a function pointer, so a capturing lambda has no frame to reach.

on
(alias fn)(ref
(unresolved type) Ui
Ui
(parameter) Ui ui
ui
)
=> ui.
ui.addMsg
addMsg
(MsgRec(typeKey:
(template instance) typeKey!(ReturnType!fn)
typeKey
!(ReturnType!fn), payload: &
(template instance) applyErased!fn
applyErased
!fn,
payloadKey:
(template instance) typeKey!(Parameters!fn[0])
typeKey
!(Parameters!fn[0])));
/// Wraps every message `child`'s subtree sends with `fn` (UI-Q4.5). Node
Node mapMsg(alias fn)(ref Ui ui, Node child)

Wraps every message child's subtree sends with fn (UI-Q4.5).

mapMsg
(alias fn)(ref
(unresolved type) Ui
Ui
(parameter) Ui ui
ui
,
(unresolved type) Node
Node
(parameter) Node child
child
)
=> ui.
ui.add
add
(NodeRec(kind: Kind.
Kind.mapMsg
mapMsg
, map: MapRec(from:
(template instance) typeKey!(Parameters!fn[0])
typeKey
!(Parameters!fn[0]),
to:
(template instance) typeKey!(ReturnType!fn)
typeKey
!(ReturnType!fn), apply: &
(template instance) applyErased!fn
applyErased
!fn)), [child]);
/** `fn`, erased: reads its argument at `from` and writes its result at `to`. `to` is raw bytes, so the result is emplaced rather than assigned: a POD type may still declare `opAssign` (`SumType` does), and `*dst = …` would run it against whatever bytes are there. */ private void
@system void applyErased(alias fn)(scope const(void)* from, scope void* to)

fn, erased: reads its argument at from and writes its result at to. to is raw bytes, so the result is emplaced rather than assigned: a POD type may still declare opAssign (SumType does), and *dst = … would run it against whatever bytes are there.

applyErased
(alias fn)(scope const(void)*
(parameter) const(void)* from
from
, scope void*
(parameter) void* to
to
) @system
{ alias
(alias) Src = Parameters!fn[0]
Src
= const Parameters!fn[0];
alias
(alias) Dst = ReturnType!fn
Dst
= ReturnType!fn;
(unresolved type) Src
Src
*
_error_ src
src
= cast(
(unresolved type) Src
Src
*) from;
(unresolved type) Dst
Dst
*
_error_ dst
dst
= cast(
(unresolved type) Dst
Dst
*) to;
emplace(dst, fn(*src)); } // ── deferred composites (UI-Q6, on the `valueForm` pattern) ──────────────── /// A composite's value form: its arguments, built when a parent places it. struct
(struct) ui_sketch.Composite(alias fn, Args...)

A composite's value form: its arguments, built when a parent places it.

Composite
(alias fn, Args...)
{ enum
(constant) isComposite = true
isComposite
= true;
Args
_error_ args
args
;
Node
Node build(ref Ui ui) const
build
(ref
(unresolved type) Ui
Ui
(parameter) Ui ui
ui
) const => fn(ui, args);
} /** Declares `name`'s value form beside the composite `Node name(ref Ui, …)`, exactly as `valueForm` does for a writer: called without a `Ui`, `name(args)` is a `Composite` holding `args`. */ enum
(unresolved type) string
string
(constant) string ui_sketch.componentForm(string name) = "auto " ~ name ~ "(Args...)(Args args)\n" ~ "if (!(Args.length && is(Args[0] == imported!\"ui_sketch\".Ui)))\n" ~ " => imported!\"ui_sketch\".Composite!(" ~ name ~ ", Args)(args);\n"

Declares name's value form beside the composite Node name(ref Ui, …), exactly as valueForm does for a writer: called without a Ui, name(args) is a Composite holding args.

componentForm
(string name) =
"auto " ~ name ~ "(Args...)(Args args)\n" ~ "if (!(Args.length && is(Args[0] == imported!\"ui_sketch\".Ui)))\n" ~ " => imported!\"ui_sketch\".Composite!(" ~ name ~ ", Args)(args);\n"; /// Seam for a later memo site (UI-Q3): it would compare `inner.args` and the /// `env` fields read with last frame's. Here it only builds. struct
(struct) ui_sketch.Memo(C)

Seam for a later memo site (UI-Q3): it would compare inner.args and the env fields read with last frame's. Here it only builds.

Memo
(C)
{ enum
(constant) isComposite = true
isComposite
= true;
C
_error_ inner
inner
;
Node
Node build(ref Ui ui) const
build
(ref
(unresolved type) Ui
Ui
(parameter) Ui ui
ui
) const => inner.
inner.build
build
(ui);
} /// ditto auto
auto memo(C)(C c)

Seam for a later memo site (UI-Q3): it would compare inner.args and the env fields read with last frame's. Here it only builds.

memo
(C)(C
(parameter) C c
c
) if (__traits(hasMember, C, "isComposite")) =>
(template instance) Memo!C
Memo
!C(c);
/** Places a value form: copies its arguments into the frame and returns a node that the deferred phase builds top-down, after every ancestor, under the env they resolve. The composite must be `@safe pure nothrow @nogc`: its thunk is stored with those attributes. */ Node
Node place(C)(ref Ui ui, scope C c)

Places a value form: copies its arguments into the frame and returns a node that the deferred phase builds top-down, after every ancestor, under the env they resolve. The composite must be @safe pure nothrow @nogc: its thunk is stored with those attributes.

place
(C)(ref
(unresolved type) Ui
Ui
(parameter) Ui ui
ui
, scope C
(parameter) C c
c
) if (__traits(hasMember, C, "isComposite"))
{ static assert(__traits(isPOD, C), "a composite's arguments are copied by value"); // The arguments escape `c`'s scope into the frame arena. That is sound // only because `frame` runs every deferred thunk before it returns, while // the model the arguments point into is still alive: the frame structure, // not dip1000, carries the guarantee. return ui.
ui.add
add
(NodeRec(kind: Kind.
Kind.deferred
deferred
, thunk: &
(template instance) buildFrom!C
buildFrom
!C, args: ui.
ui.keep
keep
(c)), null);
} /// `C`'s deferred thunk: the composite read back from its bytes, then built. /// Its attributes are inferred from `C.build`, so an impure composite has no /// thunk that converts to `DeferredThunk`, and `place` rejects it. private Node
Node buildFrom(C)(ref Ui ui, scope const(void)[] args)

C's deferred thunk: the composite read back from its bytes, then built. Its attributes are inferred from C.build, so an impure composite has no thunk that converts to DeferredThunk, and place rejects it.

buildFrom
(C)(ref
(unresolved type) Ui
Ui
(parameter) Ui ui
ui
, scope const(void)[]
(parameter) const(void)[] args
args
)
=> (() @trusted => *cast(const(C)*) args.ptr)().
() @trusted => *cast(const(C)*)args.ptr().build
build
(ui);