Switch argument order of `ui.checkbox` and `ui.radio`

`bool, text` is the more logical order, as it

* matches the visuals: `[x] text`
* puts the important part first
* more natually allows us to extend to checkboxes without a text
This commit is contained in:
Emil Ernerfeldt 2020-10-10 12:49:02 +02:00
parent a2e8d1d32c
commit 5c469551df
7 changed files with 26 additions and 27 deletions

View File

@ -7,6 +7,7 @@
* Simple drop-down combo box menu * Simple drop-down combo box menu
* Logarithmic sliders * Logarithmic sliders
* Optimization: coarse culling in the tesselator * Optimization: coarse culling in the tesselator
* CHANGED: switch argument order of `ui.checkbox` and `ui.radio`
## 0.1.4 - 2020-09-08 ## 0.1.4 - 2020-09-08

View File

@ -356,8 +356,8 @@ impl DemoApp {
ui.separator(); ui.separator();
ui.checkbox( ui.checkbox(
"Show color blend test (debug backend painter)",
&mut self.show_color_test, &mut self.show_color_test,
"Show color blend test (debug backend painter)",
); );
} }
@ -365,9 +365,9 @@ impl DemoApp {
ui.horizontal(|ui| { ui.horizontal(|ui| {
let run_mode = &mut self.run_mode; let run_mode = &mut self.run_mode;
ui.label("Run mode:"); ui.label("Run mode:");
ui.radio_value("Continuous", run_mode, RunMode::Continuous) ui.radio_value(run_mode, RunMode::Continuous, "Continuous")
.on_hover_text("Repaint everything each frame"); .on_hover_text("Repaint everything each frame");
ui.radio_value("Reactive", run_mode, RunMode::Reactive) ui.radio_value(run_mode, RunMode::Reactive, "Reactive")
.on_hover_text("Repaint when there are animations or input (e.g. mouse movement)"); .on_hover_text("Repaint when there are animations or input (e.g. mouse movement)");
}); });
} }

View File

@ -31,9 +31,9 @@ impl ColorTest {
ui.label("It is meant to ensure you do proper sRGBA decoding of both texture and vertex colors, and blend using premultiplied alpha."); ui.label("It is meant to ensure you do proper sRGBA decoding of both texture and vertex colors, and blend using premultiplied alpha.");
ui.label("If everything is set up correctly, all groups of gradients will look uniform"); ui.label("If everything is set up correctly, all groups of gradients will look uniform");
ui.checkbox("Vertex gradients", &mut self.vertex_gradients); ui.checkbox(&mut self.vertex_gradients, "Vertex gradients");
ui.checkbox("Texture gradients", &mut self.texture_gradients); ui.checkbox(&mut self.texture_gradients, "Texture gradients");
ui.checkbox("Show naive sRGBA horror", &mut self.srgb); ui.checkbox(&mut self.srgb, "Show naive sRGBA horror");
ui.heading("sRGB color test"); ui.heading("sRGB color test");
ui.label("Use a color picker to ensure this color is (255, 165, 0) / #ffa500"); ui.label("Use a color picker to ensure this color is (255, 165, 0) / #ffa500");

View File

@ -93,16 +93,16 @@ impl Sliders {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("Slider type:"); ui.label("Slider type:");
ui.radio_value("i32", integer, true); ui.radio_value(integer, true, "i32");
ui.radio_value("f64", integer, false); ui.radio_value(integer, false, "f64");
}); });
ui.label("(f32, usize etc are also possible)"); ui.label("(f32, usize etc are also possible)");
ui.checkbox("Logarithmic", logarithmic); ui.checkbox(logarithmic, "Logarithmic");
ui.label("Logarithmic sliders are great for when you want to span a huge range, i.e. from zero to a million."); ui.label("Logarithmic sliders are great for when you want to span a huge range, i.e. from zero to a million.");
ui.label("Logarithmic sliders can include infinity and zero."); ui.label("Logarithmic sliders can include infinity and zero.");
ui.checkbox("Smart Aim", smart_aim); ui.checkbox(smart_aim, "Smart Aim");
ui.label("Smart Aim will guide you towards round values when you drag the slider so you you are more likely to hit 250 than 247.23"); ui.label("Smart Aim will guide you towards round values when you drag the slider so you you are more likely to hit 250 than 247.23");
if ui.button("Reset slider demo").clicked { if ui.button("Reset slider demo").clicked {

View File

@ -71,15 +71,15 @@ impl Widgets {
.on_hover_text("The current font supports only a few non-latin characters and Egui does not currently support right-to-left text."); .on_hover_text("The current font supports only a few non-latin characters and Egui does not currently support right-to-left text.");
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.radio_value("First", &mut self.radio, Enum::First); ui.radio_value(&mut self.radio, Enum::First, "First");
ui.radio_value("Second", &mut self.radio, Enum::Second); ui.radio_value(&mut self.radio, Enum::Second, "Second");
ui.radio_value("Third", &mut self.radio, Enum::Third); ui.radio_value(&mut self.radio, Enum::Third, "Third");
}); });
combo_box_with_label(ui, "Combo Box", format!("{:?}", self.radio), |ui| { combo_box_with_label(ui, "Combo Box", format!("{:?}", self.radio), |ui| {
ui.radio_value("First", &mut self.radio, Enum::First); ui.radio_value(&mut self.radio, Enum::First, "First");
ui.radio_value("Second", &mut self.radio, Enum::Second); ui.radio_value(&mut self.radio, Enum::Second, "Second");
ui.radio_value("Third", &mut self.radio, Enum::Third); ui.radio_value(&mut self.radio, Enum::Third, "Third");
}); });
ui.add(Checkbox::new(&mut self.button_enabled, "Button enabled")); ui.add(Checkbox::new(&mut self.button_enabled, "Button enabled"));

