mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-03 02:13:21 +00:00
Run clang-format over C++ files
This commit is contained in:
parent
1884497308
commit
ca6dfc0cb5
12 changed files with 141 additions and 107 deletions
|
@ -213,8 +213,8 @@ public:
|
|||
inline std::optional<SharedString> register_font_from_data(const uint8_t *data, std::size_t len)
|
||||
{
|
||||
SharedString maybe_err;
|
||||
cbindgen_private::slint_register_font_from_data(&inner, { const_cast<uint8_t *>(data), len },
|
||||
&maybe_err);
|
||||
cbindgen_private::slint_register_font_from_data(
|
||||
&inner, { const_cast<uint8_t *>(data), len }, &maybe_err);
|
||||
if (!maybe_err.empty()) {
|
||||
return maybe_err;
|
||||
} else {
|
||||
|
@ -222,8 +222,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
cbindgen_private::WindowRcOpaque inner;
|
||||
};
|
||||
|
|
|
@ -98,7 +98,6 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// Brush is used to declare how to fill or outline shapes, such as rectangles, paths or text. A
|
||||
|
|
|
@ -163,7 +163,10 @@ 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:
|
||||
|
|
|
@ -61,12 +61,19 @@ private:
|
|||
};
|
||||
|
||||
namespace private_api {
|
||||
inline Image load_image_from_embedded_data(std::span<const uint8_t> data, std::string_view extension) {
|
||||
cbindgen_private::types::Image img(cbindgen_private::types::Image::ImageInner_None());
|
||||
cbindgen_private::types::slint_image_load_from_embedded_data(
|
||||
slint::cbindgen_private::Slice<uint8_t>{const_cast<uint8_t *>(data.data()), data.size()}, slint::cbindgen_private::Slice<uint8_t>{const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(extension.data())), extension.size()}, &img);
|
||||
return Image(img);
|
||||
}
|
||||
inline Image load_image_from_embedded_data(std::span<const uint8_t> data,
|
||||
std::string_view extension)
|
||||
{
|
||||
cbindgen_private::types::Image img(cbindgen_private::types::Image::ImageInner_None());
|
||||
cbindgen_private::types::slint_image_load_from_embedded_data(
|
||||
slint::cbindgen_private::Slice<uint8_t> { const_cast<uint8_t *>(data.data()),
|
||||
data.size() },
|
||||
slint::cbindgen_private::Slice<uint8_t> {
|
||||
const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(extension.data())),
|
||||
extension.size() },
|
||||
&img);
|
||||
return Image(img);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -205,7 +205,10 @@ 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.
|
||||
|
@ -454,10 +457,7 @@ inline Value::Value(const std::shared_ptr<slint::Model<Value>> &model)
|
|||
{
|
||||
cbindgen_private::slint_interpreter_model_notify_row_removed(¬ify, index, count);
|
||||
}
|
||||
void reset() override
|
||||
{
|
||||
cbindgen_private::slint_interpreter_model_notify_reset(¬ify);
|
||||
}
|
||||
void reset() override { cbindgen_private::slint_interpreter_model_notify_reset(¬ify); }
|
||||
};
|
||||
|
||||
auto wrapper = std::make_shared<ModelWrapper>();
|
||||
|
@ -492,7 +492,8 @@ inline Value::Value(const std::shared_ptr<slint::Model<Value>> &model)
|
|||
};
|
||||
|
||||
static const ModelAdaptorVTable vt { row_count, row_data, set_row_data, get_notify, drop };
|
||||
cbindgen_private::slint_interpreter_value_new_model(reinterpret_cast<uint8_t *>(wrapper.get()), &vt, &inner);
|
||||
cbindgen_private::slint_interpreter_value_new_model(reinterpret_cast<uint8_t *>(wrapper.get()),
|
||||
&vt, &inner);
|
||||
}
|
||||
|
||||
inline Struct::Struct(std::initializer_list<std::pair<std::string_view, Value>> args)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "slint_pathdata_internal.h"
|
||||
|
||||
namespace slint::private_api {
|
||||
using cbindgen_private::PathEvent;
|
||||
using cbindgen_private::types::PathArcTo;
|
||||
using cbindgen_private::types::PathCubicTo;
|
||||
using cbindgen_private::types::PathElement;
|
||||
|
@ -14,7 +15,6 @@ using cbindgen_private::types::PathLineTo;
|
|||
using cbindgen_private::types::PathMoveTo;
|
||||
using cbindgen_private::types::PathQuadraticTo;
|
||||
using cbindgen_private::types::Point;
|
||||
using cbindgen_private::PathEvent;
|
||||
|
||||
struct PathData
|
||||
{
|
||||
|
|
|
@ -75,7 +75,7 @@ struct Property
|
|||
|
||||
void set(const T &value) const
|
||||
{
|
||||
if ((inner._0 & 0b10) == 0b10 || this->value != value) {
|
||||
if ((inner._0 & 0b10) == 0b10 || this->value != value) {
|
||||
this->value = value;
|
||||
cbindgen_private::slint_property_set_changed(&inner, &this->value);
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace slint {
|
||||
|
||||
/// The Size structure is used to represent a two-dimensional size
|
||||
/// with width and height.
|
||||
template <typename T>
|
||||
struct Size {
|
||||
template<typename T>
|
||||
struct Size
|
||||
{
|
||||
/// The width of the size
|
||||
T width;
|
||||
/// The height of the size
|
||||
|
@ -20,10 +20,10 @@ struct Size {
|
|||
};
|
||||
|
||||
namespace cbindgen_private {
|
||||
// The Size types are expanded to the Size2D<...> type from the euclid crate which
|
||||
// is binary compatible with Size<T>
|
||||
template <typename T> using Size2D = Size<T>;
|
||||
// The Size types are expanded to the Size2D<...> type from the euclid crate which
|
||||
// is binary compatible with Size<T>
|
||||
template<typename T>
|
||||
using Size2D = Size<T>;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -53,7 +53,10 @@ 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)
|
||||
{
|
||||
|
@ -72,7 +75,10 @@ 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)
|
||||
|
@ -83,20 +89,35 @@ 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 { return &*std::string_view(*this).end(); }
|
||||
const char *end() const
|
||||
{
|
||||
return &*std::string_view(*this).end();
|
||||
}
|
||||
|
||||
/// \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
|
||||
|
@ -123,7 +144,10 @@ 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)
|
||||
|
@ -185,7 +209,10 @@ 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
|
||||
};
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ struct VRefMut
|
|||
void *instance;
|
||||
};
|
||||
|
||||
struct Layout {
|
||||
struct Layout
|
||||
{
|
||||
std::size_t size;
|
||||
std::size_t align;
|
||||
};
|
||||
|
@ -31,15 +32,17 @@ template<typename T>
|
|||
using Pin = T;
|
||||
|
||||
template<typename T>
|
||||
struct VBox {
|
||||
struct VBox
|
||||
{
|
||||
const T *vtable = nullptr;
|
||||
void *instance = nullptr;
|
||||
VBox(const VBox&) = delete;
|
||||
VBox(const VBox &) = delete;
|
||||
VBox() = default;
|
||||
VBox&operator=(const VBox&) = delete;
|
||||
~VBox() {
|
||||
VBox &operator=(const VBox &) = delete;
|
||||
~VBox()
|
||||
{
|
||||
if (vtable && instance) {
|
||||
vtable->drop({vtable, instance});
|
||||
vtable->drop({ vtable, instance });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -54,11 +57,15 @@ struct VOffset
|
|||
};
|
||||
|
||||
template<typename VTable, typename X>
|
||||
struct VRcInner {
|
||||
template<typename VTable_, typename X_> friend class VRc;
|
||||
template<typename VTable_, typename X_> friend class VWeak;
|
||||
struct VRcInner
|
||||
{
|
||||
template<typename VTable_, typename X_>
|
||||
friend class VRc;
|
||||
template<typename VTable_, typename X_>
|
||||
friend class VWeak;
|
||||
|
||||
private:
|
||||
VRcInner() : layout {} {}
|
||||
VRcInner() : layout {} { }
|
||||
const VTable *vtable = &X::static_vtable;
|
||||
std::atomic<int> strong_ref = 1;
|
||||
std::atomic<int> weak_ref = 1;
|
||||
|
@ -72,113 +79,108 @@ private:
|
|||
~VRcInner() = delete;
|
||||
};
|
||||
|
||||
struct Dyn {};
|
||||
struct Dyn
|
||||
{
|
||||
};
|
||||
|
||||
template<typename VTable, typename X = Dyn>
|
||||
class VRc {
|
||||
class VRc
|
||||
{
|
||||
VRcInner<VTable, X> *inner;
|
||||
VRc(VRcInner<VTable, X> *inner) : inner(inner) {}
|
||||
template<typename VTable_, typename X_> friend class VWeak;
|
||||
VRc(VRcInner<VTable, X> *inner) : inner(inner) { }
|
||||
template<typename VTable_, typename X_>
|
||||
friend class VWeak;
|
||||
|
||||
public:
|
||||
~VRc() {
|
||||
~VRc()
|
||||
{
|
||||
if (!--inner->strong_ref) {
|
||||
Layout layout = inner->vtable->drop_in_place({inner->vtable, &inner->data});
|
||||
Layout layout = inner->vtable->drop_in_place({ inner->vtable, &inner->data });
|
||||
layout.size += inner->data_offset;
|
||||
layout.align = std::max<size_t>(layout.align, alignof(VRcInner<VTable, Dyn>));
|
||||
inner->layout = layout;
|
||||
if (!--inner->weak_ref) {
|
||||
inner->vtable->dealloc(inner->vtable, reinterpret_cast<uint8_t*>(inner), layout);
|
||||
inner->vtable->dealloc(inner->vtable, reinterpret_cast<uint8_t *>(inner), layout);
|
||||
}
|
||||
}
|
||||
}
|
||||
VRc(const VRc &other): inner(other.inner) {
|
||||
inner->strong_ref++;
|
||||
}
|
||||
VRc &operator=(const VRc &other) {
|
||||
VRc(const VRc &other) : inner(other.inner) { inner->strong_ref++; }
|
||||
VRc &operator=(const VRc &other)
|
||||
{
|
||||
if (inner == other.inner)
|
||||
return *this;
|
||||
this->~VRc();
|
||||
new(this) VRc(other);
|
||||
new (this) VRc(other);
|
||||
return *this;
|
||||
}
|
||||
/// Construct a new VRc holding an X.
|
||||
///
|
||||
/// The type X must have a static member `static_vtable` of type VTable
|
||||
template<typename ...Args> static VRc make(Args... args) {
|
||||
auto mem = ::operator new(sizeof(VRcInner<VTable, X>), static_cast<std::align_val_t>(alignof(VRcInner<VTable, X>)));
|
||||
template<typename... Args>
|
||||
static VRc make(Args... args)
|
||||
{
|
||||
auto mem = ::operator new(sizeof(VRcInner<VTable, X>),
|
||||
static_cast<std::align_val_t>(alignof(VRcInner<VTable, X>)));
|
||||
auto inner = new (mem) VRcInner<VTable, X>;
|
||||
new (&inner->data) X(args...);
|
||||
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; }
|
||||
|
||||
VRc<VTable, Dyn> into_dyn() const { return *reinterpret_cast<const VRc<VTable, Dyn> *>(this); }
|
||||
|
||||
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;
|
||||
}
|
||||
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>
|
||||
class VWeak {
|
||||
class VWeak
|
||||
{
|
||||
VRcInner<VTable, X> *inner = nullptr;
|
||||
|
||||
public:
|
||||
VWeak() = default;
|
||||
~VWeak() {
|
||||
~VWeak()
|
||||
{
|
||||
if (inner && !--inner->weak_ref) {
|
||||
inner->vtable->dealloc(inner->vtable, reinterpret_cast<uint8_t*>(inner), inner->layout);
|
||||
inner->vtable->dealloc(inner->vtable, reinterpret_cast<uint8_t *>(inner),
|
||||
inner->layout);
|
||||
}
|
||||
}
|
||||
VWeak(const VWeak &other): inner(other.inner) {
|
||||
inner && inner->weak_ref++;
|
||||
}
|
||||
VWeak(const VRc<VTable, X> &other): inner(other.inner) {
|
||||
inner && inner->weak_ref++;
|
||||
}
|
||||
VWeak &operator=(const VWeak &other) {
|
||||
VWeak(const VWeak &other) : inner(other.inner) { inner && inner->weak_ref++; }
|
||||
VWeak(const VRc<VTable, X> &other) : inner(other.inner) { inner && inner->weak_ref++; }
|
||||
VWeak &operator=(const VWeak &other)
|
||||
{
|
||||
if (inner == other.inner)
|
||||
return *this;
|
||||
this->~VWeak();
|
||||
new(this) VWeak(other);
|
||||
new (this) VWeak(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::optional<VRc<VTable, X>> lock() const {
|
||||
std::optional<VRc<VTable, X>> lock() const
|
||||
{
|
||||
if (!inner || inner->strong_ref == 0)
|
||||
return {};
|
||||
inner->strong_ref++;
|
||||
return { VRc<VTable, X>(inner) };
|
||||
}
|
||||
|
||||
VWeak<VTable, Dyn> into_dyn() const { return *reinterpret_cast<const VWeak<VTable, Dyn> *>(this); }
|
||||
VWeak<VTable, Dyn> into_dyn() const
|
||||
{
|
||||
return *reinterpret_cast<const VWeak<VTable, Dyn> *>(this);
|
||||
}
|
||||
|
||||
friend bool operator==(const VWeak &a, const VWeak &b) {
|
||||
return a.inner == b.inner;
|
||||
}
|
||||
friend bool operator!=(const VWeak &a, const VWeak &b) {
|
||||
return a.inner != b.inner;
|
||||
}
|
||||
friend bool operator==(const VWeak &a, const VWeak &b) { return a.inner == b.inner; }
|
||||
friend bool operator!=(const VWeak &a, const VWeak &b) { return a.inner != b.inner; }
|
||||
const VTable *vtable() const { return inner ? inner->vtable : nullptr; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
} //namespace vtable
|
||||
} // namespace vtable
|
||||
|
|
|
@ -24,7 +24,6 @@ SCENARIO("Basic usage")
|
|||
REQUIRE(prop2.get() == 42 + 4);
|
||||
prop.set(55);
|
||||
REQUIRE(prop2.get() == 55 + 4);
|
||||
|
||||
}
|
||||
|
||||
REQUIRE(prop.get() == 55);
|
||||
|
@ -32,7 +31,6 @@ SCENARIO("Basic usage")
|
|||
REQUIRE(prop.get() == 33);
|
||||
}
|
||||
|
||||
|
||||
SCENARIO("Set after binding")
|
||||
{
|
||||
Property<int> prop;
|
||||
|
|
|
@ -58,11 +58,10 @@ int main(int argc, char **argv)
|
|||
auto instance = def->create();
|
||||
QWidget *wid = instance->qwidget();
|
||||
if (!wid) {
|
||||
QMessageBox::critical(
|
||||
&main, QApplication::translate("qt_viewer", "No Qt backend"),
|
||||
QApplication::translate("qt_viewer",
|
||||
"Slint is not running with the Qt backend."),
|
||||
QMessageBox::StandardButton::Ok);
|
||||
QMessageBox::critical(&main, QApplication::translate("qt_viewer", "No Qt backend"),
|
||||
QApplication::translate(
|
||||
"qt_viewer", "Slint is not running with the Qt backend."),
|
||||
QMessageBox::StandardButton::Ok);
|
||||
return;
|
||||
}
|
||||
wid->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue