mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
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:
48
crates/epaint/src/color.rs
Normal file
48
crates/epaint/src/color.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use std::{fmt::Debug, sync::Arc};
|
||||
|
||||
use ecolor::Color32;
|
||||
use emath::{Pos2, Rect};
|
||||
|
||||
/// How paths will be colored.
|
||||
#[derive(Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
pub enum ColorMode {
|
||||
/// The entire path is one solid color, this is the default.
|
||||
Solid(Color32),
|
||||
|
||||
/// Provide a callback which takes in the path's bounding box and a position and converts it to a color.
|
||||
/// When used with a path, the bounding box will have a margin of [`TessellationOptions::feathering_size_in_pixels`](`crate::tessellator::TessellationOptions::feathering_size_in_pixels`)
|
||||
///
|
||||
/// **This cannot be serialized**
|
||||
#[cfg_attr(feature = "serde", serde(skip))]
|
||||
UV(Arc<dyn Fn(Rect, Pos2) -> Color32 + Send + Sync>),
|
||||
}
|
||||
|
||||
impl Default for ColorMode {
|
||||
fn default() -> Self {
|
||||
Self::Solid(Color32::TRANSPARENT)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for ColorMode {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Solid(arg0) => f.debug_tuple("Solid").field(arg0).finish(),
|
||||
Self::UV(_arg0) => f.debug_tuple("UV").field(&"<closure>").finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for ColorMode {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(Self::Solid(l0), Self::Solid(r0)) => l0 == r0,
|
||||
(Self::UV(_l0), Self::UV(_r0)) => false,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ColorMode {
|
||||
pub const TRANSPARENT: Self = Self::Solid(Color32::TRANSPARENT);
|
||||
}
|
||||
Reference in New Issue
Block a user