lots of cleanup and some ui tweaks
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-09-23 06:25:25 -05:00
parent bb1057e950
commit 991feb18c8
11 changed files with 219 additions and 374 deletions

View file

@ -51,7 +51,6 @@ pub struct Library {
enum MenuMessage {
Delete((LibraryKind, i32)),
Open,
None,
}
impl MenuAction for MenuMessage {
@ -63,7 +62,6 @@ impl MenuAction for MenuMessage {
Message::DeleteItem((*kind, *index))
}
MenuMessage::Open => todo!(),
MenuMessage::None => todo!(),
}
}
}
@ -827,7 +825,7 @@ async fn add_db() -> Result<SqlitePool> {
SqlitePool::connect(&db_url).await.into_diagnostic()
}
fn elide_text(text: impl AsRef<str>, width: f32) -> String {
pub fn elide_text(text: impl AsRef<str>, width: f32) -> String {
const CHAR_SIZE: f32 = 8.0;
let text: String = text.as_ref().to_owned();
let text_length = text.len() as f32 * CHAR_SIZE;

View file

@ -1,5 +1,10 @@
use miette::{IntoDiagnostic, Result};
use std::{fs::File, io::BufReader, path::PathBuf, sync::Arc};
use std::{
fs::File,
io::BufReader,
path::PathBuf,
sync::{Arc, LazyLock},
};
use cosmic::{
iced::{
@ -31,7 +36,8 @@ use crate::{
};
const REFERENCE_WIDTH: f32 = 1920.0;
const REFERENCE_HEIGHT: f32 = 1080.0;
static DEFAULT_SLIDE: LazyLock<Slide> =
LazyLock::new(|| Slide::default());
// #[derive(Default, Clone, Debug)]
pub(crate) struct Presenter {
@ -147,14 +153,22 @@ impl Presenter {
let total_slides: usize =
items.iter().fold(0, |a, item| a + item.slides.len());
let slide =
items.get(0).map(|item| item.slides.get(0)).flatten();
let audio = items
.get(0)
.map(|item| item.slides.get(0).map(|slide| slide.audio()))
.flatten()
.flatten();
Self {
current_slide: items[0].slides[0].clone(),
current_slide: slide.unwrap_or(&DEFAULT_SLIDE).clone(),
current_item: 0,
current_slide_index: 0,
absolute_slide_index: 0,
total_slides,
video,
audio: items[0].slides[0].audio(),
audio,
service: items,
video_position: 0.0,
hovered_slide: None,

View file

@ -1,22 +1,19 @@
use std::any::Any;
use cosmic::iced::{self, Size};
use cosmic::iced_core::window;
use cosmic::iced::Size;
use cosmic::iced_core::widget::tree;
use cosmic::{
iced::{
clipboard::dnd::{DndAction, DndEvent, SourceEvent},
event, mouse, overlay, Event, Length, Point, Rectangle,
Vector,
clipboard::dnd::{DndEvent, SourceEvent},
event, mouse, Event, Length, Point, Rectangle, Vector,
},
iced_core::{
self, layout, renderer,
widget::{tree, Tree},
self, image::Renderer, layout, renderer, widget::Tree,
Clipboard, Shell,
},
widget::{container, Id, Widget},
widget::Widget,
Element,
};
use tracing::debug;
use crate::core::service_items::ServiceItem;
@ -133,6 +130,10 @@ impl<Message: Clone + 'static>
layout::atomic(limits, self.width, self.height)
}
fn state(&self) -> iced_core::widget::tree::State {
tree::State::new(State::new())
}
// fn operate(
// &self,
// tree: &mut Tree,
@ -231,6 +232,7 @@ impl<Message: Clone + 'static>
_ => return event::Status::Ignored,
},
Event::Dnd(DndEvent::Source(SourceEvent::Cancelled)) => {
debug!("canceled");
if state.is_dragging {
if let Some(m) = self.on_cancelled.as_ref() {
shell.publish(m.clone());
@ -241,6 +243,7 @@ impl<Message: Clone + 'static>
return event::Status::Ignored;
}
Event::Dnd(DndEvent::Source(SourceEvent::Finished)) => {
debug!("dropped");
if state.is_dragging {
if let Some(m) = self.on_finish.as_ref() {
shell.publish(m.clone());
@ -250,6 +253,7 @@ impl<Message: Clone + 'static>
}
return event::Status::Ignored;
}
Event::Dnd(event) => debug!(?event),
_ => return event::Status::Ignored,
}
event::Status::Ignored
@ -286,10 +290,8 @@ impl<Message: Clone + 'static>
cursor_position: mouse::Cursor,
viewport: &Rectangle,
) {
let state = tree.state.downcast_mut::<State>();
for item in self.service {
todo!()
}
// let state = tree.state.downcast_mut::<State>();
for item in self.service {}
}
// fn overlay<'b>(

View file

@ -2,7 +2,7 @@ use std::{io, path::PathBuf, sync::Arc};
use cosmic::{
dialog::file_chooser::{open::Dialog, FileFilter},
iced::{alignment::Vertical, Font, Length},
iced::{alignment::Vertical, Length},
iced_wgpu::graphics::text::cosmic_text::fontdb,
iced_widget::{column, row},
theme,

View file

@ -354,14 +354,6 @@ impl TextSvg {
.height(Length::Fill)
.into()
}
fn text_spans(&self) -> Vec<String> {
self.text
.lines()
.enumerate()
.map(|(i, t)| format!("<tspan x=\"50%\">{t}</tspan>"))
.collect()
}
}
pub fn shadow(
@ -408,27 +400,3 @@ pub fn text_svg_generator(
slide.text_svg = Some(text_svg);
}
}
#[cfg(test)]
mod test {
use pretty_assertions::assert_eq;
use super::TextSvg;
#[test]
fn test_text_spans() {
let mut text = TextSvg::new("yes");
text.text = "This is
multiline
text."
.into();
assert_eq!(
vec![
String::from("<tspan>This is</tspan>"),
String::from("<tspan>multiline</tspan>"),
String::from("<tspan>text.</tspan>"),
],
text.text_spans()
)
}
}