#[non_exhaustive]pub struct ScaleFitView {
pub view: View,
pub empty_row_count: i64,
}
Expand description
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.view: View
The View
that this struct wraps around
empty_row_count: i64
How many rows to leave clear below the rendered view. You might want to set this if you have more than one line of text after rendered text
Implementations§
Source§impl ScaleFitView
impl ScaleFitView
Sourcepub fn new(background_char: ColChar) -> Self
pub fn new(background_char: ColChar) -> Self
Create a new ScaleFitView
with the given background ColChar
Examples found in repository?
examples/self-resizing.rs (line 17)
16fn main() {
17 let mut scale_view = ScaleFitView::new(ColChar::BACKGROUND);
18
19 let mut text = Text::new(Vec2D::ZERO, "This is some centered text!", Modifier::None)
20 .with_align(TextAlign::Centered);
21
22 let mut sprite =
23 Sprite::new(Vec2D::ZERO, TEXTURE, Modifier::None).with_align(TextAlign2D::CENTERED);
24
25 loop {
26 text.pos = scale_view.intended_size() / 2;
27 sprite.pos = scale_view.intended_size() / 2;
28 sprite.pos.y -= 5;
29
30 scale_view.update();
31 scale_view.view.draw(&text);
32 scale_view.view.draw(&sprite);
33 let _ = scale_view.view.display_render();
34
35 thread::sleep(Duration::from_millis(10));
36 }
37}
Sourcepub const fn with_empty_row_count(self, empty_row_count: i64) -> Self
pub const fn with_empty_row_count(self, empty_row_count: i64) -> Self
Return the ScaleFitView
with an updated empty_row_count
property. Consumes the original ScaleFitView
Sourcepub fn intended_size(&self) -> Vec2D
pub fn intended_size(&self) -> Vec2D
Returns the size of the terminal, with the y adjusted as intended using the empty_row_count
property
§Panics
Panics if there is no TTY to get the terminal size of, as per terminal_size::terminal_size()
Examples found in repository?
examples/self-resizing.rs (line 26)
16fn main() {
17 let mut scale_view = ScaleFitView::new(ColChar::BACKGROUND);
18
19 let mut text = Text::new(Vec2D::ZERO, "This is some centered text!", Modifier::None)
20 .with_align(TextAlign::Centered);
21
22 let mut sprite =
23 Sprite::new(Vec2D::ZERO, TEXTURE, Modifier::None).with_align(TextAlign2D::CENTERED);
24
25 loop {
26 text.pos = scale_view.intended_size() / 2;
27 sprite.pos = scale_view.intended_size() / 2;
28 sprite.pos.y -= 5;
29
30 scale_view.update();
31 scale_view.view.draw(&text);
32 scale_view.view.draw(&sprite);
33 let _ = scale_view.view.display_render();
34
35 thread::sleep(Duration::from_millis(10));
36 }
37}
Sourcepub fn update(&mut self)
pub fn update(&mut self)
Resize and clear the View
§Panics
Panics if there is no TTY to get the terminal size of, as per terminal_size::terminal_size()
Examples found in repository?
examples/self-resizing.rs (line 30)
16fn main() {
17 let mut scale_view = ScaleFitView::new(ColChar::BACKGROUND);
18
19 let mut text = Text::new(Vec2D::ZERO, "This is some centered text!", Modifier::None)
20 .with_align(TextAlign::Centered);
21
22 let mut sprite =
23 Sprite::new(Vec2D::ZERO, TEXTURE, Modifier::None).with_align(TextAlign2D::CENTERED);
24
25 loop {
26 text.pos = scale_view.intended_size() / 2;
27 sprite.pos = scale_view.intended_size() / 2;
28 sprite.pos.y -= 5;
29
30 scale_view.update();
31 scale_view.view.draw(&text);
32 scale_view.view.draw(&sprite);
33 let _ = scale_view.view.display_render();
34
35 thread::sleep(Duration::from_millis(10));
36 }
37}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ScaleFitView
impl RefUnwindSafe for ScaleFitView
impl Send for ScaleFitView
impl Sync for ScaleFitView
impl Unpin for ScaleFitView
impl UnwindSafe for ScaleFitView
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more