Hi all,
I’m very new to gtk4 and trying to get a bit more experience by making a simple application that copies text to the clipboard upon clicking a button. However, I’m already running into trouble creating a clipboard object:
use gtk4::gdk::Clipboard;
use gtk4::prelude::*;
use gtk4::{Application, ApplicationWindow, Button};
const APP_ID: &str = "org.testing.Glower";
fn main() {
// Create a new application
let app = Application::builder().application_id(APP_ID).build();
// Connect to the "activate" signal of 'app'
app.connect_activate(build_ui);
// Run the application
app.run();
}
fn build_ui(app: &Application) {
let cb: Clipboard = DisplayExt::clipboard(&self);
// Create a button with label and margins
let button = Button::builder()
.label("😀")
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.build();
// Connect to "clicked" signal of `button`
button.connect_clicked(move |button| {
// Set the label to "Hello World!" after the button has been clicked on
button.set_label("Hello World");
});
// Create a window and set the title
let window = ApplicationWindow::builder()
.application(app)
.title("Glower")
.child(&button)
.build();
// Present window
window.present();
}
Here’s what the compiler is telling me. I feel like I’m missing something obvious but I haven’t been able to figure out where I’m going wrong.
error[E0424]: expected value, found module `self`
--> src/main.rs:19:34
|
17 | fn build_ui(app: &Application) {
| -------- this function can't have a `self` parameter
18 |
19 | let cb = DisplayExt::clipboard(&self);
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter