pub struct Layout {
pub line_offset: u16,
pub offset_x: u16,
pub offset_y: u16,
pub width: u16,
pub height: u16,
pub max_height: u16,
pub render_region: RenderRegion,
}
Expand description
Layout
represents a portion of the screen that is available to be rendered to.
Assume the highlighted part of the block below is the place available for rendering in the given box
____________
| |
| ███████|
| ██████████|
| ██████████|
'------------'
Fields§
§line_offset: u16
____________
| vvv-- line_offset
| ███████|
| ██████████|
| ██████████|
'------------'
offset_x: u16
____________
|vv-- offset_x
| ███████|
| ██████████|
| ██████████|
'------------'
offset_y: u16
.-- offset_y
|'> |
| ███████|
| ██████████|
| ██████████|
'------------'
width: u16
____________
| |
| ███████|
| ██████████|
| ██████████|
'------------'
^^^^^^^^^^^^-- width
height: u16
_____ height --.
| | <'
| ███████| <'
| ██████████| <'
| ██████████| <'
'------------'
max_height: u16
____________
|.-- max_height
|'> ███████|
|'>██████████|
|'>██████████|
'------------'
render_region: RenderRegion
The region to render if full text cannot be rendered
Implementations§
Source§impl Layout
impl Layout
Sourcepub fn with_line_offset(self, line_offset: u16) -> Self
pub fn with_line_offset(self, line_offset: u16) -> Self
Creates a new Layout
with given line_offset
.
Sourcepub fn with_offset(self, offset_x: u16, offset_y: u16) -> Self
pub fn with_offset(self, offset_x: u16, offset_y: u16) -> Self
Creates a new Layout
with new offset_x
and offset_y
.
Sourcepub fn with_render_region(self, region: RenderRegion) -> Self
pub fn with_render_region(self, region: RenderRegion) -> Self
Creates a new Layout
with new render_region
.
Sourcepub fn with_max_height(self, max_height: u16) -> Self
pub fn with_max_height(self, max_height: u16) -> Self
Creates a new Layout
with new max_height
.
Sourcepub fn with_cursor_pos(self, cursor_pos: (u16, u16)) -> Self
pub fn with_cursor_pos(self, cursor_pos: (u16, u16)) -> Self
Creates a new Layout
that represents a region past the cursor_pos
. cursor_pos
is
relative to offset_x
and offset_y
.
Sourcepub fn offset_cursor(&self, cursor_pos: (u16, u16)) -> (u16, u16)
pub fn offset_cursor(&self, cursor_pos: (u16, u16)) -> (u16, u16)
Converts a cursor_pos
relative to (offset_x
, offset_y
) to be relative to (0, 0)
Sourcepub fn line_width(&self) -> u16
pub fn line_width(&self) -> u16
Gets the width of renderable space on the first line.
____________
| vvvvvvv-- line_width
| ███████|
| ██████████|
| ██████████|
'------------'
Sourcepub fn available_width(&self) -> u16
pub fn available_width(&self) -> u16
Gets the width of renderable space on subsequent lines.
____________
| vvvvvvvvvv-- available_width
| ███████|
| ██████████|
| ██████████|
'------------'
Sourcepub fn get_start(&self, height: u16) -> u16
pub fn get_start(&self, height: u16) -> u16
Gets the starting line number for the given height
taking into account the max_height
and the render_region
.
If the height of the widget to render is 5 and the max_height is 2, then the start would be:
RenderRegion::Top
: 0RenderRegion::Middle
: 1RenderRegion::Top
: 3