Struct ascii_forge::elements::ui::NineSlice
source · pub struct NineSlice { /* private fields */ }
Implementations§
source§impl NineSlice
impl NineSlice
sourcepub fn new<C: Into<Cell>>(cells: [C; 9], size: impl Into<Vec2>) -> Self
pub fn new<C: Into<Cell>>(cells: [C; 9], size: impl Into<Vec2>) -> Self
Examples found in repository?
examples/simple.rs (line 15)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn run(&mut self, window: &mut Window) -> Result<SceneResult, Box<dyn Error>> {
// Set up a scene
let mut ui_buffer = Buffer::new((6, 3));
let chars = ['┌', '─', '┐', '│', ' ', '│', '└', '─', '┘'];
let nine_slice = ui::NineSlice::new(chars, (6, 3));
// Render Some elements to the buffer.
render!(ui_buffer, [
vec2(0, 0) => nine_slice,
vec2(1, 1) => "QUIT".green()
]);
// Loop the current scene.
loop {
window.update()?;
// Renders some elements to the window.
render!(window, [
vec2(0, 0) => format!("{:?}", cursor::position()?),
vec2(window.size().x / 2, window.size().y / 4) => ui_buffer,
]);
// If the `q` key was pressed, quit the application by returning no scene.
if window.code(KeyCode::Char('q')) {
return Ok(None);
}
// If the buffer was clicked on, quit.
if window.mouse(MouseEventKind::Down(MouseButton::Left))?
&& window.hover(
vec2(window.size().x / 2, window.size().y / 4),
ui_buffer.size(),
)?
{
return Ok(None);
}
}
}
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for NineSlice
impl Send for NineSlice
impl Sync for NineSlice
impl Unpin for NineSlice
impl UnwindSafe for NineSlice
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