From eca0ad9ec03e61c64b291e8d175c91de5486db92 Mon Sep 17 00:00:00 2001 From: Joonas Javanainen Date: Wed, 12 Jul 2017 23:39:09 +0300 Subject: [PATCH] Hide all builder "new" functions These are very unsafe when used outside the Ui::* functions. --- src/child_frame.rs | 2 +- src/input.rs | 14 +++++++------- src/menus.rs | 4 ++-- src/plothistogram.rs | 2 +- src/plotlines.rs | 2 +- src/progressbar.rs | 2 +- src/sliders.rs | 8 ++++---- src/trees.rs | 4 ++-- src/window.rs | 2 +- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/child_frame.rs b/src/child_frame.rs index 388a472..84d8ad5 100644 --- a/src/child_frame.rs +++ b/src/child_frame.rs @@ -18,7 +18,7 @@ pub struct ChildFrame<'p> { } impl<'p> ChildFrame<'p> { - pub fn new>(name: &'p ImStr, size: S) -> ChildFrame<'p> { + pub(crate) fn new>(name: &'p ImStr, size: S) -> ChildFrame<'p> { ChildFrame { name, size: size.into(), diff --git a/src/input.rs b/src/input.rs index 8044d56..0e70e2d 100644 --- a/src/input.rs +++ b/src/input.rs @@ -135,7 +135,7 @@ pub struct InputText<'ui, 'p> { } impl<'ui, 'p> InputText<'ui, 'p> { - pub fn new(label: &'p ImStr, buf: &'p mut ImString) -> Self { + pub(crate) fn new(label: &'p ImStr, buf: &'p mut ImString) -> Self { InputText { label: label, buf: buf, @@ -172,7 +172,7 @@ pub struct InputInt<'ui, 'p> { } impl<'ui, 'p> InputInt<'ui, 'p> { - pub fn new(label: &'p ImStr, value: &'p mut i32) -> Self { + pub(crate) fn new(label: &'p ImStr, value: &'p mut i32) -> Self { InputInt { label: label, value: value, @@ -209,7 +209,7 @@ pub struct InputFloat<'ui, 'p> { } impl<'ui, 'p> InputFloat<'ui, 'p> { - pub fn new(label: &'p ImStr, value: &'p mut f32) -> Self { + pub(crate) fn new(label: &'p ImStr, value: &'p mut f32) -> Self { InputFloat { label: label, value: value, @@ -249,7 +249,7 @@ macro_rules! impl_input_floatn { } impl<'ui, 'p> $InputFloatN<'ui, 'p> { - pub fn new(label: &'p ImStr, value: &'p mut [f32;$N]) -> Self { + pub(crate) fn new(label: &'p ImStr, value: &'p mut [f32;$N]) -> Self { $InputFloatN { label: label, value: value, @@ -290,7 +290,7 @@ macro_rules! impl_input_intn { } impl<'ui, 'p> $InputIntN<'ui, 'p> { - pub fn new(label: &'p ImStr, value: &'p mut [i32;$N]) -> Self { + pub(crate) fn new(label: &'p ImStr, value: &'p mut [i32;$N]) -> Self { $InputIntN { label: label, value: value, @@ -325,7 +325,7 @@ pub struct ColorEdit3<'ui, 'p> { } impl<'ui, 'p> ColorEdit3<'ui, 'p> { - pub fn new(label: &'p ImStr, value: &'p mut [f32; 3]) -> Self { + pub(crate) fn new(label: &'p ImStr, value: &'p mut [f32; 3]) -> Self { ColorEdit3 { label: label, value: value, @@ -347,7 +347,7 @@ pub struct ColorEdit4<'ui, 'p> { } impl<'ui, 'p> ColorEdit4<'ui, 'p> { - pub fn new(label: &'p ImStr, value: &'p mut [f32; 4]) -> Self { + pub(crate) fn new(label: &'p ImStr, value: &'p mut [f32; 4]) -> Self { ColorEdit4 { label: label, value: value, diff --git a/src/menus.rs b/src/menus.rs index 08e41ee..6d99e80 100644 --- a/src/menus.rs +++ b/src/menus.rs @@ -12,7 +12,7 @@ pub struct Menu<'ui, 'p> { } impl<'ui, 'p> Menu<'ui, 'p> { - pub fn new(label: &'p ImStr) -> Self { + pub(crate) fn new(label: &'p ImStr) -> Self { Menu { label: label, enabled: true, @@ -43,7 +43,7 @@ pub struct MenuItem<'ui, 'p> { } impl<'ui, 'p> MenuItem<'ui, 'p> { - pub fn new(label: &'p ImStr) -> Self { + pub(crate) fn new(label: &'p ImStr) -> Self { MenuItem { label: label, shortcut: None, diff --git a/src/plothistogram.rs b/src/plothistogram.rs index b134129..f734aae 100644 --- a/src/plothistogram.rs +++ b/src/plothistogram.rs @@ -16,7 +16,7 @@ pub struct PlotHistogram<'p> { } impl<'p> PlotHistogram<'p> { - pub fn new(label: &'p ImStr, values: &'p [f32]) -> Self { + pub(crate) fn new(label: &'p ImStr, values: &'p [f32]) -> Self { PlotHistogram { label: label, values: values, diff --git a/src/plotlines.rs b/src/plotlines.rs index 46d53ff..3566fb5 100644 --- a/src/plotlines.rs +++ b/src/plotlines.rs @@ -15,7 +15,7 @@ pub struct PlotLines<'p> { } impl<'p> PlotLines<'p> { - pub fn new(label: &'p ImStr, values: &'p [f32]) -> Self { + pub(crate) fn new(label: &'p ImStr, values: &'p [f32]) -> Self { PlotLines { label: label, values: values, diff --git a/src/progressbar.rs b/src/progressbar.rs index afe81d2..d316320 100644 --- a/src/progressbar.rs +++ b/src/progressbar.rs @@ -19,7 +19,7 @@ impl<'p> ProgressBar<'p> { /// The progress bar will be automatically sized to fill /// the entire width of the window if no custom size is /// specified. - pub fn new(fraction: f32) -> Self { + pub(crate) fn new(fraction: f32) -> Self { ProgressBar { fraction: fraction, size: ImVec2::new(-1.0, 0.0), diff --git a/src/sliders.rs b/src/sliders.rs index a68aee2..730c618 100644 --- a/src/sliders.rs +++ b/src/sliders.rs @@ -16,7 +16,7 @@ pub struct SliderInt<'ui, 'p> { } impl<'ui, 'p> SliderInt<'ui, 'p> { - pub fn new(label: &'p ImStr, value: &'p mut i32, min: i32, max: i32) -> Self { + pub(crate) fn new(label: &'p ImStr, value: &'p mut i32, min: i32, max: i32) -> Self { SliderInt { label: label, value: value, @@ -55,7 +55,7 @@ macro_rules! impl_slider_intn { } impl<'ui, 'p> $SliderIntN<'ui, 'p> { - pub fn new(label: &'p ImStr, value: &'p mut [i32; $N], min: i32, max: i32) -> Self { + pub(crate) fn new(label: &'p ImStr, value: &'p mut [i32; $N], min: i32, max: i32) -> Self { $SliderIntN { label: label, value: value, @@ -100,7 +100,7 @@ pub struct SliderFloat<'ui, 'p> { } impl<'ui, 'p> SliderFloat<'ui, 'p> { - pub fn new(label: &'p ImStr, value: &'p mut f32, min: f32, max: f32) -> Self { + pub(crate) fn new(label: &'p ImStr, value: &'p mut f32, min: f32, max: f32) -> Self { SliderFloat { label: label, value: value, @@ -147,7 +147,7 @@ macro_rules! impl_slider_floatn { } impl<'ui, 'p> $SliderFloatN<'ui, 'p> { - pub fn new(label: &'p ImStr, value: &'p mut [f32; $N], min: f32, max: f32) -> Self { + pub(crate) fn new(label: &'p ImStr, value: &'p mut [f32; $N], min: f32, max: f32) -> Self { $SliderFloatN { label: label, value: value, diff --git a/src/trees.rs b/src/trees.rs index 7aa713b..c8d2708 100644 --- a/src/trees.rs +++ b/src/trees.rs @@ -16,7 +16,7 @@ pub struct TreeNode<'ui, 'p> { } impl<'ui, 'p> TreeNode<'ui, 'p> { - pub fn new(id: &'p ImStr) -> Self { + pub(crate) fn new(id: &'p ImStr) -> Self { TreeNode { id: id, label: None, @@ -62,7 +62,7 @@ pub struct CollapsingHeader<'ui, 'p> { } impl<'ui, 'p> CollapsingHeader<'ui, 'p> { - pub fn new(label: &'p ImStr) -> Self { + pub(crate) fn new(label: &'p ImStr) -> Self { CollapsingHeader { label: label, flags: ImGuiTreeNodeFlags::empty(), diff --git a/src/window.rs b/src/window.rs index 03840fa..b56ca2e 100644 --- a/src/window.rs +++ b/src/window.rs @@ -26,7 +26,7 @@ pub struct Window<'ui, 'p> { } impl<'ui, 'p> Window<'ui, 'p> { - pub fn new(name: &'p ImStr) -> Window<'ui, 'p> { + pub(crate) fn new(name: &'p ImStr) -> Window<'ui, 'p> { Window { pos: (0.0, 0.0), pos_cond: ImGuiSetCond::empty(),