Skip to main content

LocaleId

Struct LocaleId 

Source
pub struct LocaleId { /* private fields */ }

Implementations§

Source§

impl LocaleId

Source

pub fn new(tag: impl Into<String>) -> Result<Self, LocaleIdentifierError>

Examples found in repository?
examples/showcase.rs (line 5067)
5043fn labels(ui: &mut UiDocument, parent: UiNodeId, state: &ShowcaseState) {
5044    let body = section(ui, parent, "labels", "Labels");
5045    ui.set_node_style(
5046        body,
5047        LayoutStyle::column()
5048            .with_width_percent(1.0)
5049            .with_height_percent(1.0)
5050            .with_flex_grow(1.0)
5051            .gap(10.0),
5052    );
5053    widgets::label(
5054        ui,
5055        body,
5056        "labels.plain",
5057        "Plain label",
5058        text(13.0, color(226, 232, 242)),
5059        LayoutStyle::new().with_width_percent(1.0),
5060    );
5061    let locale_items = label_locale_options();
5062    let locale_id = state
5063        .label_locale
5064        .selected_id(&locale_items)
5065        .unwrap_or("es-MX");
5066    let localization =
5067        LocalizationPolicy::new(LocaleId::new(locale_id).unwrap_or_else(|_| LocaleId::default()));
5068    let locale_row = ui.add_child(
5069        body,
5070        UiNode::container(
5071            "labels.locale.row",
5072            LayoutStyle::row()
5073                .with_width_percent(1.0)
5074                .with_align_items(taffy::prelude::AlignItems::Center)
5075                .gap(10.0),
5076        ),
5077    );
5078    let locale_label_width = 270.0;
5079    let locale_dropdown_width = 148.0;
5080    let locale_gap = 10.0;
5081    widgets::localized_label(
5082        ui,
5083        locale_row,
5084        "labels.localized",
5085        DynamicLabelMeta::keyed("showcase.localized.greeting", localized_label(locale_id)),
5086        Some(&localization),
5087        text(13.0, color(170, 202, 255)),
5088        LayoutStyle::new().with_width(locale_label_width),
5089    );
5090    let mut locale_options = ext_widgets::DropdownSelectOptions::default();
5091    locale_options.trigger_layout = LayoutStyle::row()
5092        .with_width(locale_dropdown_width)
5093        .with_height(30.0)
5094        .with_align_items(taffy::prelude::AlignItems::Center)
5095        .with_justify_content(taffy::prelude::JustifyContent::FlexStart)
5096        .gap(6.0)
5097        .padding(6.0);
5098    locale_options.text_style = text(13.0, color(226, 232, 242));
5099    locale_options.accessibility_label = Some("Locale".to_string());
5100    locale_options.menu =
5101        ext_widgets::SelectMenuOptions::default().with_action_prefix("labels.locale");
5102    locale_options.menu.width = locale_dropdown_width;
5103    locale_options.menu.row_height = 30.0;
5104    locale_options.menu.max_visible_rows = locale_items.len();
5105    locale_options.menu.text_style = text(13.0, color(226, 232, 242));
5106    locale_options.menu.portal = UiPortalTarget::Parent;
5107    let locale_nodes = ext_widgets::dropdown_select(
5108        ui,
5109        locale_row,
5110        "labels.locale",
5111        &locale_items,
5112        &state.label_locale,
5113        Some(ext_widgets::AnchoredPopup::new(
5114            UiRect::new(
5115                locale_label_width + locale_gap,
5116                0.0,
5117                locale_dropdown_width,
5118                30.0,
5119            ),
5120            UiRect::new(0.0, 0.0, 460.0, 260.0),
5121            ext_widgets::PopupPlacement::default()
5122                .with_offset(0.0)
5123                .with_viewport_margin(0.0),
5124        )),
5125        locale_options,
5126    );
5127    ui.node_mut(locale_nodes.trigger)
5128        .set_action("labels.locale.toggle");
5129    widgets::label(
5130        ui,
5131        body,
5132        "labels.muted",
5133        "Muted helper label",
5134        text(12.0, color(154, 166, 184)),
5135        LayoutStyle::new().with_width_percent(1.0),
5136    );
5137
5138    let sizes = ui.add_child(
5139        body,
5140        UiNode::container(
5141            "labels.sizes",
5142            LayoutStyle::row()
5143                .with_width_percent(1.0)
5144                .with_align_items(taffy::prelude::AlignItems::FlexEnd)
5145                .gap(12.0),
5146        ),
5147    );
5148    widgets::label(
5149        ui,
5150        sizes,
5151        "labels.size.small",
5152        "12px",
5153        text(12.0, color(226, 232, 242)),
5154        LayoutStyle::new(),
5155    );
5156    widgets::label(
5157        ui,
5158        sizes,
5159        "labels.size.default",
5160        "13px",
5161        text(13.0, color(226, 232, 242)),
5162        LayoutStyle::new(),
5163    );
5164    widgets::label(
5165        ui,
5166        sizes,
5167        "labels.size.large",
5168        "18px",
5169        text(18.0, color(246, 249, 252)),
5170        LayoutStyle::new(),
5171    );
5172    widgets::label(
5173        ui,
5174        sizes,
5175        "labels.size.display",
5176        "24px",
5177        text(24.0, color(246, 249, 252)),
5178        LayoutStyle::new(),
5179    );
5180
5181    let style_row = row(ui, body, "labels.styles", 12.0);
5182    let mut bold = text(13.0, color(246, 249, 252));
5183    bold.weight = FontWeight::BOLD;
5184    widgets::label(
5185        ui,
5186        style_row,
5187        "labels.style.bold",
5188        "Bold",
5189        bold,
5190        LayoutStyle::new(),
5191    );
5192    widgets::label(
5193        ui,
5194        style_row,
5195        "labels.style.weak",
5196        "Muted",
5197        text(13.0, color(154, 166, 184)),
5198        LayoutStyle::new(),
5199    );
5200
5201    let font_row = row(ui, body, "labels.fonts", 12.0);
5202    let mut serif = text(13.0, color(226, 232, 242));
5203    serif.family = FontFamily::Serif;
5204    widgets::label(
5205        ui,
5206        font_row,
5207        "labels.font.serif",
5208        "Serif",
5209        serif,
5210        LayoutStyle::new(),
5211    );
5212    let mut mono = text(13.0, color(226, 232, 242));
5213    mono.family = FontFamily::Monospace;
5214    widgets::label(
5215        ui,
5216        font_row,
5217        "labels.font.mono",
5218        "Monospace",
5219        mono,
5220        LayoutStyle::new(),
5221    );
5222
5223    let code_panel = ui.add_child(
5224        body,
5225        UiNode::container(
5226            "labels.code.panel",
5227            LayoutStyle::new()
5228                .with_width_percent(1.0)
5229                .padding(8.0)
5230                .with_height(36.0),
5231        )
5232        .with_visual(UiVisual::panel(
5233            color(10, 14, 20),
5234            Some(StrokeStyle::new(color(47, 59, 74), 1.0)),
5235            4.0,
5236        )),
5237    );
5238    widgets::code_label(
5239        ui,
5240        code_panel,
5241        "labels.code",
5242        "let label = widgets::label(...);",
5243        LayoutStyle::new().with_width_percent(1.0),
5244    );
5245
5246    let colors = row(ui, body, "labels.colors", 14.0);
5247    widgets::colored_label(
5248        ui,
5249        colors,
5250        "labels.color.green",
5251        "Green",
5252        color(111, 203, 159),
5253        LayoutStyle::new(),
5254    );
5255    widgets::colored_label(
5256        ui,
5257        colors,
5258        "labels.color.yellow",
5259        "Yellow",
5260        color(232, 196, 101),
5261        LayoutStyle::new(),
5262    );
5263    widgets::colored_label(
5264        ui,
5265        colors,
5266        "labels.color.red",
5267        "Red",
5268        color(244, 118, 118),
5269        LayoutStyle::new(),
5270    );
5271
5272    let wrap_row = wrapping_row(ui, body, "labels.wrap.row", 10.0);
5273    let wrap_word = ui.add_child(
5274        wrap_row,
5275        UiNode::container(
5276            "labels.wrap.word.panel",
5277            LayoutStyle::column().with_width(172.0).padding(8.0),
5278        )
5279        .with_visual(UiVisual::panel(
5280            color(18, 23, 31),
5281            Some(StrokeStyle::new(color(47, 59, 74), 1.0)),
5282            4.0,
5283        )),
5284    );
5285    widgets::wrapped_label(
5286        ui,
5287        wrap_word,
5288        "labels.wrap.word",
5289        "Word wrapping keeps this sentence readable in a narrow box.",
5290        TextWrap::Word,
5291        LayoutStyle::new().with_width_percent(1.0),
5292    );
5293    let wrap_glyph = ui.add_child(
5294        wrap_row,
5295        UiNode::container(
5296            "labels.wrap.glyph.panel",
5297            LayoutStyle::column().with_width(172.0).padding(8.0),
5298        )
5299        .with_visual(UiVisual::panel(
5300            color(18, 23, 31),
5301            Some(StrokeStyle::new(color(47, 59, 74), 1.0)),
5302            4.0,
5303        )),
5304    );
5305    widgets::wrapped_label(
5306        ui,
5307        wrap_glyph,
5308        "labels.wrap.glyph",
5309        "LongIdentifierWithoutSpaces",
5310        TextWrap::Glyph,
5311        LayoutStyle::new().with_width_percent(1.0),
5312    );
5313
5314    let links = wrapping_row(ui, body, "labels.links", 12.0);
5315    widgets::link(
5316        ui,
5317        links,
5318        "labels.link",
5319        "Internal action",
5320        widgets::LinkOptions::default()
5321            .visited(state.label_link_visited)
5322            .with_action("labels.link"),
5323    );
5324    widgets::hyperlink(
5325        ui,
5326        links,
5327        "labels.hyperlink",
5328        "Open docs.rs",
5329        "https://docs.rs/operad",
5330        widgets::LinkOptions::default()
5331            .visited(state.label_hyperlink_visited)
5332            .with_action("labels.hyperlink"),
5333    );
5334    if state.label_link_status != "No link action yet" {
5335        widgets::label(
5336            ui,
5337            body,
5338            "labels.status",
5339            format!("Last action: {}", state.label_link_status),
5340            text(12.0, color(154, 166, 184)),
5341            LayoutStyle::new().with_width_percent(1.0),
5342        );
5343    }
5344}
Source

pub fn unchecked(tag: impl Into<String>) -> Self

Source

pub fn as_str(&self) -> &str

Source

pub fn language(&self) -> &str

Source

pub fn direction_hint(&self) -> ResolvedTextDirection

Trait Implementations§

Source§

impl Clone for LocaleId

Source§

fn clone(&self) -> LocaleId

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 LocaleId

Source§

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

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

impl Default for LocaleId

Source§

fn default() -> Self

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

impl PartialEq for LocaleId

Source§

fn eq(&self, other: &LocaleId) -> 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 TryFrom<&str> for LocaleId

Source§

type Error = LocaleIdentifierError

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

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for LocaleId

Source§

impl StructuralPartialEq for LocaleId

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,