Styling allows the user to control the appearance of the user interface by manipulating the visual properties of the widgets.
The main class for controlling the visual properties of a specific widget in a certain state. It provides the following properties:
borderStyle: BorderStyle
outlineStyle: BorderStyle
float: Floating
position: Position
flexDirection: Layout
flexWrap: FlexWrap
justifyContent: Justify
alignItems: Align
textAlign: TextAlign
textDecoration: TextDecoration
textDecorationstyle": TextDecorationStyle
direction: Direction
fontFamily: String
overflowX: Overflow
overflowY: Overflow
overflow: Overflow
textOverflow: TextOverflow
display: Display
cursor: Cursor
animation: Animation
wordBreak: WordBreak
whiteSpace: WhiteSpace
width: Length
height: Length
minWidth: Length
minHeight: Length
maxWidth: Length
maxHeight: Length
borderWidth: Length4
borderColor: Color
borderRadius: Length4
outlineWidth: Length4
outlineOffset: Length4
outlineColor: Color
zIndex: Int
flex: Flex
gap: Length
margin: Length4
textDecorationColor: Color
textDecorationThickness: Length
padding: Length4
fontSize: Length
color: Color
fontWeight: Length
letterSpacing: Length
lineHeight: Length
opacity: Int
transform: Transform
boxShadow: BoxShadow
textShadow: TextShadow
top: Length
left: Length
right: Length
bottom: Length
background: Background
scalingAlgorithm: ScalingAlgorithm
Following is the description of each style prop. For possible values refer to the documentaiton of each style type.
borderStyleThe style of the border.outlineStyleOutline style. Used with input widgets.floatingDetermines whether/how elements float in the containing box (div).positionItem's position style.layoutDetermine the layout of the item when usingFLEXdisplay mode.flexWrapDetermines whether flex items wrap onto multiple lines.justifyThe style used to specify how items are placed in a row.alignThe style related to aligning an item inside its container.textAlignThe style related to aligning a text inside its container.textDecorationThe style of text decoration.textDecorationStyleThe style of text decoration shape.directionItem direction.fontFamilyFont family that the text written using a font in it.overflowXOverflow on x axis.overflowYOverflow on y axis.overflowOverflow on x and y axes.textOverflowSpecifies how to display text that expands beyond the container's borders.displayThe way the item is displayed.cursorCursor style.animationAnimations we want to apply on the item.wordBreakHow we should break the words on line end.whiteSpaceSpecifies how to deal with white spaces.widthItem width.heightItem height.minWidthThe minimum width of the item.minHeightThe minimum height of the item.maxWidthThe maximum width of the item.maxHeightThe maximum height of the item.borderWidthBorder width.borderColorBorder color.borderRadiusBorder radius, used to soften border corners (it takes a round shape)outlineWidthThe width of outline.outlineOffsetThe offset of the outline from the border.outlineColorThe color of outline.zIndexThis used to order items when they are on top of each other.flexThe flex style, determine a layout for items placement.gapSets the space between flex items or grid items, providing consistent spacing without the need for margins.marginMargin around the item.textDecorationColorText decoration color.textDecorationThicknessText decoration thickness.paddingPadding of the item.fontSizeFont size.fontColorFont color.fontWeightFont weight.letterSpacingTo control the distance between letters.lineHeightLine height. Useful in increasing or decreasing the space between lines.opacityItem opacity.transformTransformations applied on the item.boxShadowThe shadow of the box containing the item.textShadowThe shadow of the text in the item.topThe distance of the item from the top of its container or the screen (depending onpositionproperty).leftThe distance of the item from the left of its container or the screen (depending onpositionproperty).rightThe distance of the item from the right of its container or the screen (depending onpositionproperty).bottomThe distance of the item from the bottom of its container or the screen (depending onpositionproperty).backgroundItem background.scalingAlgorithmSpecifies the scaling algorithm used for images and canvases.
handler [styleProp: ast] this.setRaw(val: String);
Allows setting raw CSS value for any of the properties of the Style object.
handler [styleProp: ast] this.remove();
Removes (unsets) a previously set style.
This class allows the user to define multiple styles for a widget in different states. It also
allows specifying styles for the widget's branches, enabling the programmer to control the initial
appearance of the widget and its appearance when its state changes (e.g., when the mouse hovers
over it). It also allows controlling the styles of the widget's branches when its state changes.
Widgets do not directly interact with the Style class, instead they interact with a StyleSet.
We could apply a style on a component using the style property, in which we put the style we want
to apply.
As an example:
func createHeader (): SrdRef[Widget] {
// here we create a rectangle area to hold component widgets in it.
return Box({}).{
// styles used for this widget.
style.{
width = Length.percent(100);
height = Length.pt(40);
padding = Length4.pt(5, 0);
background = Background(PRIMARY_COLOR);
borderColor = PRIMARY_COLOR;
borderWidth = Length4.pt(1.5);
borderStyle = BorderStyle.SOLID;
display = Display.FLEX;
layout = Layout.COLUMN;
};
// widgets contained in this component.
addChildren({
// here we will have only a text clarifying that we are
// writing an example about the canvas.
Text(String("Alusus Web Platform Examples - Canvas")).{ style.{
fontColor = Color("fff");
fontSize = Length.pt(21.0);
width = Length.percent(100);
height = Length.percent(100);
background = Background(PRIMARY_COLOR);
margin = Length4.pt(5, 15);
} },
});
}~cast[SrdRef[Widget]];
}
Here as we can see we write a function to create a component and apply some styles to it.
Inside the style we put the value for each property we want, for example we specify that width should be 100%.
This can be done by passing a state specifier to the style to specify the state in which we want
that style to be applied.
For example:
Box({}).{
// Apply some style.
style.{
background = Background(LIGHT_COLOR);
};
// Override the style when the cursor hovers over the box.
style(StateSelector.HOVER).{
background = Background(DARK_COLOR);
}
}
The following states are available for use, and these states correspond to the states used in CSS:
def StateSelector: {
def ACTIVE: ":active";
def CHECKED: ":checked";
def DEFAULT: ":default";
def DISABLED: ":disabled";
def EMPTY: ":empty";
def ENABLED: ":enabled";
def FOCUS: ":focus";
def FULLSCREEN: ":fullscreen";
def HOVER: ":hover";
def IN_RANGE: ":in-range";
def INTERMEDIATE: ":indeterminate";
def INVALID: ":invalid";
def LINK: ":link";
def OPTIONAL: ":optional";
def OUT_OF_RANGE: ":out-of-range";
def READ_ONLY: ":read-only";
def READ_WRITE: ":read-write";
def REQUIRED: ":required";
def TARGET: ":target";
def VALID: ":valid";
def VISITED: ":visited";
}
ACTIVEWhen the widget is active.CHECKEDWhen the widget is checked. This applies to checkbox input widgets.DEFAULTThe default state.DISABLEDWhen the widget is disabled.EMPTYWhen the widget is empty, like an empty TextInput.ENABLEDWhen the widget is enabled.FOCUSWhen the widget is in focus, for example when clicking on a text input field in a form.FULLSCREENWhen the widget is in full screen state.HOVERWhen the cursor hovers over the widget.IN_RANGEThe state of value being in a given range.INTERMEDIATEWhen the widget is in an intermediate state.INVALIDWhen the widget is in an invalid state. For example when we enter invalid email in an email field.LINKThe state of a link.OPTIONALThe state of the widget being optional, for example in a form.OUT_OF_RANGEThe state of the widget's value being out of range.READ_ONLYThe state of the widget being in read only mode.READ_WRITEThe state of the widget being in read and write mode.REQUIREDThe state of the widget being required, for example password in login form.TARGETThe state of the widget being a target.VALIDThe state of the widget's value being valid.VISITEDThe state of the widget being visited, when the widget is a link.
We could do this in a similar way to the previous section, but with passing a class name to
the style property to specify which widgets to apply the style on.
Also, we could specify the required state of the widget in which the style gets applied to the
child. For example, the having the child style applied only when hovering the cursor over the
parent widget. This can be done by specifying the state in the style property before the
class name, as follows:
Box({}).{
// apply some styles
style.{
padding = Length4.pt(3);
background = Background(LIGHT_COLOR);
display = Display.FLEX;
layout = Layout.ROW;
align = Align.CENTER;
};
// apply a style on a child widget with the class `icon`
style(">>icon").{
padding = Length4.pt(0, 4);
width = Length.pt(20);
height = Length.pt(0);
heightTransition = Transition(0.2);
}
// apply a style on a child widget with the class `icon`
// this style is applied when we hover with the cursor on the icon
style({ StateSelector.HOVER, ">>icon" }).{
height = Length.pt(20)
}
// children widgets
addChildren({
// HyperLink widget
// which contains an image as child widget
Hyperlink(link, Image().{
url = icon;
// the class of this HyperLink is `icon`
className = String("icon");
})
});
}
Notice that we determine tha direct child that has the class icon in the first time.
Then we determine the state to be hovering with the cursor by passing StateSelector.HOVER.
class Animation {
handler this.set(totalDuration: Float, styles: Array[Style]);
handler this.set(totalDuration: Float, styles: Map[Float, Style]);
}
This class is used to create animation for a component.
set a method to set the animation we want.
There are two versions for this method, one that accepts the styles as an array, the other as map where keys represent the time and the value being the style corresponding to that time.
class Dimensions {
def width: Int;
def height: Int;
}
A class that holds dimensions information.
width the width.
height the height.
class Rectnagle {
def x: Int;
def y: Int;
def width: Int;
def height: Int;
}
A class that holds a rectangle information.
class Color {
def red: Int;
def green: Int;
def blue: Int;
def alpha: Int;
}
A class that holds color information.
red red channel value.
green green channel value.
blue blue channel value.
alpha the transparency of the color.
A class that holds distance information.
This class defines the following measuring units:
px number of pixels.
pt number of points.
mm distance in millimeters.
vw a relative distance, proportional to 1% of the browser window width.
vh a relative distance, proportional to 1% of the browser window height.
vmin a relative distance, proportional to 1% of the browser window minimum side length.
vmax a relative distance, proportional to 1% of the browser window maximum side length.
em a relative distance, proportional to text font size.
percent a percentage of the container component.
auto the auto value from CSS.
inherit the inherit value from CSS.
Each of these units is a function that creates an instance of type Length and gives it the
value that was passed as an arg to the function. The return value is of type SrdRef[Length].
For example:
Length.pt(50); // Creates an object with value of 50 points.
Also, it contains the following method:
toString a method to convery class information into a string.
Similar to Length but with 4 values, one for each direction.
This class defines the following measuring units:
px number of pixels.
pt number of points.
mm distance in millimeters.
vw a relative distance, proportional to 1% of the browser window width.
vh a relative distance, proportional to 1% of the browser window height.
vmin a relative distance, proportional to 1% of the browser window minimum side length.
vmax a relative distance, proportional to 1% of the browser window maximum side length.
em a relative distance, proportional to text font size.
percent a percentage of the container component.
auto the "auto" value from CSS.
inherit the inherit value from CSS.
Each of these units is a function that creates an instance of type Length4 and gives it the
values that were passed as args to the function. The return value is of type SrdRef[Length4].
For example:
Length4.pt(50); // Creates an object with value of 50 points for each of the 4 values.
Length4.pt(50, 30); // Creates an object with value of 50 points for vertical values (top and bottom)
// and 30 points for horizontal values (left and right).
Length4.pt(10, 20, 30, 40); // Creates an object with value top = 50 points, right = 20 points,
// bottom = 30 points, and left = 40 points.
You can also create the object and pass Length values to it instead of using the unit functions
mentioned above:
// Create Length4 and give it 50 points for vertical values (top and bottom)
// and 30 pixels for horizontal values (left and right).
SrdRef[Length4]().{ alloc()~init(Length.pt(50), Length.px(30)) }
class Transition {
def duration: Float = 0;
def fn: String;
def delay: Float = 0;
handler this.toString(): String;
}
A class that holds transition information.
duration transition duration.
fn the name of the applied transition function.
delay the delay in executing the transition.
toString a method to convert the class information to a string.
module Transform {
func matrix(a: Float, b: Float, c: Float, d: Float, tx: Float, ty: Float): String;
func matrix(
a1: Float, b1: Float, c1: Float, d1: Float,
a2: Float, b2: Float, c2: Float, d2: Float,
a3: Float, b3: Float, c3: Float, d3: Float,
a4: Float, b4: Float, c4: Float, d4: Float
): String;
func rotate(deg: Float): String;
func rotate(x: Float, y: Float, z: Float, deg: Float): String;
func scale(x: Float): String;
func scale(x: Float, y: Float): String;
func scale(x: Float, y: Float, z: Float): String;
func translate(x: ref[Length], y: ref[Length]): String;
func translate(x: ref[Length], y: ref[Length], z: ref[Length]): String;
}
A class that holds transform information.
matrix a method to define transform matrix.
There are two versions of this method, the first defines a 2D transform matrix, while the other defines 3D transform matrix.
rotate a method to apply a rotation transform on a component.
There are two versions of this method, the first do 2D rotation, while the other defines 3D rotation.
In the first method, we need only the angle, while in the second we need the axis vector we want to rotate around it by specifying its three coordinates.
scale a method to scale a shape, with two versions 2D and 3D.
translate a method to translate a shape, with two versions 2D and 3D.
class Background {
handler this_type(c: ref[Color]): SrdRef[Background];
handler this_type(
u: String, repX: Bool, repY: Bool,
pos: ref[BackgroundPosition],
s: ref[BackgroundSize]
): SrdRef[Background];
handler this_type(degree: Int, count: Int, args: ...any): SrdRef[Background];
handler this_type(v : String): SrdRef[Background];
}
Describes the properties of an element's background. It has three initializer functions:
- The first initializer creates a background with a solid color.
- The second initializer creates a background with an image.
- The third initializer creates a color gradient background. The first arg to this function is the
angle of the gradient. The second argument is the number of color tuples that describes the
gradient. Each touple consists of a
Colorfollowed by anIntrepresenting the percentage of the total distance at which that color starts. - The fourth initializer creates a background that is initialized with a string value.
class Flex {
handler this.toString(): String;
}
A class that holds flex information.
toString a method to convert the class information to a string.
class BoxShadow {
handler this~init();
handler this~init(offsetX: SrdRef[Length], offsetY: SrdRef[Length], color: Color);
handler this~init(
offsetX: SrdRef[Length],
offsetY: SrdRef[Length],
blurRadius: SrdRef[Length],
spreadRadius: SrdRef[Length],
color: Color
);
handler this~init(
inset: Bool,
offsetX: SrdRef[Length],
offsetY: SrdRef[Length],
blurRadius: SrdRef[Length],
spreadRadius: SrdRef[Length],
color: Color
);
handler this.toString(): String;
}
A class that holds shadow information for a box.
toString a method to convert the class information to a string.
class TextShadow {
handler this~init();
handler this~init(offsetX: SrdRef[Length], offsetY: SrdRef[Length], color: Color);
handler this~init(
offsetX: SrdRef[Length],
offsetY: SrdRef[Length],
blurRadius: SrdRef[Length],
color: Color
);
handler this.toString(): String;
}
A class that holds shadow information for a text.
toString a method to convert the class information to a string.
An enum class that holds possible values for position as enum.
STATICRELATIVEFIXEDABSOLUTESTICKY
An enum class that holds possible values for overflow properties.
VISIBLEHIDDENCLIPSCROLLAUTO
An enum class that holds possible values for the textOverflow property.
CLIPELLIPSIS
An enum class that holds possible values for display as enum.
INLINEINLINE_BLOCKBLOCKFLEXGRIDNONE
An enum class that holds possible values for layout as enum.
ROWROW_REVERSECOLUMNCOLUMN_REVERSE
An enum class that holds possible values for flex-wrap as enum.
NOWRAPWRAPWRAP_REVERSE
An enum class that holds possible values for align as enum.
STARTCENTERENDSTRETCH
An enum class that holds possible values for justify as enum.
STARTCENTERENDSTRETCHSPACE_BETWEENSPACE_AROUNDSPACE_EVENLY
An enum class that holds possible values for cursor as enum.
AUTODEFAULTHELPPOINTERPROGRESSWAITCROSSHAIRTEXTMOVENOT_ALLOWEDGRABGRABBINGEW_RESIZENS_RESIZENESW_RESIZENWSE_RESIZEZOOM_INZOOM_OUT
An enum class that holds possible values for border style as enum.
DOTTEDDASHEDSOLIDDOUBLEGROOVERIDGENONEHIDDEN
An enum class that holds possible values for word break as enum.
NORMALBREAK_ALLKEEP_ALLBREAK_WORD
An enum class that holds possible values for the whiteSpace property.
NORMALPREPRE_WRAPPRE_LINE
An enum class that holds possible values for direction as enum.
LTRRTL
An enum class that holds possible values for text decoration as enum.
NONEUNDERLINEOVERLINELINE_THROUGH
An enum class that holds possible values for text decoration style as enum.
SOLIDDOUBLEDOTTEDDASHEDWAVY
An enum class that holds possible values for text align as enum.
LEFTRIGHTCENTERJUSTIFY
def FontWeight: {
def NORMAL: 400;
def BOLD: 700;
}
An enum class that holds possible values for font weight.
NORMALBOLD
An enum class that holds possible values for floating as enum.
NONELEFTRIGHT
An enumeration to control the position of a background image when its dimensions do not match the dimension of the containing element. Possible values:
CENTERRIGHTLEFTTOPBOTTOM
An enumeration to control the size of a background image when its dimensions do not match the dimensions of the containing element. Possible values:
CONTAIN: Scales the image so that it's entirely visible.COVER: Scales the image so that it covers the entire background. Portions of the image may be outside the boundaries of the element and hence won't be visible.
An enumeration for possible scaling algorithms. Possible values:
AUTOSMOOTHHIGH_QUALITYPIXELATEDCRISP_EDGES