Move ui files into separate folder

This commit is contained in:
Julian Mutter 2024-02-02 19:30:52 +01:00
parent 4f65715967
commit 6a6e1d03df
5 changed files with 96 additions and 86 deletions

View File

@ -1,7 +1,6 @@
mod database;
mod mcdu;
mod sheet;
mod sheet_listing;
mod ui;
use std::{
path::{Path, PathBuf},
@ -11,94 +10,12 @@ use std::{
use clap::Parser;
use database::Database;
use env_logger::Env;
use gtk::prelude::*;
use log::{debug, error};
use mcdu::McduModel;
use relm4::prelude::*;
use relm4::RelmApp;
use sheet::Sheet;
use sheet_listing::{SheetListingInput, SheetListingModel};
use walkdir::WalkDir;
struct AppModel {
mcdu: Controller<McduModel>,
sheet_listing: Controller<SheetListingModel>,
}
#[derive(Debug)]
enum AppInput {
SearchStarted(String),
SheetPressed(PathBuf),
}
#[relm4::component]
impl SimpleComponent for AppModel {
type Input = AppInput;
type Output = ();
type Init = PathBuf;
view! {
#[root]
gtk::Window{
set_default_width: 300,
set_default_height: 300,
set_title: Some("Play music!!!"),
set_maximized: true,
gtk::Box {
set_orientation: gtk::Orientation::Horizontal,
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_hexpand: true,
gtk::ScrolledWindow {
model.sheet_listing.widget(),
set_vexpand: true,
set_hexpand: true,
// set_hscrollbar_policy: PolicyType::Never,
},
},
model.mcdu.widget(),
}
}
}
fn init(
path: Self::Init,
window: &Self::Root,
sender: ComponentSender<Self>,
) -> relm4::ComponentParts<Self> {
relm4_icons::initialize_icons();
let mcdu = McduModel::builder()
.launch(())
.forward(sender.input_sender(), |response| match response {
mcdu::McduOutput::SearchStarted(query) => AppInput::SearchStarted(query),
});
let sheet_listing =
SheetListingModel::builder()
.launch(path)
.forward(sender.input_sender(), |response| match response {
sheet_listing::SheetPressedMessage::SheetPressed(path) => {
AppInput::SheetPressed(path)
}
});
let model = AppModel {
mcdu,
sheet_listing,
};
let widgets = view_output!();
ComponentParts { model, widgets }
}
fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) {
match message {
AppInput::SheetPressed(sheet) => opener::open(sheet).unwrap(),
AppInput::SearchStarted(query) => self.sheet_listing.emit(SheetListingInput { query }),
}
}
}
use crate::ui::app::AppModel;
#[derive(Parser)]
#[command(author, version, about)]

90
src/ui/app.rs Normal file
View File

@ -0,0 +1,90 @@
use std::path::PathBuf;
use gtk::prelude::*;
use relm4::prelude::*;
use crate::ui::{mcdu::McduOutput, sheet_listing::SheetPressedMessage};
use super::{
mcdu::McduModel,
sheet_listing::{SheetListingInput, SheetListingModel},
};
pub struct AppModel {
mcdu: Controller<McduModel>,
sheet_listing: Controller<SheetListingModel>,
}
#[derive(Debug)]
pub enum AppInput {
SearchStarted(String),
SheetPressed(PathBuf),
}
#[relm4::component(pub)]
impl SimpleComponent for AppModel {
type Input = AppInput;
type Output = ();
type Init = PathBuf;
view! {
#[root]
gtk::Window{
set_default_width: 300,
set_default_height: 300,
set_title: Some("Play music!!!"),
set_maximized: true,
gtk::Box {
set_orientation: gtk::Orientation::Horizontal,
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_hexpand: true,
gtk::ScrolledWindow {
model.sheet_listing.widget(),
set_vexpand: true,
set_hexpand: true,
// set_hscrollbar_policy: PolicyType::Never,
},
},
model.mcdu.widget(),
}
}
}
fn init(
path: Self::Init,
window: &Self::Root,
sender: ComponentSender<Self>,
) -> relm4::ComponentParts<Self> {
relm4_icons::initialize_icons();
let mcdu = McduModel::builder()
.launch(())
.forward(sender.input_sender(), |response| match response {
McduOutput::SearchStarted(query) => AppInput::SearchStarted(query),
});
let sheet_listing =
SheetListingModel::builder()
.launch(path)
.forward(sender.input_sender(), |response| match response {
SheetPressedMessage::SheetPressed(path) => AppInput::SheetPressed(path),
});
let model = AppModel {
mcdu,
sheet_listing,
};
let widgets = view_output!();
ComponentParts { model, widgets }
}
fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) {
match message {
AppInput::SheetPressed(sheet) => opener::open(sheet).unwrap(),
AppInput::SearchStarted(query) => self.sheet_listing.emit(SheetListingInput { query }),
}
}
}

3
src/ui/mod.rs Normal file
View File

@ -0,0 +1,3 @@
pub mod app;
pub mod mcdu;
pub mod sheet_listing;