better preview bar

This commit is contained in:
Chris Cochrun 2024-12-06 22:19:20 -06:00
parent 6ec2e1b97b
commit 039d1043a3
3 changed files with 91 additions and 73 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
/target /target
.direnv .direnv
.sqlx .sqlx
.env
data.db

View file

@ -470,19 +470,10 @@ impl cosmic::Application for App {
let slide_preview = column![ let slide_preview = column![
Space::with_height(Length::Fill), Space::with_height(Length::Fill),
Responsive::new(|size| { Container::new(
let height = size.width * 9.0 / 16.0; self.presenter.view().map(|m| Message::Present(m)),
Container::new( )
Container::new( .align_bottom(Length::Fill),
self.presenter
.view()
.map(|m| Message::Present(m)),
)
.height(height),
)
.align_bottom(Length::Fill)
.into()
}),
Container::new(if self.presenter.video.is_some() { Container::new(if self.presenter.video.is_some() {
row![ row![
video_button_icon, video_button_icon,
@ -552,11 +543,11 @@ impl cosmic::Application for App {
) )
.clip(true) .clip(true)
.width(Length::Fill) .width(Length::Fill)
.center_y(100) .center_y(120)
]; ];
let element: Element<Message> = column.into(); let element: Element<Message> = column.into();
element.debug(true) element
} }
// View for presentation // View for presentation

View file

@ -14,8 +14,8 @@ use cosmic::{
prelude::*, prelude::*,
widget::{ widget::{
canvas::path::lyon_path::geom::euclid::num::Floor, container, canvas::path::lyon_path::geom::euclid::num::Floor, container,
image, mouse_area, scrollable, Container, Responsive, Row, image, mouse_area, responsive, scrollable, Container,
Space, Responsive, Row, Space,
}, },
Task, Task,
}; };
@ -171,17 +171,17 @@ impl Presenter {
} }
pub fn view(&self) -> Element<Message> { pub fn view(&self) -> Element<Message> {
let family = Family::Name("VictorMono Nerd Font"); responsive(|size| {
let weight = Weight::Normal; let family = Family::Name("VictorMono Nerd Font");
let stretch = Stretch::Normal; let weight = Weight::Normal;
let style = Style::Normal; let stretch = Stretch::Normal;
let font = Font { let style = Style::Normal;
family, let font = Font {
weight, family,
stretch, weight,
style, stretch,
}; style,
let text = Responsive::new(move |size| { };
let font_size = if self.current_slide.font_size() > 0 { let font_size = if self.current_slide.font_size() > 0 {
(size.width / self.current_slide.font_size() as f32) (size.width / self.current_slide.font_size() as f32)
* 3.0 * 3.0
@ -192,44 +192,47 @@ impl Presenter {
.size(font_size) .size(font_size)
.font(font); .font(font);
let text = Container::new(text).center(Length::Fill); let text = Container::new(text).center(Length::Fill);
text.into() let black = Container::new(Space::new(0, 0))
}); .style(|_| {
let black = Container::new(Space::new(0, 0)) container::background(Background::Color(
.style(|_| { Color::BLACK,
container::background(Background::Color(Color::BLACK)) ))
}) })
.width(Length::Fill) .width(Length::Fill)
.height(Length::Fill); .height(Length::Fill);
let container = match self.current_slide.background().kind { let container = match self.current_slide.background().kind
crate::BackgroundKind::Image => { {
let path = crate::BackgroundKind::Image => {
self.current_slide.background().path.clone(); let path =
Container::new( self.current_slide.background().path.clone();
image(path)
.content_fit(ContentFit::Contain)
.width(Length::Fill)
.height(Length::Fill),
)
}
crate::BackgroundKind::Video => {
if let Some(video) = &self.video {
Container::new( Container::new(
VideoPlayer::new(video) image(path)
.content_fit(ContentFit::Cover)
.width(Length::Fill) .width(Length::Fill)
.height(Length::Fill) .height(Length::Fill),
.on_end_of_stream(Message::EndVideo)
.on_new_frame(Message::VideoFrame)
.content_fit(ContentFit::Cover),
) )
} else {
Container::new(Space::new(0, 0))
} }
} crate::BackgroundKind::Video => {
}; if let Some(video) = &self.video {
stack!(black, container.center(Length::Fill), text) Container::new(
.width(Length::Fill) VideoPlayer::new(video)
.height(Length::Fill) .width(Length::Fill)
.into() .height(Length::Fill)
.on_end_of_stream(Message::EndVideo)
.on_new_frame(Message::VideoFrame)
.content_fit(ContentFit::Cover),
)
} else {
Container::new(Space::new(0, 0))
}
}
};
stack!(black, container.center(Length::Fill), text)
.width(size.width)
.height(size.width * 9.0 / 16.0)
.into()
})
.into()
} }
pub fn slide_preview(&self) -> Element<Message> { pub fn slide_preview(&self) -> Element<Message> {
@ -245,27 +248,50 @@ impl Presenter {
row.into() row.into()
} }
fn slide_delegate(&self, slide: &Slide) -> Element<Message> { fn slide_delegate<'a>(
let font_size = if slide.font_size() > 0 { &'a self,
slide.font_size() as u16 slide: &'a Slide,
} else { ) -> Element<'a, Message> {
50 let family = Family::Name("VictorMono Nerd Font");
let weight = Weight::Normal;
let stretch = Stretch::Normal;
let style = Style::Normal;
let font = Font {
family,
weight,
stretch,
style,
}; };
let text = text(slide.text()).size(font_size); let text = Responsive::new(move |size| {
let text = Container::new(text).center(Length::Fill); let font_size = if slide.font_size() > 0 {
(size.width / slide.font_size() as f32) * 3.0
} else {
50.0
};
let text = text(slide.text()).size(font_size).font(font);
let text = Container::new(text).center(Length::Fill);
text.into()
});
let container = match slide.background().kind { let container = match slide.background().kind {
crate::BackgroundKind::Image => { crate::BackgroundKind::Image => {
let path = slide.background().path.clone(); let path = slide.background().path.clone();
Container::new( Container::new(
image(path) image(path)
.content_fit(ContentFit::Cover) .content_fit(ContentFit::Contain)
.width(Length::Fill) .width(Length::Fill)
.height(Length::Fill), .height(Length::Fill),
) )
} }
crate::BackgroundKind::Video => { crate::BackgroundKind::Video => {
Container::new(Space::new(Length::Fill, Length::Fill)) Container::new(Space::new(0, 0))
.style(|_| {
container::background(Background::Color(
Color::BLACK,
))
})
.width(Length::Fill)
.height(Length::Fill)
} }
}; };
let delegate = mouse_area( let delegate = mouse_area(
@ -274,9 +300,8 @@ impl Presenter {
.width(Length::Fill) .width(Length::Fill)
.height(Length::Fill), .height(Length::Fill),
) )
.center(Length::Fill)
.height(100) .height(100)
.width(100) .width(100.0 * 16.0 / 9.0)
.padding(10), .padding(10),
) )
.on_press({ .on_press({