Skip to content

Commit c4f1d48

Browse files
Merge Develop
2 parents d0631eb + 4ff9c3a commit c4f1d48

Some content is hidden

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

53 files changed

+7039
-1473
lines changed

Cargo.toml

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

2121
[features]
22-
canvas = ["euclid", "lyon_geom", "lyon_path"]
23-
geom = ["euclid", "lyon_geom", "lyon_path"]
2422
color_from_css = []
2523
color_quantization = []
2624
experimental = []
2725

2826
[dependencies]
2927
intmap = "0.7"
30-
lyon_geom = { version = "0.17", optional = true }
31-
lyon_path = { version = "0.17", optional = true }
32-
euclid = { version = "0.22", optional = true }
3328
lazy_static = "1.4.0"
3429
bytes = "1.0"
30+
num-traits = "0.2.14"
31+
# cgmath = "0.18"
3532

3633
[dev-dependencies]
3734
libmath = "0.2.1"

Makefile

-4
This file was deleted.

Makefile.toml

-5
This file was deleted.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
UX Primitives is a core graphic and color abstraction for Angular Rust.
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 GTK for desktop development and WebAssembly for web development. We are planning to add support for mobile development.
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.
3333

3434
![Angular Rust structure](https://dudochkin-victor.github.io/assets/angular-rust/structure.svg)
3535

src/angle.rs

Whitespace-only changes.

src/box2d.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use super::Point;
2+
3+
/// A 2d axis aligned rectangle represented by its minimum and maximum coordinates.
4+
///
5+
/// # Representation
6+
///
7+
/// This struct is similar to [`Rect`], but stores rectangle as two endpoints
8+
/// instead of origin point and size. Such representation has several advantages over
9+
/// [`Rect`] representation:
10+
/// - Several operations are more efficient with `Box2D`, including [`intersection`],
11+
/// [`union`], and point-in-rect.
12+
/// - The representation is less susceptible to overflow. With [`Rect`], computation
13+
/// of second point can overflow for a large range of values of origin and size.
14+
/// However, with `Box2D`, computation of [`size`] cannot overflow if the coordinates
15+
/// are signed and the resulting size is unsigned.
16+
///
17+
/// A known disadvantage of `Box2D` is that translating the rectangle requires translating
18+
/// both points, whereas translating [`Rect`] only requires translating one point.
19+
///
20+
/// # Empty box
21+
///
22+
/// A box is considered empty (see [`is_empty`]) if any of the following is true:
23+
/// - it's area is empty,
24+
/// - it's area is negative (`min.x > max.x` or `min.y > max.y`),
25+
/// - it contains NaNs.
26+
///
27+
/// [`Rect`]: struct.Rect.html
28+
/// [`intersection`]: #method.intersection
29+
/// [`is_empty`]: #method.is_empty
30+
/// [`union`]: #method.union
31+
/// [`size`]: #method.size
32+
#[repr(C)]
33+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
34+
#[cfg_attr(
35+
feature = "serde",
36+
serde(bound(serialize = "T: Serialize", deserialize = "T: Deserialize<'de>"))
37+
)]
38+
pub struct Box2D<T> {
39+
pub min: Point<T>,
40+
pub max: Point<T>,
41+
}

src/box3d.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use crate::Point3D;
2+
3+
/// An axis aligned 3D box represented by its minimum and maximum coordinates.
4+
#[repr(C)]
5+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6+
#[cfg_attr(
7+
feature = "serde",
8+
serde(bound(serialize = "T: Serialize", deserialize = "T: Deserialize<'de>"))
9+
)]
10+
pub struct Box3D<T> {
11+
pub min: Point3D<T>,
12+
pub max: Point3D<T>,
13+
}

src/canvas/mod.rs renamed to src/canvas.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
#![cfg(feature = "canvas")]
2-
#![allow(unused_imports)]
31
#![allow(clippy::too_many_arguments)]
42

5-
use crate::{BaseLine, Color, TextAlign, TextStyle, TextWeight};
3+
use crate::{colorspace::Color, BaseLine, Gradient, TextAlign, FontStyle, FontWeight};
64

7-
mod style;
8-
pub use style::*;
9-
10-
mod image;
11-
pub use image::*;
12-
13-
mod direction;
14-
pub use direction::*;
5+
#[derive(Copy, Clone, Debug)]
6+
pub enum Direction {
7+
Ltr,
8+
Rtl,
9+
Inherit,
10+
}
1511

16-
mod text_metrics;
17-
pub use text_metrics::*;
12+
#[derive(Copy, Clone, Debug)]
13+
pub struct TextMetrics {
14+
pub width: f64,
15+
pub height: f64,
16+
}
1817

1918
#[derive(Clone, Copy, Debug)]
2019
pub enum LineCap {
@@ -57,7 +56,8 @@ impl Default for PatternExtend {
5756
}
5857
}
5958

60-
pub trait CanvasContext<P> {
59+
pub trait CanvasContext {
60+
type Pattern;
6161
// /// Get current global transformation matrix
6262
// fn get_current_transform(&self) -> Matrix<f64>;
6363

@@ -77,7 +77,7 @@ pub trait CanvasContext<P> {
7777
fn set_fill_gradient(&self, value: &Gradient);
7878

7979
/// Set fill pattern
80-
fn set_fill_pattern(&self, value: &P);
80+
fn set_fill_pattern(&self, value: &Self::Pattern);
8181

8282
/// Get filter
8383
fn get_filter(&self) -> String;
@@ -89,7 +89,7 @@ pub trait CanvasContext<P> {
8989
fn get_font(&self) -> String;
9090

9191
/// Set direction
92-
fn set_font(&self, family: &str, style: TextStyle, weight: TextWeight, size: f64);
92+
fn set_font(&self, family: &str, style: FontStyle, weight: FontWeight, size: f64);
9393

9494
/// Get global alpha
9595
fn get_global_alpha(&self) -> f64;
@@ -177,7 +177,7 @@ pub trait CanvasContext<P> {
177177
fn set_stroke_gradient(&self, value: &Gradient);
178178

179179
/// Set stroke pattern
180-
fn set_stroke_pattern(&self, value: &P);
180+
fn set_stroke_pattern(&self, value: &Self::Pattern);
181181

182182
/// Get text align
183183
fn get_text_align(&self) -> TextAlign;
@@ -322,7 +322,7 @@ pub trait CanvasContext<P> {
322322
// fn scrollPathIntoView(path: Path2D); // TODO:
323323

324324
/// Set line dash
325-
fn set_line_dash(&self, dash: Vec<f64>);
325+
fn set_line_dash(&self, dash: &[f64]);
326326

327327
/// Set transform matrix
328328
fn set_transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64);

src/canvas/direction.rs

-6
This file was deleted.

src/canvas/text_metrics.rs

-5
This file was deleted.

0 commit comments

Comments
 (0)