Getting closer to a working little system
This commit is contained in:
parent
d9459d6336
commit
c60353f8c8
9 changed files with 338 additions and 132 deletions
|
@ -1,7 +1,4 @@
|
|||
use lexpr::{
|
||||
parse::{from_str_elisp, Options},
|
||||
Parser, Value,
|
||||
};
|
||||
use crisp::types::{Keyword, Value};
|
||||
use miette::{miette, IntoDiagnostic, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
|
@ -187,6 +184,36 @@ impl Slide {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Value> for Slide {
|
||||
fn from(value: Value) -> Self {
|
||||
match value {
|
||||
Value::List(list) => lisp_to_slide(list),
|
||||
_ => Slide::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lisp_to_slide(lisp: Vec<Value>) -> Slide {
|
||||
let mut slide = SlideBuilder::new();
|
||||
let background_position = if let Some(background) =
|
||||
lisp.position(|v| Value::Keyword(Keyword::from("background")))
|
||||
{
|
||||
background + 1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
if let Some(background) = lisp.get(background_position) {
|
||||
slide.background(lisp_to_background(background));
|
||||
} else {
|
||||
slide.background(Background::default());
|
||||
}
|
||||
}
|
||||
|
||||
fn lisp_to_background(lisp: &Value) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone, Debug, Default, PartialEq, Serialize, Deserialize,
|
||||
)]
|
||||
|
|
14
src/lisp.rs
Normal file
14
src/lisp.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
use crisp::{
|
||||
env::Environment,
|
||||
types::{Symbol, Value},
|
||||
};
|
||||
|
||||
use crate::{Slide, SlideBuilder};
|
||||
|
||||
pub fn setup_env() {
|
||||
let mut env = Environment::new();
|
||||
env.insert_symbol(
|
||||
Symbol::from("slide"),
|
||||
Value::func(|args| Ok(Value::from(args))),
|
||||
)
|
||||
}
|
131
src/main.rs
131
src/main.rs
|
@ -1,26 +1,25 @@
|
|||
use clap::{command, Parser};
|
||||
use cosmic::app::{Core, Settings, Task};
|
||||
use cosmic::dialog::ashpd::url::Url;
|
||||
use cosmic::iced::keyboard::Key;
|
||||
use cosmic::iced::window::Position;
|
||||
use cosmic::iced::{
|
||||
self, event, window, ContentFit, Font, Length, Point,
|
||||
};
|
||||
use cosmic::iced::{self, event, window, Font, Length, Point};
|
||||
use cosmic::iced_core::SmolStr;
|
||||
use cosmic::iced_widget::{column, row, stack};
|
||||
use cosmic::widget::icon;
|
||||
use cosmic::prelude::*;
|
||||
use cosmic::widget::tooltip::Position as TPosition;
|
||||
use cosmic::widget::{button, image, nav_bar, text, tooltip, Space};
|
||||
use cosmic::widget::{
|
||||
button, image, nav_bar, text, tooltip, Responsive, Space,
|
||||
};
|
||||
use cosmic::widget::{icon, slider};
|
||||
use cosmic::{executor, Application, ApplicationExt, Element};
|
||||
use cosmic::{widget::Container, Theme};
|
||||
use iced_video_player::{Video, VideoPlayer};
|
||||
use miette::{miette, Result};
|
||||
use std::path::PathBuf;
|
||||
use tracing::error;
|
||||
use tracing::{debug, level_filters::LevelFilter};
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
pub mod core;
|
||||
pub mod lisp;
|
||||
pub mod ui;
|
||||
use core::slide::*;
|
||||
use ui::presenter::{self, Presenter};
|
||||
|
@ -93,7 +92,7 @@ impl Default for App {
|
|||
.build()
|
||||
.expect("oops slide");
|
||||
let slides = vec![initial_slide.clone()];
|
||||
let presenter = Presenter::with_app_slides(slides.clone());
|
||||
let presenter = Presenter::with_slides(slides.clone());
|
||||
Self {
|
||||
presenter,
|
||||
core: Core::default(),
|
||||
|
@ -152,7 +151,7 @@ impl cosmic::Application for App {
|
|||
.unwrap(),
|
||||
)
|
||||
.expect("oops video")
|
||||
.text("Hello")
|
||||
.text("")
|
||||
.font("Quicksand")
|
||||
.font_size(50)
|
||||
.text_alignment(TextAlignment::MiddleCenter)
|
||||
|
@ -179,12 +178,26 @@ impl cosmic::Application for App {
|
|||
.build()
|
||||
.expect("oops slide");
|
||||
|
||||
let slides = vec![
|
||||
initial_slide.clone(),
|
||||
second_slide.clone(),
|
||||
second_slide.clone(),
|
||||
];
|
||||
let presenter = Presenter::with_app_slides(slides.clone());
|
||||
let tetrary_slide = SlideBuilder::new()
|
||||
.background(
|
||||
PathBuf::from("/home/chris/pics/wojaks/reddit_the_xenomorph_s bigass wojak folder/Chads/ChristianChad_x16_drawing.png")
|
||||
.canonicalize()
|
||||
.unwrap(),
|
||||
)
|
||||
.expect("oops video")
|
||||
.text("Hello")
|
||||
.font("Quicksand")
|
||||
.font_size(50)
|
||||
.text_alignment(TextAlignment::MiddleCenter)
|
||||
.video_loop(false)
|
||||
.video_start_time(0.0)
|
||||
.video_end_time(0.0)
|
||||
.build()
|
||||
.expect("oops slide");
|
||||
|
||||
let slides =
|
||||
vec![initial_slide.clone(), second_slide, tetrary_slide];
|
||||
let presenter = Presenter::with_slides(slides.clone());
|
||||
let mut app = App {
|
||||
presenter,
|
||||
core,
|
||||
|
@ -347,7 +360,7 @@ impl cosmic::Application for App {
|
|||
) -> cosmic::Task<cosmic::app::Message<Message>> {
|
||||
match message {
|
||||
Message::Present(message) => {
|
||||
self.presenter.update(message);
|
||||
let _ = self.presenter.update(message);
|
||||
// self.core.nav_bar_toggle();
|
||||
Task::none()
|
||||
}
|
||||
|
@ -403,9 +416,47 @@ impl cosmic::Application for App {
|
|||
// Main window view
|
||||
fn view(&self) -> Element<Message> {
|
||||
debug!("Main view");
|
||||
let preview = self.presenter.view();
|
||||
let icon_left = icon::from_name("arrow-left");
|
||||
let icon_right = icon::from_name("arrow-right");
|
||||
|
||||
let video_range: f32 =
|
||||
if let Some(video) = &self.presenter.video {
|
||||
let duration = video.duration();
|
||||
duration.as_secs_f32()
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
let video_pos = if let Some(video) = &self.presenter.video {
|
||||
let range = video.position();
|
||||
range.as_secs_f32()
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
let video_button_icon =
|
||||
if let Some(video) = &self.presenter.video {
|
||||
if video.paused() {
|
||||
button::icon(icon::from_name("media-play"))
|
||||
.tooltip("Play")
|
||||
.on_press(Message::Present(
|
||||
presenter::Message::StartVideo,
|
||||
))
|
||||
} else {
|
||||
button::icon(icon::from_name("media-pause"))
|
||||
.tooltip("Pause")
|
||||
.on_press(Message::Present(
|
||||
presenter::Message::StartVideo,
|
||||
))
|
||||
}
|
||||
} else {
|
||||
button::icon(icon::from_name("media-play"))
|
||||
.tooltip("Play")
|
||||
.on_press(Message::Present(
|
||||
presenter::Message::StartVideo,
|
||||
))
|
||||
};
|
||||
|
||||
let row = row![
|
||||
Container::new(
|
||||
button::icon(icon_left)
|
||||
|
@ -419,13 +470,43 @@ impl cosmic::Application for App {
|
|||
.center_y(Length::Fill)
|
||||
.align_right(Length::Fill)
|
||||
.width(Length::FillPortion(1)),
|
||||
Container::new(
|
||||
Container::new(preview.map(|m| Message::Present(m)))
|
||||
.center(Length::Fill)
|
||||
.max_height(270)
|
||||
)
|
||||
Container::new(column![
|
||||
Space::with_height(Length::Fill),
|
||||
Responsive::new(move |size| {
|
||||
let height = size.width * 9.0 / 16.0;
|
||||
Container::new(
|
||||
self.presenter
|
||||
.view()
|
||||
.map(|m| Message::Present(m)),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(height)
|
||||
.into()
|
||||
}),
|
||||
Container::new(
|
||||
row![
|
||||
video_button_icon,
|
||||
Container::new(slider(
|
||||
0.0..=video_range,
|
||||
video_pos,
|
||||
|pos| {
|
||||
Message::Present(
|
||||
presenter::Message::VideoPos(pos),
|
||||
)
|
||||
}
|
||||
))
|
||||
.center_x(Length::Fill)
|
||||
.padding([7, 0, 0, 0])
|
||||
]
|
||||
.padding(5)
|
||||
)
|
||||
.align_top(Length::Shrink)
|
||||
.height(Length::Shrink)
|
||||
.center_x(Length::Fill),
|
||||
Space::with_height(Length::Fill)
|
||||
])
|
||||
.center_y(Length::Fill)
|
||||
.width(Length::FillPortion(3)),
|
||||
.center_x(Length::FillPortion(3)),
|
||||
Container::new(
|
||||
button::icon(icon_right)
|
||||
.icon_size(128)
|
||||
|
@ -526,7 +607,6 @@ fn test_slide<'a>() -> Element<'a, Message> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
|
@ -539,7 +619,6 @@ mod test {
|
|||
// fn test_lisp() {
|
||||
// let slide = test_slide();
|
||||
// if let Ok(data) = lexpr::parse::from_str_elisp(slide.as_str()) {
|
||||
// println!("{data:?}");
|
||||
// assert_eq!(slide, data)
|
||||
// } else {
|
||||
// assert!(false)
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
pub mod presenter;
|
||||
pub mod slide_preview;
|
||||
|
|
|
@ -1,40 +1,43 @@
|
|||
use std::{path::PathBuf, rc::Rc};
|
||||
use std::{path::PathBuf, rc::Rc, time::Duration};
|
||||
|
||||
use cosmic::{
|
||||
dialog::ashpd::url::Url,
|
||||
iced::{widget::text, ContentFit, Length},
|
||||
iced_widget::{row, stack, Stack},
|
||||
iced::{widget::text, Background, Color, ContentFit, Length},
|
||||
iced_widget::stack,
|
||||
prelude::*,
|
||||
widget::{
|
||||
button, container, icon::Named, image, Container, Row, Space,
|
||||
},
|
||||
widget::{container, image, Container, Row, Space},
|
||||
Task,
|
||||
};
|
||||
use iced_video_player::{Video, VideoPlayer};
|
||||
use iced_video_player::{Position, Video, VideoPlayer};
|
||||
use miette::{Context, IntoDiagnostic, Result};
|
||||
use tracing::{debug, error};
|
||||
use tracing::{debug, error, info};
|
||||
|
||||
use crate::{core::slide::Slide, BackgroundKind};
|
||||
|
||||
// #[derive(Default, Clone, Debug)]
|
||||
pub(crate) struct Presenter {
|
||||
pub slides: Vec<Slide>,
|
||||
pub current_slide: i16,
|
||||
pub current_slide: Slide,
|
||||
pub current_slide_index: u16,
|
||||
pub video: Option<Video>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(crate) enum Message {
|
||||
NextSlide,
|
||||
PrevSlide,
|
||||
SlideChange(u8),
|
||||
SlideChange(u16),
|
||||
EndVideo,
|
||||
StartVideo,
|
||||
VideoPos(f32),
|
||||
}
|
||||
|
||||
impl Presenter {
|
||||
pub fn with_app_slides(slides: Vec<Slide>) -> Self {
|
||||
pub fn with_slides(slides: Vec<Slide>) -> Self {
|
||||
Self {
|
||||
slides: slides.clone(),
|
||||
current_slide: 0,
|
||||
current_slide: slides[0].clone(),
|
||||
current_slide_index: 0,
|
||||
video: {
|
||||
if let Some(slide) = slides.get(0) {
|
||||
let path = slide.background().path.clone();
|
||||
|
@ -42,7 +45,10 @@ impl Presenter {
|
|||
let url = Url::from_file_path(path).unwrap();
|
||||
let result = Video::new(&url);
|
||||
match result {
|
||||
Ok(v) => Some(v),
|
||||
Ok(mut v) => {
|
||||
v.set_paused(true);
|
||||
Some(v)
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Had an error creating the video object: {e}");
|
||||
None
|
||||
|
@ -57,29 +63,6 @@ impl Presenter {
|
|||
},
|
||||
}
|
||||
}
|
||||
// pub fn with_initial_slide(slide: Slide) -> Self {
|
||||
// Self {
|
||||
// slides: vec![slide.clone()],
|
||||
// current_slide: 0,
|
||||
// video: {
|
||||
// let path = slide.background().path.clone();
|
||||
// if path.exists() {
|
||||
// let url = Url::from_file_path(path).unwrap();
|
||||
// let result = Video::new(&url);
|
||||
// match result {
|
||||
// Ok(v) => Some(v),
|
||||
// Err(e) => {
|
||||
// error!("Had an error creating the video object: {e}");
|
||||
// None
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// error!("File doesn't exist: ");
|
||||
// None
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn update(
|
||||
&mut self,
|
||||
|
@ -88,24 +71,75 @@ impl Presenter {
|
|||
match message {
|
||||
Message::NextSlide => {
|
||||
debug!("next slide");
|
||||
if let Some(video) = &mut self.video {
|
||||
let _ = video.restart_stream();
|
||||
if self.slides.len() as u16 - 1
|
||||
== self.current_slide_index
|
||||
{
|
||||
debug!("no more slides");
|
||||
return Task::none();
|
||||
}
|
||||
self.current_slide += 1;
|
||||
self.reset_video();
|
||||
Task::none()
|
||||
self.current_slide_index += 1;
|
||||
self.update(Message::SlideChange(
|
||||
self.current_slide_index,
|
||||
))
|
||||
}
|
||||
Message::PrevSlide => {
|
||||
debug!("prev slide");
|
||||
if let Some(video) = &mut self.video {
|
||||
let _ = video.restart_stream();
|
||||
if 0 == self.current_slide_index {
|
||||
debug!("beginning slides");
|
||||
return Task::none();
|
||||
}
|
||||
self.current_slide -= 1;
|
||||
self.reset_video();
|
||||
Task::none()
|
||||
self.current_slide_index -= 1;
|
||||
self.update(Message::SlideChange(
|
||||
self.current_slide_index,
|
||||
))
|
||||
}
|
||||
Message::SlideChange(id) => {
|
||||
debug!(id, "slide changed");
|
||||
if let Some(slide) = self.slides.get(id as usize) {
|
||||
self.current_slide = slide.clone();
|
||||
}
|
||||
if let Some(video) = &mut self.video {
|
||||
let _ = video.restart_stream();
|
||||
}
|
||||
self.reset_video();
|
||||
Task::none()
|
||||
}
|
||||
Message::EndVideo => {
|
||||
// if self.current_slide.video_loop() {
|
||||
// if let Some(video) = &mut self.video {
|
||||
// match video.restart_stream() {
|
||||
// Ok(_) => info!("Restarting video"),
|
||||
// Err(e) => {
|
||||
// error!("Couldn't restart video: {e}")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Task::none()
|
||||
}
|
||||
Message::StartVideo => {
|
||||
if let Some(video) = &mut self.video {
|
||||
video.set_paused(false);
|
||||
video
|
||||
.set_looping(self.current_slide.video_loop());
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
Message::VideoPos(position) => {
|
||||
if let Some(video) = &mut self.video {
|
||||
let position = Position::Time(
|
||||
Duration::from_secs_f32(position),
|
||||
);
|
||||
match video.seek(position, false) {
|
||||
Ok(_) => debug!(
|
||||
"Video position changed: {:?}",
|
||||
position
|
||||
),
|
||||
Err(e) => error!(
|
||||
"Problem changing video position: {e}"
|
||||
),
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
|
@ -114,25 +148,30 @@ impl Presenter {
|
|||
pub fn view(&self) -> Element<Message> {
|
||||
let text = text!("This is frodo").size(50);
|
||||
let text = Container::new(text).center(Length::Fill);
|
||||
let container = match self
|
||||
.slides
|
||||
.get(self.current_slide as usize)
|
||||
.unwrap()
|
||||
.background()
|
||||
.kind
|
||||
{
|
||||
crate::BackgroundKind::Image => Container::new(
|
||||
image("/home/chris/pics/frodo.jpg")
|
||||
.content_fit(ContentFit::Cover)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill),
|
||||
),
|
||||
let black = Container::new(Space::new(0, 0))
|
||||
.style(|_| {
|
||||
container::background(Background::Color(Color::BLACK))
|
||||
})
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill);
|
||||
let container = match self.current_slide.background().kind {
|
||||
crate::BackgroundKind::Image => {
|
||||
let path =
|
||||
self.current_slide.background().path.clone();
|
||||
Container::new(
|
||||
image(path)
|
||||
.content_fit(ContentFit::Contain)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill),
|
||||
)
|
||||
}
|
||||
crate::BackgroundKind::Video => {
|
||||
if let Some(video) = &self.video {
|
||||
Container::new(
|
||||
VideoPlayer::new(video)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.on_end_of_stream(Message::EndVideo)
|
||||
.content_fit(ContentFit::Cover),
|
||||
)
|
||||
} else {
|
||||
|
@ -140,7 +179,7 @@ impl Presenter {
|
|||
}
|
||||
}
|
||||
};
|
||||
stack!(container, text)
|
||||
stack!(black, container.center(Length::Fill), text)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
|
@ -169,7 +208,7 @@ impl Presenter {
|
|||
Container::new(Space::new(Length::Fill, Length::Fill))
|
||||
}
|
||||
};
|
||||
stack!(container, text)
|
||||
stack!(container.center(Length::Fill), text)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
|
@ -177,7 +216,7 @@ impl Presenter {
|
|||
|
||||
fn reset_video(&mut self) {
|
||||
if let Some(slide) =
|
||||
self.slides.get(self.current_slide as usize)
|
||||
self.slides.get(self.current_slide_index as usize)
|
||||
{
|
||||
match slide.background().kind {
|
||||
BackgroundKind::Image => self.video = None,
|
||||
|
@ -201,34 +240,3 @@ impl Presenter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn slide_view<'a>(
|
||||
slide: &'a Slide,
|
||||
video: &'a Option<Video>,
|
||||
) -> Stack<'a, crate::Message, cosmic::Theme> {
|
||||
let text = text!("{}", slide.text()).size(50);
|
||||
let text = Container::new(text).center(Length::Fill);
|
||||
let container = match slide.background().kind {
|
||||
crate::BackgroundKind::Image => Container::new(
|
||||
image("/home/chris/pics/frodo.jpg")
|
||||
.content_fit(ContentFit::Cover)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill),
|
||||
),
|
||||
crate::BackgroundKind::Video => {
|
||||
if let Some(video) = video {
|
||||
Container::new(
|
||||
VideoPlayer::new(video)
|
||||
.width(Length::Shrink)
|
||||
.height(Length::Fill)
|
||||
.content_fit(ContentFit::Cover),
|
||||
)
|
||||
} else {
|
||||
Container::new(Space::new(Length::Fill, Length::Fill))
|
||||
}
|
||||
}
|
||||
};
|
||||
stack!(container, text)
|
||||
// .width(Length::Fill)
|
||||
// .height(Length::Fill)
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
use crate::Slide;
|
||||
|
||||
pub struct SlidePreview<'a> {
|
||||
slides: Vec<&'a Slide>,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue