widget: main_view: add obtk ron based localization support
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -12,20 +12,23 @@ use crate::{
|
||||
widgets::policycheck_view::PolicyCheckView,
|
||||
};
|
||||
|
||||
type List = Vec<String>;
|
||||
|
||||
// [START] views
|
||||
|
||||
widget!(MainView {
|
||||
// policy_list: PolicyList,
|
||||
// policy_data_list: PolicyDataList,
|
||||
// policylist_view: u32,
|
||||
// policydata_view: u32,
|
||||
//policycheck_view: u32
|
||||
policycheck_view: PolicyCheck
|
||||
});
|
||||
|
||||
impl Template for MainView {
|
||||
fn template(self, _id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
let policycheck_view = PolicyCheckView::new()
|
||||
//.policy_number_count(0)
|
||||
//.policylist_view(id)
|
||||
//.policy_number_count(0)
|
||||
//.policylist_view(id)
|
||||
.build(ctx);
|
||||
|
||||
// let policylist_view = PolicyListView::new()
|
||||
@@ -49,6 +52,83 @@ impl Template for MainView {
|
||||
// .policylist_view(policylist_view.0)
|
||||
// .child(policydata_view)
|
||||
// .child(policylist_view)
|
||||
.child(policycheck_view)
|
||||
.child(
|
||||
TabWidget::new()
|
||||
.tab("Policynumber check", policycheck_view)
|
||||
.tab("Localization", LocalizationView::new().build(ctx))
|
||||
.build(ctx),
|
||||
)
|
||||
//.child(policycheck_view)
|
||||
}
|
||||
}
|
||||
|
||||
widget!(LocalizationView<LocalizationState> { languages: List, selected_index: i32 });
|
||||
|
||||
impl Template for LocalizationView {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
let languages = vec!["English".to_string(), "German".to_string()];
|
||||
let count = languages.len();
|
||||
|
||||
self.languages(languages).selected_index(1).child(
|
||||
Stack::new()
|
||||
.width(120)
|
||||
.margin(16)
|
||||
.spacing(8)
|
||||
.child(TextBlock::new().text("Hello").build(ctx))
|
||||
.child(TextBlock::new().text("User").build(ctx))
|
||||
.child(TextBlock::new().text("Localization dialog").build(ctx))
|
||||
.child(
|
||||
ComboBox::new()
|
||||
.count(count)
|
||||
.items_builder(move |bc, index| {
|
||||
let text = bc.get_widget(id)
|
||||
.get::<Vec<String>>("languages")[index]
|
||||
.clone();
|
||||
TextBlock::new().v_align("center").text(text).build(bc)
|
||||
})
|
||||
.on_changed("selected_index", move |states, _| {
|
||||
states.get_mut::<LocalizationState>(id).change_language();
|
||||
})
|
||||
.selected_index(id)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// [END] views
|
||||
|
||||
// [START] states
|
||||
|
||||
#[derive(AsAny, Debug, Default)]
|
||||
struct LocalizationState {
|
||||
change_language: bool,
|
||||
}
|
||||
|
||||
impl LocalizationState {
|
||||
fn change_language(&mut self) {
|
||||
self.change_language = true;
|
||||
}
|
||||
}
|
||||
|
||||
impl State for LocalizationState {
|
||||
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context<'_>) {
|
||||
if !self.change_language {
|
||||
return;
|
||||
}
|
||||
|
||||
let index = *LocalizationView::selected_index_ref(&ctx.widget()) as usize;
|
||||
let selected_language = LocalizationView::languages_ref(&ctx.widget())[index].clone();
|
||||
|
||||
match selected_language.as_str() {
|
||||
"English" => ctx.set_language("en_US"),
|
||||
"German" => ctx.set_language("de_DE"),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
self.change_language = false;
|
||||
}
|
||||
}
|
||||
|
||||
// [END] states
|
||||
|
||||
Reference in New Issue
Block a user