mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-12 05:58:35 +00:00
Add some layout functions, improve docs
This commit is contained in:
parent
965dd40876
commit
597f51410b
@ -87,6 +87,7 @@ impl FocusedWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// # Input: Keyboard
|
||||
impl<'ui> Ui<'ui> {
|
||||
/// Returns the key index of the given key identifier.
|
||||
///
|
||||
|
||||
@ -75,6 +75,7 @@ fn test_mouse_cursor_variants() {
|
||||
}
|
||||
}
|
||||
|
||||
/// # Input: Mouse
|
||||
impl<'ui> Ui<'ui> {
|
||||
/// Returns true if the given mouse button is held down.
|
||||
///
|
||||
|
||||
54
src/layout.rs
Normal file
54
src/layout.rs
Normal file
@ -0,0 +1,54 @@
|
||||
use crate::sys;
|
||||
use crate::Ui;
|
||||
|
||||
/// # Cursor/layout
|
||||
impl<'ui> Ui<'ui> {
|
||||
/// Renders a separator (generally horizontal).
|
||||
///
|
||||
/// This becomes a vertical separator inside a menu bar or in horizontal layout mode.
|
||||
pub fn separator(&self) {
|
||||
unsafe { sys::igSeparator() }
|
||||
}
|
||||
/// Call between widgets or groups to layout them horizontally.
|
||||
///
|
||||
/// X position is given in window coordinates.
|
||||
pub fn same_line(&self, pos_x: f32) {
|
||||
unsafe { sys::igSameLine(pos_x, -1.0f32) }
|
||||
}
|
||||
/// Call between widgets or groups to layout them horizontally.
|
||||
///
|
||||
/// X position is given in window coordinates.
|
||||
pub fn same_line_with_spacing(&self, pos_x: f32, spacing_w: f32) {
|
||||
unsafe { sys::igSameLine(pos_x, spacing_w) }
|
||||
}
|
||||
/// Undo a `same_line` call or force a new line when in horizontal layout mode
|
||||
pub fn new_line(&self) {
|
||||
unsafe { sys::igNewLine() }
|
||||
}
|
||||
/// Adds vertical spacing
|
||||
pub fn spacing(&self) {
|
||||
unsafe { sys::igSpacing() }
|
||||
}
|
||||
/// Fill a space of `size` in pixels with nothing on the current window.
|
||||
///
|
||||
/// Can be used to move the cursor on the window.
|
||||
pub fn dummy(&self, size: [f32; 2]) {
|
||||
unsafe { sys::igDummy(size.into()) }
|
||||
}
|
||||
/// Move content position to the right by `Style::indent_spacing`
|
||||
pub fn indent(&self) {
|
||||
unsafe { sys::igIndent(0.0) };
|
||||
}
|
||||
/// Move content position to the right by `width`
|
||||
pub fn indent_by(&self, width: f32) {
|
||||
unsafe { sys::igIndent(width) };
|
||||
}
|
||||
/// Move content position to the left by `Style::indent_spacing`
|
||||
pub fn unindent(&self) {
|
||||
unsafe { sys::igUnindent(0.0) };
|
||||
}
|
||||
/// Move content position to the left by `width`
|
||||
pub fn unindent_by(&self, width: f32) {
|
||||
unsafe { sys::igUnindent(width) };
|
||||
}
|
||||
}
|
||||
91
src/lib.rs
91
src/lib.rs
@ -61,6 +61,7 @@ mod input;
|
||||
mod input_widget;
|
||||
pub mod internal;
|
||||
mod io;
|
||||
mod layout;
|
||||
mod legacy;
|
||||
mod menus;
|
||||
mod plothistogram;
|
||||
@ -143,32 +144,6 @@ impl<'ui> Ui<'ui> {
|
||||
&*(sys::igGetDrawData() as *mut DrawData)
|
||||
}
|
||||
}
|
||||
pub fn show_demo_window(&self, opened: &mut bool) {
|
||||
unsafe {
|
||||
sys::igShowDemoWindow(opened);
|
||||
}
|
||||
}
|
||||
pub fn show_about_window(&self, opened: &mut bool) {
|
||||
unsafe {
|
||||
sys::igShowAboutWindow(opened);
|
||||
}
|
||||
}
|
||||
pub fn show_metrics_window(&self, opened: &mut bool) {
|
||||
unsafe {
|
||||
sys::igShowMetricsWindow(opened);
|
||||
}
|
||||
}
|
||||
pub fn show_style_editor(&self, style: &mut Style) {
|
||||
unsafe {
|
||||
sys::igShowStyleEditor(style.raw_mut());
|
||||
}
|
||||
}
|
||||
pub fn show_default_style_editor(&self) {
|
||||
unsafe { sys::igShowStyleEditor(ptr::null_mut()) };
|
||||
}
|
||||
pub fn show_user_guide(&self) {
|
||||
unsafe { sys::igShowUserGuide() };
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for Ui<'a> {
|
||||
@ -181,6 +156,48 @@ impl<'a> Drop for Ui<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// # Demo, debug, information
|
||||
impl<'ui> Ui<'ui> {
|
||||
/// Renders a demo window (previously called a test window), which demonstrates most
|
||||
/// Dear Imgui features.
|
||||
pub fn show_demo_window(&self, opened: &mut bool) {
|
||||
unsafe {
|
||||
sys::igShowDemoWindow(opened);
|
||||
}
|
||||
}
|
||||
/// Renders an about window.
|
||||
///
|
||||
/// Displays the Dear ImGui version/credits, and build/system information.
|
||||
pub fn show_about_window(&self, opened: &mut bool) {
|
||||
unsafe {
|
||||
sys::igShowAboutWindow(opened);
|
||||
}
|
||||
}
|
||||
/// Renders a metrics/debug window.
|
||||
///
|
||||
/// Displays Dear ImGui internals: draw commands (with individual draw calls and vertices),
|
||||
/// window list, basic internal state, etc.
|
||||
pub fn show_metrics_window(&self, opened: &mut bool) {
|
||||
unsafe {
|
||||
sys::igShowMetricsWindow(opened);
|
||||
}
|
||||
}
|
||||
/// Renders a style editor block (not a window) for the given `Style` structure
|
||||
pub fn show_style_editor(&self, style: &mut Style) {
|
||||
unsafe {
|
||||
sys::igShowStyleEditor(style.raw_mut());
|
||||
}
|
||||
}
|
||||
/// Renders a style editor block (not a window) for the currently active style
|
||||
pub fn show_default_style_editor(&self) {
|
||||
unsafe { sys::igShowStyleEditor(ptr::null_mut()) };
|
||||
}
|
||||
/// Renders a basic help/info block (not a window)
|
||||
pub fn show_user_guide(&self) {
|
||||
unsafe { sys::igShowUserGuide() };
|
||||
}
|
||||
}
|
||||
|
||||
// Window
|
||||
impl<'ui> Ui<'ui> {
|
||||
pub fn window<'p>(&self, name: &'p ImStr) -> Window<'ui, 'p> {
|
||||
@ -210,22 +227,6 @@ impl<'ui> Ui<'ui> {
|
||||
|
||||
// Layout
|
||||
impl<'ui> Ui<'ui> {
|
||||
pub fn separator(&self) {
|
||||
unsafe { sys::igSeparator() };
|
||||
}
|
||||
pub fn new_line(&self) {
|
||||
unsafe { sys::igNewLine() }
|
||||
}
|
||||
pub fn same_line(&self, pos_x: f32) {
|
||||
unsafe { sys::igSameLine(pos_x, -1.0f32) }
|
||||
}
|
||||
pub fn same_line_spacing(&self, pos_x: f32, spacing_w: f32) {
|
||||
unsafe { sys::igSameLine(pos_x, spacing_w) }
|
||||
}
|
||||
pub fn spacing(&self) {
|
||||
unsafe { sys::igSpacing() };
|
||||
}
|
||||
|
||||
pub fn columns<'p>(&self, count: i32, id: &'p ImStr, border: bool) {
|
||||
unsafe { sys::igColumns(count, id.as_ptr(), border) }
|
||||
}
|
||||
@ -254,12 +255,6 @@ impl<'ui> Ui<'ui> {
|
||||
unsafe { sys::igGetColumnsCount() }
|
||||
}
|
||||
|
||||
/// Fill a space of `size` in pixels with nothing on the current window.
|
||||
/// Can be used to move the cursor on the window.
|
||||
pub fn dummy(&self, size: [f32; 2]) {
|
||||
unsafe { sys::igDummy(size.into()) }
|
||||
}
|
||||
|
||||
/// Get cursor position on the screen, in screen coordinates.
|
||||
/// This sets the point on which the next widget will be drawn.
|
||||
///
|
||||
|
||||
@ -230,7 +230,7 @@ impl<'ui> Ui<'ui> {
|
||||
/// Changes the text wrapping position by pushing a change to the text wrapping position stack.
|
||||
///
|
||||
/// - `> 0.0`: wrap at `wrap_pos_x` position in window local space
|
||||
/// - `= 0.0`: wrap to end of window ( or column)
|
||||
/// - `= 0.0`: wrap to end of window (or column)
|
||||
/// - `< 0.0`: no wrapping
|
||||
#[must_use]
|
||||
pub fn push_text_wrap_pos(&self, wrap_pos_x: f32) -> TextWrapPosStackToken {
|
||||
|
||||
@ -11,6 +11,7 @@ fn fmt_ptr() -> *const c_char {
|
||||
FMT.as_ptr() as *const c_char
|
||||
}
|
||||
|
||||
/// # Widgets: Text
|
||||
impl<'ui> Ui<'ui> {
|
||||
/// Renders simple text
|
||||
pub fn text<T: AsRef<str>>(&self, text: T) {
|
||||
@ -32,12 +33,15 @@ impl<'ui> Ui<'ui> {
|
||||
let _ = self.push_style_color(StyleColor::Text, color);
|
||||
self.text(text);
|
||||
}
|
||||
/// Renders text wrapped to the end of window (or column)
|
||||
pub fn text_wrapped(&self, text: &ImStr) {
|
||||
unsafe { sys::igTextWrapped(fmt_ptr(), text.as_ptr()) }
|
||||
}
|
||||
/// Render a text + label combination aligned the same way as value+label widgets
|
||||
pub fn label_text(&self, label: &ImStr, text: &ImStr) {
|
||||
unsafe { sys::igLabelText(label.as_ptr(), fmt_ptr(), text.as_ptr()) }
|
||||
}
|
||||
/// Renders text with a little bullet aligned to the typical tree node
|
||||
pub fn bullet_text(&self, text: &ImStr) {
|
||||
unsafe { sys::igBulletText(fmt_ptr(), text.as_ptr()) }
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user