Re-run clang-format with version 18

This commit is contained in:
Simon Hausmann 2024-06-10 11:17:08 +02:00 committed by Simon Hausmann
parent 355a8ab62b
commit 650f19a33c
10 changed files with 70 additions and 135 deletions

View file

@ -192,10 +192,7 @@ public:
} }
/// Returns an iterator that when compared with an iterator returned by begin() can be /// Returns an iterator that when compared with an iterator returned by begin() can be
/// used to detect when all fields have been visited. /// used to detect when all fields have been visited.
iterator end() const iterator end() const { return iterator(); }
{
return iterator();
}
/// Returns the value of the field with the given \a name; Returns an std::optional without /// Returns the value of the field with the given \a name; Returns an std::optional without
/// value if the field does not exist. /// value if the field does not exist.
@ -405,8 +402,8 @@ private:
inline Value::Value(const slint::SharedVector<Value> &array) inline Value::Value(const slint::SharedVector<Value> &array)
: inner(cbindgen_private::slint_interpreter_value_new_array_model( : inner(cbindgen_private::slint_interpreter_value_new_array_model(
reinterpret_cast<const slint::SharedVector<slint::cbindgen_private::Value *> *>( reinterpret_cast<const slint::SharedVector<slint::cbindgen_private::Value *> *>(
&array))) &array)))
{ {
} }
@ -699,15 +696,16 @@ public:
// clang-format on // clang-format on
{ {
using namespace cbindgen_private; using namespace cbindgen_private;
auto actual_cb = [](void *data, auto actual_cb =
cbindgen_private::Slice<cbindgen_private::Box<cbindgen_private::Value>> [](void *data,
arg) { cbindgen_private::Slice<cbindgen_private::Box<cbindgen_private::Value>> arg) {
std::span<const Value> args_view { reinterpret_cast<const Value *>(arg.ptr), arg.len }; std::span<const Value> args_view { reinterpret_cast<const Value *>(arg.ptr),
Value r = (*reinterpret_cast<F *>(data))(args_view); arg.len };
auto inner = r.inner; Value r = (*reinterpret_cast<F *>(data))(args_view);
r.inner = cbindgen_private::slint_interpreter_value_new(); auto inner = r.inner;
return inner; r.inner = cbindgen_private::slint_interpreter_value_new();
}; return inner;
};
return cbindgen_private::slint_interpreter_component_instance_set_callback( return cbindgen_private::slint_interpreter_component_instance_set_callback(
inner(), slint::private_api::string_to_slice(name), actual_cb, inner(), slint::private_api::string_to_slice(name), actual_cb,
new F(std::move(callback)), [](void *data) { delete reinterpret_cast<F *>(data); }); new F(std::move(callback)), [](void *data) { delete reinterpret_cast<F *>(data); });
@ -773,15 +771,16 @@ public:
bool set_global_callback(std::string_view global, std::string_view name, F callback) const bool set_global_callback(std::string_view global, std::string_view name, F callback) const
{ {
using namespace cbindgen_private; using namespace cbindgen_private;
auto actual_cb = [](void *data, auto actual_cb =
cbindgen_private::Slice<cbindgen_private::Box<cbindgen_private::Value>> [](void *data,
arg) { cbindgen_private::Slice<cbindgen_private::Box<cbindgen_private::Value>> arg) {
std::span<const Value> args_view { reinterpret_cast<const Value *>(arg.ptr), arg.len }; std::span<const Value> args_view { reinterpret_cast<const Value *>(arg.ptr),
Value r = (*reinterpret_cast<F *>(data))(args_view); arg.len };
auto inner = r.inner; Value r = (*reinterpret_cast<F *>(data))(args_view);
r.inner = cbindgen_private::slint_interpreter_value_new(); auto inner = r.inner;
return inner; r.inner = cbindgen_private::slint_interpreter_value_new();
}; return inner;
};
return cbindgen_private::slint_interpreter_component_instance_set_global_callback( return cbindgen_private::slint_interpreter_component_instance_set_global_callback(
inner(), slint::private_api::string_to_slice(global), inner(), slint::private_api::string_to_slice(global),
slint::private_api::string_to_slice(name), actual_cb, new F(std::move(callback)), slint::private_api::string_to_slice(name), actual_cb, new F(std::move(callback)),

View file

@ -392,10 +392,7 @@ public:
/// Returns a copy of text stored in the system clipboard, if any. /// 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 /// If the platform doesn't support the specified clipboard, the function should return nullopt
virtual std::optional<SharedString> clipboard_text(Clipboard) virtual std::optional<SharedString> clipboard_text(Clipboard) { return {}; }
{
return {};
}
/// Spins an event loop and renders the visible windows. /// Spins an event loop and renders the visible windows.
virtual void run_event_loop() { } 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 /// 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. /// free to flush that line to the screen for display.
template<typename Callback> template<typename Callback>
requires requires(Callback callback) requires requires(Callback callback) {
{ callback(size_t(0), size_t(0), size_t(0), [&callback](std::span<Rgb565Pixel>) {});
callback(size_t(0), size_t(0), size_t(0), [&callback](std::span<Rgb565Pixel>) {}); }
}
PhysicalRegion render_by_line(Callback process_line_callback) const PhysicalRegion render_by_line(Callback process_line_callback) const
{ {
auto r = cbindgen_private::slint_software_renderer_render_by_line_rgb565( auto r = cbindgen_private::slint_software_renderer_render_by_line_rgb565(

View file

@ -345,18 +345,12 @@ public:
/// \private /// \private
/// Internal function called by the view to register itself /// Internal function called by the view to register itself
void attach_peer(private_api::ModelPeer p) void attach_peer(private_api::ModelPeer p) { peers.push_back(std::move(p)); }
{
peers.push_back(std::move(p));
}
/// \private /// \private
/// Internal function called from within bindings to register with the currently /// Internal function called from within bindings to register with the currently
/// evaluating dependency and get notified when this model's row count changes. /// evaluating dependency and get notified when this model's row count changes.
void track_row_count_changes() const void track_row_count_changes() const { model_row_count_dirty_property.get(); }
{
model_row_count_dirty_property.get();
}
/// \private /// \private
/// Internal function called from within bindings to register with the currently /// Internal function called from within bindings to register with the currently
@ -701,7 +695,7 @@ public:
FilterModel(std::shared_ptr<Model<ModelData>> source_model, FilterModel(std::shared_ptr<Model<ModelData>> source_model,
std::function<bool(const ModelData &)> filter_fn) std::function<bool(const ModelData &)> filter_fn)
: inner(std::make_shared<private_api::FilterModelInner<ModelData>>( : inner(std::make_shared<private_api::FilterModelInner<ModelData>>(
std::move(source_model), std::move(filter_fn), *this)) std::move(source_model), std::move(filter_fn), *this))
{ {
inner->source_model->attach_peer(inner); inner->source_model->attach_peer(inner);
} }
@ -789,7 +783,7 @@ public:
MapModel(std::shared_ptr<Model<SourceModelData>> source_model, MapModel(std::shared_ptr<Model<SourceModelData>> source_model,
std::function<MappedModelData(const SourceModelData &)> map_fn) std::function<MappedModelData(const SourceModelData &)> map_fn)
: inner(std::make_shared<private_api::MapModelInner<SourceModelData, MappedModelData>>( : inner(std::make_shared<private_api::MapModelInner<SourceModelData, MappedModelData>>(
*this)), *this)),
model(source_model), model(source_model),
map_fn(map_fn) map_fn(map_fn)
{ {

View file

@ -211,10 +211,7 @@ public:
#if !defined(DOXYGEN) #if !defined(DOXYGEN)
// FIXME: we need this to create GradientStop // FIXME: we need this to create GradientStop
operator const cbindgen_private::types::Color &() const operator const cbindgen_private::types::Color &() const { return inner; }
{
return inner;
}
#endif #endif
private: private:

View file

@ -173,32 +173,29 @@ public:
/// Construct an image from a SharedPixelBuffer of RGB pixels. /// Construct an image from a SharedPixelBuffer of RGB pixels.
Image(SharedPixelBuffer<Rgb8Pixel> buffer) Image(SharedPixelBuffer<Rgb8Pixel> buffer)
: data(Data::ImageInner_EmbeddedImage( : data(Data::ImageInner_EmbeddedImage(
cbindgen_private::types::ImageCacheKey::Invalid(), cbindgen_private::types::ImageCacheKey::Invalid(),
cbindgen_private::types::SharedImageBuffer::RGB8( cbindgen_private::types::SharedImageBuffer::RGB8(
cbindgen_private::types::SharedPixelBuffer<Rgb8Pixel> { cbindgen_private::types::SharedPixelBuffer<Rgb8Pixel> {
.width = buffer.width(), .width = buffer.width(),
.height = buffer.height(), .height = buffer.height(),
.data = buffer.m_data }))) .data = buffer.m_data })))
{ {
} }
/// Construct an image from a SharedPixelBuffer of RGBA pixels. /// Construct an image from a SharedPixelBuffer of RGBA pixels.
Image(SharedPixelBuffer<Rgba8Pixel> buffer) Image(SharedPixelBuffer<Rgba8Pixel> buffer)
: data(Data::ImageInner_EmbeddedImage( : data(Data::ImageInner_EmbeddedImage(
cbindgen_private::types::ImageCacheKey::Invalid(), cbindgen_private::types::ImageCacheKey::Invalid(),
cbindgen_private::types::SharedImageBuffer::RGBA8( cbindgen_private::types::SharedImageBuffer::RGBA8(
cbindgen_private::types::SharedPixelBuffer<Rgba8Pixel> { cbindgen_private::types::SharedPixelBuffer<Rgba8Pixel> {
.width = buffer.width(), .width = buffer.width(),
.height = buffer.height(), .height = buffer.height(),
.data = buffer.m_data }))) .data = buffer.m_data })))
{ {
} }
/// Returns the size of the Image in pixels. /// Returns the size of the Image in pixels.
Size<uint32_t> size() const Size<uint32_t> size() const { return cbindgen_private::types::slint_image_size(&data); }
{
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(). /// Returns the path of the image on disk, if it was constructed via Image::load_from_path().
std::optional<slint::SharedString> path() const std::optional<slint::SharedString> path() const
@ -227,10 +224,7 @@ public:
return cbindgen_private::types::slint_image_compare_equal(&a.data, &b.data); 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. /// Returns false if \a a refers to the same image as \a b; true otherwise.
friend bool operator!=(const Image &a, const Image &b) friend bool operator!=(const Image &a, const Image &b) { return !(a == b); }
{
return !(a == b);
}
/// \private /// \private
explicit Image(cbindgen_private::types::Image inner) : data(inner) { } explicit Image(cbindgen_private::types::Image inner) : data(inner) { }

View file

@ -19,7 +19,7 @@ struct SharedVector
/// Creates a new, empty vector. /// Creates a new, empty vector.
SharedVector() SharedVector()
: inner(const_cast<SharedVectorHeader *>(reinterpret_cast<const SharedVectorHeader *>( : inner(const_cast<SharedVectorHeader *>(reinterpret_cast<const SharedVectorHeader *>(
cbindgen_private::slint_shared_vector_empty()))) cbindgen_private::slint_shared_vector_empty())))
{ {
} }

View file

@ -49,10 +49,7 @@ struct SharedString
} }
/// Destroys this SharedString and frees the memory if this is the last instance /// Destroys this SharedString and frees the memory if this is the last instance
/// referencing it. /// referencing it.
~SharedString() ~SharedString() { cbindgen_private::slint_shared_string_drop(this); }
{
cbindgen_private::slint_shared_string_drop(this);
}
/// Assigns \a other to this string and returns a reference to this string. /// Assigns \a other to this string and returns a reference to this string.
SharedString &operator=(const SharedString &other) 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 /// 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 /// to this string. The underlying string data is copied. It is assumed that the string
/// is UTF-8 encoded. /// is UTF-8 encoded.
SharedString &operator=(const char *s) SharedString &operator=(const char *s) { return *this = std::string_view(s); }
{
return *this = std::string_view(s);
}
/// Move-assigns \a other to this SharedString instance. /// Move-assigns \a other to this SharedString instance.
SharedString &operator=(SharedString &&other) 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 /// Provides a view to the string data. The returned view is only valid as long as at
/// least this SharedString exists. /// least this SharedString exists.
operator std::string_view() const operator std::string_view() const { return cbindgen_private::slint_shared_string_bytes(this); }
{
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 /// Provides a raw pointer to the string data. The returned pointer is only valid as long as at
/// least this SharedString exists. /// least this SharedString exists.
auto data() const -> const char * auto data() const -> const char * { return cbindgen_private::slint_shared_string_bytes(this); }
{
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 /// Returns a pointer to the first character. It is only safe to dereference the pointer if the
/// string contains at least one character. /// string contains at least one character.
const char *begin() const const char *begin() const { return data(); }
{
return data();
}
/// Returns a point past the last character of the string. It is not safe to dereference the /// Returns a point past the last character of the string. It is not safe to dereference the
/// pointer, but it is suitable for comparison. /// pointer, but it is suitable for comparison.
const char *end() const const char *end() const
@ -111,10 +96,7 @@ struct SharedString
} }
/// \return true if the string contains no characters; false otherwise. /// \return true if the string contains no characters; false otherwise.
bool empty() const bool empty() const { return std::string_view(*this).empty(); }
{
return std::string_view(*this).empty();
}
/// \return true if the string starts with the specified prefix string; false otherwise /// \return true if the string starts with the specified prefix string; false otherwise
bool starts_with(std::string_view prefix) const bool starts_with(std::string_view prefix) const
@ -141,10 +123,7 @@ struct SharedString
/// auto str = slint::SharedString::from_number(42); // creates "42" /// auto str = slint::SharedString::from_number(42); // creates "42"
/// auto str2 = slint::SharedString::from_number(100.5) // creates "100.5" /// auto str2 = slint::SharedString::from_number(100.5) // creates "100.5"
/// \endcode /// \endcode
static SharedString from_number(double n) static SharedString from_number(double n) { return SharedString(n); }
{
return SharedString(n);
}
/// Returns true if \a a is equal to \a b; otherwise returns false. /// Returns true if \a a is equal to \a b; otherwise returns false.
friend bool operator==(const SharedString &a, const SharedString &b) friend bool operator==(const SharedString &a, const SharedString &b)
@ -206,10 +185,7 @@ struct SharedString
private: private:
/// Use SharedString::from_number /// Use SharedString::from_number
explicit SharedString(double n) explicit SharedString(double n) { cbindgen_private::slint_shared_string_from_number(this, n); }
{
cbindgen_private::slint_shared_string_from_number(this, n);
}
void *inner; // opaque void *inner; // opaque
}; };

View file

@ -29,9 +29,9 @@ struct Timer
template<std::invocable F> template<std::invocable F>
Timer(std::chrono::milliseconds interval, F callback) Timer(std::chrono::milliseconds interval, F callback)
: id(cbindgen_private::slint_timer_start( : id(cbindgen_private::slint_timer_start(
0, TimerMode::Repeated, interval.count(), 0, TimerMode::Repeated, interval.count(),
[](void *data) { (*reinterpret_cast<F *>(data))(); }, new F(std::move(callback)), [](void *data) { (*reinterpret_cast<F *>(data))(); }, new F(std::move(callback)),
[](void *data) { delete reinterpret_cast<F *>(data); })) [](void *data) { delete reinterpret_cast<F *>(data); }))
{ {
} }
Timer(const Timer &) = delete; Timer(const Timer &) = delete;

View file

@ -134,45 +134,21 @@ public:
return VRc(inner); return VRc(inner);
} }
const X *operator->() const const X *operator->() const { return &inner->data; }
{ const X &operator*() const { return inner->data; }
return &inner->data; X *operator->() { return &inner->data; }
} X &operator*() { return inner->data; }
const X &operator*() const
{
return inner->data;
}
X *operator->()
{
return &inner->data;
}
X &operator*()
{
return inner->data;
}
const VRc<VTable, Dyn> &into_dyn() const const VRc<VTable, Dyn> &into_dyn() const
{ {
return *reinterpret_cast<const VRc<VTable, Dyn> *>(this); return *reinterpret_cast<const VRc<VTable, Dyn> *>(this);
} }
VRef<VTable> borrow() const VRef<VTable> borrow() const { return { inner->vtable, inner->data_ptr() }; }
{
return { inner->vtable, inner->data_ptr() };
}
friend bool operator==(const VRc &a, const VRc &b) 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; }
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;
}
const VTable *vtable() const
{
return inner->vtable;
}
}; };
template<typename VTable, typename X = Dyn> template<typename VTable, typename X = Dyn>

View file

@ -53,7 +53,10 @@ static GLint compile_shader(GLuint program, GLuint shader_type, const GLchar *co
glGetIntegerv(ParamName, (GLint *)&saved_value); \ glGetIntegerv(ParamName, (GLint *)&saved_value); \
BindingFn(TargetName, new_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); DEFINE_SCOPED_BINDING(ScopedTextureBinding, GL_TEXTURE_BINDING_2D, glBindTexture, GL_TEXTURE_2D);