Struct RectangleShape

Source
pub struct RectangleShape<'s> { /* private fields */ }
Expand description

Specialized shape representing a rectangle

Implementations§

Source§

impl<'s> RectangleShape<'s>

Source

pub fn new() -> RectangleShape<'s>

Returns a new RectangleShape.

§Panics

Panics if a RectangleShape can’t be created for some reason.

Examples found in repository?
examples/unicode-text-entry.rs (line 118)
12fn main() -> SfResult<()> {
13    example_ensure_right_working_dir();
14
15    let mut window = RenderWindow::new(
16        (800, 600),
17        "◢◤ Unicode text entry ◥◣",
18        Style::CLOSE,
19        &Default::default(),
20    )?;
21    window.set_vertical_sync_enabled(true);
22
23    // Showcase delayed initialization of font
24    let mut font = Font::new()?;
25
26    match std::env::args().nth(1) {
27        Some(path) => font.load_from_file(&path)?,
28        None => font.load_from_memory_static(include_bytes!("resources/sansation.ttf"))?,
29    };
30    let mut string = String::from("This text can be edited.\nTry it!");
31
32    let mut text = Text::new(string.clone(), &font, 24);
33    text.set_fill_color(Color::RED);
34    text.set_outline_color(Color::YELLOW);
35    text.set_outline_thickness(2.0);
36    let mut status_text = Text::new(String::new(), &font, 16);
37    status_text.tf.position = [0., window.size().y as f32 - 64.0];
38    let mut bold = false;
39    let mut italic = false;
40    let mut underlined = false;
41    let mut strikethrough = false;
42    let mut show_cursor = true;
43
44    'mainloop: loop {
45        while let Some(ev) = window.poll_event() {
46            match ev {
47                Event::Closed => break 'mainloop,
48                Event::TextEntered { unicode } => {
49                    if unicode == 0x08 as char {
50                        string.pop();
51                    } else if unicode == 0xD as char {
52                        string.push('\n');
53                    }
54                    // Ignore ctrl+v/ctrl+v generated chars
55                    else if unicode != 0x16 as char && unicode != 0x03 as char {
56                        string.push(unicode);
57                    }
58                    text.set_string(string.clone());
59                }
60                Event::KeyPressed { code, .. } => {
61                    match code {
62                        Key::Escape => break 'mainloop,
63                        Key::F1 => bold ^= true,
64                        Key::F2 => italic ^= true,
65                        Key::F3 => underlined ^= true,
66                        Key::F4 => strikethrough ^= true,
67                        Key::F5 => show_cursor ^= true,
68                        _ => {}
69                    }
70                    let mut style = TextStyle::default();
71                    if bold {
72                        style |= TextStyle::BOLD;
73                    }
74                    if italic {
75                        style |= TextStyle::ITALIC;
76                    }
77                    if underlined {
78                        style |= TextStyle::UNDERLINED;
79                    }
80                    if strikethrough {
81                        style |= TextStyle::STRIKETHROUGH;
82                    }
83                    text.set_style(style);
84                }
85                _ => {}
86            }
87        }
88
89        let status_string = {
90            let fc = text.fill_color();
91            let oc = text.outline_color();
92            format!(
93                "fill: {:02x}{:02x}{:02x}{:02x} outline: {:02x}{:02x}{:02x}{:02x} outline thickness: {}\n\
94            style: {:?} (F1-F4) cursor: {} (F5)\n\
95            font family: {}",
96                fc.r,
97                fc.g,
98                fc.b,
99                fc.a,
100                oc.r,
101                oc.g,
102                oc.b,
103                oc.a,
104                text.outline_thickness(),
105                text.style(),
106                show_cursor,
107                font.info().family
108            )
109        };
110        status_text.set_string(status_string);
111
112        window.clear(Color::BLACK);
113        text.draw(&mut *window, &RenderStates::DEFAULT);
114        if show_cursor {
115            let mut end = text.find_character_pos(usize::MAX);
116            end.x += 2.0;
117            end.y += 2.0;
118            let mut rs = RectangleShape::new();
119            rs.set_fill_color(Color::TRANSPARENT);
120            rs.set_outline_color(Color::YELLOW);
121            rs.set_outline_thickness(-3.0);
122            rs.set_position(end);
123            rs.set_size((8.0, 24.0));
124            window.draw_rectangle_shape(&rs, &RenderStates::DEFAULT);
125        }
126        status_text.draw(&mut *window, &RenderStates::DEFAULT);
127        window.display();
128    }
129    println!("The final text is {:?}", text.string());
130    Ok(())
131}
Source

