Merge pull request #514 from sanbox-irl/sliders_and_drag_range

BREAKING: Changed sliders and drag range to require range in their constructor, and simplified their types.
This commit is contained in:
Jonathan Spira 2021-09-05 11:30:20 -07:00 committed by GitHub
commit a3464e31c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 181 additions and 208 deletions

View File

@ -2,21 +2,28 @@
## [Unreleased]
- BREAKING: Modifies `build` style methods to allow the provide closure to return a value. The build call will then return Some(value) if the closure is called, and None if it isn't.
- The most likely breaking changes users will see is that they will need to add semicolons after calling `build`, because these function no longer return `()`.
- BREAKING: Reworked `.range` calls on `Slider`, `VerticalSlider`, and `Drag` to simply take two min and max values, and requires that they are provided in the constructor.
- To update without changing behavior, use the range `T::MIN` and `T::MAX` for the given numerical type (such as `i8::MIN` and `i8::MAX`).
- Using `.range` is still maintained for simplicity, but will likely be deprecated in 0.9 and removed in 0.10!
- BREAKING: Modifies `build` style methods to allow the provide closure to return a value. The build call will then return Some(value) if the closure is called, and None if it isn't.
- The most likely breaking changes users will see is that they will need to add semicolons after calling `build`, because these function no longer return `()`.
- BREAKING: Created `with_x` variants for most functions which previously took multiple parameters where some had default arguments in the C++. This makes calling most functions simpler and more similar to the C++.
- The most likely breaking changes users will see is `button` and `same_line` now take one fewer parameter -- if you were calling `button` with `[0.0, 0.0]`, simply delete that -- otherwise, call `button_with_size`. Similarly, for `same_line`, if you were passing in `0.0.` simply delete that parameter. Otherwise, call `same_line_with_pos`.
- The most likely breaking changes users will see is `button` and `same_line` now take one fewer parameter -- if you were calling `button` with `[0.0, 0.0]`, simply delete that -- otherwise, call `button_with_size`. Similarly, for `same_line`, if you were passing in `0.0.` simply delete that parameter. Otherwise, call `same_line_with_pos`.
- BREAKING: Removed `imgui::legacy` which contained the old style of flags. The remaining flags in `imgui::legacy` have been updated to be consistent with other flags in the project.
- `imgui::legacy::ImGuiDragDropFlags` were accidentally not cleared when they were remade in `drag_drop.rs` in v0.7.0.
- `imgui::legacy::ImGuiInputTextFlags` is now `imgui::input_widgets::InputTextFlags`
- `imgui::legacy::ImGuiTreeNodeFlags` is now `imgui::widget::tree::TreeNodeFlags`
- `imgui::legacy::ImDrawListFlags` is now `imgui::draw_list::DrawListFlags`
- BREAKING: Removed `imgui::legacy` which contained the old style of flags. The remaining flags in `imgui::legacy` have been updated to be consistent with other flags in the project.
- `imgui::legacy::ImGuiDragDropFlags` were accidentally not cleared when they were remade in `drag_drop.rs` in v0.7.0.
- `imgui::legacy::ImGuiInputTextFlags` is now `imgui::input_widgets::InputTextFlags`
- `imgui::legacy::ImGuiTreeNodeFlags` is now `imgui::widget::tree::TreeNodeFlags`
- `imgui::legacy::ImDrawListFlags` is now `imgui::draw_list::DrawListFlags`
- `DrawListMut` has new methods to draw images
- The methods are `add_image`, `add_image_quad`, and `add_image_rounded`. The `imgui-examples/examples/custom_textures.rs` has been updated to show their usage.
- Additionally the `imgui::draw_list` module is now public, which contains the various draw list objects. While the `add_*` methods are preferred, `imgui::draw_list::Circle::new(&draw_list_mut, ...).build()` is equivalent
- The methods are `add_image`, `add_image_quad`, and `add_image_rounded`. The `imgui-examples/examples/custom_textures.rs` has been updated to show their usage.
- Additionally the `imgui::draw_list` module is now public, which contains the various draw list objects. While the `add_*` methods are preferred, `imgui::draw_list::Circle::new(&draw_list_mut, ...).build()` is equivalent
- BREAKING: Most tokens through the repository (eg. `WindowToken`, `TabBarToken`, `FontStackToken`, etc) now allow for permissive dropping -- i.e, you don't need to actually call the `.end()` method on them anymore. In exchange, these tokens have taken on a lifetime, which allows them to be safe. This could make some patterns impossible. Please file an issue if this causes a problem.
- `end()` no longer takes `Ui`. This is a breaking change, but hopefully should be trivial (and perhaps nice) for users to fix. Simply delete the argument, or add a `_` before the token's binding name and allow it to be dropped on its own.
@ -24,66 +31,75 @@
- BREAKING: `PopupModal`'s `new` was reworked so that it didn't take `Ui` until `build` was called. This is a breaking change if you were invoking it directly. Simply move your `ui` call to `build` or `begin`.
- Upgrade to from v1.80 to [Dear ImGui v1.82](https://github.com/ocornut/imgui/releases/tag/v1.82) (see also the [Dear ImGui v1.81](https://github.com/ocornut/imgui/releases/tag/v1.81) release notes)
- BREAKING: `imgui::ListBox::calculate_size(items_count: ..., height_in_items: ...)` has been removed as the function backing it has been marked as obsolete. The recommended approach is to calculate the size yourself and use `.size(...)` (or use the default auto-calculated size)
- BREAKING: `draw_list::CornerFlags` has been renamed to `draw_list::DrawFlags` to match the upstream change, and refle. However, the only draw flags that are useful to Rust currently are still the ones reflecting corner rounding.
- Similarly, the flag names have been updated so that `CornerFlags::$WHERE` has become `DrawFlags::ROUND_CORNERS_$WHERE`, for ecample `CornerFlags::TOP_LEFT` => `DrawFlags::ROUND_CORNERS_TOP_LEFT`.
- Importantly, `CornerFlags::NONE` became `DrawFlags::ROUND_CORNERS_NONE` (following the patter) and **not** `DrawFlags::NONE` which does exist now, and is a separate value.
- BREAKING: `InputTextFlags::ALWAYS_INSERT_MODE` is renamed to `InputTextFlags::
- However, the `always_insert_mode` funcitons on the various input builders remain as a (non-deprecated) alias, as the C++ code has kept an equivalent inline stub.
- BREAKING: `Style::circle_segment_max_error` is no more. `Style::circle_tesselation_max_error` behaves very similarly, but `circle_segment_max_error` values are not equivalent to `circle_tesselation_max_error` values.
- For example, the default `circle_segment_max_error` was 1.6, but the default `circle_tesselation_max_error` is 0.3. In practice, it's unlikely to matter much either way, though.
- BREAKING: `imgui::ListBox::calculate_size(items_count: ..., height_in_items: ...)` has been removed as the function backing it has been marked as obsolete. The recommended approach is to calculate the size yourself and use `.size(...)` (or use the default auto-calculated size)
- BREAKING: `draw_list::CornerFlags` has been renamed to `draw_list::DrawFlags` to match the upstream change, and refle. However, the only draw flags that are useful to Rust currently are still the ones reflecting corner rounding.
- Similarly, the flag names have been updated so that `CornerFlags::$WHERE` has become `DrawFlags::ROUND_CORNERS_$WHERE`, for ecample `CornerFlags::TOP_LEFT` => `DrawFlags::ROUND_CORNERS_TOP_LEFT`.
- Importantly, `CornerFlags::NONE` became `DrawFlags::ROUND_CORNERS_NONE` (following the patter) and **not** `DrawFlags::NONE` which does exist now, and is a separate value.
- BREAKING: `InputTextFlags::ALWAYS_INSERT_MODE` is renamed to `InputTextFlags::
- However, the `always_insert_mode` funcitons on the various input builders remain as a (non-deprecated) alias, as the C++ code has kept an equivalent inline stub.
- BREAKING: `Style::circle_segment_max_error` is no more. `Style::circle_tesselation_max_error` behaves very similarly, but `circle_segment_max_error` values are not equivalent to `circle_tesselation_max_error` values.
- For example, the default `circle_segment_max_error` was 1.6, but the default `circle_tesselation_max_error` is 0.3. In practice, it's unlikely to matter much either way, though.
- Restored methods to access keyboard based on backend-defined keyboard map indexes. These allow access to most keys, not just those defined in the small subset of `imgui::Keys` (note the available keys may be expanded in future by [imgui PR #2625](https://github.com/ocornut/imgui/pull/2625))
- The new methods on `imgui::Ui` are `is_key_index_down`, `is_key_index_pressed`, `is_key_index_pressed_no_repeat`, `is_key_index_released`, `is_key_index_released`
- For example `ui.is_key_released(imgui::Key::A)` is same as `ui.is_key_index_released(winit::events::VirtualKeyCode::A as i32)` when using the winit backend
- Full (32-bit) unicode support is enabled in Dear Imgui (e.g. `-DIMGUI_USE_WCHAR32` is enabled now). Previously UTF-16 was used internally.
- BREAKING: Some parts of the font atlas code now use `char` (or `u32`) instead of `u16` to reflect this.
- Note: `u32` is used over `char` in some situations, such as when surrogates are allowed
- BREAKING (sorta): Dear Imgui now will use 32 bits for character data internally. This impacts the ABI, including sizes of structs and such, and can break some low level or advanced use cases:
- If you're linking against extensions or plugins to Dear Imgui not written in Rust, you need to ensure it is built using `-DIMGUI_USE_WCHAR32`.
- However, if the `DEP_IMGUI_DEFINE_` vars are [used properly](https://github.com/4bb4/implot-rs/blob/f2a4c6a3d8919ec3438631873ce6a9f94135089c/implot-sys/build.rs#L37-L45), this is non-breaking.
- If you're using `features="wasm"` to "link" against emscripten-compiled Dear Imgui, you need to ensure you use `-DIMGUI_USE_WCHAR32` when compile the C and C++ code.
- If you're using `DEP_IMGUI_DEFINE_`s for this already, then no change is needed.
- If you're using `.cargo/config` to apply a build script override and link against a prebuilt `Dear Imgui` (or something else along these lines), you need to ensure you link with a version that was built using `-DIMGUI_USE_WCHAR32`.
- The new methods on `imgui::Ui` are `is_key_index_down`, `is_key_index_pressed`, `is_key_index_pressed_no_repeat`, `is_key_index_released`, `is_key_index_released`
- For example `ui.is_key_released(imgui::Key::A)` is same as `ui.is_key_index_released(winit::events::VirtualKeyCode::A as i32)` when using the winit backend
- Full (32-bit) unicode support is enabled in Dear Imgui (e.g. `-DIMGUI_USE_WCHAR32` is enabled now). Previously UTF-16 was used internally.
- BREAKING: Some parts of the font atlas code now use `char` (or `u32`) instead of `u16` to reflect this.
- Note: `u32` is used over `char` in some situations, such as when surrogates are allowed
- BREAKING (sorta): Dear Imgui now will use 32 bits for character data internally. This impacts the ABI, including sizes of structs and such, and can break some low level or advanced use cases:
- If you're linking against extensions or plugins to Dear Imgui not written in Rust, you need to ensure it is built using `-DIMGUI_USE_WCHAR32`.
- However, if the `DEP_IMGUI_DEFINE_` vars are [used properly](https://github.com/4bb4/implot-rs/blob/f2a4c6a3d8919ec3438631873ce6a9f94135089c/implot-sys/build.rs#L37-L45), this is non-breaking.
- If you're using `features="wasm"` to "link" against emscripten-compiled Dear Imgui, you need to ensure you use `-DIMGUI_USE_WCHAR32` when compile the C and C++ code.
- If you're using `DEP_IMGUI_DEFINE_`s for this already, then no change is needed.
- If you're using `.cargo/config` to apply a build script override and link against a prebuilt `Dear Imgui` (or something else along these lines), you need to ensure you link with a version that was built using `-DIMGUI_USE_WCHAR32`.
## [0.7.0] - 2021-02-04
- Upgrade to [Dear ImGui v1.80](https://github.com/ocornut/imgui/releases/tag/v1.80). (Note that the new table functionality is not yet supported, however)
- `Ui::key_index()` is now called internally when needed, and the various `is_key_foo` now take a `Key` directly: https://github.com/imgui-rs/imgui-rs/pull/416
- `is_key_down`, `is_key_pressed`, `is_key_released` and `key_pressed_amount` now take a `Key` instead of `u32` (breaking).
- `key_index` is no longer public (breaking). If you need access to the key map, it can be accessed as `ui.io().key_map[key]` (If you need to do this, file a bug, since I'm open to exposing this if there's actually a use case).
- `is_key_down`, `is_key_pressed`, `is_key_released` and `key_pressed_amount` now take a `Key` instead of `u32` (breaking).
- `key_index` is no longer public (breaking). If you need access to the key map, it can be accessed as `ui.io().key_map[key]` (If you need to do this, file a bug, since I'm open to exposing this if there's actually a use case).
- `winit` 0.23/0.24 handling has been (hopefully) fixed: https://github.com/imgui-rs/imgui-rs/pull/420 (breaking, see also https://github.com/imgui-rs/imgui-rs/issues/412).
- `imgui-winit-support`'s `winit-23` feature no longer supports `winit` version `0.24` (this caused an unintentional semver breakage before, unfortunately).
- `imgui-winit-support` has a new `winit-24` feature for 0.24 support.
- By default `imgui-winit-support` feature now enables `winit-24`, and not `winit-23` (by default it will always enable the latest).
- `imgui-winit-support`'s `winit-23` feature no longer supports `winit` version `0.24` (this caused an unintentional semver breakage before, unfortunately).
- `imgui-winit-support` has a new `winit-24` feature for 0.24 support.
- By default `imgui-winit-support` feature now enables `winit-24`, and not `winit-23` (by default it will always enable the latest).
- The `imgui` crate no longer depends on `gfx` or `glium` directly: https://github.com/imgui-rs/imgui-rs/pull/420 (breaking, related to the previous change).
- That is, the `gfx` and `glium` features are removed to reduce version compatibility issues going forward.
- This only matters if you manually implement `gfx` or `glium` renderers without using the `imgui-glium-renderer` or `imgui-gfx-renderer` crates.
- In the (somewhat unlikely) case you were relying on these this, you should define your own vertex type that's layout-compatible with `imgui::DrawVert`, and replace calls to `imgui::DrawList::vtx_buffer()` with `imgui::DrawList::transmute_vtx_buffer::<MyDrawVert>()`. You can see `imgui_glium_renderer::GliumDrawVert` and `imgui_gfx_renderer::GfxDrawVert` types respectively for examples of this, if needed, but it should be straightforward enough if you're already implementing a renderer from scratch.
- This is admittedly less convenient, but avoids depending on any specific version of `gfx` or `glium` in the core `imgui` crate, which will ease maintenance and reduce unintentional breakage in the future.
- That is, the `gfx` and `glium` features are removed to reduce version compatibility issues going forward.
- This only matters if you manually implement `gfx` or `glium` renderers without using the `imgui-glium-renderer` or `imgui-gfx-renderer` crates.
- In the (somewhat unlikely) case you were relying on these this, you should define your own vertex type that's layout-compatible with `imgui::DrawVert`, and replace calls to `imgui::DrawList::vtx_buffer()` with `imgui::DrawList::transmute_vtx_buffer::<MyDrawVert>()`. You can see `imgui_glium_renderer::GliumDrawVert` and `imgui_gfx_renderer::GfxDrawVert` types respectively for examples of this, if needed, but it should be straightforward enough if you're already implementing a renderer from scratch.
- This is admittedly less convenient, but avoids depending on any specific version of `gfx` or `glium` in the core `imgui` crate, which will ease maintenance and reduce unintentional breakage in the future.
- Non-window DrawList support has been fixed/improved: https://github.com/imgui-rs/imgui-rs/pull/414
- `WindowDrawList` has been renamed to `DrawListMut`, to reflect that it may refer to other kinds of draw lists, and is mutable, unlike `imgui::DrawList` (breaking).
- `Ui::get_background_draw_list()` has been fixed when used outside of a window context, and now has an example.
- `Ui::get_foreground_draw_list()` has been added, analogous to `Ui::get_background_draw_list()`.
- `WindowDrawList` has been renamed to `DrawListMut`, to reflect that it may refer to other kinds of draw lists, and is mutable, unlike `imgui::DrawList` (breaking).
- `Ui::get_background_draw_list()` has been fixed when used outside of a window context, and now has an example.
- `Ui::get_foreground_draw_list()` has been added, analogous to `Ui::get_background_draw_list()`.
- Added drag drop support, with a safe and an unsafe variant: https://github.com/imgui-rs/imgui-rs/pull/428
- `DragDropSource` allows users to create a dragdrop payload which is either empty, of `'static + Copy` data,
- `DragDropSource` allows users to create a dragdrop payload which is either empty, of `'static + Copy` data,
or `unsafe`, allowing for theoretically arbitrary payloads.
- `DragDropTarget` allows users to accept any of the above payloads.
- Extensive documentation has been made on all of these features, hopefully as a target for future features.
- `DragDropTarget` allows users to accept any of the above payloads.
- Extensive documentation has been made on all of these features, hopefully as a target for future features.
- `ImColor` (which is a wrapper around `u32`) has been renamed to `ImColor32` in order to avoid confusion with the `ImColor` type from the Dear ImGui C++ code (which is a wrapper around `ImVec4`). In the future an `ImColor` type which maps more closely to the C++ one will be added.
- Additionally, a number of constructor and accessor methods have been added to it `ImColor`, which are `const fn` where possible.
- Additionally, a number of constructor and accessor methods have been added to it `ImColor`, which are `const fn` where possible.
- The `im_str!` macro can now be used in `const` contexts (when the `format!` version is not used).
- `im_str!` now verifies that the parameter has no interior nuls at compile time. This can be avoided to get the old (truncating) behavior by forcing it to use the `format!`-like version, e.g. `im_str!("for_some_reason_this_should_be_truncated\0 there {}", "")`.
- This is not recommended, and is probably not useful.
- This is not recommended, and is probably not useful.
- Many functions are now `const fn`.
@ -92,21 +108,21 @@
- The `io.config_windows_memory_compact_timer` flag has been renamed to `io.config_memory_compact_timer`. This follows the similar rename in the C++ ImGui, and was done because it no longer only applies to window memory usage.
- The variants of `ColorEditInputMode` and `ColorEditDisplayMode` have been renamed to be CamelCase instead of upper case (e.g. `ColorEditFooMode::RGB` => `ColorEditFooMode::Rgb`).
- However, this change is probably not breaking (in practice if not in theory) because const aliases using the old names are provided.
- However, this change is probably not breaking (in practice if not in theory) because const aliases using the old names are provided.
## [0.6.1] - 2020-12-16
- Support for winit 0.24.x
- Note: this change was accidentally semver-breaking, see the caveat below.
- Note: this change was accidentally semver-breaking, see the caveat below.
- Support multiple simultaneous winit versions in imgui-winit-support:
- The latest will be if more than one is specified, and a single warning will be logged in debug builds (based on `cfg!(debug_assertions)`) at runtime if multiple are specified.
- This is intended to make features behave a bit more closely to additively, and reduce the pain of using this crate in a larger workspace.
- The latest will be if more than one is specified, and a single warning will be logged in debug builds (based on `cfg!(debug_assertions)`) at runtime if multiple are specified.
- This is intended to make features behave a bit more closely to additively, and reduce the pain of using this crate in a larger workspace.
- Avoid dropping mouse events when press/release are on the same frame (macos)
- Substantial repository layout reorganization
### Caveat: Semver broken in 0.6.1 in `imgui-winit-support`
*Note from the future: `imgui-winit-support@0.6.1` has been yanked. I don't believe the breakage impacted the other crates so I'm leaving those to avoid impacting non-`winit` usages.*
_Note from the future: `imgui-winit-support@0.6.1` has been yanked. I don't believe the breakage impacted the other crates so I'm leaving those to avoid impacting non-`winit` usages._
This release accidentally broke semver, and should have been 0.7.0. It will be yanked when 0.7.0 is released, unless there are objections.
@ -231,8 +247,8 @@ As mentioned, the 0.6.1 release of `imgui-winit-support` has been yanked.
- Gfx renderer re-exports imgui and gfx
- These functions now take/return PathBuf: log_filename, set_log_filename, ini_filename, set_logfilename
- ID stack manipulation now uses stack tokens
- Parameter stack pushes *must almost always be paired by a manual call to stack pop*
- Container widget tokens *must be ended manually by calling end*. Closure-based function (e.g. build()) are unaffected and do this automatically
- Parameter stack pushes _must almost always be paired by a manual call to stack pop_
- Container widget tokens _must be ended manually by calling end_. Closure-based function (e.g. build()) are unaffected and do this automatically
- Bump minimum Rust version to 1.36 (some dependencies, including winit, require MaybeUninit)
- Upgrade to cimgui / imgui 1.72b
@ -336,18 +352,18 @@ As mentioned, the 0.6.1 release of `imgui-winit-support` has been yanked.
### Added
- New things in imgui/cimgui 1.53.1
- Style: Add `PopupRounding`, `FrameBorderSize`, `WindowBorderSize`, `PopupBorderSize`.
- DemoWindow: Add `no_close` state.
- Input: Add `no_undo_redo` method.
- *imgui-sys*:
- `igStyleColorsDark` and `igStyleColorsLight`
- DragDrop low level API
- `igGetFrameHeight`
- `igBeginCombo`, `igEndCombo`
- `igSetItemDefaultFocus`
- `igGetOverlayDrawList` and `igGetDrawListSharedData`
- `ImFontConfig_DefaultConstructor`
- `ImDrawList_AddImageRounded`
- Style: Add `PopupRounding`, `FrameBorderSize`, `WindowBorderSize`, `PopupBorderSize`.
- DemoWindow: Add `no_close` state.
- Input: Add `no_undo_redo` method.
- _imgui-sys_:
- `igStyleColorsDark` and `igStyleColorsLight`
- DragDrop low level API
- `igGetFrameHeight`
- `igBeginCombo`, `igEndCombo`
- `igSetItemDefaultFocus`
- `igGetOverlayDrawList` and `igGetDrawListSharedData`
- `ImFontConfig_DefaultConstructor`
- `ImDrawList_AddImageRounded`
- Input: Add `read_only` and `password` methods.
- Various utility functions
- Support for changing the mouse cursor
@ -360,16 +376,16 @@ As mentioned, the 0.6.1 release of `imgui-winit-support` has been yanked.
### Changed
- Upgrade to imgui/cimgui 1.53.1
- Rename `Ui::show_test_window` to `Ui::show_demo_window`. Keep redirection.
- Rename `sys::igGetItemsLineHeightWithSpacing` to `sys::igGetFrameHeightWithSpacing`. Keep redirection.
- Rename `ImGuiTreeNodeFlags::AllowOverlapMode` to `ImGuiTreeNodeFlags::AllowItemOverlap`. `sys::igSetNextWindowContentSize()`. Keep redirection.
- Rename `sys::ImGuiTextBuffer_append()` helper to `appendf()`.
- Rename `ImGuiStyleVar::ChildWindowRounding` to `ImGuiStyleVar::ChildRounding`. Keep redirection.
- Rename `StyleVar::ChildWindowRounding` to `StyleVar::ChildRounding`. Keep redirection.
- Rename `ImGuiCol::ChildWindowBg` to `ImGuiCol::ChildBg`. Keep redirection.
- Rename `Ui::show_test_window` to `Ui::show_demo_window`. Keep redirection.
- Rename `sys::igGetItemsLineHeightWithSpacing` to `sys::igGetFrameHeightWithSpacing`. Keep redirection.
- Rename `ImGuiTreeNodeFlags::AllowOverlapMode` to `ImGuiTreeNodeFlags::AllowItemOverlap`. `sys::igSetNextWindowContentSize()`. Keep redirection.
- Rename `sys::ImGuiTextBuffer_append()` helper to `appendf()`.
- Rename `ImGuiStyleVar::ChildWindowRounding` to `ImGuiStyleVar::ChildRounding`. Keep redirection.
- Rename `StyleVar::ChildWindowRounding` to `StyleVar::ChildRounding`. Keep redirection.
- Rename `ImGuiCol::ChildWindowBg` to `ImGuiCol::ChildBg`. Keep redirection.
- Upgrade glium to 0.22.0. This updates winit to 0.16. This changes the way
HIDPI are calculated. Depending on your needs, you may want to set HIDPI to 1
by setting the environment variable `WINIT_HIDPI_FACTOR=1` if you use X11.
HIDPI are calculated. Depending on your needs, you may want to set HIDPI to 1
by setting the environment variable `WINIT_HIDPI_FACTOR=1` if you use X11.
- `frame()` now takes a single `FrameSize` argument
- Bump minimum Rust version to 1.24
- `set_mouse_down` takes button states by value, not by reference
@ -377,17 +393,17 @@ by setting the environment variable `WINIT_HIDPI_FACTOR=1` if you use X11.
### Deprecated
- Various imgui-sys things that were deprecated in imgui/cimgui 1.53.1
- Obsolete `sys::igIsRootWindowFocused()` in favor of using `sys::igIsWindowFocused(ImGuiFocusedFlags::RootWindow)`.
- Obsolete `sys::igIsRootWindowOrAnyChildFocused()` in favor of using `sys::igIsWindowFocused(ImGuiFocusedFlags::RootAndChildWindows)`.
- Obsolete `sys::igIsRootWindowOrAnyChildHovered()` in favor of using `sys::igIsWindowHovered(ImGuiHoveredFlags::RootAndChildWindows)`.
- Obsolete `sys::SetNextWindowContentWidth()` in favor of using - Obsolete `Window::show_borders`. Use `StyleVar` instead.
- Obsolete `ImGuiCol::ComboBg`. Use `PopupBg` instead.
- Obsolete `sys::igIsRootWindowFocused()` in favor of using `sys::igIsWindowFocused(ImGuiFocusedFlags::RootWindow)`.
- Obsolete `sys::igIsRootWindowOrAnyChildFocused()` in favor of using `sys::igIsWindowFocused(ImGuiFocusedFlags::RootAndChildWindows)`.
- Obsolete `sys::igIsRootWindowOrAnyChildHovered()` in favor of using `sys::igIsWindowHovered(ImGuiHoveredFlags::RootAndChildWindows)`.
- Obsolete `sys::SetNextWindowContentWidth()` in favor of using - Obsolete `Window::show_borders`. Use `StyleVar` instead.
- Obsolete `ImGuiCol::ComboBg`. Use `PopupBg` instead.
### Removed
- Features that were removed in imgui/cimgui 1.53.1
- Remove `anti_aliased: bool` final parameter of `sys::ImDrawList_AddPolyline` and `sys::ImDrawList_AddConvexPolyFilled`.
- Remove `ImGuiWindowFlags::ShowBorders` window flag. Borders are now fully set up in the ImGuiStyle structure.
- Remove `anti_aliased: bool` final parameter of `sys::ImDrawList_AddPolyline` and `sys::ImDrawList_AddConvexPolyFilled`.
- Remove `ImGuiWindowFlags::ShowBorders` window flag. Borders are now fully set up in the ImGuiStyle structure.
- Various imgui-sys things that were deprecated in imgui/cimgui 1.52
## [0.0.18] - 2017-12-23
@ -487,9 +503,9 @@ by setting the environment variable `WINIT_HIDPI_FACTOR=1` if you use X11.
- Support for scoped color customization
- Support for child frames
- Unsafe ImString/ImStr creation functions for advanced users:
- `ImString::from_utf8_unchecked` (renamed from `ImString::from_bytes_unchecked`)
- `ImString::from_utf8_with_nul_unchecked`
- `ImStr::from_utf8_with_nul_unchecked` (renamed from `ImStr::from_bytes_unchecked`)
- `ImString::from_utf8_unchecked` (renamed from `ImString::from_bytes_unchecked`)
- `ImString::from_utf8_with_nul_unchecked`
- `ImStr::from_utf8_with_nul_unchecked` (renamed from `ImStr::from_bytes_unchecked`)
### Changed
@ -610,9 +626,9 @@ by setting the environment variable `WINIT_HIDPI_FACTOR=1` if you use X11.
- ImStr::as_ptr is now part of the public API
- Upgrade to bitflags 0.7
- Upgrade to imgui/cimgui 1.49
* Several imgui_sys structs have changed
* CollapsingHeader API has changed
* New window flags are supported
- Several imgui_sys structs have changed
- CollapsingHeader API has changed
- New window flags are supported
## [0.0.8] - 2016-04-15
@ -675,7 +691,7 @@ by setting the environment variable `WINIT_HIDPI_FACTOR=1` if you use X11.
- Initial release with cimgui/imgui 1.44, glium 0.9
[Unreleased]: https://github.com/Gekkio/imgui-rs/compare/v0.7.0...HEAD
[unreleased]: https://github.com/Gekkio/imgui-rs/compare/v0.7.0...HEAD
[0.7.0]: https://github.com/Gekkio/imgui-rs/compare/v0.6.1...v0.7.0
[0.6.1]: https://github.com/Gekkio/imgui-rs/compare/v0.6.0...v0.6.1
[0.6.0]: https://github.com/Gekkio/imgui-rs/compare/v0.5.0...v0.6.0

View File

@ -41,29 +41,27 @@ fn example_1(ui: &Ui, state: &mut State) {
ui.text("Unsigned: u8 u16 u32 u64");
ui.text("Floats: f32 f64");
Slider::new(im_str!("u8 value"))
Slider::new(im_str!("u8 value"), 0, 255)
.build(ui, &mut state.u8_value);
Slider::new(im_str!("f32 value"))
Slider::new(im_str!("f32 value"), -f32::MIN, f32::MAX)
.build(ui, &mut state.f32_value);
ui.separator();
ui.text("Slider range can be limited:");
Slider::new(im_str!("i32 value with range"))
.range(-999 ..= 999)
Slider::new(im_str!("i32 value with range"), -999, 999)
.build(ui, &mut state.i32_value);
ui.text("Note that for 32-bit/64-bit types, sliders are always limited to half of the natural type range!");
ui.separator();
ui.text("Value formatting can be customized with a C-style printf string:");
Slider::new(im_str!("f64 value with custom formatting"))
.range(-999_999_999.0 ..= 999_999_999.0)
Slider::new(im_str!("f64 value with custom formatting"), -999_999_999.0, 999_999_999.0)
.display_format(im_str!("%09.0f"))
.build(ui, &mut state.f64_formatted);
ui.separator();
ui.text("Vertical sliders require a size parameter but otherwise work in a similar way:");
VerticalSlider::new(im_str!("vertical\nu8 value"), [50.0, 50.0])
VerticalSlider::new(im_str!("vertical\nu8 value"), [50.0, 50.0], u8::MIN, u8::MAX)
.build(ui, &mut state.u8_value);
});
}
@ -74,11 +72,11 @@ fn example_2(ui: &Ui, state: &mut State) {
.position([20.0, 120.0], Condition::Appearing);
w.build(ui, || {
ui.text("You can easily build a slider group from an array of values:");
Slider::new(im_str!("[u8; 4]")).build_array(ui, &mut state.array);
Slider::new(im_str!("[u8; 4]"), 0, u8::MAX).build_array(ui, &mut state.array);
ui.text("You don't need to use arrays with known length; arbitrary slices can be used:");
let slice: &mut [u8] = &mut state.array[1..=2];
Slider::new(im_str!("subslice")).build_array(ui, slice);
Slider::new(im_str!("subslice"), 0, u8::MAX).build_array(ui, slice);
});
}

View File

@ -448,7 +448,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
));
ui.spacing();
Slider::new(im_str!("Wrap width")).range(-20.0 ..= 600.0)
Slider::new(im_str!("Wrap width"), -20.0, 600.0)
.display_format(im_str!("%.0f"))
.build(ui, &mut state.wrap_width);
@ -545,7 +545,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
.step(0.01)
.step_fast(1.0)
.build();
Drag::new(im_str!("drag float")).range(-1.0..=1.0).speed(0.001).build(ui, &mut state.f0);
Drag::new(im_str!("drag float")).range(-1.0, 1.0).speed(0.001).build(ui, &mut state.f0);
ui.input_float3(im_str!("input float3"), &mut state.vec3f)
.build();
ColorEdit::new(im_str!("color 1"), &mut state.col1).build(ui);
@ -899,9 +899,7 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) {
ui.text(format!("Scrolling Text {}", i));
}
});
Slider::new(im_str!("Value"))
.range(0.0..=1.0)
.build(ui, &mut state.f);
Slider::new(im_str!("Value"), 0.0, 1.0).build(ui, &mut state.f);
ui.input_float(im_str!("Input"), &mut state.f)
.step(0.1)
@ -936,9 +934,7 @@ fn show_example_app_auto_resize(ui: &Ui, state: &mut AutoResizeState, opened: &m
Note that you probably don't want to query the window size to
output your content because that would create a feedback loop.",
);
Slider::new(im_str!("Number of lines"))
.range(1..=20)
.build(ui, &mut state.lines);
Slider::new(im_str!("Number of lines"), 1, 20).build(ui, &mut state.lines);
for i in 0..state.lines {
ui.text(format!("{:2$}This is line {}", "", i, i as usize * 4));
}

