forked from imgui-rs/imgui-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
use imgui_sys; | ||
use libc::size_t; | ||
use std::marker::PhantomData; | ||
use std::ptr; | ||
|
||
use super::{ | ||
Ui, | ||
ImGuiInputTextFlags, ImGuiInputTextFlags_CharsDecimal, ImGuiInputTextFlags_CharsHexadecimal, | ||
ImGuiInputTextFlags_CharsUppercase, ImGuiInputTextFlags_CharsNoBlank, | ||
ImGuiInputTextFlags_AutoSelectAll, ImGuiInputTextFlags_EnterReturnsTrue, | ||
ImGuiInputTextFlags_CallbackCompletion, ImGuiInputTextFlags_CallbackHistory, | ||
ImGuiInputTextFlags_CallbackAlways, ImGuiInputTextFlags_CallbackCharFilter, | ||
ImGuiInputTextFlags_AllowTabInput, //ImGuiInputTextFlags_CtrlEnterForNewLine, | ||
ImGuiInputTextFlags_NoHorizontalScroll, ImGuiInputTextFlags_AlwaysInsertMode, | ||
ImStr | ||
}; | ||
|
||
#[must_use] | ||
pub struct InputText<'ui, 'p> { | ||
label: ImStr<'p>, | ||
buf: &'p mut str, | ||
flags: ImGuiInputTextFlags, | ||
_phantom: PhantomData<&'ui Ui<'ui>> | ||
} | ||
|
||
impl<'ui, 'p> InputText<'ui, 'p> { | ||
pub fn new(label: ImStr<'p>, buf: &'p mut str) -> Self { | ||
InputText { | ||
label: label, | ||
buf: buf, | ||
flags: ImGuiInputTextFlags::empty(), | ||
_phantom: PhantomData | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn flags(self, flags: ImGuiInputTextFlags) -> Self { | ||
InputText { | ||
flags: flags, | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn chars_decimal(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_CharsDecimal, value), | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn chars_hexadecimal(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_CharsHexadecimal, value), | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn chars_uppercase(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_CharsUppercase, value), | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn chars_noblank(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_CharsNoBlank, value), | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn auto_select_all(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_AutoSelectAll, value), | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn enter_returns_true(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_EnterReturnsTrue, value), | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn callback_completion(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_CallbackCompletion, value), | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn callback_history(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_CallbackHistory, value), | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn callback_always(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_CallbackAlways, value), | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn callback_char_filter(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_CallbackCharFilter, value), | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn allow_tab_input(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_AllowTabInput, value), | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn no_horizontal_scroll(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_NoHorizontalScroll, value), | ||
.. self | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn always_insert_mode(self, value: bool) -> Self { | ||
InputText { | ||
flags: self.flags.with(ImGuiInputTextFlags_AlwaysInsertMode, value), | ||
.. self | ||
} | ||
} | ||
|
||
// TODO: boxed closure...? | ||
// pub fn callback(self) -> Self { } | ||
|
||
pub fn build(self) -> bool { | ||
unsafe { | ||
imgui_sys::igInputText( | ||
self.label.as_ptr(), | ||
// TODO: this is evil. Perhaps something else than &mut str is better | ||
self.buf.as_ptr() as *mut i8, | ||
self.buf.len() as size_t, | ||
self.flags, | ||
None, | ||
ptr::null_mut()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters