diff --git a/api/sixtyfps-cpp/cbindgen.rs b/api/sixtyfps-cpp/cbindgen.rs index d904aa599..ca8e77153 100644 --- a/api/sixtyfps-cpp/cbindgen.rs +++ b/api/sixtyfps-cpp/cbindgen.rs @@ -352,7 +352,12 @@ fn gen_corelib( config.export.body.insert( "LayoutInfo".to_owned(), " inline LayoutInfo merge(const LayoutInfo &other) const; - friend inline LayoutInfo operator+(const LayoutInfo &a, const LayoutInfo &b) { return a.merge(b); }".into(), + friend inline LayoutInfo operator+(const LayoutInfo &a, const LayoutInfo &b) { return a.merge(b); } + friend bool operator==(const LayoutInfo&, const LayoutInfo&) = default;".into(), + ); + config.export.body.insert( + "StandardListViewItem".to_owned(), + "friend bool operator==(const StandardListViewItem&, const StandardListViewItem&) = default;".into(), ); config .export diff --git a/api/sixtyfps-cpp/include/sixtyfps.h b/api/sixtyfps-cpp/include/sixtyfps.h index 30c3a5754..cf0a6f403 100644 --- a/api/sixtyfps-cpp/include/sixtyfps.h +++ b/api/sixtyfps-cpp/include/sixtyfps.h @@ -54,6 +54,7 @@ using ItemTreeNode = cbindgen_private::ItemTreeNode; using cbindgen_private::KeyboardModifiers; using cbindgen_private::KeyEvent; using cbindgen_private::PointerEvent; +using cbindgen_private::StandardListViewItem; /// Internal function that checks that the API that must be called from the main /// thread is indeed called from the main thread, or abort the program otherwise @@ -393,18 +394,6 @@ inline LayoutInfo LayoutInfo::merge(const LayoutInfo &other) const std::max(preferred, other.preferred), std::min(stretch, other.stretch) }; } - -/// FIXME! this should be done by cbindgen -inline bool operator==(const LayoutInfo &a, const LayoutInfo &b) -{ - return a.min == b.min && a.max == b.max && a.min_percent == b.min_percent - && a.max_percent == b.max_percent && a.preferred == b.preferred - && a.stretch == b.stretch; -} -inline bool operator!=(const LayoutInfo &a, const LayoutInfo &b) -{ - return !(a == b); -} } namespace private_api { @@ -821,20 +810,6 @@ cbindgen_private::NativeStyleMetrics::~NativeStyleMetrics() } #endif // !defined(DOXYGEN) -using cbindgen_private::StandardListViewItem; -namespace cbindgen_private { -inline bool operator==(const StandardListViewItem &a, const StandardListViewItem &b) -{ - static_assert(sizeof(StandardListViewItem) == sizeof(std::tuple), - "must update to cover all fields"); - return a.text == b.text; -} -inline bool operator!=(const StandardListViewItem &a, const StandardListViewItem &b) -{ - return !(a == b); -} -} - namespace private_api { // Code generated by SixtyFPS <= 0.1.5 uses this enum with VersionCheckHelper enum class [[deprecated]] VersionCheck { Major = SIXTYFPS_VERSION_MAJOR, diff --git a/api/sixtyfps-cpp/include/sixtyfps_color.h b/api/sixtyfps-cpp/include/sixtyfps_color.h index 4d9a03373..318bd6d8e 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_color.h +++ b/api/sixtyfps-cpp/include/sixtyfps_color.h @@ -149,15 +149,7 @@ public: /// Returns true if \a lhs has the same values for the individual color channels as \a rhs; /// false otherwise. - friend bool operator==(const Color &lhs, const Color &rhs) - { - return lhs.inner.red == rhs.inner.red && lhs.inner.green == rhs.inner.green - && lhs.inner.blue == rhs.inner.blue && lhs.inner.alpha == rhs.inner.alpha; - } - - /// Returns true if \a lhs has any different values for the individual color channels as \a rhs; - /// false otherwise. - friend bool operator!=(const Color &lhs, const Color &rhs) { return !(lhs == rhs); } + friend bool operator==(const Color &lhs, const Color &rhs) = default; /// Writes the \a color to the specified \a stream and returns a reference to the /// stream. diff --git a/api/sixtyfps-cpp/include/sixtyfps_interpreter.h b/api/sixtyfps-cpp/include/sixtyfps_interpreter.h index 19caf154c..6c3e0137a 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_interpreter.h +++ b/api/sixtyfps-cpp/include/sixtyfps_interpreter.h @@ -400,12 +400,6 @@ public: { return cbindgen_private::sixtyfps_interpreter_value_eq(&a.inner, &b.inner); } - /// Returns true if \a and \b hold values of the same type and the underlying vales are not - /// equal. - friend bool operator!=(const Value &a, const Value &b) - { - return !cbindgen_private::sixtyfps_interpreter_value_eq(&a.inner, &b.inner); - } private: inline Value(const void *) = delete; // Avoid that for example Value("foo") turns to Value(bool) diff --git a/api/sixtyfps-cpp/include/sixtyfps_pathdata.h b/api/sixtyfps-cpp/include/sixtyfps_pathdata.h index 4727db7a0..a522c9043 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_pathdata.h +++ b/api/sixtyfps-cpp/include/sixtyfps_pathdata.h @@ -42,23 +42,7 @@ public: { } - friend bool operator==(const PathData &a, const PathData &b) - { - if (a.data.tag != b.data.tag) - return false; - switch (a.data.tag) { - case cbindgen_private::types::PathData::Tag::Elements: - return a.data.elements._0 == b.data.elements._0; - case cbindgen_private::types::PathData::Tag::Events: - return a.data.events._0 == b.data.events._0 && b.data.events._0 == b.data.events._0; - case cbindgen_private::types::PathData::Tag::Commands: - return a.data.commands._0 == b.data.commands._0; - case cbindgen_private::types::PathData::Tag::None: - return true; - } - return false; // unreachable - } - friend bool operator!=(const PathData &a, const PathData &b) { return !(a == b); } + friend bool operator==(const PathData &a, const PathData &b) = default; private: static SharedVector elements_from_array(const PathElement *firstElement, diff --git a/sixtyfps_compiler/builtins.60 b/sixtyfps_compiler/builtins.60 index b6ef7d651..d17afa5b1 100644 --- a/sixtyfps_compiler/builtins.60 +++ b/sixtyfps_compiler/builtins.60 @@ -415,7 +415,7 @@ PropertyAnimation := _ { } export struct StandardListViewItem := { - //-name:sixtyfps::StandardListViewItem + //-name:sixtyfps::private_api::StandardListViewItem text: string } diff --git a/sixtyfps_compiler/generator/cpp.rs b/sixtyfps_compiler/generator/cpp.rs index 925be00ae..b5d02dde0 100644 --- a/sixtyfps_compiler/generator/cpp.rs +++ b/sixtyfps_compiler/generator/cpp.rs @@ -565,11 +565,9 @@ pub fn generate(doc: &Document) -> impl std::fmt::Display { } fn generate_struct(file: &mut File, name: &str, fields: &BTreeMap) { - let mut operator_eq = String::new(); let mut members = fields .iter() .map(|(name, t)| { - write!(operator_eq, " && a.{0} == b.{0}", ident(name)).unwrap(); ( Access::Public, Declaration::Var(Var { @@ -588,22 +586,13 @@ fn generate_struct(file: &mut File, name: &str, fields: &BTreeMap) Access::Public, Declaration::Function(Function { name: "operator==".to_owned(), - signature: format!("(const {0} &a, const {0} &b) -> bool", name), + signature: format!("(const {0} &a, const {0} &b) -> bool = default", name), is_friend: true, - statements: Some(vec![format!("return true{};", operator_eq)]), - ..Function::default() - }), - )); - members.push(( - Access::Public, - Declaration::Function(Function { - name: "operator!=".to_owned(), - signature: format!("(const {0} &a, const {0} &b) -> bool", name), - is_friend: true, - statements: Some(vec!["return !(a == b);".into()]), + statements: None, ..Function::default() }), )); + file.declarations.push(Declaration::Struct(Struct { name: name.into(), members, diff --git a/sixtyfps_runtime/corelib/layout.rs b/sixtyfps_runtime/corelib/layout.rs index 2d5aa0898..c4748f424 100644 --- a/sixtyfps_runtime/corelib/layout.rs +++ b/sixtyfps_runtime/corelib/layout.rs @@ -19,7 +19,6 @@ pub enum Orientation { type Coord = f32; /// The constraint that applies to an item -// NOTE: when adding new fields, the C++ operator== also need updates // Also, the field needs to be in alphabetical order because how the generated code sort fields for struct #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq)]