mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-03 05:12:55 +00:00
C++ interpreter API: add a Value::Value(int) constructor (#974)
This commit is contained in:
parent
ea2e91ece9
commit
350f0d0d6a
3 changed files with 12 additions and 0 deletions
|
|
@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- C++ interpreter API: added a `Value::Value(int)` constructor
|
||||||
|
|
||||||
## [0.2.0] - 2022-02-10
|
## [0.2.0] - 2022-02-10
|
||||||
|
|
||||||
This version changes some APIs in incompatible ways. For details how to migrate your application code, see the [C++ migration guide](api/cpp/docs/cpp_migration.md)
|
This version changes some APIs in incompatible ways. For details how to migrate your application code, see the [C++ migration guide](api/cpp/docs/cpp_migration.md)
|
||||||
|
|
|
||||||
|
|
@ -366,6 +366,9 @@ public:
|
||||||
|
|
||||||
/// Constructs a new Value that holds the double \a value.
|
/// Constructs a new Value that holds the double \a value.
|
||||||
Value(double value) { cbindgen_private::slint_interpreter_value_new_double(value, &inner); }
|
Value(double value) { cbindgen_private::slint_interpreter_value_new_double(value, &inner); }
|
||||||
|
/// Constructs a new Value that holds the int \a value.
|
||||||
|
/// Internally this is stored as a double and Value::type() will return Value::Type::Number.
|
||||||
|
Value(int value) : Value(static_cast<double>(value)) { }
|
||||||
/// Constructs a new Value that holds the string \a str.
|
/// Constructs a new Value that holds the string \a str.
|
||||||
Value(const SharedString &str)
|
Value(const SharedString &str)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,11 @@ SCENARIO("Value API")
|
||||||
auto number_opt = value.to_number();
|
auto number_opt = value.to_number();
|
||||||
REQUIRE(number_opt.has_value());
|
REQUIRE(number_opt.has_value());
|
||||||
REQUIRE(number_opt.value() == number);
|
REQUIRE(number_opt.value() == number);
|
||||||
|
|
||||||
|
Value v2 = 42;
|
||||||
|
REQUIRE(v2.type() == Value::Type::Number);
|
||||||
|
REQUIRE(v2 == value);
|
||||||
|
REQUIRE(*v2.to_number() == number);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Construct a bool")
|
SECTION("Construct a bool")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue