Skip to main content

Localized

Struct Localized 

Source
pub struct Localized<'a> {
    pub key: &'a str,
    pub fallback: &'a str,
}
Expand description

A localizable label with a stable lookup key and fallback text.

Fields§

§key: &'a str

Stable localization key.

§fallback: &'a str

Fallback text used when no translation is available.

Implementations§

Source§

impl<'a> Localized<'a>

Source

pub const fn new(key: &'a str, fallback: &'a str) -> Self

Creates a new localized label.

Examples found in repository?
examples/root_delegate.rs (line 21)
19    fn title(&self, view: AppView) -> Localized<'a> {
20        match view {
21            AppView::Home => Localized::new("home.title", "Home"),
22            AppView::Detail => Localized::new("detail.title", "Detail"),
23        }
24    }
More examples
Hide additional examples
examples/uikit_root.rs (line 43)
42    fn configure(&mut self, registration: &mut ViewRegistration<'static, DemoViewId, 2>) {
43        registration.set_title(Localized::new("root.title", "Devices"));
44        registration.set_clips_to_bounds(true);
45        let list_frame = registration.frame();
46        let _ = registration.add_child(
47            ChildView::new(DemoViewId::DevicesList, list_frame)
48                .with_kind(ViewKind::List)
49                .with_title(Localized::new("devices.title", "Devices")),
50        );
51        let _ = registration.add_child(
52            ChildView::new(
53                DemoViewId::AlertOverlay,
54                Rectangle::new(Point::new(16, 16), Size::new(0, 0)),
55            )
56            .with_kind(ViewKind::AlertHost)
57            .with_hidden(true)
58            .with_alpha(0),
59        );
60    }
examples/alerts.rs (line 18)
11fn main() {
12    let bounds = Rectangle::new(Point::zero(), Size::new(320, 240));
13    let theme = support::theme();
14    let i18n = support::i18n();
15    let mut canvas = support::NullCanvas::new(bounds.size);
16
17    let spec = AlertSpec::confirm(
18        Localized::new("alert.title", "Delete item?"),
19        Localized::new("alert.message", "This action cannot be undone."),
20    );
21    let mut alert = AlertView::new(spec);
22    let panel = alert.panel(bounds, &theme, &i18n);
23    alert.draw(&mut canvas, panel, &theme, &i18n);
24    let _ = alert.handle_touch(TouchEvent::new(panel.center(), TouchPhase::Start, 1), panel);
25
26    let mut host = AlertHost::<u8, 2>::new();
27    let _ = host.present(7, spec);
28    let _ = host.layer(bounds, &theme, &i18n);
29    host.draw(&mut canvas, bounds, &theme, &i18n);
30    let _ = host.handle_touch(
31        TouchEvent::new(Point::new(160, 160), TouchPhase::End, 2),
32        bounds,
33        &theme,
34        &i18n,
35    );
36
37    let mut modal = ModalHost::new();
38    modal.show(3_u8);
39    let _ = modal.current(bounds, &theme);
40    let _ = Rgb565::BLACK;
41}
examples/containers.rs (line 31)
25fn main() {
26    let bounds = Rectangle::new(Point::zero(), Size::new(320, 240));
27    let split = SplitView::new(SplitAxis::Horizontal, 620, 12);
28    let _layout = split.layout(bounds);
29
30    let mut stack = StackView::<Screen, _, 4>::new(Screen::Devices, |screen| match screen {
31        Screen::Devices => Localized::new("screen.devices", "Devices"),
32        Screen::DeviceDetail => Localized::new("screen.detail", "Device"),
33    });
34    let _ = stack.push_view(Screen::DeviceDetail);
35    let _ = stack.motion(bounds);
36    let _ = stack.handle_touch(
37        TouchEvent::new(Point::new(12, 12), TouchPhase::Start, 1),
38        bounds,
39    );
40
41    let tabs = [
42        TabSpec {
43            key: TabId::Home,
44            icon: "H",
45            title: Localized::new("tab.home", "Home"),
46        },
47        TabSpec {
48            key: TabId::Logs,
49            icon: "L",
50            title: Localized::new("tab.logs", "Logs"),
51        },
52        TabSpec {
53            key: TabId::Settings,
54            icon: "S",
55            title: Localized::new("tab.settings", "Settings"),
56        },
57    ];
58    let mut tab_view = TabView::new(tabs, 0);
59    let _ = tab_view.content_frame(bounds, &support::theme());
60    let _ = tab_view.handle_touch(
61        TouchEvent::new(Point::new(200, 220), TouchPhase::End, 2),
62        bounds,
63        &support::theme(),
64    );
65}
examples/buttons.rs (line 21)
11fn main() {
12    let mut canvas = support::NullCanvas::new(Size::new(320, 240));
13    let theme = support::theme();
14    let i18n = support::i18n();
15
16    let mut primary = Button::new(
17        Rectangle::new(Point::new(16, 16), Size::new(132, 56)),
18        ButtonSpec {
19            key: 1_u8,
20            icon: Some("+"),
21            label: Localized::new("button.add", "Add device"),
22            kind: ButtonKind::Primary,
23        },
24    );
25    let secondary = Button::new(
26        Rectangle::new(Point::new(16, 84), Size::new(132, 48)),
27        ButtonSpec {
28            key: 2_u8,
29            icon: None,
30            label: Localized::new("button.more", "More"),
31            kind: ButtonKind::Secondary,
32        },
33    );
34    let destructive = Button::new(
35        Rectangle::new(Point::new(16, 144), Size::new(132, 48)),
36        ButtonSpec {
37            key: 3_u8,
38            icon: None,
39            label: Localized::new("button.delete", "Delete"),
40            kind: ButtonKind::Destructive,
41        },
42    );
43
44    primary.draw(&mut canvas, &theme, &i18n);
45    secondary.draw(&mut canvas, &theme, &i18n);
46    destructive.draw(&mut canvas, &theme, &i18n);
47
48    let _ = primary.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::Start, 1));
49    let response = primary.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::End, 2));
50    let _pressed = response.action == Some(1);
51
52    let _ = Rgb565::BLACK;
53}
src/alert/spec.rs (line 54)
51    pub const fn error(message: Localized<'a>) -> Self {
52        Self {
53            kind: AlertKind::Error,
54            title: Localized::new("fs.alert.error", "Error"),
55            message,
56            actions: [AlertAction {
57                id: 0,
58                label: Localized::new("fs.alert.ok", "OK"),
59                role: AlertButtonRole::Destructive,
60            }],
61        }
62    }
63
64    /// Creates a one-button warning alert.
65    pub const fn warning(message: Localized<'a>) -> Self {
66        Self {
67            kind: AlertKind::Warning,
68            title: Localized::new("fs.alert.warning", "Warning"),
69            message,
70            actions: [AlertAction {
71                id: 0,
72                label: Localized::new("fs.alert.ok", "OK"),
73                role: AlertButtonRole::Primary,
74            }],
75        }
76    }
77}
78
79impl<'a> AlertSpec<'a, 2> {
80    /// Creates a two-button confirmation alert.
81    pub const fn confirm(title: Localized<'a>, message: Localized<'a>) -> Self {
82        Self {
83            kind: AlertKind::Confirm,
84            title,
85            message,
86            actions: [
87                AlertAction {
88                    id: 0,
89                    label: Localized::new("fs.alert.cancel", "Cancel"),
90                    role: AlertButtonRole::Secondary,
91                },
92                AlertAction {
93                    id: 1,
94                    label: Localized::new("fs.alert.confirm", "Confirm"),
95                    role: AlertButtonRole::Primary,
96                },
97            ],
98        }
99    }

Trait Implementations§

Source§

impl<'a> Clone for Localized<'a>

Source§

fn clone(&self) -> Localized<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Localized<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for Localized<'a>

Source§

fn eq(&self, other: &Localized<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Copy for Localized<'a>

Source§

impl<'a> Eq for Localized<'a>

Source§

impl<'a> StructuralPartialEq for Localized<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Localized<'a>

§

impl<'a> RefUnwindSafe for Localized<'a>

§

impl<'a> Send for Localized<'a>

§

impl<'a> Sync for Localized<'a>

§

impl<'a> Unpin for Localized<'a>

§

impl<'a> UnsafeUnpin for Localized<'a>

§

impl<'a> UnwindSafe for Localized<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.