Removal of testing stuff
This commit is contained in:
parent
9d939bc563
commit
8004243a8f
209
src/main.rs
209
src/main.rs
|
@ -1,158 +1,16 @@
|
|||
use gtk::prelude::*;
|
||||
use gtk::glib::BoxedAnyObject;
|
||||
use relm4::prelude::*;
|
||||
use relm4_icons::icon_name;
|
||||
use std::cell::Ref;
|
||||
|
||||
struct HeaderModel;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum HeaderOutput {
|
||||
Counters,
|
||||
Edit,
|
||||
Export,
|
||||
}
|
||||
|
||||
#[relm4::component]
|
||||
impl SimpleComponent for HeaderModel {
|
||||
type Init = ();
|
||||
type Input = ();
|
||||
type Output = HeaderOutput;
|
||||
|
||||
view! {
|
||||
#[root]
|
||||
gtk::HeaderBar {
|
||||
#[wrap(Some)]
|
||||
set_title_widget = >k::Box {
|
||||
add_css_class: "linked",
|
||||
#[name = "group"]
|
||||
gtk::ToggleButton {
|
||||
set_label: "Counters",
|
||||
set_active: true,
|
||||
connect_toggled[sender] => move |btn| {
|
||||
if btn.is_active() {
|
||||
sender.output(HeaderOutput::Counters).unwrap()
|
||||
}
|
||||
},
|
||||
},
|
||||
gtk::ToggleButton {
|
||||
set_label: "Edit",
|
||||
set_group: Some(&group),
|
||||
connect_toggled[sender] => move |btn| {
|
||||
if btn.is_active() {
|
||||
sender.output(HeaderOutput::Edit).unwrap()
|
||||
}
|
||||
},
|
||||
},
|
||||
gtk::ToggleButton {
|
||||
set_label: "Export",
|
||||
set_group: Some(&group),
|
||||
connect_toggled[sender] => move |btn| {
|
||||
if btn.is_active() {
|
||||
sender.output(HeaderOutput::Export).unwrap()
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn init(
|
||||
_init: Self::Init,
|
||||
root: &Self::Root,
|
||||
sender: ComponentSender<Self>,
|
||||
) -> ComponentParts<Self> {
|
||||
let model = HeaderModel;
|
||||
let widgets = view_output!();
|
||||
ComponentParts { model, widgets }
|
||||
}
|
||||
}
|
||||
|
||||
struct DialogModel {
|
||||
hidden: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum DialogInput {
|
||||
Show,
|
||||
Accept,
|
||||
Cancel,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum DialogOutput {
|
||||
Close,
|
||||
}
|
||||
|
||||
#[relm4::component]
|
||||
impl SimpleComponent for DialogModel {
|
||||
type Init = ();
|
||||
type Input = DialogInput;
|
||||
type Output = DialogOutput;
|
||||
|
||||
view! {
|
||||
gtk::MessageDialog {
|
||||
set_modal: true,
|
||||
#[watch]
|
||||
set_visible: !model.hidden,
|
||||
set_text: Some("Do you want to close before saving?"),
|
||||
set_secondary_text: Some("All unsaved changes will be lost"),
|
||||
add_button: ("Close", gtk::ResponseType::Accept),
|
||||
add_button: ("Cancel", gtk::ResponseType::Cancel),
|
||||
connect_response[sender] => move |_, resp| {
|
||||
sender.input(if resp == gtk::ResponseType::Accept {
|
||||
DialogInput::Accept
|
||||
} else {
|
||||
DialogInput::Cancel
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>) {
|
||||
match message {
|
||||
DialogInput::Show => self.hidden = false,
|
||||
DialogInput::Accept => {
|
||||
self.hidden = true;
|
||||
sender.output(DialogOutput::Close).unwrap()
|
||||
}
|
||||
DialogInput::Cancel => self.hidden = true,
|
||||
}
|
||||
}
|
||||
|
||||
fn init(
|
||||
_init: Self::Init,
|
||||
root: &Self::Root,
|
||||
sender: ComponentSender<Self>,
|
||||
) -> ComponentParts<Self> {
|
||||
let model = DialogModel { hidden: true };
|
||||
let widgets = view_output!();
|
||||
ComponentParts { model, widgets }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum AppMode {
|
||||
Counters,
|
||||
Edit,
|
||||
Export,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum AppMsg {
|
||||
SetMode(AppMode),
|
||||
CloseRequest,
|
||||
Close,
|
||||
Increment,
|
||||
Decrement,
|
||||
}
|
||||
|
||||
struct AppModel {
|
||||
mode: AppMode,
|
||||
header: Controller<HeaderModel>,
|
||||
samples: gtk::MultiSelection,
|
||||
dialog: Controller<DialogModel>,
|
||||
counter: u8,
|
||||
}
|
||||
|
||||
struct Sample {
|
||||
|
@ -169,12 +27,12 @@ impl SimpleComponent for AppModel {
|
|||
|
||||
view! {
|
||||
gtk::Window {
|
||||
set_titlebar: Some(model.header.widget()),
|
||||
set_default_width: 300,
|
||||
set_default_height: 100,
|
||||
set_title: Some("SampleAmp"),
|
||||
set_default_width: 700,
|
||||
set_default_height: 400,
|
||||
|
||||
connect_close_request[sender] => move |_| {
|
||||
sender.input(AppMsg::CloseRequest);
|
||||
sender.input(AppMsg::Close);
|
||||
gtk::Inhibit(true)
|
||||
},
|
||||
|
||||
|
@ -213,54 +71,23 @@ impl SimpleComponent for AppModel {
|
|||
}
|
||||
},
|
||||
|
||||
gtk::Label {
|
||||
#[watch]
|
||||
set_label: &format!("Currently in the {:?} mode", model.mode),
|
||||
},
|
||||
|
||||
gtk::Box {
|
||||
set_orientation: gtk::Orientation::Horizontal,
|
||||
set_spacing: 5,
|
||||
gtk::Button::from_icon_name(icon_name::PLUS) {
|
||||
connect_clicked => AppMsg::Increment,
|
||||
set_height_request: 100,
|
||||
gtk::Label {
|
||||
#[watch]
|
||||
set_label: "Sample playback",
|
||||
},
|
||||
|
||||
gtk::Button::from_icon_name(icon_name::MINUS) {
|
||||
connect_clicked => AppMsg::Decrement,
|
||||
},
|
||||
},
|
||||
|
||||
gtk::Label {
|
||||
#[watch]
|
||||
set_label: &format!("Counter: {}", model.counter),
|
||||
set_margin_all: 5,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn init(
|
||||
counter: Self::Init,
|
||||
_: Self::Init,
|
||||
window: &Self::Root,
|
||||
sender: ComponentSender<Self>,
|
||||
) -> relm4::ComponentParts<Self> {
|
||||
let header: Controller<HeaderModel> =
|
||||
HeaderModel::builder()
|
||||
.launch(())
|
||||
.forward(sender.input_sender(), |msg| match msg {
|
||||
HeaderOutput::Counters => AppMsg::SetMode(AppMode::Counters),
|
||||
HeaderOutput::Edit => AppMsg::SetMode(AppMode::Edit),
|
||||
HeaderOutput::Export => AppMsg::SetMode(AppMode::Export),
|
||||
});
|
||||
|
||||
let dialog = DialogModel::builder()
|
||||
.transient_for(window)
|
||||
.launch(())
|
||||
.forward(sender.input_sender(), |msg| match msg {
|
||||
DialogOutput::Close => AppMsg::Close,
|
||||
});
|
||||
|
||||
let factory1 = gtk::SignalListItemFactory::new();
|
||||
factory1.connect_bind(move |_factory, item| {
|
||||
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
|
||||
|
@ -290,10 +117,6 @@ impl SimpleComponent for AppModel {
|
|||
let samples = gtk::MultiSelection::new(Some(samples));
|
||||
|
||||
let model = AppModel {
|
||||
counter,
|
||||
mode: AppMode::Counters,
|
||||
header,
|
||||
dialog,
|
||||
samples
|
||||
};
|
||||
let widgets = view_output!();
|
||||
|
@ -303,21 +126,9 @@ impl SimpleComponent for AppModel {
|
|||
|
||||
fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) {
|
||||
match message {
|
||||
AppMsg::SetMode(mode) => {
|
||||
self.mode = mode;
|
||||
}
|
||||
AppMsg::CloseRequest => {
|
||||
self.dialog.sender().send(DialogInput::Show).unwrap();
|
||||
}
|
||||
AppMsg::Close => {
|
||||
relm4::main_application().quit();
|
||||
}
|
||||
AppMsg::Increment => {
|
||||
self.counter = self.counter.wrapping_add(1);
|
||||
}
|
||||
AppMsg::Decrement => {
|
||||
self.counter = self.counter.wrapping_sub(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue