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

Remove unused callback from GUI exercise #1293

Merged
merged 7 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 5 additions & 4 deletions src/exercises/day-3/simple-gui.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# A Simple GUI Library
# Drawing A Simple GUI

Let us design a classical GUI library using our new knowledge of traits and
trait objects.
trait objects. We'll only implement the drawing of it (as text) for simplicity.

We will have a number of widgets in our library:

* `Window`: has a `title` and contains other widgets.
* `Button`: has a `label` and a callback function which is invoked when the
button is pressed.
* `Button`: has a `label`. In reality, it would also take a callback
to allow the called to do something when the button is clicked
mgeisler marked this conversation as resolved.
Show resolved Hide resolved
but we won't include that since we're only drawing the GUI.
* `Label`: has a `label`.

The widgets will implement a `Widget` trait, see below.
Expand Down
7 changes: 2 additions & 5 deletions src/exercises/day-3/simple-gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ impl Label {

pub struct Button {
label: Label,
callback: Box<dyn FnMut()>,
}

impl Button {
fn new(label: &str, callback: Box<dyn FnMut()>) -> Button {
fn new(label: &str) -> Button {
Button {
label: Label::new(label),
callback,
}
}
}
Expand Down Expand Up @@ -158,8 +156,7 @@ fn main() {
let mut window = Window::new("Rust GUI Demo 1.23");
window.add_widget(Box::new(Label::new("This is a small text GUI demo.")));
window.add_widget(Box::new(Button::new(
"Click me!",
Box::new(|| println!("You clicked the button!")),
"Click me!"
)));
window.draw();
}
Expand Down
2 changes: 1 addition & 1 deletion src/exercises/day-3/solutions-morning.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Day 3 Morning Exercise

## A Simple GUI Library
## Drawing A Simple GUI

([back to exercise](simple-gui.md))

Expand Down