UI System

Contents
- Layout
- Custom / general component properties and functions
- Panels
- Common panel properties and functions
- Common scrollbar properties and functiions
- Label components
- Common label properties and functions
- Image components
- Common image properties and functions
- Button components
- Common button properties and functions
- TextBox components
- Common textbox properties and functions
- Other components
- Styling
- Layout Helpers
- Grid Layout
- Anchoring
- Relative Positioning
- Before/After render hooks
Layout
Layout in DVN follows the following structure:
Application -> [Windows] -> [Views] -> [Components] <-> [Components]
Which basically means an application owns a list of windows, each window owns a list of views, each view owns a list of components which may hold a list of components too.
To create custom components you simply inherit the Component class and do whatever you need.
Custom / general component properties and functions
@property ulong dataId();
@property void dataId(ulong newDataId);
@property Painting currentPainting();
@property size_t id();
@property bool isHidden();
@property bool hasFocus();
@property bool isDisabled();
@property bool isEnabled();
@property Color fillColor();
@property void fillColor(Color color);
@property Color borderColor();
@property void borderColor(Color color);
@property Color topcolor();
@property void topColor(Color color);
@property IntVector size();
@property void size(IntVector newSize);
@property int width();
@property int height();
@property IntVector position();
@property void position(IntVector newPosition);
@property int x();
@property int y();
@property Component parent();
@property Window window();
@property View view();
@property size_t componentsLength();
@property size_t visibleComponentsLength();
void fireMouseButtonDown(MouseButton button, IntVector mousePosition);
void fireMouseButtonUp(MouseButton button, IntVector mousePosition);
void fireMouseMove(IntVector mousePosition);
void fireTextInput(dchar c);
void fireKeyboardDown(KeyboardKey key);
void fireKeyboardUp(KeyboardKey key);
void update();
void updateRect(bool updateParent);
void updateRect();
void enableSwiping(bool delegate(MouseButton,SwipeDirection,IntVector) swipe, int tolerance = 150);
void show();
void hide();
void addComponent(Component component);
void removeComponent(Component component, bool updateRect = true);
void clearComponents();
void onMouseButtonDown(MouseButtonEventHandler handler, bool ignoreIntersection = false);
void onMouseButtonUp(MouseButtonEventHandler handler, bool ignoreIntersection = false);
void onKeyboardDown(KeyboardEventHandler handler, bool ignoreFocus = false);
void onKeyboardUp(KeyboardEventHandler handler, bool ignoreFocus = false);
void onMouseMove(MouseMoveEventHandler handler);
void onTextInput(TextInputEventHandler handler, bool ignoreFocus = false);
bool intersectsWith(IntVector position);
void gainFocus();
void loseFocus();
void enable();
void disable();
void clean();
Panels
Panels are basically containers of components that can be scrollable.
To create a panel simply do:
auto panel = new Panel(window);
addComponent(panel);
// Set properties here ...
To create a scrollable panel you set a scroll margin on it and then pass it to a scroll bar component.
Example:
panel.scrollMargin = IntVector(0,cast(int)((cast(double)settingsPanel.height / 3.5) / 2));
...
auto scrollBar = new ScrollBar(window, panel);
addComponent(scrollBar);
// Set properties
panel.makeScrollableWithWheel(); // Must be called after we initiate the scroll bar.
Common panel properties and functions
@property IntVector scrollMargin();
@property void scrollMargin(IntVector margin);
@property IntVector scrollPosition();
@property int minScrollVertical();
@property int maxScrollVertical();
@property int minScrollHorizontal();
@property int maxScrollHorizontal();
void scroll(int x, int y);
void scrollTo(int x, int y);
void scrollX(int x);
void scrollY(int y);
void makeScrollableWithWheel();
Common scrollbar properties and functiions
@property size_t fontSize();
@property void fontSize(size_t newFontSize);
@property string fontName();
@property void fontName(string newFontName);
@property string defaultName();
@property void defaultName(string newName);
@property bool isVertical();
@property void isVertical(bool setAsVertical);
@property size_t buttonScrollAmount();
@property void buttonScrollAmount(size_t newButtonScrollAmount);
void scrollToEnd();
Label components
To create a label component simply use the Label class.
auto label = new Label(window);
addComponent(label);
// Set properties here
label.updateRect();
label.show();
Common label properties and functions
@property bool isLink();
@property void isLink(bool newIsLink);
@property dstring text();
@property void text(dstring newText);
@property bool shadow();
@property void shadow(bool useShadow);
@property Color color();
@property void color(Color newColor);
@property Color shadowColor();
@property void shadowColor(Color newColor);
@property string fontName();
@property void fontName(string newFontName);
@property size_t fontSize();
@property void fontSize(size_t newFontSize);
void wrapText(size_t wrapWidth);
Image components
You can create an image component using the Image class.
auto image = new Image(window, "resourceName");
// auto image = new Image(window, "path/to/image.png", true);
addComponent(image);
// Set properties
image.show();
Common image properties and functions
@property double scale();
@property void scale(double newScale);
@property string name();
@property void name(string newName);
@property int opacity();
@property void opacity(int newOpacity);
@property bool isFilePath();
void makeCover();
void unmakeCover();
void setRawPosition(IntVector position);
Button components
To create a button simply use the Button class.
auto button = new Button(window);
addComponent(button);
// Set properties
button.show();
Common button properties and functions
@property dstring text();
@property void text(dstring newText);
@property Color textColor();
@property void textColor(Color newColor);
@property string fontName();
@property void fontName(string newFontName);
@property size_t fontSize();
@property void fontSize(size_t newFontSize);
@property bool fitToSize();
@property void fitToSize(bool shouldFitToSize);
void verifyClick(bool delegate() verification)
void onButtonClick(MouseButtonEventHandler eventHandler);
TextBox components
To create a textbox component simply use the TextBox class.
auto textbox = new TextBox(window);
addComponent(textbox);
// Set properties
textbox.show();
Common textbox properties and functions
@property dstring text();
@property void text(dstring newText);
@property Color textColor();
@property void textColor(Color newColor);
@property string fontName();
@property void fontName(string newFontName);
@property size_t fontSize();
@property void fontSize(size_t newFontSize);
@property int textPadding();
@property void textPadding(int newPadding);
@property bool centerText();
@property void centerText(bool shouldCenterText);
@property dchar hideCharacter();
@property void hideCharacter(dchar character);
@property size_t maxCharacters();
@property void maxCharacters(size_t amount);
Other components
Here's a list of other components you may use:
- Animation
- DropDown
- Video
- ProgressBar
- TabView
- ListPanel
- RawImage (Obsolete, use Image)
Styling
You can style certain components in a lot of ways using their paint properties. For example below is an example on styling a button.
void restyleButton(Button button, string buttonBackgroundColor, string buttonBackgroundBottomColor, string buttonBorderColor)
{
button.defaultPaint.backgroundColor = buttonBackgroundColor.getColorByHex;
button.defaultPaint.backgroundBottomColor = buttonBackgroundBottomColor.getColorByHex;
button.defaultPaint.borderColor = buttonBorderColor.getColorByHex;
button.defaultPaint.shadowColor = buttonBackgroundColor.getColorByHex;
button.hoverPaint.backgroundColor = button.defaultPaint.backgroundColor.changeAlpha(220);
button.hoverPaint.backgroundBottomColor = button.defaultPaint.backgroundBottomColor.changeAlpha(220);
button.hoverPaint.borderColor = button.defaultPaint.borderColor.changeAlpha(220);
button.hoverPaint.shadowColor = buttonBackgroundColor.getColorByHex.changeAlpha(220);
button.clickPaint.backgroundColor = button.defaultPaint.backgroundColor.changeAlpha(240);
button.clickPaint.backgroundBottomColor = button.defaultPaint.backgroundBottomColor.changeAlpha(240);
button.clickPaint.borderColor = button.defaultPaint.borderColor.changeAlpha(240);
button.clickPaint.shadowColor = buttonBackgroundColor.getColorByHex.changeAlpha(240);
button.restyle();
button.show();
}
...
restyleButton(searchButton,
"3498DB",
"2E86C1",
"21618C");
Layout Helpers
DVN includes layout helpers designed to make UI placement flexible, readable, and easy to maintain.
You can mix automatic layouts (like grids) with manual positioning or anchoring depending on your needs.
Grid Layout
A GridLayout automatically arranges components into rows and columns.
This is useful for menus, settings screens, inventory grids, or any structured interface.
Example:
auto grid = new GridLayout(
// Parent container (typically a View or Panel)
this,
// Spacing between cells in pixels
12
);
foreach (r; 0 .. 10) // 10 rows
{
auto row = grid.addRow();
foreach (c; 0 .. 5) // 5 columns
{
auto label = new Label(window);
// Configure the component...
row.add(label); // can be any component
}
}
// Apply layout to all components added to the grid
grid.update();
Anchoring
Anchoring aligns a component relative to its parent (either a view or another component).
This is useful for simple layouts or UI elements that must stay attached to a specific screen region.
Example:
component.anchor = Anchor.right;
Available Anchors:
topLeft top topRight
left center right
bottomLeft bottom bottomRight
Interaction with GridLayout
- If you set anchor before putting the component into a GridLayout and then call grid.update(), the grid will overwrite the position.
- If you call grid.update() first, and then set anchor or move the component, your manual positioning will override the grid.
In other words: GridLayout and anchoring both just write positions. Whichever you apply last effectively takes priority.
For clarity and maintainability, it's recommended to either let the grid fully control positions, or keep the component outside the grid if you plan to position it manually.
Relative Positioning
For finer manual control, components can be positioned relative to another component.
This is useful when building flows like stacked buttons, linked labels, or dynamic menus.
Example:
component_1.moveBelow(component_2);
Available movement helpers:
void moveBelow(Component other, int spacing = 0, bool center = false);
void moveAbove(Component other, int spacing = 0, bool center = false);
void moveRightOf(Component other, int spacing = 0, bool center = false);
void moveLeftOf(Component other, int spacing = 0, bool center = false);
spacing adds pixel distance between components and center = false/true controls whether they're aligned to the same edge or centered relative to the other component.
Before/After render hooks
All components have a before and after render hook that can be used to hook into their render process. This is espcially useful for characters where you can hook into a character and replace their render with something else, ex. a Live2D render.
Simply call these two function on a component to do it.
void setBeforeRender(void delegate() beforeRender);
void setAfterRender(void delegate() afterRender);