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:
Simon Hausmann 2021-06-21 11:38:51 +02:00
parent fb7050e3e6
commit 11d46bcc23
6 changed files with 23 additions and 17 deletions

View file

@ -477,7 +477,7 @@ public:
template<typename C, typename ModelData>
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
struct RepeaterInner : AbstractRepeaterView
@ -489,7 +489,7 @@ class Repeater
std::optional<ComponentHandle<C>> ptr;
};
std::vector<ComponentWithState> data;
Property<bool> is_dirty { true };
private_api::Property<bool> is_dirty { true };
void row_added(int index, int count) override
{
@ -559,9 +559,10 @@ public:
}
template<typename Parent>
void ensure_updated_listview(const Parent *parent, const Property<float> *viewport_width,
const Property<float> *viewport_height,
[[maybe_unused]] const Property<float> *viewport_y,
void ensure_updated_listview(const Parent *parent,
const private_api::Property<float> *viewport_width,
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
{
// 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)) };
}
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;
viewport_width->set(listview_width);

View file

@ -209,6 +209,8 @@ RgbaColor<float> Color::to_argb_float() const
return RgbaColor<float>(*this);
}
namespace private_api {
template<>
inline void
Property<Color>::set_animated_value(const Color &new_value,
@ -218,4 +220,6 @@ Property<Color>::set_animated_value(const Color &new_value,
&animation_data);
}
}
} // namespace private_api
} // namespace sixtyfps

View file

@ -65,8 +65,6 @@ inline void sixtyfps_property_set_animated_binding_helper(
handle, binding, user_data, drop_user_data, animation_data, transition_data);
}
}
template<typename T>
struct Property
{
@ -303,4 +301,6 @@ private:
cbindgen_private::PropertyTrackerOpaque inner;
};
} // namespace private_api
} // namespace sixtyfps

View file

@ -53,7 +53,7 @@ TEST_CASE("Basic SharedVector API", "[vector]")
TEST_CASE("Property Tracker")
{
using namespace sixtyfps;
using namespace sixtyfps::private_api;
PropertyTracker tracker1;
PropertyTracker tracker2;
Property<int> prop(42);

View file

@ -373,7 +373,7 @@ fn handle_property_binding(
));
} else if let Expression::TwoWayBinding(nr, next) = &binding_expression {
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(),
p1 = access_member(elem, prop_name, &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"));
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 {
match item.property_animations.get(prop_name) {
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() {
@ -775,7 +775,7 @@ fn generate_component(
component_struct.members.push((
Access::Private,
Declaration::Var(Var {
ty: "sixtyfps::Property<int>".into(),
ty: "sixtyfps::private_api::Property<int>".into(),
name: "index".into(),
init: None,
}),
@ -784,7 +784,7 @@ fn generate_component(
component_struct.members.push((
Access::Private,
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(),
init: None,
}),
@ -847,7 +847,7 @@ fn generate_component(
Declaration::Function(Function {
name: "listview_layout".into(),
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(),
statements: Some(vec![
"float vp_w = viewport_width->get();".to_owned(),

View file

@ -308,7 +308,7 @@ fn gen_corelib(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> {
r"
namespace sixtyfps {{
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,
))