fluid
Fluid is a declarative library to build graphical user interfaces. Done the D
way, the Fluid way.
These pages serve as the reference documentation for the library. For the time being, there
are no recommended learning resources, but you can get a quickstart using the tour:
dub run fluid:tour
Import Fluid per module, or all at once:
import fluid;
General nodes
In Fluid, most things are accomplished with nodes. The most basic task a node can do is displaying text or providing interaction.Labelcan be used to display text on the screen.Buttonis a clickable button.Hyperlinkis a website link.ImageViewdisplays images.ProgressBarshows completion status of an operation.Separatordraws a line to separate unrelated content.
run(
label("Hello, World!")
);
Layout nodes
A single node isn't very useful on its own — but nodes can be composed together. Using handy layout nodes likeFrame or Space you can arrange other nodes on the screen.
Use a NodeSlot to quickly switch between displayed nodes.
DragSlotcan be dragged and rearranged by the user.FieldSlotassociates input with informative nodes, expanding hit regions.Frameis a more general, styleable variant ofspace.GridFramecreates a grid layout.MapFrameplaces nodes in arbitrary positions.NodeSlotwraps a node for quick replacement.OnionFramestacks nodes on top of each other (layers).PopupButtonis a handy shortcut for building dropdown menus.PopupFramedisplays outside of regular layout flow.Spacealigns nodes in a column or row.ScrollFrameallows scrolling through a lot of content.SwitchSlot(experimental) changes layouts for different screen sizes.
run(
vspace(
label("This text displays above"),
label("This text displays below"),
),
);
Input nodes
Note: Documentation for this section is incomplete.Get information from the user using input nodes.
Buttonis a clickable button.Checkboxis a box that can be selected and deselected.CodeInputis a code editor with syntax highlighting.FieldSlotassociates input with informative nodes, expanding hit regions.NumberInputtakes a number and does basic math.PasswordInputtakes a sensitive passphrase, without displaying it.Radioboxallows selecting one out of multiple options.ScrollInputis a bare scrollbar.SizeLockrestricts maximum size of a node for responsive layouts.Sliderselects one out of multiple values of a range.TextInputtakes text — a single line, or many.
TextInput name;
Checkbox agreement;
run(
vframe(
fieldSlot!vspace(
label("Your name"),
name = lineInput(),
),
fieldSlot!hspace(
agreement = checkbox(),
label("I agree to the rules"),
),
button("Continue", delegate { }),
),
);
Theming
Note: Documentation for this section is incomplete.Fluid apps can be styled with a stylesheet.
fluid.stylecontains a list of stylable properties.fluid.themeoffers a declarative way of building stylesheets.fluid.default_themedefines Fluid's default look.
import fluid.theme;
auto theme = Theme(
rule!Frame(
margin.sideY = 4,
backgroundColor = color("#6abbe8"),
gap = 4,
),
);
Tree actions
Note: Documentation for this section is incomplete.Manipulate the node tree: search, modify, interact, automate, test, by hooking into tree events with Fluid's
tree actions.
fluid.actionscontains a basic collection of tree actions.TestSpacecan automatically test your nodes.
fluid.io.
auto ui = vspace(
label("A tree action can click this button"),
button("Click me!", delegate { }),
);
ui.focusChild()
.then((Focusable child) => child
.runInputAction!(FluidInputAction.press));
Your own nodes
Note: Documentation for this section is incomplete.Extend a class from
Node or any other Fluid node to extend Fluid's functionality.
See fluid.node for a reference.
// Define your node's behavior with a Node class
class ColoredRectangle : Node {
CanvasIO canvasIO;
Vector2 size;
override void resizeImpl(Vector2 space) {
require(canvasIO);
minSize = size;
}
override void drawImpl(Rectangle outer, Rectangle inner) {
canvasIO.drawRectangle(inner,
color("#600"));
}
}
// Construct the node with a node builder
alias rectangle = nodeBuilder!ColoredRectangle;
Input and output
Note: Documentation for this section is incomplete.Fluid does not communicate with the operating system on its own. To display content on the screen, and to take input from the keyboard and mouse, it uses a set of I/O nodes.
fluid.iodefines standard interfaces for I/O processing.RaylibView and RaylibStackimplement Raylib support.NodeChainis an optimized base class for I/O implementations.
Transformation
hoverTransformremaps mouse input to different screen areas.resolutionOverrideforces rendering at set resolution.
Low-level
Nodes for unit testing and for specialized use-cases.ArsdImageChainloads images usingarsd.ClipboardChainimplements local (non-system) clipboard.FileChainimplements basic file system access through Phobos.FocusChainkeeps track of the currently focused node.HoverChainmaps mouse pointer input to nodes.InputMapChainmaps button presses to input actions.OverlayChainprovides space for popup frames and similar.PreferenceChainloads common user preferences.TimeChainreads time passed with the system clock.TimeMachinefakes passage of time for testing.
auto root = raylibStack(
label("I'm displayed with Raylib!"),
);
while (!WindowShouldClose) {
BeginDrawing();
root.draw();
EndDrawing();
}