Struct Label

Source
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

Source

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);
Source

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)
Source

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)
Source

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));
Source

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

Source§

fn draw(&mut self, parent: &mut dyn CellAccessor)

Draws the widget to the valid CellAccessor passed
Source§

fn pack( &mut self, parent: &dyn HasSize, halign: HorizontalAlign, valign: VerticalAlign, margin: (usize, usize), )

Aligns the widget with the parent as reference
Source§

fn draw_box(&mut self)

Expose the painter trait draw_box for all widgets, which outlines the space enclosed within the widget
Source§

fn resize(&mut self, new_size: Size)

Resize the given widget to new dimensions given by Size
Source§

fn frame(&self) -> &Frame

Return a reference the renderer, Base in general cases
Source§

fn frame_mut(&mut self) -> &mut Frame

Return a mutable reference to the renderer, Base in general cases

Auto Trait Implementations§

§

impl Freeze for Label

§

impl RefUnwindSafe for Label

§

impl Send for Label

§

impl Sync for Label

§

impl Unpin for Label

§

impl UnwindSafe for Label

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.