diff --git a/src/main.rs b/src/main.rs index 0fb4c10..5f748d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,12 @@ mod patch; mod titlebar; mod boxes; +mod menu; +mod popover; use titlebar::CustomTitleBar; use boxes::*; +use popover::CustomPopoverMenu; use std::path::PathBuf; use std::rc::Rc; @@ -13,8 +16,10 @@ use gtk4::{ gdk::{ Display }, + gio::MenuModel, Application, ApplicationWindow, + Builder, StyleContext, }; @@ -36,19 +41,29 @@ fn build_ui(app: &Application) { &Display::default().expect("Error initializing CSS provider!"), &provider, gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION, - ); + ); + + let builder = Builder::new(); + builder.add_from_resource("/com/wyattjmiller/snespatcher/appmenu.xml").expect("Error initializing app menu!"); + //println!("{:?}", builder.list_properties()); let app_window: Rc = Rc::new(ApplicationWindow::new(app)); - let header_bar: CustomTitleBar = CustomTitleBar::new(); + let popover_menu: CustomPopoverMenu = CustomPopoverMenu::new(); + let header_bar: CustomTitleBar = CustomTitleBar::new(&popover_menu); let app_box: AppBox = AppBox::new(); let patch_box: PatchBox = PatchBox::new(&app_window); let rom_box: RomBox = RomBox::new(&app_window); + // set popover_menu methods + popover_menu.set_texts(); + + // TODO: Set popover textviews and put them in a separate file // set header bar methods header_bar.set_buttons(); header_bar.set_titlebar(); header_bar.set_window(&app_window); header_bar.click_run_button(); + header_bar.click_menu(); // set patch box methods patch_box.set_label(); diff --git a/src/menu.rs b/src/menu.rs new file mode 100644 index 0000000..0d6ff99 --- /dev/null +++ b/src/menu.rs @@ -0,0 +1,4 @@ +enum PatchType { + Ips, + Bps, +} \ No newline at end of file diff --git a/src/popover.rs b/src/popover.rs new file mode 100644 index 0000000..d0943dd --- /dev/null +++ b/src/popover.rs @@ -0,0 +1,49 @@ +use std::rc::Rc; +use futures::executor::block_on; +use gtk4::prelude::*; +use gtk4::subclass::prelude::*; +use gtk4::{ + gdk::Paintable, + glib::*, + ApplicationWindow, + HeaderBar, + Button, + Window, + Popover, + Builder, + IconTheme, + IconLookupFlags, + TextDirection, + MenuButton, + TextView, + Box, + Orientation, +}; + +#[derive(Debug, Clone, Downgrade)] +pub struct CustomPopoverMenu { + pub popover: Popover, + pub pop_box: Box, + pub test_text_view:Button, + pub subtest_text_view: Button, +} + +impl CustomPopoverMenu { + pub fn new() -> CustomPopoverMenu { + CustomPopoverMenu { + popover: Popover::new(), + pop_box: Box::new(Orientation::Vertical, 0), + test_text_view: Button::new(), + subtest_text_view: Button::new(), + } + } + + pub fn set_texts(&self) { + self.test_text_view.set_label("About"); + self.subtest_text_view.set_label("Psyche!"); + self.pop_box.append(&self.test_text_view); + self.pop_box.append(&self.subtest_text_view); + self.pop_box.set_visible(true); + self.popover.set_child(Some(&self.pop_box)); + } +} \ No newline at end of file diff --git a/src/titlebar.rs b/src/titlebar.rs index c7f9993..d9e3ded 100644 --- a/src/titlebar.rs +++ b/src/titlebar.rs @@ -1,61 +1,88 @@ use std::rc::Rc; use futures::executor::block_on; -use gtk4::prelude::*; +use gtk4::{prelude::*}; +use gtk4::subclass::prelude::*; use gtk4::{ + gdk::Paintable, glib::*, ApplicationWindow, HeaderBar, Button, - Window + Window, + Popover, + Builder, + IconTheme, + IconLookupFlags, + TextDirection, + MenuButton, }; +use crate::popover::CustomPopoverMenu; + #[derive(Debug, Downgrade)] pub struct CustomTitleBar { pub window: Window, pub titlebar: HeaderBar, pub run_button: Button, - pub type_button: Button, + pub menu_button: MenuButton, + pub popover_menu: CustomPopoverMenu, } impl CustomTitleBar { - pub fn new() -> CustomTitleBar { + pub fn new(pop: &CustomPopoverMenu) -> CustomTitleBar { + // loading PopoverMenu logic goes here CustomTitleBar { window: Window::new(), titlebar: HeaderBar::new(), run_button: Button::new(), - type_button: Button::new(), + menu_button: MenuButton::new(), + popover_menu: pop.clone(), } } pub fn set_buttons(&self) { // set labels self.run_button.set_label("Apply Patch"); - self.type_button.set_label("Patch Type"); + //self.menu_button.set_label("Menu"); // set css class; it turns blue! self.run_button.set_css_classes(&["run_btn"]); // set visibility self.run_button.set_visible(true); - self.type_button.set_visible(true); + self.menu_button.set_visible(true); + + // symbolic + // let menu_button = IconTheme::new(); + // menu_button.lookup_icon("open-menu-symbolic", &[], 16, 1, TextDirection::Ltr, IconLookupFlags::empty()); + self.menu_button.set_popover(Some(&self.popover_menu.popover)); - // asdf - } pub fn click_run_button(&self) { self.run_button.connect_clicked(move |button| { - button.set_label("Avery is awesome!"); + button.set_label("Avery is awesome!"); }); } + pub fn click_menu(&self) { + // self.menu_button.connect_clicked(clone!(@weak self as this => + // move |_| { + // this.popover.show(); + // })); + } + pub fn set_window(&self, window: &ApplicationWindow) { window.set_titlebar(Some(&self.titlebar)); } pub fn set_titlebar(&self) { self.titlebar.pack_start(&self.run_button); - self.titlebar.pack_start(&self.type_button); + self.titlebar.pack_end(&self.menu_button); self.titlebar.set_css_classes(&["headerbar"]) } + + pub fn set_popover(&self) { + // huh? why is this method here again? + } } \ No newline at end of file