mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-24 03:48:30 +00:00
add input_text hinting
This commit is contained in:
parent
b3f5558557
commit
3d3097e222
@ -30,6 +30,7 @@ struct State {
|
|||||||
item2: usize,
|
item2: usize,
|
||||||
item3: i32,
|
item3: i32,
|
||||||
text: ImString,
|
text: ImString,
|
||||||
|
text_with_hint: ImString,
|
||||||
text_multiline: ImString,
|
text_multiline: ImString,
|
||||||
i0: i32,
|
i0: i32,
|
||||||
f0: f32,
|
f0: f32,
|
||||||
@ -60,6 +61,7 @@ impl Default for State {
|
|||||||
buf.push_str("日本語");
|
buf.push_str("日本語");
|
||||||
let mut text = ImString::with_capacity(128);
|
let mut text = ImString::with_capacity(128);
|
||||||
text.push_str("Hello, world!");
|
text.push_str("Hello, world!");
|
||||||
|
let text_with_hint = ImString::with_capacity(128);
|
||||||
let mut text_multiline = ImString::with_capacity(128);
|
let mut text_multiline = ImString::with_capacity(128);
|
||||||
text_multiline.push_str("Hello, world!\nMultiline");
|
text_multiline.push_str("Hello, world!\nMultiline");
|
||||||
State {
|
State {
|
||||||
@ -90,6 +92,7 @@ impl Default for State {
|
|||||||
item2: 0,
|
item2: 0,
|
||||||
item3: 0,
|
item3: 0,
|
||||||
text,
|
text,
|
||||||
|
text_with_hint,
|
||||||
text_multiline,
|
text_multiline,
|
||||||
i0: 123,
|
i0: 123,
|
||||||
f0: 0.001,
|
f0: 0.001,
|
||||||
@ -533,6 +536,9 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
|
|||||||
|
|
||||||
ui.input_text(im_str!("input text"), &mut state.text)
|
ui.input_text(im_str!("input text"), &mut state.text)
|
||||||
.build();
|
.build();
|
||||||
|
ui.input_text(im_str!("input text with hint"), &mut state.text_with_hint)
|
||||||
|
.hint(im_str!("enter text here"))
|
||||||
|
.build();
|
||||||
ui.input_int(im_str!("input int"), &mut state.i0).build();
|
ui.input_int(im_str!("input int"), &mut state.i0).build();
|
||||||
Drag::new(im_str!("drag int")).build(ui, &mut state.i0);
|
Drag::new(im_str!("drag int")).build(ui, &mut state.i0);
|
||||||
ui.input_float(im_str!("input float"), &mut state.f0)
|
ui.input_float(im_str!("input float"), &mut state.f0)
|
||||||
|
|||||||
@ -159,6 +159,7 @@ extern "C" fn resize_callback(data: *mut sys::ImGuiInputTextCallbackData) -> c_i
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct InputText<'ui, 'p> {
|
pub struct InputText<'ui, 'p> {
|
||||||
label: &'p ImStr,
|
label: &'p ImStr,
|
||||||
|
hint: Option<&'p ImStr>,
|
||||||
buf: &'p mut ImString,
|
buf: &'p mut ImString,
|
||||||
flags: ImGuiInputTextFlags,
|
flags: ImGuiInputTextFlags,
|
||||||
_phantom: PhantomData<&'ui Ui<'ui>>,
|
_phantom: PhantomData<&'ui Ui<'ui>>,
|
||||||
@ -168,12 +169,20 @@ 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,
|
||||||
|
hint: None,
|
||||||
buf,
|
buf,
|
||||||
flags: ImGuiInputTextFlags::empty(),
|
flags: ImGuiInputTextFlags::empty(),
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the hint displayed in the input text background.
|
||||||
|
#[inline]
|
||||||
|
pub fn hint(mut self, hint: &'p ImStr) -> Self {
|
||||||
|
self.hint = Some(hint);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
impl_text_flags!(InputText);
|
impl_text_flags!(InputText);
|
||||||
|
|
||||||
// TODO: boxed closure...?
|
// TODO: boxed closure...?
|
||||||
@ -190,14 +199,26 @@ impl<'ui, 'p> InputText<'ui, 'p> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let result = sys::igInputText(
|
let result = if let Some(hint) = self.hint {
|
||||||
self.label.as_ptr(),
|
sys::igInputTextWithHint(
|
||||||
ptr,
|
self.label.as_ptr(),
|
||||||
capacity,
|
hint.as_ptr(),
|
||||||
self.flags.bits(),
|
ptr,
|
||||||
callback,
|
capacity,
|
||||||
data,
|
self.flags.bits(),
|
||||||
);
|
callback,
|
||||||
|
data,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
sys::igInputText(
|
||||||
|
self.label.as_ptr(),
|
||||||
|
ptr,
|
||||||
|
capacity,
|
||||||
|
self.flags.bits(),
|
||||||
|
callback,
|
||||||
|
data,
|
||||||
|
)
|
||||||
|
};
|
||||||
self.buf.refresh_len();
|
self.buf.refresh_len();
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user