Move all cbindgen generated code into

sixtyfps::cbindgen_private

Having private in the name makes it clear that this is ... private,
and cbindgen helps remember that it's generated.
This commit is contained in:
Simon Hausmann 2020-08-25 15:29:48 +02:00
parent 2fa953ce8a
commit 14fe897086
12 changed files with 108 additions and 108 deletions

View file

@ -16,7 +16,7 @@ LICENSE END */
#include <vector>
#include <memory>
namespace sixtyfps::internal {
namespace sixtyfps::cbindgen_private {
// Workaround https://github.com/eqrion/cbindgen/issues/43
struct ComponentVTable;
struct ItemVTable;
@ -27,31 +27,31 @@ struct ItemVTable;
namespace sixtyfps {
extern "C" {
extern const internal::ItemVTable RectangleVTable;
extern const internal::ItemVTable BorderRectangleVTable;
extern const internal::ItemVTable TextVTable;
extern const internal::ItemVTable TouchAreaVTable;
extern const internal::ItemVTable ImageVTable;
extern const internal::ItemVTable PathVTable;
extern const internal::ItemVTable FlickableVTable;
extern const internal::ItemVTable WindowVTable;
extern const cbindgen_private::ItemVTable RectangleVTable;
extern const cbindgen_private::ItemVTable BorderRectangleVTable;
extern const cbindgen_private::ItemVTable TextVTable;
extern const cbindgen_private::ItemVTable TouchAreaVTable;
extern const cbindgen_private::ItemVTable ImageVTable;
extern const cbindgen_private::ItemVTable PathVTable;
extern const cbindgen_private::ItemVTable FlickableVTable;
extern const cbindgen_private::ItemVTable WindowVTable;
}
// Bring opaque structure in scope
using internal::ComponentVTable;
using ItemTreeNode = internal::ItemTreeNode<uint8_t>;
using cbindgen_private::ComponentVTable;
using ItemTreeNode = cbindgen_private::ItemTreeNode<uint8_t>;
using ComponentRef = VRef<ComponentVTable>;
using ItemVisitorRefMut = VRefMut<internal::ItemVisitorVTable>;
using internal::TraversalOrder;
using internal::EasingCurve;
using internal::TextHorizontalAlignment;
using internal::TextVerticalAlignment;
using internal::Slice;
using ItemVisitorRefMut = VRefMut<cbindgen_private::ItemVisitorVTable>;
using cbindgen_private::TraversalOrder;
using cbindgen_private::EasingCurve;
using cbindgen_private::TextHorizontalAlignment;
using cbindgen_private::TextVerticalAlignment;
using cbindgen_private::Slice;
struct ComponentWindow
{
ComponentWindow() { internal::sixtyfps_component_window_gl_renderer_init(&inner); }
~ComponentWindow() { internal::sixtyfps_component_window_drop(&inner); }
ComponentWindow() { cbindgen_private::sixtyfps_component_window_gl_renderer_init(&inner); }
~ComponentWindow() { cbindgen_private::sixtyfps_component_window_drop(&inner); }
ComponentWindow(const ComponentWindow &) = delete;
ComponentWindow(ComponentWindow &&) = delete;
ComponentWindow &operator=(const ComponentWindow &) = delete;
@ -72,25 +72,25 @@ struct ComponentWindow
template<typename Component>
void free_graphics_resources(Component *c) const
{
internal::sixtyfps_component_window_free_graphics_resources(
cbindgen_private::sixtyfps_component_window_free_graphics_resources(
&inner, VRef<ComponentVTable> { &Component::component_type, c });
}
private:
internal::ComponentWindowOpaque inner;
cbindgen_private::ComponentWindowOpaque inner;
};
using internal::BorderRectangle;
using internal::Flickable;
using internal::Image;
using internal::Path;
using internal::Rectangle;
using internal::Text;
using internal::TouchArea;
using internal::Window;
using cbindgen_private::BorderRectangle;
using cbindgen_private::Flickable;
using cbindgen_private::Image;
using cbindgen_private::Path;
using cbindgen_private::Rectangle;
using cbindgen_private::Text;
using cbindgen_private::TouchArea;
using cbindgen_private::Window;
constexpr inline ItemTreeNode make_item_node(std::uintptr_t offset,
const internal::ItemVTable *vtable,
const cbindgen_private::ItemVTable *vtable,
uint32_t child_count, uint32_t child_index)
{
return ItemTreeNode { ItemTreeNode::Item_Body {
@ -103,9 +103,9 @@ constexpr inline ItemTreeNode make_dyn_node(std::uintptr_t offset)
ItemTreeNode::Tag::DynamicTree, offset } };
}
using internal::sixtyfps_visit_item_tree;
using internal::MouseEvent;
using internal::InputEventResult;
using cbindgen_private::sixtyfps_visit_item_tree;
using cbindgen_private::MouseEvent;
using cbindgen_private::InputEventResult;
template<typename GetDynamic>
inline InputEventResult process_input_event(
ComponentRef component, int64_t &mouse_grabber, MouseEvent mouse_event,
@ -114,7 +114,7 @@ inline InputEventResult process_input_event(
if (mouse_grabber != -1) {
auto item_index = mouse_grabber & 0xffffffff;
auto rep_index = mouse_grabber >> 32;
auto offset = internal::sixtyfps_item_offset(component, tree, item_index);
auto offset = cbindgen_private::sixtyfps_item_offset(component, tree, item_index);
mouse_event.pos = { mouse_event.pos.x - offset.x , mouse_event.pos.y - offset.y };
const auto &item_node = tree.ptr[item_index];
InputEventResult result = InputEventResult::EventIgnored;
@ -136,18 +136,18 @@ inline InputEventResult process_input_event(
}
return result;
} else {
return internal::sixtyfps_process_ungrabbed_mouse_event(component, mouse_event, &mouse_grabber);
return cbindgen_private::sixtyfps_process_ungrabbed_mouse_event(component, mouse_event, &mouse_grabber);
}
}
// layouts:
using internal::grid_layout_info;
using internal::GridLayoutCellData;
using internal::GridLayoutData;
using internal::PathLayoutData;
using internal::PathLayoutItemData;
using internal::solve_grid_layout;
using internal::solve_path_layout;
using cbindgen_private::grid_layout_info;
using cbindgen_private::GridLayoutCellData;
using cbindgen_private::GridLayoutData;
using cbindgen_private::PathLayoutData;
using cbindgen_private::PathLayoutItemData;
using cbindgen_private::solve_grid_layout;
using cbindgen_private::solve_path_layout;
// models

View file

@ -38,22 +38,22 @@ public:
friend bool operator!=(const Color &lhs, const Color &rhs) { return !(lhs == rhs); }
private:
internal::types::Color inner;
cbindgen_private::types::Color inner;
};
template<>
void Property<Color>::set_animated_value(const Color &new_value,
const internal::PropertyAnimation &animation_data)
const cbindgen_private::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_value_color(&inner, value, new_value, &animation_data);
cbindgen_private::sixtyfps_property_set_animated_value_color(&inner, value, new_value, &animation_data);
}
template<>
template<typename F>
void Property<Color>::set_animated_binding(F binding,
const internal::PropertyAnimation &animation_data)
const cbindgen_private::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_binding_color(
cbindgen_private::sixtyfps_property_set_animated_binding_color(
&inner,
[](void *user_data, Color *value) {
*reinterpret_cast<Color *>(value) = (*reinterpret_cast<F *>(user_data))();

View file

@ -15,16 +15,16 @@ LICENSE END */
namespace sixtyfps {
using internal::types::PathArcTo;
using internal::types::PathElement;
using internal::types::PathEvent;
using internal::types::PathLineTo;
using internal::types::Point;
using cbindgen_private::types::PathArcTo;
using cbindgen_private::types::PathElement;
using cbindgen_private::types::PathEvent;
using cbindgen_private::types::PathLineTo;
using cbindgen_private::types::Point;
struct PathData
{
public:
using Tag = internal::types::PathData::Tag;
using Tag = cbindgen_private::types::PathData::Tag;
PathData() : data(Data::None()) { }
PathData(const PathElement *firstElement, size_t count)
@ -47,7 +47,7 @@ private:
return tmp;
}
static internal::types::PathData events_from_array(const PathEvent *firstEvent,
static cbindgen_private::types::PathData events_from_array(const PathEvent *firstEvent,
size_t event_count,
const Point *firstCoordinate,
size_t coordinate_count)
@ -59,7 +59,7 @@ private:
return Data::Events(events, coordinates);
}
using Data = internal::types::PathData;
using Data = cbindgen_private::types::PathData;
Data data;
};

View file

@ -12,7 +12,7 @@ LICENSE END */
#include <string_view>
namespace sixtyfps {
namespace internal {
namespace cbindgen_private {
struct PropertyAnimation;
}
}
@ -24,13 +24,13 @@ namespace sixtyfps {
template<typename T>
struct Property
{
Property() { internal::sixtyfps_property_init(&inner); }
~Property() { internal::sixtyfps_property_drop(&inner); }
Property() { cbindgen_private::sixtyfps_property_init(&inner); }
~Property() { cbindgen_private::sixtyfps_property_drop(&inner); }
Property(const Property &) = delete;
Property(Property &&) = delete;
Property &operator=(const Property &) = delete;
explicit Property(const T &value) : value(value) {
internal::sixtyfps_property_init(&inner);
cbindgen_private::sixtyfps_property_init(&inner);
}
/* Should it be implicit?
@ -41,19 +41,19 @@ struct Property
void set(const T &value) const
{
this->value = value;
internal::sixtyfps_property_set_changed(&inner);
cbindgen_private::sixtyfps_property_set_changed(&inner);
}
const T &get() const
{
internal::sixtyfps_property_update(&inner, &value);
cbindgen_private::sixtyfps_property_update(&inner, &value);
return value;
}
template<typename F>
void set_binding(F binding) const
{
internal::sixtyfps_property_set_binding(
cbindgen_private::sixtyfps_property_set_binding(
&inner,
[](void *user_data, void *value) {
*reinterpret_cast<T *>(value) = (*reinterpret_cast<F *>(user_data))();
@ -62,35 +62,35 @@ struct Property
}
inline void set_animated_value(const T &value,
const internal::PropertyAnimation &animation_data);
const cbindgen_private::PropertyAnimation &animation_data);
template<typename F>
inline void set_animated_binding(F binding, const internal::PropertyAnimation &animation_data);
inline void set_animated_binding(F binding, const cbindgen_private::PropertyAnimation &animation_data);
private:
internal::PropertyHandleOpaque inner;
cbindgen_private::PropertyHandleOpaque inner;
mutable T value{};
};
template<>
void Property<int32_t>::set_animated_value(const int32_t &new_value,
const internal::PropertyAnimation &animation_data)
const cbindgen_private::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_value_int(&inner, value, new_value, &animation_data);
cbindgen_private::sixtyfps_property_set_animated_value_int(&inner, value, new_value, &animation_data);
}
template<>
void Property<float>::set_animated_value(const float &new_value,
const internal::PropertyAnimation &animation_data)
const cbindgen_private::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_value_float(&inner, value, new_value, &animation_data);
cbindgen_private::sixtyfps_property_set_animated_value_float(&inner, value, new_value, &animation_data);
}
template<>
template<typename F>
void Property<int32_t>::set_animated_binding(F binding,
const internal::PropertyAnimation &animation_data)
const cbindgen_private::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_binding_int(
cbindgen_private::sixtyfps_property_set_animated_binding_int(
&inner,
[](void *user_data, int32_t *value) {
*reinterpret_cast<int32_t *>(value) = (*reinterpret_cast<F *>(user_data))();
@ -102,9 +102,9 @@ void Property<int32_t>::set_animated_binding(F binding,
template<>
template<typename F>
void Property<float>::set_animated_binding(F binding,
const internal::PropertyAnimation &animation_data)
const cbindgen_private::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_binding_float(
cbindgen_private::sixtyfps_property_set_animated_binding_float(
&inner,
[](void *user_data, float *value) {
*reinterpret_cast<float *>(value) = (*reinterpret_cast<F *>(user_data))();
@ -115,18 +115,18 @@ void Property<float>::set_animated_binding(F binding,
struct PropertyTracker
{
PropertyTracker() { internal::sixtyfps_property_tracker_init(&inner); }
~PropertyTracker() { internal::sixtyfps_property_tracker_drop(&inner); }
PropertyTracker() { cbindgen_private::sixtyfps_property_tracker_init(&inner); }
~PropertyTracker() { cbindgen_private::sixtyfps_property_tracker_drop(&inner); }
PropertyTracker(const PropertyTracker &) = delete;
PropertyTracker &operator=(const PropertyTracker &) = delete;
bool is_dirty() const {
return internal::sixtyfps_property_tracker_is_dirty(&inner);
return cbindgen_private::sixtyfps_property_tracker_is_dirty(&inner);
}
template<typename F>
void evaluate(const F &f) const {
internal::sixtyfps_property_tracker_evaluate(
cbindgen_private::sixtyfps_property_tracker_evaluate(
&inner,
[](void *f){ (*reinterpret_cast<const F*>(f))(); },
const_cast<F*>(&f)
@ -134,7 +134,7 @@ struct PropertyTracker
}
private:
internal::PropertyTrackerOpaque inner;
cbindgen_private::PropertyTrackerOpaque inner;
};
} // namespace sixtyfps

View file

@ -18,13 +18,13 @@ namespace sixtyfps {
struct Resource
{
public:
using Tag = internal::types::Resource::Tag;
using Tag = cbindgen_private::types::Resource::Tag;
Resource() : data(Data::None()) { }
Resource(const SharedString &file_path) : data(Data::AbsoluteFilePath(file_path)) { }
private:
using Data = internal::types::Resource;
using Data = cbindgen_private::types::Resource;
Data data;
};

View file

@ -18,23 +18,23 @@ struct SharedArray
{
SharedArray()
{
internal::sixtyfps_shared_array_new_null(reinterpret_cast<SharedArray<uint8_t> *>(this));
cbindgen_private::sixtyfps_shared_array_new_null(reinterpret_cast<SharedArray<uint8_t> *>(this));
}
SharedArray(const SharedArray &other)
{
internal::sixtyfps_shared_array_clone(
cbindgen_private::sixtyfps_shared_array_clone(
reinterpret_cast<SharedArray<uint8_t> *>(this),
reinterpret_cast<const SharedArray<uint8_t> *>(&other));
}
~SharedArray()
{
internal::sixtyfps_shared_array_drop(reinterpret_cast<SharedArray<uint8_t> *>(this));
cbindgen_private::sixtyfps_shared_array_drop(reinterpret_cast<SharedArray<uint8_t> *>(this));
}
SharedArray &operator=(const SharedArray &other)
{
internal::sixtyfps_shared_array_drop(reinterpret_cast<SharedArray<uint8_t> *>(this));
internal::sixtyfps_shared_array_clone(
cbindgen_private::sixtyfps_shared_array_drop(reinterpret_cast<SharedArray<uint8_t> *>(this));
cbindgen_private::sixtyfps_shared_array_clone(
reinterpret_cast<SharedArray<uint8_t> *>(this),
reinterpret_cast<const SharedArray<uint8_t> *>(&other));
return *this;

View file

@ -17,8 +17,8 @@ namespace sixtyfps {
// template<typename... Args>
struct Signal
{
Signal() { internal::sixtyfps_signal_init(&inner); }
~Signal() { internal::sixtyfps_signal_drop(&inner); }
Signal() { cbindgen_private::sixtyfps_signal_init(&inner); }
~Signal() { cbindgen_private::sixtyfps_signal_drop(&inner); }
Signal(const Signal &) = delete;
Signal(Signal &&) = delete;
Signal &operator=(const Signal &) = delete;
@ -26,7 +26,7 @@ struct Signal
template<typename F>
void set_handler(F binding)
{
internal::sixtyfps_signal_set_handler(
cbindgen_private::sixtyfps_signal_set_handler(
&inner,
[](void *user_data) {
(*reinterpret_cast<F *>(user_data))();
@ -36,10 +36,10 @@ struct Signal
void emit() const
{
internal::sixtyfps_signal_emit(&inner);
cbindgen_private::sixtyfps_signal_emit(&inner);
}
private:
internal::SignalOpaque inner;
cbindgen_private::SignalOpaque inner;
};
}

View file

@ -16,27 +16,27 @@ namespace sixtyfps {
struct SharedString
{
SharedString() { internal::sixtyfps_shared_string_from_bytes(this, "", 0); }
SharedString() { cbindgen_private::sixtyfps_shared_string_from_bytes(this, "", 0); }
SharedString(std::string_view s)
{
internal::sixtyfps_shared_string_from_bytes(this, s.data(), s.size());
cbindgen_private::sixtyfps_shared_string_from_bytes(this, s.data(), s.size());
}
SharedString(const char *s) : SharedString(std::string_view(s)) { }
SharedString(const SharedString &other)
{
internal::sixtyfps_shared_string_clone(this, &other);
cbindgen_private::sixtyfps_shared_string_clone(this, &other);
}
~SharedString() { internal::sixtyfps_shared_string_drop(this); }
~SharedString() { cbindgen_private::sixtyfps_shared_string_drop(this); }
SharedString &operator=(const SharedString &other)
{
internal::sixtyfps_shared_string_drop(this);
internal::sixtyfps_shared_string_clone(this, &other);
cbindgen_private::sixtyfps_shared_string_drop(this);
cbindgen_private::sixtyfps_shared_string_clone(this, &other);
return *this;
}
SharedString &operator=(std::string_view s)
{
internal::sixtyfps_shared_string_drop(this);
internal::sixtyfps_shared_string_from_bytes(this, s.data(), s.size());
cbindgen_private::sixtyfps_shared_string_drop(this);
cbindgen_private::sixtyfps_shared_string_from_bytes(this, s.data(), s.size());
return *this;
}
SharedString &operator=(SharedString &&other)
@ -45,8 +45,8 @@ struct SharedString
return *this;
}
operator std::string_view() const { return internal::sixtyfps_shared_string_bytes(this); }
auto data() const -> const char * { return internal::sixtyfps_shared_string_bytes(this); }
operator std::string_view() const { return cbindgen_private::sixtyfps_shared_string_bytes(this); }
auto data() const -> const char * { return cbindgen_private::sixtyfps_shared_string_bytes(this); }
static SharedString from_number(double n) { return SharedString(n); }
@ -61,7 +61,7 @@ struct SharedString
private:
/// Use SharedString::from_number
explicit SharedString(double n) { internal::sixtyfps_shared_string_from_number(this, n); }
explicit SharedString(double n) { cbindgen_private::sixtyfps_shared_string_from_number(this, n); }
void *inner; // opaque
};
}

View file

@ -15,10 +15,10 @@ LICENSE END */
namespace sixtyfps::testing {
inline void mock_elapsed_time(int64_t time_in_ms)
{
internal::sixtyfps_mock_elapsed_time(time_in_ms);
cbindgen_private::sixtyfps_mock_elapsed_time(time_in_ms);
}
template<typename Component>
inline void send_mouse_click(Component &component, float x, float y) {
internal::sixtyfps_send_mouse_click({&Component::component_type, &component}, x, y);
cbindgen_private::sixtyfps_send_mouse_click({&Component::component_type, &component}, x, y);
}
} // namespace sixtyfps

View file

@ -251,7 +251,7 @@ fn property_animation_code(
) -> Option<String> {
if let Some(animation) = element.property_animations.get(property_name) {
Some(new_struct_with_bindings(
"sixtyfps::internal::PropertyAnimation",
"sixtyfps::cbindgen_private::PropertyAnimation",
&animation.borrow().bindings,
component,
))
@ -658,7 +658,7 @@ fn generate_component(
Access::Public,
Declaration::Function(Function {
name: "root_item".into(),
signature: "() -> VRef<sixtyfps::internal::ItemVTable>".into(),
signature: "() -> VRef<sixtyfps::cbindgen_private::ItemVTable>".into(),
statements: Some(vec![format!(
"return {{ &sixtyfps::{vt}, &this->{id} }};",
vt = root_elem.base_type.as_native().vtable_symbol,

View file

@ -60,7 +60,7 @@ fn main() {
let mut config = cbindgen::Config {
pragma_once: true,
include_version: true,
namespaces: Some(vec!["sixtyfps".into(), "internal".into()]),
namespaces: Some(vec!["sixtyfps".into(), "cbindgen_private".into()]),
line_length: 100,
tab_width: 4,
// Note: we might need to switch to C if we need to generate bindings for language that needs C headers
@ -153,7 +153,7 @@ fn main() {
// Put the rust type in a deeper "types" namespace, so the use of same type in for example generated
// Property<> fields uses the public `sixtyfps::Blah` type
special_config.namespaces =
Some(vec!["sixtyfps".into(), "internal".into(), "types".into()]);
Some(vec!["sixtyfps".into(), "cbindgen_private".into(), "types".into()]);
cbindgen::Builder::new()
.with_config(special_config)
.with_src(crate_dir.join("graphics.rs"))

View file

@ -17,7 +17,7 @@ fn main() {
let config = cbindgen::Config {
pragma_once: true,
include_version: true,
namespaces: Some(vec!["sixtyfps".into(), "internal".into()]),
namespaces: Some(vec!["sixtyfps".into(), "cbindgen_private".into()]),
line_length: 100,
tab_width: 4,
// Note: we might need to switch to C if we need to generate bindings for language that needs C headers