ColorGenerator

Struct ColorGenerator 

Source
pub struct ColorGenerator { /* private fields */ }
Expand description

Automatic color generator for creating visually distinct label colors.

ColorGenerator produces a sequence of pseudo-random colors that are perceptually distinct and readable. It’s useful for assigning colors to multiple labels automatically.

§Examples

use musubi::{Report, ColorGenerator, Level};

let mut cg = ColorGenerator::new();

Report::new()
    // ...
    .with_label(0..3)
    .with_color(&cg.next_color())  // First color
    .with_label(4..5)
    .with_color(&cg.next_color())  // Second color (different)
    // ...

Implementations§

Source§

impl ColorGenerator

Source

pub fn new() -> Self

Create a new color generator with default brightness.

Source

pub fn new_with_brightness(brightness: f32) -> Self

Create a new color generator with the specified brightness.

Source

pub fn next_color(&mut self) -> GenColor

Generate the next color in the sequence.

Each call returns a different color code that is visually distinct from previous colors. The sequence is deterministic based on the initial state.

§Examples
use musubi::ColorGenerator;

let mut cg = ColorGenerator::new();
let color1 = cg.next_color();
let color2 = cg.next_color();  // Different from color1
let color3 = cg.next_color();  // Different from color1 and color2

Trait Implementations§

Source§

impl Default for ColorGenerator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.