-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef68be4
commit bae4fe5
Showing
5 changed files
with
129 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use gtk::prelude::*; | ||
use relm4::prelude::*; | ||
|
||
struct App { | ||
counter: u8, | ||
} | ||
|
||
#[derive(Debug)] | ||
enum Msg { | ||
Increment, | ||
Decrement, | ||
} | ||
|
||
#[relm4::component] | ||
impl SimpleComponent for App { | ||
type Init = u8; | ||
type Input = Msg; | ||
type Output = (); | ||
|
||
view! { | ||
gtk::Window { | ||
set_title: Some("Simple app"), | ||
set_default_size: (300, 100), | ||
|
||
gtk::Box { | ||
set_orientation: gtk::Orientation::Vertical, | ||
set_spacing: 5, | ||
set_margin_all: 5, | ||
|
||
gtk::Button { | ||
set_label: "Increment", | ||
connect_clicked => Msg::Increment, | ||
}, | ||
|
||
gtk::Button { | ||
set_label: "Decrement", | ||
connect_clicked => Msg::Decrement, | ||
}, | ||
|
||
gtk::Label { | ||
#[watch] | ||
set_label: &format!("Counter: {}", model.counter), | ||
set_margin_all: 5, | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Initialize the component. | ||
fn init( | ||
counter: Self::Init, | ||
root: &Self::Root, | ||
sender: ComponentSender<Self>, | ||
) -> ComponentParts<Self> { | ||
let model = App { counter }; | ||
|
||
// Insert the code generation of the view! macro here | ||
let widgets = view_output!(); | ||
|
||
ComponentParts { model, widgets } | ||
} | ||
|
||
fn update(&mut self, _msg: Self::Input, _sender: ComponentSender<Self>) { | ||
panic!("test"); | ||
} | ||
|
||
fn handle_panic() -> bool { | ||
println!("Panic handler called!"); | ||
true | ||
} | ||
} | ||
|
||
fn main() { | ||
let app = RelmApp::new("relm4.example.simple"); | ||
app.run::<App>(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters