pub struct Label { /* private fields */ }
Expand description
Display text to widgets
§Examples
use oxide::core::{VerticalAlign, HorizontalAlign, Widget};
use oxide::{Dialog, Label};
let mut maindlg = Dialog::new(60, 10);
let mut label = Label::from_str("Hi, this is an example!");
label.pack(&maindlg, HorizontalAlign::Middle, VerticalAlign::Middle, (0,0));
maindlg.add_label(label);
maindlg.draw_box();
Implementations§
Source§impl Label
impl Label
Sourcepub fn new(cols: usize, rows: usize) -> Label
pub fn new(cols: usize, rows: usize) -> Label
Construct a new Label widget cols
wide by rols
high. Initial text is empty
and left aligned
§Examples
use oxide::Label;
let mut label = Label::new(60, 10);
Sourcepub fn from_str<S: Into<String>>(s: S) -> Label
pub fn from_str<S: Into<String>>(s: S) -> Label
Construct a new label widget from an existing string s. s can either be a
&str
or String
, and a label will be constructed that is the size of the
length of characters in s. Text is left aligned by default
§Examples
use oxide::Label;
let mut label1 = Label::from_str("This is a label"); // label is size (15x1)
let s = "Here's another label".to_string();
let mut label2 = Label::from_str(s); // label is size (20x1)
Sourcepub fn from_str_ref(s: &str) -> Label
pub fn from_str_ref(s: &str) -> Label
Construct a new label widget from an existing string s. s can either be a
&str
or String
, and a label will be constructed that is the size of the
length of characters in s. Text is left aligned by default
§Examples
use oxide::Label;
let mut label1 = Label::from_str("This is a label"); // label is size (15x1)
let s = "Here's another label".to_string();
let mut label2 = Label::from_str(s); // label is size (20x1)
Sourcepub fn align_text(
&mut self,
halign: HorizontalAlign,
valign: VerticalAlign,
margin: (usize, usize),
)
pub fn align_text( &mut self, halign: HorizontalAlign, valign: VerticalAlign, margin: (usize, usize), )
Specify a custom alignment for the text within the widget. Each line drawn within the label will adhere to the alignments passed for the text. *note that text alignment is with respect to the label
§Examples
use oxide::core::{HorizontalAlign, VerticalAlign};
use oxide::Label;
let mut label = Label::new(20, 3);
label.set_text("Centered");
label.align_text(HorizontalAlign::Middle, VerticalAlign::Middle, (0,0));
Sourcepub fn set_text<S: Into<String>>(&mut self, new_str: S)
pub fn set_text<S: Into<String>>(&mut self, new_str: S)
Set the text of the widget to the passed &str
or String
. If the
widget does not have enough room to display the new text, the label
will only show the truncated text. resize() must be called to extend
the size of the label.
§Examples
use rustty::HasSize;
use oxide::core::Widget;
use oxide::Label;
let mut label1 = Label::new(20, 3);
label1.set_text("Initial text");
Trait Implementations§
Source§impl Widget for Label
impl Widget for Label
Source§fn draw(&mut self, parent: &mut dyn CellAccessor)
fn draw(&mut self, parent: &mut dyn CellAccessor)
CellAccessor
passedSource§fn pack(
&mut self,
parent: &dyn HasSize,
halign: HorizontalAlign,
valign: VerticalAlign,
margin: (usize, usize),
)
fn pack( &mut self, parent: &dyn HasSize, halign: HorizontalAlign, valign: VerticalAlign, margin: (usize, usize), )
parent
as reference