mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Hide Property<T> and PropertyTracker<T> from the public C++ API
Move those two classes into the private_api namespace, which is excluded from the API reference documentation. For generate code the explicit qualification of Property<T> is changed, for the cbindgen generated item types the private_api namespace is pulled into the cbindgen_private namespace.
This commit is contained in:
parent
fb7050e3e6
commit
11d46bcc23
6 changed files with 23 additions and 17 deletions
|
@ -477,7 +477,7 @@ public:
|
||||||
template<typename C, typename ModelData>
|
template<typename C, typename ModelData>
|
||||||
class Repeater
|
class Repeater
|
||||||
{
|
{
|
||||||
Property<std::shared_ptr<Model<ModelData>>> model;
|
private_api::Property<std::shared_ptr<Model<ModelData>>> model;
|
||||||
|
|
||||||
#if !defined(DOXYGEN) // hide from public API
|
#if !defined(DOXYGEN) // hide from public API
|
||||||
struct RepeaterInner : AbstractRepeaterView
|
struct RepeaterInner : AbstractRepeaterView
|
||||||
|
@ -489,7 +489,7 @@ class Repeater
|
||||||
std::optional<ComponentHandle<C>> ptr;
|
std::optional<ComponentHandle<C>> ptr;
|
||||||
};
|
};
|
||||||
std::vector<ComponentWithState> data;
|
std::vector<ComponentWithState> data;
|
||||||
Property<bool> is_dirty { true };
|
private_api::Property<bool> is_dirty { true };
|
||||||
|
|
||||||
void row_added(int index, int count) override
|
void row_added(int index, int count) override
|
||||||
{
|
{
|
||||||
|
@ -559,9 +559,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Parent>
|
template<typename Parent>
|
||||||
void ensure_updated_listview(const Parent *parent, const Property<float> *viewport_width,
|
void ensure_updated_listview(const Parent *parent,
|
||||||
const Property<float> *viewport_height,
|
const private_api::Property<float> *viewport_width,
|
||||||
[[maybe_unused]] const Property<float> *viewport_y,
|
const private_api::Property<float> *viewport_height,
|
||||||
|
[[maybe_unused]] const private_api::Property<float> *viewport_y,
|
||||||
float listview_width, [[maybe_unused]] float listview_height) const
|
float listview_width, [[maybe_unused]] float listview_height) const
|
||||||
{
|
{
|
||||||
// TODO: the rust code in model.rs try to only allocate as many items as visible items
|
// TODO: the rust code in model.rs try to only allocate as many items as visible items
|
||||||
|
@ -589,7 +590,8 @@ public:
|
||||||
return { &C::static_vtable, const_cast<C *>(&(**x.ptr)) };
|
return { &C::static_vtable, const_cast<C *>(&(**x.ptr)) };
|
||||||
}
|
}
|
||||||
|
|
||||||
float compute_layout_listview(const Property<float> *viewport_width, float listview_width) const
|
float compute_layout_listview(const private_api::Property<float> *viewport_width,
|
||||||
|
float listview_width) const
|
||||||
{
|
{
|
||||||
float offset = 0;
|
float offset = 0;
|
||||||
viewport_width->set(listview_width);
|
viewport_width->set(listview_width);
|
||||||
|
|
|
@ -209,6 +209,8 @@ RgbaColor<float> Color::to_argb_float() const
|
||||||
return RgbaColor<float>(*this);
|
return RgbaColor<float>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace private_api {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline void
|
inline void
|
||||||
Property<Color>::set_animated_value(const Color &new_value,
|
Property<Color>::set_animated_value(const Color &new_value,
|
||||||
|
@ -218,4 +220,6 @@ Property<Color>::set_animated_value(const Color &new_value,
|
||||||
&animation_data);
|
&animation_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace private_api
|
||||||
|
|
||||||
|
} // namespace sixtyfps
|
||||||
|
|
|
@ -65,8 +65,6 @@ inline void sixtyfps_property_set_animated_binding_helper(
|
||||||
handle, binding, user_data, drop_user_data, animation_data, transition_data);
|
handle, binding, user_data, drop_user_data, animation_data, transition_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Property
|
struct Property
|
||||||
{
|
{
|
||||||
|
@ -303,4 +301,6 @@ private:
|
||||||
cbindgen_private::PropertyTrackerOpaque inner;
|
cbindgen_private::PropertyTrackerOpaque inner;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace private_api
|
||||||
|
|
||||||
} // namespace sixtyfps
|
} // namespace sixtyfps
|
||||||
|
|
|
@ -53,7 +53,7 @@ TEST_CASE("Basic SharedVector API", "[vector]")
|
||||||
|
|
||||||
TEST_CASE("Property Tracker")
|
TEST_CASE("Property Tracker")
|
||||||
{
|
{
|
||||||
using namespace sixtyfps;
|
using namespace sixtyfps::private_api;
|
||||||
PropertyTracker tracker1;
|
PropertyTracker tracker1;
|
||||||
PropertyTracker tracker2;
|
PropertyTracker tracker2;
|
||||||
Property<int> prop(42);
|
Property<int> prop(42);
|
||||||
|
|
|
@ -373,7 +373,7 @@ fn handle_property_binding(
|
||||||
));
|
));
|
||||||
} else if let Expression::TwoWayBinding(nr, next) = &binding_expression {
|
} else if let Expression::TwoWayBinding(nr, next) = &binding_expression {
|
||||||
init.push(format!(
|
init.push(format!(
|
||||||
"sixtyfps::Property<{ty}>::link_two_way(&{p1}, &{p2});",
|
"sixtyfps::private_api::Property<{ty}>::link_two_way(&{p1}, &{p2});",
|
||||||
ty = prop_type.cpp_type().unwrap_or_default(),
|
ty = prop_type.cpp_type().unwrap_or_default(),
|
||||||
p1 = access_member(elem, prop_name, &component, "this"),
|
p1 = access_member(elem, prop_name, &component, "this"),
|
||||||
p2 = access_named_reference(nr, &component, "this")
|
p2 = access_named_reference(nr, &component, "this")
|
||||||
|
@ -400,7 +400,7 @@ fn handle_property_binding(
|
||||||
|
|
||||||
let is_state_info = matches!(prop_type, Type::Struct { name: Some(name), .. } if name.ends_with("::StateInfo"));
|
let is_state_info = matches!(prop_type, Type::Struct { name: Some(name), .. } if name.ends_with("::StateInfo"));
|
||||||
if is_state_info {
|
if is_state_info {
|
||||||
format!("sixtyfps::set_state_binding({}, {});", cpp_prop, binding_code)
|
format!("sixtyfps::private_api::set_state_binding({}, {});", cpp_prop, binding_code)
|
||||||
} else {
|
} else {
|
||||||
match item.property_animations.get(prop_name) {
|
match item.property_animations.get(prop_name) {
|
||||||
Some(crate::object_tree::PropertyAnimation::Static(anim)) => {
|
Some(crate::object_tree::PropertyAnimation::Static(anim)) => {
|
||||||
|
@ -754,7 +754,7 @@ fn generate_component(
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
format!("sixtyfps::Property<{}>", cpp_type)
|
format!("sixtyfps::private_api::Property<{}>", cpp_type)
|
||||||
};
|
};
|
||||||
|
|
||||||
if property_decl.is_alias.is_none() {
|
if property_decl.is_alias.is_none() {
|
||||||
|
@ -775,7 +775,7 @@ fn generate_component(
|
||||||
component_struct.members.push((
|
component_struct.members.push((
|
||||||
Access::Private,
|
Access::Private,
|
||||||
Declaration::Var(Var {
|
Declaration::Var(Var {
|
||||||
ty: "sixtyfps::Property<int>".into(),
|
ty: "sixtyfps::private_api::Property<int>".into(),
|
||||||
name: "index".into(),
|
name: "index".into(),
|
||||||
init: None,
|
init: None,
|
||||||
}),
|
}),
|
||||||
|
@ -784,7 +784,7 @@ fn generate_component(
|
||||||
component_struct.members.push((
|
component_struct.members.push((
|
||||||
Access::Private,
|
Access::Private,
|
||||||
Declaration::Var(Var {
|
Declaration::Var(Var {
|
||||||
ty: format!("sixtyfps::Property<{}>", cpp_model_data_type),
|
ty: format!("sixtyfps::private_api::Property<{}>", cpp_model_data_type),
|
||||||
name: "model_data".into(),
|
name: "model_data".into(),
|
||||||
init: None,
|
init: None,
|
||||||
}),
|
}),
|
||||||
|
@ -847,7 +847,7 @@ fn generate_component(
|
||||||
Declaration::Function(Function {
|
Declaration::Function(Function {
|
||||||
name: "listview_layout".into(),
|
name: "listview_layout".into(),
|
||||||
signature:
|
signature:
|
||||||
"(float *offset_y, const sixtyfps::Property<float> *viewport_width) const -> void"
|
"(float *offset_y, const sixtyfps::private_api::Property<float> *viewport_width) const -> void"
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
statements: Some(vec![
|
statements: Some(vec![
|
||||||
"float vp_w = viewport_width->get();".to_owned(),
|
"float vp_w = viewport_width->get();".to_owned(),
|
||||||
|
|
|
@ -308,7 +308,7 @@ fn gen_corelib(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> {
|
||||||
r"
|
r"
|
||||||
namespace sixtyfps {{
|
namespace sixtyfps {{
|
||||||
namespace private_api {{ enum class VersionCheck {{ Major = {}, Minor = {}, Patch = {} }}; class ComponentWindow; }}
|
namespace private_api {{ enum class VersionCheck {{ Major = {}, Minor = {}, Patch = {} }}; class ComponentWindow; }}
|
||||||
namespace cbindgen_private {{ using sixtyfps::private_api::ComponentWindow; using namespace vtable; struct KeyEvent; }}
|
namespace cbindgen_private {{ using sixtyfps::private_api::ComponentWindow; using namespace vtable; struct KeyEvent; using namespace private_api; }}
|
||||||
}}",
|
}}",
|
||||||
0, 0, 6,
|
0, 0, 6,
|
||||||
))
|
))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue