Permalink
Browse files

Switch from async callbacks to the with keyword

  • Loading branch information...
antoyo committed Jul 21, 2017
1 parent fb25e28 commit 4356d379cbd7c9aa8d92bb592a5ecd201384f2ec
View
@@ -19,14 +19,12 @@ branch = "master"
repository = "antoyo/relm"
[dependencies]
futures = "^0.1.14"
glib = "^0.1.2"
glib-sys = "^0.3.4"
gobject-sys = "^0.3.3"
gtk = "^0.1.1"
gtk-sys = "^0.3.3"
libc = "^0.2.22"
log = "^0.3.8"
[dependencies.futures-glib]
git = "https://github.com/antoyo/futures-glib-rs"

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
@@ -21,7 +21,6 @@
#![feature(proc_macro)]
extern crate futures;
extern crate futures_glib;
extern crate gtk;
#[macro_use]
@@ -30,48 +29,49 @@ extern crate relm_attributes;
#[macro_use]
extern crate relm_derive;
use std::cell::Cell;
use std::rc::Rc;
use gtk::{
Inhibit,
WidgetExt,
};
use relm::{Relm, Resolver, Widget};
use relm::{Relm, Widget};
use relm_attributes::widget;
use self::Msg::*;
#[derive(Msg)]
pub enum Msg {
Delete(Resolver<Inhibit>),
Delete,
Press,
Release,
Quit,
}
pub struct Model {
press_count: i32,
press_count: Rc<Cell<i32>>,
relm: Relm<Win>,
}
#[widget]
impl Widget for Win {
fn model(relm: &Relm<Self>, _: ()) -> Model {
Model {
press_count: 0,
press_count: Rc::new(Cell::new(0)),
relm: relm.clone(),
}
}
fn update(&mut self, event: Msg) {
match event {
Delete(mut resolver) => {
let inhibit = self.model.press_count > 3;
resolver.resolve(Inhibit(inhibit));
if !inhibit {
Delete => {
if self.model.press_count.get() <= 3 {
self.model.relm.stream().emit(Quit);
}
},
Press => {
self.model.press_count += 1;
self.model.press_count.set(self.model.press_count.get() + 1);
println!("Press");
},
Release => {
@@ -85,11 +85,15 @@ impl Widget for Win {
gtk::Window {
key_press_event(_, key) => (Press, Inhibit(false)),
key_release_event(_, key) => (Release, Inhibit(false)),
delete_event(_, _) => async Delete,
delete_event(_, _) with (press_count) => (Delete, inhibit_delete_event(&press_count)),
}
}
}
fn inhibit_delete_event(press_count: &Rc<Cell<i32>>) -> Inhibit {
Inhibit(press_count.get() > 3)
}
fn main() {
Win::run(()).unwrap();
}
Oops, something went wrong.

0 comments on commit 4356d37

Please sign in to comment.