diff --git a/src/app.rs b/src/app.rs index cdcbef6..11a0029 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,10 +5,11 @@ use terminput::KeyCode; use crate::Demo; pub(crate) struct MyApp { + // Put in any variables here counter: usize, frame_counter: usize, } - +// Implement the [`crate::Demo`] trait to outline the behaviour impl Demo for MyApp { fn new() -> Self { Self { @@ -18,20 +19,30 @@ impl Demo for MyApp { } async fn frame(&mut self, term: &mut crate::Term) -> Result<(), String> { + // This example draws two moving sine waves on the screen. + // Put in your behaviour here + + // Draw function term.draw(|fr| { self.frame_counter = self.frame_counter.wrapping_add(1); - let style = Style::new().light_yellow().on_black(); + // Color and the draw area + let style = Style::new().light_yellow().on_black(); + let area = fr.area(); + + // Create a block with title and credits let block = Block::bordered() .style(style) - .title("Example demo") - .title_bottom("Sine - made by: wilkuu (Jakub Stachurski), jakub@snt.utwente.nl"); + .title("Example demo: Sine") + .title_bottom("By: wilkuu (Jakub Stachurski), jakub@snt.utwente.nl"); - let area = fr.area(); + // Area inside of the block let barea = block.inner(area); + // Draw the block fr.render_widget(block, area); + // Demo drawing logic replace with own stuff let xl = barea.x; let xr = barea.width + barea.x; @@ -54,6 +65,7 @@ impl Demo for MyApp { * Into::::into(barea.height / 2-1) + Into::::into(barea.y)).round() as u16; if y2 == y1 { + // Individual character drawing, there is probably a better way to achieve this. buf.set_span(x, (y1.saturating_sub(1)).max(barea.y), &Span::from("_").light_magenta(), 1); buf.set_span(x, y1, &Span::from("#").light_magenta(), 1); buf.set_span(x, (y1.saturating_add(1)).min(yt), &Span::from("-").light_magenta(), 1); @@ -68,6 +80,7 @@ impl Demo for MyApp { } } + // Center text let mut lines: Vec= Vec::new(); lines.push("Use W/S to change the counter. Enter to exit.".into()); lines.push(format!("Counter: {}", self.counter).into()); @@ -75,13 +88,13 @@ impl Demo for MyApp { let text = Paragraph::new(lines).centered().style(style); fr.render_widget(text, Rect::new(barea.width/2 - 25, barea.height/2, 50, 4)); - }).map_err(|e| e.to_string())?; Ok(()) } async fn input(&mut self, event: terminput::Event) -> Result<(), String> { + // Handle input using terminput. if let terminput::Event::Key(kv) = event { match kv.code { KeyCode::Char('w') => {