Skip to content

Latest commit

 

History

History
55 lines (45 loc) · 1.48 KB

File metadata and controls

55 lines (45 loc) · 1.48 KB

Text

The Text widget displays texts. It has three methods of constructions: raw &str, the text function, and the Text::new constructor. You can change the font, set different sizes, set its width and height, and align vertically or horizontally.

use iced::{
    Font, Length,
    alignment::{Horizontal, Vertical},
    font::Family,
    widget::{Text, column, text, text::Shaping},
};

fn main() -> iced::Result {
    iced::run("My App", MyApp::update, MyApp::view)
}

#[derive(Debug, Clone)]
enum Message {}

#[derive(Default)]
struct MyApp;

impl MyApp {
    fn update(&mut self, _message: Message) {}

    fn view(&self) -> iced::Element<Message> {
        column![
            "Construct from &str",
            text("Construct from function"),
            Text::new("Construct from struct"),
            text("Different font").font(Font {
                family: Family::Fantasy,
                ..Font::DEFAULT
            }),
            text("Larger text").size(24),
            text("Special character 😊").shaping(Shaping::Advanced),
            text("Center")
                .width(Length::Fill)
                .align_x(Horizontal::Center),
            text("Vertical center")
                .height(Length::Fill)
                .align_y(Vertical::Center),
        ]
        .into()
    }
}

Text

➡️ Next: Button

📘 Back: Table of contents