Slint · Slint components
This page shows the Slint implementation. Slint components written for native Rust applications and the browser. Browse the catalog, run each live example, and copy the .slint source into your own app.
Label
A versatile label component for displaying text with support for secondary text, highlighting, masking, and customizable styling. Perfect for form labels, captions, and general text display with optional/required indicators.
#Import
use gpui_kit::component::label::{Label, HighlightsMatch};// Installed in ui/components. That directory is on the Slint include path, so import by file name:
import { Label } from "label.slint";use iced::widget::{column, container, mouse_area, row, scrollable, svg, text};
use iced::{Alignment, Element, Length, Task, Theme};import { Text, View } from "nsh";
import { Input } from "./input";
import { Label } from "./label";#Usage
GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
// The whole component: a line of text, an asterisk when the field is
// required, and a slot after both for a hint or the control itself.
let usage = column![
Label::new("Workspace name"),
Label::new("Email address").required(true),
Label::new("Seats").suffix(hint("up to 20")),
Label::new("Billing email")
.required(true)
.suffix(hint("we only use it for invoices")),
]
.spacing(12.0);NSHNo NSH version of this example yet.
#Form labels
// Required field
Label::new("Email Address")
.secondary("*")
.text_color(cx.theme().destructive)
// Optional field
Label::new("Phone Number")
.secondary("(optional)")
// Field with description
Label::new("Password")
.secondary("(minimum 8 characters)")Label {
text: "Email";
required: true;
}
Input {
placeholder: "you@example.com";
}// The required mark and the secondary text are the two things a form needs
// from a label: `required(true)` draws the asterisk in the danger colour, and
// `suffix` carries what the field wants beside it.
let form_labels = column![
Label::new("Email").required(true),
Input::new("email").placeholder("you@example.com"),
Label::new("Phone").suffix(hint("(optional)")),
Input::new("phone").placeholder("+1 555 0100"),
Label::new("Release date")
.required(true)
.suffix(hint("(YYYY-MM-DD)")),
Input::new("date").placeholder("2026-01-31"),
]
.spacing(8.0);const form = (
<View style={{ gap: 6 }}>
<Label text="Email" required />
<Input placeholder="name@example.com" onChangeText={() => {}} />
</View>
);#Basic Label
Label::new("This is a label")SlintNo Slint version of this example yet.
let basic = Label::new("This is a label");const basic = <Label text="Project name" />;#Label with Secondary Text
// Label with optional indicator
Label::new("Company Address")
.secondary("(optional)")
// Label with required indicator
Label::new("Email Address")
.secondary("(required)")VerticalLayout {
spacing: 8px;
alignment: start;
Label {
text: "Workspace name";
Text {
text: "Visible to everyone in the organisation.";
color: Theme.muted-foreground;
font-size: Theme.font-size-xs;
vertical-alignment: center;
}
}
Label {
text: "Storage";
Label {
text: "(GB)";
size: ControlSize.small;
}
}
}// A unit or a parenthetical note follows the label in the muted colour,
// where Slint nests a smaller `Label` in the slot.
let secondary = column![
Label::new("Storage").suffix(hint("(GB)")),
Label::new("Workspace name").suffix(hint("visible to everyone in the organisation")),
]
.spacing(8.0);const secondary = (
<Label text="Workspace" secondary="Visible to your team" />
);#Text Alignment
// Left aligned (default)
Label::new("Text align left")
// Center aligned
Label::new("Text align center")
.text_center()
// Right aligned
Label::new("Text align right")
.text_right()SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.
#Text Highlighting
// Full text highlighting (finds all matches)
Label::new("Hello World Hello")
.highlights("Hello")
// Prefix highlighting (only matches at start)
Label::new("Hello World")
.highlights(HighlightsMatch::Prefix("Hello".into()))
// Highlight with secondary text
Label::new("Company Name")
.secondary("(optional)")
.highlights("Company")SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.
#Color and Styling
use gpui_kit::component::green_500;
// Custom text color
Label::new("Color Label")
.text_color(green_500())
// Font styling
Label::new("Font Size Label")
.text_size(px(20.))
.font_semibold()
.line_height(rems(1.8))SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.
#Masked Labels
// For sensitive information
Label::new("9,182,1 USD")
.text_2xl()
.masked(true) // Shows as "•••••••••••"
// Toggle masking programmatically
Label::new("500 USD")
.text_xl()
.masked(self.masked)SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.
#Multi-line Text
// Text wrapping with line height
div().w(px(200.)).child(
Label::new(
"Label should support text wrap in default, \
if the text is too long, it should wrap to the next line."
)
.line_height(rems(1.8))
)VerticalLayout {
spacing: 8px;
alignment: start;
Label {
text: "Describe what changed in this release and why it matters to someone reading the changelog for the first time.";
}
Input {
placeholder: "Release notes";
}
}NSHNo NSH version of this example yet.
#Different Sizes
// Using text size utilities
Label::new("Extra Large").text_2xl()
Label::new("Large").text_xl()
Label::new("Medium").text_base() // default
Label::new("Small").text_sm()
Label::new("Extra Small").text_xs()Label {
text: "Small";
size: ControlSize.small;
}
Label {
text: "Medium";
}
Label {
text: "Large";
size: ControlSize.large;
required: true;
}NSHNo NSH version of this example yet.
#Search Highlighting
// Interactive search highlighting
let search_term = "Hello";
Label::new("Hello World Hello Universe")
.highlights(search_term) // Highlights all "Hello" occurrencesSlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.
#Sensitive Information
// Financial data with toggle
h_flex()
.child(
Label::new("$9,182.50 USD")
.text_2xl()
.masked(self.is_masked)
)
.child(
Button::new("toggle-mask")
.ghost()
.icon(if self.is_masked { IconName::EyeOff } else { IconName::Eye })
.on_click(|this, _, _, _| {
this.is_masked = !this.is_masked;
})
)SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.
#Multi-language Support
// Supports Unicode text
Label::new("这是一个标签") // Chinese text
Label::new("こんにちは世界") // Japanese text
Label::new("🌍 Hello World 🚀") // EmojisSlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.
#Status Indicators
// Success status
Label::new("✓ Verified")
.text_color(cx.theme().success)
// Warning status
Label::new("⚠ Pending Review")
.text_color(cx.theme().warning)
// Error status
Label::new("✗ Failed")
.text_color(cx.theme().destructive)SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.
#Custom Layouts
// Flex layout with labels
h_flex()
.justify_between()
.child(Label::new("Total Amount"))
.child(Label::new("$1,234.56").font_semibold())
// Grid layout
v_flex()
.gap_2()
.child(Label::new("Name:").font_semibold())
.child(Label::new("John Doe"))
.child(Label::new("Email:").font_semibold())
.child(Label::new("john@example.com"))SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.
#API Reference
#Label
| Method | Description |
|---|---|
new(text) | Create a new label with text |
secondary(text) | Add secondary text (usually for optional/required indicators) |
masked(bool) | Show/hide text with bullet characters |
highlights(match) | Highlight matching text |
#HighlightsMatch
| Variant | Description |
|---|---|
Full(text) | Highlights all occurrences of the text |
Prefix(text) | Highlights only if text appears at the beginning |
| Method | Description |
|---|---|
as_str() | Get the search text as string |
is_prefix() | Check if this is a prefix match |
#Styling Methods (via Styled trait)
| Method | Description |
|---|---|
text_color(color) | Set text color |
text_size(size) | Set font size |
text_center() | Center align text |
text_right() | Right align text |
font_semibold() | Set font weight to semibold |
font_bold() | Set font weight to bold |
line_height(height) | Set line height |
text_xs() | Extra small text size |
text_sm() | Small text size |
text_base() | Base text size (default) |
text_lg() | Large text size |
text_xl() | Extra large text size |
text_2xl() | 2x large text size |
#Label
A form label. Mirrors GPUI Component's `Label`: optional required mark, muted secondary text, and sizes.
| Name | Kind | Type | Default |
|---|---|---|---|
text | in | string | |
required | in | bool | |
size | in | ControlSize | ControlSize.medium |