Repository navigation
Styling Materials
Blinc provides comprehensive styling options from simple colors to advanced GPU-accelerated material effects.
Colors are RGBA with values from 0.0 to 1.0:
// RGBA constructor
Color::rgba(0.2, 0.4, 0.8, 1.0) // Blue, fully opaque
Color::rgba(1.0, 0.0, 0.0, 0.5) // Red, 50% transparent
// From array (common pattern)
Color::from([0.2, 0.4, 0.8, 1.0])
// Predefined colors
Color::WHITE
Color::BLACK
Color::RED
Color::GREEN
Color::BLUE
Color::TRANSPARENTdiv()
.bg(Color::rgba(0.1, 0.1, 0.15, 1.0))
// From array shorthand
div().bg([0.1, 0.1, 0.15, 1.0])For gradients, use the .background() method with a Brush:
use blinc::core::{Brush, Gradient, GradientStop, Point};
div()
.w(200.0)
.h(100.0)
.background(Brush::Gradient(Gradient::linear_with_stops(
Point::new(0.0, 0.0), // Start point
Point::new(200.0, 0.0), // End point
vec![
GradientStop::new(0.0, Color::rgba(0.9, 0.2, 0.5, 1.0)),
GradientStop::new(0.5, Color::rgba(0.9, 0.5, 0.2, 1.0)),
GradientStop::new(1.0, Color::rgba(0.2, 0.8, 0.6, 1.0)),
],
)))div()
.rounded(8.0) // Uniform radius
.rounded_full() // Pill shape (50% of smallest dimension)
.rounded_corners(
16.0, // Top-left
16.0, // Top-right
8.0, // Bottom-right
8.0, // Bottom-left
)div()
.shadow_sm() // Small shadow
.shadow_md() // Medium shadow
.shadow_lg() // Large shadow
.shadow_xl() // Extra large shadowdiv().shadow_params(
2.0, // Offset X
4.0, // Offset Y
12.0, // Blur radius
Color::rgba(0.0, 0.0, 0.0, 0.3)
)An inset shadow draws inside the element, over its background, as CSS box-shadow: inset does.
use blinc::core::Shadow;
div()
.w(120.0)
.h(50.0)
.inset_shadow(Shadow::new(0.0, 2.0, 8.0, Color::rgba(0.0, 0.0, 0.0, 0.3)))
// The inner shadow of the theme
div().shadow_inner()div()
.opacity(0.5) // 50% opacity
.opaque() // opacity: 1.0
.translucent() // opacity: 0.5
.invisible() // opacity: 0.0Apply 2D transforms to any element:
div()
.translate(10.0, 20.0) // Move by (x, y)
.scale(1.5) // Uniform scale
.scale_xy(1.5, 0.8) // Non-uniform scale
.rotate(45.0_f32.to_radians()) // Rotate (radians)
.rotate_deg(45.0) // Rotate (degrees)For combined transforms:
use blinc::core::Transform;
div().transform(
Transform::translate(100.0, 50.0)
.then_scale(1.2, 1.2)
.then_rotate(0.1)
)Blinc includes GPU-accelerated material effects for modern, polished UIs.
Creates a frosted glass effect with background blur:
use blinc::core::Color;
use blinc::layout::prelude::*;
// Quick glass
div().glass();
// Customized glass
div().effect(
GlassMaterial::new()
.blur(20.0) // Blur radius, as in CSS blur()
.tint(Color::rgba(1.0, 1.0, 1.0, 0.1))
.saturation(1.2) // Color saturation
.brightness(1.0) // Brightness adjustment
.noise(0.03) // Frosted texture
.border(0.8) // Border highlight intensity
.aberration(0.4) // Colour fringes at the rim, 0 to 1
.bevel(1.0) // Rim width and strength; negative curves inward
);aberration and bevel shape the rim of liquid glass. GlassMaterial::simple()
has no such rim. GlassStyle has the same two methods, and CSS sets them with
glass-aberration, glass-bevel and glass-curvature. See
Liquid Glass Rim.
Glass shows what is painted behind it, text and SVGs included. A glass with a blur under 2 device pixels keeps full detail. Content that moves behind a glass through a motion binding does not show in it yet.
A window can move a glass without painting the page again. Use this for a lens that the pointer drags. Bind the position of the glass to a signal:
div()
.absolute()
.w(190.0)
.h(190.0)
.rounded(95.0)
.effect(GlassMaterial::new().blur(0.0))
.bind_transform_from(position, |(x, y)| Transform::translate(x, y))The window moves the glass in this way when all of these are true:
- The binding only translates the glass.
- The glass has no children.
- No ancestor of the glass fades, scales or rotates it, or adds an effect to it.
- The ancestors of the glass clip it to an area. In that area, nothing paints after the glass.
- Nothing under the glass in that area is another glass, a canvas, or content that a binding or an animation moves.
- No entry, exit, layout or CSS animation is running.
If one of these is not true, each move paints the page again. The result looks
the same, but it uses more CPU time and GPU memory. Put the lens in a container
with overflow_clip(), as the last child, to meet the rules about the area.
liquid_glass_demo in the examples crate shows a range of aberrations and a lens
that you can drag:
cargo run --release -p blinc_app_examples --features cn --example liquid_glass_demoGlass Presets:
GlassMaterial::ultra_thin() // Very subtle
GlassMaterial::thin() // Light blur
GlassMaterial::regular() // Standard (default)
GlassMaterial::thick() // Heavy blur
GlassMaterial::frosted() // Frosted window style
GlassMaterial::card() // Card-like appearanceUse the existing fluent element builders for grouped glass. Compatible native panels composite their material and children together before applying the panel's opacity and effects. Overlapping children therefore share the panel fade.
use blinc::layout::prelude::*;
let panel = div()
.w(280.0)
.p(16.0)
.glass()
.opacity(0.8)
.child(text("Outer panel"))
.child(
div()
.p(8.0)
.effect(GlassMaterial::simple().blur(12.0))
.child(text("Nested panel")),
);First-level panels use the prepared frame backdrop. A nested panel samples prior
paint within its enclosing glass isolation; content painted later is excluded.
The renderer derives nesting from the element tree. Applications do not set
GroupGlass.nested or construct GroupGlass commands.
Glass is also a brush. .background(GlassStyle) uses the same element grouping,
child ownership and automatic nesting as .effect(GlassMaterial). The material
form lowers to Brush::Glass when drawn; .glass() is its default shorthand.
use blinc::core::GlassStyle;
use blinc::layout::prelude::*;
let panel = div()
.w(280.0)
.p(16.0)
.background(GlassStyle::new().blur(12.0))
.opacity(0.8)
.child(text("Glass brush panel"));The forms can be mixed in one tree. An explicit glass material takes precedence
over a glass background on the same element. Element shadow and border-color
settings override those embedded in the brush. Element nesting comes from the
tree, rather than GlassStyle.depth; canvas draws can set that depth themselves.
Grouping requires a drawing context with glass and collected-content support.
Custom Flow shaders, portal boundaries and 3D owners do not have the same grouped
glass guarantees. The wet_glass_demo uses a custom Flow shader with
sample_scene(), a separate path from this native glass material.
Creates reflective metallic surfaces:
use blinc::core::MetallicMaterial;
div().material(Material::Metallic(
MetallicMaterial::new()
.color(Color::WHITE)
.roughness(0.3) // 0 = mirror, 1 = matte
.metallic(1.0) // Metal intensity
.reflection(0.5) // Reflection strength
))Metallic Presets:
MetallicMaterial::chrome() // Polished chrome
MetallicMaterial::brushed() // Brushed metal
MetallicMaterial::gold() // Gold finish
MetallicMaterial::silver() // Silver finish
MetallicMaterial::copper() // Copper finishdiv().glass() // Default glass material
div().metallic() // Default metallic material
div().chrome() // Chrome preset
div().gold() // Gold presetControl rendering order with layers:
use blinc::layout::RenderLayer;
div()
.layer(RenderLayer::Background) // Rendered first
.child(background_content())
div()
.layer(RenderLayer::Foreground) // Rendered on top
.child(overlay_content())Glass materials select the glass render layer automatically. Put the background and panel in the same scene:
use blinc::core::Color;
use blinc::layout::prelude::*;
stack()
.child(div().w(320.0).h(200.0).bg(Color::BLUE))
.child(
div()
.w(280.0)
.h(160.0)
.glass()
.child(text("Glass panel")),
);fn card() -> Div {
div()
.p(16.0)
.rounded(12.0)
.bg(Color::rgba(0.15, 0.15, 0.2, 1.0))
.shadow_md()
}fn glass_card() -> Div {
div()
.p(16.0)
.rounded(16.0)
.glass()
.shadow_lg()
}fn primary_button() -> Div {
div()
.px(4.0)
.py(2.0)
.rounded(8.0)
.bg(Color::rgba(0.3, 0.5, 0.9, 1.0))
}
fn secondary_button() -> Div {
div()
.px(4.0)
.py(2.0)
.rounded(8.0)
.bg(Color::rgba(0.2, 0.2, 0.25, 1.0))
}
fn ghost_button() -> Div {
div()
.px(4.0)
.py(2.0)
.rounded(8.0)
.bg(Color::TRANSPARENT)
}Use stateful::<S>() to create elements with automatic hover/press state transitions:
use blinc::layout::stateful::stateful;
fn hoverable_card() -> impl ElementBuilder {
stateful::<ButtonState>()
.p(16.0)
.rounded(12.0)
.on_state(|ctx| {
let bg = match ctx.state() {
ButtonState::Idle => Color::rgba(0.15, 0.15, 0.2, 1.0),
ButtonState::Hovered => Color::rgba(0.18, 0.18, 0.24, 1.0),
ButtonState::Pressed => Color::rgba(0.12, 0.12, 0.16, 1.0),
_ => Color::rgba(0.15, 0.15, 0.2, 1.0),
};
div().bg(bg)
})
.child(text("Hover me").color(Color::WHITE))
}Common colors for dark-themed UIs:
// Backgrounds
let bg_primary = Color::rgba(0.08, 0.08, 0.12, 1.0);
let bg_secondary = Color::rgba(0.12, 0.12, 0.16, 1.0);
let bg_tertiary = Color::rgba(0.16, 0.16, 0.2, 1.0);
// Surfaces
let surface = Color::rgba(0.15, 0.15, 0.2, 1.0);
let surface_hover = Color::rgba(0.18, 0.18, 0.24, 1.0);
// Text
let text_primary = Color::WHITE;
let text_secondary = Color::rgba(0.7, 0.7, 0.8, 1.0);
let text_muted = Color::rgba(0.5, 0.5, 0.6, 1.0);
// Accent
let accent = Color::rgba(0.4, 0.6, 1.0, 1.0);
let accent_hover = Color::rgba(0.5, 0.7, 1.0, 1.0);
// Status
let success = Color::rgba(0.2, 0.8, 0.4, 1.0);
let warning = Color::rgba(0.9, 0.7, 0.2, 1.0);
let error = Color::rgba(0.9, 0.3, 0.3, 1.0);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