mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 22:31:14 +00:00
Allow an implicit conversion from a color or a linear gradient to Brush in C++
This commit is contained in:
parent
c41062e9bb
commit
262eb00af4
2 changed files with 3 additions and 9 deletions
|
@ -54,11 +54,8 @@ class Brush
|
|||
{
|
||||
public:
|
||||
Brush() : data(Inner::NoBrush()) { }
|
||||
explicit Brush(const Color &color) : data(Inner::SolidColor(color.inner)) { }
|
||||
explicit Brush(const LinearGradientBrush &gradient)
|
||||
: data(Inner::LinearGradient(gradient.inner))
|
||||
{
|
||||
}
|
||||
Brush(const Color &color) : data(Inner::SolidColor(color.inner)) { }
|
||||
Brush(const LinearGradientBrush &gradient) : data(Inner::LinearGradient(gradient.inner)) { }
|
||||
|
||||
friend bool operator==(const Brush &a, const Brush &b) { return a.data == b.data; }
|
||||
friend bool operator!=(const Brush &a, const Brush &b) { return a.data != b.data; }
|
||||
|
|
|
@ -1479,9 +1479,6 @@ fn compile_expression(
|
|||
(Type::Float32, Type::Color) => {
|
||||
format!("sixtyfps::Color::from_argb_encoded({})", f)
|
||||
}
|
||||
(Type::Color, Type::Brush) => {
|
||||
format!("sixtyfps::Brush({})", f)
|
||||
}
|
||||
(Type::Object { .. }, Type::Object{ fields, name: Some(n)}) => {
|
||||
format!(
|
||||
"[&](const auto &o){{ {struct_name} s; auto& [{field_members}] = s; {fields}; return s; }}({obj})",
|
||||
|
@ -1661,7 +1658,7 @@ fn compile_expression(
|
|||
format!("sixtyfps::GradientStop{{ {}, {}, }}", color, position)
|
||||
});
|
||||
format!(
|
||||
"[&] {{ const sixtyfps::GradientStop stops[] = {{ {} }}; return sixtyfps::Brush(sixtyfps::LinearGradientBrush({}, stops, {})); }}()",
|
||||
"[&] {{ const sixtyfps::GradientStop stops[] = {{ {} }}; return sixtyfps::LinearGradientBrush({}, stops, {}); }}()",
|
||||
stops_it.join(", "), angle, stops.len()
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue