Skip to main content

densa_core/
lib.rs

1//! Primitive types shared by every densa crate.
2//!
3//! Dependency-free on purpose: text layout, rendering and application code all agree on
4//! these types without depending on each other.
5//!
6//! ```
7//! use densa_core::{Color, Point, Rect};
8//!
9//! // x, y, width, height. Stored as edges: neighbours built from the same edge value
10//! // (`Rect::from_edges`, or `translate`) tile exactly.
11//! let cell = Rect::new(10.0, 20.0, 100.0, 18.0);
12//! assert!(cell.contains(Point::new(10.0, 20.0)));
13//! assert!(!cell.contains(Point::new(110.0, 20.0)), "the right edge is outside");
14//! assert_eq!(cell.intersect(Rect::new(0.0, 0.0, 50.0, 50.0)).width(), 40.0);
15//!
16//! // Colors are linear RGB; `srgb` reads the hex code a design tool gives.
17//! let accent = Color::srgb(0x3B82F6);
18//! assert_eq!(accent.to_srgb_hex(), 0x3B82F6);
19//! let faint = accent.with_alpha(0.25);
20//! assert_eq!(faint.a, 0.25);
21//! ```
22
23mod color;
24mod geometry;
25
26pub use color::Color;
27pub use geometry::{Point, Rect, Size};