pub struct DynamicLabelMeta {
pub key: Option<String>,
pub fallback: String,
pub locale: Option<LocaleId>,
pub direction: TextDirection,
pub bidi: BidiPolicy,
pub update: LabelUpdatePolicy,
}Fields§
§key: Option<String>§fallback: String§locale: Option<LocaleId>§direction: TextDirection§bidi: BidiPolicy§update: LabelUpdatePolicyImplementations§
Source§impl DynamicLabelMeta
impl DynamicLabelMeta
pub fn literal(text: impl Into<String>) -> Self
Sourcepub fn keyed(key: impl Into<String>, fallback: impl Into<String>) -> Self
pub fn keyed(key: impl Into<String>, fallback: impl Into<String>) -> Self
Examples found in repository?
examples/showcase.rs (line 3355)
3313fn labels(ui: &mut UiDocument, parent: UiNodeId, state: &ShowcaseState) {
3314 let body = section(ui, parent, "labels", "Labels");
3315 ui.set_node_style(
3316 body,
3317 LayoutStyle::column()
3318 .with_width_percent(1.0)
3319 .with_height_percent(1.0)
3320 .with_flex_grow(1.0)
3321 .gap(10.0),
3322 );
3323 widgets::label(
3324 ui,
3325 body,
3326 "labels.plain",
3327 "Plain label",
3328 text(13.0, color(226, 232, 242)),
3329 LayoutStyle::new().with_width_percent(1.0),
3330 );
3331 let locale_items = label_locale_options();
3332 let locale_id = state
3333 .label_locale
3334 .selected_id(&locale_items)
3335 .unwrap_or("es-MX");
3336 let localization =
3337 LocalizationPolicy::new(LocaleId::new(locale_id).unwrap_or_else(|_| LocaleId::default()));
3338 let locale_row = ui.add_child(
3339 body,
3340 UiNode::container(
3341 "labels.locale.row",
3342 LayoutStyle::row()
3343 .with_width_percent(1.0)
3344 .with_align_items(taffy::prelude::AlignItems::Center)
3345 .gap(10.0),
3346 ),
3347 );
3348 let locale_label_width = 270.0;
3349 let locale_dropdown_width = 148.0;
3350 let locale_gap = 10.0;
3351 widgets::localized_label(
3352 ui,
3353 locale_row,
3354 "labels.localized",
3355 DynamicLabelMeta::keyed("showcase.localized.greeting", localized_label(locale_id)),
3356 Some(&localization),
3357 text(13.0, color(170, 202, 255)),
3358 LayoutStyle::new().with_width(locale_label_width),
3359 );
3360 let mut locale_options = ext_widgets::DropdownSelectOptions::default();
3361 locale_options.trigger_layout = LayoutStyle::row()
3362 .with_width(locale_dropdown_width)
3363 .with_height(30.0)
3364 .with_align_items(taffy::prelude::AlignItems::Center)
3365 .with_justify_content(taffy::prelude::JustifyContent::Center)
3366 .padding(6.0);
3367 locale_options.text_style = text(13.0, color(226, 232, 242));
3368 locale_options.accessibility_label = Some("Locale".to_string());
3369 locale_options.menu =
3370 ext_widgets::SelectMenuOptions::default().with_action_prefix("labels.locale");
3371 locale_options.menu.width = locale_dropdown_width;
3372 locale_options.menu.row_height = 30.0;
3373 locale_options.menu.max_visible_rows = locale_items.len();
3374 locale_options.menu.text_style = text(13.0, color(226, 232, 242));
3375 locale_options.menu.portal = UiPortalTarget::Parent;
3376 let locale_nodes = ext_widgets::dropdown_select(
3377 ui,
3378 locale_row,
3379 "labels.locale",
3380 &locale_items,
3381 &state.label_locale,
3382 Some(ext_widgets::AnchoredPopup::new(
3383 UiRect::new(
3384 locale_label_width + locale_gap,
3385 0.0,
3386 locale_dropdown_width,
3387 30.0,
3388 ),
3389 UiRect::new(0.0, 0.0, 460.0, 260.0),
3390 ext_widgets::PopupPlacement::default().with_viewport_margin(0.0),
3391 )),
3392 locale_options,
3393 );
3394 ui.node_mut(locale_nodes.trigger)
3395 .set_action("labels.locale.toggle");
3396 widgets::label(
3397 ui,
3398 body,
3399 "labels.muted",
3400 "Muted helper label",
3401 text(12.0, color(154, 166, 184)),
3402 LayoutStyle::new().with_width_percent(1.0),
3403 );
3404
3405 let sizes = ui.add_child(
3406 body,
3407 UiNode::container(
3408 "labels.sizes",
3409 LayoutStyle::row()
3410 .with_width_percent(1.0)
3411 .with_align_items(taffy::prelude::AlignItems::FlexEnd)
3412 .gap(12.0),
3413 ),
3414 );
3415 widgets::label(
3416 ui,
3417 sizes,
3418 "labels.size.small",
3419 "12px",
3420 text(12.0, color(226, 232, 242)),
3421 LayoutStyle::new(),
3422 );
3423 widgets::label(
3424 ui,
3425 sizes,
3426 "labels.size.default",
3427 "13px",
3428 text(13.0, color(226, 232, 242)),
3429 LayoutStyle::new(),
3430 );
3431 widgets::label(
3432 ui,
3433 sizes,
3434 "labels.size.large",
3435 "18px",
3436 text(18.0, color(246, 249, 252)),
3437 LayoutStyle::new(),
3438 );
3439 widgets::label(
3440 ui,
3441 sizes,
3442 "labels.size.display",
3443 "24px",
3444 text(24.0, color(246, 249, 252)),
3445 LayoutStyle::new(),
3446 );
3447
3448 let style_row = row(ui, body, "labels.styles", 12.0);
3449 let mut bold = text(13.0, color(246, 249, 252));
3450 bold.weight = FontWeight::BOLD;
3451 widgets::label(
3452 ui,
3453 style_row,
3454 "labels.style.bold",
3455 "Bold",
3456 bold,
3457 LayoutStyle::new(),
3458 );
3459 widgets::label(
3460 ui,
3461 style_row,
3462 "labels.style.weak",
3463 "Muted",
3464 text(13.0, color(154, 166, 184)),
3465 LayoutStyle::new(),
3466 );
3467
3468 let font_row = row(ui, body, "labels.fonts", 12.0);
3469 let mut serif = text(13.0, color(226, 232, 242));
3470 serif.family = FontFamily::Serif;
3471 widgets::label(
3472 ui,
3473 font_row,
3474 "labels.font.serif",
3475 "Serif",
3476 serif,
3477 LayoutStyle::new(),
3478 );
3479 let mut mono = text(13.0, color(226, 232, 242));
3480 mono.family = FontFamily::Monospace;
3481 widgets::label(
3482 ui,
3483 font_row,
3484 "labels.font.mono",
3485 "Monospace",
3486 mono,
3487 LayoutStyle::new(),
3488 );
3489
3490 let code_panel = ui.add_child(
3491 body,
3492 UiNode::container(
3493 "labels.code.panel",
3494 LayoutStyle::new()
3495 .with_width_percent(1.0)
3496 .padding(8.0)
3497 .with_height(36.0),
3498 )
3499 .with_visual(UiVisual::panel(
3500 color(10, 14, 20),
3501 Some(StrokeStyle::new(color(47, 59, 74), 1.0)),
3502 4.0,
3503 )),
3504 );
3505 widgets::code_label(
3506 ui,
3507 code_panel,
3508 "labels.code",
3509 "let label = widgets::label(...);",
3510 LayoutStyle::new().with_width_percent(1.0),
3511 );
3512
3513 let colors = row(ui, body, "labels.colors", 14.0);
3514 widgets::colored_label(
3515 ui,
3516 colors,
3517 "labels.color.green",
3518 "Green",
3519 color(111, 203, 159),
3520 LayoutStyle::new(),
3521 );
3522 widgets::colored_label(
3523 ui,
3524 colors,
3525 "labels.color.yellow",
3526 "Yellow",
3527 color(232, 196, 101),
3528 LayoutStyle::new(),
3529 );
3530 widgets::colored_label(
3531 ui,
3532 colors,
3533 "labels.color.red",
3534 "Red",
3535 color(244, 118, 118),
3536 LayoutStyle::new(),
3537 );
3538
3539 let wrap_row = wrapping_row(ui, body, "labels.wrap.row", 10.0);
3540 let wrap_word = ui.add_child(
3541 wrap_row,
3542 UiNode::container(
3543 "labels.wrap.word.panel",
3544 LayoutStyle::column().with_width(172.0).padding(8.0),
3545 )
3546 .with_visual(UiVisual::panel(
3547 color(18, 23, 31),
3548 Some(StrokeStyle::new(color(47, 59, 74), 1.0)),
3549 4.0,
3550 )),
3551 );
3552 widgets::wrapped_label(
3553 ui,
3554 wrap_word,
3555 "labels.wrap.word",
3556 "Word wrapping keeps this sentence readable in a narrow box.",
3557 TextWrap::Word,
3558 LayoutStyle::new().with_width_percent(1.0),
3559 );
3560 let wrap_glyph = ui.add_child(
3561 wrap_row,
3562 UiNode::container(
3563 "labels.wrap.glyph.panel",
3564 LayoutStyle::column().with_width(172.0).padding(8.0),
3565 )
3566 .with_visual(UiVisual::panel(
3567 color(18, 23, 31),
3568 Some(StrokeStyle::new(color(47, 59, 74), 1.0)),
3569 4.0,
3570 )),
3571 );
3572 widgets::wrapped_label(
3573 ui,
3574 wrap_glyph,
3575 "labels.wrap.glyph",
3576 "LongIdentifierWithoutSpaces",
3577 TextWrap::Glyph,
3578 LayoutStyle::new().with_width_percent(1.0),
3579 );
3580
3581 let links = wrapping_row(ui, body, "labels.links", 12.0);
3582 widgets::link(
3583 ui,
3584 links,
3585 "labels.link",
3586 "Internal action",
3587 widgets::LinkOptions::default()
3588 .visited(state.label_link_visited)
3589 .with_action("labels.link"),
3590 );
3591 widgets::hyperlink(
3592 ui,
3593 links,
3594 "labels.hyperlink",
3595 "Open docs.rs",
3596 "https://docs.rs/operad",
3597 widgets::LinkOptions::default()
3598 .visited(state.label_hyperlink_visited)
3599 .with_action("labels.hyperlink"),
3600 );
3601 if state.label_link_status != "No link action yet" {
3602 widgets::label(
3603 ui,
3604 body,
3605 "labels.status",
3606 format!("Last action: {}", state.label_link_status),
3607 text(12.0, color(154, 166, 184)),
3608 LayoutStyle::new().with_width_percent(1.0),
3609 );
3610 }
3611}pub fn dynamic( key: impl Into<String>, fallback: impl Into<String>, revision: u64, ) -> Self
pub fn with_locale(self, locale: LocaleId) -> Self
pub fn with_direction(self, direction: TextDirection) -> Self
pub fn with_bidi(self, bidi: BidiPolicy) -> Self
pub fn with_update(self, update: LabelUpdatePolicy) -> Self
pub fn resolved_direction( &self, policy: Option<&LocalizationPolicy>, ) -> ResolvedTextDirection
Trait Implementations§
Source§impl Clone for DynamicLabelMeta
impl Clone for DynamicLabelMeta
Source§fn clone(&self) -> DynamicLabelMeta
fn clone(&self) -> DynamicLabelMeta
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DynamicLabelMeta
impl Debug for DynamicLabelMeta
Source§impl PartialEq for DynamicLabelMeta
impl PartialEq for DynamicLabelMeta
Source§fn eq(&self, other: &DynamicLabelMeta) -> bool
fn eq(&self, other: &DynamicLabelMeta) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for DynamicLabelMeta
impl StructuralPartialEq for DynamicLabelMeta
Auto Trait Implementations§
impl Freeze for DynamicLabelMeta
impl RefUnwindSafe for DynamicLabelMeta
impl Send for DynamicLabelMeta
impl Sync for DynamicLabelMeta
impl Unpin for DynamicLabelMeta
impl UnsafeUnpin for DynamicLabelMeta
impl UnwindSafe for DynamicLabelMeta
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
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>
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)
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)
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
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.