View File

@ -305,7 +305,7 @@ impl Style {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("Default text style:"); ui.label("Default text style:");
for &value in &[TextStyle::Body, TextStyle::Monospace] { for &value in &[TextStyle::Body, TextStyle::Monospace] {
ui.radio_value(format!("{:?}", value), body_text_style, value); ui.radio_value(body_text_style, value, format!("{:?}", value));
} }
}); });
ui.collapsing("Spacing", |ui| spacing.ui(ui)); ui.collapsing("Spacing", |ui| spacing.ui(ui));

View File

@ -503,37 +503,35 @@ impl Ui {
self.add(Hyperlink::new(url)) self.add(Hyperlink::new(url))
} }
pub fn text_edit(&mut self, text: &mut String) -> Response {
self.add(TextEdit::new(text))
}
/// Shortcut for `add(Button::new(text))` /// Shortcut for `add(Button::new(text))`
#[must_use = "You should check if the user clicked this with `if ui.button(...).clicked { ... } "] #[must_use = "You should check if the user clicked this with `if ui.button(...).clicked { ... } "]
pub fn button(&mut self, text: impl Into<String>) -> Response { pub fn button(&mut self, text: impl Into<String>) -> Response {
self.add(Button::new(text)) self.add(Button::new(text))
} }
// Argument order matching that of Dear ImGui
/// Show a checkbox. /// Show a checkbox.
pub fn checkbox(&mut self, text: impl Into<String>, checked: &mut bool) -> Response { pub fn checkbox(&mut self, checked: &mut bool, text: impl Into<String>) -> Response {
self.add(Checkbox::new(checked, text)) self.add(Checkbox::new(checked, text))
} }
// Argument order matching that of Dear ImGui
/// Show a radio button. /// Show a radio button.
pub fn radio(&mut self, text: impl Into<String>, checked: bool) -> Response { pub fn radio(&mut self, checked: bool, text: impl Into<String>) -> Response {
self.add(RadioButton::new(checked, text)) self.add(RadioButton::new(checked, text))
} }
pub fn text_edit(&mut self, text: &mut String) -> Response {
self.add(TextEdit::new(text))
}
/// Show a radio button. It is selected if `*current_value == radio_value`. /// Show a radio button. It is selected if `*current_value == radio_value`.
/// If clicked, `radio_value` is assigned to `*current_value`; /// If clicked, `radio_value` is assigned to `*current_value`;
pub fn radio_value<Value: PartialEq>( pub fn radio_value<Value: PartialEq>(
&mut self, &mut self,
text: impl Into<String>,
current_value: &mut Value, current_value: &mut Value,
radio_value: Value, radio_value: Value,
text: impl Into<String>,
) -> Response { ) -> Response {
let response = self.radio(text, *current_value == radio_value); let response = self.radio(*current_value == radio_value, text);
if response.clicked { if response.clicked {
*current_value = radio_value; *current_value = radio_value;
} }