Skip to content

Commit

Permalink
Rebased PR to advanced-text
Browse files Browse the repository at this point in the history
  • Loading branch information
bungoboingo committed Mar 22, 2023
1 parent 403019e commit 2adaf3f
Show file tree
Hide file tree
Showing 45 changed files with 845 additions and 1,951 deletions.
1 change: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ repository = "https://github.com/iced-rs/iced"

[dependencies]
bitflags = "1.2"
thiserror = "1"
twox-hash = { version = "1.5", default-features = false }

[dependencies.palette]
Expand Down
18 changes: 18 additions & 0 deletions core/src/angle.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::{Point, Rectangle, Vector};
use std::f32::consts::PI;

#[derive(Debug, Copy, Clone, PartialEq)]
Expand All @@ -13,3 +14,20 @@ impl From<Degrees> for Radians {
Radians(degrees.0 * PI / 180.0)
}
}

impl Radians {
/// Calculates the line in which the [`Angle`] intercepts the `bounds`.
pub fn to_distance(&self, bounds: &Rectangle) -> (Point, Point) {
let v1 = Vector::new(f32::cos(self.0), f32::sin(self.0));

let distance_to_rect = f32::min(
f32::abs((bounds.y - bounds.center().y) / v1.y),
f32::abs(((bounds.x + bounds.width) - bounds.center().x) / v1.x),
);

let start = bounds.center() + v1 * distance_to_rect;
let end = bounds.center() - v1 * distance_to_rect;

(start, end)
}
}
58 changes: 2 additions & 56 deletions core/src/gradient.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! For creating a Gradient.
pub use linear::Linear;

use crate::{Color, Radians, Rectangle, Vector};
use crate::{Color, Radians};

#[derive(Debug, Clone, Copy, PartialEq)]
/// A fill which transitions colors progressively along a direction, either linearly, radially (TBD),
Expand All @@ -23,7 +23,7 @@ impl Gradient {
}

/// Adjust the opacity of the gradient by a multiplier applied to each color stop.
pub fn transparentize(mut self, alpha_multiplier: f32) -> Self {
pub fn mul_alpha(mut self, alpha_multiplier: f32) -> Self {
match &mut self {
Gradient::Linear(linear) => {
for stop in &mut linear.color_stops {
Expand All @@ -34,60 +34,6 @@ impl Gradient {

self
}

/// Packs the [`Gradient`] into a buffer for use in shader code.
pub fn pack(&self, bounds: Rectangle) -> [f32; 44] {
match self {
Gradient::Linear(linear) => {
let mut pack: [f32; 44] = [0.0; 44];
let mut offsets: [f32; 8] = [2.0; 8];

for (index, stop) in
linear.color_stops.iter().enumerate().take(8)
{
let [r, g, b, a] = stop.color.into_linear();

pack[(index * 4)] = r;
pack[(index * 4) + 1] = g;
pack[(index * 4) + 2] = b;
pack[(index * 4) + 3] = a;

offsets[index] = stop.offset;
}

pack[32] = offsets[0];
pack[33] = offsets[1];
pack[34] = offsets[2];
pack[35] = offsets[3];
pack[36] = offsets[4];
pack[37] = offsets[5];
pack[38] = offsets[6];
pack[39] = offsets[7];

let v1 = Vector::new(
f32::cos(linear.angle.0),
f32::sin(linear.angle.0),
);

let distance_to_rect = f32::min(
f32::abs((bounds.y - bounds.center().y) / v1.y),
f32::abs(
((bounds.x + bounds.width) - bounds.center().x) / v1.x,
),
);

let start = bounds.center() + v1 * distance_to_rect;
let end = bounds.center() - v1 * distance_to_rect;

pack[40] = start.x;
pack[41] = start.y;
pack[42] = end.x;
pack[43] = end.y;

pack
}
}
}
}

#[derive(Debug, Default, Clone, Copy, PartialEq)]
Expand Down
Empty file removed core/src/gradient/linear.rs
Empty file.
Empty file removed examples/modern_art/src/main.rs
Empty file.
6 changes: 4 additions & 2 deletions examples/tour/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use iced::widget::{
scrollable, slider, text, text_input, toggler, vertical_space,
};
use iced::widget::{Button, Column, Container, Slider};
use iced::{alignment, widget, Degrees, Gradient, Radians, Theme};
use iced::{Color, Element, Length, Renderer, Sandbox, Settings};
use iced::{
alignment, widget, Color, Degrees, Element, Gradient, Length, Radians,
Renderer, Sandbox, Settings, Theme,
};

pub fn main() -> iced::Result {
env_logger::init();
Expand Down
Empty file removed glow/src/program.rs
Empty file.
Empty file removed glow/src/quad/compatibility.rs
Empty file.
Empty file removed glow/src/quad/core.rs
Empty file.
158 changes: 0 additions & 158 deletions glow/src/shader/quad/compatibility/gradient.frag

This file was deleted.

72 changes: 0 additions & 72 deletions glow/src/shader/quad/compatibility/gradient.vert

This file was deleted.

Loading

0 comments on commit 2adaf3f

Please sign in to comment.