Skip to content

Commit 0d28292

Browse files
v0.2.1 (#16)
* v0.2.1
1 parent c4f1d48 commit 0d28292

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+5529
-206
lines changed

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ux-primitives"
3-
version = "0.1.4"
3+
version = "0.2.1"
44
authors = ["Victor Dudochkin <dudochkin.victor@gmail.com>"]
55
readme = "README.md"
66
homepage = "https://angular-rust.github.io/ux-primitives"

Diff for: README.md

+58-14
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,70 @@
2727
[loc-badge]: https://img.shields.io/tokei/lines/github/angular-rust/ux-primitives?style=flat-square
2828
[loc-url]: https://github.com/angular-rust/ux-primitives
2929

30-
UX Primitives is a core graphic and color abstraction for Angular Rust.
30+
UX Primitives is a powerful library for working with color and graphics. It is one of the main building blocks of the Angular Rust framework. This library is well organized and easy to use.
3131

32-
**Angular Rust** is a high productivity, `platform-agnostic` frontend framework for the [Rust language](https://www.rust-lang.org/). It now supports desktop and web development. Angular Rust currently uses Clutter for desktop development and WebAssembly for web development. We are planning to add support for mobile development.
32+
## Quick Start
33+
34+
Add UX primitives to your project using Cargo-edit or by editing the Cargo.toml file:
35+
36+
cargo add ux-primitives
37+
38+
### Basic usage
39+
40+
```rust
41+
use primitives::prelude::*;
42+
43+
use primitives::foundation::{colorschemes::Tetrad, colorspace::HslColor};
44+
45+
fn main() {
46+
// Get Palette Color
47+
let base = color::TEAL_9;
48+
49+
println!("Base color {}", base.to_hex_string());
50+
51+
println!("Lighten {}", base.lighten(10.0).to_hex_string());
52+
53+
println!("Darken {}", base.darken(10.0).to_hex_string());
54+
55+
println!("Hue Adjusted {}", base.adjust_hue(90.).to_hex_string());
56+
57+
println!("Complement {}", base.complement().to_hex_string());
3358

34-
![Angular Rust structure](https://dudochkin-victor.github.io/assets/angular-rust/structure.svg)
59+
println!("Inverted {}", base.invert().to_hex_string());
60+
61+
println!("Saturated {}", base.saturate(50.).to_hex_string());
62+
63+
println!("Desaturated {}", base.desaturate(50.).to_hex_string());
64+
65+
println!("Grayscale {}", base.grayscale().to_hex_string());
66+
67+
let hsl: HslColor = base.into();
68+
69+
println!("{} {}", base, hsl);
70+
71+
// Generate color scheme
72+
let scheme = Tetrad::new(base);
73+
// You can adjust color scheme parameters before get colors
74+
println!();
75+
76+
for idx in 0..scheme.num_of_colors() {
77+
match scheme.get_color(idx) {
78+
Some(col) => println!("Color: {}", col.to_hex_string()),
79+
None => println!("No color")
80+
}
81+
}
82+
}
83+
```
3584

3685
## Features
3786

38-
- [x] Graphic abstraction for cairo and web canvas, implemented in [UX Animate](https://github.com/angular-rust/ux-animate)
39-
- [x] Most used color spaces: RGB, RGBA, HSL, HSV, LAB, CMY, CMYK
87+
- [x] Graphic abstraction for native and web canvas implemented in [UX Animate](https://github.com/angular-rust/ux-animate)
88+
- [x] The most commonly used color spaces: RGB, RGBA, HSL, HSV, LAB, CMY, CMYK.
4089
- [x] Color conversion: RGB to HSL, etc.
41-
- [x] Support for color quantization to make the color closer to the palette
42-
- [x] Palette `Open Color`
43-
90+
- [x] Support for color quantization to bring the color closer to the palette.
91+
- [x] Palette [Open Color](https://github.com/yeun/open-color) (4.5 thousand stars)
92+
- [x] Generation of color scheme according to [color theory](http://en.wikipedia.org/wiki/Color_theory).
93+
- [x] Basic traits for interactive applications (WIP).
4494

4595
## Color scheme for UI design
4696

@@ -55,12 +105,6 @@ UX Primitives contain powerfull palette for easy of use and more professional lo
55105

56106
![available colors](https://dudochkin-victor.github.io/assets/ux-primitives/open-color.svg)
57107

58-
## Quick Start
59-
60-
Install UX Primitives:
61-
62-
cargo add ux-primitives
63-
64108
## Learn More
65109

66110
* [Manual, Docs, etc](https://angular-rust.github.io/)

Diff for: src/colorspace/mod.rs

-61
This file was deleted.

Diff for: src/angle.rs renamed to src/foundation/angle.rs

File renamed without changes.

Diff for: src/box2d.rs renamed to src/foundation/box2d.rs

File renamed without changes.

Diff for: src/box3d.rs renamed to src/foundation/box3d.rs

File renamed without changes.

Diff for: src/foundation/colorschemes/analogous.rs

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#![allow(unused_imports)]
2+
use crate::foundation::colorspace::{Color, HsvColor};
3+
4+
use super::ryb_rotate;
5+
6+
/// The analog colors are those colors which lie on either side of any given color.
7+
///
8+
/// Often these are color schemes found in nature.
9+
/// An application that makes use of analogous colors usually feels harmonious.
10+
/// The secondary color, as described above, can often be an analogous color.
11+
#[derive(Debug, Clone)]
12+
pub struct Analogous {
13+
angle: f32,
14+
contrast: f32,
15+
16+
colors: Vec<Color>,
17+
primary_color: Color,
18+
}
19+
20+
impl Analogous {
21+
/// Generate Analogous scheme with your color, 10 degree angle and 25 percent of contrast
22+
pub fn new(primary: Color) -> Self {
23+
Self::with_parameters(primary, Some(10.0), Some(25.0))
24+
}
25+
26+
pub fn with_parameters(primary: Color, angle: Option<f32>, contrast: Option<f32>) -> Self {
27+
let mut instance = Self {
28+
colors: Vec::new(),
29+
primary_color: primary,
30+
angle: angle.unwrap_or(10.0),
31+
contrast: contrast.unwrap_or(25.0),
32+
};
33+
instance.generate();
34+
35+
instance
36+
}
37+
38+
fn generate(&mut self) {
39+
self.colors = vec![self.primary_color];
40+
let primary_hsb: HsvColor = self.primary_color.into();
41+
42+
const ARRAY: [[f32; 2]; 4] = [[1.0, 2.2], [2.0, 1.0], [-1.0, -0.5], [-2.0, 1.0]];
43+
44+
for idx in 0..ARRAY.len() {
45+
let one = ARRAY[idx][0];
46+
let two = ARRAY[idx][1];
47+
48+
// set hue
49+
let mut new_hsb: HsvColor = ryb_rotate(primary_hsb.into(), self.angle * one);
50+
51+
// value is brightness
52+
let t: f32 = 0.44 - two * 0.1;
53+
if primary_hsb.value - self.contrast * two < t {
54+
new_hsb.value = t * 100.0;
55+
} else {
56+
new_hsb.value = primary_hsb.value - self.contrast * two;
57+
}
58+
59+
// set saturation
60+
new_hsb.saturation -= 5.0;
61+
62+
self.colors.push(new_hsb.into());
63+
}
64+
}
65+
66+
pub fn angle(&self) -> f32 {
67+
self.angle
68+
}
69+
70+
pub fn set_angle(&mut self, value: f32) {
71+
self.angle = value;
72+
self.generate();
73+
}
74+
75+
pub fn contrast(&self) -> f32 {
76+
self.contrast
77+
}
78+
79+
pub fn set_contrast(&mut self, value: f32) {
80+
self.contrast = value;
81+
self.generate();
82+
}
83+
84+
pub fn num_of_colors(&self) -> usize {
85+
self.colors.len()
86+
}
87+
88+
pub fn get_color(&self, index: usize) -> Option<Color> {
89+
self.colors.get(index).copied()
90+
}
91+
92+
pub fn primary_color(&self) -> Color {
93+
self.primary_color
94+
}
95+
96+
pub fn set_primary_color(&mut self, value: Color) {
97+
self.primary_color = value;
98+
self.generate();
99+
}
100+
}

Diff for: src/foundation/colorschemes/complementary.rs

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#![allow(unused_imports)]
2+
use crate::foundation::colorspace::{Color, HsvColor};
3+
4+
use super::ryb_rotate;
5+
6+
/// The complementary colors are the colors which are directly opposite from one another on the color wheel.
7+
///
8+
/// Complementary colors are contrasting and stand out against each other.
9+
/// Often it is a good idea to use a complementary color as the highlight color, as described above.
10+
#[derive(Debug, Clone)]
11+
pub struct Complementary {
12+
colors: Vec<Color>,
13+
primary_color: Color,
14+
}
15+
16+
impl Complementary {
17+
pub fn new(primary: Color) -> Self {
18+
let mut instance = Self {
19+
colors: Vec::new(),
20+
primary_color: primary,
21+
};
22+
instance.generate();
23+
24+
instance
25+
}
26+
27+
fn generate(&mut self) {
28+
self.colors = vec![self.primary_color];
29+
30+
let primary_hsb: HsvColor = self.primary_color.into();
31+
32+
let mut contrasting: HsvColor = primary_hsb;
33+
34+
// value is brightness
35+
if primary_hsb.value > 40.0 {
36+
contrasting.value = 10.0 + primary_hsb.value * 0.25;
37+
} else {
38+
contrasting.value = 100.0 - primary_hsb.value * 0.25;
39+
}
40+
self.colors.push(contrasting.into());
41+
42+
// supporting
43+
let mut supporting: HsvColor = primary_hsb;
44+
45+
supporting.value = 30.0 + primary_hsb.value;
46+
supporting.saturation = 10.0 + primary_hsb.saturation * 0.3;
47+
self.colors.push(supporting.into());
48+
49+
// complement
50+
let complement: HsvColor = ryb_rotate(self.primary_color, 180.0);
51+
self.colors.push(complement.into());
52+
53+
// contrasting complement
54+
let mut contrasting_complement: HsvColor = complement.clone();
55+
56+
if complement.value > 30.0 {
57+
contrasting_complement.value = 10.0 + complement.value * 0.25;
58+
} else {
59+
contrasting_complement.value = 100.0 - complement.value * 0.25;
60+
}
61+
self.colors.push(contrasting_complement.into());
62+
63+
// supporting complement
64+
let mut supporting_complement: HsvColor = complement;
65+
66+
supporting_complement.value = 30.0 + complement.value;
67+
supporting_complement.saturation = 10.0 + complement.saturation * 0.3;
68+
self.colors.push(supporting_complement.into());
69+
}
70+
71+
pub fn num_of_colors(&self) -> usize {
72+
self.colors.len()
73+
}
74+
75+
pub fn get_color(&self, index: usize) -> Option<Color> {
76+
self.colors.get(index).copied()
77+
}
78+
79+
pub fn primary_color(&self) -> Color {
80+
self.primary_color
81+
}
82+
83+
pub fn set_primary_color(&mut self, val: Color) {
84+
self.primary_color = val;
85+
self.generate();
86+
}
87+
}

0 commit comments

Comments
 (0)