orbit/kit/utils.rs
1// Utility functions for OrbitKit
2
3/// Color utilities
4pub mod color {
5 /// Lighten a color by a percentage
6 pub fn lighten(color: &str, _amount: f32) -> String {
7 // For now, just a placeholder
8 // In a real implementation, this would lighten the color
9 color.to_string()
10 }
11
12 /// Darken a color by a percentage
13 pub fn darken(color: &str, _amount: f32) -> String {
14 // For now, just a placeholder
15 // In a real implementation, this would darken the color
16 color.to_string()
17 }
18
19 /// Convert RGB to HSL
20 pub fn rgb_to_hsl(_r: u8, _g: u8, _b: u8) -> (f32, f32, f32) {
21 // For now, just a placeholder
22 // In a real implementation, this would convert RGB to HSL
23 (0.0, 0.0, 0.0)
24 }
25
26 /// Convert HSL to RGB
27 pub fn hsl_to_rgb(_h: f32, _s: f32, _l: f32) -> (u8, u8, u8) {
28 // For now, just a placeholder
29 // In a real implementation, this would convert HSL to RGB
30 (0, 0, 0)
31 }
32}
33
34/// String utilities
35pub mod string {
36 /// Truncate a string to a maximum length
37 pub fn truncate(s: &str, max_length: usize) -> String {
38 if s.len() <= max_length {
39 s.to_string()
40 } else {
41 format!("{}...", &s[0..max_length - 3])
42 }
43 }
44
45 /// Capitalize the first letter of a string
46 pub fn capitalize(s: &str) -> String {
47 let mut chars = s.chars();
48 match chars.next() {
49 None => String::new(),
50 Some(first) => {
51 let first_upper = first.to_uppercase().to_string();
52 first_upper + chars.as_str()
53 }
54 }
55 }
56}
57
58/// Math utilities
59pub mod math {
60 /// Clamp a value between a minimum and maximum
61 pub fn clamp<T: PartialOrd>(value: T, min: T, max: T) -> T {
62 if value < min {
63 min
64 } else if value > max {
65 max
66 } else {
67 value
68 }
69 }
70
71 /// Linear interpolation between two values
72 pub fn lerp(a: f32, b: f32, t: f32) -> f32 {
73 a + (b - a) * t
74 }
75}