some preliminary work on libraries
This commit is contained in:
parent
50abdf1783
commit
df944f980c
|
@ -4,10 +4,13 @@ use cosmic::iced::Executor;
|
||||||
use miette::{miette, Result};
|
use miette::{miette, Result};
|
||||||
use sqlx::{Connection, SqliteConnection};
|
use sqlx::{Connection, SqliteConnection};
|
||||||
|
|
||||||
|
use super::kinds::ServiceItemKind;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Model<T> {
|
pub struct Model<T> {
|
||||||
pub items: Vec<T>,
|
pub items: Vec<T>,
|
||||||
pub db: SqliteConnection,
|
pub db: SqliteConnection,
|
||||||
|
pub kind: ServiceItemKind,
|
||||||
}
|
}
|
||||||
impl<T> Model<T> {
|
impl<T> Model<T> {
|
||||||
pub fn add_item(&mut self, item: T) -> Result<()> {
|
pub fn add_item(&mut self, item: T) -> Result<()> {
|
||||||
|
|
|
@ -23,6 +23,7 @@ use std::path::PathBuf;
|
||||||
use tracing::{debug, level_filters::LevelFilter};
|
use tracing::{debug, level_filters::LevelFilter};
|
||||||
use tracing::{error, warn};
|
use tracing::{error, warn};
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
use ui::library::Library;
|
||||||
|
|
||||||
pub mod core;
|
pub mod core;
|
||||||
pub mod lisp;
|
pub mod lisp;
|
||||||
|
@ -87,6 +88,7 @@ struct App {
|
||||||
current_slide: Slide,
|
current_slide: Slide,
|
||||||
presentation_open: bool,
|
presentation_open: bool,
|
||||||
cli_mode: bool,
|
cli_mode: bool,
|
||||||
|
library: Library,
|
||||||
library_open: bool,
|
library_open: bool,
|
||||||
library_width: f32,
|
library_width: f32,
|
||||||
}
|
}
|
||||||
|
@ -172,6 +174,7 @@ impl cosmic::Application for App {
|
||||||
current_slide,
|
current_slide,
|
||||||
presentation_open: false,
|
presentation_open: false,
|
||||||
cli_mode: !input.ui,
|
cli_mode: !input.ui,
|
||||||
|
library: Library::new(&items),
|
||||||
library_open: true,
|
library_open: true,
|
||||||
library_width: 60.0,
|
library_width: 60.0,
|
||||||
};
|
};
|
||||||
|
@ -547,9 +550,9 @@ impl cosmic::Application for App {
|
||||||
]
|
]
|
||||||
.spacing(3);
|
.spacing(3);
|
||||||
|
|
||||||
// let library = Container::new("library")
|
let library = Container::new(self.library.view())
|
||||||
// .center(Length::Fill)
|
.center(Length::Fill)
|
||||||
// .width(self.library_width);
|
.width(self.library_width);
|
||||||
// let drag_handle = Container::new(Space::new(1, Length::Fill))
|
// let drag_handle = Container::new(Space::new(1, Length::Fill))
|
||||||
// .style(|t| nav_bar_style(t));
|
// .style(|t| nav_bar_style(t));
|
||||||
// let dragger = MouseArea::new(drag_handle)
|
// let dragger = MouseArea::new(drag_handle)
|
||||||
|
|
|
@ -1,18 +1,26 @@
|
||||||
use cosmic::{Element, Task};
|
use cosmic::{
|
||||||
|
iced::Length,
|
||||||
|
iced_widget::{column, text},
|
||||||
|
widget::{button, horizontal_space, icon, row},
|
||||||
|
Element, Task,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::core::{
|
use crate::core::{
|
||||||
images::Image, model::Model, presentations::Presentation,
|
images::Image, kinds::ServiceItemKind, model::Model,
|
||||||
|
presentations::Presentation, service_items::ServiceItemModel,
|
||||||
songs::Song, videos::Video,
|
songs::Song, videos::Video,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Library {
|
pub(crate) struct Library {
|
||||||
song_library: Model<Song>,
|
song_library: Model<Song>,
|
||||||
image_library: Model<Image>,
|
image_library: Model<Image>,
|
||||||
video_library: Model<Video>,
|
video_library: Model<Video>,
|
||||||
presentation_library: Model<Presentation>,
|
presentation_library: Model<Presentation>,
|
||||||
|
library_open: Option<ServiceItemKind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Message {
|
#[derive(Clone)]
|
||||||
|
pub(crate) enum Message {
|
||||||
AddItem,
|
AddItem,
|
||||||
RemoveItem,
|
RemoveItem,
|
||||||
OpenItem,
|
OpenItem,
|
||||||
|
@ -20,6 +28,9 @@ enum Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Library {
|
impl Library {
|
||||||
|
pub fn new(service_items: &ServiceItemModel) -> Library {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
pub fn update(&mut self, message: Message) -> Task<Message> {
|
pub fn update(&mut self, message: Message) -> Task<Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::AddItem => todo!(),
|
Message::AddItem => todo!(),
|
||||||
|
@ -30,6 +41,42 @@ impl Library {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<Message> {
|
pub fn view(&self) -> Element<Message> {
|
||||||
|
let column = column![
|
||||||
|
self.library_item(&self.song_library),
|
||||||
|
self.library_item(&self.image_library),
|
||||||
|
self.library_item(&self.video_library),
|
||||||
|
self.library_item(&self.presentation_library),
|
||||||
|
];
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn library_item<T>(
|
||||||
|
&self,
|
||||||
|
model: &Model<T>,
|
||||||
|
) -> Element<Message> {
|
||||||
|
let mut row = row::<Message>();
|
||||||
|
let title = match &model.kind {
|
||||||
|
ServiceItemKind::Song(song) => {
|
||||||
|
row = row.push(text!("Songs"));
|
||||||
|
}
|
||||||
|
ServiceItemKind::Video(video) => {
|
||||||
|
row = row.push(text!("Videos"));
|
||||||
|
}
|
||||||
|
ServiceItemKind::Image(image) => {
|
||||||
|
row = row.push(text!("Images"));
|
||||||
|
}
|
||||||
|
ServiceItemKind::Presentation(presentation) => {
|
||||||
|
row = row.push(text!("Presentations"));
|
||||||
|
}
|
||||||
|
ServiceItemKind::Content(slide) => todo!(),
|
||||||
|
};
|
||||||
|
let item_count = model.items.len();
|
||||||
|
row = row.push(text!("{}", item_count));
|
||||||
|
row = row.push(horizontal_space().width(Length::Fill));
|
||||||
|
row = row.push(
|
||||||
|
button::icon(icon::from_name("arrow-down"))
|
||||||
|
.on_press(Message::None),
|
||||||
|
);
|
||||||
|
row.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue