diff --git a/api/cpp/include/slint-interpreter.h b/api/cpp/include/slint-interpreter.h index a86836e91..f640116d8 100644 --- a/api/cpp/include/slint-interpreter.h +++ b/api/cpp/include/slint-interpreter.h @@ -192,10 +192,7 @@ public: } /// Returns an iterator that when compared with an iterator returned by begin() can be /// used to detect when all fields have been visited. - iterator end() const - { - return iterator(); - } + iterator end() const { return iterator(); } /// Returns the value of the field with the given \a name; Returns an std::optional without /// value if the field does not exist. @@ -405,8 +402,8 @@ private: inline Value::Value(const slint::SharedVector &array) : inner(cbindgen_private::slint_interpreter_value_new_array_model( - reinterpret_cast *>( - &array))) + reinterpret_cast *>( + &array))) { } @@ -699,15 +696,16 @@ public: // clang-format on { using namespace cbindgen_private; - auto actual_cb = [](void *data, - cbindgen_private::Slice> - arg) { - std::span args_view { reinterpret_cast(arg.ptr), arg.len }; - Value r = (*reinterpret_cast(data))(args_view); - auto inner = r.inner; - r.inner = cbindgen_private::slint_interpreter_value_new(); - return inner; - }; + auto actual_cb = + [](void *data, + cbindgen_private::Slice> arg) { + std::span args_view { reinterpret_cast(arg.ptr), + arg.len }; + Value r = (*reinterpret_cast(data))(args_view); + auto inner = r.inner; + r.inner = cbindgen_private::slint_interpreter_value_new(); + return inner; + }; return cbindgen_private::slint_interpreter_component_instance_set_callback( inner(), slint::private_api::string_to_slice(name), actual_cb, new F(std::move(callback)), [](void *data) { delete reinterpret_cast(data); }); @@ -773,15 +771,16 @@ public: bool set_global_callback(std::string_view global, std::string_view name, F callback) const { using namespace cbindgen_private; - auto actual_cb = [](void *data, - cbindgen_private::Slice> - arg) { - std::span args_view { reinterpret_cast(arg.ptr), arg.len }; - Value r = (*reinterpret_cast(data))(args_view); - auto inner = r.inner; - r.inner = cbindgen_private::slint_interpreter_value_new(); - return inner; - }; + auto actual_cb = + [](void *data, + cbindgen_private::Slice> arg) { + std::span args_view { reinterpret_cast(arg.ptr), + arg.len }; + Value r = (*reinterpret_cast(data))(args_view); + auto inner = r.inner; + r.inner = cbindgen_private::slint_interpreter_value_new(); + return inner; + }; return cbindgen_private::slint_interpreter_component_instance_set_global_callback( inner(), slint::private_api::string_to_slice(global), slint::private_api::string_to_slice(name), actual_cb, new F(std::move(callback)), diff --git a/api/cpp/include/slint-platform.h b/api/cpp/include/slint-platform.h index d9dad4360..0c252d9e3 100644 --- a/api/cpp/include/slint-platform.h +++ b/api/cpp/include/slint-platform.h @@ -392,10 +392,7 @@ public: /// Returns a copy of text stored in the system clipboard, if any. /// /// If the platform doesn't support the specified clipboard, the function should return nullopt - virtual std::optional clipboard_text(Clipboard) - { - return {}; - } + virtual std::optional clipboard_text(Clipboard) { return {}; } /// Spins an event loop and renders the visible windows. virtual void run_event_loop() { } @@ -698,10 +695,9 @@ public: /// to fill it with pixels. After the line buffer is filled with pixels, your implementation is /// free to flush that line to the screen for display. template - requires requires(Callback callback) - { - callback(size_t(0), size_t(0), size_t(0), [&callback](std::span) {}); - } + requires requires(Callback callback) { + callback(size_t(0), size_t(0), size_t(0), [&callback](std::span) {}); + } PhysicalRegion render_by_line(Callback process_line_callback) const { auto r = cbindgen_private::slint_software_renderer_render_by_line_rgb565( diff --git a/api/cpp/include/slint.h b/api/cpp/include/slint.h index b21dd7d29..d80b37b19 100644 --- a/api/cpp/include/slint.h +++ b/api/cpp/include/slint.h @@ -345,18 +345,12 @@ public: /// \private /// Internal function called by the view to register itself - void attach_peer(private_api::ModelPeer p) - { - peers.push_back(std::move(p)); - } + void attach_peer(private_api::ModelPeer p) { peers.push_back(std::move(p)); } /// \private /// Internal function called from within bindings to register with the currently /// evaluating dependency and get notified when this model's row count changes. - void track_row_count_changes() const - { - model_row_count_dirty_property.get(); - } + void track_row_count_changes() const { model_row_count_dirty_property.get(); } /// \private /// Internal function called from within bindings to register with the currently @@ -701,7 +695,7 @@ public: FilterModel(std::shared_ptr> source_model, std::function filter_fn) : inner(std::make_shared>( - std::move(source_model), std::move(filter_fn), *this)) + std::move(source_model), std::move(filter_fn), *this)) { inner->source_model->attach_peer(inner); } @@ -789,7 +783,7 @@ public: MapModel(std::shared_ptr> source_model, std::function map_fn) : inner(std::make_shared>( - *this)), + *this)), model(source_model), map_fn(map_fn) { diff --git a/api/cpp/include/slint_color.h b/api/cpp/include/slint_color.h index 2d11ee476..4b626a294 100644 --- a/api/cpp/include/slint_color.h +++ b/api/cpp/include/slint_color.h @@ -211,10 +211,7 @@ public: #if !defined(DOXYGEN) // FIXME: we need this to create GradientStop - operator const cbindgen_private::types::Color &() const - { - return inner; - } + operator const cbindgen_private::types::Color &() const { return inner; } #endif private: diff --git a/api/cpp/include/slint_image.h b/api/cpp/include/slint_image.h index 4d4cacf60..5cb512636 100644 --- a/api/cpp/include/slint_image.h +++ b/api/cpp/include/slint_image.h @@ -173,32 +173,29 @@ public: /// Construct an image from a SharedPixelBuffer of RGB pixels. Image(SharedPixelBuffer buffer) : data(Data::ImageInner_EmbeddedImage( - cbindgen_private::types::ImageCacheKey::Invalid(), - cbindgen_private::types::SharedImageBuffer::RGB8( - cbindgen_private::types::SharedPixelBuffer { - .width = buffer.width(), - .height = buffer.height(), - .data = buffer.m_data }))) + cbindgen_private::types::ImageCacheKey::Invalid(), + cbindgen_private::types::SharedImageBuffer::RGB8( + cbindgen_private::types::SharedPixelBuffer { + .width = buffer.width(), + .height = buffer.height(), + .data = buffer.m_data }))) { } /// Construct an image from a SharedPixelBuffer of RGBA pixels. Image(SharedPixelBuffer buffer) : data(Data::ImageInner_EmbeddedImage( - cbindgen_private::types::ImageCacheKey::Invalid(), - cbindgen_private::types::SharedImageBuffer::RGBA8( - cbindgen_private::types::SharedPixelBuffer { - .width = buffer.width(), - .height = buffer.height(), - .data = buffer.m_data }))) + cbindgen_private::types::ImageCacheKey::Invalid(), + cbindgen_private::types::SharedImageBuffer::RGBA8( + cbindgen_private::types::SharedPixelBuffer { + .width = buffer.width(), + .height = buffer.height(), + .data = buffer.m_data }))) { } /// Returns the size of the Image in pixels. - Size size() const - { - return cbindgen_private::types::slint_image_size(&data); - } + Size size() const { return cbindgen_private::types::slint_image_size(&data); } /// Returns the path of the image on disk, if it was constructed via Image::load_from_path(). std::optional path() const @@ -227,10 +224,7 @@ public: return cbindgen_private::types::slint_image_compare_equal(&a.data, &b.data); } /// Returns false if \a a refers to the same image as \a b; true otherwise. - friend bool operator!=(const Image &a, const Image &b) - { - return !(a == b); - } + friend bool operator!=(const Image &a, const Image &b) { return !(a == b); } /// \private explicit Image(cbindgen_private::types::Image inner) : data(inner) { } diff --git a/api/cpp/include/slint_sharedvector.h b/api/cpp/include/slint_sharedvector.h index b24de9c07..e0d755251 100644 --- a/api/cpp/include/slint_sharedvector.h +++ b/api/cpp/include/slint_sharedvector.h @@ -19,7 +19,7 @@ struct SharedVector /// Creates a new, empty vector. SharedVector() : inner(const_cast(reinterpret_cast( - cbindgen_private::slint_shared_vector_empty()))) + cbindgen_private::slint_shared_vector_empty()))) { } diff --git a/api/cpp/include/slint_string.h b/api/cpp/include/slint_string.h index 4ac9e1fcf..c89a04c6c 100644 --- a/api/cpp/include/slint_string.h +++ b/api/cpp/include/slint_string.h @@ -49,10 +49,7 @@ struct SharedString } /// Destroys this SharedString and frees the memory if this is the last instance /// referencing it. - ~SharedString() - { - cbindgen_private::slint_shared_string_drop(this); - } + ~SharedString() { cbindgen_private::slint_shared_string_drop(this); } /// Assigns \a other to this string and returns a reference to this string. SharedString &operator=(const SharedString &other) { @@ -71,10 +68,7 @@ struct SharedString /// Assigns null-terminated string pointer \a s to this string and returns a reference /// to this string. The underlying string data is copied. It is assumed that the string /// is UTF-8 encoded. - SharedString &operator=(const char *s) - { - return *this = std::string_view(s); - } + SharedString &operator=(const char *s) { return *this = std::string_view(s); } /// Move-assigns \a other to this SharedString instance. SharedString &operator=(SharedString &&other) @@ -85,23 +79,14 @@ struct SharedString /// Provides a view to the string data. The returned view is only valid as long as at /// least this SharedString exists. - operator std::string_view() const - { - return cbindgen_private::slint_shared_string_bytes(this); - } + operator std::string_view() const { return cbindgen_private::slint_shared_string_bytes(this); } /// Provides a raw pointer to the string data. The returned pointer is only valid as long as at /// least this SharedString exists. - auto data() const -> const char * - { - return cbindgen_private::slint_shared_string_bytes(this); - } + auto data() const -> const char * { return cbindgen_private::slint_shared_string_bytes(this); } /// Returns a pointer to the first character. It is only safe to dereference the pointer if the /// string contains at least one character. - const char *begin() const - { - return data(); - } + const char *begin() const { return data(); } /// Returns a point past the last character of the string. It is not safe to dereference the /// pointer, but it is suitable for comparison. const char *end() const @@ -111,10 +96,7 @@ struct SharedString } /// \return true if the string contains no characters; false otherwise. - bool empty() const - { - return std::string_view(*this).empty(); - } + bool empty() const { return std::string_view(*this).empty(); } /// \return true if the string starts with the specified prefix string; false otherwise bool starts_with(std::string_view prefix) const @@ -141,10 +123,7 @@ struct SharedString /// auto str = slint::SharedString::from_number(42); // creates "42" /// auto str2 = slint::SharedString::from_number(100.5) // creates "100.5" /// \endcode - static SharedString from_number(double n) - { - return SharedString(n); - } + static SharedString from_number(double n) { return SharedString(n); } /// Returns true if \a a is equal to \a b; otherwise returns false. friend bool operator==(const SharedString &a, const SharedString &b) @@ -206,10 +185,7 @@ struct SharedString private: /// Use SharedString::from_number - explicit SharedString(double n) - { - cbindgen_private::slint_shared_string_from_number(this, n); - } + explicit SharedString(double n) { cbindgen_private::slint_shared_string_from_number(this, n); } void *inner; // opaque }; diff --git a/api/cpp/include/slint_timer.h b/api/cpp/include/slint_timer.h index 3524726ac..3b146db9e 100644 --- a/api/cpp/include/slint_timer.h +++ b/api/cpp/include/slint_timer.h @@ -29,9 +29,9 @@ struct Timer template Timer(std::chrono::milliseconds interval, F callback) : id(cbindgen_private::slint_timer_start( - 0, TimerMode::Repeated, interval.count(), - [](void *data) { (*reinterpret_cast(data))(); }, new F(std::move(callback)), - [](void *data) { delete reinterpret_cast(data); })) + 0, TimerMode::Repeated, interval.count(), + [](void *data) { (*reinterpret_cast(data))(); }, new F(std::move(callback)), + [](void *data) { delete reinterpret_cast(data); })) { } Timer(const Timer &) = delete; diff --git a/api/cpp/include/vtable.h b/api/cpp/include/vtable.h index d6a00fb48..03738dad9 100644 --- a/api/cpp/include/vtable.h +++ b/api/cpp/include/vtable.h @@ -134,45 +134,21 @@ public: return VRc(inner); } - const X *operator->() const - { - return &inner->data; - } - const X &operator*() const - { - return inner->data; - } - X *operator->() - { - return &inner->data; - } - X &operator*() - { - return inner->data; - } + const X *operator->() const { return &inner->data; } + const X &operator*() const { return inner->data; } + X *operator->() { return &inner->data; } + X &operator*() { return inner->data; } const VRc &into_dyn() const { return *reinterpret_cast *>(this); } - VRef borrow() const - { - return { inner->vtable, inner->data_ptr() }; - } + VRef borrow() const { return { inner->vtable, inner->data_ptr() }; } - friend bool operator==(const VRc &a, const VRc &b) - { - return a.inner == b.inner; - } - friend bool operator!=(const VRc &a, const VRc &b) - { - return a.inner != b.inner; - } - const VTable *vtable() const - { - return inner->vtable; - } + friend bool operator==(const VRc &a, const VRc &b) { return a.inner == b.inner; } + friend bool operator!=(const VRc &a, const VRc &b) { return a.inner != b.inner; } + const VTable *vtable() const { return inner->vtable; } }; template diff --git a/examples/opengl_texture/main.cpp b/examples/opengl_texture/main.cpp index cc1feb0a2..0030149d6 100644 --- a/examples/opengl_texture/main.cpp +++ b/examples/opengl_texture/main.cpp @@ -53,7 +53,10 @@ static GLint compile_shader(GLuint program, GLuint shader_type, const GLchar *co glGetIntegerv(ParamName, (GLint *)&saved_value); \ BindingFn(TargetName, new_value); \ } \ - ~StructName() { BindingFn(TargetName, saved_value); } \ + ~StructName() \ + { \ + BindingFn(TargetName, saved_value); \ + } \ } DEFINE_SCOPED_BINDING(ScopedTextureBinding, GL_TEXTURE_BINDING_2D, glBindTexture, GL_TEXTURE_2D);