From de69a0c103759d380bccca4557b5a2071f1e16ab Mon Sep 17 00:00:00 2001 From: Jack Mac Date: Wed, 6 Oct 2021 13:09:34 -0400 Subject: [PATCH] deprecated `InputInt` and `InputFloat`, switched to using `InputScalar` --- CHANGELOG.markdown | 6 ++++++ imgui-examples/examples/test_window_impl.rs | 8 ++++---- imgui/src/input_widget.rs | 20 ++++++++++++++++---- imgui/src/lib.rs | 8 ++++---- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 8177b1b..925861c 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -16,6 +16,12 @@ - BREAKING: We now only support `glium 0.30`. We're in a difficult position supporting arbitrary `glium` versions in our renderer, since `glium` is only in a semi-maintained state. `glium` users, please get in contact in issues to let us know what will work best for your needs! +- Added `InputScalar` and `InputScalarN`. These are the core Input modules that Dear ImGui uses, and ultimately what `InputFloat` and `InputInt` turn into. See deprecation of `InputFloat` and `InputInt` as a result. Thank you to @EmbersArc for [implementing this here](https://github.com/imgui-rs/imgui-rs/pull/544). + +- BREAKING: `ui.input_int` and `ui.input_float` now return `InputScalar<'ui, 'l, f32/i32>`, instead of `InputFloat`/`InputInt`. This struct has all of the same flags as `InputFloat` and `InputInt` did. + +- DEPRECATED: `InputFloat` and `InputInt` have been deprecated. `ui.input_float` and `ui.input_int` are _not_, however, and instead will just call `input_scalar` as appropriate. Therefore, please switch your code to `ui.input_float` or `ui.input_int`. + ## [0.8.0] - 2021-09-17 Welcome to the `0.8.0` update. This is one of the largest updates imgui-rs has ever seen; it will generate errors in a `0.7` project, but hopefully it should be both quick to fix, and enjoyable to update. See our [release page](https://github.com/imgui-rs/imgui-rs/releases/tag/v0.8.0) for more information and a list of contributors to this cycle. Thank you to everyone who uses `imgui-rs`, files issues, and spend their time and effort to PR new changes into the codebase. Because of all that effort, this is by far the best `imgui-rs` has looked! diff --git a/imgui-examples/examples/test_window_impl.rs b/imgui-examples/examples/test_window_impl.rs index 2ba4daf..f58c100 100644 --- a/imgui-examples/examples/test_window_impl.rs +++ b/imgui-examples/examples/test_window_impl.rs @@ -551,10 +551,10 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { ColorEdit3::new("color 1", &mut state.col1).build(ui); ColorEdit4::new("color 2", &mut state.col2).build(ui); - ui.input_scalar("input scalar i64", &mut state.u0).build(ui); - ui.input_scalar("input scalar f64", &mut state.d0).build(ui); - ui.input_scalar_n("input scalar int array", &mut state.vec3i).build(ui); - ui.input_scalar_n("input scalar float array", &mut state.vec3f).build(ui); + ui.input_scalar("input scalar i64", &mut state.u0).build(); + ui.input_scalar("input scalar f64", &mut state.d0).build(); + ui.input_scalar_n("input scalar int array", &mut state.vec3i).build(); + ui.input_scalar_n("input scalar float array", &mut state.vec3f).build(); TreeNode::new("Multi-component Widgets").build(ui, || { ui.input_float2("input float2", &mut state.vec2f) diff --git a/imgui/src/input_widget.rs b/imgui/src/input_widget.rs index a2e329d..5b4af13 100644 --- a/imgui/src/input_widget.rs +++ b/imgui/src/input_widget.rs @@ -488,6 +488,10 @@ pub struct InputInt<'ui, 'p, L> { } impl<'ui, 'p, L: AsRef> InputInt<'ui, 'p, L> { + #[deprecated( + since = "0.9.0", + note = "use `ui.input_int` or `ui.input_scalar` instead" + )] pub fn new(ui: &'ui Ui, label: L, value: &'p mut i32) -> Self { InputInt { label, @@ -527,6 +531,10 @@ pub struct InputFloat<'ui, 'p, L, F = &'static str> { } impl<'ui, 'p, L: AsRef> InputFloat<'ui, 'p, L> { + #[deprecated( + since = "0.9.0", + note = "use `ui.input_float` or `ui.input_scalar` instead" + )] pub fn new(ui: &'ui Ui, label: L, value: &'p mut f32) -> Self { InputFloat { label, @@ -742,9 +750,11 @@ impl<'ui, 'p, L: AsRef, T: DataTypeKind, F: AsRef> InputScalar<'ui, 'p /// Builds an input scalar that is bound to the given value. /// /// Returns true if the value was changed. - pub fn build(self, ui: &Ui) -> bool { + pub fn build(self) -> bool { unsafe { - let (one, two) = ui.scratch_txt_with_opt(self.label, self.display_format); + let (one, two) = self + .ui + .scratch_txt_with_opt(self.label, self.display_format); sys::igInputScalar( one, @@ -826,9 +836,11 @@ impl<'ui, 'p, L: AsRef, T: DataTypeKind, F: AsRef> InputScalarN<'ui, ' /// Builds a horizontal array of multiple input scalars attached to the given slice. /// /// Returns true if any value was changed. - pub fn build(self, ui: &Ui) -> bool { + pub fn build(self) -> bool { unsafe { - let (one, two) = ui.scratch_txt_with_opt(self.label, self.display_format); + let (one, two) = self + .ui + .scratch_txt_with_opt(self.label, self.display_format); sys::igInputScalarN( one, diff --git a/imgui/src/lib.rs b/imgui/src/lib.rs index 82447d1..36a173b 100644 --- a/imgui/src/lib.rs +++ b/imgui/src/lib.rs @@ -474,8 +474,8 @@ impl<'ui> Ui { &'ui self, label: L, value: &'p mut f32, - ) -> InputFloat<'ui, 'p, L> { - InputFloat::new(self, label, value) + ) -> InputScalar<'ui, 'p, f32, L> { + self.input_scalar(label, value) } #[doc(alias = "InputFloat2")] pub fn input_float2<'p, L, T>( @@ -521,8 +521,8 @@ impl<'ui> Ui { &'ui self, label: L, value: &'p mut i32, - ) -> InputInt<'ui, 'p, L> { - InputInt::new(self, label, value) + ) -> InputScalar<'ui, 'p, i32, L> { + self.input_scalar(label, value).step(1) } #[doc(alias = "InputInt2")] pub fn input_int2<'p, L, T>(&'ui self, label: L, value: &'p mut T) -> InputInt2<'ui, 'p, L, T>