mirror of
https://github.com/slint-ui/slint.git
synced 2025-12-23 09:19:32 +00:00
C++: drops IntSize in favor of Size<T> (#922)
Fixes #909 Since we declare the struct in C++, we don't need to declare it in rust for cbindgen anymore, as long as we expose the Size2D type from euclid to the cbindgen_private namespace
This commit is contained in:
parent
7a735a48db
commit
753784c331
4 changed files with 31 additions and 32 deletions
|
|
@ -161,7 +161,6 @@ fn gen_corelib(
|
|||
"slint_image_size",
|
||||
"slint_image_path",
|
||||
"TimerMode", // included in generated_public.h
|
||||
"IntSize", // included in generated_public.h
|
||||
"RenderingState", // included in generated_public.h
|
||||
"SetRenderingNotifierError", // included in generated_public.h
|
||||
"GraphicsAPI", // included in generated_public.h
|
||||
|
|
@ -267,7 +266,6 @@ fn gen_corelib(
|
|||
"slint_color_darker",
|
||||
"slint_image_size",
|
||||
"slint_image_path",
|
||||
"IntSize",
|
||||
]
|
||||
.iter()
|
||||
.filter(|exclusion| !rust_types.iter().any(|inclusion| inclusion == *exclusion))
|
||||
|
|
@ -317,20 +315,11 @@ fn gen_corelib(
|
|||
public_config.export.exclude.push("Point".into());
|
||||
public_config.export.include = vec![
|
||||
"TimerMode".into(),
|
||||
"IntSize".into(),
|
||||
"RenderingState".into(),
|
||||
"SetRenderingNotifierError".into(),
|
||||
"GraphicsAPI".into(),
|
||||
];
|
||||
|
||||
public_config.export.body.insert(
|
||||
"IntSize".to_owned(),
|
||||
r#"
|
||||
/// Compares this IntSize with \a other and returns true if they are equal; false otherwise.
|
||||
bool operator==(const IntSize &other) const = default;"#
|
||||
.to_owned(),
|
||||
);
|
||||
|
||||
cbindgen::Builder::new()
|
||||
.with_config(public_config)
|
||||
.with_src(crate_dir.join("timers.rs"))
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#pragma once
|
||||
#include <string_view>
|
||||
#include "slint_generated_public.h"
|
||||
#include "slint_size.h"
|
||||
#include "slint_image_internal.h"
|
||||
#include "slint_string.h"
|
||||
#include "slint_sharedvector.h"
|
||||
|
|
@ -33,7 +34,7 @@ public:
|
|||
*/
|
||||
|
||||
/// Returns the size of the Image in pixels.
|
||||
IntSize size() const { return cbindgen_private::types::slint_image_size(&data); }
|
||||
Size<unsigned int> 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
|
||||
|
|
|
|||
29
api/cpp/include/slint_size.h
Normal file
29
api/cpp/include/slint_size.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright © SixtyFPS GmbH <info@sixtyfps.io>
|
||||
// SPDX-License-Identifier: (GPL-3.0-only OR LicenseRef-SixtyFPS-commercial)
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace slint {
|
||||
|
||||
/// The Size structure is used to represent a two-dimensional size
|
||||
/// with width and height.
|
||||
template <typename T>
|
||||
struct Size {
|
||||
/// The width of the size
|
||||
T width;
|
||||
/// The height of the size
|
||||
T height;
|
||||
|
||||
/// Compares with \a other and returns true if they are equal; false otherwise.
|
||||
bool operator==(const Size &other) const = default;
|
||||
};
|
||||
|
||||
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>;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -185,25 +185,5 @@ pub(crate) mod ffi {
|
|||
y: f32,
|
||||
}
|
||||
|
||||
/// Expand Size so that cbindgen can see it. ( is in fact euclid::default::Size2D<f32>)
|
||||
#[cfg(cbindgen)]
|
||||
#[repr(C)]
|
||||
struct Size {
|
||||
width: f32,
|
||||
height: f32,
|
||||
}
|
||||
|
||||
// Expand Size so that cbindgen can see it. ( is in fact euclid::default::Size2D<u32>)
|
||||
/// The Size structure is used to represent a two-dimensional size
|
||||
/// with width and height.
|
||||
#[cfg(cbindgen)]
|
||||
#[repr(C)]
|
||||
struct IntSize {
|
||||
/// The width of the size
|
||||
width: u32,
|
||||
/// The height of the size
|
||||
height: u32,
|
||||
}
|
||||
|
||||
pub use super::path::ffi::*;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue