pub enum FontColorTransferFunction {
Off,
Gamma(f32),
TwoCoverageMinusCoverageSq,
}Expand description
How to convert font coverage values into alpha and color values.
epaint stores all glyphs in the font atlas as white (with varying opacity), so that egui can reuse the same glyph for different text colors (with a simple color multiplication in the shader).
Because of this simplification, we need to apply a non-linear ramp to the glyph colors before writing them into the font atlas, as a way to compensate.
This whole thing is less than rigorous.
It would be better to either render all text colors into the font atlas (which would require more atlas space, but would allow for more accurate rendering of colored text and emojis), or do the color compensation in the shader, based on the active text color.
When experimenting, use https://fonts.google.com/specimen/Ubuntu to compare to a ground truth.
See https://hikogui.org/2022/10/24/the-trouble-with-anti-aliasing.html for related analysis.
Variants§
Off
Use the raw RGBA values from the font rasterizer, without any conversion.
This is the required mode for colored emojis etc.
This mode looks good for black-on-white text, i.e. light mode.
Gamma(f32)
alpha = coverage^gamma.
Gamma=1 looks good for black-on-white text, i.e. light mode.
TwoCoverageMinusCoverageSq
alpha = 2 * coverage - coverage^2
This looks good for white-on-black text, i.e. dark mode.
Very similar to a gamma of 0.5, but produces sharper text. See https://www.desmos.com/calculator/w0ndf5blmn for a comparison to gamma=0.5.
Implementations§
Source§impl FontColorTransferFunction
impl FontColorTransferFunction
Sourcepub const LIGHT_MODE_DEFAULT: Self = Self::Off
pub const LIGHT_MODE_DEFAULT: Self = Self::Off
A good-looking default for light mode (black-on-white text).
Sourcepub const DARK_MODE_DEFAULT: Self = Self::TwoCoverageMinusCoverageSq
pub const DARK_MODE_DEFAULT: Self = Self::TwoCoverageMinusCoverageSq
A good-looking default for dark mode (white-on-black text).
Sourcepub fn to_atlas_color(self, input_color: Color32) -> Color32
pub fn to_atlas_color(self, input_color: Color32) -> Color32
How to convert a white color written by the font rasterizer into a color to be written into the font atlas.
Sourcepub fn alpha_from_coverage(self, coverage: f32) -> f32
pub fn alpha_from_coverage(self, coverage: f32) -> f32
Convert coverage to alpha.
pub fn color_from_coverage(self, coverage: f32) -> Color32
Trait Implementations§
Source§impl Clone for FontColorTransferFunction
impl Clone for FontColorTransferFunction
Source§fn clone(&self) -> FontColorTransferFunction
fn clone(&self) -> FontColorTransferFunction
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for FontColorTransferFunction
Source§impl Debug for FontColorTransferFunction
impl Debug for FontColorTransferFunction
Source§impl Default for FontColorTransferFunction
impl Default for FontColorTransferFunction
Source§fn default() -> FontColorTransferFunction
fn default() -> FontColorTransferFunction
Source§impl<'de> Deserialize<'de> for FontColorTransferFunction
impl<'de> Deserialize<'de> for FontColorTransferFunction
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for FontColorTransferFunction
Auto Trait Implementations§
impl Freeze for FontColorTransferFunction
impl RefUnwindSafe for FontColorTransferFunction
impl Send for FontColorTransferFunction
impl Sync for FontColorTransferFunction
impl Unpin for FontColorTransferFunction
impl UnsafeUnpin for FontColorTransferFunction
impl UnwindSafe for FontColorTransferFunction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more