Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

book: Update to 0.7 release #1324

Merged
merged 5 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
349 changes: 182 additions & 167 deletions book/listings/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion book/listings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dirs = "5.0"
walkdir = "2.3"

[build-dependencies]
glib-build-tools = "0.17"
glib-build-tools = "0.18"

# actions
[[bin]]
Expand Down
4 changes: 2 additions & 2 deletions book/listings/actions/3/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn build_ui(app: &Application) {
let action_count = SimpleAction::new_stateful(
"count",
Some(&i32::static_variant_type()),
original_state.to_variant(),
&original_state.to_variant(),
);
action_count.connect_activate(clone!(@weak label => move |action, parameter| {
// Get state
Expand All @@ -80,7 +80,7 @@ fn build_ui(app: &Application) {

// Increase state by parameter and store state
state += parameter;
action.set_state(state.to_variant());
action.set_state(&state.to_variant());

// Update label with new state
label.set_label(&format!("Counter: {state}"));
Expand Down
4 changes: 2 additions & 2 deletions book/listings/actions/4/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn build_ui(app: &Application) {
let action_count = SimpleAction::new_stateful(
"count",
Some(&i32::static_variant_type()),
original_state.to_variant(),
&original_state.to_variant(),
);
action_count.connect_activate(clone!(@weak label => move |action, parameter| {
// Get state
Expand All @@ -76,7 +76,7 @@ fn build_ui(app: &Application) {

// Increase state by parameter and save state
state += parameter;
action.set_state(state.to_variant());
action.set_state(&state.to_variant());

// Update label with new state
label.set_label(&format!("Counter: {state}"));
Expand Down
4 changes: 2 additions & 2 deletions book/listings/actions/5/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Window {
let action_count = SimpleAction::new_stateful(
"count",
Some(&i32::static_variant_type()),
original_state.to_variant(),
&original_state.to_variant(),
);

action_count.connect_activate(clone!(@weak label => move |action, parameter| {
Expand All @@ -47,7 +47,7 @@ impl Window {

// Increase state by parameter and save state
state += parameter;
action.set_state(state.to_variant());
action.set_state(&state.to_variant());

// Update label with new state
label.set_label(&format!("Counter: {state}"));
Expand Down
8 changes: 4 additions & 4 deletions book/listings/actions/6/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Window {
let action_count = SimpleAction::new_stateful(
"count",
Some(&i32::static_variant_type()),
original_state.to_variant(),
&original_state.to_variant(),
);

action_count.connect_activate(clone!(@weak label => move |action, parameter| {
Expand All @@ -48,7 +48,7 @@ impl Window {

// Increase state by parameter and save state
state += parameter;
action.set_state(state.to_variant());
action.set_state(&state.to_variant());

// Update label with new state
label.set_label(&format!("Counter: {state}"));
Expand All @@ -70,7 +70,7 @@ impl Window {
let action_orientation = SimpleAction::new_stateful(
"orientation",
Some(&String::static_variant_type()),
"Vertical".to_variant(),
&"Vertical".to_variant(),
);

action_orientation.connect_activate(clone!(@weak gtk_box =>
Expand All @@ -89,7 +89,7 @@ impl Window {

// Set orientation and save state
gtk_box.set_orientation(orientation);
action.set_state(parameter.to_variant());
action.set_state(&parameter.to_variant());
}));
self.add_action(&action_orientation);
//ANCHOR_END: action_orientation
Expand Down
4 changes: 2 additions & 2 deletions book/listings/actions/7/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Window {
let action_count = SimpleAction::new_stateful(
"count",
Some(&i32::static_variant_type()),
original_state.to_variant(),
&original_state.to_variant(),
);

action_count.connect_activate(clone!(@weak label => move |action, parameter| {
Expand All @@ -66,7 +66,7 @@ impl Window {

// Increase state by parameter and save state
state += parameter;
action.set_state(state.to_variant());
action.set_state(&state.to_variant());

// Update label with new state
label.set_label(&format!("Counter: {state}"));
Expand Down
6 changes: 2 additions & 4 deletions book/listings/css/1/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use gdk::Display;
use gtk::prelude::*;
use gtk::{
gdk, glib, Application, ApplicationWindow, Button, CssProvider, StyleContext,
};
use gtk::{gdk, glib, Application, ApplicationWindow, Button, CssProvider};

// ANCHOR: main
const APP_ID: &str = "org.gtk_rs.Css1";
Expand All @@ -25,7 +23,7 @@ fn load_css() {
provider.load_from_data(include_str!("style.css"));

// Add the provider to the default screen
StyleContext::add_provider_for_display(
gtk::style_context_add_provider_for_display(
&Display::default().expect("Could not connect to a display."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
Expand Down
6 changes: 2 additions & 4 deletions book/listings/css/2/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use gdk::Display;
use gtk::prelude::*;
use gtk::{
gdk, glib, Application, ApplicationWindow, Button, CssProvider, StyleContext,
};
use gtk::{gdk, glib, Application, ApplicationWindow, Button, CssProvider};

const APP_ID: &str = "org.gtk_rs.Css2";

Expand All @@ -24,7 +22,7 @@ fn load_css() {
provider.load_from_data(include_str!("style.css"));

// Add the provider to the default screen
StyleContext::add_provider_for_display(
gtk::style_context_add_provider_for_display(
&Display::default().expect("Could not connect to a display."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
Expand Down
6 changes: 2 additions & 4 deletions book/listings/css/3/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use gdk::Display;
use gtk::prelude::*;
use gtk::{
gdk, glib, Application, ApplicationWindow, Button, CssProvider, StyleContext,
};
use gtk::{gdk, glib, Application, ApplicationWindow, Button, CssProvider};

const APP_ID: &str = "org.gtk_rs.Css3";

Expand All @@ -24,7 +22,7 @@ fn load_css() {
provider.load_from_data(include_str!("style.css"));

// Add the provider to the default screen
StyleContext::add_provider_for_display(
gtk::style_context_add_provider_for_display(
&Display::default().expect("Could not connect to a display."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
Expand Down
6 changes: 2 additions & 4 deletions book/listings/css/4/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use gdk::Display;
use gtk::prelude::*;
use gtk::{
gdk, glib, Application, ApplicationWindow, Button, CssProvider, StyleContext,
};
use gtk::{gdk, glib, Application, ApplicationWindow, Button, CssProvider};

const APP_ID: &str = "org.gtk_rs.Css4";

Expand All @@ -24,7 +22,7 @@ fn load_css() {
provider.load_from_data(include_str!("style.css"));

// Add the provider to the default screen
StyleContext::add_provider_for_display(
gtk::style_context_add_provider_for_display(
&Display::default().expect("Could not connect to a display."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
Expand Down
4 changes: 2 additions & 2 deletions book/listings/css/7/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod window;

use gdk::Display;
use gtk::prelude::*;
use gtk::{gdk, glib, Application, CssProvider, StyleContext};
use gtk::{gdk, glib, Application, CssProvider};

use crate::window::Window;

Expand All @@ -26,7 +26,7 @@ fn load_css() {
provider.load_from_data(include_str!("style.css"));

// Add the provider to the default screen
StyleContext::add_provider_for_display(
gtk::style_context_add_provider_for_display(
&Display::default().expect("Could not connect to a display."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
Expand Down
4 changes: 2 additions & 2 deletions book/listings/css/8/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod window;

use gdk::Display;
use gtk::prelude::*;
use gtk::{gdk, glib, Application, CssProvider, StyleContext};
use gtk::{gdk, glib, Application, CssProvider};

use crate::window::Window;

Expand All @@ -26,7 +26,7 @@ fn load_css() {
provider.load_from_data(include_str!("style.css"));

// Add the provider to the default screen
StyleContext::add_provider_for_display(
gtk::style_context_add_provider_for_display(
&Display::default().expect("Could not connect to a display."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
Expand Down
4 changes: 2 additions & 2 deletions book/listings/css/9/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod window;

use gdk::Display;
use gtk::prelude::*;
use gtk::{gdk, glib, Application, CssProvider, StyleContext};
use gtk::{gdk, glib, Application, CssProvider};

use crate::window::Window;

Expand All @@ -26,7 +26,7 @@ fn load_css() {
provider.load_from_data(include_str!("style.css"));

// Add the provider to the default screen
StyleContext::add_provider_for_display(
gtk::style_context_add_provider_for_display(
&Display::default().expect("Could not connect to a display."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
Expand Down
2 changes: 1 addition & 1 deletion book/listings/list_widgets/2/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn build_ui(app: &Application) {
let vector: Vec<IntegerObject> = (0..=100_000).map(IntegerObject::new).collect();

// Create new model
let model = gio::ListStore::new(IntegerObject::static_type());
let model = gio::ListStore::new::<IntegerObject>();

// Add the vector to the model
model.extend_from_slice(&vector);
Expand Down
2 changes: 1 addition & 1 deletion book/listings/list_widgets/3/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn build_ui(app: &Application) {
let vector: Vec<IntegerObject> = (0..=100_000).map(IntegerObject::new).collect();

// Create new model
let model = gio::ListStore::new(IntegerObject::static_type());
let model = gio::ListStore::new::<IntegerObject>();

// Add the vector to the model
model.extend_from_slice(&vector);
Expand Down
2 changes: 1 addition & 1 deletion book/listings/list_widgets/4/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn build_ui(app: &Application) {
let vector: Vec<IntegerObject> = (0..=100_000).map(IntegerObject::new).collect();

// Create new model
let model = gio::ListStore::new(IntegerObject::static_type());
let model = gio::ListStore::new::<IntegerObject>();

// Add the vector to the model
model.extend_from_slice(&vector);
Expand Down
2 changes: 1 addition & 1 deletion book/listings/list_widgets/5/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn build_ui(app: &Application) {
let vector: Vec<IntegerObject> = (0..=100_000).map(IntegerObject::new).collect();

// Create new model
let model = gio::ListStore::new(IntegerObject::static_type());
let model = gio::ListStore::new::<IntegerObject>();

// Add the vector to the model
model.extend_from_slice(&vector);
Expand Down
6 changes: 3 additions & 3 deletions book/listings/main_event_loop/3/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::thread;
use std::time::Duration;

use glib::{clone, Continue, MainContext, Priority};
use glib::{clone, MainContext, Priority};
use gtk::prelude::*;
use gtk::{glib, Application, ApplicationWindow, Button};

Expand Down Expand Up @@ -47,10 +47,10 @@ fn build_ui(app: &Application) {
// The main loop executes the closure as soon as it receives the message
receiver.attach(
None,
clone!(@weak button => @default-return Continue(false),
clone!(@weak button => @default-return glib::ControlFlow::Break,
move |enable_button| {
button.set_sensitive(enable_button);
Continue(true)
glib::ControlFlow::Continue
}
),
);
Expand Down
6 changes: 3 additions & 3 deletions book/listings/main_event_loop/4/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use glib::{clone, timeout_future_seconds, Continue, MainContext, Priority};
use glib::{clone, timeout_future_seconds, MainContext, Priority};
use gtk::prelude::*;
use gtk::{glib, Application, ApplicationWindow, Button};

Expand Down Expand Up @@ -43,10 +43,10 @@ fn build_ui(app: &Application) {
// The main loop executes the closure as soon as it receives the message
receiver.attach(
None,
clone!(@weak button => @default-return Continue(false),
clone!(@weak button => @default-return glib::ControlFlow::Break,
move |enable_button| {
button.set_sensitive(enable_button);
Continue(true)
glib::ControlFlow::Continue
}
),
);
Expand Down
6 changes: 2 additions & 4 deletions book/listings/saving_window_state/1/custom_window/imp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use gio::Settings;
use glib::signal::Inhibit;
use gtk::subclass::prelude::*;
use gtk::{gio, glib, ApplicationWindow};
use once_cell::sync::OnceCell;
Expand Down Expand Up @@ -28,14 +27,13 @@ impl ObjectImpl for Window {
impl WidgetImpl for Window {}
impl WindowImpl for Window {
// Save window state right before the window will be closed
fn close_request(&self) -> Inhibit {
fn close_request(&self) -> glib::ControlFlow {
// Save window size
self.obj()
.save_window_size()
.expect("Failed to save window state");

// Don't inhibit the default handler
Inhibit(false)
glib::ControlFlow::Continue
}
}
impl ApplicationWindowImpl for Window {}
Expand Down
3 changes: 1 addition & 2 deletions book/listings/settings/1/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use gio::Settings;
use gtk::glib::signal::Inhibit;
use gtk::prelude::*;
use gtk::{gio, glib, Align, Application, ApplicationWindow, Switch};

Expand Down Expand Up @@ -47,7 +46,7 @@ fn build_ui(app: &Application) {
.set_boolean("is-switch-enabled", is_enabled)
.expect("Could not set setting.");
// Don't inhibit the default handler
Inhibit(false)
glib::ControlFlow::Continue
});
// ANCHOR_END: connect_state_set

Expand Down
2 changes: 1 addition & 1 deletion book/listings/todo/1/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Window {

fn setup_tasks(&self) {
// Create new model
let model = gio::ListStore::new(TaskObject::static_type());
let model = gio::ListStore::new::<TaskObject>();

// Get state and set model
self.imp().tasks.replace(Some(model));
Expand Down
3 changes: 1 addition & 2 deletions book/listings/todo/2/window/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::cell::RefCell;
use std::fs::File;

use gio::Settings;
use glib::signal::Inhibit;
use glib::subclass::InitializingObject;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
Expand Down Expand Up @@ -68,7 +67,7 @@ impl WidgetImpl for Window {}
// ANCHOR: window_impl
// Trait shared by all windows
impl WindowImpl for Window {
fn close_request(&self) -> Inhibit {
fn close_request(&self) -> glib::ControlFlow {
// Store task data in vector
let backup_data: Vec<TaskData> = self
.obj()
Expand Down
2 changes: 1 addition & 1 deletion book/listings/todo/2/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Window {
// ANCHOR: setup_tasks
fn setup_tasks(&self) {
// Create new model
let model = gio::ListStore::new(TaskObject::static_type());
let model = gio::ListStore::new::<TaskObject>();

// Get state and set model
self.imp().tasks.replace(Some(model));
Expand Down
Loading