pub struct ColorPicker<'a> {
pub title: &'a str,
pub value: ColorValue,
pub owner: Option<&'a dyn HasWindowHandle>,
}Expand description
Color picker dialog.
The color picker dialog allows the user to select a color, which is returned as an RGB value. The dialog may also show a palette of predefined colors for the user to choose from.
let color = rustydialogs::ColorPicker {
title: "Pick a Color",
value: rustydialogs::ColorValue {
red: 64,
green: 128,
blue: 255,
},
owner: None,
}.show();
if let Some(color) = color {
println!("RGB({}, {}, {})", color.red, color.green, color.blue);
}Fields§
§title: &'a strThe title of the dialog.
value: ColorValueThe initial color value to show in the color picker dialog.
owner: Option<&'a dyn HasWindowHandle>The owner window of the dialog.
Implementations§
Source§impl<'a> ColorPicker<'a>
impl<'a> ColorPicker<'a>
Sourcepub fn show(&self) -> Option<ColorValue>
pub fn show(&self) -> Option<ColorValue>
Show the dialog.
Returns Some(ColorValue) if the user selected a color and confirmed the dialog, or None if the user cancelled the dialog.
Examples found in repository?
examples/color_picker.rs (line 12)
1fn main() {
2 let picker = rustydialogs::ColorPicker {
3 title: "Pick a color",
4 value: rustydialogs::ColorValue {
5 red: 0xFF,
6 green: 0x00,
7 blue: 0x77,
8 },
9 owner: None,
10 };
11
12 match picker.show() {
13 Some(color) => println!(
14 "Selected color: #{:02X}{:02X}{:02X}",
15 color.red, color.green, color.blue
16 ),
17 None => println!("Color selection canceled"),
18 }
19}More examples
examples/tests.rs (line 293)
284fn test_color_picker() {
285 println!("\n{}", Color("==== Testing ColorPicker ====", "120;190;255"));
286
287 step("Select pure RED (#FF0000) and press OK.",
288 Some(rustydialogs::ColorValue { red: 255, green: 0, blue: 0 }),
289 || rustydialogs::ColorPicker {
290 title: "[tests] ColorPicker",
291 value: rustydialogs::ColorValue { red: 255, green: 0, blue: 0 },
292 owner: None,
293 }.show()
294 );
295
296 step("Select specific color (#4FB3A3) (79, 179, 163) and press OK.",
297 Some(rustydialogs::ColorValue { red: 79, green: 179, blue: 163 }),
298 || rustydialogs::ColorPicker {
299 title: "[tests] ColorPicker",
300 value: rustydialogs::ColorValue { red: 255, green: 0, blue: 0 },
301 owner: None,
302 }.show()
303 );
304
305 step("Dismiss the dialog.",
306 None,
307 || rustydialogs::ColorPicker {
308 title: "[tests] Dismiss ColorPicker",
309 value: rustydialogs::ColorValue { red: 255, green: 0, blue: 0 },
310 owner: None,
311 }.show()
312 );
313}Trait Implementations§
Source§impl<'a> Clone for ColorPicker<'a>
impl<'a> Clone for ColorPicker<'a>
Source§fn clone(&self) -> ColorPicker<'a>
fn clone(&self) -> ColorPicker<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<'a> Copy for ColorPicker<'a>
Auto Trait Implementations§
impl<'a> Freeze for ColorPicker<'a>
impl<'a> !RefUnwindSafe for ColorPicker<'a>
impl<'a> !Send for ColorPicker<'a>
impl<'a> !Sync for ColorPicker<'a>
impl<'a> Unpin for ColorPicker<'a>
impl<'a> UnsafeUnpin for ColorPicker<'a>
impl<'a> !UnwindSafe for ColorPicker<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more