View File

@ -1,6 +1,5 @@
//! Internal raw utilities (don't use unless you know what you're doing!)
use std::ops::{RangeFrom, RangeInclusive, RangeToInclusive};
use std::slice;
/// A generic version of the raw imgui-sys ImVector struct types
@ -127,94 +126,34 @@ pub enum DataType {
/// representation in memory as the primitive value described by the associated `KIND` constant.
pub unsafe trait DataTypeKind: Copy {
const KIND: DataType;
const SLIDER_MIN: Self;
const SLIDER_MAX: Self;
}
unsafe impl DataTypeKind for i8 {
const KIND: DataType = DataType::I8;
const SLIDER_MIN: Self = std::i8::MIN;
const SLIDER_MAX: Self = std::i8::MAX;
}
unsafe impl DataTypeKind for u8 {
const KIND: DataType = DataType::U8;
const SLIDER_MIN: Self = std::u8::MIN;
const SLIDER_MAX: Self = std::u8::MAX;
}
unsafe impl DataTypeKind for i16 {
const KIND: DataType = DataType::I16;
const SLIDER_MIN: Self = std::i16::MIN;
const SLIDER_MAX: Self = std::i16::MAX;
}
unsafe impl DataTypeKind for u16 {
const KIND: DataType = DataType::U16;
const SLIDER_MIN: Self = std::u16::MIN;
const SLIDER_MAX: Self = std::u16::MAX;
}
unsafe impl DataTypeKind for i32 {
const KIND: DataType = DataType::I32;
const SLIDER_MIN: Self = std::i32::MIN / 2;
const SLIDER_MAX: Self = std::i32::MAX / 2;
}
unsafe impl DataTypeKind for u32 {
const KIND: DataType = DataType::U32;
const SLIDER_MIN: Self = std::u32::MIN / 2;
const SLIDER_MAX: Self = std::u32::MAX / 2;
}
unsafe impl DataTypeKind for i64 {
const KIND: DataType = DataType::I64;
const SLIDER_MIN: Self = std::i64::MIN / 2;
const SLIDER_MAX: Self = std::i64::MAX / 2;
}
unsafe impl DataTypeKind for u64 {
const KIND: DataType = DataType::U64;
const SLIDER_MIN: Self = std::u64::MIN / 2;
const SLIDER_MAX: Self = std::u64::MAX / 2;
}
unsafe impl DataTypeKind for f32 {
const KIND: DataType = DataType::F32;
const SLIDER_MIN: Self = std::f32::MIN / 2.0;
const SLIDER_MAX: Self = std::f32::MAX / 2.0;
}
unsafe impl DataTypeKind for f64 {
const KIND: DataType = DataType::F64;
const SLIDER_MIN: Self = std::f64::MIN / 2.0;
const SLIDER_MAX: Self = std::f64::MAX / 2.0;
}
pub trait InclusiveRangeBounds<T: Copy> {
fn start_bound(&self) -> Option<&T>;
fn end_bound(&self) -> Option<&T>;
}
impl<T: Copy> InclusiveRangeBounds<T> for RangeFrom<T> {
#[inline]
fn start_bound(&self) -> Option<&T> {
Some(&self.start)
}
#[inline]
fn end_bound(&self) -> Option<&T> {
None
}
}
impl<T: Copy> InclusiveRangeBounds<T> for RangeInclusive<T> {
#[inline]
fn start_bound(&self) -> Option<&T> {
Some(self.start())
}
#[inline]
fn end_bound(&self) -> Option<&T> {
Some(self.end())
}
}
impl<T: Copy> InclusiveRangeBounds<T> for RangeToInclusive<T> {
#[inline]
fn start_bound(&self) -> Option<&T> {
None
}
#[inline]
fn end_bound(&self) -> Option<&T> {
Some(&self.end)
}
}

View File

@ -1,7 +1,7 @@
use std::os::raw::c_void;
use std::ptr;
use crate::internal::{DataTypeKind, InclusiveRangeBounds};
use crate::internal::DataTypeKind;
use crate::string::ImStr;
use crate::sys;
use crate::widget::slider::SliderFlags;
@ -34,9 +34,9 @@ impl<'a, T: DataTypeKind> Drag<'a, T> {
}
/// Sets the range (inclusive)
#[inline]
pub fn range<R: InclusiveRangeBounds<T>>(mut self, range: R) -> Self {
self.min = range.start_bound().copied();
self.max = range.end_bound().copied();
pub fn range(mut self, min: T, max: T) -> Self {
self.min = Some(min);
self.max = Some(max);
self
}
/// Sets the value increment for a movement of one pixel.
@ -140,9 +140,9 @@ impl<'a, T: DataTypeKind> DragRange<'a, T> {
}
}
#[inline]
pub fn range<R: InclusiveRangeBounds<T>>(mut self, range: R) -> Self {
self.min = range.start_bound().copied();
self.max = range.end_bound().copied();
pub fn range(mut self, min: T, max: T) -> Self {
self.min = Some(min);
self.max = Some(max);
self
}
/// Sets the value increment for a movement of one pixel.

View File

@ -2,7 +2,7 @@ use bitflags::bitflags;
use std::os::raw::c_void;
use std::ptr;
use crate::internal::{DataTypeKind, InclusiveRangeBounds};
use crate::internal::DataTypeKind;
use crate::string::ImStr;
use crate::sys;
use crate::Ui;
@ -38,42 +38,32 @@ pub struct Slider<'a, T: DataTypeKind> {
impl<'a, T: DataTypeKind> Slider<'a, T> {
/// Constructs a new slider builder with the given range.
#[doc(alias = "SliderScalar", alias = "SliderScalarN")]
pub fn new(label: &ImStr) -> Slider<T> {
pub fn new(label: &ImStr, min: T, max: T) -> Slider<T> {
Slider {
label,
min: T::SLIDER_MIN,
max: T::SLIDER_MAX,
min,
max,
display_format: None,
flags: SliderFlags::empty(),
}
}
/// Sets the range (inclusive)
///
/// The argument uses the standard Rust [`std::ops::Range`] syntax.
///
/// For example, to set both the min and max values:
/// Sets the range inclusively, such that both values given
/// are valid values which the slider can be dragged to.
///
/// ```rust
/// # use imgui::im_str;
/// imgui::Slider::new(im_str!("Example"))
/// .range(1 ..= 10)
/// imgui::Slider::new(im_str!("Example"), i8::MIN, i8::MAX)
/// .range(4, 8)
/// // Remember to call .build(&ui)
/// ;
/// ```
///
/// To set only the max value, using the default minimum value:
///
/// ```rust
/// # use imgui::im_str;
/// imgui::Slider::new(im_str!("Example"))
/// .range(..= 10)
/// // Remember to call .build(&ui)
/// ;
/// ```
/// It is safe, though up to C++ Dear ImGui, on how to handle when
/// `min > max`.
#[inline]
pub fn range<R: InclusiveRangeBounds<T>>(mut self, range: R) -> Self {
self.min = range.start_bound().copied().unwrap_or(T::SLIDER_MIN);
self.max = range.end_bound().copied().unwrap_or(T::SLIDER_MAX);
pub fn range(mut self, min: T, max: T) -> Self {
self.min = min;
self.max = max;
self
}
/// Sets the display format using *a C-style printf string*
@ -141,22 +131,45 @@ pub struct VerticalSlider<'a, T: DataTypeKind + Copy> {
impl<'a, T: DataTypeKind> VerticalSlider<'a, T> {
/// Constructs a new vertical slider builder with the given size and range.
///
/// ```rust
/// # use imgui::im_str;
/// imgui::VerticalSlider::new(im_str!("Example"), [20.0, 20.0], i8::MIN, i8::MAX)
/// .range(4, 8)
/// // Remember to call .build(&ui)
/// ;
/// ```
///
/// It is safe, though up to C++ Dear ImGui, on how to handle when
/// `min > max`.
#[doc(alias = "VSliderScalar")]
pub fn new(label: &ImStr, size: [f32; 2]) -> VerticalSlider<T> {
pub fn new(label: &ImStr, size: [f32; 2], min: T, max: T) -> VerticalSlider<T> {
VerticalSlider {
label,
size,
min: T::SLIDER_MIN,
max: T::SLIDER_MAX,
min,
max,
display_format: None,
flags: SliderFlags::empty(),
}
}
/// Sets the range (inclusive)
/// Sets the range for the vertical slider.
///
/// ```rust
/// # use imgui::im_str;
/// imgui::VerticalSlider::new(im_str!("Example"), [20.0, 20.0], i8::MIN, i8::MAX)
/// .range(4, 8)
/// // Remember to call .build(&ui)
/// ;
/// ```
///
/// It is safe, though up to C++ Dear ImGui, on how to handle when
/// `min > max`.
#[inline]
pub fn range<R: InclusiveRangeBounds<T>>(mut self, range: R) -> Self {
self.min = range.start_bound().copied().unwrap_or(T::SLIDER_MIN);
self.max = range.end_bound().copied().unwrap_or(T::SLIDER_MAX);
pub fn range(mut self, min: T, max: T) -> Self {
self.min = min;
self.max = max;
self
}
/// Sets the display format using *a C-style printf string*
@ -204,7 +217,8 @@ pub struct AngleSlider<'a> {
}
impl<'a> AngleSlider<'a> {
/// Constructs a new angle slider builder.
/// Constructs a new angle slider builder, where its minimum defaults to -360.0 and
/// maximum defaults to 360.0
#[doc(alias = "SliderAngle")]
pub fn new(label: &ImStr) -> AngleSlider {
AngleSlider {
@ -215,11 +229,21 @@ impl<'a> AngleSlider<'a> {
flags: SliderFlags::empty(),
}
}
/// Sets the range (in degrees, inclusive)
/// Sets the range in degrees (inclusive)
/// ```rust
/// # use imgui::im_str;
/// imgui::AngleSlider::new(im_str!("Example"))
/// .range_degrees(-20.0, 20.0)
/// // Remember to call .build(&ui)
/// ;
/// ```
///
/// It is safe, though up to C++ Dear ImGui, on how to handle when
/// `min > max`.
#[inline]
pub fn range_degrees<R: InclusiveRangeBounds<f32>>(mut self, range: R) -> Self {
self.min_degrees = range.start_bound().copied().unwrap_or(-360.0);
self.max_degrees = range.end_bound().copied().unwrap_or(360.0);
pub fn range_degrees(mut self, min_degrees: f32, max_degrees: f32) -> Self {
self.min_degrees = min_degrees;
self.max_degrees = max_degrees;
self
}
/// Sets the minimum value (in degrees)