mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
C++ API: Make LinearGradientBrush and GradientStop private API
This commit is contained in:
parent
9819f7f6b7
commit
adeb192f6e
3 changed files with 20 additions and 7 deletions
|
@ -15,8 +15,11 @@ LICENSE END */
|
||||||
|
|
||||||
namespace sixtyfps {
|
namespace sixtyfps {
|
||||||
|
|
||||||
|
namespace private_api {
|
||||||
|
|
||||||
using cbindgen_private::types::GradientStop;
|
using cbindgen_private::types::GradientStop;
|
||||||
|
|
||||||
|
/// \private
|
||||||
/// LinearGradientBrush represents a gradient for a brush that is a linear sequence of color stops,
|
/// LinearGradientBrush represents a gradient for a brush that is a linear sequence of color stops,
|
||||||
/// that are aligned at a specific angle.
|
/// that are aligned at a specific angle.
|
||||||
class LinearGradientBrush
|
class LinearGradientBrush
|
||||||
|
@ -50,12 +53,12 @@ public:
|
||||||
private:
|
private:
|
||||||
cbindgen_private::types::LinearGradientBrush inner;
|
cbindgen_private::types::LinearGradientBrush inner;
|
||||||
|
|
||||||
friend class Brush;
|
friend class sixtyfps::Brush;
|
||||||
|
|
||||||
static SharedVector<GradientStop>
|
static SharedVector<private_api::GradientStop>
|
||||||
make_linear_gradient(float angle, const GradientStop *firstStop, int stopCount)
|
make_linear_gradient(float angle, const GradientStop *firstStop, int stopCount)
|
||||||
{
|
{
|
||||||
SharedVector<GradientStop> gradient;
|
SharedVector<private_api::GradientStop> gradient;
|
||||||
gradient.push_back({ Color::from_argb_encoded(0).inner, angle });
|
gradient.push_back({ Color::from_argb_encoded(0).inner, angle });
|
||||||
for (int i = 0; i < stopCount; ++i, ++firstStop)
|
for (int i = 0; i < stopCount; ++i, ++firstStop)
|
||||||
gradient.push_back(*firstStop);
|
gradient.push_back(*firstStop);
|
||||||
|
@ -63,6 +66,8 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// Brush is used to declare how to fill or outline shapes, such as rectangles, paths or text. A
|
/// Brush is used to declare how to fill or outline shapes, such as rectangles, paths or text. A
|
||||||
/// brush is either a solid color or a linear gradient.
|
/// brush is either a solid color or a linear gradient.
|
||||||
class Brush
|
class Brush
|
||||||
|
@ -72,8 +77,12 @@ public:
|
||||||
Brush() : Brush(Color {}) { }
|
Brush() : Brush(Color {}) { }
|
||||||
/// Constructs a new brush that is of color \a color.
|
/// Constructs a new brush that is of color \a color.
|
||||||
Brush(const Color &color) : data(Inner::SolidColor(color.inner)) { }
|
Brush(const Color &color) : data(Inner::SolidColor(color.inner)) { }
|
||||||
|
/// \private
|
||||||
/// Constructs a new brush that is the gradient \a gradient.
|
/// Constructs a new brush that is the gradient \a gradient.
|
||||||
Brush(const LinearGradientBrush &gradient) : data(Inner::LinearGradient(gradient.inner)) { }
|
Brush(const private_api::LinearGradientBrush &gradient)
|
||||||
|
: data(Inner::LinearGradient(gradient.inner))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the color of the brush. If the brush is a gradient, this function returns the color
|
/// Returns the color of the brush. If the brush is a gradient, this function returns the color
|
||||||
/// of the first stop.
|
/// of the first stop.
|
||||||
|
|
|
@ -16,6 +16,10 @@ LICENSE END */
|
||||||
|
|
||||||
namespace sixtyfps {
|
namespace sixtyfps {
|
||||||
|
|
||||||
|
namespace private_api {
|
||||||
|
class LinearGradientBrush;
|
||||||
|
}
|
||||||
|
|
||||||
class Color;
|
class Color;
|
||||||
|
|
||||||
/// RgbaColor stores the red, green, blue and alpha components of a color
|
/// RgbaColor stores the red, green, blue and alpha components of a color
|
||||||
|
@ -178,7 +182,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cbindgen_private::types::Color inner;
|
cbindgen_private::types::Color inner;
|
||||||
friend class LinearGradientBrush;
|
friend class private_api::LinearGradientBrush;
|
||||||
friend class Brush;
|
friend class Brush;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1700,10 +1700,10 @@ fn compile_expression(
|
||||||
let mut stops_it = stops.iter().map(|(color, stop)| {
|
let mut stops_it = stops.iter().map(|(color, stop)| {
|
||||||
let color = compile_expression(color, component);
|
let color = compile_expression(color, component);
|
||||||
let position = compile_expression(stop, component);
|
let position = compile_expression(stop, component);
|
||||||
format!("sixtyfps::GradientStop{{ {}, {}, }}", color, position)
|
format!("sixtyfps::private_api::GradientStop{{ {}, {}, }}", color, position)
|
||||||
});
|
});
|
||||||
format!(
|
format!(
|
||||||
"[&] {{ const sixtyfps::GradientStop stops[] = {{ {} }}; return sixtyfps::LinearGradientBrush({}, stops, {}); }}()",
|
"[&] {{ const sixtyfps::private_api::GradientStop stops[] = {{ {} }}; return sixtyfps::private_api::LinearGradientBrush({}, stops, {}); }}()",
|
||||||
stops_it.join(", "), angle, stops.len()
|
stops_it.join(", "), angle, stops.len()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue