I would like to add characters to an input field using Rust gtk4. I've created the entry field as such (please assume I have a main function that runs the app and I another function that creates the UI):
let input = Entry::builder()
.placeholder_text("Enter input")
.build();
And a button for the character '1'
:
let one_button = Button::builder()
.label("1")
.margin_top(12)
.margin_start(12)
.margin_end(12)
.build();
I want for when I clicked the button one_button
I get the character '1'
on the entry field. To do this I thought to create an empty string and pass it in when the button is clicked where I would push the character '1'
into it. As such,
let entry = String::new();
one_button.connect_clicked(clone!(@strong entry =>
move |_| {
entry.push_str("1");
input.set_text(&entry);
}
));
but I get the following error:
cannot borrow `entry` as mutable, as it is not declared as mutable
Is there a better way to do this?