Skip to main content

LocalizationPolicy

Struct LocalizationPolicy 

Source
pub struct LocalizationPolicy {
    pub locale: LocaleId,
    pub text_direction: TextDirection,
    pub bidi: BidiPolicy,
    pub layout_mirroring: LayoutMirrorMode,
}

Fields§

§locale: LocaleId§text_direction: TextDirection§bidi: BidiPolicy§layout_mirroring: LayoutMirrorMode

Implementations§

Source§

impl LocalizationPolicy

Source

pub fn new(locale: LocaleId) -> Self

Examples found in repository?
examples/showcase.rs (line 2495)
2473fn labels(ui: &mut UiDocument, parent: UiNodeId, state: &ShowcaseState) {
2474    let body = section(ui, parent, "labels", "Labels");
2475    ui.node_mut(body).style.layout = LayoutStyle::column()
2476        .with_width_percent(1.0)
2477        .with_height_percent(1.0)
2478        .with_flex_grow(1.0)
2479        .gap(10.0)
2480        .as_taffy_style()
2481        .clone();
2482    widgets::label(
2483        ui,
2484        body,
2485        "labels.plain",
2486        "Plain label",
2487        text(13.0, color(226, 232, 242)),
2488        LayoutStyle::new().with_width_percent(1.0),
2489    );
2490    let locale_items = label_locale_options();
2491    let locale_id = state
2492        .label_locale
2493        .selected_id(&locale_items)
2494        .unwrap_or("es-MX");
2495    let localization = LocalizationPolicy::new(LocaleId::new(locale_id).expect("valid locale"));
2496    let locale_row = ui.add_child(
2497        body,
2498        UiNode::container(
2499            "labels.locale.row",
2500            LayoutStyle::row()
2501                .with_width_percent(1.0)
2502                .with_align_items(taffy::prelude::AlignItems::Center)
2503                .gap(10.0),
2504        ),
2505    );
2506    let locale_label_width = 270.0;
2507    let locale_dropdown_width = 148.0;
2508    let locale_gap = 10.0;
2509    widgets::localized_label(
2510        ui,
2511        locale_row,
2512        "labels.localized",
2513        DynamicLabelMeta::keyed("showcase.localized.greeting", localized_label(locale_id)),
2514        Some(&localization),
2515        text(13.0, color(170, 202, 255)),
2516        LayoutStyle::new().with_width(locale_label_width),
2517    );
2518    let mut locale_options = widgets::DropdownSelectOptions::default();
2519    locale_options.trigger_layout = LayoutStyle::row()
2520        .with_width(locale_dropdown_width)
2521        .with_height(30.0)
2522        .with_align_items(taffy::prelude::AlignItems::Center)
2523        .with_justify_content(taffy::prelude::JustifyContent::Center)
2524        .padding(6.0);
2525    locale_options.text_style = text(13.0, color(226, 232, 242));
2526    locale_options.accessibility_label = Some("Locale".to_string());
2527    locale_options.menu = widgets::SelectMenuOptions::default().with_action_prefix("labels.locale");
2528    locale_options.menu.width = locale_dropdown_width;
2529    locale_options.menu.row_height = 30.0;
2530    locale_options.menu.max_visible_rows = locale_items.len();
2531    locale_options.menu.text_style = text(13.0, color(226, 232, 242));
2532    let locale_nodes = widgets::dropdown_select(
2533        ui,
2534        locale_row,
2535        "labels.locale",
2536        &locale_items,
2537        &state.label_locale,
2538        Some(widgets::AnchoredPopup::new(
2539            UiRect::new(
2540                locale_label_width + locale_gap,
2541                0.0,
2542                locale_dropdown_width,
2543                30.0,
2544            ),
2545            UiRect::new(0.0, 0.0, 460.0, 260.0),
2546            widgets::PopupPlacement::default(),
2547        )),
2548        locale_options,
2549    );
2550    ui.node_mut(locale_nodes.trigger).action = Some("labels.locale.toggle".into());
2551    widgets::label(
2552        ui,
2553        body,
2554        "labels.muted",
2555        "Muted helper label",
2556        text(12.0, color(154, 166, 184)),
2557        LayoutStyle::new().with_width_percent(1.0),
2558    );
2559
2560    let sizes = ui.add_child(
2561        body,
2562        UiNode::container(
2563            "labels.sizes",
2564            LayoutStyle::row()
2565                .with_width_percent(1.0)
2566                .with_align_items(taffy::prelude::AlignItems::FlexEnd)
2567                .gap(12.0),
2568        ),
2569    );
2570    widgets::label(
2571        ui,
2572        sizes,
2573        "labels.size.small",
2574        "12px",
2575        text(12.0, color(226, 232, 242)),
2576        LayoutStyle::new(),
2577    );
2578    widgets::label(
2579        ui,
2580        sizes,
2581        "labels.size.default",
2582        "13px",
2583        text(13.0, color(226, 232, 242)),
2584        LayoutStyle::new(),
2585    );
2586    widgets::label(
2587        ui,
2588        sizes,
2589        "labels.size.large",
2590        "18px",
2591        text(18.0, color(246, 249, 252)),
2592        LayoutStyle::new(),
2593    );
2594    widgets::label(
2595        ui,
2596        sizes,
2597        "labels.size.display",
2598        "24px",
2599        text(24.0, color(246, 249, 252)),
2600        LayoutStyle::new(),
2601    );
2602
2603    let style_row = row(ui, body, "labels.styles", 12.0);
2604    let mut bold = text(13.0, color(246, 249, 252));
2605    bold.weight = FontWeight::BOLD;
2606    widgets::label(
2607        ui,
2608        style_row,
2609        "labels.style.bold",
2610        "Bold",
2611        bold,
2612        LayoutStyle::new(),
2613    );
2614    widgets::label(
2615        ui,
2616        style_row,
2617        "labels.style.weak",
2618        "Muted",
2619        text(13.0, color(154, 166, 184)),
2620        LayoutStyle::new(),
2621    );
2622
2623    let font_row = row(ui, body, "labels.fonts", 12.0);
2624    let mut serif = text(13.0, color(226, 232, 242));
2625    serif.family = FontFamily::Serif;
2626    widgets::label(
2627        ui,
2628        font_row,
2629        "labels.font.serif",
2630        "Serif",
2631        serif,
2632        LayoutStyle::new(),
2633    );
2634    let mut mono = text(13.0, color(226, 232, 242));
2635    mono.family = FontFamily::Monospace;
2636    widgets::label(
2637        ui,
2638        font_row,
2639        "labels.font.mono",
2640        "Monospace",
2641        mono,
2642        LayoutStyle::new(),
2643    );
2644
2645    let code_panel = ui.add_child(
2646        body,
2647        UiNode::container(
2648            "labels.code.panel",
2649            LayoutStyle::new()
2650                .with_width_percent(1.0)
2651                .padding(8.0)
2652                .with_height(36.0),
2653        )
2654        .with_visual(UiVisual::panel(
2655            color(10, 14, 20),
2656            Some(StrokeStyle::new(color(47, 59, 74), 1.0)),
2657            4.0,
2658        )),
2659    );
2660    widgets::code_label(
2661        ui,
2662        code_panel,
2663        "labels.code",
2664        "let label = widgets::label(...);",
2665        LayoutStyle::new().with_width_percent(1.0),
2666    );
2667
2668    let colors = row(ui, body, "labels.colors", 14.0);
2669    widgets::colored_label(
2670        ui,
2671        colors,
2672        "labels.color.green",
2673        "Green",
2674        color(111, 203, 159),
2675        LayoutStyle::new(),
2676    );
2677    widgets::colored_label(
2678        ui,
2679        colors,
2680        "labels.color.yellow",
2681        "Yellow",
2682        color(232, 196, 101),
2683        LayoutStyle::new(),
2684    );
2685    widgets::colored_label(
2686        ui,
2687        colors,
2688        "labels.color.red",
2689        "Red",
2690        color(244, 118, 118),
2691        LayoutStyle::new(),
2692    );
2693
2694    let wrap_row = wrapping_row(ui, body, "labels.wrap.row", 10.0);
2695    let wrap_word = ui.add_child(
2696        wrap_row,
2697        UiNode::container(
2698            "labels.wrap.word.panel",
2699            LayoutStyle::column().with_width(172.0).padding(8.0),
2700        )
2701        .with_visual(UiVisual::panel(
2702            color(18, 23, 31),
2703            Some(StrokeStyle::new(color(47, 59, 74), 1.0)),
2704            4.0,
2705        )),
2706    );
2707    widgets::wrapped_label(
2708        ui,
2709        wrap_word,
2710        "labels.wrap.word",
2711        "Word wrapping keeps this sentence readable in a narrow box.",
2712        TextWrap::Word,
2713        LayoutStyle::new().with_width_percent(1.0),
2714    );
2715    let wrap_glyph = ui.add_child(
2716        wrap_row,
2717        UiNode::container(
2718            "labels.wrap.glyph.panel",
2719            LayoutStyle::column().with_width(172.0).padding(8.0),
2720        )
2721        .with_visual(UiVisual::panel(
2722            color(18, 23, 31),
2723            Some(StrokeStyle::new(color(47, 59, 74), 1.0)),
2724            4.0,
2725        )),
2726    );
2727    widgets::wrapped_label(
2728        ui,
2729        wrap_glyph,
2730        "labels.wrap.glyph",
2731        "LongIdentifierWithoutSpaces",
2732        TextWrap::Glyph,
2733        LayoutStyle::new().with_width_percent(1.0),
2734    );
2735
2736    let links = wrapping_row(ui, body, "labels.links", 12.0);
2737    widgets::link(
2738        ui,
2739        links,
2740        "labels.link",
2741        "Internal action",
2742        widgets::LinkOptions::default()
2743            .visited(state.label_link_visited)
2744            .with_action("labels.link"),
2745    );
2746    widgets::hyperlink(
2747        ui,
2748        links,
2749        "labels.hyperlink",
2750        "Open docs.rs",
2751        "https://docs.rs/operad",
2752        widgets::LinkOptions::default()
2753            .visited(state.label_hyperlink_visited)
2754            .with_action("labels.hyperlink"),
2755    );
2756    if state.label_link_status != "No link action yet" {
2757        widgets::label(
2758            ui,
2759            body,
2760            "labels.status",
2761            format!("Last action: {}", state.label_link_status),
2762            text(12.0, color(154, 166, 184)),
2763            LayoutStyle::new().with_width_percent(1.0),
2764        );
2765    }
2766}
Source

pub fn with_text_direction(self, text_direction: TextDirection) -> Self

Source

pub fn with_bidi(self, bidi: BidiPolicy) -> Self

Source

pub fn with_layout_mirroring(self, layout_mirroring: LayoutMirrorMode) -> Self

Source

pub fn resolved_direction(&self) -> ResolvedTextDirection

Source

pub fn should_mirror_layout(&self) -> bool

Trait Implementations§

Source§

impl Clone for LocalizationPolicy

Source§

fn clone(&self) -> LocalizationPolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for LocalizationPolicy

Source§

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

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

impl Default for LocalizationPolicy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for LocalizationPolicy

Source§

fn eq(&self, other: &LocalizationPolicy) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Eq for LocalizationPolicy

Source§

impl StructuralPartialEq for LocalizationPolicy

Auto Trait Implementations§

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> 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<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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,