Repository navigation
Text Rich Text
Blinc has two main elements that show text. Use text() for plain text.
Use rich_text() for text with inline formatting in HTML-like markup.
For headings, paragraphs, captions, and inline composition, see the Typography helpers guide.
The simplest way to show text is the text() element:
use blinc::layout::prelude::*;
// Basic text
text("Hello, World!")
// Styled text
text("Styled text")
.size(24.0)
.color(Color::BLUE)
.bold()
.italic()
// Text with decorations
text("Underlined and struck")
.underline()
.strikethrough()| Method | Description |
|---|---|
.size(f32) |
Font size in pixels |
.color(Color) |
Text color |
.bold() |
Bold weight |
.italic() |
Italic style |
.underline() |
Underline decoration |
.strikethrough() |
Strikethrough decoration |
.align(TextAlign) |
Horizontal alignment (Left, Center, Right) |
.v_align(TextVerticalAlign) |
Vertical alignment (Top, Center, Baseline) |
.font_family(FontFamily) |
Custom font family |
.line_height(f32) |
Line height multiplier (default: 1.2) |
.no_wrap() |
Keeps the text on one line |
The rich_text() element supports inline formatting with HTML-like tags. If a single block of text needs mixed styles, use this element.
use blinc::layout::prelude::*;
// Basic formatting
rich_text("This has <b>bold</b> and <i>italic</i> text.")
.size(16.0)
.default_color(Color::WHITE)
// Nested tags
rich_text("<b>Bold with <i>nested italic</i></b>")
// Inline colors. `r##` lets the string hold `"#`.
rich_text(r##"Colors: <span color="#FF0000">red</span> and <span color="blue">blue</span>"##)
// Links (clickable, opens in browser)
rich_text(r#"Visit <a href="https://example.com">our website</a> for more info."#)| Tag | Effect |
|---|---|
<b>, <strong>
|
Bold text |
<i>, <em>
|
Italic text |
<u> |
Underlined text |
<s>, <strike>, <del>
|
Strikethrough text |
<a href="url"> |
Clickable link (auto-underlined) |
<span color="..."> |
Inline color |
The <span color="..."> tag accepts several color formats:
// Hex colors
rich_text(r##"<span color="#FF0000">Red</span>"##)
rich_text(r##"<span color="#F00">Short hex</span>"##)
rich_text(r##"<span color="#FF000080">With alpha</span>"##)
// Named colors (CSS subset)
rich_text(r#"<span color="crimson">Crimson</span>"#)
rich_text(r#"<span color="steelblue">Steel Blue</span>"#)
// RGB/RGBA
rich_text(r#"<span color="rgb(255, 128, 0)">Orange</span>"#)Supported named colors:
- black, white, red, green, blue, yellow, cyan, magenta, gray, silver
- maroon, olive, navy, purple, teal, orange, pink, brown, lime, coral
- gold, indigo, violet, crimson, salmon, tomato, skyblue, steelblue, transparent
Rich text decodes common HTML entities automatically:
rich_text("Use <b> for bold") // Renders: Use <b> for bold
rich_text("© 2024 • All Rights Reserved ™")
rich_text("“Smart quotes” — and …")Supported entities:
-
<,>,&,",', -
©,®,™ -
—,–,… -
‘,’,“,”,•,· - Numeric entities (
A,A)
To control styles from code, use the range-based API with byte indices:
// Style specific byte ranges
rich_text("Hello World")
.bold_range(0..5) // "Hello" is bold
.color_range(6..11, Color::CYAN) // "World" is cyan
.size(18.0)
.default_color(Color::WHITE)
// Multiple overlapping styles
rich_text("Important Notice: Please read carefully!")
.bold_range(0..16) // "Important Notice" bold
.color_range(0..9, Color::ORANGE) // "Important" orange
.underline_range(18..39) // "Please read carefully" underlinedThese range methods are available:
.bold_range(Range<usize>).italic_range(Range<usize>).underline_range(Range<usize>).strikethrough_range(Range<usize>).color_range(Range<usize>, Color).link_range(Range<usize>, url: &str)
Links that come from <a href> in the markup, from .link_range(), or from a StyledText, are
interactive:
- On macOS, Linux and Windows, a click on a link opens the URL in the default browser of the system. On other platforms, Blinc writes a warning to the log.
- Over a link, the cursor changes to a pointer.
- Rich text underlines links automatically to make them visible.
rich_text(r#"
Check the <a href="https://docs.example.com">documentation</a>
or view the <a href="https://github.com/example">source code</a>.
"#)
.size(14.0)
.default_color(Color::WHITE)For simple clickable text, use the link() widget:
// Default behavior - opens URL in browser
link("Click here", "https://example.com")
// A larger link
link("Styled link", "https://example.com")
.font_size(18.0)
// An underline only while the pointer is over the link
link("Quiet link", "https://example.com")
.underline_on_hover()
// Your own action in place of the browser
link("Log the URL", "https://example.com")
.font_size(14.0)
.on_click(|url, _| println!("{url}"))The modifiers of a link combine. If two of them set the underline, the last one applies.
Links, blockquotes, rules, lists, and tables take their colors from rules in the default stylesheet. Thus, a stylesheet can restyle them:
| Class | Element | Default |
|---|---|---|
blinc-link |
a link()
|
--text-link, --primary-hover on hover |
blinc-blockquote |
a blockquote()
|
--surface-overlay fill, --border left edge |
blinc-hr |
an hr()
|
--border |
blinc-list-marker |
a bullet or number | --text-tertiary |
blinc-task-box |
the box of a task item, checked for a done item |
--text-tertiary |
blinc-thead, blinc-tfoot
|
the head and foot of a table | --surface-overlay |
blinc-th, blinc-td
|
text from th_text(), td_text()
|
--text-primary, --text-secondary
|
blinc-tr-alt |
an odd row from striped_tr()
|
--accent-subtle |
.blinc-link { color: #0ea5e9; }
.blinc-tr-alt { background: transparent; }If you give a color to the widget (text_color, hr_color, header_bg, a
configuration color), the widget sets it on the element. That color then has
priority over the rule.
To integrate with syntax highlighting or markdown rendering, create rich text from a pre-built StyledText:
use blinc::layout::styled_text::{StyledText, StyledLine, TextSpan};
let styled = StyledText {
lines: vec![
StyledLine {
text: "Hello World".to_string(),
spans: vec![
// Bytes 0 to 5, red and bold
TextSpan::new(0, 5, Color::RED, true),
],
},
],
};
rich_text_styled(styled)
.size(16.0)
.default_color(Color::WHITE)This complete example shows various text features:
use blinc::app::prelude::*;
use blinc::core::Color;
fn demo_ui() -> impl ElementBuilder {
div()
.flex_col()
.gap(4.0)
.p(5.0)
// Plain text
.child(
text("Plain Text Example")
.size(24.0)
.color(Color::WHITE)
.bold()
)
// Rich text with inline formatting
.child(
rich_text("This is <b>bold</b>, <i>italic</i>, and <span color=\"#00FF00\">green</span>.")
.size(16.0)
.default_color(Color::WHITE)
)
// Interactive link
.child(
rich_text(r#"Visit <a href="https://github.com">GitHub</a> for more."#)
.size(16.0)
.default_color(Color::WHITE)
)
// Range-based styling
.child(
rich_text("Programmatic styling with ranges")
.bold_range(0..12)
.color_range(13..20, Color::CYAN)
.underline_range(21..32)
.size(16.0)
.default_color(Color::WHITE)
)
}To see all features at work, run the rich text demo:
cargo run -p blinc_app_examples --example rich_text_demoGetting Started
Migrating
Mobile Development
Example Gallery
- Example Gallery
- Canvas Element
- Canvas Kit Interactive
- Carousel Demo - Selector API Showcase
- Chrome-Style Tabs
- blinc_cn Components
- Run with
cargo run -p blinc_app_examples --features cn --example cn_pickers_demo. - Code Element
- Complex SVG
- CSS Debug
- CSS Visual Features
- Layer Effects
- Emoji and HTML Entities
- @flow Shader
- Fluid Surface
- Skeleton animation with glTF +
blinc_canvas_kit. - Gpu Pass Demo
- Image CSS Styling
- Image Layer Test
- Keyframe Animation Canvas
- Markdown Editor
- 3D Mesh Demo — renders the Khronos glTF
DamagedHelmetsample model - Motion Demo
- Music Player Glass Card
- Node-editor demo — pre-wired graph with three node types, typed
- Notch Menu Bar
- Overflow Fade
- Overlay System
- Pointer Query
- Rich Text Element
- Rich Text Editor
- Scroll Container
- Semantic @flow
- Sortable
- Stateful API + Signal-bound modifiers demo.
- End-to-end 3D demo wiring Blinc's SceneKit3D renderer up to
- Unified Styling API
- SVG Animation
- Table Builder
- Tabler Icons
- Minimal text positioning test
- Text Input Widgets
- KHR_texture_transform
- Theme System
- Timeline Animation
- Typography
- Wet Glass
- Windowed Application
Web Development
Core Concepts
- Elements & Layout
- Styling & Materials
- CSS Styling
- Theming
- Event Handling
- Accessibility
- State Management
- Lists & Conditional Content
- Element Refs
Animation
Components
Component Library (blinc_cn)
- Overview
- Button
- Card
- Icons
- Typography
- Dialog
- Form Components
- Date, Time and Colour Pickers
- Rich Text Editor
- Code Editor
- Navigation
- Feedback
- Layout
- Data Display
Widgets
- Buttons & Inputs
- Text & Rich Text
- Code Editor
- Scroll Containers
- Virtualized List
- Canvas Drawing
- Gestures
- Notched Surfaces
- Images & SVG
- Audio & Video
- Markdown Rendering
Canvas Kit
Advanced
- Routing & Navigation
- Multi-Window
- System Integration
- Element Query API
- Overlay System
- Custom State Machines
- Pointer Query
- Performance Tips
- Flow Shaders
- 3D Rendering
- Custom GPU Passes
- Hot reloading
Architecture
Contributing