Skip to content

Latest commit

 

History

History
57 lines (44 loc) · 1.49 KB

text.md

File metadata and controls

57 lines (44 loc) · 1.49 KB

Text

The Text widget is able to display texts. It has three methods of constructions. It is able to change the font, the size of the font, and display special characters. The text inside the widget can be horizontally or vertically centered.

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


pub fn main() -> iced::Result {
    iced::application("My app", update, view).run()
}


#[derive(Debug, Clone)]

enum Message {
    _Increment,
}

fn update(_value: &mut u64, _message: Message) {}

fn view(_value: &u64) -> Column<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)
            .align_y(Vertical::Center),
        text("Vertical center")
            .height(Length::Fill)
            .align_y(Vertical::Center),
    ].into()
}

Text

➡️ Next: Button

📘 Back: Table of contents