fluid.node
-
abstract classNode: fluid.node.HasContext;Represents a Fluid node.-
Layoutlayout;Layout for this node. -
TagListtags;Tags assigned for this node. -
Breadcrumbsbreadcrumbs;Breadcrumbs assigned and applicable to this node. Loaded every resize and every draw. -
HitFilterhitFilter;Filter to apply to every result ofinBounds, controlling how the node reacts to some events, such as mouse click or a finger touch.By changing this toHitFilter.miss, this can be used to prevent a node from accepting hover input, making it "invisible" to such input. A value ofHitFilter.missBranchwill disable the whole branch, including its children.HitFilter.hitBranchwill only block children from taking input, but retain the node's ability to take it. The default value allows all events. -
boolisThemeExplicit;True if the theme has been assigned explicitly by a direct assignment. If false, the node will instead inherit themes from the parent.This can be set to false to reset the theme. -
protected Vector2minSize;Minimum size of the node. -
@safe this();Construct a new node.The typical approach to constructing new nodes is viafluid.utils.nodeBuilder. A node component would provide an alias pointing to thenodeBuilderinstance, which can then be used as a factory function. For example,Labelprovides thelabelnode builder. Using these has increased convenience by making it possible to specify special properties while constructing the node, for exampleauto myLabel = label(.layout!1, .theme, "Hello, World!"); // Equivalent of: auto myLabel = new Label("Hello, World!"); myLabel.layout = .layout!1; myLabel.theme = .theme;See also
fluid.utils.nodeBuilder -
@safe boolisHidden() const scope return;Check if the node is hidden. -
@safe boolisHidden(bool value) scope return;Set the visibility -
@safe boolopEquals(const Object other) const;Return value
True if both nodes are the same node. -
@safe inout(Theme)theme() inout; @safe Themetheme(Theme newValue);The theme defines how the node will appear to the user.Themes affect the node and its children, and can respond to changes in state, like values changing or user interaction. If no theme has been set, a default one will be provided and used automatically. SeeThemefor more information.Return value
Currently active theme.Parameters
Theme newValueChange the current theme. -
@safe voidinheritTheme(Theme value);Nodes automatically inherit theme from their parent, and the root node implicitly inherits the default theme. An explicitly-set theme will override any inherited themes recursively, stopping at nodes that also have themes set explicitly.Parameters
Theme valueTheme to inherit. See also
theme -
@safe voidresetTheme();Clear the currently assigned theme -
ref @safe inout(Style)style() inout;Current style, used for sizing. Does not include any changes made bywhenclauses or callbacks.Direct changes are discouraged, and are likely to be discarded when reloading themes. Use themes instead. -
Thisshow(this This = Node)() return;Show the node. -
Thishide(this This = Node)() return;Hide the node. -
Thisdisable(this This = Node)();Disable this node. -
Thisenable(this This = Node)();Enable this node. -
final nothrow @safe inout(TreeContext)treeContext() inout;Return value
ActiveTreeContextfor this node. -
final @safe TreeContexttreeContext(TreeContext context);ChangeTreeContextused by this tree. Triggers a resize if the new context is different from the one set.Parameters
TreeContext contextNew context to set. Return value
Same context as passed. -
final @safe voidtoggleShow();Toggle the node's visibility. -
final @safe voidremove();Remove this node from the tree before the next draw. -
@safe booltoRemove(bool value); @safe booltoRemove() const;is used to mark nodes for removal. A node marked as such should stop being drawn, and should be removed from the tree.toRemoveParameters
bool valueNew value to use for the node. Return value
True if the node is to be removed from the tree. -
final @safe Vector2getMinSize() const;Get the minimum size of this node. -
@safe boolisHovered() const;Check if this node is hovered.Returns false if the node or, while the node is being drawn, some of its ancestors are disabled. -
ref @safe inout(bool)isDisabled() inout;Check if this node is disabled. -
voidapplyAll(this This, Parameters...)(Parameters params);Apply all of the given node parameters on this node.This can be used to activate node parameters after the node has been constructed, or inside of a node constructor.Note
Due to language limitations, this function has to be called with the dot operator, likethis..applyAll()Parameters
Parameters paramsNode parameters to activate. Applying parameters from inside of a node constructor.class MyNode : Node { this() { this.applyAll( .layout!"fill", ); } override void resizeImpl(Vector2) { } override void drawImpl(Rectangle, Rectangle) { } } auto myNode = new MyNode; assert(myNode.layout == .layout!"fill"); -
final @safe voidstartAction(TreeAction action); final @safe voidstartTreeAction(TreeAction action);Perform a tree action the next time this node is drawn.Tree actions can be used to analyze the node tree and modify its behavior while it runs. Actions can listen and respond to hooks likebeforeDrawandafterDraw. They can interact with existing nodes or inject nodes in any place of the tree. Limited scope: The action will only act on this branch of the tree:beforeDrawandafterDrawhooks will only fire for this node and its children.can be used to disable this, and search the entire tree. Starting actions: Most usually, a tree actions provides its own function for creating and starting, so this method does not need to be called directly. This method may still be used if more control is needed, or to implement a such a starter function. If an action has already started, callingstartTreeActionagain will replace it. Making it possible to adjust the action's scope, or restart the action automatically if it stops. Lifetime control: Tree actions are responsible for their own lifetime. After a tree action starts, it will decide for itself when it should end. This can be overridden by explicitly calling thestartActionTreeAction.stopmethod.Parameters
TreeAction actionAction to start. -
protected final @safe autostartBranchAction(BranchAction action); final autostartBranchAction(T)(T range)
if (isForwardRange!T && is(ElementType!T : BranchAction));Start a branch action (or multiple) to run on children of this node.This should only be used insidedrawImpl. The action will stop as soon as the return value goes out of scope.Parameters
BranchAction actionBranch action to run. A branch action implements a subset of tree action's functionality, guaraneeing correct behavior when combined with this. T rangeMultiple actions can be launched at once by passing a range of branch actions. Return value
A RAII struct that stops all started actions as soon as the struct leaves the scope. -
@safe boolisResizePending() const;Return value
True if this node is to be resized before the next frame. -
final nothrow @safe voidupdateSize() scope;Recalculate the window size before next draw. -
final @safe voidconfigure(TreeWrapper wrapper);Reconfigure the node to use a specific wrapper (I/O stack). Triggers a resize.If not called, the default wrapper is used, seecreateDefaultTreeWrapper.Parameters
TreeWrapper wrapperWrapper to use. See also
configureBlank -
final @safe voidconfigureBlank();Remove tree wrapper. Triggers a resize.This is equivalent to callingconfigure(null). Seeconfigurefor details. -
final @trusted voiddrawAsRoot(Rectangle viewport = Rectangle(0, 0, 0, 0));Draw this node as a root node. -
protected @safe voiddrawChild(Node child, Rectangle space);Draw a child node at the specified location inside of this node.Before drawing a node, it must first be resized. This should be done ahead of time inresizeImpl. UseupdateSize()to cause it to be called before the next draw call.Parameters
Node childChild to draw. Rectangle spaceSpace to place the node in. The drawn node will be aligned inside the given box according to its layoutfield. -
@safe RectanglemarginBoxForSpace(Rectangle space) const;Get the node's margin box for given available space. The margin box, nor the available space aren't typically given to a node, but this may be useful for its parent nodes.Parameters
Rectangle spaceAvailable space box assigned for the node. Return value
The margin box calculated from the given space rectangle. -
@safe RectanglepaddingBoxForSpace(Rectangle space) const;Get the node's padding box (outer box) for set available space.Parameters
Rectangle spaceAvailable space box given to the node. Return value
The padding box calculated from the given space rectangle. -
protected @safe voidprepareChild(Node child);Prepare a child for use. This is automatically called byresizeChildand only meant for advanced usage.This method is intended to be used when conventional resizing throughresizeImplis not desired. This can be used to implement an advanced system with a different resizing mechanism, or something likeNodeChain, which changes how children are managed. Be mindful that child nodes must have some preparation mechanism available to initialize their I/O systems and resources — normally this is done byresizeImpl.Parameters
Node childChild node to resize. -
protected @safe Vector2resizeChild(Node child, Vector2 space);Resize a child of this node.Parameters
Node childChild node to resize. Vector2 spaceMaximum space available for the child to use. Return value
Space allocated by the child node. -
Tuse(T : IO)(); Tuse(T : IO)(out T io);Connect to an I/O system -
Trequire(T : IO)(); Trequire(T : IO)(out T io);Require -
voidload(T, I : IO)(I io, ref T resource);Load a resource associated with the given I/O.The resource should be continuously loaded duringresizeImpl. Even if a resource has already been loaded, it has to be declared withso the I/O system knows it is still in use.loadCanvasIO canvasIO; DrawableImage image; void resizeImpl(Vector2 space) { require(canvasIO); load(canvasIO, image); }Parameters
I ioI/O system to use to load the resource. T resourceResource to load. -
autoimplementIO(this This)();Enable I/O interfaces implemented by this node.Return value
A RAII struct that disables these interfaces on destruction. -
protected abstract @safe voidresizeImpl(Vector2 space);This is the implementation of resizing to be provided by children.If style margins/paddings are non-zero, they are automatically subtracted from space, so they are handled automatically. -
protected abstract @safe voiddrawImpl(Rectangle paddingBox, Rectangle contentBox);Draw this node.Tip
Instead of directly accessingstyle, usepickStyleto enable temporarily changing styles as visual feedback.resizeshould still use the normal style.Parameters
Rectangle paddingBoxArea which should be used by the node. It should include styling elements such as background, but no content. Rectangle contentBoxArea which should be filled with content of the node, such as child nodes, text, etc. -
protected @safe boolhoveredImpl(Rectangle rect, Vector2 mousePosition);Check if the node is hovered.This function is currently being phased out in favor of theobstructsfunction. This will be called right before drawImpl for each node in order to determine the which node should handle mouse input. The default behavior considers the entire area of the node to be "hoverable".Parameters
Rectangle rectArea the node should be drawn in, as provided by drawImpl. Vector2 mousePositionCurrent mouse position within the window. -
protected @safe HitFilterinBoundsImpl(Rectangle outer, Rectangle inner, Vector2 position); final @safe HitFilterinBounds(Rectangle outer, Rectangle inner, Vector2 position);Test if the specified point is the node's bounds. This is used to map screen positions to nodes, such as when determining which nodes are hovered by mouse. If the node contains the point, then it's a "hit," and if not, it's a "miss."This is rarely used in nodes built into Fluid. A notable example where this is overridden isSpace, which is always transparent, expecting children to block occupied areas. This makesSpacevery handy for visually transparent overlays. User-provided implementation should override; calls testing the node's bounds should useinBoundsImpl, which automatically applies theinBoundshitFilterfield as a filter on the result.See also
hitFilterto filter the return value, making the node or its children transparent.Parameters
Rectangle outerPadding box of the node. Rectangle innerContent box of the node. Vector2 positionTested position. Return value
Any of the values ofHitFilter. In most cases, eitherHitFilter.hitorHitFilter.miss, depending whether the node can be hit or not in the specific point. Children nodes do not contribute to a node's opaqueness. The return value ofis filtered by the value ofinBoundshitFilter. Returning a value ofHitFilter.hitBranchcan be used to hijack hover events that would otherwise be handled by the children. -
@safe RectanglefocusBoxImpl(Rectangle inner) const;The focus box defines the focused part of the node. This is relevant in nodes which may have a selectable subset, such as a dropdown box, which may be more important at present moment (selected). Scrolling actions likescrollIntoViewwill use the focus box to make sure the selected area is presented to the user.Return value
The focus box of the node. -
@safe StylepickStyle();Get the current style. -
protected @safe voidreloadStyles();Reload style from the current theme.
-
-
@safe voidrun(Node node);Start a Fluid GUI app.This is meant to be the easiest way to launch a Fluid app. Call this in yourmain()function with the node holding your user interface, and that's it! The function will not return until the app is closed.
You can close the UI programmatically by callingvoid main() { run( label("Hello, World!"), ); }remove()on the root node. The exact behavior of this function is defined by theTreeWrapperin use, so some functionality may vary. Some backends might not support this.Parameters
Node nodeThis node will serve as the root of your user interface until closed. If you wish to change it at runtime, wrap it in a NodeSlot. -
@safe RunCallbackmockRun(RunCallback callback);Set a new function to use instead ofrun. -
@safe intrunWhileDrawing(Publisher!() publisher, Node node, int frameLimit = (int).max);Draw the node in a loop until an event happens.This is useful for testing. A chain of tree actions can be finished off with a call to this function to ensure it will finish after a frame or few.Parameters
Publisher!() publisherPublisher to subscribe to. If the publisher emits an event, drawing will stop and this function will return. Node nodeNode to draw in loop. int frameLimitMaximum number of frames that may be drawn. Errors if reached. Return value
Number of frames that were drawn as a consequence.