mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 22:31:14 +00:00
Generate linear gradient in C++
This commit is contained in:
parent
c5ab214f55
commit
d90fce9c1d
2 changed files with 19 additions and 1 deletions
|
@ -155,6 +155,9 @@ public:
|
|||
<< ")";
|
||||
}
|
||||
|
||||
// FIXME: we need this to create GradientStop
|
||||
operator const cbindgen_private::types::Color&() { return inner; }
|
||||
|
||||
private:
|
||||
cbindgen_private::types::Color inner;
|
||||
friend class LinearGradientBrush;
|
||||
|
|
|
@ -1645,7 +1645,22 @@ fn compile_expression(
|
|||
"sixtyfps::EasingCurve(sixtyfps::EasingCurve::Tag::CubicBezier, {}, {}, {}, {})",
|
||||
a, b, c, d
|
||||
),
|
||||
Expression::LinearGradient{..} => todo!(),
|
||||
Expression::LinearGradient{angle, stops} => {
|
||||
let angle = compile_expression(angle, component);
|
||||
let mut stops_it = stops.iter().map(|(color, stop)| {
|
||||
let color = compile_expression(color, component);
|
||||
let position = if matches!(stop, Expression::Invalid) {
|
||||
"std::numeric_limits<double>::quiet_NaN()".to_string()
|
||||
} else {
|
||||
compile_expression(stop, component)
|
||||
};
|
||||
format!("sixtyfps::GradientStop{{ {}, {}, }}", color, position)
|
||||
});
|
||||
format!(
|
||||
"[&] {{ const sixtyfps::GradientStop stops[] = {{ {} }}; return sixtyfps::LinearGradientBrush({}, stops, {}); }}()",
|
||||
stops_it.join(", "), angle, stops.len()
|
||||
)
|
||||
}
|
||||
Expression::EnumerationValue(value) => {
|
||||
format!("sixtyfps::{}::{}", value.enumeration.name, value.to_string())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue