Repository navigation
Button
Buttons trigger actions.
use blinc::cn::prelude::*;
button("Click me")
.on_click(|_| println!("Clicked!"))The label takes a string or a signal. When the label changes, it is patched in place.
// Primary (default) - main actions
button("Save").variant(ButtonVariant::Primary)
// Secondary - alternative actions
button("Cancel").variant(ButtonVariant::Secondary)
// Destructive - dangerous actions
button("Delete").variant(ButtonVariant::Destructive)
// Outline - bordered
button("Edit").variant(ButtonVariant::Outline)
// Ghost - minimal
button("More").variant(ButtonVariant::Ghost)
// Link - looks like a link
button("Learn more").variant(ButtonVariant::Link)button("Small").size(ButtonSize::Small)
button("Default").size(ButtonSize::Medium)
button("Large").size(ButtonSize::Large)
// Icon only (square)
button("").size(ButtonSize::Icon).icon(icons::SETTINGS)
// A size of your own: width, height
button("Wide").size(ButtonSize::Custom(160.0, 48.0))use blinc::icons::icons;
button("Settings").icon(icons::SETTINGS)
// After the label
button("Next")
.icon(icons::ARROW_RIGHT)
.icon_position(IconPosition::End)disabled takes a bool or a signal, so a button can follow a state:
button("Disabled").disabled(true)
button("Save").disabled(&is_saving)A disabled button does not respond to clicks, and it has the disabled look.
A stylesheet defines the look of a button. The .cn-button rules of
CN_STYLES set its fill, text color, border and shadow. They also set how these
change on hover, on press and while the button is disabled. The rules include a
transition, so a button changes smoothly between states. Each variant and size
has a class that your own rules can use:
| Class | Matches |
|---|---|
.cn-button |
every cn button |
.cn-button--primary, --secondary, --destructive, --outline, --ghost, --link
|
the variant |
.cn-button--sm, --md, --lg, --icon, --custom
|
the size |
/* A brand colour for primary buttons, eased on hover. Your rules win over
cn's whatever their specificity. */
.cn-button--primary { background: #6d28d9; }
.cn-button--primary:hover:not(:disabled) { background: #7c3aed; }
.cn-button--primary:active:not(:disabled) { background: #5b21b6; }
/* One button of your own */
.danger { background: #c0392b; transition: background-color 150ms ease; }
.danger:disabled { background: #555; color: #999; }button("Delete").class("danger")The :hover:not(:disabled) selector keeps a rule off a disabled button.
:active matches while the pointer is down on the button or on anything inside
it, as on the web. The text and icons inside the button take its color. A rule
that changes this color also changes them.
.color(..) on the builder fixes the text color in every state. A fluent value
(a value that you set with a builder method) overrides the cn rules, as an
inline style does on the web.
div()
.flex_row()
.gap(2.0)
.child(button("Save").variant(ButtonVariant::Primary))
.child(button("Cancel").variant(ButtonVariant::Outline))gap takes units of 4px, so gap(2.0) is 8px.
button("")
.size(ButtonSize::Icon)
.variant(ButtonVariant::Ghost)
.icon(icons::X)
.on_click(|_| close_dialog())let saving = ctx.use_signal(false);
button("Save")
.disabled(saving)
.on_click(move |_| saving.set(true))| Method | Type | Default | Description |
|---|---|---|---|
variant |
ButtonVariant |
Primary |
Visual style |
size |
ButtonSize |
Medium |
Small, Medium, Large, Icon or Custom(w, h)
|
disabled |
bool or signal |
false |
Disables interaction |
icon |
&str |
none | An icon from blinc::icons::icons
|
icon_position |
IconPosition |
Start |
Start or End
|
icon_size |
f32 |
label size + 2 | Icon size in px |
color |
Color |
by variant | Text color in every state |
on_click |
Fn(&EventContext) |
none | Called on a click |
class, id
|
&str |
none | Selectors for your own rules |
Getting 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