Skip to content

Commit

Permalink
feat: add content color, update example slides, add block widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Chleba committed Jun 4, 2024
1 parent 6329488 commit 0878dde
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .config/config.json5
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"<left>": "Previous",
"<up>": "Previous",
"<right>": "Next",
"<down>": "Next"
"<down>": "Next",
"<r>": "Reload"
},
}
}
1 change: 1 addition & 0 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ pub enum Action {

Previous,
Next,
Reload,
}
6 changes: 5 additions & 1 deletion src/components/slides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Slides {

let big_title = BigText::builder()
.pixel_size(PixelSize::Sextant)
.lines(vec![title_text.red().into()])
.lines(vec![title_text.green().into()])
.alignment(Alignment::Center)
.build();
big_title.unwrap()
Expand Down Expand Up @@ -191,6 +191,10 @@ impl Component for Slides {
Action::Previous => {
self.previous_slide();
}
Action::Reload => {
self.get_json_slides();
self.store_images();
}
_ => {}
}
Ok(None)
Expand Down
1 change: 1 addition & 0 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct ContentJson {
pub type_: SlideContentType,
pub content: Option<String>,
pub rect: Option<Rect>,
pub color: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
Expand Down
22 changes: 18 additions & 4 deletions src/slide_builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::Path;
use std::{path::Path, str::FromStr};

use crate::enums::{ContentJson, ReturnSlideWidget, SlideContentType, SlideJson};
use color_eyre::{eyre::Result, owo_colors::OwoColorize};
Expand All @@ -8,7 +8,10 @@ use ratatui::{
prelude::*,
style::Stylize,
text::Line,
widgets::{block::{self, Title}, Block, Borders, Paragraph, WidgetRef},
widgets::{
block::{self, Title},
Block, Borders, Paragraph, WidgetRef,
},
};
use ratatui_image::{picker::Picker, Image, Resize, StatefulImage};
use tui_big_text::BigText;
Expand All @@ -21,14 +24,25 @@ pub fn get_slide_content_string(slide: ContentJson) -> String {
content_str
}

fn get_slide_content_color(slide: ContentJson) -> String {
if let Some(c) = slide.color {
return c;
}
String::from("#FF0000")
}

fn make_slide_paragraph<'a>(slide: ContentJson) -> ReturnSlideWidget<'a> {
let content = get_slide_content_string(slide);
ReturnSlideWidget::Paragraph(Paragraph::new(content))
}

fn make_slide_line<'a>(slide: ContentJson) -> ReturnSlideWidget<'a> {
let content = get_slide_content_string(slide);
ReturnSlideWidget::Line(Line::from(content))
let content = get_slide_content_string(slide.clone());
let color = get_slide_content_color(slide);
ReturnSlideWidget::Line(
Line::from(content)
.style(Style::default().fg(Color::from_str(&color).unwrap_or(Color::Blue))),
)
}

fn make_slide_bigtext<'a>(slide: ContentJson) -> ReturnSlideWidget<'a> {
Expand Down
Binary file added talk_example/images/ratatui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions talk_example/slides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"box_size": {
"percent_width": 75,
"percent_height": 65
},

"slides" : [
{
"title": "RATATUI",
"content": [
{
"type": "Image",
"content": "./images/ratatui.png",
"rect": { "x": 21, "y": 6, "width": 20, "height": 20 }
},
{
"type": "Line",
"content": "A Rust library for creating",
"rect": { "x": 18, "y": 17, "width": 40, "height": 1 },
"color": "#FFFFee"
},
{
"type": "Line",
"content": "TERMINAL USER INTERFACES",
"rect": { "x": 19, "y": 18, "width": 40, "height": 1 },
"color": "#FFFF00"
}
]
},

{
"title": "whoami",
"content": [
{
"type": "Paragraph",
"content": "Lukas Chleba Franek\n\n- https://github.com/Chleba\n- web, embedded, games, tools",
"rect": { "x": 5, "y": 6, "width": 40, "height": 9 }
}
]
}
]
}
44 changes: 0 additions & 44 deletions talk_example/slides.json5

This file was deleted.

0 comments on commit 0878dde

Please sign in to comment.