-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Showing
3 changed files
with
64 additions
and
0 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
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,46 @@ | ||
// You can copy/paste this file every time you need a simple GObject | ||
// to hold some data | ||
|
||
use glib::once_cell::sync::Lazy; | ||
use glib::prelude::*; | ||
use glib::subclass::prelude::*; | ||
use glib::subclass::Signal; | ||
use glib::Properties; | ||
use std::cell::RefCell; | ||
|
||
mod imp { | ||
use super::*; | ||
|
||
#[derive(Properties, Default)] | ||
#[properties(wrapper_type = super::Author)] | ||
pub struct Author { | ||
#[property(get, set)] | ||
name: RefCell<String>, | ||
#[property(get, set)] | ||
surname: RefCell<String>, | ||
} | ||
|
||
#[glib::derived_properties] | ||
impl ObjectImpl for Author { | ||
fn signals() -> &'static [Signal] { | ||
static SIGNALS: Lazy<Vec<Signal>> = | ||
Lazy::new(|| vec![Signal::builder("awarded").build()]); | ||
SIGNALS.as_ref() | ||
} | ||
} | ||
|
||
#[glib::object_subclass] | ||
impl ObjectSubclass for Author { | ||
const NAME: &'static str = "Author"; | ||
type Type = super::Author; | ||
} | ||
} | ||
|
||
glib::wrapper! { | ||
pub struct Author(ObjectSubclass<imp::Author>); | ||
} | ||
impl Author { | ||
pub fn new() -> Self { | ||
glib::Object::builder().build() | ||
} | ||
} |
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,14 @@ | ||
mod author; | ||
|
||
use glib::prelude::*; | ||
|
||
fn main() { | ||
let author = author::Author::new(); | ||
author.set_name("John"); | ||
author.set_surname("Doe"); | ||
author.connect("awarded", true, |_author| { | ||
println!("Author received a new award!"); | ||
None | ||
}); | ||
println!("Author: {} {}", author.name(), author.surname()); | ||
} |