mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-24 11:58:32 +00:00
Fixes recommended by clippy
This commit is contained in:
parent
130ebfc931
commit
da9ee9302b
@ -46,6 +46,7 @@ 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.
|
by setting the environment variable `WINIT_HIDPI_FACTOR=1` if you use X11.
|
||||||
- `frame()` now takes a single `FrameSize` argument
|
- `frame()` now takes a single `FrameSize` argument
|
||||||
- Bump minimum Rust version to 1.24
|
- Bump minimum Rust version to 1.24
|
||||||
|
- `set_mouse_down` takes button states by value, not by reference
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
|
|||||||
@ -204,7 +204,7 @@ fn configure_keys(imgui: &mut ImGui) {
|
|||||||
|
|
||||||
fn update_mouse(imgui: &mut ImGui, mouse_state: &mut MouseState) {
|
fn update_mouse(imgui: &mut ImGui, mouse_state: &mut MouseState) {
|
||||||
imgui.set_mouse_pos(mouse_state.pos.0 as f32, mouse_state.pos.1 as f32);
|
imgui.set_mouse_pos(mouse_state.pos.0 as f32, mouse_state.pos.1 as f32);
|
||||||
imgui.set_mouse_down(&[
|
imgui.set_mouse_down([
|
||||||
mouse_state.pressed.0,
|
mouse_state.pressed.0,
|
||||||
mouse_state.pressed.1,
|
mouse_state.pressed.1,
|
||||||
mouse_state.pressed.2,
|
mouse_state.pressed.2,
|
||||||
|
|||||||
@ -242,7 +242,7 @@ fn configure_keys(imgui: &mut ImGui) {
|
|||||||
|
|
||||||
fn update_mouse(imgui: &mut ImGui, mouse_state: &mut MouseState) {
|
fn update_mouse(imgui: &mut ImGui, mouse_state: &mut MouseState) {
|
||||||
imgui.set_mouse_pos(mouse_state.pos.0 as f32, mouse_state.pos.1 as f32);
|
imgui.set_mouse_pos(mouse_state.pos.0 as f32, mouse_state.pos.1 as f32);
|
||||||
imgui.set_mouse_down(&[
|
imgui.set_mouse_down([
|
||||||
mouse_state.pressed.0,
|
mouse_state.pressed.0,
|
||||||
mouse_state.pressed.1,
|
mouse_state.pressed.1,
|
||||||
mouse_state.pressed.2,
|
mouse_state.pressed.2,
|
||||||
|
|||||||
@ -13,7 +13,6 @@ extern crate gfx;
|
|||||||
extern crate glium;
|
extern crate glium;
|
||||||
|
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::mem;
|
|
||||||
use std::os::raw::{c_char, c_float, c_int, c_short, c_uchar, c_uint, c_ushort, c_void};
|
use std::os::raw::{c_char, c_float, c_int, c_short, c_uchar, c_uint, c_ushort, c_void};
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
@ -902,7 +901,7 @@ pub struct ImDrawData {
|
|||||||
|
|
||||||
impl ImDrawData {
|
impl ImDrawData {
|
||||||
pub unsafe fn cmd_lists(&self) -> &[*const ImDrawList] {
|
pub unsafe fn cmd_lists(&self) -> &[*const ImDrawList] {
|
||||||
let cmd_lists: *const *const ImDrawList = mem::transmute(self.cmd_lists);
|
let cmd_lists = self.cmd_lists as *const *const ImDrawList;
|
||||||
slice::from_raw_parts(cmd_lists, self.cmd_lists_count as usize)
|
slice::from_raw_parts(cmd_lists, self.cmd_lists_count as usize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ pub struct ChildFrame<'ui, 'p> {
|
|||||||
impl<'ui, 'p> ChildFrame<'ui, 'p> {
|
impl<'ui, 'p> ChildFrame<'ui, 'p> {
|
||||||
pub fn new<S: Into<ImVec2>>(_: &Ui<'ui>, name: &'p ImStr, size: S) -> ChildFrame<'ui, 'p> {
|
pub fn new<S: Into<ImVec2>>(_: &Ui<'ui>, name: &'p ImStr, size: S) -> ChildFrame<'ui, 'p> {
|
||||||
ChildFrame {
|
ChildFrame {
|
||||||
name: name,
|
name,
|
||||||
size: size.into(),
|
size: size.into(),
|
||||||
border: false,
|
border: false,
|
||||||
flags: ImGuiWindowFlags::empty(),
|
flags: ImGuiWindowFlags::empty(),
|
||||||
|
|||||||
28
src/drag.rs
28
src/drag.rs
@ -65,8 +65,8 @@ pub struct DragFloat<'ui, 'p> {
|
|||||||
impl<'ui, 'p> DragFloat<'ui, 'p> {
|
impl<'ui, 'p> DragFloat<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut f32) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut f32) -> Self {
|
||||||
DragFloat {
|
DragFloat {
|
||||||
label: label,
|
label,
|
||||||
value: value,
|
value,
|
||||||
speed: 1.0,
|
speed: 1.0,
|
||||||
min: 0.0,
|
min: 0.0,
|
||||||
max: 0.0,
|
max: 0.0,
|
||||||
@ -113,8 +113,8 @@ macro_rules! impl_drag_floatn {
|
|||||||
impl<'ui, 'p> $DragFloatN<'ui, 'p> {
|
impl<'ui, 'p> $DragFloatN<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [f32; $N]) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [f32; $N]) -> Self {
|
||||||
$DragFloatN {
|
$DragFloatN {
|
||||||
label: label,
|
label,
|
||||||
value: value,
|
value,
|
||||||
speed: 1.0,
|
speed: 1.0,
|
||||||
min: 0.0,
|
min: 0.0,
|
||||||
max: 0.0,
|
max: 0.0,
|
||||||
@ -172,9 +172,9 @@ impl<'ui, 'p> DragFloatRange2<'ui, 'p> {
|
|||||||
current_max: &'p mut f32,
|
current_max: &'p mut f32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
DragFloatRange2 {
|
DragFloatRange2 {
|
||||||
label: label,
|
label,
|
||||||
current_min: current_min,
|
current_min,
|
||||||
current_max: current_max,
|
current_max,
|
||||||
speed: 1.0,
|
speed: 1.0,
|
||||||
min: 0.0,
|
min: 0.0,
|
||||||
max: 0.0,
|
max: 0.0,
|
||||||
@ -227,8 +227,8 @@ pub struct DragInt<'ui, 'p> {
|
|||||||
impl<'ui, 'p> DragInt<'ui, 'p> {
|
impl<'ui, 'p> DragInt<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut i32) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut i32) -> Self {
|
||||||
DragInt {
|
DragInt {
|
||||||
label: label,
|
label,
|
||||||
value: value,
|
value,
|
||||||
speed: 1.0,
|
speed: 1.0,
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 0,
|
max: 0,
|
||||||
@ -271,8 +271,8 @@ macro_rules! impl_drag_intn {
|
|||||||
impl<'ui, 'p> $DragIntN<'ui, 'p> {
|
impl<'ui, 'p> $DragIntN<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [i32; $N]) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [i32; $N]) -> Self {
|
||||||
$DragIntN {
|
$DragIntN {
|
||||||
label: label,
|
label,
|
||||||
value: value,
|
value,
|
||||||
speed: 1.0,
|
speed: 1.0,
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 0,
|
max: 0,
|
||||||
@ -326,9 +326,9 @@ impl<'ui, 'p> DragIntRange2<'ui, 'p> {
|
|||||||
current_max: &'p mut i32,
|
current_max: &'p mut i32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
DragIntRange2 {
|
DragIntRange2 {
|
||||||
label: label,
|
label,
|
||||||
current_min: current_min,
|
current_min,
|
||||||
current_max: current_max,
|
current_max,
|
||||||
speed: 1.0,
|
speed: 1.0,
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 0,
|
max: 0,
|
||||||
|
|||||||
18
src/fonts.rs
18
src/fonts.rs
@ -68,9 +68,9 @@ impl FontGlyphRange {
|
|||||||
"A glyph range must be zero-terminated."
|
"A glyph range must be zero-terminated."
|
||||||
);
|
);
|
||||||
|
|
||||||
for i in 0..slice.len() - 1 {
|
for (i, &glyph) in slice.iter().enumerate().take(slice.len() - 1) {
|
||||||
assert_ne!(
|
assert_ne!(
|
||||||
slice[i], 0,
|
glyph, 0,
|
||||||
"A glyph in a range cannot be zero. \
|
"A glyph in a range cannot be zero. \
|
||||||
(Glyph is zero at index {})",
|
(Glyph is zero at index {})",
|
||||||
i
|
i
|
||||||
@ -122,14 +122,14 @@ impl FontGlyphRange {
|
|||||||
|
|
||||||
unsafe fn to_ptr(&self, atlas: *mut sys::ImFontAtlas) -> *const sys::ImWchar {
|
unsafe fn to_ptr(&self, atlas: *mut sys::ImFontAtlas) -> *const sys::ImWchar {
|
||||||
match &self.0 {
|
match &self.0 {
|
||||||
&FontGlyphRangeData::Chinese => sys::ImFontAtlas_GetGlyphRangesChinese(atlas),
|
FontGlyphRangeData::Chinese => sys::ImFontAtlas_GetGlyphRangesChinese(atlas),
|
||||||
&FontGlyphRangeData::Cyrillic => sys::ImFontAtlas_GetGlyphRangesCyrillic(atlas),
|
FontGlyphRangeData::Cyrillic => sys::ImFontAtlas_GetGlyphRangesCyrillic(atlas),
|
||||||
&FontGlyphRangeData::Default => sys::ImFontAtlas_GetGlyphRangesDefault(atlas),
|
FontGlyphRangeData::Default => sys::ImFontAtlas_GetGlyphRangesDefault(atlas),
|
||||||
&FontGlyphRangeData::Japanese => sys::ImFontAtlas_GetGlyphRangesJapanese(atlas),
|
FontGlyphRangeData::Japanese => sys::ImFontAtlas_GetGlyphRangesJapanese(atlas),
|
||||||
&FontGlyphRangeData::Korean => sys::ImFontAtlas_GetGlyphRangesKorean(atlas),
|
FontGlyphRangeData::Korean => sys::ImFontAtlas_GetGlyphRangesKorean(atlas),
|
||||||
&FontGlyphRangeData::Thai => sys::ImFontAtlas_GetGlyphRangesThai(atlas),
|
FontGlyphRangeData::Thai => sys::ImFontAtlas_GetGlyphRangesThai(atlas),
|
||||||
|
|
||||||
&FontGlyphRangeData::Custom(ptr) => ptr,
|
FontGlyphRangeData::Custom(ptr) => *ptr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/input.rs
26
src/input.rs
@ -147,8 +147,8 @@ pub struct InputText<'ui, 'p> {
|
|||||||
impl<'ui, 'p> InputText<'ui, 'p> {
|
impl<'ui, 'p> InputText<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, buf: &'p mut ImString) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, buf: &'p mut ImString) -> Self {
|
||||||
InputText {
|
InputText {
|
||||||
label: label,
|
label,
|
||||||
buf: buf,
|
buf,
|
||||||
flags: ImGuiInputTextFlags::empty(),
|
flags: ImGuiInputTextFlags::empty(),
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
@ -185,10 +185,10 @@ pub struct InputTextMultiline<'ui, 'p> {
|
|||||||
impl<'ui, 'p> InputTextMultiline<'ui, 'p> {
|
impl<'ui, 'p> InputTextMultiline<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, buf: &'p mut ImString, size: sys::ImVec2) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, buf: &'p mut ImString, size: sys::ImVec2) -> Self {
|
||||||
InputTextMultiline {
|
InputTextMultiline {
|
||||||
label: label,
|
label,
|
||||||
buf: buf,
|
buf,
|
||||||
flags: ImGuiInputTextFlags::empty(),
|
flags: ImGuiInputTextFlags::empty(),
|
||||||
size: size,
|
size,
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,8 +226,8 @@ pub struct InputInt<'ui, 'p> {
|
|||||||
impl<'ui, 'p> InputInt<'ui, 'p> {
|
impl<'ui, 'p> InputInt<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut i32) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut i32) -> Self {
|
||||||
InputInt {
|
InputInt {
|
||||||
label: label,
|
label,
|
||||||
value: value,
|
value,
|
||||||
step: 1,
|
step: 1,
|
||||||
step_fast: 100,
|
step_fast: 100,
|
||||||
flags: ImGuiInputTextFlags::empty(),
|
flags: ImGuiInputTextFlags::empty(),
|
||||||
@ -265,8 +265,8 @@ pub struct InputFloat<'ui, 'p> {
|
|||||||
impl<'ui, 'p> InputFloat<'ui, 'p> {
|
impl<'ui, 'p> InputFloat<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut f32) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut f32) -> Self {
|
||||||
InputFloat {
|
InputFloat {
|
||||||
label: label,
|
label,
|
||||||
value: value,
|
value,
|
||||||
step: 0.0,
|
step: 0.0,
|
||||||
step_fast: 0.0,
|
step_fast: 0.0,
|
||||||
decimal_precision: -1,
|
decimal_precision: -1,
|
||||||
@ -307,8 +307,8 @@ macro_rules! impl_input_floatn {
|
|||||||
impl<'ui, 'p> $InputFloatN<'ui, 'p> {
|
impl<'ui, 'p> $InputFloatN<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [f32; $N]) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [f32; $N]) -> Self {
|
||||||
$InputFloatN {
|
$InputFloatN {
|
||||||
label: label,
|
label,
|
||||||
value: value,
|
value,
|
||||||
decimal_precision: -1,
|
decimal_precision: -1,
|
||||||
flags: ImGuiInputTextFlags::empty(),
|
flags: ImGuiInputTextFlags::empty(),
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
@ -349,8 +349,8 @@ macro_rules! impl_input_intn {
|
|||||||
impl<'ui, 'p> $InputIntN<'ui, 'p> {
|
impl<'ui, 'p> $InputIntN<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [i32; $N]) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [i32; $N]) -> Self {
|
||||||
$InputIntN {
|
$InputIntN {
|
||||||
label: label,
|
label,
|
||||||
value: value,
|
value,
|
||||||
flags: ImGuiInputTextFlags::empty(),
|
flags: ImGuiInputTextFlags::empty(),
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -246,9 +246,9 @@ impl ImGui {
|
|||||||
let io = self.io();
|
let io = self.io();
|
||||||
(io.mouse_delta.x, io.mouse_delta.y)
|
(io.mouse_delta.x, io.mouse_delta.y)
|
||||||
}
|
}
|
||||||
pub fn set_mouse_down(&mut self, states: &[bool; 5]) {
|
pub fn set_mouse_down(&mut self, states: [bool; 5]) {
|
||||||
let io = self.io_mut();
|
let io = self.io_mut();
|
||||||
io.mouse_down = *states;
|
io.mouse_down = states;
|
||||||
}
|
}
|
||||||
pub fn set_mouse_wheel(&mut self, value: f32) {
|
pub fn set_mouse_wheel(&mut self, value: f32) {
|
||||||
let io = self.io_mut();
|
let io = self.io_mut();
|
||||||
@ -337,7 +337,7 @@ impl ImGui {
|
|||||||
}
|
}
|
||||||
pub fn set_imgui_key(&mut self, key: ImGuiKey, mapping: u8) {
|
pub fn set_imgui_key(&mut self, key: ImGuiKey, mapping: u8) {
|
||||||
let io = self.io_mut();
|
let io = self.io_mut();
|
||||||
io.key_map[key as usize] = mapping as i32;
|
io.key_map[key as usize] = i32::from(mapping);
|
||||||
}
|
}
|
||||||
/// Map [`ImGuiKey`] values into user's key index
|
/// Map [`ImGuiKey`] values into user's key index
|
||||||
pub fn get_key_index(&self, key: ImGuiKey) -> usize {
|
pub fn get_key_index(&self, key: ImGuiKey) -> usize {
|
||||||
|
|||||||
@ -14,7 +14,7 @@ pub struct Menu<'ui, 'p> {
|
|||||||
impl<'ui, 'p> Menu<'ui, 'p> {
|
impl<'ui, 'p> Menu<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr) -> Self {
|
||||||
Menu {
|
Menu {
|
||||||
label: label,
|
label,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ pub struct MenuItem<'ui, 'p> {
|
|||||||
impl<'ui, 'p> MenuItem<'ui, 'p> {
|
impl<'ui, 'p> MenuItem<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr) -> Self {
|
||||||
MenuItem {
|
MenuItem {
|
||||||
label: label,
|
label,
|
||||||
shortcut: None,
|
shortcut: None,
|
||||||
selected: None,
|
selected: None,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
|||||||
@ -20,8 +20,8 @@ pub struct PlotHistogram<'ui, 'p> {
|
|||||||
impl<'ui, 'p> PlotHistogram<'ui, 'p> {
|
impl<'ui, 'p> PlotHistogram<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, values: &'p [f32]) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, values: &'p [f32]) -> Self {
|
||||||
PlotHistogram {
|
PlotHistogram {
|
||||||
label: label,
|
label,
|
||||||
values: values,
|
values,
|
||||||
values_offset: 0usize,
|
values_offset: 0usize,
|
||||||
overlay_text: None,
|
overlay_text: None,
|
||||||
scale_min: f32::MAX,
|
scale_min: f32::MAX,
|
||||||
|
|||||||
@ -20,8 +20,8 @@ pub struct PlotLines<'ui, 'p> {
|
|||||||
impl<'ui, 'p> PlotLines<'ui, 'p> {
|
impl<'ui, 'p> PlotLines<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, values: &'p [f32]) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, values: &'p [f32]) -> Self {
|
||||||
PlotLines {
|
PlotLines {
|
||||||
label: label,
|
label,
|
||||||
values: values,
|
values,
|
||||||
values_offset: 0usize,
|
values_offset: 0usize,
|
||||||
overlay_text: None,
|
overlay_text: None,
|
||||||
scale_min: f32::MAX,
|
scale_min: f32::MAX,
|
||||||
|
|||||||
@ -22,7 +22,7 @@ impl<'ui, 'p> ProgressBar<'ui, 'p> {
|
|||||||
/// specified.
|
/// specified.
|
||||||
pub fn new(_: &Ui<'ui>, fraction: f32) -> Self {
|
pub fn new(_: &Ui<'ui>, fraction: f32) -> Self {
|
||||||
ProgressBar {
|
ProgressBar {
|
||||||
fraction: fraction,
|
fraction,
|
||||||
size: ImVec2::new(-1.0, 0.0),
|
size: ImVec2::new(-1.0, 0.0),
|
||||||
overlay_text: None,
|
overlay_text: None,
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
|
|||||||
@ -18,10 +18,10 @@ pub struct SliderInt<'ui, 'p> {
|
|||||||
impl<'ui, 'p> SliderInt<'ui, 'p> {
|
impl<'ui, 'p> SliderInt<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut i32, min: i32, max: i32) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut i32, min: i32, max: i32) -> Self {
|
||||||
SliderInt {
|
SliderInt {
|
||||||
label: label,
|
label,
|
||||||
value: value,
|
value,
|
||||||
min: min,
|
min,
|
||||||
max: max,
|
max,
|
||||||
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.0f\0") },
|
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.0f\0") },
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
@ -65,10 +65,10 @@ macro_rules! impl_slider_intn {
|
|||||||
max: i32,
|
max: i32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
$SliderIntN {
|
$SliderIntN {
|
||||||
label: label,
|
label,
|
||||||
value: value,
|
value,
|
||||||
min: min,
|
min,
|
||||||
max: max,
|
max,
|
||||||
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.0f\0") },
|
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.0f\0") },
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
@ -111,10 +111,10 @@ pub struct SliderFloat<'ui, 'p> {
|
|||||||
impl<'ui, 'p> SliderFloat<'ui, 'p> {
|
impl<'ui, 'p> SliderFloat<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut f32, min: f32, max: f32) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut f32, min: f32, max: f32) -> Self {
|
||||||
SliderFloat {
|
SliderFloat {
|
||||||
label: label,
|
label,
|
||||||
value: value,
|
value,
|
||||||
min: min,
|
min,
|
||||||
max: max,
|
max,
|
||||||
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.3f\0") },
|
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.3f\0") },
|
||||||
power: 1.0,
|
power: 1.0,
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
@ -166,10 +166,10 @@ macro_rules! impl_slider_floatn {
|
|||||||
max: f32,
|
max: f32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
$SliderFloatN {
|
$SliderFloatN {
|
||||||
label: label,
|
label,
|
||||||
value: value,
|
value,
|
||||||
min: min,
|
min,
|
||||||
max: max,
|
max,
|
||||||
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.3f\0") },
|
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.3f\0") },
|
||||||
power: 1.0,
|
power: 1.0,
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::mem;
|
|
||||||
use std::ops::{Deref, Index, RangeFull};
|
use std::ops::{Deref, Index, RangeFull};
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
use std::str;
|
use std::str;
|
||||||
@ -130,7 +129,9 @@ impl Deref for ImString {
|
|||||||
fn deref(&self) -> &ImStr {
|
fn deref(&self) -> &ImStr {
|
||||||
// as_ptr() is used, because we need to look at the bytes to figure out the length
|
// as_ptr() is used, because we need to look at the bytes to figure out the length
|
||||||
// self.0.len() is incorrect, because there might be more than one nul byte in the end
|
// self.0.len() is incorrect, because there might be more than one nul byte in the end
|
||||||
unsafe { mem::transmute(CStr::from_ptr(self.0.as_ptr() as *const c_char)) }
|
unsafe {
|
||||||
|
&*(CStr::from_ptr(self.0.as_ptr() as *const c_char) as *const CStr as *const ImStr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +156,7 @@ impl ImStr {
|
|||||||
s.as_ref()
|
s.as_ref()
|
||||||
}
|
}
|
||||||
pub unsafe fn from_utf8_with_nul_unchecked(bytes: &[u8]) -> &ImStr {
|
pub unsafe fn from_utf8_with_nul_unchecked(bytes: &[u8]) -> &ImStr {
|
||||||
mem::transmute(bytes)
|
&*(bytes as *const [u8] as *const ImStr)
|
||||||
}
|
}
|
||||||
pub fn as_ptr(&self) -> *const c_char {
|
pub fn as_ptr(&self) -> *const c_char {
|
||||||
self.0.as_ptr()
|
self.0.as_ptr()
|
||||||
|
|||||||
@ -16,7 +16,7 @@ pub struct TreeNode<'ui, 'p> {
|
|||||||
impl<'ui, 'p> TreeNode<'ui, 'p> {
|
impl<'ui, 'p> TreeNode<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, id: &'p ImStr) -> Self {
|
pub fn new(_: &Ui<'ui>, id: &'p ImStr) -> Self {
|
||||||
TreeNode {
|
TreeNode {
|
||||||
id: id,
|
id,
|
||||||
label: None,
|
label: None,
|
||||||
opened: false,
|
opened: false,
|
||||||
opened_cond: ImGuiCond::empty(),
|
opened_cond: ImGuiCond::empty(),
|
||||||
@ -126,7 +126,7 @@ pub struct CollapsingHeader<'ui, 'p> {
|
|||||||
impl<'ui, 'p> CollapsingHeader<'ui, 'p> {
|
impl<'ui, 'p> CollapsingHeader<'ui, 'p> {
|
||||||
pub fn new(_: &Ui<'ui>, label: &'p ImStr) -> Self {
|
pub fn new(_: &Ui<'ui>, label: &'p ImStr) -> Self {
|
||||||
CollapsingHeader {
|
CollapsingHeader {
|
||||||
label: label,
|
label,
|
||||||
flags: ImGuiTreeNodeFlags::empty(),
|
flags: ImGuiTreeNodeFlags::empty(),
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ impl<'ui, 'p> Window<'ui, 'p> {
|
|||||||
pos_cond: ImGuiCond::empty(),
|
pos_cond: ImGuiCond::empty(),
|
||||||
size: (0.0, 0.0),
|
size: (0.0, 0.0),
|
||||||
size_cond: ImGuiCond::empty(),
|
size_cond: ImGuiCond::empty(),
|
||||||
name: name,
|
name,
|
||||||
opened: None,
|
opened: None,
|
||||||
flags: ImGuiWindowFlags::empty(),
|
flags: ImGuiWindowFlags::empty(),
|
||||||
border: false,
|
border: false,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user