Incular logoIncular
API ReferenceLayout Values

Color

Compact sRGBA8 color with linear, HSL, and HSV conversions.

use incular::prelude::*;

fn main() {
    let accent = Color::rgba(30, 32, 40, 255);
    println!("accent: {:?}", accent.to_linear_rgba());
    let back = Color::from_linear_rgba(accent.to_linear_rgba());
    println!("round-trip: {:?}", back == accent);
    println!("white: {:?}", Color::WHITE.to_hsl());
}

Swatches with a linear round-trip — copy, paste, and run:

use incular::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let accent = Color::rgba(30, 32, 40, 255);
    let back = Color::from_linear_rgba(accent.to_linear_rgba());
    let app = Application::new(move |_cx| {
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(
                Row::builder()
                    .spacing(8.0)
                    .children(Vec::<Widget>::from([
                        Container::new()
                                .color(Color::WHITE)
                                .width(80.0)
                                .height(80.0).into(),
                        Container::new()
                                .color(accent)
                                .width(80.0)
                                .height(80.0).into(),
                        Container::new()
                                .color(back)
                                .width(80.0)
                                .height(80.0).into(),
                    ]))
                    .build(),
            )
            .build()
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}
MemberKindNotes
TRANSPARENTConstantrgba(0,0,0,0)
WHITEConstantrgba(255,255,255,255)
BLACKConstantrgba(0,0,0,255)
rgba(r,g,b,a)Constructorconst fn, u8 channels
to_linear_rgbaConversionGamma-correct blending math
from_linear_rgbaConversionSanitizes NaN, clamps 0..=1
to_hsl / to_hsvConversionVia HslColor / HsvColor

Per-channel Lerp with clamped t. Used by Container, TextStyle, and Paint.

Related: Brush.