pub fn with_texture(texture: &'s Texture) -> RectangleShape<'s>

Returns a new RectangleShape with the provided texture.

Source

pub fn with_size(size: Vector2f) -> RectangleShape<'s>

Returns a new RectangleShape with the provided size.

Source

pub fn from_rect(rect: FloatRect) -> Self

Returns a new RectangleShape created from a FloatRect.

Examples found in repository?
examples/vertex-arrays.rs (line 69)
10fn main() -> SfResult<()> {
11    let mut window = RenderWindow::new(
12        (800, 600),
13        "Vertex array example",
14        Style::CLOSE,
15        &Default::default(),
16    )?;
17    window.set_vertical_sync_enabled(true);
18
19    let mut vertex_array = [
20        Vertex::with_pos_color((20.0, 30.0).into(), Color::GREEN),
21        Vertex::with_pos_color((30.0, 30.0).into(), Color::GREEN),
22        Vertex::with_pos_color((40.0, 40.0).into(), Color::GREEN),
23        Vertex::with_pos_color((50.0, 50.0).into(), Color::GREEN),
24        Vertex::with_pos_color((60.0, 60.0).into(), Color::GREEN),
25        Vertex::with_pos_color((50.0, 80.0).into(), Color::GREEN),
26    ];
27
28    println!("\nIterate over the vertices of a vertex array");
29    for v in &vertex_array {
30        println!("Vertex Color: {:?} | Position: {:?}", v.color, v.position)
31    }
32
33    println!("\nMutable access to a vertex");
34    println!(
35        "Before Vertex Color: {:?} | Position: {:?}",
36        vertex_array[1].color, vertex_array[1].position
37    );
38    vertex_array[1].position.x = 100.0;
39    println!(
40        "After Vertex Color: {:?} | Position: {:?}",
41        vertex_array[1].color, vertex_array[1].position
42    );
43
44    println!("\nImmutable access to a vertex");
45    println!(
46        "Vertex Color: {:?} | Position: {:?}",
47        vertex_array[1].color, vertex_array[1].position
48    );
49
50    let vertex = &mut vertex_array[1];
51    println!(
52        "Before Vertex Color: {:?} | Position: {:?}",
53        vertex.color, vertex.position
54    );
55    vertex.position.x = 100.0;
56    println!(
57        "After Vertex Color: {:?} | Position: {:?}",
58        vertex.color, vertex.position
59    );
60
61    // Or:
62    vertex_array[1] = Vertex::with_pos((20., 40.).into());
63    println!("[2] After Vertex Position: {:?}", vertex_array[1].position);
64    println!(
65        "Vertex Color: {:?} | Position: {:?}",
66        vertex_array[1].color, vertex_array[1].position
67    );
68    let bounds = vertex_array_bounds(&vertex_array);
69    let mut bound_rect = RectangleShape::from_rect(bounds);
70    bound_rect.set_fill_color(Color::TRANSPARENT);
71    bound_rect.set_outline_thickness(1.0);
72    bound_rect.set_outline_color(Color::YELLOW);
73
74    'mainloop: loop {
75        while let Some(e) = window.poll_event() {
76            if e == Event::Closed {
77                break 'mainloop;
78            }
79        }
80        let rs = RenderStates::default();
81        // Clear the window
82        window.clear(Color::BLACK);
83        window.draw_primitives(&vertex_array, PrimitiveType::LINE_STRIP, &rs);
84        window.draw_rectangle_shape(&bound_rect, &RenderStates::DEFAULT);
85        // Display things on screen
86        window.display()
87    }
88    Ok(())
89}
Source

