mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 22:31:14 +00:00
WIP: API to expose image loading from C++ and Rust
This commit is contained in:
parent
4584c40544
commit
0b3fecf300
15 changed files with 140 additions and 68 deletions
|
@ -195,7 +195,11 @@ fn to_eval_value<'cx>(
|
|||
}
|
||||
},
|
||||
Type::Image => {
|
||||
Ok(Value::Image(ImageReference::AbsoluteFilePath(val.to_string(cx)?.value().into())))
|
||||
let path = val.to_string(cx)?.value();
|
||||
Ok(Value::Image(
|
||||
sixtyfps_corelib::graphics::Image::load_from_path(std::path::Path::new(&path))
|
||||
.or_else(|_| cx.throw_error(format!("cannot load image {:?}", path)))?,
|
||||
))
|
||||
}
|
||||
Type::Bool => Ok(Value::Bool(val.downcast_or_throw::<JsBoolean, _>(cx)?.value())),
|
||||
Type::Struct { fields, .. } => {
|
||||
|
@ -243,7 +247,7 @@ fn to_js_value<'cx>(
|
|||
Value::Number(n) => JsNumber::new(cx, n).as_value(cx),
|
||||
Value::String(s) => JsString::new(cx, s.as_str()).as_value(cx),
|
||||
Value::Bool(b) => JsBoolean::new(cx, b).as_value(cx),
|
||||
Value::Image(r) => match r {
|
||||
Value::Image(r) => match r.0 {
|
||||
ImageReference::None => JsUndefined::new().as_value(cx),
|
||||
ImageReference::AbsoluteFilePath(path) => JsString::new(cx, path.as_str()).as_value(cx),
|
||||
ImageReference::EmbeddedData { .. } | ImageReference::EmbeddedRgbaImage { .. } => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue