pub struct CheckBox {
pub handle: ControlHandle,
/* private fields */
}Expand description
A check box consists of a square box and an application-defined labe that indicates a choice the user can make by selecting the button. Applications typically display check boxes to enable the user to choose one or more options that are not mutually exclusive.
CheckBox is not behind any features.
Builder parameters:
parent: Required. The checkbox parent container.text: The checkbox text.size: The checkbox size.position: The checkbox position.enabled: If the checkbox can be used by the user. It also has a grayed out look if disabled.flags: A combination of the CheckBoxFlags values.ex_flags: A combination of win32 window extended flags. Unlikeflags, ex_flags must be used straight from winapifont: The font used for the checkbox textbackground_color: The background color of the checkbox. Defaults to the default window background (light gray)check_state: The default check statefocus: The control receive focus after being created
Control events:
OnButtonClick: When the checkbox is clicked once by the userOnButtonDoubleClick: When the checkbox is clicked twice rapidly by the userMousePress(_): Generic mouse press events on the checkboxOnMouseMove: Generic mouse mouse eventOnMouseWheel: Generic mouse wheel event
use native_windows_gui2 as nwg;
fn build_checkbox(button: &mut nwg::CheckBox, window: &nwg::Window, font: &nwg::Font) {
nwg::CheckBox::builder()
.text("Hello")
.flags(nwg::CheckBoxFlags::VISIBLE)
.font(Some(font))
.parent(window)
.build(button);
}Fields§
§handle: ControlHandleImplementations§
Source§impl CheckBox
impl CheckBox
Sourcepub fn builder<'a>() -> CheckBoxBuilder<'a>
pub fn builder<'a>() -> CheckBoxBuilder<'a>
Examples found in repository?
357 fn build_partial<W: Into<ControlHandle>>(
358 data: &mut AnimalUi,
359 parent: Option<W>,
360 ) -> Result<(), NwgError> {
361 let parent = parent.unwrap().into();
362
363 nwg::Label::builder()
364 .text("Name:")
365 .h_align(nwg::HTextAlign::Right)
366 .parent(&parent)
367 .build(&mut data.label1)?;
368
369 nwg::Label::builder()
370 .text("Race:")
371 .h_align(nwg::HTextAlign::Right)
372 .parent(&parent)
373 .build(&mut data.label2)?;
374
375 nwg::Label::builder()
376 .text("Is fluffy:")
377 .h_align(nwg::HTextAlign::Right)
378 .parent(&parent)
379 .build(&mut data.label3)?;
380
381 nwg::TextInput::builder()
382 .text("Mittens")
383 .parent(&parent)
384 .build(&mut data.name_input)?;
385
386 nwg::ComboBox::builder()
387 .collection(vec!["Cat", "Dog", "Pidgeon", "Monkey"])
388 .selected_index(Some(0))
389 .parent(&parent)
390 .build(&mut data.race_input)?;
391
392 nwg::CheckBox::builder()
393 .text("")
394 .check_state(nwg::CheckBoxState::Checked)
395 .parent(&parent)
396 .build(&mut data.is_soft_input)?;
397
398 nwg::Button::builder()
399 .text("Save")
400 .parent(&parent)
401 .build(&mut data.save_btn)?;
402
403 nwg::GridLayout::builder()
404 .parent(&parent)
405 .max_size([1000, 150])
406 .min_size([100, 120])
407 .child(0, 0, &data.label1)
408 .child(0, 1, &data.label2)
409 .child(0, 2, &data.label3)
410 .child(1, 0, &data.name_input)
411 .child(1, 1, &data.race_input)
412 .child(1, 2, &data.is_soft_input)
413 .build(&data.layout)?;
414
415 nwg::GridLayout::builder()
416 .min_size([100, 200])
417 .max_column(Some(2))
418 .max_row(Some(6))
419 .child(1, 5, &data.save_btn)
420 .parent(&parent)
421 .build(&data.layout2)?;
422
423 Ok(())
424 }
425
426 fn process_event<'a>(
427 &self,
428 _evt: nwg::Event,
429 _evt_data: &nwg::EventData,
430 _handle: ControlHandle,
431 ) {
432 }
433
434 fn handles(&self) -> Vec<&ControlHandle> {
435 Vec::new()
436 }
437 }
438}
439
440mod partial_food_ui {
441 use self::nwg::{ControlHandle, NwgError, PartialUi};
442 use super::*;
443 use native_windows_gui2 as nwg;
444
445 impl PartialUi for FoodUi {
446 fn build_partial<W: Into<ControlHandle>>(
447 data: &mut FoodUi,
448 parent: Option<W>,
449 ) -> Result<(), NwgError> {
450 let parent = parent.unwrap().into();
451
452 nwg::Label::builder()
453 .text("Name:")
454 .h_align(nwg::HTextAlign::Right)
455 .parent(&parent)
456 .build(&mut data.label1)?;
457
458 nwg::Label::builder()
459 .text("Tasty:")
460 .h_align(nwg::HTextAlign::Right)
461 .parent(&parent)
462 .build(&mut data.label2)?;
463
464 nwg::TextInput::builder()
465 .text("Banana")
466 .parent(&parent)
467 .build(&mut data.name_input)?;
468
469 nwg::CheckBox::builder()
470 .text("")
471 .check_state(nwg::CheckBoxState::Checked)
472 .parent(&parent)
473 .build(&mut data.tasty_input)?;
474
475 nwg::Button::builder()
476 .text("Save")
477 .parent(&parent)
478 .build(&mut data.save_btn)?;
479
480 nwg::GridLayout::builder()
481 .parent(&parent)
482 .max_size([1000, 90])
483 .min_size([100, 80])
484 .child(0, 0, &data.label1)
485 .child(0, 1, &data.label2)
486 .child(1, 0, &data.name_input)
487 .child(1, 1, &data.tasty_input)
488 .build(&data.layout)?;
489
490 nwg::GridLayout::builder()
491 .min_size([100, 200])
492 .max_column(Some(2))
493 .max_row(Some(6))
494 .child(1, 5, &data.save_btn)
495 .parent(&parent)
496 .build(&data.layout2)?;
497
498 Ok(())
499 }Sourcepub fn tristate(&self) -> bool
pub fn tristate(&self) -> bool
Return true if the checkbox can have a third state or false otherwise
Sourcepub fn set_tristate(&self, tri: bool)
pub fn set_tristate(&self, tri: bool)
Sets or unsets the checkbox as tristate
Sourcepub fn check_state(&self) -> CheckBoxState
pub fn check_state(&self) -> CheckBoxState
Return the check state of the check box
Sourcepub fn set_check_state(&self, state: CheckBoxState)
pub fn set_check_state(&self, state: CheckBoxState)
Sets the check state of the check box
Sourcepub fn enabled(&self) -> bool
pub fn enabled(&self) -> bool
Return true if the control user can interact with the control, return false otherwise
Sourcepub fn set_enabled(&self, v: bool)
pub fn set_enabled(&self, v: bool)
Enable or disable the control
Sourcepub fn visible(&self) -> bool
pub fn visible(&self) -> bool
Return true if the control is visible to the user. Will return true even if the control is outside of the parent client view (ex: at the position (10000, 10000))
Sourcepub fn set_visible(&self, v: bool)
pub fn set_visible(&self, v: bool)
Show or hide the control to the user
Sourcepub fn set_position(&self, x: i32, y: i32)
pub fn set_position(&self, x: i32, y: i32)
Set the position of the check box in the parent window
Sourcepub fn class_name(&self) -> &'static str
pub fn class_name(&self) -> &'static str
Winapi class name used during control creation
Sourcepub fn forced_flags(&self) -> u32
pub fn forced_flags(&self) -> u32
Winapi flags required by the control