added popover

This commit is contained in:
Wyatt J. Miller 2021-08-25 19:37:59 -04:00
parent d5b28f0b94
commit d2ff6e2a74
4 changed files with 108 additions and 13 deletions

View File

@ -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<ApplicationWindow> = 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();

4
src/menu.rs Normal file
View File

@ -0,0 +1,4 @@
enum PatchType {
Ips,
Bps,
}

49
src/popover.rs Normal file
View File

@ -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));
}
}

View File

@ -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?
}
}