Add scaffold for home page

This commit is contained in:
Elias Projahn 2023-09-20 13:49:02 +02:00
parent 8c56e90994
commit 3ef0fe960b
11 changed files with 266 additions and 1 deletions

64
src/home_page.rs Normal file
View file

@ -0,0 +1,64 @@
use adw::subclass::{navigation_page::NavigationPageImpl, prelude::*};
use gtk::glib;
mod imp {
use crate::tile::MusicusTile;
use super::*;
#[derive(Debug, Default, gtk::CompositeTemplate)]
#[template(resource = "/de/johrpan/musicus/home_page.ui")]
pub struct MusicusHomePage {
#[template_child]
pub search_entry: TemplateChild<gtk::SearchEntry>,
#[template_child]
pub persons_flow_box: TemplateChild<gtk::FlowBox>,
#[template_child]
pub works_flow_box: TemplateChild<gtk::FlowBox>,
#[template_child]
pub recordings_flow_box: TemplateChild<gtk::FlowBox>,
}
#[glib::object_subclass]
impl ObjectSubclass for MusicusHomePage {
const NAME: &'static str = "MusicusHomePage";
type Type = super::MusicusHomePage;
type ParentType = adw::NavigationPage;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for MusicusHomePage {
fn constructed(&self) {
self.parent_constructed();
self.search_entry
.set_key_capture_widget(Some(self.obj().as_ref()));
for _ in 0..9 {
self.persons_flow_box.append(&MusicusTile::new());
self.works_flow_box.append(&MusicusTile::new());
self.recordings_flow_box.append(&MusicusTile::new());
}
}
}
impl WidgetImpl for MusicusHomePage {}
impl NavigationPageImpl for MusicusHomePage {}
}
glib::wrapper! {
pub struct MusicusHomePage(ObjectSubclass<imp::MusicusHomePage>)
@extends gtk::Widget, adw::NavigationPage;
}
impl MusicusHomePage {
pub fn new() -> Self {
glib::Object::new()
}
}

View file

@ -1,5 +1,7 @@
mod application;
mod config;
mod home_page;
mod tile;
mod welcome_page;
mod window;

39
src/tile.rs Normal file
View file

@ -0,0 +1,39 @@
use gtk::{glib, subclass::prelude::*};
mod imp {
use super::*;
#[derive(Debug, Default, gtk::CompositeTemplate)]
#[template(resource = "/de/johrpan/musicus/tile.ui")]
pub struct MusicusTile {}
#[glib::object_subclass]
impl ObjectSubclass for MusicusTile {
const NAME: &'static str = "MusicusTile";
type Type = super::MusicusTile;
type ParentType = gtk::FlowBoxChild;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for MusicusTile {}
impl WidgetImpl for MusicusTile {}
impl FlowBoxChildImpl for MusicusTile {}
}
glib::wrapper! {
pub struct MusicusTile(ObjectSubclass<imp::MusicusTile>)
@extends gtk::Widget, gtk::FlowBoxChild;
}
impl MusicusTile {
pub fn new() -> Self {
glib::Object::new()
}
}

View file

@ -1,4 +1,4 @@
use crate::welcome_page::MusicusWelcomePage;
use crate::{welcome_page::MusicusWelcomePage, home_page::MusicusHomePage};
use adw::subclass::prelude::*;
use gtk::{gio, glib, prelude::*};
@ -20,6 +20,7 @@ mod imp {
type ParentType = adw::ApplicationWindow;
fn class_init(klass: &mut Self::Class) {
MusicusHomePage::static_type();
MusicusWelcomePage::static_type();
klass.bind_template();
klass.bind_template_instance_callbacks();
@ -60,5 +61,6 @@ impl MusicusWindow {
async fn set_library_folder(&self, folder: &gio::File) {
let path = folder.path();
log::info!("{path:?}");
self.imp().navigation_view.replace_with_tags(&["home"]);
}
}