use super::db_browser; use super::home_page; use super::jlc_downloader; use super::part_viewer; use iced::widget as w; use iced::{ Element, Length, alignment::{Horizontal, Vertical}, widget::{Column, Container, Text}, }; use iced_aw::Tabs; use iced_aw::iced_fonts; struct MainWindow { title: String, theme: iced::Theme, curr_tab: TabId, tab_pos: iced_aw::tabs::TabBarPosition, home_page: home_page::HomePage, } impl Default for MainWindow { fn default() -> Self { Self { title: Default::default(), theme: Default::default(), curr_tab: Default::default(), tab_pos: iced_aw::tabs::TabBarPosition::Top, home_page: Default::default(), } } } const ICON_BYTES: &[u8] = include_bytes!("./../../fonts/icons.ttf"); const ICON: iced::Font = iced::Font::with_name("icons"); pub fn main_window() { iced::application(MainWindow::default, MainWindow::update, MainWindow::view) .title(MainWindow::title) .font(iced_fonts::REQUIRED_FONT_BYTES) .font(ICON_BYTES) .run(); } #[derive(Debug, Clone)] pub enum MainWindowMsg { TabSelected(TabId), TabClosed(TabId), ThemeChanged(iced::Theme), TitleChanged(String), HomePageMsg(home_page::HomePageMsg), Nothing, } #[derive(Debug, Default, Clone, PartialEq, Eq)] enum TabId { #[default] HomePage, JlcDownloader, DbBrowser, PartViewer, } impl MainWindow { fn title(&self) -> String { self.title.clone() } fn update(&mut self, msg: MainWindowMsg) { match msg { MainWindowMsg::ThemeChanged(theme) => { self.theme = theme; } MainWindowMsg::TitleChanged(title) => { self.title = title; } MainWindowMsg::Nothing => { println!("Nothing"); iced::debug::time("Test".to_owned()); } MainWindowMsg::HomePageMsg(message) => { self.home_page.update(message); } MainWindowMsg::TabSelected(tab_id) => { self.curr_tab = tab_id; } MainWindowMsg::TabClosed(tab_id) => todo!(), } } fn view(&self) -> Element<'_, MainWindowMsg> { let t = Tabs::new(MainWindowMsg::TabSelected) .tab_icon_position(iced_aw::tabs::Position::Left) .on_close(MainWindowMsg::TabClosed) .push( TabId::HomePage, self.home_page.tab_label(), self.home_page.view(), ) .set_active_tab(&self.curr_tab) .icon_font(ICON) .tab_bar_style(Box::new(iced_aw::style::tab_bar::primary)) .tab_bar_position(self.tab_pos.clone()); w::button("ClickMe").on_press(MainWindowMsg::Nothing).into() } } pub trait TabFrame { type Message; fn title(&self) -> String; fn tab_label(&self) -> iced_aw::TabLabel; fn container(&self) -> Element<'_, Self::Message>; fn view(&self) -> Element<'_, Self::Message> { w::Container::new(self.container()) .width(Length::Fill) .height(Length::Fill) .align_x(Horizontal::Left) .align_y(Vertical::Top) .padding(5) .into() } }