Added ability to define colors at UV coordinates along a path (#4353)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR. * Remember to run `cargo fmt` and `cargo cranky`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> I had to make a couple types not Copy because closures, but it should'nt be a massive deal. I tried my best to make the API change as non breaking as possible. Anywhere a PathStroke is used, you can just use a normal Stroke instead. As mentioned above, the bezier paths couldn't be copy anymore, but IMO that's a minor caveat. --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
co-authored by
Emil Ernerfeldt
parent
ff8cfc2aa0
commit
2ce82cce21
@@ -7,7 +7,7 @@ use crate::{
|
||||
};
|
||||
use epaint::{
|
||||
text::{Fonts, Galley, LayoutJob},
|
||||
CircleShape, ClippedShape, RectShape, Rounding, Shape, Stroke,
|
||||
CircleShape, ClippedShape, PathStroke, RectShape, Rounding, Shape, Stroke,
|
||||
};
|
||||
|
||||
/// Helper to paint shapes and text to a specific region on a specific layer.
|
||||
@@ -280,7 +280,7 @@ impl Painter {
|
||||
/// # Paint different primitives
|
||||
impl Painter {
|
||||
/// Paints a line from the first point to the second.
|
||||
pub fn line_segment(&self, points: [Pos2; 2], stroke: impl Into<Stroke>) -> ShapeIdx {
|
||||
pub fn line_segment(&self, points: [Pos2; 2], stroke: impl Into<PathStroke>) -> ShapeIdx {
|
||||
self.add(Shape::LineSegment {
|
||||
points,
|
||||
stroke: stroke.into(),
|
||||
@@ -288,13 +288,13 @@ impl Painter {
|
||||
}
|
||||
|
||||
/// Paints a horizontal line.
|
||||
pub fn hline(&self, x: impl Into<Rangef>, y: f32, stroke: impl Into<Stroke>) -> ShapeIdx {
|
||||
self.add(Shape::hline(x, y, stroke))
|
||||
pub fn hline(&self, x: impl Into<Rangef>, y: f32, stroke: impl Into<PathStroke>) -> ShapeIdx {
|
||||
self.add(Shape::hline(x, y, stroke.into()))
|
||||
}
|
||||
|
||||
/// Paints a vertical line.
|
||||
pub fn vline(&self, x: f32, y: impl Into<Rangef>, stroke: impl Into<Stroke>) -> ShapeIdx {
|
||||
self.add(Shape::vline(x, y, stroke))
|
||||
pub fn vline(&self, x: f32, y: impl Into<Rangef>, stroke: impl Into<PathStroke>) -> ShapeIdx {
|
||||
self.add(Shape::vline(x, y, stroke.into()))
|
||||
}
|
||||
|
||||
pub fn circle(
|
||||
@@ -513,7 +513,7 @@ impl Painter {
|
||||
}
|
||||
|
||||
fn tint_shape_towards(shape: &mut Shape, target: Color32) {
|
||||
epaint::shape_transform::adjust_colors(shape, &|color| {
|
||||
epaint::shape_transform::adjust_colors(shape, move |color| {
|
||||
if *color != Color32::PLACEHOLDER {
|
||||
*color = crate::ecolor::tint_color_towards(*color, target);
|
||||
}
|
||||
@@ -521,7 +521,7 @@ fn tint_shape_towards(shape: &mut Shape, target: Color32) {
|
||||
}
|
||||
|
||||
fn multiply_opacity(shape: &mut Shape, opacity: f32) {
|
||||
epaint::shape_transform::adjust_colors(shape, &|color| {
|
||||
epaint::shape_transform::adjust_colors(shape, move |color| {
|
||||
if *color != Color32::PLACEHOLDER {
|
||||
*color = color.gamma_multiply(opacity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user