mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-03 15:14:35 +00:00
parent
74bc9521b9
commit
07bf0974d7
5 changed files with 51 additions and 1 deletions
|
@ -383,6 +383,17 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns a std::optional that contains an Image if the type of this Value is
|
||||
/// Type::Image, otherwise an empty optional is returned.
|
||||
std::optional<Image> to_image() const
|
||||
{
|
||||
if (auto *img = cbindgen_private::sixtyfps_interpreter_value_to_image(&inner)) {
|
||||
return *reinterpret_cast<const Image *>(img);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
// template<typename T> std::optional<T> get() const;
|
||||
|
||||
/// Constructs a new Value that holds the double \a value.
|
||||
|
@ -409,6 +420,12 @@ public:
|
|||
cbindgen_private::sixtyfps_interpreter_value_new_struct(&struc.inner, &inner);
|
||||
}
|
||||
|
||||
/// Constructs a new Value that holds the Image \a img.
|
||||
Value(const Image &img)
|
||||
{
|
||||
cbindgen_private::sixtyfps_interpreter_value_new_image(&img, &inner);
|
||||
}
|
||||
|
||||
/// Returns the type the variant holds.
|
||||
Type type() const { return cbindgen_private::sixtyfps_interpreter_value_type(&inner); }
|
||||
|
||||
|
|
|
@ -95,6 +95,23 @@ SCENARIO("Value API")
|
|||
REQUIRE(struct_opt.has_value());
|
||||
}
|
||||
|
||||
SECTION("Construct an image")
|
||||
{
|
||||
// ensure a backend exists, using private api
|
||||
sixtyfps::private_api::WindowRc wnd;
|
||||
|
||||
REQUIRE(!value.to_image().has_value());
|
||||
sixtyfps::Image image = sixtyfps::Image::load_from_path(SOURCE_DIR "/../../vscode_extension/extension-logo.png");
|
||||
REQUIRE(image.size().width == 128);
|
||||
value = Value(image);
|
||||
REQUIRE(value.type() == Value::Type::Image);
|
||||
|
||||
auto image2 = value.to_image();
|
||||
REQUIRE(image2.has_value());
|
||||
REQUIRE(image2->size().width == 128);
|
||||
REQUIRE(image == *image2);
|
||||
}
|
||||
|
||||
SECTION("Construct a model")
|
||||
{
|
||||
// And test that it is properly destroyed when the value is destroyed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue