Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gtk-macros
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Felix Häcker
gtk-macros
Commits
8537cc48
Commit
8537cc48
authored
Mar 14, 2020
by
Bilal Elmoussaoui
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bilelmoussaoui/examples' into 'master'
Add basic examples See merge request
!3
parents
97188cbc
2e0797b2
Pipeline
#160789
passed with stages
in 6 minutes and 19 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
175 additions
and
1 deletion
+175
-1
src/lib.rs
src/lib.rs
+175
-1
No files found.
src/lib.rs
View file @
8537cc48
///
/// Retrieve a widget from a gtk::Builder
///
/// - Before:
///
/// Example:
///
/// ```no_run
/// let builder = gtk::Builder::new_frm_resource("/org/gnome/App/ui/widget.ui");
/// let widget: gtk::Label = builder.get_object("my_label").expect("Failed to find my_label object");
/// widget.set_text("Hello world!");
///
/// ```
///
/// - After:
///
/// Example 1:
///
/// ```no_run
/// let builder = gtk::Builder::new_from_resource("/org/gnome/App/ui/widget.ui");
/// get_widget!(builder, gtk::Label, my_label);
/// my_label.set_text("Hello world!");
/// ```
/// Example 2:
///
/// ```no_run
/// let builder = gtk::Builder::new_from_resource("/org/gnome/App/ui/widget.ui");
/// get_widget!(builder, gtk::Label, @my_label).set_text("Hello world!");
/// ```
#[macro_export]
macro_rules!
get_widget
{
(
$builder:expr
,
$wtype:ty
,
@
$name:ident
)
=>
{{
...
...
@@ -9,6 +38,29 @@ macro_rules! get_widget {
};
}
/// Spawn a future
///
/// - Before:
///
/// Example:
///
/// ```no_run
/// let ctx = glib::MainContext::default();
/// ctx.spawn_local(async {
/// something.await;
/// });
/// ```
///
/// - After:
///
/// Example:
///
/// ```no_run
/// spawn!(async {
/// something.await;
/// });
/// ```
#[macro_export]
macro_rules!
spawn
{
(
$future:expr
)
=>
{
...
...
@@ -17,6 +69,23 @@ macro_rules! spawn {
};
}
/// Send an event through a glib::Sender
///
/// - Before:
///
/// Example:
///
/// ```no_run
/// sender.send(Action::DoThing).expect("Failed to send DoThing through the glib channel?");
/// ```
///
/// - After:
///
/// Example:
///
/// ```no_run
/// send!(self.sender, Action::DoThing);
/// ```
#[macro_export]
macro_rules!
send
{
(
$sender:expr
,
$action:expr
)
=>
{
...
...
@@ -26,6 +95,40 @@ macro_rules! send {
};
}
/// Create a new action
///
/// - Before:
///
/// Example:
///
/// ```no_run
/// let widget = get_widget!(builder, gtk::Window, widget);
/// let actions = gio::SimpleActionGroup::new();
/// widget.insert_action_group("export", Some(&actions));
///
/// let action = gio::SimpleAction::new("do", None);
/// action.connect_activate(move |action, _| {
/// // Do something
/// });
/// actions.add_action(&action);
/// ```
///
/// - After:
///
/// Example:
///
/// ```no_run
/// let widget = get_widget!(builder, gtk::Window, widget);
/// let actions = gio::SimpleActionGroup::new();
/// widget.insert_action_group("export", Some(&actions));
/// action!(
/// actions,
/// "do",
/// move |action, _| {
/// // Do something
/// },
/// );
/// ```
#[macro_export]
macro_rules!
action
{
(
$actions_group:expr
,
$name:expr
,
$callback:expr
)
=>
{
...
...
@@ -40,6 +143,41 @@ macro_rules! action {
};
}
/// Create a new stateful action
///
/// - Before:
///
/// Example:
///
/// ```no_run
/// let actions = gio::SimpleActionGroup::new();
///
/// let is_dark_mode = false;
/// let action = gio::SimpleAction::new_stateful("dark-mode", None, &is_dark_mode.to_variant());
/// action.connect_activate(move |action, _| {
/// let state = action.get_state().unwrap();
/// let action_state: bool = state.get().unwrap();
/// let is_dark_mode = !action_state;
/// action.set_state(&is_dark_mode.to_variant());
/// });
/// actions.add_action(&action);
/// ```
///
/// - After:
///
/// Example:
/// ```no_run
/// let actions = gio::SimpleActionGroup::new();
/// let is_dark_mode = false;
/// stateful_action!(actions, "dark-mode", is_dark_mode, move |action, _| {
/// let state = action.get_state().unwrap();
/// let action_state: bool = state.get().unwrap();
/// let is_dark_mode = !action_state;
/// action.set_state(&is_dark_mode.to_variant());
///
/// // Store the state using gsettings for example
/// });
/// ```
#[macro_export]
macro_rules!
stateful_action
{
(
$actions_group:expr
,
$name:expr
,
$state:expr
,
$callback:expr
)
=>
{
...
...
@@ -54,7 +192,43 @@ macro_rules! stateful_action {
};
}
/// Retrieve an action from a gio::ActionGroup
///
/// - Before:
///
/// Example:
///
/// ```no_run
/// let actions = gio::SimpleActionGroup::new();
/// action!(
/// actions,
/// "delete",
/// move |action, _| {
/// // Do something
/// },
/// );
/// let action = actions.lookup_action("delete")
/// .unwrap()
/// .downcast::<gio::SimpleAction>()
/// .unwrap();
/// action.set_enabled(false);
/// ```
///
/// - After:
///
/// Example:
///
/// ```no_run
/// let actions = gio::SimpleActionGroup::new();
/// action!(
/// actions,
/// "delete",
/// move |action, _| {
/// // Do something
/// },
/// );
/// get_action!(actions, @delete).set_enabled(false);
/// ```
#[macro_export]
macro_rules!
get_action
{
(
$actions:expr
,
@
$name:ident
)
=>
{{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment