[][src]Struct druid::widget::Label

pub struct Label<T> { /* fields omitted */ }

A label that displays some text.

Implementations

impl<T: Data> Label<T>[src]

pub fn new(text: impl Into<LabelText<T>>) -> Self[src]

Construct a new Label widget.

use druid::LocalizedString;
use druid::widget::Label;

// Construct a new Label using static string.
let _: Label<u32> = Label::new("Hello world");

// Construct a new Label using localized string.
let text = LocalizedString::new("hello-counter").with_arg("count", |data: &u32, _env| (*data).into());
let _: Label<u32> = Label::new(text);

// Construct a new dynamic Label. Text will be updated when data changes.
let _: Label<u32> = Label::new(|data: &u32, _env: &_| format!("Hello world: {}", data));

pub fn dynamic(text: impl Fn(&T, &Env) -> String + 'static) -> Self[src]

Construct a new dynamic label.

The contents of this label are generated from the data using a closure.

This is provided as a convenience; a closure can also be passed to new, but due to limitations of the implementation of that method, the types in the closure need to be annotated, which is not true for this method.

Examples

The following are equivalent.

use druid::Env;
use druid::widget::Label;
let label1: Label<u32> = Label::new(|data: &u32, _: &Env| format!("total is {}", data));
let label2: Label<u32> = Label::dynamic(|data, _| format!("total is {}", data));

pub fn text_align(self, _align: UnitPoint) -> Self[src]

👎 Deprecated since 0.5.0:

Use an Align widget instead

Set text alignment.

pub fn with_text_color(self, color: impl Into<KeyOrValue<Color>>) -> Self[src]

Builder-style method for setting the text color.

The argument can be either a Color or a Key<Color>.

pub fn with_text_size(self, size: impl Into<KeyOrValue<f64>>) -> Self[src]

Builder-style method for setting the text size.

The argument can be either an f64 or a Key<f64>.

pub fn with_font(self, font: impl Into<KeyOrValue<&'static str>>) -> Self[src]

Builder-style method for setting the font.

The argument can be a &str, String, or Key<&str>.

pub fn set_text(&mut self, text: impl Into<String>)[src]

Set a new text.

Takes an already resolved string as input.

If you're looking for full LabelText support, then you need to create a new Label.

pub fn text(&self) -> &str[src]

Returns this label's current text.

pub fn set_text_color(&mut self, color: impl Into<KeyOrValue<Color>>)[src]

Set the text color.

The argument can be either a Color or a Key<Color>.

pub fn set_text_size(&mut self, size: impl Into<KeyOrValue<f64>>)[src]

Set the text size.

The argument can be either an f64 or a Key<f64>.

pub fn set_font(&mut self, font: impl Into<KeyOrValue<&'static str>>)[src]

Set the font.

The argument can be a &str, String, or Key<&str>.

Trait Implementations

impl<T: Data> Widget<T> for Label<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Label<T>

impl<T> !Send for Label<T>

impl<T> !Sync for Label<T>

impl<T> Unpin for Label<T>

impl<T> !UnwindSafe for Label<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> RoundFrom<T> for T

impl<T, U> RoundInto<U> for T where
    U: RoundFrom<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.