Text

Struct Text 

Source
pub struct Text {
    pub text: String,
    pub color: Color,
    pub font_size: u16,
    pub font_name: String,
    pub font_style: FontStyle,
}

Fields§

§text: String§color: Color§font_size: u16§font_name: String§font_style: FontStyle

Implementations§

Source§

impl Text

Source

pub fn new(text: String, font_size: u16, font_name: Option<&str>) -> Self

Examples found in repository?
examples/basic.rs (line 55)
43fn main() {
44    let mut my_app = MyApp;
45
46    let mut pd_sdl: PgSdl = PgSdl::init("Benday", 1200, 720, Some(60), true, Colors::SKY_BLUE);
47
48    pd_sdl
49        .add_widget(
50            "button",
51            Box::new(Button::new(
52                Colors::ROYAL_BLUE,
53                rect!(500, 500, 200, 100),
54                Some(9),
55                Some(Text::new("Auto !".to_string(), 16, None)),
56            )),
57        )
58        .add_widget(
59            "slider",
60            Box::new(Slider::new(
61                Colors::ROYAL_BLUE,
62                rect!(110, 220, 200, 100),
63                Some(9),
64                SliderType::Continuous {
65                    display: None,
66                    default_value: 0.5,
67                },
68            )),
69        )
70        .add_widget(
71            "text input",
72            Box::new(TextInput::new(
73                Colors::WHITE,
74                rect!(222, 295, 200, 100),
75                Some(9),
76                Some(Text::new("Auto !".to_string(), 16, None)),
77            )),
78        );
79
80    pd_sdl.run(&mut my_app);
81}
More examples
Hide additional examples
examples/spring_test/main.rs (line 121)
92fn main() {
93    let my_app = &mut PhysicsApp {
94        masses: Vec::from([
95            Mass::new(Vec2::new(0.0, 0.0), 0.0, 0.0, Colors::BLACK, true),
96            Mass::new(Vec2::new(600.0, 400.0), 1.0, 20.0, Colors::ORANGE, true),
97            Mass::new(Vec2::new(600.0, 450.0), 1.0, 15.0, Colors::ORANGE, true),
98            Mass::new(Vec2::new(600.0, 550.0), 5.0, 25.0, Colors::RED, false),
99            Mass::new(Vec2::new(800.0, 200.0), 1.0, 20.0, Colors::GREEN, true),
100            Mass::new(Vec2::new(800.0, 650.0), 1.0, 20.0, Colors::MAGENTA, false),
101        ]),
102        rods: Vec::from([
103            Rod::new(3, 4, 250.0, 10.0, Colors::BROWN),
104            Rod::new(3, 5, 50.0, 10.0, Colors::BROWN),
105        ]),
106        springs: Vec::from([
107            Spring::new(0, 0, 1.0, 0.5, 0.0, 20.0, Colors::WHITE),
108            Spring::new(2, 3, 0.5, 0.2, 150.0, 40.0, Colors::BEIGE),
109        ]),
110        motors: Vec::from([Motor::new(1, 2, 0.4, Colors::LIGHT_GREY)]),
111    };
112
113    let mut app: PgSdl = PgSdl::init("Spring test", 1200, 720, Some(60), true, Colors::SKY_BLUE);
114    app.add_widgets(HashMap::from([
115        (
116            "play",
117            Box::new(Button::new(
118                Colors::ORANGE,
119                rect!(300, 35, 120, 50),
120                Some(9),
121                Some(Text::new("Start".to_string(), 18, None)),
122            )) as Box<dyn Widget>,
123        ),
124        (
125            "speed",
126            Box::new(Slider::new(
127                Colors::ORANGE,
128                rect!(500, 50, 200, 30),
129                Some(20),
130                SliderType::Continuous {
131                    default_value: 0.0,
132                    display: Some(Box::new(|value| format!("{:.2}", value))),
133                },
134            )),
135        ),
136    ]));
137    app.run(my_app);
138}

Trait Implementations§

Source§

impl Default for Text

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnwindSafe for Text

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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

fn type_name(&self) -> &'static str

Gets the type name of self
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> Downcast for T
where T: AsAny + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
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.