lustre/stylish/font
Font styling functions for lustre_stylish.
This module provides functions for styling text, including:
- Font families (typeface, serif, sans-serif, monospace)
- Font size and color
- Text alignment (left, right, center, justify)
- Font weight (bold, light, etc.)
- Font styles (italic, underline, strike-through)
- Letter and word spacing
Example
import lustre_stylish as el
import lustre/stylish/font
el.el([
font.color(el.rgb(0.0, 0.0, 1.0)),
font.size(18),
font.family([font.typeface("Open Sans"), font.sans_serif]),
], el.text("Stylish text!"))
Note: font.color, font.size, and font.family are inherited,
meaning you can set them at the top of your view and all subsequent
nodes will have that value.
Types
An attribute that can be attached to an element.
pub type Attribute(msg) =
@internal Attribute(@internal Aligned, msg)
Values
pub const align_left: @internal Attribute(@internal Aligned, msg)
Align text to the left.
pub const align_right: @internal Attribute(@internal Aligned, msg)
Align text to the right.
pub fn color(
font_color: stylish.Color,
) -> @internal Attribute(@internal Aligned, msg)
Set the text color.
This is inherited by child elements.
Example
el.el([font.color(el.rgb(1.0, 0.0, 0.0))], el.text("Red text"))
pub fn family(
families: List(Font),
) -> @internal Attribute(@internal Aligned, msg)
Set the font family stack.
This is inherited by child elements. Fonts are tried in order until one is available on the user’s system.
Example
el.el([
font.family([
font.typeface("Helvetica Neue"),
font.typeface("Helvetica"),
font.sans_serif,
])
], el.text("Clean text"))
pub const hairline: @internal Attribute(@internal Aligned, msg)
Font weight 100 (lightest).
pub const justify: @internal Attribute(@internal Aligned, msg)
Justify text to both edges.
pub fn letter_spacing(
offset: Float,
) -> @internal Attribute(@internal Aligned, msg)
Set spacing between letters.
Example
el.el([font.letter_spacing(2.0)], el.text("S p a c e d"))
pub const regular: @internal Attribute(@internal Aligned, msg)
Font weight 400 (normal/regular).
pub fn size(
size: Int,
) -> @internal Attribute(@internal Aligned, msg)
Set the font size in pixels.
This is inherited by child elements.
Example
el.el([font.size(24)], el.text("Large text"))
pub fn typeface(name: String) -> Font
A specific typeface by name.
Example
font.typeface("Open Sans")
pub const unitalicized: @internal Attribute(
@internal Aligned,
msg,
)
Remove italic styling (useful for overriding inherited italic).
pub fn word_spacing(
offset: Float,
) -> @internal Attribute(@internal Aligned, msg)
Set spacing between words.
Example
el.el([font.word_spacing(10.0)], el.text("Wide words"))