Add doc aliases

This commit is contained in:
toyboot4e 2021-03-05 13:50:14 +09:00
parent 26f3a68924
commit 9b90f0e9d0
33 changed files with 262 additions and 2 deletions

View File

@ -4,53 +4,65 @@ use crate::Ui;
/// # Columns
impl<'ui> Ui<'ui> {
#[doc(alias = "Columns")]
pub fn columns(&self, count: i32, id: &ImStr, border: bool) {
unsafe { sys::igColumns(count, id.as_ptr(), border) }
}
/// Switches to the next column.
///
/// If the current row is finished, switches to first column of the next row
#[doc(alias = "NextColumn")]
pub fn next_column(&self) {
unsafe { sys::igNextColumn() }
}
/// Returns the index of the current column
#[doc(alias = "GetColumnIndex")]
pub fn current_column_index(&self) -> i32 {
unsafe { sys::igGetColumnIndex() }
}
/// Returns the width of the current column (in pixels)
#[doc(alias = "GetColumnWidth")]
pub fn current_column_width(&self) -> f32 {
unsafe { sys::igGetColumnWidth(-1) }
}
#[doc(alias = "GetColumnWidth")]
/// Returns the width of the given column (in pixels)
pub fn column_width(&self, column_index: i32) -> f32 {
unsafe { sys::igGetColumnWidth(column_index) }
}
#[doc(alias = "SetColumnWidth")]
/// Sets the width of the current column (in pixels)
pub fn set_current_column_width(&self, width: f32) {
unsafe { sys::igSetColumnWidth(-1, width) };
}
#[doc(alias = "SetColumnWidth")]
/// Sets the width of the given column (in pixels)
pub fn set_column_width(&self, column_index: i32, width: f32) {
unsafe { sys::igSetColumnWidth(column_index, width) };
}
/// Returns the offset of the current column (in pixels from the left side of the content
/// region)
#[doc(alias = "GetColumnOffset")]
pub fn current_column_offset(&self) -> f32 {
unsafe { sys::igGetColumnOffset(-1) }
}
/// Returns the offset of the given column (in pixels from the left side of the content region)
#[doc(alias = "GetColumnOffset")]
pub fn column_offset(&self, column_index: i32) -> f32 {
unsafe { sys::igGetColumnOffset(column_index) }
}
/// Sets the offset of the current column (in pixels from the left side of the content region)
#[doc(alias = "SetColumnOffset")]
pub fn set_current_column_offset(&self, offset_x: f32) {
unsafe { sys::igSetColumnOffset(-1, offset_x) };
}
/// Sets the offset of the given column (in pixels from the left side of the content region)
#[doc(alias = "SetColumnOffset")]
pub fn set_column_offset(&self, column_index: i32, offset_x: f32) {
unsafe { sys::igSetColumnOffset(column_index, offset_x) };
}
/// Returns the current amount of columns
#[doc(alias = "GetColumnCount")]
pub fn column_count(&self) -> i32 {
unsafe { sys::igGetColumnsCount() }
}

View File

@ -79,6 +79,7 @@ impl Context {
/// # Panics
///
/// Panics if an active context already exists
#[doc(alias = "CreateContext")]
pub fn create() -> Self {
Self::create_internal(None)
}
@ -87,10 +88,12 @@ impl Context {
/// # Panics
///
/// Panics if an active context already exists
#[doc(alias = "CreateContext")]
pub fn create_with_shared_font_atlas(shared_font_atlas: Rc<RefCell<SharedFontAtlas>>) -> Self {
Self::create_internal(Some(shared_font_atlas))
}
/// Suspends this context so another context can be the active context.
#[doc(alias = "CreateContext")]
pub fn suspend(self) -> SuspendedContext {
let _guard = CTX_MUTEX.lock();
assert!(
@ -183,10 +186,12 @@ impl Context {
self.renderer_name = renderer_name;
}
/// Loads settings from a string slice containing settings in .Ini file format
#[doc(alias = "LoadIniSettingsFromMemory")]
pub fn load_ini_settings(&mut self, data: &str) {
unsafe { sys::igLoadIniSettingsFromMemory(data.as_ptr() as *const _, data.len()) }
}
/// Saves settings to a mutable string buffer in .Ini file format
#[doc(alias = "SaveInitSettingsToMemory")]
pub fn save_ini_settings(&mut self, buf: &mut String) {
let data = unsafe { CStr::from_ptr(sys::igSaveIniSettingsToMemory(ptr::null_mut())) };
buf.push_str(&data.to_string_lossy());
@ -236,6 +241,7 @@ impl Context {
}
impl Drop for Context {
#[doc(alias = "DestroyContext")]
fn drop(&mut self) {
let _guard = CTX_MUTEX.lock();
// If this context is the active context, Dear ImGui automatically deactivates it during
@ -270,6 +276,7 @@ pub struct SuspendedContext(Context);
impl SuspendedContext {
/// Creates a new suspended imgui-rs context.
#[doc(alias = "CreateContext")]
pub fn create() -> Self {
Self::create_internal(None)
}
@ -283,6 +290,7 @@ impl SuspendedContext {
/// containing the activated context.
/// If there is already an active context, nothing happens and `Err` is returned, containing
/// the original suspended context.
#[doc(alias = "SetCurrentContext")]
pub fn activate(self) -> Result<Context, SuspendedContext> {
let _guard = CTX_MUTEX.lock();
if no_current_context() {
@ -465,6 +473,7 @@ impl Context {
}
}
/// Returns an immutable reference to the user interface style
#[doc(alias = "GetStyle")]
pub fn style(&self) -> &Style {
unsafe {
// safe because Style is a transparent wrapper around sys::ImGuiStyle
@ -472,6 +481,7 @@ impl Context {
}
}
/// Returns a mutable reference to the user interface style
#[doc(alias = "GetStyle")]
pub fn style_mut(&mut self) -> &mut Style {
unsafe {
// safe because Style is a transparent wrapper around sys::ImGuiStyle
@ -498,6 +508,7 @@ impl Context {
/// # Panics
///
/// Panics if the context uses a shared font atlas that is already borrowed
#[doc(alias = "NewFame")]
pub fn frame(&mut self) -> Ui {
// Clear default font if it no longer exists. This could be an error in the future
let default_font = self.io().font_default;

View File

@ -346,6 +346,7 @@ impl<'ui> DragDropTarget<'ui> {
/// Creates a new DragDropTarget, holding the [Ui]'s lifetime for the duration
/// of its existence. This is required since this struct runs some code on its Drop
/// to end the DragDropTarget code.
#[doc(alias = "BeginDragDropTarget")]
pub fn new(_ui: &Ui<'_>) -> Option<Self> {
let should_begin = unsafe { sys::igBeginDragDropTarget() };
if should_begin {

View File

@ -39,6 +39,7 @@ impl<'ui> DrawListMut<'ui> {
}
}
#[doc(alias = "GetWindowDrawList")]
pub(crate) fn window(_: &Ui<'ui>) -> Self {
Self::lock_draw_list();
Self {
@ -47,6 +48,7 @@ impl<'ui> DrawListMut<'ui> {
}
}
#[doc(alias = "GetBackgroundDrawList")]
pub(crate) fn background(_: &Ui<'ui>) -> Self {
Self::lock_draw_list();
Self {
@ -55,6 +57,7 @@ impl<'ui> DrawListMut<'ui> {
}
}
#[doc(alias = "GetForegroundDrawList")]
pub(crate) fn foreground(_: &Ui<'ui>) -> Self {
Self::lock_draw_list();
Self {
@ -82,6 +85,7 @@ impl<'ui> DrawListMut<'ui> {
/// });
/// }
/// ```
#[doc(alias = "ChannelsSplit")]
pub fn channels_split<F: FnOnce(&ChannelsSplit)>(&self, channels_count: u32, f: F) {
unsafe { sys::ImDrawList_ChannelsSplit(self.draw_list, channels_count as i32) };
f(&ChannelsSplit {
@ -104,6 +108,7 @@ impl<'ui> ChannelsSplit<'ui> {
/// Change current channel.
///
/// Panic if channel_index overflows the number of channels.
#[doc(alias = "ChannelsSetCurrent")]
pub fn set_current(&self, channel_index: u32) {
assert!(
channel_index < self.channels_count,
@ -120,6 +125,7 @@ impl<'ui> ChannelsSplit<'ui> {
/// Drawing functions
impl<'ui> DrawListMut<'ui> {
/// Returns a line from point `p1` to `p2` with color `c`.
#[doc(alias = "AddLine")]
pub fn add_line<C>(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> Line<'ui>
where
C: Into<ImColor32>,
@ -129,6 +135,7 @@ impl<'ui> DrawListMut<'ui> {
/// Returns a rectangle whose upper-left corner is at point `p1`
/// and lower-right corner is at point `p2`, with color `c`.
#[doc(alias = "AddRectFilled", alias = "AddRect")]
pub fn add_rect<C>(&'ui self, p1: [f32; 2], p2: [f32; 2], c: C) -> Rect<'ui>
where
C: Into<ImColor32>,
@ -141,6 +148,7 @@ impl<'ui> DrawListMut<'ui> {
/// The remains parameters are the respective color of the corners
/// in the counter-clockwise starting from the upper-left corner
/// first.
#[doc(alias = "AddRectFilledMultiColor")]
pub fn add_rect_filled_multicolor<C1, C2, C3, C4>(
&self,
p1: [f32; 2],
@ -170,6 +178,7 @@ impl<'ui> DrawListMut<'ui> {
/// Returns a triangle with the given 3 vertices `p1`, `p2` and `p3`
/// and color `c`.
#[doc(alias = "AddTriangleFilled", alias = "AddTriangle")]
pub fn add_triangle<C>(
&'ui self,
p1: [f32; 2],
@ -184,6 +193,7 @@ impl<'ui> DrawListMut<'ui> {
}
/// Returns a circle with the given `center`, `radius` and `color`.
#[doc(alias = "AddCircleFilled", alias = "AddCircle")]
pub fn add_circle<C>(&'ui self, center: [f32; 2], radius: f32, color: C) -> Circle<'ui>
where
C: Into<ImColor32>,
@ -192,6 +202,7 @@ impl<'ui> DrawListMut<'ui> {
}
/// Draw a text whose upper-left corner is at point `pos`.
#[doc(alias = "AddText")]
pub fn add_text<C, T>(&self, pos: [f32; 2], col: C, text: T)
where
C: Into<ImColor32>,
@ -209,6 +220,7 @@ impl<'ui> DrawListMut<'ui> {
/// Returns a Bezier curve stretching from `pos0` to `pos1`, whose
/// curvature is defined by `cp0` and `cp1`.
#[doc(alias = "AddBezier", alias = "AddBezierCubic")]
pub fn add_bezier_curve<C>(
&'ui self,
pos0: [f32; 2],
@ -227,6 +239,7 @@ impl<'ui> DrawListMut<'ui> {
///
/// Clip all drawings done within the closure `f` in the given
/// rectangle.
#[doc(alias = "PushClipRect", alias = "PopClipRect")]
pub fn with_clip_rect<F>(&self, min: [f32; 2], max: [f32; 2], f: F)
where
F: FnOnce(),
@ -241,6 +254,7 @@ impl<'ui> DrawListMut<'ui> {
/// Clip all drawings done within the closure `f` in the given
/// rectangle. Intersect with all clipping rectangle previously on
/// the stack.
#[doc(alias = "PushClipRect", alias = "PopClipRect")]
pub fn with_clip_rect_intersect<F>(&self, min: [f32; 2], max: [f32; 2], f: F)
where
F: FnOnce(),

View File

@ -65,6 +65,7 @@ pub struct FontAtlas {
unsafe impl RawCast<sys::ImFontAtlas> for FontAtlas {}
impl FontAtlas {
#[doc(alias = "AddFontDefault", alias = "AddFont")]
pub fn add_font(&mut self, font_sources: &[FontSource]) -> FontId {
let (head, tail) = font_sources.split_first().unwrap();
let font_id = self.add_font_internal(head, false);
@ -130,10 +131,12 @@ impl FontAtlas {
None
}
/// Returns true if the font atlas has been built
#[doc(alias = "IsBuilt")]
pub fn is_built(&self) -> bool {
unsafe { sys::ImFontAtlas_IsBuilt(self.raw() as *const sys::ImFontAtlas as *mut _) }
}
/// Builds a 1 byte per-pixel font atlas texture
#[doc(alias = "GetTextDataAsAlpha8")]
pub fn build_alpha8_texture(&mut self) -> FontAtlasTexture {
let mut pixels: *mut c_uchar = ptr::null_mut();
let mut width: c_int = 0;
@ -167,6 +170,7 @@ impl FontAtlas {
}
}
/// Builds a 4 byte per-pixel font atlas texture
#[doc(alias = "GetTextDataAsRGBA32")]
pub fn build_rgba32_texture(&mut self) -> FontAtlasTexture {
let mut pixels: *mut c_uchar = ptr::null_mut();
let mut width: c_int = 0;
@ -200,12 +204,14 @@ impl FontAtlas {
}
}
/// Clears the font atlas completely (both input and output data)
#[doc(alias = "Clear")]
pub fn clear(&mut self) {
unsafe {
sys::ImFontAtlas_Clear(self.raw_mut());
}
}
/// Clears output font data (glyph storage, UV coordinates)
#[doc(alias = "ClearFonts")]
pub fn clear_fonts(&mut self) {
unsafe {
sys::ImFontAtlas_ClearFonts(self.raw_mut());
@ -214,12 +220,14 @@ impl FontAtlas {
/// Clears output texture data.
///
/// Can be used to save RAM once the texture has been transferred to the GPU.
#[doc(alias = "ClearTexData")]
pub fn clear_tex_data(&mut self) {
unsafe {
sys::ImFontAtlas_ClearTexData(self.raw_mut());
}
}
/// Clears all the data used to build the textures and fonts
#[doc(alias = "ClearInputData")]
pub fn clear_input_data(&mut self) {
unsafe {
sys::ImFontAtlas_ClearInputData(self.raw_mut());
@ -423,12 +431,14 @@ pub struct FontAtlasTexture<'a> {
pub struct SharedFontAtlas(pub(crate) *mut sys::ImFontAtlas);
impl SharedFontAtlas {
#[doc(alias = "ImFontAtlas", alias = "ImFontAtlas::ImFontAtlas")]
pub fn create() -> SharedFontAtlas {
SharedFontAtlas(unsafe { sys::ImFontAtlas_ImFontAtlas() })
}
}
impl Drop for SharedFontAtlas {
#[doc(alias = "ImFontAtlas::Destory")]
fn drop(&mut self) {
unsafe { sys::ImFontAtlas_destroy(self.0) };
}

View File

@ -10,22 +10,26 @@ pub mod glyph_ranges;
/// # Fonts
impl<'ui> Ui<'ui> {
/// Returns the current font
#[doc(alias = "GetFont")]
pub fn current_font(&self) -> &Font {
unsafe { Font::from_raw(&*sys::igGetFont()) }
}
/// Returns the current font size (= height in pixels) with font scale applied
#[doc(alias = "GetFontSize")]
pub fn current_font_size(&self) -> f32 {
unsafe { sys::igGetFontSize() }
}
/// Returns the UV coordinate for a white pixel.
///
/// Useful for drawing custom shapes with the draw list API.
#[doc(alias = "FontTexUvWhitePixel")]
pub fn font_tex_uv_white_pixel(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetFontTexUvWhitePixel(&mut out) };
out.into()
}
/// Sets the font scale of the current window
#[doc(alias = "SetWindowFontScale")]
pub fn set_window_font_scale(&self, scale: f32) {
unsafe { sys::igSetWindowFontScale(scale) }
}

View File

@ -96,6 +96,7 @@ impl<'ui> Ui<'ui> {
///
/// Equivalent to indexing the Io struct `key_map` field: `ui.io().key_map[key]`
#[inline]
#[doc(alias = "GetKeyIndex")]
fn key_index(&self, key: Key) -> i32 {
unsafe { sys::igGetKeyIndex(key as i32) }
}
@ -103,6 +104,7 @@ impl<'ui> Ui<'ui> {
///
/// Equivalent to indexing the Io struct `keys_down` field: `ui.io().keys_down[key_index]`
#[inline]
#[doc(alias = "IsKeyDown")]
pub fn is_key_down(&self, key: Key) -> bool {
let key_index = self.key_index(key);
unsafe { sys::igIsKeyDown(key_index) }
@ -112,6 +114,7 @@ impl<'ui> Ui<'ui> {
///
/// Affected by key repeat settings (`io.key_repeat_delay`, `io.key_repeat_rate`)
#[inline]
#[doc(alias = "IsKeyPressed")]
pub fn is_key_pressed(&self, key: Key) -> bool {
let key_index = self.key_index(key);
unsafe { sys::igIsKeyPressed(key_index, true) }
@ -128,6 +131,7 @@ impl<'ui> Ui<'ui> {
/// Returns true if the key was released (went from down to !down)
#[inline]
#[doc(alias = "IsKeyReleased")]
pub fn is_key_released(&self, key: Key) -> bool {
let key_index = self.key_index(key);
unsafe { sys::igIsKeyReleased(key_index) }
@ -138,6 +142,7 @@ impl<'ui> Ui<'ui> {
/// Usually returns 0 or 1, but might be >1 if `rate` is small enough that `io.delta_time` >
/// `rate`.
#[inline]
#[doc(alias = "GetKeyPressedAmount")]
pub fn key_pressed_amount(&self, key: Key, repeat_delay: f32, rate: f32) -> u32 {
let key_index = self.key_index(key);
unsafe { sys::igGetKeyPressedAmount(key_index, repeat_delay, rate) as u32 }
@ -148,12 +153,14 @@ impl<'ui> Ui<'ui> {
/// This is the equivalent to [set_keyboard_focus_here_with_offset](Self::set_keyboard_focus_here_with_offset)
/// with `target_widget` set to `FocusedWidget::Next`.
#[inline]
#[doc(alias = "SetKeyboardFocusHere")]
pub fn set_keyboard_focus_here(&self) {
self.set_keyboard_focus_here_with_offset(FocusedWidget::Next);
}
/// Focuses keyboard on a widget relative to current position.
#[inline]
#[doc(alias = "SetKeyboardFocusHere")]
pub fn set_keyboard_focus_here_with_offset(&self, target_widget: FocusedWidget) {
unsafe {
sys::igSetKeyboardFocusHere(target_widget.as_offset());

View File

@ -92,26 +92,32 @@ impl<'ui> Ui<'ui> {
/// Returns true if the given mouse button is held down.
///
/// Equivalent to indexing the Io struct with the button, e.g. `ui.io()[button]`.
#[doc(alias = "IsMouseDown")]
pub fn is_mouse_down(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseDown(button as i32) }
}
/// Returns true if any mouse button is held down
#[doc(alias = "IsAnyMouseDown")]
pub fn is_any_mouse_down(&self) -> bool {
unsafe { sys::igIsAnyMouseDown() }
}
/// Returns true if the given mouse button was clicked (went from !down to down)
#[doc(alias = "IsMouseClicked")]
pub fn is_mouse_clicked(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseClicked(button as i32, false) }
}
/// Returns true if the given mouse button was double-clicked
#[doc(alias = "IsMouseDoubleClicked")]
pub fn is_mouse_double_clicked(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseDoubleClicked(button as i32) }
}
/// Returns true if the given mouse button was released (went from down to !down)
#[doc(alias = "IsMouseReleased")]
pub fn is_mouse_released(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseReleased(button as i32) }
}
/// Returns true if the mouse is currently dragging with the given mouse button held down
#[doc(alias = "IsMouseDragging")]
pub fn is_mouse_dragging(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseDragging(button as i32, -1.0) }
}
@ -119,6 +125,7 @@ impl<'ui> Ui<'ui> {
///
/// If the given threshold is invalid or negative, the global distance threshold is used
/// (`io.mouse_drag_threshold`).
#[doc(alias = "IsMouseDragging")]
pub fn is_mouse_dragging_with_threshold(&self, button: MouseButton, threshold: f32) -> bool {
unsafe { sys::igIsMouseDragging(button as i32, threshold) }
}
@ -130,6 +137,7 @@ impl<'ui> Ui<'ui> {
unsafe { sys::igIsMouseHoveringRect(r_min.into(), r_max.into(), true) }
}
/// Returns the mouse position backed up at the time of opening a popup
#[doc(alias = "GetMousePosOnOpeningCurrentPopup")]
pub fn mouse_pos_on_opening_current_popup(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetMousePosOnOpeningCurrentPopup(&mut out) };
@ -143,6 +151,7 @@ impl<'ui> Ui<'ui> {
///
/// This is the same as [mouse_drag_delta_with_button](Self::mouse_drag_delta_with_button) with
/// `button` set to `MouseButton::Left`.
#[doc(alias = "GetMouseDragDelta")]
pub fn mouse_drag_delta(&self) -> [f32; 2] {
self.mouse_drag_delta_with_button(MouseButton::Left)
}
@ -154,6 +163,7 @@ impl<'ui> Ui<'ui> {
///
/// This is the same as [mouse_drag_delta_with_threshold](Self::mouse_drag_delta_with_threshold) with
/// `threshold` set to `-1.0`, which uses the global threshold `io.mouse_drag_threshold`.
#[doc(alias = "GetMouseDragDelta")]
pub fn mouse_drag_delta_with_button(&self, button: MouseButton) -> [f32; 2] {
self.mouse_drag_delta_with_threshold(button, -1.0)
}
@ -162,12 +172,14 @@ impl<'ui> Ui<'ui> {
/// This is locked and returns [0.0, 0.0] until the mouse has moved past the given threshold.
/// If the given threshold is invalid or negative, the global distance threshold is used
/// (`io.mouse_drag_threshold`).
#[doc(alias = "GetMouseDragDelta")]
pub fn mouse_drag_delta_with_threshold(&self, button: MouseButton, threshold: f32) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetMouseDragDelta(&mut out, button as i32, threshold) };
out.into()
}
/// Resets the current delta from initial clicking position.
#[doc(alias = "ResetMouseDragDelta")]
pub fn reset_mouse_drag_delta(&self, button: MouseButton) {
// This mutates the Io struct, but targets an internal field so there can't be any
// references to it
@ -176,6 +188,7 @@ impl<'ui> Ui<'ui> {
/// Returns the currently desired mouse cursor type.
///
/// Returns `None` if no cursor should be displayed
#[doc(alias = "GetMouseCursor")]
pub fn mouse_cursor(&self) -> Option<MouseCursor> {
match unsafe { sys::igGetMouseCursor() } {
sys::ImGuiMouseCursor_Arrow => Some(MouseCursor::Arrow),
@ -193,6 +206,7 @@ impl<'ui> Ui<'ui> {
/// Sets the desired mouse cursor type.
///
/// Passing `None` hides the mouse cursor.
#[doc(alias = "SetMouseCursor")]
pub fn set_mouse_cursor(&self, cursor_type: Option<MouseCursor>) {
unsafe {
sys::igSetMouseCursor(
@ -202,9 +216,11 @@ impl<'ui> Ui<'ui> {
);
}
}
#[doc(alias = "IsMousePosValid")]
pub fn is_current_mouse_pos_valid(&self) -> bool {
unsafe { sys::igIsMousePosValid(ptr::null()) }
}
#[doc(alias = "IsMousePosValid")]
pub fn is_mouse_pos_valid(&self, mouse_pos: [f32; 2]) -> bool {
unsafe { sys::igIsMousePosValid(&mouse_pos.into()) }
}

View File

@ -317,6 +317,7 @@ unsafe impl RawCast<sys::ImGuiIO> for Io {}
impl Io {
/// Queue new character input
#[doc(alias = "AddInputCharactersUTF8")]
pub fn add_input_character(&mut self, character: char) {
let mut buf = [0; 5];
character.encode_utf8(&mut buf);
@ -325,6 +326,7 @@ impl Io {
}
}
/// Clear character input buffer
#[doc(alias = "ClearCharacters")]
pub fn clear_input_characters(&mut self) {
unsafe {
sys::ImGuiIO_ClearInputCharacters(self.raw_mut());

View File

@ -15,6 +15,7 @@ impl<'ui> Ui<'ui> {
/// Renders a separator (generally horizontal).
///
/// This becomes a vertical separator inside a menu bar or in horizontal layout mode.
#[doc(alias = "Separator")]
pub fn separator(&self) {
unsafe { sys::igSeparator() }
}
@ -25,6 +26,7 @@ impl<'ui> Ui<'ui> {
///
/// This is equivalent to calling [same_line_with_pos](Self::same_line_with_pos)
/// with the `pos` set to 0.0, which uses `Style::item_spacing`.
#[doc(alias = "SameLine")]
pub fn same_line(&self) {
self.same_line_with_pos(0.0);
}
@ -35,6 +37,7 @@ impl<'ui> Ui<'ui> {
///
/// This is equivalent to calling [same_line_with_spacing](Self::same_line_with_spacing)
/// with the `spacing` set to -1.0, which means no extra spacing.
#[doc(alias = "SameLine")]
pub fn same_line_with_pos(&self, pos_x: f32) {
self.same_line_with_spacing(pos_x, -1.0)
}
@ -42,21 +45,25 @@ impl<'ui> Ui<'ui> {
/// Call between widgets or groups to layout them horizontally.
///
/// X position is given in window coordinates.
#[doc(alias = "SameLine")]
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
#[doc(alias = "NewLine")]
pub fn new_line(&self) {
unsafe { sys::igNewLine() }
}
/// Adds vertical spacing
#[doc(alias = "Spacing")]
pub fn spacing(&self) {
unsafe { sys::igSpacing() }
}
/// Fills a space of `size` in pixels with nothing on the current window.
///
/// Can be used to move the cursor on the window.
#[doc(alias = "Dummy")]
pub fn dummy(&self, size: [f32; 2]) {
unsafe { sys::igDummy(size.into()) }
}
@ -65,11 +72,13 @@ impl<'ui> Ui<'ui> {
///
/// This is equivalent to [indent_by](Self::indent_by) with `width` set to
/// `Style::ident_spacing`.
#[doc(alias = "Indent")]
pub fn indent(&self) {
self.indent_by(0.0)
}
/// Moves content position to the right by `width`
#[doc(alias = "Indent")]
pub fn indent_by(&self, width: f32) {
unsafe { sys::igIndent(width) };
}
@ -77,10 +86,12 @@ impl<'ui> Ui<'ui> {
///
/// This is equivalent to [unindent_by](Self::unindent_by) with `width` set to
/// `Style::ident_spacing`.
#[doc(alias = "Unindent")]
pub fn unindent(&self) {
self.unindent_by(0.0)
}
/// Moves content position to the left by `width`
#[doc(alias = "Unindent")]
pub fn unindent_by(&self, width: f32) {
unsafe { sys::igUnindent(width) };
}
@ -89,6 +100,7 @@ impl<'ui> Ui<'ui> {
/// May be useful to handle the same mouse event on a group of items, for example.
///
/// Returns a `GroupToken` that must be ended by calling `.end()`
#[doc(alias = "BeginGroup")]
pub fn begin_group(&self) -> GroupToken {
unsafe { sys::igBeginGroup() };
GroupToken::new(self)
@ -96,6 +108,7 @@ impl<'ui> Ui<'ui> {
/// Creates a layout group and runs a closure to construct the contents.
///
/// May be useful to handle the same mouse event on a group of items, for example.
#[doc(alias = "BeginGroup")]
pub fn group<R, F: FnOnce() -> R>(&self, f: F) -> R {
let group = self.begin_group();
let result = f();
@ -103,6 +116,7 @@ impl<'ui> Ui<'ui> {
result
}
/// Returns the cursor position (in window coordinates)
#[doc(alias = "GetCursorPos")]
pub fn cursor_pos(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetCursorPos(&mut out) };
@ -111,10 +125,12 @@ impl<'ui> Ui<'ui> {
/// Sets the cursor position (in window coordinates).
///
/// This sets the point on which the next widget will be drawn.
#[doc(alias = "SetCursorPos")]
pub fn set_cursor_pos(&self, pos: [f32; 2]) {
unsafe { sys::igSetCursorPos(pos.into()) };
}
/// Returns the initial cursor position (in window coordinates)
#[doc(alias = "GetCursorStartPos")]
pub fn cursor_start_pos(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetCursorStartPos(&mut out) };
@ -123,30 +139,37 @@ impl<'ui> Ui<'ui> {
/// Returns the cursor position (in absolute screen coordinates).
///
/// This is especially useful for drawing, as the drawing API uses screen coordinates.
#[doc(alias = "GetCursorScreenPos")]
pub fn cursor_screen_pos(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetCursorScreenPos(&mut out) };
out.into()
}
/// Sets the cursor position (in absolute screen coordinates)
#[doc(alias = "SetCursorScreenPos")]
pub fn set_cursor_screen_pos(&self, pos: [f32; 2]) {
unsafe { sys::igSetCursorScreenPos(pos.into()) }
}
/// Vertically aligns text baseline so that it will align properly to regularly frame items.
///
/// Call this if you have text on a line before a framed item.
#[doc(alias = "AlignTextToFramePadding")]
pub fn align_text_to_frame_padding(&self) {
unsafe { sys::igAlignTextToFramePadding() };
}
#[doc(alias = "GetTextLineHeight")]
pub fn text_line_height(&self) -> f32 {
unsafe { sys::igGetTextLineHeight() }
}
#[doc(alias = "GetTextLineHeightWithSpacing")]
pub fn text_line_height_with_spacing(&self) -> f32 {
unsafe { sys::igGetTextLineHeightWithSpacing() }
}
#[doc(alias = "GetFrameHeight")]
pub fn frame_height(&self) -> f32 {
unsafe { sys::igGetFrameHeight() }
}
#[doc(alias = "GetFrameLineHeightWithSpacing")]
pub fn frame_height_with_spacing(&self) -> f32 {
unsafe { sys::igGetFrameHeightWithSpacing() }
}

View File

@ -89,6 +89,7 @@ mod window;
pub use core as __core;
/// Returns the underlying Dear ImGui library version
#[doc(alias = "GetVersion")]
pub fn dear_imgui_version() -> &'static str {
unsafe {
let bytes = CStr::from_ptr(sys::igGetVersion()).to_bytes();
@ -106,12 +107,14 @@ impl Context {
/// Returns the global imgui-rs time.
///
/// Incremented by Io::delta_time every frame.
#[doc(alias = "GetTime")]
pub fn time(&self) -> f64 {
unsafe { sys::igGetTime() }
}
/// Returns the global imgui-rs frame count.
///
/// Incremented by 1 every frame.
#[doc(alias = "GetFrameCount")]
pub fn frame_count(&self) -> i32 {
unsafe { sys::igGetFrameCount() }
}
@ -125,6 +128,7 @@ pub struct Ui<'ui> {
impl<'ui> Ui<'ui> {
/// Returns an immutable reference to the inputs/outputs object
#[doc(alias = "GetIO")]
pub fn io(&self) -> &Io {
unsafe { &*(sys::igGetIO() as *const Io) }
}
@ -143,6 +147,7 @@ impl<'ui> Ui<'ui> {
*self.ctx.style()
}
/// Renders the frame and returns a reference to the resulting draw data
#[doc(alias = "Render", alias = "GetDrawData")]
pub fn render(self) -> &'ui DrawData {
unsafe {
sys::igRender();
@ -152,6 +157,7 @@ impl<'ui> Ui<'ui> {
}
impl<'a> Drop for Ui<'a> {
#[doc(alias = "EndFrame")]
fn drop(&mut self) {
if !thread::panicking() {
unsafe {
@ -165,6 +171,7 @@ impl<'a> Drop for Ui<'a> {
impl<'ui> Ui<'ui> {
/// Renders a demo window (previously called a test window), which demonstrates most
/// Dear Imgui features.
#[doc(alias = "SnowDemoWindow")]
pub fn show_demo_window(&self, opened: &mut bool) {
unsafe {
sys::igShowDemoWindow(opened);
@ -173,6 +180,7 @@ impl<'ui> Ui<'ui> {
/// Renders an about window.
///
/// Displays the Dear ImGui version/credits, and build/system information.
#[doc(alias = "ShowAboutWindow")]
pub fn show_about_window(&self, opened: &mut bool) {
unsafe {
sys::igShowAboutWindow(opened);
@ -182,22 +190,26 @@ impl<'ui> Ui<'ui> {
///
/// Displays Dear ImGui internals: draw commands (with individual draw calls and vertices),
/// window list, basic internal state, etc.
#[doc(alias = "ShowMetricsWindow")]
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
#[doc(alias = "ShowStyleEditor")]
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
#[doc(alias = "ShowStyleEditor")]
pub fn show_default_style_editor(&self) {
unsafe { sys::igShowStyleEditor(ptr::null_mut()) };
}
/// Renders a basic help/info block (not a window)
#[doc(alias = "ShowUserGuide")]
pub fn show_user_guide(&self) {
unsafe { sys::igShowUserGuide() };
}
@ -241,9 +253,11 @@ impl<T> From<*mut T> for Id<'static> {
// Widgets: Input
impl<'ui> Ui<'ui> {
#[doc(alias = "InputText", alias = "InputTextWithHint")]
pub fn input_text<'p>(&self, label: &'p ImStr, buf: &'p mut ImString) -> InputText<'ui, 'p> {
InputText::new(self, label, buf)
}
#[doc(alias = "InputText", alias = "InputTextMultiline")]
pub fn input_text_multiline<'p>(
&self,
label: &'p ImStr,
@ -252,6 +266,7 @@ impl<'ui> Ui<'ui> {
) -> InputTextMultiline<'ui, 'p> {
InputTextMultiline::new(self, label, buf, size)
}
#[doc(alias = "InputFloat2")]
pub fn input_float<'p>(&self, label: &'p ImStr, value: &'p mut f32) -> InputFloat<'ui, 'p> {
InputFloat::new(self, label, value)
}
@ -262,6 +277,7 @@ impl<'ui> Ui<'ui> {
) -> InputFloat2<'ui, 'p> {
InputFloat2::new(self, label, value)
}
#[doc(alias = "InputFloat3")]
pub fn input_float3<'p>(
&self,
label: &'p ImStr,
@ -269,6 +285,7 @@ impl<'ui> Ui<'ui> {
) -> InputFloat3<'ui, 'p> {
InputFloat3::new(self, label, value)
}
#[doc(alias = "InputFloat4")]
pub fn input_float4<'p>(
&self,
label: &'p ImStr,
@ -276,15 +293,19 @@ impl<'ui> Ui<'ui> {
) -> InputFloat4<'ui, 'p> {
InputFloat4::new(self, label, value)
}
#[doc(alias = "InputInt")]
pub fn input_int<'p>(&self, label: &'p ImStr, value: &'p mut i32) -> InputInt<'ui, 'p> {
InputInt::new(self, label, value)
}
#[doc(alias = "InputInt2")]
pub fn input_int2<'p>(&self, label: &'p ImStr, value: &'p mut [i32; 2]) -> InputInt2<'ui, 'p> {
InputInt2::new(self, label, value)
}
#[doc(alias = "InputInt3")]
pub fn input_int3<'p>(&self, label: &'p ImStr, value: &'p mut [i32; 3]) -> InputInt3<'ui, 'p> {
InputInt3::new(self, label, value)
}
#[doc(alias = "InputInt4")]
pub fn input_int4<'p>(&self, label: &'p ImStr, value: &'p mut [i32; 4]) -> InputInt4<'ui, 'p> {
InputInt4::new(self, label, value)
}
@ -318,6 +339,7 @@ impl<'ui> Ui<'ui> {
/// }
/// }
/// ```
#[doc(alias = "BeginTooltip", alias = "EndTootip")]
pub fn tooltip<F: FnOnce()>(&self, f: F) {
unsafe { sys::igBeginTooltip() };
f();
@ -326,6 +348,7 @@ impl<'ui> Ui<'ui> {
/// Construct a tooltip window that can have any kind of content.
///
/// Returns a `TooltipToken` that must be ended by calling `.end()`
#[doc(alias = "BeginTooltip")]
pub fn begin_tooltip(&self) -> TooltipToken<'_> {
unsafe { sys::igBeginTooltip() };
TooltipToken::new(self)
@ -345,6 +368,7 @@ impl<'ui> Ui<'ui> {
/// }
/// }
/// ```
#[doc(alias = "BeginTooltip", alias = "EndTootip")]
pub fn tooltip_text<T: AsRef<str>>(&self, text: T) {
self.tooltip(|| self.text(text));
}
@ -352,6 +376,7 @@ impl<'ui> Ui<'ui> {
// Widgets: ListBox
impl<'ui> Ui<'ui> {
#[doc(alias = "ListBox")]
pub fn list_box<'p, StringType: AsRef<ImStr> + ?Sized>(
&self,
label: &'p ImStr,
@ -374,12 +399,14 @@ impl<'ui> Ui<'ui> {
}
impl<'ui> Ui<'ui> {
#[doc(alias = "PlotLines")]
pub fn plot_lines<'p>(&self, label: &'p ImStr, values: &'p [f32]) -> PlotLines<'ui, 'p> {
PlotLines::new(self, label, values)
}
}
impl<'ui> Ui<'ui> {
#[doc(alias = "PlotHistogram")]
pub fn plot_histogram<'p>(
&self,
label: &'p ImStr,
@ -394,6 +421,7 @@ impl<'ui> Ui<'ui> {
///
/// This is the same as [calc_text_size_with_opts](Self::calc_text_size_with_opts)
/// with `hide_text_after_double_hash` set to false and `wrap_width` set to `-1.0`.
#[doc(alias = "CalcTextSize")]
pub fn calc_text_size<T: AsRef<str>>(&self, text: T) -> [f32; 2] {
self.calc_text_size_with_opts(text, false, -1.0)
}
@ -404,6 +432,7 @@ impl<'ui> Ui<'ui> {
/// This is a feature of imgui.
///
/// wrap_width allows you to request a width at which to wrap the text to a newline for the calculation.
#[doc(alias = "CalcTextSize")]
pub fn calc_text_size_with_opts<T: AsRef<str>>(
&self,
text: T,
@ -461,16 +490,19 @@ impl<'ui> Ui<'ui> {
/// }
/// ```
#[must_use]
#[doc(alias = "GetWindowDrawList")]
pub fn get_window_draw_list(&'ui self) -> DrawListMut<'ui> {
DrawListMut::window(self)
}
#[must_use]
#[doc(alias = "GetBackgroundDrawList")]
pub fn get_background_draw_list(&'ui self) -> DrawListMut<'ui> {
DrawListMut::background(self)
}
#[must_use]
#[doc(alias = "GetForegroundDrawList")]
pub fn get_foreground_draw_list(&'ui self) -> DrawListMut<'ui> {
DrawListMut::foreground(self)
}

View File

@ -125,6 +125,7 @@ impl<'p> PopupModal<'p> {
}
/// Consume and draw the PopupModal.
#[doc(alias = "BeginPopupModal")]
pub fn build<F: FnOnce()>(self, ui: &Ui<'_>, f: F) {
if let Some(_popup) = self.begin_popup(ui) {
f();
@ -136,6 +137,7 @@ impl<'p> PopupModal<'p> {
///
/// This should be called *per frame*, whereas [`open_popup`](Self::open_popup) should be called *once*
/// when you want to actual create the popup.
#[doc(alias = "BeginPopupModal")]
pub fn begin_popup<'ui>(self, ui: &Ui<'ui>) -> Option<PopupToken<'ui>> {
let render = unsafe {
sys::igBeginPopupModal(
@ -163,6 +165,7 @@ impl<'ui> Ui<'ui> {
/// The confusing aspect to popups is that ImGui holds "control" over the popup fundamentally, so that ImGui
/// can also force close a popup when a user clicks outside a popup. If you do not want users to be
/// able to close a popup without selected an option, use [`PopupModal`].
#[doc(alias = "OpenPopup")]
pub fn open_popup(&self, str_id: &ImStr) {
unsafe { sys::igOpenPopup(str_id.as_ptr(), 0) };
}
@ -171,6 +174,7 @@ impl<'ui> Ui<'ui> {
///
/// This should be called *per frame*, whereas [`open_popup`](Self::open_popup) should be called *once*
/// when you want to actual create the popup.
#[doc(alias = "BeginPopup")]
pub fn begin_popup(&self, str_id: &ImStr) -> Option<PopupToken<'_>> {
let render =
unsafe { sys::igBeginPopup(str_id.as_ptr(), WindowFlags::empty().bits() as i32) };
@ -186,6 +190,7 @@ impl<'ui> Ui<'ui> {
///
/// This should be called *per frame*, whereas [`open_popup`](Self::open_popup) should be called *once*
/// when you want to actual create the popup.
#[doc(alias = "BeginPopup")]
pub fn popup<F>(&self, str_id: &ImStr, f: F)
where
F: FnOnce(),
@ -206,6 +211,7 @@ impl<'ui> Ui<'ui> {
/// Close a popup. Should be called within the closure given as argument to
/// [`Ui::popup`] or [`Ui::popup_modal`].
#[doc(alias = "CloseCurrentPopup")]
pub fn close_current_popup(&self) {
unsafe { sys::igCloseCurrentPopup() };
}

View File

@ -61,6 +61,7 @@ impl DrawData {
/// buffers.
///
/// **This is slow and most likely a waste of resources. Always prefer indexed rendering!**
#[doc(alias = "DeIndexAllBuffers")]
pub fn deindex_all_buffers(&mut self) {
unsafe {
sys::ImDrawData_DeIndexAllBuffers(self.raw_mut());
@ -70,6 +71,7 @@ impl DrawData {
///
/// Can be used if your final output buffer is at a different scale than imgui-rs expects, or
/// if there is a difference between your window resolution and framebuffer resolution.
#[doc(alias = "ScaleClipRects")]
pub fn scale_clip_rects(&mut self, fb_scale: [f32; 2]) {
unsafe {
sys::ImDrawData_ScaleClipRects(self.raw_mut(), fb_scale.into());

View File

@ -34,6 +34,7 @@ impl<'ui> Ui<'ui> {
/// ui.text("I use the custom font!");
/// font.pop(&ui);
/// ```
#[doc(alias = "PushFont")]
pub fn push_font(&self, id: FontId) -> FontStackToken<'_> {
let fonts = self.fonts();
let font = fonts
@ -57,6 +58,7 @@ impl<'ui> Ui<'ui> {
/// ui.text("I'm red!");
/// color.pop(&ui);
/// ```
#[doc(alias = "PushStyleColorVec4")]
pub fn push_style_color(&self, style_color: StyleColor, color: [f32; 4]) -> ColorStackToken {
unsafe { sys::igPushStyleColorVec4(style_color as i32, color.into()) };
ColorStackToken::new(self)
@ -112,6 +114,7 @@ impl<'ui> Ui<'ui> {
/// ui.text("I'm transparent!");
/// style.pop(&ui);
/// ```
#[doc(alias = "PushStyleVar")]
pub fn push_style_var(&self, style_var: StyleVar) -> StyleStackToken {
unsafe { push_style_var(style_var) };
StyleStackToken::new(self)
@ -192,6 +195,7 @@ pub struct MultiColorStackToken {
impl MultiColorStackToken {
/// Pops changes from the color stack
#[doc(alias = "PopStyleColor")]
pub fn pop(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igPopStyleColor(self.count as i32) };
@ -231,6 +235,7 @@ pub struct MultiStyleStackToken {
impl MultiStyleStackToken {
/// Pops changes from the style stack
#[doc(alias = "PopStyleVar")]
pub fn pop(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igPopStyleVar(self.count as i32) };
@ -294,6 +299,7 @@ impl<'ui> Ui<'ui> {
/// - `= 0.0`: default to ~2/3 of window width
/// - `< 0.0`: `item_width` pixels relative to the right of window (-1.0 always aligns width to
/// the right side)
#[doc(alias = "PushItemWith")]
pub fn push_item_width(&self, item_width: f32) -> ItemWidthStackToken {
unsafe { sys::igPushItemWidth(item_width) };
ItemWidthStackToken { _ctx: self.ctx }
@ -304,12 +310,14 @@ impl<'ui> Ui<'ui> {
/// - `= 0.0`: default to ~2/3 of window width
/// - `< 0.0`: `item_width` pixels relative to the right of window (-1.0 always aligns width to
/// the right side)
#[doc(alias = "SetNextItemWidth")]
pub fn set_next_item_width(&self, item_width: f32) {
unsafe { sys::igSetNextItemWidth(item_width) };
}
/// Returns the width of the item given the pushed settings and the current cursor position.
///
/// This is NOT necessarily the width of last item.
#[doc(alias = "CalcItemWidth")]
pub fn calc_item_width(&self) -> f32 {
unsafe { sys::igCalcItemWidth() }
}
@ -321,6 +329,7 @@ impl<'ui> Ui<'ui> {
/// with `wrap_pos_x` set to 0.0.
///
/// Returns a `TextWrapPosStackToken` that may be popped by calling `.pop()`
#[doc(alias = "PushTextWrapPos")]
pub fn push_text_wrap_pos(&self) -> TextWrapPosStackToken {
self.push_text_wrap_pos_with_pos(0.0)
}
@ -332,6 +341,7 @@ impl<'ui> Ui<'ui> {
/// - `> 0.0`: wrap at `wrap_pos_x` position in window local space
/// - `= 0.0`: wrap to end of window (or column)
/// - `< 0.0`: no wrapping
#[doc(alias = "PushTextWrapPos")]
pub fn push_text_wrap_pos_with_pos(&self, wrap_pos_x: f32) -> TextWrapPosStackToken {
unsafe { sys::igPushTextWrapPos(wrap_pos_x) };
TextWrapPosStackToken { _ctx: self.ctx }
@ -340,6 +350,7 @@ impl<'ui> Ui<'ui> {
/// Changes an item flag by pushing a change to the item flag stack.
///
/// Returns a `ItemFlagsStackToken` that may be popped by calling `.pop()`
#[doc(alias = "PushItemFlag")]
pub fn push_item_flag(&self, item_flag: ItemFlag) -> ItemFlagsStackToken {
use self::ItemFlag::*;
match item_flag {
@ -366,6 +377,7 @@ pub struct ItemWidthStackToken {
impl ItemWidthStackToken {
/// Pops a change from the item width stack
#[doc(alias = "PopItemWidth")]
pub fn pop(mut self, _: &Ui) {
self._ctx = ptr::null();
unsafe { sys::igPopItemWidth() };
@ -379,6 +391,7 @@ pub struct TextWrapPosStackToken {
impl TextWrapPosStackToken {
/// Pops a change from the text wrap position stack
#[doc(alias = "PopTextWrapPos")]
pub fn pop(mut self, _: &Ui) {
self._ctx = ptr::null();
unsafe { sys::igPopTextWrapPos() };
@ -393,6 +406,8 @@ pub struct ItemFlagsStackToken {
impl ItemFlagsStackToken {
/// Pops a change from the item flags stack
#[doc(alias = "PopAllowKeyboardFocus", alias = "PopButtonRepeat")]
pub fn pop(mut self, _: &Ui) {
self._ctx = ptr::null();
const ALLOW_KEYBOARD_FOCUS: ItemFlag = ItemFlag::AllowKeyboardFocus(true);
@ -430,6 +445,7 @@ impl<'ui> Ui<'ui> {
///
/// Returns an `IdStackToken` that can be popped by calling `.end()`
/// or by dropping manually.
#[doc(alias = "PushId")]
pub fn push_id<'a, I: Into<Id<'a>>>(&self, id: I) -> IdStackToken<'ui> {
let id = id.into();

View File

@ -153,12 +153,14 @@ unsafe impl RawCast<sys::ImGuiStyle> for Style {}
impl Style {
/// Scales all sizes in the style
#[doc(alias = "ScaleAllSizes")]
pub fn scale_all_sizes(&mut self, scale_factor: f32) {
unsafe {
sys::ImGuiStyle_ScaleAllSizes(self.raw_mut(), scale_factor);
}
}
/// Replaces current colors with classic Dear ImGui style
#[doc(alias = "StyleColors", alias = "StlyeColorsClassic")]
pub fn use_classic_colors(&mut self) -> &mut Self {
unsafe {
sys::igStyleColorsClassic(self.raw_mut());
@ -166,6 +168,7 @@ impl Style {
self
}
/// Replaces current colors with a new, recommended style
#[doc(alias = "StyleColors", alias = "StyleColorsDark")]
pub fn use_dark_colors(&mut self) -> &mut Self {
unsafe {
sys::igStyleColorsDark(self.raw_mut());
@ -174,6 +177,7 @@ impl Style {
}
/// Replaces current colors with a light style. Best used with borders and a custom, thicker
/// font
#[doc(alias = "StyleColors", alias = "StyleColorsLight")]
pub fn use_light_colors(&mut self) -> &mut Self {
unsafe {
sys::igStyleColorsLight(self.raw_mut());

View File

@ -25,85 +25,101 @@ bitflags! {
/// # Item/widget utilities
impl<'ui> Ui<'ui> {
/// Returns `true` if the last item is hovered
#[doc(alias = "IsItemHovered")]
pub fn is_item_hovered(&self) -> bool {
unsafe { sys::igIsItemHovered(0) }
}
/// Returns `true` if the last item is hovered based on the given flags
#[doc(alias = "IsItemHovered")]
pub fn is_item_hovered_with_flags(&self, flags: ItemHoveredFlags) -> bool {
unsafe { sys::igIsItemHovered(flags.bits() as i32) }
}
/// Returns `true` if the last item is active
#[doc(alias = "IsItemActive")]
pub fn is_item_active(&self) -> bool {
unsafe { sys::igIsItemActive() }
}
#[doc(alias = "IsItemFocused")]
/// Returns `true` if the last item is focused for keyboard/gamepad navigation
pub fn is_item_focused(&self) -> bool {
unsafe { sys::igIsItemFocused() }
}
/// Returns `true` if the last item is being clicked by `MouseButton::Left`.
///
/// This is the same as [is_item_clicked_with_button](Self::is_item_clicked_with_button)
/// with `button` set to `MouseButton::Left`.
#[doc(alias = "IsItemClicked")]
pub fn is_item_clicked(&self) -> bool {
self.is_item_clicked_with_button(MouseButton::Left)
}
/// Returns `true` if the last item is being clicked
#[doc(alias = "IsItemClicked")]
pub fn is_item_clicked_with_button(&self, button: MouseButton) -> bool {
unsafe { sys::igIsItemClicked(button as i32) }
}
/// Returns `true` if the last item is visible
#[doc(alias = "IsItemVisible")]
pub fn is_item_visible(&self) -> bool {
unsafe { sys::igIsItemVisible() }
}
/// Returns `true` if the last item modified its underlying value this frame or was pressed
#[doc(alias = "IsItemEdited")]
pub fn is_item_edited(&self) -> bool {
unsafe { sys::igIsItemEdited() }
}
/// Returns `true` if the last item was just made active
#[doc(alias = "IsItemActivated")]
pub fn is_item_activated(&self) -> bool {
unsafe { sys::igIsItemActivated() }
}
/// Returns `true` if the last item was just made inactive
#[doc(alias = "IsItemDeactivated")]
pub fn is_item_deactivated(&self) -> bool {
unsafe { sys::igIsItemDeactivated() }
}
/// Returns `true` if the last item was just made inactive and made a value change when it was
#[doc(alias = "IsItemDeactivatedAfterEdit")]
/// active
pub fn is_item_deactivated_after_edit(&self) -> bool {
unsafe { sys::igIsItemDeactivatedAfterEdit() }
}
/// Returns `true` if the last item open state was toggled
#[doc(alias = "IsItemToggledOpen")]
pub fn is_item_toggled_open(&self) -> bool {
unsafe { sys::igIsItemToggledOpen() }
}
/// Returns `true` if any item is hovered
#[doc(alias = "IsAnyItemHovered")]
pub fn is_any_item_hovered(&self) -> bool {
unsafe { sys::igIsAnyItemHovered() }
}
/// Returns `true` if any item is active
#[doc(alias = "IsAnyItemActive")]
pub fn is_any_item_active(&self) -> bool {
unsafe { sys::igIsAnyItemActive() }
}
/// Returns `true` if any item is focused
#[doc(alias = "IsAnyItemFocused")]
pub fn is_any_item_focused(&self) -> bool {
unsafe { sys::igIsAnyItemFocused() }
}
/// Returns the upper-left bounding rectangle of the last item (in screen coordinates)
#[doc(alias = "GetItemRectMin")]
pub fn item_rect_min(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetItemRectMin(&mut out) }
out.into()
}
/// Returns the lower-right bounding rectangle of the last item (in screen coordinates)
#[doc(alias = "GetItemRectMax")]
pub fn item_rect_max(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetItemRectMax(&mut out) }
out.into()
}
/// Returns the size of the last item
#[doc(alias = "GetItemRectSize")]
pub fn item_rect_size(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetItemRectSize(&mut out) }
@ -112,10 +128,12 @@ impl<'ui> Ui<'ui> {
/// Allows the last item to be overlapped by a subsequent item.
///
/// Both may be activated during the same frame before the later one takes priority.
#[doc(alias = "SetItemAllowOverlap")]
pub fn set_item_allow_overlap(&self) {
unsafe { sys::igSetItemAllowOverlap() };
}
/// Makes the last item the default focused item of the window
#[doc(alias = "SetItemDefaultFocus")]
pub fn set_item_default_focus(&self) {
unsafe { sys::igSetItemDefaultFocus() };
}
@ -124,22 +142,26 @@ impl<'ui> Ui<'ui> {
/// # Miscellaneous utilities
impl<'ui> Ui<'ui> {
/// Returns `true` if the rectangle (of given size, starting from cursor position) is visible
#[doc(alias = "IsRectVisibleNil")]
pub fn is_cursor_rect_visible(&self, size: [f32; 2]) -> bool {
unsafe { sys::igIsRectVisibleNil(size.into()) }
}
/// Returns `true` if the rectangle (in screen coordinates) is visible
#[doc(alias = "IsRectVisibleNilVec2")]
pub fn is_rect_visible(&self, rect_min: [f32; 2], rect_max: [f32; 2]) -> bool {
unsafe { sys::igIsRectVisibleVec2(rect_min.into(), rect_max.into()) }
}
/// Returns the global imgui-rs time.
///
/// Incremented by Io::delta_time every frame.
#[doc(alias = "GetTime")]
pub fn time(&self) -> f64 {
unsafe { sys::igGetTime() }
}
/// Returns the global imgui-rs frame count.
///
/// Incremented by 1 every frame.
#[doc(alias = "GetFrameCount")]
pub fn frame_count(&self) -> i32 {
unsafe { sys::igGetFrameCount() }
}
@ -147,6 +169,7 @@ impl<'ui> Ui<'ui> {
///
/// Use this function if you need to access the colors, but don't want to clone the entire
/// style object.
#[doc(alias = "GetStyle")]
pub fn style_color(&self, style_color: StyleColor) -> [f32; 4] {
self.ctx.style()[style_color]
}

View File

@ -192,6 +192,7 @@ pub struct ColorEdit<'a> {
impl<'a> ColorEdit<'a> {
/// Constructs a new color editor builder.
#[doc(alias = "ColorEdit3", alias = "ColorEdit4")]
pub fn new<T: Into<EditableColor<'a>>>(label: &'a ImStr, value: T) -> ColorEdit<'a> {
ColorEdit {
label,
@ -366,6 +367,7 @@ pub struct ColorPicker<'a> {
impl<'a> ColorPicker<'a> {
/// Constructs a new color picker builder.
#[doc(alias = "ColorButton")]
pub fn new<T: Into<EditableColor<'a>>>(label: &'a ImStr, value: T) -> ColorPicker<'a> {
ColorPicker {
label,
@ -637,6 +639,7 @@ impl<'ui> Ui<'ui> {
/// Initializes current color editor/picker options (generally on application startup) if you
/// want to select a default format, picker type, etc. Users will be able to change many
/// settings, unless you use .options(false) in your widget builders.
#[doc(alias = "SetColorEditOptions")]
pub fn set_color_edit_options(&self, flags: ColorEditFlags) {
unsafe {
sys::igSetColorEditOptions(flags.bits() as i32);

View File

@ -64,6 +64,7 @@ pub struct ComboBox<'a> {
impl<'a> ComboBox<'a> {
/// Constructs a new combo box builder.
#[doc(alias = "BeginCombo")]
pub const fn new(label: &'a ImStr) -> ComboBox<'a> {
ComboBox {
label,
@ -175,6 +176,7 @@ create_token!(
/// # Convenience functions
impl<'a> ComboBox<'a> {
/// Builds a simple combo box for choosing from a slice of values
#[doc(alias = "BeginCombo")]
pub fn build_simple<T, L>(
self,
ui: &Ui,
@ -207,6 +209,7 @@ impl<'a> ComboBox<'a> {
result
}
/// Builds a simple combo box for choosing from a slice of strings
#[doc(alias = "BeginCombo")]
pub fn build_simple_string<S>(self, ui: &Ui, current_item: &mut usize, items: &[&S]) -> bool
where
S: AsRef<ImStr> + ?Sized,

View File

@ -21,6 +21,7 @@ pub struct Drag<'a, T: DataTypeKind> {
impl<'a, T: DataTypeKind> Drag<'a, T> {
/// Constructs a new drag slider builder.
#[doc(alias = "DragScalar", alias = "DragScalarN")]
pub fn new(label: &ImStr) -> Drag<T> {
Drag {
label,
@ -126,6 +127,7 @@ pub struct DragRange<'a, T: DataTypeKind> {
impl<'a, T: DataTypeKind> DragRange<'a, T> {
/// Constructs a new drag slider builder.
#[doc(alias = "DragIntRange2", alias = "DragFloatRange2")]
pub fn new(label: &ImStr) -> DragRange<T> {
DragRange {
label,
@ -175,6 +177,7 @@ impl<'a> DragRange<'a, f32> {
/// Builds a drag range slider that is bound to the given min/max values.
///
/// Returns true if the slider value was changed.
#[doc(alias = "DragFloatRange2")]
pub fn build(self, _: &Ui, min: &mut f32, max: &mut f32) -> bool {
unsafe {
sys::igDragFloatRange2(
@ -200,6 +203,7 @@ impl<'a> DragRange<'a, i32> {
/// Builds a drag range slider that is bound to the given min/max values.
///
/// Returns true if the slider value was changed.
#[doc(alias = "DragIntRange2")]
pub fn build(self, _: &Ui, min: &mut i32, max: &mut i32) -> bool {
unsafe {
sys::igDragIntRange2(

View File

@ -18,6 +18,7 @@ pub struct Image {
impl Image {
/// Creates a new image builder with the given texture and size
#[doc(alias = "Image")]
pub const fn new(texture_id: TextureId, size: [f32; 2]) -> Image {
Image {
texture_id,
@ -83,6 +84,7 @@ pub struct ImageButton {
impl ImageButton {
/// Creates a new image button builder with the given texture and size
#[doc(alias = "ImageButton")]
pub fn new(texture_id: TextureId, size: [f32; 2]) -> ImageButton {
ImageButton {
texture_id,

View File

@ -22,6 +22,7 @@ pub struct ListBox<'a> {
impl<'a> ListBox<'a> {
/// Constructs a new list box builder.
#[doc(alias = "ListBoxHeaderVec2", alias = "ListBoxHeaderInt")]
pub const fn new(label: &'a ImStr) -> ListBox<'a> {
ListBox {
label,

View File

@ -13,6 +13,7 @@ impl<'ui> Ui<'ui> {
///
/// Returns `None` if the menu bar is not visible and no content should be rendered.
#[must_use]
#[doc(alias = "BeginMainMenuBar")]
pub fn begin_main_menu_bar(&self) -> Option<MainMenuBarToken<'ui>> {
if unsafe { sys::igBeginMainMenuBar() } {
Some(MainMenuBarToken::new(self))
@ -23,6 +24,7 @@ impl<'ui> Ui<'ui> {
/// Creates a full-screen main menu bar and runs a closure to construct the contents.
///
/// Note: the closure is not called if the menu bar is not visible.
#[doc(alias = "BeginMenuBar")]
pub fn main_menu_bar<F: FnOnce()>(&self, f: F) {
if let Some(_menu_bar) = self.begin_main_menu_bar() {
f();
@ -35,6 +37,7 @@ impl<'ui> Ui<'ui> {
///
/// Returns `None` if the menu bar is not visible and no content should be rendered.
#[must_use]
#[doc(alias = "BeginMenuBar")]
pub fn begin_menu_bar(&self) -> Option<MenuBarToken<'_>> {
if unsafe { sys::igBeginMenuBar() } {
Some(MenuBarToken::new(self))
@ -45,6 +48,7 @@ impl<'ui> Ui<'ui> {
/// Creates a menu bar in the current window and runs a closure to construct the contents.
///
/// Note: the closure is not called if the menu bar is not visible.
#[doc(alias = "BeginMenuBar")]
pub fn menu_bar<F: FnOnce()>(&self, f: F) {
if let Some(_menu_bar) = self.begin_menu_bar() {
f();
@ -61,6 +65,7 @@ impl<'ui> Ui<'ui> {
/// This is the equivalent of [begin_menu_with_enabled](Self::begin_menu_with_enabled)
/// with `enabled` set to `true`.
#[must_use]
#[doc(alias = "BeginMenu")]
pub fn begin_menu(&self, label: &ImStr) -> Option<MenuToken<'_>> {
self.begin_menu_with_enabled(label, true)
}
@ -72,6 +77,7 @@ impl<'ui> Ui<'ui> {
///
/// Returns `None` if the menu is not visible and no content should be rendered.
#[must_use]
#[doc(alias = "BeginMenu")]
pub fn begin_menu_with_enabled(&self, label: &ImStr, enabled: bool) -> Option<MenuToken<'_>> {
if unsafe { sys::igBeginMenu(label.as_ptr(), enabled) } {
Some(MenuToken::new(self))
@ -85,6 +91,7 @@ impl<'ui> Ui<'ui> {
///
/// This is the equivalent of [menu_with_enabled](Self::menu_with_enabled)
/// with `enabled` set to `true`.
#[doc(alias = "BeginMenu")]
pub fn menu<F: FnOnce()>(&self, label: &ImStr, f: F) {
self.menu_with_enabled(label, true, f);
}
@ -92,6 +99,7 @@ impl<'ui> Ui<'ui> {
/// Creates a menu and runs a closure to construct the contents.
///
/// Note: the closure is not called if the menu is not visible.
#[doc(alias = "BeginMenu")]
pub fn menu_with_enabled<F: FnOnce()>(&self, label: &ImStr, enabled: bool, f: F) {
if let Some(_menu) = self.begin_menu_with_enabled(label, enabled) {
f();
@ -146,6 +154,7 @@ impl<'a> MenuItem<'a> {
/// Builds the menu item.
///
/// Returns true if the menu item is activated.
#[doc(alias = "MenuItemBool")]
pub fn build(self, _: &Ui) -> bool {
unsafe {
sys::igMenuItemBool(

View File

@ -27,6 +27,8 @@ impl<'ui> Ui<'ui> {
/// This is the equivalent of [button_with_size](Self::button_with_size)
/// with `size` set to `[0.0, 0.0]`, which will size the button to the
/// label's width in the current style.
/// the current style.
#[doc("Button")]
pub fn button(&self, label: &ImStr) -> bool {
self.button_with_size(label, [0.0, 0.0])
}
@ -37,36 +39,42 @@ impl<'ui> Ui<'ui> {
///
/// Setting `size` as `[0.0, 0.0]` will size the button to the label's width in
/// the current style.
#[doc("Button")]
pub fn button_with_size(&self, label: &ImStr, size: [f32; 2]) -> bool {
unsafe { sys::igButton(label.as_ptr(), size.into()) }
}
/// Renders a small clickable button that is easy to embed in text.
///
/// Returns true if this button was clicked.
#[doc("SmallButton")]
pub fn small_button(&self, label: &ImStr) -> bool {
unsafe { sys::igSmallButton(label.as_ptr()) }
}
/// Renders a widget with button behaviour without the visual look.
///
/// Returns true if this button was clicked.
#[doc("InvisibleButton")]
pub fn invisible_button(&self, id: &ImStr, size: [f32; 2]) -> bool {
unsafe { sys::igInvisibleButton(id.as_ptr(), size.into(), 0) }
}
/// Renders a widget with button behaviour without the visual look.
///
/// Returns true if this button was clicked.
#[doc("InvisibleButton")]
pub fn invisible_button_flags(&self, id: &ImStr, size: [f32; 2], flags: ButtonFlags) -> bool {
unsafe { sys::igInvisibleButton(id.as_ptr(), size.into(), flags.bits() as i32) }
}
/// Renders a square button with an arrow shape.
///
/// Returns true if this button was clicked.
#[doc("ArrowButton")]
pub fn arrow_button(&self, id: &ImStr, direction: Direction) -> bool {
unsafe { sys::igArrowButton(id.as_ptr(), direction as i32) }
}
/// Renders a simple checkbox.
///
/// Returns true if this checkbox was clicked.
#[doc("Checkbox")]
pub fn checkbox(&self, label: &ImStr, value: &mut bool) -> bool {
unsafe { sys::igCheckbox(label.as_ptr(), value as *mut bool) }
}
@ -91,12 +99,14 @@ impl<'ui> Ui<'ui> {
/// Renders a simple radio button.
///
/// Returns true if this radio button was clicked.
#[doc("RadioButtonBool")]
pub fn radio_button_bool(&self, label: &ImStr, active: bool) -> bool {
unsafe { sys::igRadioButtonBool(label.as_ptr(), active) }
}
/// Renders a radio button suitable for choosing an arbitrary value.
///
/// Returns true if this radio button was clicked.
#[doc("RadioButtonBool")]
pub fn radio_button<T>(&self, label: &ImStr, value: &mut T, button_value: T) -> bool
where
T: Copy + PartialEq,
@ -108,6 +118,7 @@ impl<'ui> Ui<'ui> {
pressed
}
/// Renders a small circle and keeps the cursor on the same line
#[doc("Bullet")]
pub fn bullet(&self) {
unsafe { sys::igBullet() };
}

View File

@ -32,6 +32,7 @@ impl<'a> ProgressBar<'a> {
/// The progress bar will be automatically sized to fill the entire width of the window if no
/// custom size is specified.
#[inline]
#[doc(alias = "ProgressBar")]
pub const fn new(fraction: f32) -> ProgressBar<'a> {
ProgressBar {
fraction,

View File

@ -34,6 +34,7 @@ pub struct Selectable<'a> {
impl<'a> Selectable<'a> {
/// Constructs a new selectable builder.
#[inline]
#[doc(alias = "Selectable")]
pub const fn new(label: &ImStr) -> Selectable {
Selectable {
label,

View File

@ -37,6 +37,7 @@ pub struct Slider<'a, T: DataTypeKind> {
impl<'a, T: DataTypeKind> Slider<'a, T> {
/// Constructs a new slider builder with the given range.
#[doc(alias = "SliderScalar", alias = "SliderScalarN")]
pub fn new(label: &ImStr) -> Slider<T> {
Slider {
label,
@ -118,6 +119,7 @@ pub struct VerticalSlider<'a, T: DataTypeKind + Copy> {
impl<'a, T: DataTypeKind> VerticalSlider<'a, T> {
/// Constructs a new vertical slider builder with the given size and range.
#[doc(alias = "VSliderScalar")]
pub fn new(label: &ImStr, size: [f32; 2]) -> VerticalSlider<T> {
VerticalSlider {
label,
@ -181,6 +183,7 @@ pub struct AngleSlider<'a> {
impl<'a> AngleSlider<'a> {
/// Constructs a new angle slider builder.
#[doc(alias = "SliderAngle")]
pub fn new(label: &ImStr) -> AngleSlider {
AngleSlider {
label,

View File

@ -63,6 +63,7 @@ pub struct TabBar<'a> {
impl<'a> TabBar<'a> {
#[inline]
#[doc(alias = "BeginTabBar")]
pub const fn new(id: &'a ImStr) -> Self {
Self {
id,
@ -127,6 +128,7 @@ pub struct TabItem<'a> {
}
impl<'a> TabItem<'a> {
#[doc(alias = "BeginTabItem")]
pub fn new(name: &'a ImStr) -> Self {
Self {
name,

View File

@ -14,6 +14,7 @@ fn fmt_ptr() -> *const c_char {
/// # Widgets: Text
impl<'ui> Ui<'ui> {
/// Renders simple text
#[doc(alias = "TextUnformatted")]
pub fn text<T: AsRef<str>>(&self, text: T) {
let s = text.as_ref();
unsafe {
@ -36,14 +37,17 @@ impl<'ui> Ui<'ui> {
style.end();
}
/// Renders text wrapped to the end of window (or column)
#[doc(alias = "TextWrapperd")]
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
#[doc(alias = "LabelText")]
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
#[doc(alias = "BulletText")]
pub fn bullet_text(&self, text: &ImStr) {
unsafe { sys::igBulletText(fmt_ptr(), text.as_ptr()) }
}

View File

@ -300,6 +300,7 @@ impl<'a> TreeNodeToken<'a> {
}
impl Drop for TreeNodeToken<'_> {
#[doc(alias = "TreePop")]
fn drop(&mut self) {
if self.1 {
unsafe { sys::igTreePop() }
@ -317,6 +318,7 @@ pub struct CollapsingHeader<'a> {
impl<'a> CollapsingHeader<'a> {
/// Constructs a new collapsing header builder
#[doc(alias = "CollapsingHeader")]
pub fn new(label: &ImStr) -> CollapsingHeader {
CollapsingHeader {
label,

View File

@ -20,6 +20,7 @@ pub struct ChildWindow<'a> {
impl<'a> ChildWindow<'a> {
/// Creates a new child window builder with the given ID
#[doc(alas = "BeginChildID")]
pub fn new<T: Into<Id<'a>>>(id: T) -> ChildWindow<'a> {
ChildWindow {
id: id.into(),
@ -54,12 +55,14 @@ impl<'a> ChildWindow<'a> {
/// Does not include window decorations (title bar, menu bar, etc.). Set one of the values to
/// 0.0 to leave the size automatic.
#[inline]
#[doc(alias = "SetNextWindowContentSize")]
pub fn content_size(mut self, size: [f32; 2]) -> Self {
self.content_size = size;
self
}
/// Sets the window focused state, which can be used to bring the window to front
#[inline]
#[doc(alias = "SetNextWindwowFocus")]
pub fn focused(mut self, focused: bool) -> Self {
self.focused = focused;
self
@ -68,6 +71,7 @@ impl<'a> ChildWindow<'a> {
///
/// See also `draw_background`
#[inline]
#[doc(alias = "SetNextWindowContentBgAlpha")]
pub fn bg_alpha(mut self, bg_alpha: f32) -> Self {
self.bg_alpha = bg_alpha;
self

View File

@ -4,12 +4,14 @@ use crate::Ui;
/// # Content region
impl<'ui> Ui<'ui> {
/// Returns the current content boundaries (in *window coordinates*)
#[doc(alias = "GetContentRegionMax")]
pub fn content_region_max(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetContentRegionMax(&mut out) };
out.into()
}
/// Equal to `ui.content_region_max()` - `ui.cursor_pos()`
#[doc(alias = "GetContentRegionAvail")]
pub fn content_region_avail(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetContentRegionAvail(&mut out) };
@ -18,6 +20,7 @@ impl<'ui> Ui<'ui> {
/// Content boundaries min (in *window coordinates*).
///
/// Roughly equal to [0.0, 0.0] - scroll.
#[doc(alias = "GetContentRegionMin")]
pub fn window_content_region_min(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetWindowContentRegionMin(&mut out) };
@ -26,11 +29,13 @@ impl<'ui> Ui<'ui> {
/// Content boundaries max (in *window coordinates*).
///
/// Roughly equal to [0.0, 0.0] + size - scroll.
#[doc(alias = "GetContentRegionMax")]
pub fn window_content_region_max(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetWindowContentRegionMax(&mut out) };
out.into()
}
#[doc(alias = "GetContentRegionWidth")]
pub fn window_content_region_width(&self) -> f32 {
unsafe { sys::igGetWindowContentRegionWidth() }
}

View File

@ -113,36 +113,44 @@ bitflags! {
/// # Window utilities
impl<'ui> Ui<'ui> {
/// Returns true if the current window appeared during this frame
#[doc(alias = "IsWindowAppearing")]
pub fn is_window_appearing(&self) -> bool {
unsafe { sys::igIsWindowAppearing() }
}
/// Returns true if the current window is in collapsed state (= only the title bar is visible)
#[doc(alias = "IsWindowCollapsed")]
pub fn is_window_collapsed(&self) -> bool {
unsafe { sys::igIsWindowCollapsed() }
}
/// Returns true if the current window is focused
#[doc(alias = "IsWindowFocused")]
pub fn is_window_focused(&self) -> bool {
unsafe { sys::igIsWindowFocused(0) }
}
/// Returns true if the current window is focused based on the given flags
#[doc(alias = "IsWindowFocused")]
pub fn is_window_focused_with_flags(&self, flags: WindowFocusedFlags) -> bool {
unsafe { sys::igIsWindowFocused(flags.bits() as i32) }
}
/// Returns true if the current window is hovered
#[doc(alias = "IsWindowHovered")]
pub fn is_window_hovered(&self) -> bool {
unsafe { sys::igIsWindowHovered(0) }
}
/// Returns true if the current window is hovered based on the given flags
#[doc(alias = "IsWindowHovered")]
pub fn is_window_hovered_with_flags(&self, flags: WindowHoveredFlags) -> bool {
unsafe { sys::igIsWindowHovered(flags.bits() as i32) }
}
/// Returns the position of the current window (in screen space)
#[doc(alias = "GetWindowPos")]
pub fn window_pos(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetWindowPos(&mut out) };
out.into()
}
/// Returns the size of the current window
#[doc(alias = "GetWindowPos")]
pub fn window_size(&self) -> [f32; 2] {
let mut out = sys::ImVec2::zero();
unsafe { sys::igGetWindowSize(&mut out) };

View File

@ -6,38 +6,45 @@ impl<'ui> Ui<'ui> {
/// Returns the horizontal scrolling position.
///
/// Value is between 0.0 and self.scroll_max_x().
#[doc(alias = "GetScrollX")]
pub fn scroll_x(&self) -> f32 {
unsafe { sys::igGetScrollX() }
}
/// Returns the vertical scrolling position.
///
/// Value is between 0.0 and self.scroll_max_y().
#[doc(alias = "GetScrollY")]
pub fn scroll_y(&self) -> f32 {
unsafe { sys::igGetScrollY() }
}
/// Returns the maximum horizontal scrolling position.
///
/// Roughly equal to content size X - window size X.
#[doc(alias = "GetScrollMaxX")]
pub fn scroll_max_x(&self) -> f32 {
unsafe { sys::igGetScrollMaxX() }
}
/// Returns the maximum vertical scrolling position.
///
/// Roughly equal to content size Y - window size Y.
#[doc(alias = "GetScrollMaxY")]
pub fn scroll_max_y(&self) -> f32 {
unsafe { sys::igGetScrollMaxY() }
}
/// Sets the horizontal scrolling position
#[doc(alias = "SetScrollX")]
pub fn set_scroll_x(&self, scroll_x: f32) {
unsafe { sys::igSetScrollX(scroll_x) };
}
/// Sets the vertical scroll position
#[doc(alias = "SetScrollY")]
pub fn set_scroll_y(&self, scroll_y: f32) {
unsafe { sys::igSetScrollY(scroll_y) };
}
/// Adjusts the horizontal scroll position to make the current cursor position visible.
///
/// This is the same as [set_scroll_here_x_with_ratio](Self::set_scroll_here_x_with_ratio) but with `ratio` at 0.5.
#[doc(alias = "SetScrollHereX")]
pub fn set_scroll_here_x(&self) {
self.set_scroll_here_x_with_ratio(0.5);
}
@ -48,12 +55,14 @@ impl<'ui> Ui<'ui> {
/// - `0.0`: left
/// - `0.5`: center
/// - `1.0`: right
#[doc(alias = "SetScrollHereX")]
pub fn set_scroll_here_x_with_ratio(&self, center_x_ratio: f32) {
unsafe { sys::igSetScrollHereX(center_x_ratio) };
}
/// Adjusts the vertical scroll position to make the current cursor position visible
///
/// This is the same as [set_scroll_here_y_with_ratio](Self::set_scroll_here_y_with_ratio) but with `ratio` at 0.5.
#[doc(alias = "SetScrollHereY")]
pub fn set_scroll_here_y(&self) {
self.set_scroll_here_y_with_ratio(0.5);
}
@ -64,9 +73,11 @@ impl<'ui> Ui<'ui> {
/// - `0.0`: top
/// - `0.5`: center
/// - `1.0`: bottom
#[doc(alias = "SetScrollHereY")]
pub fn set_scroll_here_y_with_ratio(&self, center_y_ratio: f32) {
unsafe { sys::igSetScrollHereY(center_y_ratio) };
}
#[doc(alias = "SetScrollFromPosX")]
/// Adjusts the horizontal scroll position to make the given position visible
///
/// This is the same as [set_scroll_from_pos_x_with_ratio](Self::set_scroll_from_pos_x_with_ratio)
@ -81,6 +92,7 @@ impl<'ui> Ui<'ui> {
/// - `0.0`: left
/// - `0.5`: center
/// - `1.0`: right
#[doc(alias = "SetScrollFromPosX")]
pub fn set_scroll_from_pos_x_with_ratio(&self, local_x: f32, center_x_ratio: f32) {
unsafe { sys::igSetScrollFromPosX(local_x, center_x_ratio) };
}
@ -88,6 +100,7 @@ impl<'ui> Ui<'ui> {
///
/// This is the same as [set_scroll_from_pos_y_with_ratio](Self::set_scroll_from_pos_y_with_ratio)
/// but with `ratio` at 0.5.
#[doc(alias = "SetScrollFromPosY")]
pub fn set_scroll_from_pos_y(&self, local_y: f32) {
self.set_scroll_from_pos_y_with_ratio(local_y, 0.5);
}
@ -98,6 +111,7 @@ impl<'ui> Ui<'ui> {
/// - `0.0`: top
/// - `0.5`: center
/// - `1.0`: bottom
#[doc(alias = "SetScrollFromPosY")]
pub fn set_scroll_from_pos_y_with_ratio(&self, local_y: f32, center_y_ratio: f32) {
unsafe { sys::igSetScrollFromPosY(local_y, center_y_ratio) };
}