Skip to main content

RectOffset

Struct RectOffset 

Source
pub struct RectOffset {
    pub left: f32,
    pub right: f32,
    pub bottom: f32,
    pub top: f32,
}

Fields§

§left: f32§right: f32§bottom: f32§top: f32

Implementations§

Source§

impl RectOffset

Source

pub const fn new(left: f32, right: f32, top: f32, bottom: f32) -> RectOffset

Examples found in repository?
examples/ui_skins.rs (line 28)
6async fn main() {
7    let skin1 = {
8        let font = load_ttf_font("examples/ui_assets/HTOWERT.TTF")
9            .await
10            .unwrap();
11        let label_style = root_ui()
12            .style_builder()
13            .with_font(&font)
14            .unwrap()
15            .text_color(Color::from_rgba(180, 180, 120, 255))
16            .font_size(30)
17            .build();
18
19        let window_style = root_ui()
20            .style_builder()
21            .background(
22                Image::from_file_with_format(
23                    include_bytes!("../examples/ui_assets/window_background.png"),
24                    None,
25                )
26                .unwrap(),
27            )
28            .background_margin(RectOffset::new(20.0, 20.0, 10.0, 10.0))
29            .margin(RectOffset::new(-20.0, -30.0, 0.0, 0.0))
30            .build();
31
32        let button_style = root_ui()
33            .style_builder()
34            .background(
35                Image::from_file_with_format(
36                    include_bytes!("../examples/ui_assets/button_background.png"),
37                    None,
38                )
39                .unwrap(),
40            )
41            .background_margin(RectOffset::new(37.0, 37.0, 5.0, 5.0))
42            .margin(RectOffset::new(10.0, 10.0, 0.0, 0.0))
43            .background_hovered(
44                Image::from_file_with_format(
45                    include_bytes!("../examples/ui_assets/button_hovered_background.png"),
46                    None,
47                )
48                .unwrap(),
49            )
50            .background_clicked(
51                Image::from_file_with_format(
52                    include_bytes!("../examples/ui_assets/button_clicked_background.png"),
53                    None,
54                )
55                .unwrap(),
56            )
57            .with_font(&font)
58            .unwrap()
59            .text_color(Color::from_rgba(180, 180, 100, 255))
60            .font_size(40)
61            .build();
62
63        let editbox_style = root_ui()
64            .style_builder()
65            .background_margin(RectOffset::new(0., 0., 0., 0.))
66            .with_font(&font)
67            .unwrap()
68            .text_color(Color::from_rgba(120, 120, 120, 255))
69            .color_selected(Color::from_rgba(190, 190, 190, 255))
70            .font_size(50)
71            .build();
72
73        Skin {
74            editbox_style,
75            window_style,
76            button_style,
77            label_style,
78            ..root_ui().default_skin()
79        }
80    };
81
82    let skin2 = {
83        let font = load_ttf_font("examples/ui_assets/MinimalPixel v2.ttf")
84            .await
85            .unwrap();
86        let label_style = root_ui()
87            .style_builder()
88            .with_font(&font)
89            .unwrap()
90            .text_color(Color::from_rgba(120, 120, 120, 255))
91            .font_size(25)
92            .build();
93
94        let window_style = root_ui()
95            .style_builder()
96            .background(
97                Image::from_file_with_format(
98                    include_bytes!("../examples/ui_assets/window_background_2.png"),
99                    None,
100                )
101                .unwrap(),
102            )
103            .background_margin(RectOffset::new(52.0, 52.0, 52.0, 52.0))
104            .margin(RectOffset::new(-30.0, 0.0, -30.0, 0.0))
105            .build();
106
107        let button_style = root_ui()
108            .style_builder()
109            .background(
110                Image::from_file_with_format(
111                    include_bytes!("../examples/ui_assets/button_background_2.png"),
112                    None,
113                )
114                .unwrap(),
115            )
116            .background_margin(RectOffset::new(8.0, 8.0, 8.0, 8.0))
117            .background_hovered(
118                Image::from_file_with_format(
119                    include_bytes!("../examples/ui_assets/button_hovered_background_2.png"),
120                    None,
121                )
122                .unwrap(),
123            )
124            .background_clicked(
125                Image::from_file_with_format(
126                    include_bytes!("../examples/ui_assets/button_clicked_background_2.png"),
127                    None,
128                )
129                .unwrap(),
130            )
131            .with_font(&font)
132            .unwrap()
133            .text_color(Color::from_rgba(180, 180, 100, 255))
134            .font_size(40)
135            .build();
136
137        let checkbox_style = root_ui()
138            .style_builder()
139            .background(
140                Image::from_file_with_format(
141                    include_bytes!("../examples/ui_assets/checkbox_background.png"),
142                    None,
143                )
144                .unwrap(),
145            )
146            .background_hovered(
147                Image::from_file_with_format(
148                    include_bytes!("../examples/ui_assets/checkbox_hovered_background.png"),
149                    None,
150                )
151                .unwrap(),
152            )
153            .background_clicked(
154                Image::from_file_with_format(
155                    include_bytes!("../examples/ui_assets/checkbox_clicked_background.png"),
156                    None,
157                )
158                .unwrap(),
159            )
160            .build();
161
162        let editbox_style = root_ui()
163            .style_builder()
164            .background(
165                Image::from_file_with_format(
166                    include_bytes!("../examples/ui_assets/editbox_background.png"),
167                    None,
168                )
169                .unwrap(),
170            )
171            .background_margin(RectOffset::new(2., 2., 2., 2.))
172            .with_font(&font)
173            .unwrap()
174            .text_color(Color::from_rgba(120, 120, 120, 255))
175            .font_size(25)
176            .build();
177
178        let combobox_style = root_ui()
179            .style_builder()
180            .background(
181                Image::from_file_with_format(
182                    include_bytes!("../examples/ui_assets/combobox_background.png"),
183                    None,
184                )
185                .unwrap(),
186            )
187            .background_margin(RectOffset::new(4., 25., 6., 6.))
188            .with_font(&font)
189            .unwrap()
190            .text_color(Color::from_rgba(120, 120, 120, 255))
191            .color(Color::from_rgba(210, 210, 210, 255))
192            .font_size(25)
193            .build();
194
195        Skin {
196            window_style,
197            button_style,
198            label_style,
199            checkbox_style,
200            editbox_style,
201            combobox_style,
202            ..root_ui().default_skin()
203        }
204    };
205    let default_skin = root_ui().default_skin().clone();
206
207    let mut window1_skin = skin1.clone();
208    let mut window2_skin = skin2.clone();
209
210    let mut checkbox = false;
211    let mut text = String::new();
212    let mut number = 0.0f32;
213    let mut combobox = 0;
214
215    loop {
216        clear_background(GRAY);
217
218        root_ui().group(hash!(), vec2(70.0, 100.0), |ui| {
219            ui.label(None, "Window 1");
220
221            if ui.button(None, "Skin 1") {
222                window1_skin = skin1.clone();
223            }
224            if ui.button(None, "Skin 2") {
225                window1_skin = skin2.clone();
226            }
227            if ui.button(None, "No Skin") {
228                window1_skin = default_skin.clone();
229            }
230        });
231        root_ui().same_line(0.);
232        root_ui().group(hash!(), vec2(70.0, 100.0), |ui| {
233            ui.label(None, "Window 2");
234            if ui.button(None, "Skin 1") {
235                window2_skin = skin1.clone();
236            }
237            if ui.button(None, "Skin 2") {
238                window2_skin = skin2.clone();
239            }
240            if ui.button(None, "No Skin") {
241                window2_skin = default_skin.clone();
242            }
243        });
244
245        root_ui().push_skin(&window1_skin);
246
247        root_ui().window(hash!(), vec2(20., 250.), vec2(300., 300.), |ui| {
248            widgets::Button::new("Play")
249                .position(vec2(65.0, 15.0))
250                .ui(ui);
251            widgets::Button::new("Options")
252                .position(vec2(40.0, 75.0))
253                .ui(ui);
254
255            widgets::Button::new("Quit")
256                .position(vec2(65.0, 195.0))
257                .ui(ui);
258        });
259        root_ui().pop_skin();
260
261        root_ui().push_skin(&window2_skin);
262        root_ui().window(hash!(), vec2(250., 20.), vec2(500., 250.), |ui| {
263            ui.checkbox(hash!(), "Checkbox 1", &mut checkbox);
264            ui.combo_box(
265                hash!(),
266                "Combobox",
267                &["First option", "Second option"],
268                &mut combobox,
269            );
270            ui.input_text(hash!(), "Text", &mut text);
271            ui.drag(hash!(), "Drag", None, &mut number);
272
273            widgets::Button::new("Apply")
274                .position(vec2(80.0, 150.0))
275                .ui(ui);
276            widgets::Button::new("Cancel")
277                .position(vec2(280.0, 150.0))
278                .ui(ui);
279        });
280        root_ui().pop_skin();
281
282        next_frame().await;
283    }
284}

Trait Implementations§

Source§

impl Clone for RectOffset

Source§

fn clone(&self) -> RectOffset

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RectOffset

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RectOffset

Source§

fn default() -> RectOffset

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

impl PartialEq for RectOffset

Source§

fn eq(&self, other: &RectOffset) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for RectOffset

Source§

impl StructuralPartialEq for RectOffset

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,