pub struct RawLabel<T> { /* private fields */ }
Expand description
A widget that displays text data.
This requires the Data
to implement TextStorage
; to handle static, dynamic, or
localized text, use Label
.
Implementations§
source§impl<T: TextStorage> RawLabel<T>
impl<T: TextStorage> RawLabel<T>
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new RawLabel
.
Examples found in repository?
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
fn build_root_widget() -> impl Widget<AppState> {
let label = Scroll::new(
RawLabel::new()
.with_text_color(Color::BLACK)
.with_line_break_mode(LineBreaking::WordWrap)
.lens(AppState::rendered)
.expand_width()
.padding((SPACER_SIZE * 4.0, SPACER_SIZE)),
)
.vertical()
.background(Color::grey8(222))
.expand();
let textbox = TextBox::multiline()
.lens(AppState::raw)
.controller(RichTextRebuilder)
.expand()
.padding(5.0);
Split::columns(label, textbox)
}
More examples
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
fn build_root_widget() -> impl Widget<AppState> {
let label = Scroll::new(
RawLabel::new()
.with_text_color(Color::BLACK)
.controller(LabelController)
.background(Color::WHITE)
.expand_width()
.padding((SPACER_SIZE * 4.0, SPACER_SIZE))
.background(Color::grey8(222)),
)
.vertical();
let line_break_chooser = Flex::column()
.with_child(Label::new("Line break mode"))
.with_spacer(SPACER_SIZE)
.with_child(RadioGroup::column(vec![
("Clip", LineBreaking::Clip),
("Wrap", LineBreaking::WordWrap),
("Overflow", LineBreaking::Overflow),
]))
.lens(AppState::line_break_mode);
let alignment_picker = Flex::column()
.with_child(Label::new("Justification"))
.with_spacer(SPACER_SIZE)
.with_child(RadioGroup::column(vec![
("Start", TextAlignment::Start),
("End", TextAlignment::End),
("Center", TextAlignment::Center),
("Justified", TextAlignment::Justified),
]))
.lens(AppState::alignment);
let controls = Flex::row()
.cross_axis_alignment(druid::widget::CrossAxisAlignment::Start)
.with_child(alignment_picker)
.with_spacer(SPACER_SIZE)
.with_child(line_break_chooser)
.padding(SPACER_SIZE);
Flex::column()
.cross_axis_alignment(druid::widget::CrossAxisAlignment::Start)
.with_child(controls)
.with_flex_child(label, 1.0)
}
sourcepub fn with_text_color(self, color: impl Into<KeyOrValue<Color>>) -> Self
pub fn with_text_color(self, color: impl Into<KeyOrValue<Color>>) -> Self
Builder-style method for setting the text color.
The argument can be either a Color
or a Key<Color>
.
Examples found in repository?
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
fn build_root_widget() -> impl Widget<AppState> {
let label = Scroll::new(
RawLabel::new()
.with_text_color(Color::BLACK)
.with_line_break_mode(LineBreaking::WordWrap)
.lens(AppState::rendered)
.expand_width()
.padding((SPACER_SIZE * 4.0, SPACER_SIZE)),
)
.vertical()
.background(Color::grey8(222))
.expand();
let textbox = TextBox::multiline()
.lens(AppState::raw)
.controller(RichTextRebuilder)
.expand()
.padding(5.0);
Split::columns(label, textbox)
}
More examples
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
fn build_root_widget() -> impl Widget<AppState> {
let label = Scroll::new(
RawLabel::new()
.with_text_color(Color::BLACK)
.controller(LabelController)
.background(Color::WHITE)
.expand_width()
.padding((SPACER_SIZE * 4.0, SPACER_SIZE))
.background(Color::grey8(222)),
)
.vertical();
let line_break_chooser = Flex::column()
.with_child(Label::new("Line break mode"))
.with_spacer(SPACER_SIZE)
.with_child(RadioGroup::column(vec![
("Clip", LineBreaking::Clip),
("Wrap", LineBreaking::WordWrap),
("Overflow", LineBreaking::Overflow),
]))
.lens(AppState::line_break_mode);
let alignment_picker = Flex::column()
.with_child(Label::new("Justification"))
.with_spacer(SPACER_SIZE)
.with_child(RadioGroup::column(vec![
("Start", TextAlignment::Start),
("End", TextAlignment::End),
("Center", TextAlignment::Center),
("Justified", TextAlignment::Justified),
]))
.lens(AppState::alignment);
let controls = Flex::row()
.cross_axis_alignment(druid::widget::CrossAxisAlignment::Start)
.with_child(alignment_picker)
.with_spacer(SPACER_SIZE)
.with_child(line_break_chooser)
.padding(SPACER_SIZE);
Flex::column()
.cross_axis_alignment(druid::widget::CrossAxisAlignment::Start)
.with_child(controls)
.with_flex_child(label, 1.0)
}
sourcepub fn with_text_size(self, size: impl Into<KeyOrValue<f64>>) -> Self
pub fn with_text_size(self, size: impl Into<KeyOrValue<f64>>) -> Self
Builder-style method for setting the text size.
The argument can be either an f64
or a Key<f64>
.
sourcepub fn with_font(self, font: impl Into<KeyOrValue<FontDescriptor>>) -> Self
pub fn with_font(self, font: impl Into<KeyOrValue<FontDescriptor>>) -> Self
Builder-style method for setting the font.
The argument can be a FontDescriptor
or a Key<FontDescriptor>
that refers to a font defined in the Env
.
sourcepub fn with_line_break_mode(self, mode: LineBreaking) -> Self
pub fn with_line_break_mode(self, mode: LineBreaking) -> Self
Builder-style method to set the LineBreaking
behaviour.
Examples found in repository?
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
fn build_root_widget() -> impl Widget<AppState> {
let label = Scroll::new(
RawLabel::new()
.with_text_color(Color::BLACK)
.with_line_break_mode(LineBreaking::WordWrap)
.lens(AppState::rendered)
.expand_width()
.padding((SPACER_SIZE * 4.0, SPACER_SIZE)),
)
.vertical()
.background(Color::grey8(222))
.expand();
let textbox = TextBox::multiline()
.lens(AppState::raw)
.controller(RichTextRebuilder)
.expand()
.padding(5.0);
Split::columns(label, textbox)
}
sourcepub fn with_text_alignment(self, alignment: TextAlignment) -> Self
pub fn with_text_alignment(self, alignment: TextAlignment) -> Self
Builder-style method to set the TextAlignment
.
sourcepub fn set_text_color(&mut self, color: impl Into<KeyOrValue<Color>>)
pub fn set_text_color(&mut self, color: impl Into<KeyOrValue<Color>>)
Set the text color.
The argument can be either a Color
or a Key<Color>
.
If you change this property, you are responsible for calling
request_layout
to ensure the label is updated.
sourcepub fn set_text_size(&mut self, size: impl Into<KeyOrValue<f64>>)
pub fn set_text_size(&mut self, size: impl Into<KeyOrValue<f64>>)
Set the text size.
The argument can be either an f64
or a Key<f64>
.
If you change this property, you are responsible for calling
request_layout
to ensure the label is updated.
sourcepub fn set_font(&mut self, font: impl Into<KeyOrValue<FontDescriptor>>)
pub fn set_font(&mut self, font: impl Into<KeyOrValue<FontDescriptor>>)
Set the font.
The argument can be a FontDescriptor
or a Key<FontDescriptor>
that refers to a font defined in the Env
.
If you change this property, you are responsible for calling
request_layout
to ensure the label is updated.
sourcepub fn set_line_break_mode(&mut self, mode: LineBreaking)
pub fn set_line_break_mode(&mut self, mode: LineBreaking)
Set the LineBreaking
behaviour.
If you change this property, you are responsible for calling
request_layout
to ensure the label is updated.
Examples found in repository?
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
fn update(
&mut self,
child: &mut RawLabel<AppState>,
ctx: &mut UpdateCtx,
old_data: &AppState,
data: &AppState,
env: &Env,
) {
if old_data.line_break_mode != data.line_break_mode {
child.set_line_break_mode(data.line_break_mode);
ctx.request_layout();
}
if old_data.alignment != data.alignment {
child.set_text_alignment(data.alignment);
ctx.request_layout();
}
child.update(ctx, old_data, data, env);
}
sourcepub fn set_text_alignment(&mut self, alignment: TextAlignment)
pub fn set_text_alignment(&mut self, alignment: TextAlignment)
Set the TextAlignment
for this layout.
Examples found in repository?
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
fn update(
&mut self,
child: &mut RawLabel<AppState>,
ctx: &mut UpdateCtx,
old_data: &AppState,
data: &AppState,
env: &Env,
) {
if old_data.line_break_mode != data.line_break_mode {
child.set_line_break_mode(data.line_break_mode);
ctx.request_layout();
}
if old_data.alignment != data.alignment {
child.set_text_alignment(data.alignment);
ctx.request_layout();
}
child.update(ctx, old_data, data, env);
}
sourcepub fn draw_at(&self, ctx: &mut PaintCtx<'_, '_, '_>, origin: impl Into<Point>)
pub fn draw_at(&self, ctx: &mut PaintCtx<'_, '_, '_>, origin: impl Into<Point>)
Draw this label’s text at the provided Point
, without internal padding.
This is a convenience for widgets that want to use Label as a way of managing a dynamic or localized string, but want finer control over where the text is drawn.
sourcepub fn baseline_offset(&self) -> f64
pub fn baseline_offset(&self) -> f64
Return the offset of the first baseline relative to the bottom of the widget.