Return the bool for pressed from the underlying functions and added

comments documenting example use.
This commit is contained in:
Nick Palmer 2017-09-02 19:59:14 +01:00
parent 5dd0079880
commit 206056fc9f
No known key found for this signature in database
GPG Key ID: E4E523DDAAA2B0D4

View File

@ -716,17 +716,47 @@ impl<'ui> Ui<'ui> {
// Widgets: Radio
impl<'ui> Ui<'ui> {
/// Creates a radio button for selecting an integer value.
/// Returns true if pressed.
///
/// # Example
/// ```rust,no_run
/// # use imgui::*;
/// # let mut imgui = ImGui::init();
/// # let ui = imgui.frame((0, 0), (0, 0), 0.1);
/// # let selected_radio_value = 2;
/// ui.radio_button(im_str!("Item 1"), &mut selected_radio_value, 1);
/// ui.radio_button(im_str!("Item 2"), &mut selected_radio_value, 2);
/// ui.radio_button(im_str!("Item 3"), &mut selected_radio_value, 3);
/// ```
pub fn radio_button<'p>(&self,
label: &'p ImStr,
value: &'p mut i32,
wanted: i32) {
wanted: i32) -> bool {
unsafe {
imgui_sys::igRadioButton(label.as_ptr(), value, wanted);
return imgui_sys::igRadioButton(label.as_ptr(), value, wanted);
}
}
pub fn radio_button_bool<'p>(&self, label: &'p ImStr, value: bool) {
/// Creates a radio button that shows as selected if the given value is true.
/// Returns true if pressed.
///
/// # Example
/// ```rust,no_run
/// # use imgui::*;
/// # let mut imgui = ImGui::init();
/// # let ui = imgui.frame((0, 0), (0, 0), 0.1);
/// # let selected_radio_value = "cats".to_string();
/// if ui.radio_button_bool(im_str!("Cats"), state.radio_button_test == "cats") {
/// state.radio_button_test = "cats".to_string();
/// }
/// if ui.radio_button_bool(im_str!("Dogs"), state.radio_button_test == "dogs") {
/// state.radio_button_test = "dogs".to_string();
/// }
/// ```
pub fn radio_button_bool<'p>(&self, label: &'p ImStr, value: bool) -> bool {
unsafe {
imgui_sys::igRadioButtonBool(label.as_ptr(), value);
return imgui_sys::igRadioButtonBool(label.as_ptr(), value);
}
}
}