#![allow(non_upper_case_globals)]
use bitflags::bitflags;
use std::ffi::CStr;
use std::os::raw::c_int;
use std::str;
use crate::fonts::atlas::{FontAtlas, FontAtlasTexture, FontConfig};
use crate::fonts::font::Font;
use crate::fonts::glyph_ranges::FontGlyphRanges;
use crate::input::keyboard::Key;
use crate::input::mouse::{MouseButton, MouseCursor};
use crate::internal::RawCast;
use crate::render::draw_data::{DrawIdx, DrawVert};
use crate::render::renderer::TextureId;
use crate::style::{Style, StyleColor, StyleVar};
use crate::{Condition, Context, Ui};
#[deprecated(since = "0.1.0", note = "use Font instead")]
pub type ImFont = Font;
#[deprecated(since = "0.1.0", note = "use Key instead")]
pub type ImGuiKey = Key;
#[deprecated(since = "0.1.0", note = "use MouseCursor instead")]
pub type ImGuiMouseCursor = MouseCursor;
#[deprecated(since = "0.1.0", note = "use MouseButton instead")]
pub type ImMouseButton = MouseButton;
#[deprecated(since = "0.1.0", note = "use FontConfig instead")]
pub type ImFontConfig = FontConfig;
#[deprecated(since = "0.1.0", note = "use FontAtlas instead")]
pub type ImFontAtlas = FontAtlas;
#[deprecated(since = "0.1.0", note = "use Context instead")]
pub type ImGui = Context;
#[deprecated(since = "0.1.0", note = "use Condition instead")]
pub type ImGuiCond = Condition;
#[deprecated(since = "0.1.0", note = "use StyleColor instead")]
pub type ImGuiCol = StyleColor;
#[deprecated(since = "0.1.0", note = "use TextureId instead")]
pub type ImTexture = TextureId;
#[deprecated(since = "0.1.0", note = "use Style instead")]
pub type ImGuiStyle = Style;
#[deprecated(since = "0.1.0", note = "use DrawIdx instead")]
pub type ImDrawIdx = DrawIdx;
#[deprecated(since = "0.1.0", note = "use DrawVert instead")]
pub type ImDrawVert = DrawVert;
#[deprecated(since = "0.1.0", note = "use FontAtlasTexture instead")]
pub type TextureHandle<'a> = FontAtlasTexture<'a>;
#[deprecated(since = "0.1.0", note = "use FontGlyphRanges instead")]
pub type FontGlyphRange = FontGlyphRanges;
bitflags!(
#[repr(C)]
pub struct ImGuiColorEditFlags: c_int {
const NoAlpha = 1;
const NoPicker = 1 << 2;
const NoOptions = 1 << 3;
const NoSmallPreview = 1 << 4;
const NoInputs = 1 << 5;
const NoTooltip = 1 << 6;
const NoLabel = 1 << 7;
const NoSidePreview = 1 << 8;
const NoDragDrop = 1 << 9;
const AlphaBar = 1 << 16;
const AlphaPreview = 1 << 17;
const AlphaPreviewHalf= 1 << 18;
const HDR = 1 << 19;
const RGB = 1 << 20;
const HSV = 1 << 21;
const HEX = 1 << 22;
const Uint8 = 1 << 23;
const Float = 1 << 24;
const PickerHueBar = 1 << 25;
const PickerHueWheel = 1 << 26;
}
);
bitflags!(
#[repr(C)]
pub struct ImGuiComboFlags: c_int {
const PopupAlignLeft = 1;
const HeightSmall = 1 << 1;
const HeightRegular = 1 << 2;
const HeightLarge = 1 << 3;
const HeightLargest = 1 << 4;
const NoArrowButton = 1 << 5;
const NoPreview = 1 << 6;
const HeightMask = ImGuiComboFlags::HeightSmall.bits
| ImGuiComboFlags::HeightRegular.bits
| ImGuiComboFlags::HeightLarge.bits
| ImGuiComboFlags::HeightLargest.bits;
}
);
bitflags!(
#[repr(C)]
pub struct ImGuiDragDropFlags: c_int {
const SourceNoPreviewTooltip = 1;
const SourceNoDisableHover = 1 << 1;
const SourceNoHoldToOpenOthers = 1 << 2;
const SourceAllowNullID = 1 << 3;
const SourceExtern = 1 << 4;
const SourceAutoExpirePayload = 1 << 5;
const AcceptBeforeDelivery = 1 << 10;
const AcceptNoDrawDefaultRect = 1 << 11;
const AcceptNoPreviewTooltip = 1 << 12;
const AcceptPeekOnly = ImGuiDragDropFlags::AcceptBeforeDelivery.bits
| ImGuiDragDropFlags::AcceptNoDrawDefaultRect.bits;
}
);
bitflags!(
#[repr(C)]
pub struct ImDrawCornerFlags: c_int {
const TopLeft = 1;
const TopRight = 1 << 1;
const BotLeft = 1 << 2;
const BotRight = 1 << 3;
const Top = ImDrawCornerFlags::TopLeft.bits
| ImDrawCornerFlags::TopRight.bits;
const Bot = ImDrawCornerFlags::BotLeft.bits
| ImDrawCornerFlags::BotRight.bits;
const Left = ImDrawCornerFlags::TopLeft.bits
| ImDrawCornerFlags::BotLeft.bits;
const Right = ImDrawCornerFlags::TopRight.bits
| ImDrawCornerFlags::BotRight.bits;
const All = 0xF;
}
);
bitflags!(
#[repr(C)]
pub struct ImDrawListFlags: c_int {
const AntiAliasedLines = 1;
const AntiAliasedFill = 1 << 1;
}
);
bitflags!(
#[repr(C)]
pub struct ImGuiFocusedFlags: c_int {
const ChildWindows = 1;
const RootWindow = 1 << 1;
const AnyWindow = 1 << 2;
const RootAndChildWindows =
ImGuiFocusedFlags::RootWindow.bits | ImGuiFocusedFlags::ChildWindows.bits;
}
);
bitflags!(
#[repr(C)]
pub struct ImGuiHoveredFlags: c_int {
const ChildWindows = 1;
const RootWindow = 1 << 1;
const AnyWindow = 1 << 2;
const AllowWhenBlockedByPopup = 1 << 3;
const AllowWhenBlockedByActiveItem = 1 << 5;
const AllowWhenOverlapped = 1 << 6;
const AllowWhenDisabled = 1 << 7;
const RectOnly = ImGuiHoveredFlags::AllowWhenBlockedByPopup.bits
| ImGuiHoveredFlags::AllowWhenBlockedByActiveItem.bits
| ImGuiHoveredFlags::AllowWhenOverlapped.bits;
const RootAndChildWindows = ImGuiFocusedFlags::RootWindow.bits
| ImGuiFocusedFlags::ChildWindows.bits;
}
);
bitflags!(
#[repr(C)]
pub struct ImGuiInputTextFlags: c_int {
const CharsDecimal = 1;
const CharsHexadecimal = 1 << 1;
const CharsUppercase = 1 << 2;
const CharsNoBlank = 1 << 3;
const AutoSelectAll = 1 << 4;
const EnterReturnsTrue = 1 << 5;
const CallbackCompletion = 1 << 6;
const CallbackHistory = 1 << 7;
const CallbackAlways = 1 << 8;
const CallbackCharFilter = 1 << 9;
const AllowTabInput = 1 << 10;
const CtrlEnterForNewLine = 1 << 11;
const NoHorizontalScroll = 1 << 12;
const AlwaysInsertMode = 1 << 13;
const ReadOnly = 1 << 14;
const Password = 1 << 15;
const NoUndoRedo = 1 << 16;
const CharsScientific = 1 << 17;
const CallbackResize = 1 << 18;
}
);
bitflags!(
#[repr(C)]
pub struct ImGuiSelectableFlags: c_int {
const DontClosePopups = 1;
const SpanAllColumns = 1 << 1;
const AllowDoubleClick = 1 << 2;
const Disabled = 1 << 3;
}
);
bitflags!(
#[repr(C)]
pub struct ImGuiTreeNodeFlags: c_int {
const Selected = 1;
const Framed = 1 << 1;
const AllowItemOverlap = 1 << 2;
const NoTreePushOnOpen = 1 << 3;
const NoAutoOpenOnLog = 1 << 4;
const DefaultOpen = 1 << 5;
const OpenOnDoubleClick = 1 << 6;
const OpenOnArrow = 1 << 7;
const Leaf = 1 << 8;
const Bullet = 1 << 9;
const FramePadding = 1 << 10;
const NavLeftJumpsBackHere = 1 << 13;
const CollapsingHeader =
ImGuiTreeNodeFlags::Framed.bits | ImGuiTreeNodeFlags::NoTreePushOnOpen.bits |
ImGuiTreeNodeFlags::NoAutoOpenOnLog.bits;
}
);
bitflags!(
#[repr(C)]
pub struct ImGuiWindowFlags: c_int {
const NoTitleBar = 1;
const NoResize = 1 << 1;
const NoMove = 1 << 2;
const NoScrollbar = 1 << 3;
const NoScrollWithMouse = 1 << 4;
const NoCollapse = 1 << 5;
const AlwaysAutoResize = 1 << 6;
const NoBackground = 1 << 7;
const NoSavedSettings = 1 << 8;
const NoMouseInputs = 1 << 9;
const MenuBar = 1 << 10;
const HorizontalScrollbar = 1 << 11;
const NoFocusOnAppearing = 1 << 12;
const NoBringToFrontOnFocus = 1 << 13;
const AlwaysVerticalScrollbar = 1 << 14;
const AlwaysHorizontalScrollbar = 1<< 15;
const AlwaysUseWindowPadding = 1 << 16;
const NoNavInputs = 1 << 18;
const NoNavFocus = 1 << 19;
const NoNav = ImGuiWindowFlags::NoNavInputs.bits | ImGuiWindowFlags::NoNavFocus.bits;
const NoDecoration = ImGuiWindowFlags::NoTitleBar.bits | ImGuiWindowFlags::NoResize.bits
| ImGuiWindowFlags::NoScrollbar.bits | ImGuiWindowFlags::NoCollapse.bits;
const NoInputs = ImGuiWindowFlags::NoMouseInputs.bits | ImGuiWindowFlags::NoNavInputs.bits
| ImGuiWindowFlags::NoNavFocus.bits;
}
);
impl Context {
#[deprecated(since = "0.1.0", note = "Use Context::create instead")]
pub fn init() -> Context {
Context::create()
}
#[deprecated(since = "0.1.0", note = "Access Io::ini_saving_rate directly instead")]
pub fn set_ini_saving_rate(&mut self, value: f32) {
let io = self.io_mut();
io.ini_saving_rate = value;
}
#[deprecated(
since = "0.1.0",
note = "Access Io::font_global_scale directly instead"
)]
pub fn set_font_global_scale(&mut self, value: f32) {
let io = self.io_mut();
io.font_global_scale = value;
}
#[deprecated(
since = "0.1.0",
note = "Access Io::mouse_double_click_time directly instead"
)]
pub fn set_mouse_double_click_time(&mut self, value: f32) {
let io = self.io_mut();
io.mouse_double_click_time = value;
}
#[deprecated(
since = "0.1.0",
note = "Access Io::mouse_double_click_max_dist directly instead"
)]
pub fn set_mouse_double_click_max_dist(&mut self, value: f32) {
let io = self.io_mut();
io.mouse_double_click_max_dist = value;
}
#[deprecated(
since = "0.1.0",
note = "Access Io::mouse_drag_threshold directly instead"
)]
pub fn set_mouse_drag_threshold(&mut self, value: f32) {
let io = self.io_mut();
io.mouse_drag_threshold = value;
}
#[deprecated(since = "0.1.0", note = "Access Io::key_repeat_delay directly instead")]
pub fn set_key_repeat_delay(&mut self, value: f32) {
let io = self.io_mut();
io.key_repeat_delay = value;
}
#[deprecated(since = "0.1.0", note = "Access Io::key_repeat_rate directly instead")]
pub fn set_key_repeat_rate(&mut self, value: f32) {
let io = self.io_mut();
io.key_repeat_rate = value;
}
#[deprecated(since = "0.1.0", note = "Access Io::display_size directly instead")]
pub fn display_size(&self) -> (f32, f32) {
let io = self.io();
(io.display_size[0], io.display_size[1])
}
#[deprecated(
since = "0.1.0",
note = "Access Io::display_framebuffer_scale directly instead"
)]
pub fn display_framebuffer_scale(&self) -> (f32, f32) {
let io = self.io();
(
io.display_framebuffer_scale[0],
io.display_framebuffer_scale[1],
)
}
#[deprecated(since = "0.1.0", note = "Access Io::mouse_pos directly instead")]
pub fn mouse_pos(&self) -> (f32, f32) {
let io = self.io();
(io.mouse_pos[0], io.mouse_pos[1])
}
#[deprecated(since = "0.1.0", note = "Access Io::mouse_pos directly instead")]
pub fn set_mouse_pos(&mut self, x: f32, y: f32) {
let io = self.io_mut();
io.mouse_pos = [x, y];
}
#[deprecated(since = "0.1.0", note = "Access Io::mouse_delta directly instead")]
pub fn mouse_delta(&self) -> (f32, f32) {
let io = self.io();
(io.mouse_delta[0], io.mouse_delta[1])
}
#[deprecated(since = "0.1.0", note = "Access Io::mouse_down directly instead")]
pub fn mouse_down(&self) -> [bool; 5] {
let io = self.io();
io.mouse_down
}
#[deprecated(since = "0.1.0", note = "Access Io::mouse_down directly instead")]
pub fn set_mouse_down(&mut self, states: [bool; 5]) {
let io = self.io_mut();
io.mouse_down = states;
}
#[deprecated(since = "0.1.0", note = "Access Io::mouse_wheel directly instead")]
pub fn set_mouse_wheel(&mut self, value: f32) {
let io = self.io_mut();
io.mouse_wheel = value;
}
#[deprecated(since = "0.1.0", note = "Access Io::mouse_wheel directly instead")]
pub fn mouse_wheel(&self) -> f32 {
let io = self.io();
io.mouse_wheel
}
#[deprecated(since = "0.1.0", note = "Use Ui::mouse_drag_delta instead")]
pub fn mouse_drag_delta(&self, button: MouseButton) -> (f32, f32) {
let delta = unsafe { sys::igGetMouseDragDelta_nonUDT2(button as c_int, -1.0) };
delta.into()
}
#[deprecated(
since = "0.1.0",
note = "Access Io::mouse_draw_cursor directly instead"
)]
pub fn set_mouse_draw_cursor(&mut self, value: bool) {
let io = self.io_mut();
io.mouse_draw_cursor = value;
}
#[deprecated(
since = "0.1.0",
note = "Access Io::mouse_draw_cursor directly instead"
)]
pub fn mouse_draw_cursor(&self) -> bool {
let io = self.io();
io.mouse_draw_cursor
}
#[deprecated(since = "0.1.0", note = "Use Ui::is_mouse_dragging instead")]
pub fn is_mouse_dragging(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseDragging(button as c_int, -1.0) }
}
#[deprecated(since = "0.1.0", note = "Use Ui::is_mouse_down instead")]
pub fn is_mouse_down(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseDown(button as c_int) }
}
#[deprecated(since = "0.1.0", note = "Use Ui::is_mouse_clicked instead")]
pub fn is_mouse_clicked(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseClicked(button as c_int, false) }
}
#[deprecated(since = "0.1.0", note = "Use Ui::is_mouse_double_clicked instead")]
pub fn is_mouse_double_clicked(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseDoubleClicked(button as c_int) }
}
#[deprecated(since = "0.1.0", note = "Use Ui::is_mouse_released instead")]
pub fn is_mouse_released(&self, button: MouseButton) -> bool {
unsafe { sys::igIsMouseReleased(button as c_int) }
}
#[deprecated(since = "0.1.0", note = "Access Io::key_ctrl directly instead")]
pub fn key_ctrl(&self) -> bool {
let io = self.io();
io.key_ctrl
}
#[deprecated(since = "0.1.0", note = "Access Io::key_ctrl directly instead")]
pub fn set_key_ctrl(&mut self, value: bool) {
let io = self.io_mut();
io.key_ctrl = value;
}
#[deprecated(since = "0.1.0", note = "Access Io::key_shift directly instead")]
pub fn key_shift(&self) -> bool {
let io = self.io();
io.key_shift
}
#[deprecated(since = "0.1.0", note = "Access Io::key_shift directly instead")]
pub fn set_key_shift(&mut self, value: bool) {
let io = self.io_mut();
io.key_shift = value;
}
#[deprecated(since = "0.1.0", note = "Access Io::key_alt directly instead")]
pub fn key_alt(&self) -> bool {
let io = self.io();
io.key_alt
}
#[deprecated(since = "0.1.0", note = "Access Io::key_alt directly instead")]
pub fn set_key_alt(&mut self, value: bool) {
let io = self.io_mut();
io.key_alt = value;
}
#[deprecated(since = "0.1.0", note = "Access Io::key_super directly instead")]
pub fn key_super(&self) -> bool {
let io = self.io();
io.key_super
}
#[deprecated(since = "0.1.0", note = "Access Io::key_super directly instead")]
pub fn set_key_super(&mut self, value: bool) {
let io = self.io_mut();
io.key_super = value;
}
#[deprecated(since = "0.1.0", note = "Access Io::keys_down directly instead")]
pub fn set_key(&mut self, key: u8, pressed: bool) {
let io = self.io_mut();
io.keys_down[key as usize] = pressed;
}
#[deprecated(since = "0.1.0", note = "Index Io::key_map with the key instead")]
pub fn set_imgui_key(&mut self, key: Key, mapping: u8) {
let io = self.io_mut();
io.key_map[key as usize] = u32::from(mapping);
}
#[deprecated(since = "0.1.0", note = "Index Io::key_map with the key instead")]
pub fn get_key_index(&self, key: Key) -> usize {
unsafe { sys::igGetKeyIndex(key as i32) as usize }
}
#[deprecated(since = "0.1.0", note = "Use Ui::is_key_down instead")]
pub fn is_key_down(&self, user_key_index: usize) -> bool {
unsafe { sys::igIsKeyDown(user_key_index as c_int) }
}
#[deprecated(since = "0.1.0", note = "Use Ui::is_key_pressed instead")]
pub fn is_key_pressed(&self, user_key_index: usize) -> bool {
unsafe { sys::igIsKeyPressed(user_key_index as c_int, true) }
}
#[deprecated(since = "0.1.0", note = "Use Ui::is_key_released instead")]
pub fn is_key_released(&self, user_key_index: usize) -> bool {
unsafe { sys::igIsKeyReleased(user_key_index as c_int) }
}
#[deprecated(since = "0.1.0", note = "Use Io::add_input_character instead")]
pub fn add_input_character(&mut self, character: char) {
let mut buf = [0; 5];
character.encode_utf8(&mut buf);
unsafe {
sys::ImGuiIO_AddInputCharactersUTF8(self.io_mut().raw_mut(), buf.as_ptr() as *const _);
}
}
#[deprecated(since = "0.1.0", note = "Access Io::framerate directly instead")]
pub fn get_frame_rate(&self) -> f32 {
self.io().framerate
}
#[deprecated(since = "0.1.0", note = "Use Context::time instead")]
pub fn get_time(&self) -> f64 {
self.time()
}
#[deprecated(since = "0.1.0", note = "Use Context::frame_count instead")]
pub fn get_frame_count(&self) -> i32 {
self.frame_count()
}
}
impl<'ui> Ui<'ui> {
#[deprecated(
since = "0.1.0",
note = "This function is potentially unsafe and will be removed"
)]
pub fn imgui(&self) -> &Context {
self.ctx
}
#[deprecated(
since = "0.1.0",
note = "Access Io::want_capture_mouse directly instead"
)]
pub fn want_capture_mouse(&self) -> bool {
let io = self.io();
io.want_capture_mouse
}
#[deprecated(
since = "0.1.0",
note = "Access Io::want_capture_keyboard directly instead"
)]
pub fn want_capture_keyboard(&self) -> bool {
let io = self.io();
io.want_capture_keyboard
}
#[deprecated(since = "0.1.0", note = "Access Io::framerate directly instead")]
pub fn framerate(&self) -> f32 {
let io = self.io();
io.framerate
}
#[deprecated(
since = "0.1.0",
note = "Access Io::metrics_render_vertices directly instead"
)]
pub fn metrics_render_vertices(&self) -> i32 {
let io = self.io();
io.metrics_render_vertices
}
#[deprecated(
since = "0.1.0",
note = "Access Io::metrics_render_indices directly instead"
)]
pub fn metrics_render_indices(&self) -> i32 {
let io = self.io();
io.metrics_render_indices
}
#[deprecated(
since = "0.1.0",
note = "Access Io::metrics_active_windows directly instead"
)]
pub fn metrics_active_windows(&self) -> i32 {
let io = self.io();
io.metrics_active_windows
}
}
#[deprecated(since = "0.1.0", note = "Use dear_imgui_version instead")]
pub fn get_version() -> &'static str {
unsafe {
let bytes = CStr::from_ptr(sys::igGetVersion()).to_bytes();
str::from_utf8_unchecked(bytes)
}
}
impl<'ui> Ui<'ui> {
#[deprecated(since = "0.1.0", note = "use Ui::push_style_color instead")]
pub fn with_color_var<T, F>(&self, style_color: StyleColor, color: [f32; 4], f: F) -> T
where
F: FnOnce() -> T,
{
let _token = self.push_style_color(style_color, color);
f()
}
#[deprecated(since = "0.1.0", note = "use Ui::push_style_colors instead")]
pub fn with_color_vars<'a, T, F, I>(&self, style_colors: I, f: F) -> T
where
F: FnOnce() -> T,
I: IntoIterator<Item = &'a (StyleColor, [f32; 4])>,
{
let _token = self.push_style_colors(style_colors);
f()
}
#[deprecated(since = "0.1.0", note = "use Ui::push_style_var instead")]
pub fn with_style_var<T, F>(&self, style_var: StyleVar, f: F) -> T
where
F: FnOnce() -> T,
{
let _token = self.push_style_var(style_var);
f()
}
#[deprecated(since = "0.1.0", note = "use Ui::push_style_vars instead")]
pub fn with_style_vars<'a, T, F, I>(&self, style_vars: I, f: F) -> T
where
F: FnOnce() -> T,
I: IntoIterator<Item = &'a StyleVar>,
{
let _token = self.push_style_vars(style_vars);
f()
}
#[deprecated(since = "0.1.0", note = "use Ui::push_item_width instead")]
pub fn with_item_width<T, F>(&self, item_width: f32, f: F) -> T
where
F: FnOnce() -> T,
{
let _token = self.push_item_width(item_width);
f()
}
#[deprecated(since = "0.1.0", note = "use Ui::push_text_wrap_pos instead")]
pub fn with_text_wrap_pos<T, F>(&self, wrap_pos_x: f32, f: F) -> T
where
F: FnOnce() -> T,
{
let _token = self.push_text_wrap_pos(wrap_pos_x);
f()
}
}