ui work, needs more work done
This commit is contained in:
parent
073b4a1eb8
commit
cd1cb7250a
160
src/boxes.rs
Normal file
160
src/boxes.rs
Normal file
@ -0,0 +1,160 @@
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::{
|
||||
glib::*,
|
||||
ApplicationWindow,
|
||||
Box,
|
||||
Button,
|
||||
FileChooserAction,
|
||||
FileChooserDialog,
|
||||
Label,
|
||||
Orientation,
|
||||
ResponseType,
|
||||
};
|
||||
|
||||
pub trait CustomBox {
|
||||
fn click_button(&self) {}
|
||||
fn set_button(&self) {}
|
||||
fn set_label(&self) {}
|
||||
fn set_box(&self) {}
|
||||
}
|
||||
|
||||
pub struct AppBox {
|
||||
pub app_box: Box,
|
||||
}
|
||||
|
||||
#[derive(Debug, Downgrade)]
|
||||
pub struct RomBox {
|
||||
pub rom_box: Box,
|
||||
pub rom_button: Button,
|
||||
pub rom_label: Label,
|
||||
pub rom_filechooser: FileChooserDialog,
|
||||
}
|
||||
|
||||
#[derive(Debug, Downgrade)]
|
||||
pub struct PatchBox {
|
||||
pub patch_box: Box,
|
||||
pub patch_button: Button,
|
||||
pub patch_label: Label,
|
||||
pub patch_filechooser: FileChooserDialog,
|
||||
}
|
||||
|
||||
impl AppBox {
|
||||
pub fn new() -> AppBox {
|
||||
AppBox {
|
||||
app_box: Box::new(Orientation::Vertical, 0),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_box(&self, rom_box: &RomBox, patch_box: &PatchBox) {
|
||||
self.app_box.set_visible(true);
|
||||
self.app_box.append(&rom_box.rom_box);
|
||||
self.app_box.append(&patch_box.patch_box);
|
||||
}
|
||||
}
|
||||
|
||||
impl RomBox {
|
||||
pub fn new(app: &ApplicationWindow) -> RomBox {
|
||||
RomBox {
|
||||
rom_box: Box::new(Orientation::Horizontal, 0),
|
||||
rom_button: Button::new(),
|
||||
rom_label: Label::new(Some("Choose ROM")),
|
||||
rom_filechooser: FileChooserDialog::new(
|
||||
Some("Select a ROM"),
|
||||
Some(app),
|
||||
FileChooserAction::Open,
|
||||
&[("OK", ResponseType::Ok), ("Cancel", ResponseType::Cancel)]
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CustomBox for RomBox {
|
||||
fn click_button(&self) {
|
||||
self.rom_button.connect_clicked(clone!(@weak self as this =>
|
||||
move |_| {
|
||||
this.rom_filechooser.show();
|
||||
}));
|
||||
}
|
||||
|
||||
fn set_button(&self) {
|
||||
self.rom_button.set_margin_top(20);
|
||||
self.rom_button.set_margin_bottom(0);
|
||||
self.rom_button.set_margin_start(20);
|
||||
self.rom_button.set_margin_end(20);
|
||||
self.rom_button.set_visible(true);
|
||||
self.rom_button.set_label("Open");
|
||||
}
|
||||
|
||||
fn set_label(&self) {
|
||||
self.rom_label.set_margin_top(20);
|
||||
self.rom_label.set_margin_bottom(0);
|
||||
self.rom_label.set_margin_start(20);
|
||||
self.rom_label.set_margin_end(20);
|
||||
self.rom_label.set_visible(true);
|
||||
}
|
||||
|
||||
fn set_box(&self) {
|
||||
self.rom_box.set_homogeneous(true);
|
||||
self.rom_box.set_visible(true);
|
||||
self.rom_box.append(&self.rom_label);
|
||||
self.rom_box.append(&self.rom_button);
|
||||
}
|
||||
}
|
||||
|
||||
impl PatchBox {
|
||||
pub fn new(app: &ApplicationWindow) -> PatchBox {
|
||||
PatchBox {
|
||||
patch_box: Box::new(Orientation::Horizontal, 0),
|
||||
patch_button: Button::new(),
|
||||
patch_label: Label::new(Some("Choose Patch")),
|
||||
patch_filechooser: FileChooserDialog::new(
|
||||
Some("Select a Patch"),
|
||||
Some(app),
|
||||
FileChooserAction::Open,
|
||||
&[("OK", ResponseType::Ok), ("Cancel", ResponseType::Cancel)]
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CustomBox for PatchBox{
|
||||
fn click_button(&self) {
|
||||
self.patch_button.connect_clicked(clone!(@weak self as this =>
|
||||
move |_| {
|
||||
this.patch_filechooser.show();
|
||||
|
||||
|
||||
|
||||
//this.patch_filechooser.close();
|
||||
}));
|
||||
|
||||
// self.patch_filechooser.connect_response(clone!(@weak self as this =>
|
||||
// move |_, ResponseType::Ok| {
|
||||
// this.patch_filechooser.close();
|
||||
// }));
|
||||
}
|
||||
|
||||
fn set_button(&self) {
|
||||
self.patch_button.set_margin_top(20);
|
||||
self.patch_button.set_margin_bottom(20);
|
||||
self.patch_button.set_margin_start(20);
|
||||
self.patch_button.set_margin_end(20);
|
||||
self.patch_button.set_visible(true);
|
||||
self.patch_button.set_label("Open");
|
||||
}
|
||||
|
||||
fn set_label(&self) {
|
||||
self.patch_label.set_margin_top(20);
|
||||
self.patch_label.set_margin_bottom(20);
|
||||
self.patch_label.set_margin_start(20);
|
||||
self.patch_label.set_margin_end(20);
|
||||
self.patch_label.set_visible(true);
|
||||
}
|
||||
|
||||
fn set_box(&self) {
|
||||
self.patch_box.set_homogeneous(true);
|
||||
self.patch_box.set_visible(true);
|
||||
self.patch_box.append(&self.patch_label);
|
||||
self.patch_box.append(&self.patch_button);
|
||||
}
|
||||
}
|
60
src/titlebar.rs
Normal file
60
src/titlebar.rs
Normal file
@ -0,0 +1,60 @@
|
||||
use std::rc::Rc;
|
||||
use futures::executor::block_on;
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::{
|
||||
glib::*,
|
||||
ApplicationWindow,
|
||||
HeaderBar,
|
||||
Button,
|
||||
Window
|
||||
};
|
||||
|
||||
#[derive(Debug, Downgrade)]
|
||||
pub struct CustomTitleBar {
|
||||
pub window: Window,
|
||||
pub titlebar: HeaderBar,
|
||||
pub run_button: Button,
|
||||
pub type_button: Button,
|
||||
}
|
||||
|
||||
impl CustomTitleBar {
|
||||
pub fn new() -> CustomTitleBar {
|
||||
CustomTitleBar {
|
||||
window: Window::new(),
|
||||
titlebar: HeaderBar::new(),
|
||||
run_button: Button::new(),
|
||||
type_button: Button::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_buttons(&self) {
|
||||
// set labels
|
||||
self.run_button.set_label("Apply Patch");
|
||||
self.type_button.set_label("Patch Type");
|
||||
|
||||
// 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);
|
||||
|
||||
// asdf
|
||||
|
||||
}
|
||||
|
||||
pub fn click_run_button(&self) {
|
||||
self.run_button.connect_clicked(move |button| {
|
||||
button.set_label("Avery is awesome!");
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user