pub fn size(&self) -> Vector2f

Get the size of a rectangle shape

Return the height Size of the rectangle

Source

pub fn set_size<S: Into<Vector2f>>(&mut self, size: S)

Set the size of a rectangle shape

§Arguments
  • size - The new size of the rectangle
Examples found in repository?
examples/cursor.rs (line 45)
36fn draw_button(
37    rect: &Rect<i32>,
38    shape: &mut RectangleShape,
39    text: &mut Text,
40    string: &str,
41    render_window: &mut RenderWindow,
42    style: ButtonStyle,
43) {
44    shape.set_position((rect.left as f32, rect.top as f32));
45    shape.set_size((rect.width as f32, rect.height as f32));
46    let (rect_fill, rect_outline, text_fill) = match style {
47        ButtonStyle::Normal => (Color::TRANSPARENT, Color::WHITE, Color::WHITE),
48        ButtonStyle::Highlighted => (Color::WHITE, Color::WHITE, Color::BLACK),
49        ButtonStyle::Selected => (Color::GREEN, Color::GREEN, Color::BLACK),
50        ButtonStyle::Error => (Color::RED, Color::BLACK, Color::BLACK),
51    };
52    shape.set_outline_color(rect_outline);
53    shape.set_fill_color(rect_fill);
54    text.tf.position = [rect.left as f32 + 12.0, rect.top as f32 + 8.0];
55    text.set_fill_color(text_fill);
56    text.set_string(string.to_owned());
57    render_window.draw_rectangle_shape(shape, &RenderStates::DEFAULT);
58    text.draw(render_window, &RenderStates::DEFAULT);
59}
60
61fn bstyle(highlighted: bool, selected: bool, error: bool) -> ButtonStyle {
62    if error {
63        ButtonStyle::Error
64    } else if highlighted {
65        ButtonStyle::Highlighted
66    } else if selected {
67        ButtonStyle::Selected
68    } else {
69        ButtonStyle::Normal
70    }
71}
72
73fn main() -> SfResult<()> {
74    example_ensure_right_working_dir();
75
76    let mut cursor = Cursor::from_system(CursorType::Arrow)?;
77    let mut rw = RenderWindow::new(
78        (800, 800),
79        "SFML cursor example",
80        Style::CLOSE,
81        &ContextSettings::default(),
82    )?;
83    rw.set_vertical_sync_enabled(true);
84    let font = Font::from_file("sansation.ttf")?;
85    let mut failed_index = usize::MAX;
86    let mut selected_index = usize::MAX;
87    let set_button = Rect::new(348, 500, 100, 32);
88    let hotspot_button = Rect::new(458, 500, 100, 32);
89    let clear_button = Rect::new(568, 500, 100, 32);
90    let mut pixel_grid = [false; DRAW_GRID_WH as usize * DRAW_GRID_WH as usize];
91    let mut hotspot_selection = false;
92    let mut hotspot_selected = false;
93    let mut hotspot = Vector2::new(8, 8);
94    let mut modif = false;
95
96    let mut buttons = Vec::new();
97    let cursor_types = [
98        CursorType::Arrow,
99        CursorType::ArrowWait,
100        CursorType::Wait,
101        CursorType::Text,
102        CursorType::Hand,
103        CursorType::SizeHorizontal,
104        CursorType::SizeVertical,
105        CursorType::SizeTopLeftBottomRight,
106        CursorType::SizeBottomLeftTopRight,
107        CursorType::SizeLeft,
108        CursorType::SizeRight,
109        CursorType::SizeTop,
110        CursorType::SizeBottom,
111        CursorType::SizeTopLeft,
112        CursorType::SizeBottomRight,
113        CursorType::SizeBottomLeft,
114        CursorType::SizeTopRight,
115        CursorType::SizeAll,
116        CursorType::Cross,
117        CursorType::Help,
118        CursorType::NotAllowed,
119    ];
120    for i in 0..cursor_types.len() {
121        buttons.push(Rect::new(16, 16 + i as i32 * 36, 250, 32));
122    }
123
124    while rw.is_open() {
125        while let Some(ev) = rw.poll_event() {
126            match ev {
127                Event::Closed => rw.close(),
128                Event::MouseButtonPressed {
129                    button: mouse::Button::Left,
130                    x,
131                    y,
132                } => {
133                    for (i, b) in buttons.iter().enumerate() {
134                        if mouse_over(b, x, y) {
135                            match cursor.load_from_system(cursor_types[i]) {
136                                Ok(()) => {
137                                    unsafe {
138                                        rw.set_mouse_cursor(&cursor);
139                                    }
140                                    selected_index = i;
141                                }
142                                Err(e) => {
143                                    eprintln!("{e}");
144                                    failed_index = i;
145                                }
146                            }
147                        }
148                    }
149                    if mouse_over(&set_button, x, y) {
150                        let mut pixels = [0; DRAW_GRID_WH as usize * DRAW_GRID_WH as usize * 4];
151                        for (i, px) in pixel_grid.iter().enumerate() {
152                            let offset = i * 4;
153                            if *px {
154                                pixels[offset] = 255;
155                                pixels[offset + 1] = 255;
156                                pixels[offset + 2] = 255;
157                                pixels[offset + 3] = 255;
158                            }
159                        }
160                        unsafe {
161                            match cursor.load_from_pixels(
162                                &pixels,
163                                Vector2::new(DRAW_GRID_WH as u32, DRAW_GRID_WH as u32),
164                                hotspot,
165                            ) {
166                                Ok(()) => {
167                                    rw.set_mouse_cursor(&cursor);
168                                }
169                                Err(e) => {
170                                    eprintln!("{e}");
171                                }
172                            }
173                        }
174                        modif = false;
175                    }
176                    if mouse_over(&clear_button, x, y) {
177                        for px in pixel_grid.iter_mut() {
178                            *px = false;
179                        }
180                        modif = true;
181                    }
182                    if mouse_over(&hotspot_button, x, y) {
183                        hotspot_selection = true;
184                    }
185                }
186                Event::MouseButtonReleased {
187                    button: mouse::Button::Left,
188                    ..
189                } => {
190                    if hotspot_selected {
191                        hotspot_selection = false;
192                        hotspot_selected = false;
193                    }
194                }
195                _ => {}
196            }
197        }
198        let mut set_button_highlighted = false;
199        let mut hotspot_button_highlighted = false;
200        let mut clear_button_highlighted = false;
201        // System cursor set button interactions
202        let mp = rw.mouse_position();
203        let mut highlight_index = usize::MAX;
204        for (i, b) in buttons.iter().enumerate() {
205            if mouse_over(b, mp.x, mp.y) {
206                highlight_index = i;
207            }
208        }
209        if mouse_over(&set_button, mp.x, mp.y) {
210            set_button_highlighted = true;
211        }
212        if mouse_over(&hotspot_button, mp.x, mp.y) {
213            hotspot_button_highlighted = true;
214        }
215        if mouse_over(&clear_button, mp.x, mp.y) {
216            clear_button_highlighted = true;
217        }
218        // Grid interactions
219        let rela_x = mp.x - DRAW_AREA_TOPLEFT.0 as i32;
220        let rela_y = mp.y - DRAW_AREA_TOPLEFT.1 as i32;
221        let (gx, gy) = (rela_x / DRAW_CELL_WH as i32, rela_y / DRAW_CELL_WH as i32);
222        if gx >= 0 && gy >= 0 {
223            if let Some(cell) = gridindex(&mut pixel_grid, gx as usize, gy as usize) {
224                if hotspot_selection {
225                    hotspot_selected = true;
226                    hotspot = Vector2::new(gx as u32, gy as u32);
227                    modif = true;
228                } else if mouse::Button::Left.is_pressed() {
229                    *cell = true;
230                    modif = true;
231                } else if mouse::Button::Right.is_pressed() {
232                    *cell = false;
233                    modif = true;
234                }
235            }
236        }
237        rw.clear(Color::BLACK);
238        // Draw system cursor set buttons
239        let mut shape = RectangleShape::default();
240        let mut text = Text::new(String::new(), &font, 14);
241        shape.set_outline_thickness(-1.0);
242        shape.set_outline_color(Color::WHITE);
243        for (i, b) in buttons.iter().enumerate() {
244            let types = [
245                "ARROW",
246                "ARROW_WAIT",
247                "WAIT",
248                "TEXT",
249                "HAND",
250                "SIZE_HORIZONTAL",
251                "SIZE_VERTICAL",
252                "SIZE_TOP_LEFT_BOTTOM_RIGHT",
253                "SIZE_BOTTOM_LEFT_TOP_RIGHT",
254                "SIZE_LEFT",
255                "SIZE_RIGHT",
256                "SIZE_TOP",
257                "SIZE_BOTTOM",
258                "SIZE_TOP_LEFT",
259                "SIZE_BOTTOM_RIGHT",
260                "SIZE_BOTTOM_LEFT",
261                "SIZE_TOP_RIGHT",
262                "SIZE_ALL",
263                "CROSS",
264                "HELP",
265                "NOT_ALLOWED",
266            ];
267            draw_button(
268                b,
269                &mut shape,
270                &mut text,
271                types[i],
272                &mut rw,
273                bstyle(highlight_index == i, selected_index == i, failed_index == i),
274            );
275        }
276        // Draw pixel drawing grid
277        shape.set_fill_color(Color::TRANSPARENT);
278        for y in 0..DRAW_GRID_WH {
279            for x in 0..DRAW_GRID_WH {
280                if hotspot.x == x as u32 && hotspot.y == y as u32 {
281                    shape.set_outline_color(Color::RED);
282                } else {
283                    shape.set_outline_color(Color::rgb(180, 180, 180));
284                }
285                if gridindex(&mut pixel_grid, x as usize, y as usize).is_some_and(|bool| *bool) {
286                    shape.set_fill_color(Color::WHITE);
287                } else {
288                    shape.set_fill_color(Color::TRANSPARENT);
289                }
290                shape.set_size((DRAW_CELL_WH as f32, DRAW_CELL_WH as f32));
291                shape.set_position((
292                    DRAW_AREA_TOPLEFT.0 as f32 + (x as f32 * DRAW_CELL_WH as f32),
293                    DRAW_AREA_TOPLEFT.1 as f32 + (y as f32 * DRAW_CELL_WH as f32),
294                ));
295                rw.draw_rectangle_shape(&shape, &RenderStates::DEFAULT);
296            }
297        }
298        draw_button(
299            &set_button,
300            &mut shape,
301            &mut text,
302            if modif { "Set*" } else { "Set" },
303            &mut rw,
304            bstyle(set_button_highlighted, false, false),
305        );
306        draw_button(
307            &hotspot_button,
308            &mut shape,
309            &mut text,
310            "Hotspot",
311            &mut rw,
312            bstyle(hotspot_button_highlighted, hotspot_selection, false),
313        );
314        draw_button(
315            &clear_button,
316            &mut shape,
317            &mut text,
318            "Clear",
319            &mut rw,
320            bstyle(clear_button_highlighted, false, false),
321        );
322        rw.display();
323    }
324    Ok(())
325}
More examples
Hide additional examples
examples/unicode-text-entry.rs (line 123)
12fn main() -> SfResult<()> {
13    example_ensure_right_working_dir();
14
15    let mut window = RenderWindow::new(
16        (800, 600),
17        "◢◤ Unicode text entry ◥◣",
18        Style::CLOSE,
19        &Default::default(),
20    )?;
21    window.set_vertical_sync_enabled(true);
22
23    // Showcase delayed initialization of font
24    let mut font = Font::new()?;
25
26    match std::env::args().nth(1) {
27        Some(path) => font.load_from_file(&path)?,
28        None => font.load_from_memory_static(include_bytes!("resources/sansation.ttf"))?,
29    };
30    let mut string = String::from("This text can be edited.\nTry it!");
31
32    let mut text = Text::new(string.clone(), &font, 24);
33    text.set_fill_color(Color::RED);
34    text.set_outline_color(Color::YELLOW);
35    text.set_outline_thickness(2.0);
36    let mut status_text = Text::new(String::new(), &font, 16);
37    status_text.tf.position = [0., window.size().y as f32 - 64.0];
38    let mut bold = false;
39    let mut italic = false;
40    let mut underlined = false;
41    let mut strikethrough = false;
42    let mut show_cursor = true;
43
44    'mainloop: loop {
45        while let Some(ev) = window.poll_event() {
46            match ev {
47                Event::Closed => break 'mainloop,
48                Event::TextEntered { unicode } => {
49                    if unicode == 0x08 as char {
50                        string.pop();
51                    } else if unicode == 0xD as char {
52                        string.push('\n');
53                    }
54                    // Ignore ctrl+v/ctrl+v generated chars
55                    else if unicode != 0x16 as char && unicode != 0x03 as char {
56                        string.push(unicode);
57                    }
58                    text.set_string(string.clone());
59                }
60                Event::KeyPressed { code, .. } => {
61                    match code {
62                        Key::Escape => break 'mainloop,
63                        Key::F1 => bold ^= true,
64                        Key::F2 => italic ^= true,
65                        Key::F3 => underlined ^= true,
66                        Key::F4 => strikethrough ^= true,
67                        Key::F5 => show_cursor ^= true,
68                        _ => {}
69                    }
70                    let mut style = TextStyle::default();
71                    if bold {
72                        style |= TextStyle::BOLD;
73                    }
74                    if italic {
75                        style |= TextStyle::ITALIC;
76                    }
77                    if underlined {
78                        style |= TextStyle::UNDERLINED;
79                    }
80                    if strikethrough {
81                        style |= TextStyle::STRIKETHROUGH;
82                    }
83                    text.set_style(style);
84                }
85                _ => {}
86            }
87        }
88
89        let status_string = {
90            let fc = text.fill_color();
91            let oc = text.outline_color();
92            format!(
93                "fill: {:02x}{:02x}{:02x}{:02x} outline: {:02x}{:02x}{:02x}{:02x} outline thickness: {}\n\
94            style: {:?} (F1-F4) cursor: {} (F5)\n\
95            font family: {}",
96                fc.r,
97                fc.g,
98                fc.b,
99                fc.a,
100                oc.r,
101                oc.g,
102                oc.b,
103                oc.a,
104                text.outline_thickness(),
105                text.style(),
106                show_cursor,
107                font.info().family
108            )
109        };
110        status_text.set_string(status_string);
111
112        window.clear(Color::BLACK);
113        text.draw(&mut *window, &RenderStates::DEFAULT);
114        if show_cursor {
115            let mut end = text.find_character_pos(usize::MAX);
116            end.x += 2.0;
117            end.y += 2.0;
118            let mut rs = RectangleShape::new();
119            rs.set_fill_color(Color::TRANSPARENT);
120            rs.set_outline_color(Color::YELLOW);
121            rs.set_outline_thickness(-3.0);
122            rs.set_position(end);
123            rs.set_size((8.0, 24.0));
124            window.draw_rectangle_shape(&rs, &RenderStates::DEFAULT);
125        }
126        status_text.draw(&mut *window, &RenderStates::DEFAULT);
127        window.display();
128    }
129    println!("The final text is {:?}", text.string());
130    Ok(())
131}

