Replace ImCond with Condition

This commit is contained in:
Joonas Javanainen 2019-06-27 17:29:09 +03:00
parent 2c7ac89564
commit f7a7961cee
No known key found for this signature in database
GPG Key ID: D39CCA5CB19B9179
10 changed files with 57 additions and 55 deletions

View File

@ -16,7 +16,7 @@ fn hello_world<'a>(ui: &Ui<'a>) -> bool {
let window_title = im_str!("Hello world (DirectX)"); let window_title = im_str!("Hello world (DirectX)");
ui.window(window_title) ui.window(window_title)
.size((300.0, 100.0), ImGuiCond::FirstUseEver) .size((300.0, 100.0), Condition::FirstUseEver)
.build(|| { .build(|| {
ui.text(im_str!("Hello world!")); ui.text(im_str!("Hello world!"));
ui.text(im_str!("こんにちは世界!")); ui.text(im_str!("こんにちは世界!"));

View File

@ -39,8 +39,8 @@ fn main() {
fn example_selector(state: &mut State, ui: &Ui) { fn example_selector(state: &mut State, ui: &Ui) {
ui.window(im_str!("Color button examples")) ui.window(im_str!("Color button examples"))
.position((20.0, 20.0), ImGuiCond::Appearing) .position((20.0, 20.0), Condition::Appearing)
.size((700.0, 80.0), ImGuiCond::Appearing) .size((700.0, 80.0), Condition::Appearing)
.resizable(false) .resizable(false)
.build(|| { .build(|| {
let ex1 = ui.radio_button(im_str!("Example 1: Basics"), &mut state.example, 1); let ex1 = ui.radio_button(im_str!("Example 1: Basics"), &mut state.example, 1);
@ -53,8 +53,8 @@ fn example_selector(state: &mut State, ui: &Ui) {
fn example_1(state: &mut State, ui: &Ui) { fn example_1(state: &mut State, ui: &Ui) {
ui.window(im_str!("Example 1: Basics")) ui.window(im_str!("Example 1: Basics"))
.size((700.0, 300.0), ImGuiCond::Appearing) .size((700.0, 300.0), Condition::Appearing)
.position((20.0, 120.0), ImGuiCond::Appearing) .position((20.0, 120.0), Condition::Appearing)
.build(|| { .build(|| {
ui.text_wrapped(im_str!( ui.text_wrapped(im_str!(
"Color button is a widget that displays a color value as a clickable rectangle. \ "Color button is a widget that displays a color value as a clickable rectangle. \
@ -101,8 +101,8 @@ fn example_1(state: &mut State, ui: &Ui) {
fn example_2(ui: &Ui) { fn example_2(ui: &Ui) {
ui.window(im_str!("Example 2: Alpha component")) ui.window(im_str!("Example 2: Alpha component"))
.size((700.0, 320.0), ImGuiCond::Appearing) .size((700.0, 320.0), Condition::Appearing)
.position((20.0, 140.0), ImGuiCond::Appearing) .position((20.0, 140.0), Condition::Appearing)
.build(|| { .build(|| {
ui.text_wrapped(im_str!( ui.text_wrapped(im_str!(
"The displayed color is passed to the button as four float values between \ "The displayed color is passed to the button as four float values between \

View File

@ -71,7 +71,7 @@ impl CustomTexturesApp {
fn show_textures(&self, ui: &Ui) { fn show_textures(&self, ui: &Ui) {
ui.window(im_str!("Hello textures")) ui.window(im_str!("Hello textures"))
.size((400.0, 600.0), ImGuiCond::FirstUseEver) .size((400.0, 600.0), Condition::FirstUseEver)
.build(|| { .build(|| {
ui.text(im_str!("Hello textures!")); ui.text(im_str!("Hello textures!"));
if let Some(my_texture_id) = self.my_texture_id { if let Some(my_texture_id) = self.my_texture_id {

View File

@ -12,7 +12,7 @@ fn main() {
fn hello_world<'a>(ui: &Ui<'a>) -> bool { fn hello_world<'a>(ui: &Ui<'a>) -> bool {
ui.window(im_str!("Hello world")) ui.window(im_str!("Hello world"))
.size((300.0, 100.0), ImGuiCond::FirstUseEver) .size((300.0, 100.0), Condition::FirstUseEver)
.build(|| { .build(|| {
ui.text(im_str!("Hello world!")); ui.text(im_str!("Hello world!"));
ui.text(im_str!("こんにちは世界!")); ui.text(im_str!("こんにちは世界!"));

View File

@ -284,7 +284,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
.scroll_bar(!state.no_scrollbar) .scroll_bar(!state.no_scrollbar)
.collapsible(!state.no_collapse) .collapsible(!state.no_collapse)
.menu_bar(!state.no_menu) .menu_bar(!state.no_menu)
.size((550.0, 680.0), ImGuiCond::FirstUseEver); .size((550.0, 680.0), Condition::FirstUseEver);
if !state.no_close { if !state.no_close {
window = window.opened(opened) window = window.opened(opened)
} }
@ -810,7 +810,7 @@ fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) {
ui.with_color_var(ImGuiCol::WindowBg, (0.0, 0.0, 0.0, 0.3), || { ui.with_color_var(ImGuiCol::WindowBg, (0.0, 0.0, 0.0, 0.3), || {
ui.window(im_str!("Example: Fixed Overlay")) ui.window(im_str!("Example: Fixed Overlay"))
.opened(opened) .opened(opened)
.position(window_pos, ImGuiCond::Always) .position(window_pos, Condition::Always)
.title_bar(false) .title_bar(false)
.resizable(false) .resizable(false)
.always_auto_resize(true) .always_auto_resize(true)
@ -830,7 +830,7 @@ fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) {
fn show_example_app_manipulating_window_title(ui: &Ui) { fn show_example_app_manipulating_window_title(ui: &Ui) {
ui.window(im_str!("Same title as another window##1")) ui.window(im_str!("Same title as another window##1"))
.position((100.0, 100.0), ImGuiCond::FirstUseEver) .position((100.0, 100.0), Condition::FirstUseEver)
.build(|| { .build(|| {
ui.text( ui.text(
"This is window 1. "This is window 1.
@ -838,7 +838,7 @@ My title is the same as window 2, but my identifier is unique.",
); );
}); });
ui.window(im_str!("Same title as another window##2")) ui.window(im_str!("Same title as another window##2"))
.position((100.0, 200.0), ImGuiCond::FirstUseEver) .position((100.0, 200.0), Condition::FirstUseEver)
.build(|| { .build(|| {
ui.text( ui.text(
"This is window 2. "This is window 2.
@ -850,13 +850,13 @@ My title is the same as window 1, but my identifier is unique.",
let num = ui.imgui().get_frame_count(); // The C++ version uses rand() here let num = ui.imgui().get_frame_count(); // The C++ version uses rand() here
let title = im_str!("Animated title {} {}###AnimatedTitle", chars[ch_idx], num); let title = im_str!("Animated title {} {}###AnimatedTitle", chars[ch_idx], num);
ui.window(title) ui.window(title)
.position((100.0, 300.0), ImGuiCond::FirstUseEver) .position((100.0, 300.0), Condition::FirstUseEver)
.build(|| ui.text("This window has a changing title")); .build(|| ui.text("This window has a changing title"));
} }
fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState, opened: &mut bool) { fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState, opened: &mut bool) {
ui.window(im_str!("Example: Custom rendering")) ui.window(im_str!("Example: Custom rendering"))
.size((350.0, 560.0), ImGuiCond::FirstUseEver) .size((350.0, 560.0), Condition::FirstUseEver)
.opened(opened) .opened(opened)
.build(|| { .build(|| {
ui.text("Primitives"); ui.text("Primitives");

View File

@ -96,23 +96,6 @@ bitflags!(
} }
); );
bitflags!(
/// Condition flags
#[repr(C)]
pub struct ImGuiCond: c_int {
/// Set the variable
const Always = 1;
/// Set the variable once per runtime session (only the first call with succeed)
const Once = 1 << 1;
/// Set the variable if the object/window has no persistently saved data (no entry in .ini
/// file)
const FirstUseEver = 1 << 2;
/// Set the variable if the object/window is appearing after being hidden/inactive (or the
/// first time)
const Appearing = 1 << 3;
}
);
bitflags!( bitflags!(
/// Configuration flags /// Configuration flags
#[repr(C)] #[repr(C)]

View File

@ -37,9 +37,10 @@ pub use bindings::{
ImFontAtlas_GetGlyphRangesDefault, ImFontAtlas_GetGlyphRangesJapanese, ImFontAtlas_GetGlyphRangesDefault, ImFontAtlas_GetGlyphRangesJapanese,
ImFontAtlas_GetGlyphRangesKorean, ImFontAtlas_GetGlyphRangesThai, ImFontAtlas_GetGlyphRangesKorean, ImFontAtlas_GetGlyphRangesThai,
ImFontAtlas_GetGlyphRangesVietnamese, ImFontAtlas_GetTexDataAsRGBA32, ImFontConfig, ImFontAtlas_GetGlyphRangesVietnamese, ImFontAtlas_GetTexDataAsRGBA32, ImFontConfig,
ImFontGlyphRangesBuilder, ImGuiContext, ImGuiID, ImGuiIO, ImGuiIO_AddInputCharacter, ImFontGlyphRangesBuilder, ImGuiCond, ImGuiCond_, ImGuiCond_Always, ImGuiCond_Appearing,
ImGuiIO_AddInputCharactersUTF8, ImGuiIO_ClearInputCharacters, ImGuiInputTextCallback, ImGuiCond_FirstUseEver, ImGuiCond_Once, ImGuiContext, ImGuiID, ImGuiIO,
ImGuiInputTextCallbackData, ImGuiInputTextCallbackData_DeleteChars, ImGuiIO_AddInputCharacter, ImGuiIO_AddInputCharactersUTF8, ImGuiIO_ClearInputCharacters,
ImGuiInputTextCallback, ImGuiInputTextCallbackData, ImGuiInputTextCallbackData_DeleteChars,
ImGuiInputTextCallbackData_HasSelection, ImGuiInputTextCallbackData_ImGuiInputTextCallbackData, ImGuiInputTextCallbackData_HasSelection, ImGuiInputTextCallbackData_ImGuiInputTextCallbackData,
ImGuiInputTextCallbackData_InsertChars, ImGuiInputTextCallbackData_destroy, ImGuiListClipper, ImGuiInputTextCallbackData_InsertChars, ImGuiInputTextCallbackData_destroy, ImGuiListClipper,
ImGuiPayload, ImGuiSizeCallback, ImGuiStorage, ImGuiTextBuffer, ImGuiTextFilter, ImTextureID, ImGuiPayload, ImGuiSizeCallback, ImGuiStorage, ImGuiTextBuffer, ImGuiTextFilter, ImTextureID,

View File

@ -36,9 +36,9 @@ pub use self::sliders::{
pub use self::string::{ImStr, ImString}; pub use self::string::{ImStr, ImString};
pub use self::style::StyleVar; pub use self::style::StyleVar;
pub use self::sys::{ pub use self::sys::{
ImDrawIdx, ImDrawVert, ImGuiCol, ImGuiColorEditFlags, ImGuiCond, ImGuiFocusedFlags, ImDrawIdx, ImDrawVert, ImGuiCol, ImGuiColorEditFlags, ImGuiFocusedFlags, ImGuiHoveredFlags,
ImGuiHoveredFlags, ImGuiInputTextFlags, ImGuiKey, ImGuiMouseCursor, ImGuiSelectableFlags, ImGuiInputTextFlags, ImGuiKey, ImGuiMouseCursor, ImGuiSelectableFlags, ImGuiStyle,
ImGuiStyle, ImGuiTreeNodeFlags, ImGuiWindowFlags, ImVec2, ImVec4, ImGuiTreeNodeFlags, ImGuiWindowFlags, ImVec2, ImVec4,
}; };
pub use self::trees::{CollapsingHeader, TreeNode}; pub use self::trees::{CollapsingHeader, TreeNode};
pub use self::window::Window; pub use self::window::Window;
@ -1730,3 +1730,21 @@ impl<'ui> Ui<'ui> {
WindowDrawList::new(self) WindowDrawList::new(self)
} }
} }
/// Condition for applying a setting
#[repr(i8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Condition {
/// Never apply the setting
Never = -1,
/// Always apply the setting
Always = sys::ImGuiCond_Always as i8,
/// Apply the setting once per runtime session (only the first call will succeed)
Once = sys::ImGuiCond_Once as i8,
/// Apply the setting if the object/window has no persistently saved data (no entry in .ini
/// file)
FirstUseEver = sys::ImGuiCond_FirstUseEver as i8,
/// Apply the setting if the object/window is appearing after being hidden/inactive (or the
/// first time)
Appearing = sys::ImGuiCond_Appearing as i8,
}

View File

@ -1,14 +1,14 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use sys; use sys;
use super::{ImGuiCond, ImGuiTreeNodeFlags, ImStr, Ui}; use super::{Condition, ImGuiTreeNodeFlags, ImStr, Ui};
#[must_use] #[must_use]
pub struct TreeNode<'ui, 'p> { pub struct TreeNode<'ui, 'p> {
id: &'p ImStr, id: &'p ImStr,
label: Option<&'p ImStr>, label: Option<&'p ImStr>,
opened: bool, opened: bool,
opened_cond: ImGuiCond, opened_cond: Condition,
flags: ImGuiTreeNodeFlags, flags: ImGuiTreeNodeFlags,
_phantom: PhantomData<&'ui Ui<'ui>>, _phantom: PhantomData<&'ui Ui<'ui>>,
} }
@ -19,7 +19,7 @@ impl<'ui, 'p> TreeNode<'ui, 'p> {
id, id,
label: None, label: None,
opened: false, opened: false,
opened_cond: ImGuiCond::empty(), opened_cond: Condition::Never,
flags: ImGuiTreeNodeFlags::empty(), flags: ImGuiTreeNodeFlags::empty(),
_phantom: PhantomData, _phantom: PhantomData,
} }
@ -30,7 +30,7 @@ impl<'ui, 'p> TreeNode<'ui, 'p> {
self self
} }
#[inline] #[inline]
pub fn opened(mut self, opened: bool, cond: ImGuiCond) -> Self { pub fn opened(mut self, opened: bool, cond: Condition) -> Self {
self.opened = opened; self.opened = opened;
self.opened_cond = cond; self.opened_cond = cond;
self self
@ -97,8 +97,8 @@ impl<'ui, 'p> TreeNode<'ui, 'p> {
} }
pub fn build<F: FnOnce()>(self, f: F) { pub fn build<F: FnOnce()>(self, f: F) {
let render = unsafe { let render = unsafe {
if !self.opened_cond.is_empty() { if self.opened_cond != Condition::Never {
sys::igSetNextItemOpen(self.opened, self.opened_cond); sys::igSetNextItemOpen(self.opened, self.opened_cond as _);
} }
sys::igTreeNodeExStrStr( sys::igTreeNodeExStrStr(
self.id.as_ptr(), self.id.as_ptr(),

View File

@ -2,15 +2,15 @@ use std::marker::PhantomData;
use std::ptr; use std::ptr;
use sys; use sys;
use super::{ImGuiCond, ImGuiWindowFlags, ImStr, Ui}; use super::{Condition, ImGuiWindowFlags, ImStr, Ui};
#[must_use] #[must_use]
pub struct Window<'ui, 'p> { pub struct Window<'ui, 'p> {
pos: (f32, f32), pos: (f32, f32),
pos_cond: ImGuiCond, pos_cond: Condition,
pos_pivot: (f32, f32), pos_pivot: (f32, f32),
size: (f32, f32), size: (f32, f32),
size_cond: ImGuiCond, size_cond: Condition,
name: &'p ImStr, name: &'p ImStr,
opened: Option<&'p mut bool>, opened: Option<&'p mut bool>,
flags: ImGuiWindowFlags, flags: ImGuiWindowFlags,
@ -21,10 +21,10 @@ impl<'ui, 'p> Window<'ui, 'p> {
pub fn new(_: &Ui<'ui>, name: &'p ImStr) -> Window<'ui, 'p> { pub fn new(_: &Ui<'ui>, name: &'p ImStr) -> Window<'ui, 'p> {
Window { Window {
pos: (0.0, 0.0), pos: (0.0, 0.0),
pos_cond: ImGuiCond::empty(), pos_cond: Condition::Never,
pos_pivot: (0.0, 0.0), pos_pivot: (0.0, 0.0),
size: (0.0, 0.0), size: (0.0, 0.0),
size_cond: ImGuiCond::empty(), size_cond: Condition::Never,
name, name,
opened: None, opened: None,
flags: ImGuiWindowFlags::empty(), flags: ImGuiWindowFlags::empty(),
@ -32,7 +32,7 @@ impl<'ui, 'p> Window<'ui, 'p> {
} }
} }
#[inline] #[inline]
pub fn position(mut self, pos: (f32, f32), cond: ImGuiCond) -> Self { pub fn position(mut self, pos: (f32, f32), cond: Condition) -> Self {
self.pos = pos; self.pos = pos;
self.pos_cond = cond; self.pos_cond = cond;
self self
@ -43,7 +43,7 @@ impl<'ui, 'p> Window<'ui, 'p> {
self self
} }
#[inline] #[inline]
pub fn size(mut self, size: (f32, f32), cond: ImGuiCond) -> Self { pub fn size(mut self, size: (f32, f32), cond: Condition) -> Self {
self.size = size; self.size = size;
self.size_cond = cond; self.size_cond = cond;
self self
@ -144,11 +144,11 @@ impl<'ui, 'p> Window<'ui, 'p> {
} }
pub fn build<F: FnOnce()>(self, f: F) { pub fn build<F: FnOnce()>(self, f: F) {
let render = unsafe { let render = unsafe {
if !self.pos_cond.is_empty() { if self.pos_cond != Condition::Never {
sys::igSetNextWindowPos(self.pos.into(), self.pos_cond, self.pos_pivot.into()); sys::igSetNextWindowPos(self.pos.into(), self.pos_cond as _, self.pos_pivot.into());
} }
if !self.size_cond.is_empty() { if self.size_cond != Condition::Never {
sys::igSetNextWindowSize(self.size.into(), self.size_cond); sys::igSetNextWindowSize(self.size.into(), self.size_cond as _);
} }
sys::igBegin( sys::igBegin(
self.name.as_ptr(), self.name.as_ptr(),