-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
examples: Add an example for scale functionality. #535
Conversation
@@ -0,0 +1,108 @@ | |||
use gtk::prelude::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run cargo fmt on your code.
examples/scale/main.rs
Outdated
horizontal_scale.connect_local( | ||
"value-changed", | ||
false, | ||
move |args| { | ||
let slider = args[0] | ||
.get::<Scale>() | ||
.expect("The value needs to be of type `Scale`."); | ||
|
||
println!("Horizontal scale value: {:?}", slider.value()); | ||
None | ||
}) | ||
.expect("Could not connect to signal."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
horizontal_scale.connect_local( | |
"value-changed", | |
false, | |
move |args| { | |
let slider = args[0] | |
.get::<Scale>() | |
.expect("The value needs to be of type `Scale`."); | |
println!("Horizontal scale value: {:?}", slider.value()); | |
None | |
}) | |
.expect("Could not connect to signal."); | |
horizontal_scale. connect_value_changed(move |slider { | |
println!("Horizontal scale value: {:?}", slider.value()); | |
}); |
why not just?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe display those values on a label?
examples/scale/main.rs
Outdated
vertical_scale.connect_local( | ||
"value-changed", | ||
false, | ||
move |args| { | ||
let slider = args[0] | ||
.get::<Scale>() | ||
.expect("The value needs to be of type `Scale`."); | ||
|
||
println!("Vertical scale value: {:?}", slider.value()); | ||
None | ||
}) | ||
.expect("Could not connect to signal."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vertical_scale.connect_local( | |
"value-changed", | |
false, | |
move |args| { | |
let slider = args[0] | |
.get::<Scale>() | |
.expect("The value needs to be of type `Scale`."); | |
println!("Vertical scale value: {:?}", slider.value()); | |
None | |
}) | |
.expect("Could not connect to signal."); | |
vertical_scale.connect_local( | |
"value-changed", | |
false, | |
move |args| { | |
let slider = args[0] | |
.get::<Scale>() | |
.expect("The value needs to be of type `Scale`."); | |
println!("Vertical scale value: {:?}", slider.value()); | |
None | |
}) | |
.expect("Could not connect to signal."); |
Same as the horizontal scale
examples/scale/main.rs
Outdated
|
||
fn main() { | ||
let application = Application::new( | ||
Some("com.github.gtk-rs.examples.builder_pattern"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some("com.github.gtk-rs.examples.builder_pattern"), | |
Some("com.github.gtk-rs.examples.scale"), |
examples/scale/main.rs
Outdated
use gtk::{ Adjustment, | ||
Application, | ||
ApplicationWindow, | ||
Grid, | ||
Label, | ||
Orientation, | ||
Scale | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely don't like importing everything here. In general, I would do that unless the type/function/macro is used more than once.
examples/scale/README.md
Outdated
@@ -0,0 +1,5 @@ | |||
# Basics | |||
|
|||
This example demonstrates how to create `scales` and place them in the `window` using a grid. It also shows how to implement `callbacks`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example demonstrates how to create `scales` and place them in the `window` using a grid. It also shows how to implement `callbacks`. | |
This example demonstrates how to create `gtk::Scale` and place them in the `gtk::Window` using a grid. |
Something like this?
examples/scale/README.md
Outdated
@@ -0,0 +1,5 @@ | |||
# Basics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Basics | |
# Scale |
maybe?
This also needs to be added to the main readme inside the examples directory
Thanks for the example! overall looks good to me. Do you mind taking the screenshot using the default GTK theme like the other examples? |
Thank you for taking time and review the PR. I have tried to implement all the suggestions except the screenshot. The only computer I have access to is a Pop Os! and I could not change it to the theme to match the ones in the other examples (the default GTK theme). :( Please let me know if this is okay. Thank you! |
You can change the theme in the settings i believe and switch back once you took the screenshot. Sorry for the long delay, i forgot you actually replied. |
Rebased and fixed on #1569, thanks |
Added a simple example for scale functionality.
Tested on Linux (Pop!_OS 21.04).