Add missing PhantomData to builders

I keep forgetting about this :/ :/ :/
This commit is contained in:
Joonas Javanainen 2017-07-12 23:51:24 +03:00
parent eca0ad9ec0
commit a48f0bdbd9
No known key found for this signature in database
GPG Key ID: D39CCA5CB19B9179
6 changed files with 37 additions and 20 deletions

View File

@ -18,6 +18,8 @@
- Button, selectable, histogram, plotlines, and progress bar accept size with `Into<ImVec2>`
- `ImString::new` always succeeds and any interior NULs truncate the string. **Breaking change**
- All builder constructor functions (e.g. Window::new) are no longer public.
The only safe way to construct builders is through a `&Ui` reference.
### Deprecated
@ -25,6 +27,11 @@
- `ImString::from_bytes_unchecked` (renamed to `ImString::from_utf8_unchecked`)
- `ImStr::from_bytes_unchecked` (renamed to `ImStr::from_utf8_with_nul_unchecked`)
### Fixed
- Histogram, plotlines, progressbar builders were not tied to the `&Ui`
lifetime, so it was possible to misuse them.
## [0.0.14] - 2017-06-18
### Added

View File

@ -1,8 +1,7 @@
use imgui_sys;
use ImStr;
use ImVec2;
use ImGuiWindowFlags;
use std::marker::PhantomData;
use super::{ImStr, ImVec2, ImGuiWindowFlags, Ui};
use super::{ImGuiWindowFlags_NoMove, ImGuiWindowFlags_NoScrollbar, ImGuiWindowFlags_NoScrollWithMouse,
ImGuiWindowFlags_NoCollapse, ImGuiWindowFlags_AlwaysAutoResize,
ImGuiWindowFlags_ShowBorders, ImGuiWindowFlags_NoInputs, ImGuiWindowFlags_MenuBar,
@ -11,18 +10,20 @@ use super::{ImGuiWindowFlags_NoMove, ImGuiWindowFlags_NoScrollbar, ImGuiWindowFl
ImGuiWindowFlags_AlwaysHorizontalScrollbar, ImGuiWindowFlags_AlwaysUseWindowPadding};
#[must_use]
pub struct ChildFrame<'p> {
pub struct ChildFrame<'ui, 'p> {
name: &'p ImStr,
size: ImVec2,
flags: ImGuiWindowFlags,
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'p> ChildFrame<'p> {
pub(crate) fn new<S: Into<ImVec2>>(name: &'p ImStr, size: S) -> ChildFrame<'p> {
impl<'ui, 'p> ChildFrame<'ui, 'p> {
pub(crate) fn new<S: Into<ImVec2>>(name: &'p ImStr, size: S) -> ChildFrame<'ui, 'p> {
ChildFrame {
name,
size: size.into(),
flags: ImGuiWindowFlags::empty(),
_phantom: PhantomData,
}
}
#[inline]

View File

@ -715,13 +715,13 @@ impl<'ui> Ui<'ui> {
}
impl<'ui> Ui<'ui> {
pub fn plot_lines<'p>(&self, label: &'p ImStr, values: &'p [f32]) -> PlotLines<'p> {
pub fn plot_lines<'p>(&self, label: &'p ImStr, values: &'p [f32]) -> PlotLines<'ui, 'p> {
PlotLines::new(label, values)
}
}
impl<'ui> Ui<'ui> {
pub fn plot_histogram<'p>(&self, label: &'p ImStr, values: &'p [f32]) -> PlotHistogram<'p> {
pub fn plot_histogram<'p>(&self, label: &'p ImStr, values: &'p [f32]) -> PlotHistogram<'ui, 'p> {
PlotHistogram::new(label, values)
}
}
@ -753,7 +753,7 @@ impl<'ui> Ui<'ui> {
/// .overlay_text(im_str!("Progress!"))
/// .build();
/// ```
pub fn progress_bar<'p>(&self, fraction: f32) -> ProgressBar<'p> { ProgressBar::new(fraction) }
pub fn progress_bar<'p>(&self, fraction: f32) -> ProgressBar<'ui, 'p> { ProgressBar::new(fraction) }
}
impl<'ui> Ui<'ui> {
@ -777,7 +777,7 @@ impl<'ui> Ui<'ui> {
/// ui.text_colored((1.0, 0.0, 0.0, 1.0), im_str!("hello mate!"));
/// });
/// });
pub fn child_frame<'p, S: Into<ImVec2>>(&self, name: &'p ImStr, size: S) -> ChildFrame<'p> { ChildFrame::new(name, size.into()) }
pub fn child_frame<'p, S: Into<ImVec2>>(&self, name: &'p ImStr, size: S) -> ChildFrame<'ui, 'p> { ChildFrame::new(name, size.into()) }
}
impl<'ui> Ui<'ui> {

View File

@ -1,11 +1,12 @@
use imgui_sys;
use std::{f32, mem, ptr};
use std::marker::PhantomData;
use std::os::raw::c_float;
use super::{ImStr, ImVec2};
use super::{ImStr, ImVec2, Ui};
#[must_use]
pub struct PlotHistogram<'p> {
pub struct PlotHistogram<'ui, 'p> {
label: &'p ImStr,
values: &'p [f32],
values_offset: usize,
@ -13,9 +14,10 @@ pub struct PlotHistogram<'p> {
scale_min: f32,
scale_max: f32,
graph_size: ImVec2,
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'p> PlotHistogram<'p> {
impl<'ui, 'p> PlotHistogram<'ui, 'p> {
pub(crate) fn new(label: &'p ImStr, values: &'p [f32]) -> Self {
PlotHistogram {
label: label,
@ -25,6 +27,7 @@ impl<'p> PlotHistogram<'p> {
scale_min: f32::MAX,
scale_max: f32::MAX,
graph_size: ImVec2::new(0.0f32, 0.0f32),
_phantom: PhantomData,
}
}

View File

@ -1,10 +1,12 @@
use imgui_sys;
use std::{f32, mem, ptr};
use std::marker::PhantomData;
use std::os::raw::c_float;
use super::{ImStr, ImVec2};
use super::{ImStr, ImVec2, Ui};
#[must_use]
pub struct PlotLines<'p> {
pub struct PlotLines<'ui, 'p> {
label: &'p ImStr,
values: &'p [f32],
values_offset: usize,
@ -12,9 +14,10 @@ pub struct PlotLines<'p> {
scale_min: f32,
scale_max: f32,
graph_size: ImVec2,
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'p> PlotLines<'p> {
impl<'ui, 'p> PlotLines<'ui, 'p> {
pub(crate) fn new(label: &'p ImStr, values: &'p [f32]) -> Self {
PlotLines {
label: label,
@ -24,6 +27,7 @@ impl<'p> PlotLines<'p> {
scale_min: f32::MAX,
scale_max: f32::MAX,
graph_size: ImVec2::new(0.0f32, 0.0f32),
_phantom: PhantomData,
}
}

View File

@ -1,19 +1,20 @@
#![warn(missing_docs)]
use imgui_sys;
use std::marker::PhantomData;
use std::ptr;
use super::{ImStr, ImVec2};
use super::{ImStr, ImVec2, Ui};
/// Progress bar widget.
#[must_use]
pub struct ProgressBar<'p> {
pub struct ProgressBar<'ui, 'p> {
fraction: f32,
size: ImVec2,
overlay_text: Option<&'p ImStr>,
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'p> ProgressBar<'p> {
impl<'ui, 'p> ProgressBar<'ui, 'p> {
/// Creates a progress bar with a given fraction showing
/// the progress (0.0 = 0%, 1.0 = 100%).
/// The progress bar will be automatically sized to fill
@ -24,6 +25,7 @@ impl<'p> ProgressBar<'p> {
fraction: fraction,
size: ImVec2::new(-1.0, 0.0),
overlay_text: None,
_phantom: PhantomData,
}
}