Add input_text_multiline

This commit is contained in:
OKAMURA, Yasunobu 2018-04-30 15:14:31 +09:00
parent 1bdb2226d2
commit 9b283bbad0
4 changed files with 58 additions and 1 deletions

View File

@ -2,6 +2,10 @@
## [Unreleased]
### Added
- `input_text_multiline`
## [0.0.18] - 2017-12-23
### Added

View File

@ -34,6 +34,7 @@ struct State {
item: i32,
item2: i32,
text: ImString,
text_multiline: ImString,
i0: i32,
f0: f32,
vec2f: [f32; 2],
@ -56,6 +57,8 @@ impl Default for State {
buf.push_str("日本語");
let mut text = ImString::with_capacity(128);
text.push_str("Hello, world!");
let mut text_mutiline = ImString::with_capacity(128);
text_mutiline.push_str("Hello, world!\nMultiline");
State {
show_app_main_menu_bar: false,
show_app_console: false,
@ -83,6 +86,7 @@ impl Default for State {
item: 0,
item2: 0,
text: text,
text_multiline: text_mutiline,
i0: 123,
f0: 0.001,
vec2f: [0.10, 0.20],
@ -382,6 +386,11 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
ui.text_colored((1.0, 1.0, 0.0, 1.0), im_str!("Yellow"));
ui.text_disabled(im_str!("Disabled"));
});
ui.tree_node(im_str!("Multi-line text")).build(|| {
ui.input_text_multiline(im_str!("multiline"), &mut state.text_multiline, (300., 100.)).build();
});
ui.tree_node(im_str!("Word Wrapping")).build(|| {
ui.text_wrapped(im_str!(
"This text should automatically wrap on the edge of \

View File

@ -155,6 +155,47 @@ impl<'ui, 'p> InputText<'ui, 'p> {
}
}
#[must_use]
pub struct InputTextMultiline<'ui, 'p> {
label: &'p ImStr,
buf: &'p mut ImString,
flags: ImGuiInputTextFlags,
size: sys::ImVec2,
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'ui, 'p> InputTextMultiline<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, buf: &'p mut ImString, size: sys::ImVec2) -> Self {
InputTextMultiline {
label: label,
buf: buf,
flags: ImGuiInputTextFlags::empty(),
size: size,
_phantom: PhantomData,
}
}
impl_text_flags!(InputText);
// TODO: boxed closure...?
// pub fn callback(self) -> Self { }
pub fn build(self) -> bool {
unsafe {
sys::igInputTextMultiline(
self.label.as_ptr(),
self.buf.as_mut_ptr(),
self.buf.capacity_with_nul(),
self.size,
self.flags,
None,
ptr::null_mut(),
)
}
}
}
#[must_use]
pub struct InputInt<'ui, 'p> {
label: &'p ImStr,

View File

@ -18,7 +18,7 @@ pub use drag::{DragFloat, DragFloat2, DragFloat3, DragFloat4, DragInt, DragInt2,
DragInt4, DragFloatRange2, DragIntRange2};
pub use fonts::{FontGlyphRange, ImFontAtlas, ImFont, ImFontConfig};
pub use input::{InputFloat, InputFloat2, InputFloat3, InputFloat4, InputInt, InputInt2, InputInt3,
InputInt4, InputText};
InputInt4, InputText, InputTextMultiline};
pub use menus::{Menu, MenuItem};
pub use plothistogram::PlotHistogram;
pub use plotlines::PlotLines;
@ -639,6 +639,9 @@ impl<'ui> Ui<'ui> {
pub fn input_text<'p>(&self, label: &'p ImStr, buf: &'p mut ImString) -> InputText<'ui, 'p> {
InputText::new(self, label, buf)
}
pub fn input_text_multiline<'p, S: Into<ImVec2>>(&self, label: &'p ImStr, buf: &'p mut ImString, size: S) -> InputTextMultiline<'ui, 'p> {
InputTextMultiline::new(self, label, buf, size.into())
}
pub fn input_float<'p>(&self, label: &'p ImStr, value: &'p mut f32) -> InputFloat<'ui, 'p> {
InputFloat::new(self, label, value)
}