[−][src]Struct druid::widget::Label
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]
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]
fn event(
&mut self,
_ctx: &mut EventCtx,
_event: &Event,
_data: &mut T,
_env: &Env
)
[src]
&mut self,
_ctx: &mut EventCtx,
_event: &Event,
_data: &mut T,
_env: &Env
)
fn lifecycle(
&mut self,
_ctx: &mut LifeCycleCtx,
event: &LifeCycle,
data: &T,
env: &Env
)
[src]
&mut self,
_ctx: &mut LifeCycleCtx,
event: &LifeCycle,
data: &T,
env: &Env
)
fn update(&mut self, ctx: &mut UpdateCtx, old_data: &T, data: &T, env: &Env)
[src]
fn layout(
&mut self,
ctx: &mut LayoutCtx,
bc: &BoxConstraints,
_data: &T,
env: &Env
) -> Size
[src]
&mut self,
ctx: &mut LayoutCtx,
bc: &BoxConstraints,
_data: &T,
env: &Env
) -> Size
fn paint(&mut self, ctx: &mut PaintCtx, _data: &T, env: &Env)
[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> RoundFrom<T> for T
fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
fn round_into(self) -> U
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]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,