-
Hi ! In my toy project, I'm trying to export a simple array of a custom struct import { Button, VerticalBox } from "std-widgets.slint";
export struct TranslationArgument {
name: string,
value: string,
}
export global Fluent {
pure callback translate(string, [TranslationArgument]) -> string;
}
export component AppWindow inherits Window {
in-out property<int> counter: 42;
callback request-increase-value();
protected pure function tr(str: string, args: [TranslationArgument]) -> string {
return Fluent.translate(str, args);
}
VerticalBox {
Text {
text: root.tr("Counter : {$counter}", [{name: "counter", value: root.counter}]);
}
Button {
text: root.tr("Increase value", []);
clicked => {
root.request-increase-value();
}
}
}
} But when trying to use the callback slint::include_modules!();
use std::collections::HashMap;
use i18n_embed::{
fluent::{fluent_language_loader, FluentLanguageLoader},
DesktopLanguageRequester,
};
use rust_embed::RustEmbed;
#[derive(RustEmbed)]
#[folder = "i18n"] // path to the compiled localization resources
struct Localizations;
fn main() -> Result<(), slint::PlatformError> {
let language_loader: FluentLanguageLoader = fluent_language_loader!();
let requested_languages = DesktopLanguageRequester::requested_languages();
let _tr = i18n_embed::select(&language_loader, &Localizations, &requested_languages)
.expect("failed to setup translations");
let ui = AppWindow::new()?;
ui.global::<Fluent>().on_translate(move |str, args| {
let mut arguments = HashMap::new();
for (name, value) in args { // HERE : args is a ModelRc<TranslationArgument>
arguments[name] = value.clone();
}
language_loader.get_args_concrete(&str, arguments).into()
});
let ui_handle = ui.as_weak();
ui.on_request_increase_value(move || {
let ui = ui_handle.unwrap();
ui.set_counter(ui.get_counter() + 1);
});
ui.run()
} So we see that args got the type So is it impossible to use arrays, or is it a bug ? I'm using slint ui 1.3.0 Regards |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I could be wrong but I believe a for loop typically desugars to using into_iter(). ModelRc I believe has iter() but not into_iter(). So I think you need to change the line to
|
Beta Was this translation helpful? Give feedback.
I could be wrong but I believe a for loop typically desugars to using into_iter(). ModelRc I believe has iter() but not into_iter(). So I think you need to change the line to
for (name, value) in args.iter()