Trait Implementations§

Source§

impl<'s> Clone for RectangleShape<'s>

Source§

fn clone(&self) -> RectangleShape<'s>

Return a new RectangleShape or panic! if there is not enough memory

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'s> Debug for RectangleShape<'s>

Source§

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

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

impl Default for RectangleShape<'_>

Source§

fn default() -> Self

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

impl Drop for RectangleShape<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'s> Shape<'s> for RectangleShape<'s>

Source§

fn set_texture(&mut self, texture: &'s Texture, reset_rect: bool)

Changes the source texture of the shape. Read more
Source§

fn disable_texture(&mut self)

Disables texturing for this shape.
Source§

fn set_texture_rect(&mut self, rect: IntRect)

Sets the sub-rectangle of the texture that the shape will display. Read more
Source§

fn set_fill_color(&mut self, color: Color)

Sets the fill color of the shape. Read more
Source§

fn set_outline_color(&mut self, color: Color)

Sets the outline color of the shape. Read more
Source§

fn set_outline_thickness(&mut self, thickness: f32)

Sets the thickness of the shape’s outline. Read more
Source§

fn texture(&self) -> Option<&'s Texture>

Gets the source texture of the shape. Read more
Source§

fn texture_rect(&self) -> IntRect

Gets the sub-rectangle of the texture displayed by the shape.
Source§

fn fill_color(&self) -> Color

Gets the fill color of this shape.
Source§

fn outline_color(&self) -> Color

Gets the outline color of this shape.
Source§

fn outline_thickness(&self) -> f32

Gets the outline thickness of this shape.
Source§

fn point_count(&self) -> usize

Gets the total number of points of the shape.
Source§

fn point(&self, index: usize) -> Vector2f

Gets a point of the shape. Read more
Source§

fn local_bounds(&self) -> FloatRect

Gets the local bounding rectangle of the entity. Read more
Source§

fn global_bounds(&self) -> FloatRect

Gets the global (non-minimal) bounding rectangle of the entity. Read more
Source§

fn points(&self) -> impl Iterator<Item = Vector2f>

Returns an immutable iterator over all points
Source§

impl Transformable for RectangleShape<'_>

Source§

fn set_position<P: Into<Vector2f>>(&mut self, position: P)

Sets the position of the object. Read more
Source§

fn set_rotation(&mut self, angle: f32)

Set the orientation of the object in degrees. Read more
Source§

fn set_scale<S: Into<Vector2f>>(&mut self, scale: S)

Sets the scale factors of the object. Read more
Source§

fn set_origin<O: Into<Vector2f>>(&mut self, origin: O)

Sets the local origin of the object. Read more
Source§

fn position(&self) -> Vector2f

Gets the position of the object.
Source§

fn rotation(&self) -> f32

Gets the rotation of the object in degrees. Read more
Source§

fn get_scale(&self) -> Vector2f

Gets the current scale of the object.
Source§

fn origin(&self) -> Vector2f

Gets the local origin of the object.
Source§

fn move_<O: Into<Vector2f>>(&mut self, offset: O)

Moves the object by a given offset. Read more
Source§

fn rotate(&mut self, angle: f32)

Rotates the object. Read more
Source§

fn scale<F: Into<Vector2f>>(&mut self, factors: F)

Scales the object. Read more
Source§

fn transform(&self) -> &Transform

Gets the combined transform of the object.
Source§

fn inverse_transform(&self) -> &Transform

Gets the inverse combined transform of the object.

Auto Trait Implementations§

§

impl<'s> Freeze for RectangleShape<'s>

§

impl<'s> RefUnwindSafe for RectangleShape<'s>

§

impl<'s> !Send for RectangleShape<'s>

§

impl<'s> !Sync for RectangleShape<'s>

§

impl<'s> Unpin for RectangleShape<'s>

§

impl<'s> UnwindSafe for RectangleShape<'s>

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