fluid.size_lock
Size locking allows placing restrictions on the size of a node. Using the
SizeLock node
template, one can set limits on the maximum size of a node.
Normally, nodes default to using the least space they can: the bare minimum they need
to display correctly. If their
Node.layout.align property is set to fill, they will
instead attempt to use all of the space they're given. Using SizeLock allows
for a compromise by placing a limit on how much space a node can use.
Note
Usinglayout!"fill" with SizeLock will negate the lock's effect. Use a different
alignment like "start", "center" or "end".
Size limit can be used to center content on a wide screen. By using
sizeLock!node,
.layout!"center" and .sizeLimitX, we can create space around the node for comfortable
reading.
import fluid;
sizeLock!vframe(
.sizeLimitX(400), // Maximum width of 800 px
.layout!(1, "center"), // Use excess space to center the node
label(
"By using sizeLock and setting the right limit, a node can be "
~ "forced to use a specific amount of space. This can make your "
~ "app easier to use on a wide screen, without affecting smaller "
~ "windows or displays."
),
);
-
@safe SizeLimitsizeLimit(size_t x, size_t y); @safe SizeLimitsizeLimitX(size_t x); @safe SizeLimitsizeLimitY(size_t y); @safe FloatSizeLimitsizeLimit(float x, float y); @safe FloatSizeLimitsizeLimitX(float x); @safe FloatSizeLimitsizeLimitY(float y);Thenode property sets the maximum amount of space asizeLimitSizeLocknode can use.can only be used withsizeLimitSizeLock.Parameters
size_t xMaximum width of the node in pixels. size_t yMaximum height of the node in pixels. Return value
A configured node parameter struct, which can be passed into thesizeLocknode builder. This will be aSizeBoundsstruct if the input parameters arefloat(preferred), orSizeLimitif they aresize_tlikeuintorulong. -
structFloatSizeLimit;This node property defines the maximum size for aSizeLocknode. Nodes can be given a limit by setting eitherwidthorheight.Theinitvalue defaults to no restrictions.-
Vector2limit;The imposed limit as a vector. Thexfield is the maximum width, andyis the maximum height. They both default toinfinity, effectively not setting any limit. -
ref @safe inout(float)width() inout return;Return value
The maximum width imposed on the node. -
@safe boolisWidthLimited() const;Return value
True if there is a limit applied to node width. -
ref @safe inout(float)height() inout return;Return value
The maximum height imposed on the node. -
@safe boolisHeightLimited() const;Return value
True, if there is a limit applied to node height.
-
-
templatesizeLock(alias T)A node builder that constructs aSizeLocknode.can be used with other node builders, for examplesizeLockwill use a vertical frame as its base, whilesizeLock!vframe()will use a horizontal frame.sizeLock!hframe() -
classSizeLock(T : Node): T;"locks" the size of a node, limiting the amount of space it will use from the space it is given.SizeLockSize locks are extremely useful for responsible applications, as they can make sure the content doesn't span too much space on large screens. For example, a width limit can be set withsizeLimitX, preventing nodes from spanning the entire width of the screen.import fluid; // The frame will appear horizontally-centered in the parent node, // and will fill it vertically sizeLock!vframe( .layout!(1, "center", "fill"), .sizeLimitX(400), label("Hello, World!") );-
SizeLimitlimit;The maximum size of this node. If a value on either axis is0, limit will not be applied on the axis.has been superseded bylimitsizeLimit, which uses floats instead of integers, like the rest of Fluid. For now, it takes priority oversizeLimitif set. -
FloatSizeLimitsizeLimit;The maximum size of the node.
-