#![cfg_attr(target_arch = "xtensa", no_std, no_main)]
#![cfg_attr(
target_arch = "xtensa",
feature(impl_trait_in_assoc_type, type_alias_impl_trait)
)]
use oxivgl::view::NavAction;
use oxivgl::{
enums::EventCode,
event::Event,
translation::{self, StaticCStr as S},
view::{register_event_on, View},
widgets::{Obj, Align, Dropdown, Label, WidgetError},
};
static LANGUAGES: [S; 4] = [S::from_cstr(c"en"), S::from_cstr(c"de"), S::from_cstr(c"es"), S::NULL];
static TAGS: [S; 5] = [
S::from_cstr(c"hello"), S::from_cstr(c"welcome"),
S::from_cstr(c"button"), S::from_cstr(c"goodbye"), S::NULL,
];
static TRANSLATIONS: [S; 12] = [
S::from_cstr(c"Hello!"), S::from_cstr(c"Welcome to LVGL"),
S::from_cstr(c"Press a button"), S::from_cstr(c"Goodbye"),
S::from_cstr(c"Hallo!"), S::from_cstr(c"Willkommen bei LVGL"),
S::from_cstr(c"Taste druecken"), S::from_cstr(c"Auf Wiedersehen"),
S::from_cstr(c"Hola!"), S::from_cstr(c"Bienvenido a LVGL"),
S::from_cstr(c"Pulsa un boton"), S::from_cstr(c"Adios"),
];
static LANG_CSTR: [&core::ffi::CStr; 3] = [c"en", c"de", c"es"];
#[derive(Default)]
struct WidgetLabel7 {
dd: Option<Dropdown<'static>>,
_lbl_hello: Option<Label<'static>>,
_lbl_welcome: Option<Label<'static>>,
_lbl_button: Option<Label<'static>>,
_lbl_goodbye: Option<Label<'static>>,
}
impl View for WidgetLabel7 {
fn create(&mut self, container: &Obj<'static>) -> Result<(), WidgetError> {
translation::add_static(&LANGUAGES, &TAGS, &TRANSLATIONS);
translation::set_language(c"en");
let dd = Dropdown::new(container)?;
dd.set_options("English\nDeutsch\nEspanol");
dd.align(Align::TopMid, 0, 10);
dd.bubble_events();
let lbl_hello = Label::new(container)?;
lbl_hello.set_translation_tag("hello");
lbl_hello.align(Align::Center, 0, -40);
let lbl_welcome = Label::new(container)?;
lbl_welcome.set_translation_tag("welcome");
lbl_welcome.align(Align::Center, 0, -10);
let lbl_button = Label::new(container)?;
lbl_button.set_translation_tag("button");
lbl_button.align(Align::Center, 0, 20);
let lbl_goodbye = Label::new(container)?;
lbl_goodbye.set_translation_tag("goodbye");
lbl_goodbye.align(Align::Center, 0, 50);
self.dd = Some(dd);
self._lbl_hello = Some(lbl_hello);
self._lbl_welcome = Some(lbl_welcome);
self._lbl_button = Some(lbl_button);
self._lbl_goodbye = Some(lbl_goodbye);
Ok(())
}
fn register_events(&mut self) {
if let Some(ref dd) = self.dd { register_event_on(self, dd.handle()); }
}
fn on_event(&mut self, event: &Event) -> NavAction {
if event.code() == EventCode::VALUE_CHANGED {
if let Some(ref dd) = self.dd {
let idx = dd.get_selected() as usize;
if idx < LANG_CSTR.len() {
translation::set_language(LANG_CSTR[idx]);
}
}
}
NavAction::None
}
fn update(&mut self) -> Result<NavAction, WidgetError> {
Ok(NavAction::None)
}
}
oxivgl_examples_common::example_main!(WidgetLabel7::default());