mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 22:54:36 +00:00
Rename translucent to transparentize and mixed to mix
This commit is contained in:
parent
64ad1ce357
commit
4845241ebf
13 changed files with 64 additions and 64 deletions
|
@ -203,9 +203,9 @@ fn gen_corelib(
|
|||
"Point",
|
||||
"slint_color_brighter",
|
||||
"slint_color_darker",
|
||||
"slint_color_translucent",
|
||||
"slint_color_transparentize",
|
||||
"slint_color_opaque",
|
||||
"slint_color_mixed",
|
||||
"slint_color_mix",
|
||||
"slint_color_with_alpha",
|
||||
"slint_image_size",
|
||||
"slint_image_path",
|
||||
|
@ -294,9 +294,9 @@ fn gen_corelib(
|
|||
),
|
||||
(
|
||||
vec!["Color", "slint_color_brighter", "slint_color_darker",
|
||||
"slint_color_translucent",
|
||||
"slint_color_transparentize",
|
||||
"slint_color_opaque",
|
||||
"slint_color_mixed",
|
||||
"slint_color_mix",
|
||||
"slint_color_with_alpha",],
|
||||
vec![],
|
||||
"slint_color_internal.h",
|
||||
|
@ -349,9 +349,9 @@ fn gen_corelib(
|
|||
"slint_new_path_events",
|
||||
"slint_color_brighter",
|
||||
"slint_color_darker",
|
||||
"slint_color_translucent",
|
||||
"slint_color_transparentize",
|
||||
"slint_color_opaque",
|
||||
"slint_color_mixed",
|
||||
"slint_color_mix",
|
||||
"slint_color_with_alpha",
|
||||
"slint_image_size",
|
||||
"slint_image_path",
|
||||
|
|
|
@ -144,7 +144,7 @@ public:
|
|||
///
|
||||
/// For _increasing_ the opacity, see Brush::opaque(float) and
|
||||
/// Brush::with_alpha(float).
|
||||
inline Brush translucent(float factor) const;
|
||||
inline Brush transparentize(float factor) const;
|
||||
/// Returns a new version of this brush with the opacity increased by \a factor,
|
||||
/// meaning the new opacity will be scaled up by `1.0 + factor`.
|
||||
///
|
||||
|
@ -152,7 +152,7 @@ public:
|
|||
/// changed to be at least `0.0` before applying it, and thus the current
|
||||
/// value cannot be decreased.
|
||||
///
|
||||
/// For _decreasing_ the opacity, see Brush::translucent(float)
|
||||
/// For _decreasing_ the opacity, see Brush::transparentize(float)
|
||||
/// and Brush::with_alpha(float).
|
||||
inline Brush opaque(float factor) const;
|
||||
|
||||
|
@ -243,24 +243,24 @@ inline Brush Brush::darker(float factor) const
|
|||
return result;
|
||||
}
|
||||
|
||||
inline Brush Brush::translucent(float factor) const
|
||||
inline Brush Brush::transparentize(float factor) const
|
||||
{
|
||||
Brush result = *this;
|
||||
switch (data.tag) {
|
||||
case Tag::SolidColor:
|
||||
cbindgen_private::types::slint_color_translucent(&data.solid_color._0, factor,
|
||||
cbindgen_private::types::slint_color_transparentize(&data.solid_color._0, factor,
|
||||
&result.data.solid_color._0);
|
||||
break;
|
||||
case Tag::LinearGradient:
|
||||
for (std::size_t i = 1; i < data.linear_gradient._0.size(); ++i) {
|
||||
cbindgen_private::types::slint_color_translucent(
|
||||
cbindgen_private::types::slint_color_transparentize(
|
||||
&data.linear_gradient._0[i].color, factor,
|
||||
&result.data.linear_gradient._0[i].color);
|
||||
}
|
||||
break;
|
||||
case Tag::RadialGradient:
|
||||
for (std::size_t i = 0; i < data.linear_gradient._0.size(); ++i) {
|
||||
cbindgen_private::types::slint_color_translucent(
|
||||
cbindgen_private::types::slint_color_transparentize(
|
||||
&data.radial_gradient._0[i].color, factor,
|
||||
&result.data.radial_gradient._0[i].color);
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ public:
|
|||
///
|
||||
/// For _increasing_ the opacity, see Color::opaque(float) and
|
||||
/// Color::with_alpha(float).
|
||||
inline Color translucent(float factor) const;
|
||||
inline Color transparentize(float factor) const;
|
||||
/// Returns a new version of this color with the opacity increased by \a factor,
|
||||
/// meaning the new opacity will be scaled up by `1.0 + factor`.
|
||||
///
|
||||
|
@ -163,13 +163,13 @@ public:
|
|||
/// changed to be at least `0.0` before applying it, and thus the current
|
||||
/// value cannot be decreased.
|
||||
///
|
||||
/// For _decreasing_ the opacity, see Color::translucent(float) and
|
||||
/// For _decreasing_ the opacity, see Color::transparentize(float) and
|
||||
/// Color::with_alpha(float).
|
||||
inline Color opaque(float factor) const;
|
||||
|
||||
/// Returns a new color that is a mix of \a this and \a other, with a proportion
|
||||
/// factor given by \a factor (which will be clamped to be between `0.0` and `1.0`).
|
||||
inline Color mixed(const Color &other, float factor) const;
|
||||
inline Color mix(const Color &other, float factor) const;
|
||||
|
||||
/// Returns a new version of this color with the opacity set to \a alpha.
|
||||
inline Color with_alpha(float alpha) const;
|
||||
|
@ -215,10 +215,10 @@ inline Color Color::darker(float factor) const
|
|||
return result;
|
||||
}
|
||||
|
||||
inline Color Color::translucent(float factor) const
|
||||
inline Color Color::transparentize(float factor) const
|
||||
{
|
||||
Color result;
|
||||
cbindgen_private::types::slint_color_translucent(&inner, factor, &result.inner);
|
||||
cbindgen_private::types::slint_color_transparentize(&inner, factor, &result.inner);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -229,10 +229,10 @@ inline Color Color::opaque(float factor) const
|
|||
return result;
|
||||
}
|
||||
|
||||
inline Color Color::mixed(const Color &other, float factor) const
|
||||
inline Color Color::mix(const Color &other, float factor) const
|
||||
{
|
||||
Color result;
|
||||
cbindgen_private::types::slint_color_mixed(&inner, &other.inner, factor, &result.inner);
|
||||
cbindgen_private::types::slint_color_mix(&inner, &other.inner, factor, &result.inner);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,9 +47,9 @@ pub enum BuiltinFunction {
|
|||
StringIsFloat,
|
||||
ColorBrighter,
|
||||
ColorDarker,
|
||||
ColorTranslucent,
|
||||
ColorTransparentize,
|
||||
ColorOpaque,
|
||||
ColorMixed,
|
||||
ColorMix,
|
||||
ColorWithAlpha,
|
||||
ImageSize,
|
||||
ArrayLength,
|
||||
|
@ -150,7 +150,7 @@ impl BuiltinFunction {
|
|||
return_type: Box::new(Type::Brush),
|
||||
args: vec![Type::Brush, Type::Float32],
|
||||
},
|
||||
BuiltinFunction::ColorTranslucent => Type::Function {
|
||||
BuiltinFunction::ColorTransparentize => Type::Function {
|
||||
return_type: Box::new(Type::Brush),
|
||||
args: vec![Type::Brush, Type::Float32],
|
||||
},
|
||||
|
@ -158,7 +158,7 @@ impl BuiltinFunction {
|
|||
return_type: Box::new(Type::Brush),
|
||||
args: vec![Type::Brush, Type::Float32],
|
||||
},
|
||||
BuiltinFunction::ColorMixed => Type::Function {
|
||||
BuiltinFunction::ColorMix => Type::Function {
|
||||
return_type: Box::new(Type::Color),
|
||||
args: vec![Type::Color, Type::Color, Type::Float32],
|
||||
},
|
||||
|
@ -235,9 +235,9 @@ impl BuiltinFunction {
|
|||
BuiltinFunction::StringToFloat | BuiltinFunction::StringIsFloat => true,
|
||||
BuiltinFunction::ColorBrighter
|
||||
| BuiltinFunction::ColorDarker
|
||||
| BuiltinFunction::ColorTranslucent
|
||||
| BuiltinFunction::ColorTransparentize
|
||||
| BuiltinFunction::ColorOpaque
|
||||
| BuiltinFunction::ColorMixed
|
||||
| BuiltinFunction::ColorMix
|
||||
| BuiltinFunction::ColorWithAlpha => true,
|
||||
// ImageSize is pure, except when loading images via the network. Then the initial size will be 0/0 and
|
||||
// we need to make sure that calls to this function stay within a binding, so that the property
|
||||
|
@ -287,9 +287,9 @@ impl BuiltinFunction {
|
|||
BuiltinFunction::StringToFloat | BuiltinFunction::StringIsFloat => true,
|
||||
BuiltinFunction::ColorBrighter
|
||||
| BuiltinFunction::ColorDarker
|
||||
| BuiltinFunction::ColorTranslucent
|
||||
| BuiltinFunction::ColorTransparentize
|
||||
| BuiltinFunction::ColorOpaque
|
||||
| BuiltinFunction::ColorMixed
|
||||
| BuiltinFunction::ColorMix
|
||||
| BuiltinFunction::ColorWithAlpha => true,
|
||||
BuiltinFunction::ImageSize => true,
|
||||
BuiltinFunction::ArrayLength => true,
|
||||
|
|
|
@ -2710,14 +2710,14 @@ fn compile_builtin_function_call(
|
|||
BuiltinFunction::ColorDarker => {
|
||||
format!("{}.darker({})", a.next().unwrap(), a.next().unwrap())
|
||||
}
|
||||
BuiltinFunction::ColorTranslucent => {
|
||||
format!("{}.translucent({})", a.next().unwrap(), a.next().unwrap())
|
||||
BuiltinFunction::ColorTransparentize => {
|
||||
format!("{}.transparentize({})", a.next().unwrap(), a.next().unwrap())
|
||||
}
|
||||
BuiltinFunction::ColorOpaque => {
|
||||
format!("{}.opaque({})", a.next().unwrap(), a.next().unwrap())
|
||||
}
|
||||
BuiltinFunction::ColorMixed => {
|
||||
format!("{}.mixed({}, {})", a.next().unwrap(), a.next().unwrap(), a.next().unwrap())
|
||||
BuiltinFunction::ColorMix => {
|
||||
format!("{}.mix({}, {})", a.next().unwrap(), a.next().unwrap(), a.next().unwrap())
|
||||
}
|
||||
BuiltinFunction::ColorWithAlpha => {
|
||||
format!("{}.with_alpha({})", a.next().unwrap(), a.next().unwrap())
|
||||
|
|
|
@ -2365,21 +2365,21 @@ fn compile_builtin_function_call(
|
|||
let factor = a.next().unwrap();
|
||||
quote!(#x.darker(#factor as f32))
|
||||
}
|
||||
BuiltinFunction::ColorTranslucent => {
|
||||
BuiltinFunction::ColorTransparentize => {
|
||||
let x = a.next().unwrap();
|
||||
let factor = a.next().unwrap();
|
||||
quote!(#x.translucent(#factor as f32))
|
||||
quote!(#x.transparentize(#factor as f32))
|
||||
}
|
||||
BuiltinFunction::ColorOpaque => {
|
||||
let x = a.next().unwrap();
|
||||
let factor = a.next().unwrap();
|
||||
quote!(#x.opaque(#factor as f32))
|
||||
}
|
||||
BuiltinFunction::ColorMixed => {
|
||||
BuiltinFunction::ColorMix => {
|
||||
let x = a.next().unwrap();
|
||||
let y = a.next().unwrap();
|
||||
let factor = a.next().unwrap();
|
||||
quote!(#x.mixed(&#y.into(), #factor as f32))
|
||||
quote!(#x.mix(&#y.into(), #factor as f32))
|
||||
}
|
||||
BuiltinFunction::ColorWithAlpha => {
|
||||
let x = a.next().unwrap();
|
||||
|
|
|
@ -93,9 +93,9 @@ fn builtin_function_cost(function: &BuiltinFunction) -> isize {
|
|||
BuiltinFunction::StringIsFloat => 50,
|
||||
BuiltinFunction::ColorBrighter => 50,
|
||||
BuiltinFunction::ColorDarker => 50,
|
||||
BuiltinFunction::ColorTranslucent => 50,
|
||||
BuiltinFunction::ColorTransparentize => 50,
|
||||
BuiltinFunction::ColorOpaque => 50,
|
||||
BuiltinFunction::ColorMixed => 50,
|
||||
BuiltinFunction::ColorMix => 50,
|
||||
BuiltinFunction::ColorWithAlpha => 50,
|
||||
BuiltinFunction::ImageSize => 50,
|
||||
BuiltinFunction::ArrayLength => 50,
|
||||
|
|
|
@ -857,10 +857,10 @@ impl<'a> LookupObject for ColorExpression<'a> {
|
|||
};
|
||||
None.or_else(|| f("brighter", member_function(BuiltinFunction::ColorBrighter)))
|
||||
.or_else(|| f("darker", member_function(BuiltinFunction::ColorDarker)))
|
||||
.or_else(|| f("translucent", member_function(BuiltinFunction::ColorTranslucent)))
|
||||
.or_else(|| f("transparentize", member_function(BuiltinFunction::ColorTransparentize)))
|
||||
.or_else(|| f("opaque", member_function(BuiltinFunction::ColorOpaque)))
|
||||
.or_else(|| f("with-alpha", member_function(BuiltinFunction::ColorWithAlpha)))
|
||||
.or_else(|| f("mixed", member_function(BuiltinFunction::ColorMixed)))
|
||||
.or_else(|| f("mix", member_function(BuiltinFunction::ColorMix)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -135,19 +135,19 @@ impl Brush {
|
|||
/// For _increasing_ the opacity, see [`opaque`](fn@Brush::opaque) and
|
||||
/// [`with_alpha`](fn@Brush::with_alpha).
|
||||
#[must_use]
|
||||
pub fn translucent(&self, amount: f32) -> Self {
|
||||
pub fn transparentize(&self, amount: f32) -> Self {
|
||||
match self {
|
||||
Brush::SolidColor(c) => Brush::SolidColor(c.translucent(amount)),
|
||||
Brush::SolidColor(c) => Brush::SolidColor(c.transparentize(amount)),
|
||||
Brush::LinearGradient(g) => Brush::LinearGradient(LinearGradientBrush::new(
|
||||
g.angle(),
|
||||
g.stops().map(|s| GradientStop {
|
||||
color: s.color.translucent(amount),
|
||||
color: s.color.transparentize(amount),
|
||||
position: s.position,
|
||||
}),
|
||||
)),
|
||||
Brush::RadialGradient(g) => {
|
||||
Brush::RadialGradient(RadialGradientBrush::new_circle(g.stops().map(|s| {
|
||||
GradientStop { color: s.color.translucent(amount), position: s.position }
|
||||
GradientStop { color: s.color.transparentize(amount), position: s.position }
|
||||
})))
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ impl Brush {
|
|||
/// changed to be at least `0.0` before applying it, and thus the current
|
||||
/// value cannot be decreased.
|
||||
///
|
||||
/// For _decreasing_ the opacity, see [`translucent`](fn@Brush::translucent) and
|
||||
/// For _decreasing_ the opacity, see [`transparentize`](fn@Brush::transparentize) and
|
||||
/// [`with_alpha`](fn@Brush::with_alpha).
|
||||
#[must_use]
|
||||
pub fn opaque(&self, amount: f32) -> Self {
|
||||
|
|
|
@ -207,17 +207,17 @@ impl Color {
|
|||
/// ```
|
||||
/// # use i_slint_core::graphics::Color;
|
||||
/// let red = Color::from_argb_u8(255, 255, 0, 0);
|
||||
/// assert_eq!(red.translucent(0.5), Color::from_argb_u8(128, 255, 0, 0));
|
||||
/// assert_eq!(red.transparentize(0.5), Color::from_argb_u8(128, 255, 0, 0));
|
||||
/// ```
|
||||
///
|
||||
/// Decreasing the opacity of a blue color to be 20% of the current value:
|
||||
/// ```
|
||||
/// # use i_slint_core::graphics::Color;
|
||||
/// let blue = Color::from_argb_u8(200, 0, 0, 255);
|
||||
/// assert_eq!(blue.translucent(0.2), Color::from_argb_u8(40, 0, 0, 255));
|
||||
/// assert_eq!(blue.transparentize(0.2), Color::from_argb_u8(40, 0, 0, 255));
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn translucent(&self, factor: f32) -> Self {
|
||||
pub fn transparentize(&self, factor: f32) -> Self {
|
||||
let mut rgba: RgbaColor<u8> = (*self).into();
|
||||
rgba.alpha = scale_u8(rgba.alpha, factor.clamp(0.0, 1.0));
|
||||
rgba.into()
|
||||
|
@ -230,7 +230,7 @@ impl Color {
|
|||
/// changed to be at least `0.0` before applying it, and thus the current
|
||||
/// value cannot be decreased.
|
||||
///
|
||||
/// For _decreasing_ the opacity, see [`translucent`](fn@Color::translucent) and
|
||||
/// For _decreasing_ the opacity, see [`transparentize`](fn@Color::transparentize) and
|
||||
/// [`with_alpha`](fn@Color::with_alpha).
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -263,7 +263,7 @@ impl Color {
|
|||
/// # use i_slint_core::graphics::Color;
|
||||
/// let red = Color::from_rgb_u8(255, 0, 0);
|
||||
/// let black = Color::from_rgb_u8(0, 0, 0);
|
||||
/// assert_eq!(red.mixed(&black, 0.5), Color::from_rgb_u8(128, 0, 0));
|
||||
/// assert_eq!(red.mix(&black, 0.5), Color::from_rgb_u8(128, 0, 0));
|
||||
/// ```
|
||||
///
|
||||
/// Mix Purple with OrangeRed with `75%`:`25%` ratio:
|
||||
|
@ -271,10 +271,10 @@ impl Color {
|
|||
/// # use i_slint_core::graphics::Color;
|
||||
/// let purple = Color::from_rgb_u8(128, 0, 128);
|
||||
/// let orange_red = Color::from_rgb_u8(255, 69, 0);
|
||||
/// assert_eq!(purple.mixed(&orange_red, 0.75), Color::from_rgb_u8(160, 17, 96));
|
||||
/// assert_eq!(purple.mix(&orange_red, 0.75), Color::from_rgb_u8(160, 17, 96));
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn mixed(&self, other: &Self, factor: f32) -> Self {
|
||||
pub fn mix(&self, other: &Self, factor: f32) -> Self {
|
||||
// * NOTE: The opacity (`alpha` as a "percentage") of each color involved
|
||||
// * must be taken into account when mixing them. Because of this,
|
||||
// * we cannot just interpolate between them.
|
||||
|
@ -452,8 +452,8 @@ pub(crate) mod ffi {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn slint_color_translucent(col: &Color, factor: f32, out: *mut Color) {
|
||||
core::ptr::write(out, col.translucent(factor))
|
||||
pub unsafe extern "C" fn slint_color_transparentize(col: &Color, factor: f32, out: *mut Color) {
|
||||
core::ptr::write(out, col.transparentize(factor))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -462,13 +462,13 @@ pub(crate) mod ffi {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn slint_color_mixed(
|
||||
pub unsafe extern "C" fn slint_color_mix(
|
||||
col1: &Color,
|
||||
col2: &Color,
|
||||
factor: f32,
|
||||
out: *mut Color,
|
||||
) {
|
||||
core::ptr::write(out, col1.mixed(col2, factor))
|
||||
core::ptr::write(out, col1.mix(col2, factor))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
|
@ -680,13 +680,13 @@ fn call_builtin_function(
|
|||
panic!("First argument not a color");
|
||||
}
|
||||
}
|
||||
BuiltinFunction::ColorTranslucent => {
|
||||
BuiltinFunction::ColorTransparentize => {
|
||||
if arguments.len() != 2 {
|
||||
panic!("internal error: incorrect argument count to ColorFaded")
|
||||
}
|
||||
if let Value::Brush(brush) = eval_expression(&arguments[0], local_context) {
|
||||
if let Value::Number(factor) = eval_expression(&arguments[1], local_context) {
|
||||
brush.translucent(factor as _).into()
|
||||
brush.transparentize(factor as _).into()
|
||||
} else {
|
||||
panic!("Second argument not a number");
|
||||
}
|
||||
|
@ -708,9 +708,9 @@ fn call_builtin_function(
|
|||
panic!("First argument not a color");
|
||||
}
|
||||
}
|
||||
BuiltinFunction::ColorMixed => {
|
||||
BuiltinFunction::ColorMix => {
|
||||
if arguments.len() != 3 {
|
||||
panic!("internal error: incorrect argument count to ColorMixed")
|
||||
panic!("internal error: incorrect argument count to ColorMix")
|
||||
}
|
||||
|
||||
let arg0 = eval_expression(&arguments[0], local_context);
|
||||
|
@ -731,7 +731,7 @@ fn call_builtin_function(
|
|||
unreachable!()
|
||||
};
|
||||
|
||||
color_a.mixed(&color_b, factor as _).into()
|
||||
color_a.mix(&color_b, factor as _).into()
|
||||
}
|
||||
BuiltinFunction::ColorWithAlpha => {
|
||||
if arguments.len() != 2 {
|
||||
|
|
|
@ -6,8 +6,8 @@ Test := Rectangle {
|
|||
property<brush> color_brush: blue;
|
||||
// allow to use brighter and darker on a brush
|
||||
property<brush> ligher: true ? color_brush.brighter(50%) : color_brush.darker(50%);
|
||||
// allow to use `translucent` and `opaque` on brushes
|
||||
property<brush> seethru: true ? color_brush.translucent(30%) : color_brush.opaque(200%);
|
||||
// allow to use `transparentize` and `opaque` on brushes
|
||||
property<brush> seethru: true ? color_brush.transparentize(30%) : color_brush.opaque(200%);
|
||||
// allow to use `with_alpha` on brushes
|
||||
property<brush> invisible: color_brush.with-alpha(0%);
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ Test := Rectangle {
|
|||
|
||||
property<color> i1: rgb(0, 666, -85);
|
||||
|
||||
// allow to use `mixed` on colors
|
||||
property<color> p1: true ? b1.mixed(r1, 30%) : y1.mixed(c1, 70%);
|
||||
// allow to use `mix` on colors
|
||||
property<color> p1: true ? b1.mix(r1, 30%) : y1.mix(c1, 70%);
|
||||
// allow to use `with_alpha` on colors
|
||||
property<brush> invisible: b1.with-alpha(0%);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue