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
/// 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<Value> &array)
: inner(cbindgen_private::slint_interpreter_value_new_array_model(
reinterpret_cast<const slint::SharedVector<slint::cbindgen_private::Value *> *>(
&array)))
reinterpret_cast<const slint::SharedVector<slint::cbindgen_private::Value *> *>(
&array)))
{
}
@ -699,15 +696,16 @@ public:
// clang-format on
{
using namespace cbindgen_private;
auto actual_cb = [](void *data,
cbindgen_private::Slice<cbindgen_private::Box<cbindgen_private::Value>>
arg) {
std::span<const Value> args_view { reinterpret_cast<const Value *>(arg.ptr), arg.len };
Value r = (*reinterpret_cast<F *>(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<cbindgen_private::Box<cbindgen_private::Value>> arg) {
std::span<const Value> args_view { reinterpret_cast<const Value *>(arg.ptr),
arg.len };
Value r = (*reinterpret_cast<F *>(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<F *>(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<cbindgen_private::Box<cbindgen_private::Value>>
arg) {
std::span<const Value> args_view { reinterpret_cast<const Value *>(arg.ptr), arg.len };
Value r = (*reinterpret_cast<F *>(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<cbindgen_private::Box<cbindgen_private::Value>> arg) {
std::span<const Value> args_view { reinterpret_cast<const Value *>(arg.ptr),
arg.len };
Value r = (*reinterpret_cast<F *>(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)),

View file

@ -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<SharedString> clipboard_text(Clipboard)
{
return {};
}
virtual std::optional<SharedString> 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<typename Callback>
requires requires(Callback callback)
{
callback(size_t(0), size_t(0), size_t(0), [&callback](std::span<Rgb565Pixel>) {});
}
requires requires(Callback callback) {
callback(size_t(0), size_t(0), size_t(0), [&callback](std::span<Rgb565Pixel>) {});
}
PhysicalRegion render_by_line(Callback process_line_callback) const
{
auto r = cbindgen_private::slint_software_renderer_render_by_line_rgb565(

View file

@ -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<Model<ModelData>> source_model,
std::function<bool(const ModelData &)> filter_fn)
: 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);
}
@ -789,7 +783,7 @@ public:
MapModel(std::shared_ptr<Model<SourceModelData>> source_model,
std::function<MappedModelData(const SourceModelData &)> map_fn)
: inner(std::make_shared<private_api::MapModelInner<SourceModelData, MappedModelData>>(
*this)),
*this)),
model(source_model),
map_fn(map_fn)
{

View file

@ -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:

View file

@ -173,32 +173,29 @@ public:
/// Construct an image from a SharedPixelBuffer of RGB pixels.
Image(SharedPixelBuffer<Rgb8Pixel> buffer)
: data(Data::ImageInner_EmbeddedImage(
cbindgen_private::types::ImageCacheKey::Invalid(),
cbindgen_private::types::SharedImageBuffer::RGB8(
cbindgen_private::types::SharedPixelBuffer<Rgb8Pixel> {
.width = buffer.width(),
.height = buffer.height(),
.data = buffer.m_data })))
cbindgen_private::types::ImageCacheKey::Invalid(),
cbindgen_private::types::SharedImageBuffer::RGB8(
cbindgen_private::types::SharedPixelBuffer<Rgb8Pixel> {
.width = buffer.width(),
.height = buffer.height(),
.data = buffer.m_data })))
{
}
/// Construct an image from a SharedPixelBuffer of RGBA pixels.
Image(SharedPixelBuffer<Rgba8Pixel> buffer)
: data(Data::ImageInner_EmbeddedImage(
cbindgen_private::types::ImageCacheKey::Invalid(),
cbindgen_private::types::SharedImageBuffer::RGBA8(
cbindgen_private::types::SharedPixelBuffer<Rgba8Pixel> {
.width = buffer.width(),
.height = buffer.height(),
.data = buffer.m_data })))
cbindgen_private::types::ImageCacheKey::Invalid(),
cbindgen_private::types::SharedImageBuffer::RGBA8(
cbindgen_private::types::SharedPixelBuffer<Rgba8Pixel> {
.width = buffer.width(),
.height = buffer.height(),
.data = buffer.m_data })))
{
}
/// Returns the size of the Image in pixels.
Size<uint32_t> size() const
{
return cbindgen_private::types::slint_image_size(&data);
}
Size<uint32_t> 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<slint::SharedString> 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) { }

View file

@ -19,7 +19,7 @@ struct SharedVector
/// Creates a new, empty vector.
SharedVector()
: 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
/// 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
};

View file

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

View file

@ -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<VTable, Dyn> &into_dyn() const
{
return *reinterpret_cast<const VRc<VTable, Dyn> *>(this);
}
VRef<VTable> borrow() const
{
return { inner->vtable, inner->data_ptr() };
}
VRef<VTable> 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<typename VTable, typename X = Dyn>