Bulk of changes required to support main + docking

This commit is contained in:
dbr 2021-10-27 19:24:12 +11:00
parent 08b778524d
commit 929dd2fcfe
7 changed files with 126 additions and 13 deletions

View File

@ -138,7 +138,16 @@ impl<'ui> DrawListMut<'ui> {
pub(crate) fn background(_: &Ui) -> Self {
Self::lock_draw_list(DrawListType::Background);
Self {
draw_list: unsafe { sys::igGetBackgroundDrawList() },
draw_list: unsafe {
cfg_if::cfg_if! {
if #[cfg(feature = "docking")] {
// Has extra overload in docking branch
sys::igGetBackgroundDrawListNil()
} else {
sys::igGetBackgroundDrawList()
}
}
},
draw_list_type: DrawListType::Background,
_phantom: PhantomData,
}
@ -148,7 +157,16 @@ impl<'ui> DrawListMut<'ui> {
pub(crate) fn foreground(_: &Ui) -> Self {
Self::lock_draw_list(DrawListType::Foreground);
Self {
draw_list: unsafe { sys::igGetForegroundDrawList() },
draw_list: unsafe {
cfg_if::cfg_if! {
if #[cfg(feature = "docking")] {
// Has extra overload in docking branch
sys::igGetForegroundDrawListNil()
} else {
sys::igGetForegroundDrawList()
}
}
},
draw_list_type: DrawListType::Foreground,
_phantom: PhantomData,
}

View File

@ -52,6 +52,9 @@ bitflags! {
///
/// Not used by core imgui-rs.
const IS_TOUCH_SCREEN = sys::ImGuiConfigFlags_IsTouchScreen;
#[cfg(feature = "docking")]
const DOCKING_ENABLE = sys::ImGuiConfigFlags_DockingEnable;
}
}
@ -174,6 +177,21 @@ pub struct Io {
/// framebuffer coordinates
pub display_framebuffer_scale: [f32; 2],
#[cfg(feature = "docking")]
pub config_docking_no_split: bool,
#[cfg(feature = "docking")]
pub config_docking_always_tab_bar: bool,
#[cfg(feature = "docking")]
pub config_docking_transparent_payload: bool,
#[cfg(feature = "docking")]
pub config_viewports_no_auto_merge: bool,
#[cfg(feature = "docking")]
pub config_viewports_notask_bar_icon: bool,
#[cfg(feature = "docking")]
pub config_viewports_no_decoration: bool,
#[cfg(feature = "docking")]
pub config_viewports_no_default_parent: bool,
/// Request imgui-rs to draw a mouse cursor for you
pub mouse_draw_cursor: bool,
/// macOS-style input behavior.
@ -215,7 +233,9 @@ pub struct Io {
pub(crate) set_clipboard_text_fn:
Option<unsafe extern "C" fn(user_data: *mut c_void, text: *const c_char)>,
pub(crate) clipboard_user_data: *mut c_void,
#[cfg(not(feature="docking"))]
ime_set_input_screen_pos_fn: Option<unsafe extern "C" fn(x: c_int, y: c_int)>,
#[cfg(not(feature="docking"))]
ime_window_handle: *mut c_void,
/// Mouse position, in pixels.
///
@ -232,6 +252,8 @@ pub struct Io {
/// Most users don't have a mouse with a horizontal wheel, and may not be filled by all
/// backends.
pub mouse_wheel_h: f32,
#[cfg(feature = "docking")]
pub mouse_hovered_viewport: sys::ImGuiID,
/// Keyboard modifier pressed: Control
pub key_ctrl: bool,
/// Keyboard modifier pressed: Shift
@ -291,6 +313,9 @@ pub struct Io {
/// f32::MAX]), so a disappearing/reappearing mouse won't have a huge delta.
pub mouse_delta: [f32; 2],
#[cfg(feature = "docking")]
pub want_capture_mouse_unless_popup_close: bool,
key_mods: sys::ImGuiKeyModFlags,
key_mods_prev: sys::ImGuiKeyModFlags,
mouse_pos_prev: [f32; 2],
@ -300,6 +325,8 @@ pub struct Io {
mouse_double_clicked: [bool; 5],
mouse_released: [bool; 5],
mouse_down_owned: [bool; 5],
#[cfg(feature = "docking")]
mouse_down_owned_unless_popup_close: [bool; 5],
mouse_down_was_double_click: [bool; 5],
mouse_down_duration: [f32; 5],
mouse_down_duration_prev: [f32; 5],
@ -310,6 +337,8 @@ pub struct Io {
nav_inputs_down_duration: [f32; NavInput::COUNT + NavInput::INTERNAL_COUNT],
nav_inputs_down_duration_prev: [f32; NavInput::COUNT + NavInput::INTERNAL_COUNT],
pen_pressure: f32,
#[cfg(feature = "docking")]
app_focus_lost: bool,
input_queue_surrogate: sys::ImWchar16,
input_queue_characters: ImVector<sys::ImWchar>,
}
@ -451,7 +480,9 @@ fn test_io_memory_layout() {
assert_field_offset!(get_clipboard_text_fn, GetClipboardTextFn);
assert_field_offset!(set_clipboard_text_fn, SetClipboardTextFn);
assert_field_offset!(clipboard_user_data, ClipboardUserData);
#[cfg(not(feature="docking"))]
assert_field_offset!(ime_set_input_screen_pos_fn, ImeSetInputScreenPosFn);
#[cfg(not(feature="docking"))]
assert_field_offset!(ime_window_handle, ImeWindowHandle);
assert_field_offset!(mouse_pos, MousePos);
assert_field_offset!(mouse_down, MouseDown);

View File

@ -31,6 +31,9 @@ pub struct DrawData {
/// Based on io.display_frame_buffer_scale. Typically [1.0, 1.0] on normal displays, and
/// [2.0, 2.0] on Retina displays, but fractional values are also possible.
pub framebuffer_scale: [f32; 2],
#[cfg(feature = "docking")]
OwnerViewport: *mut sys::ImGuiViewport,
}
unsafe impl RawCast<sys::ImDrawData> for DrawData {}

View File

@ -251,6 +251,12 @@ pub enum StyleColor {
TabActive = sys::ImGuiCol_TabActive,
TabUnfocused = sys::ImGuiCol_TabUnfocused,
TabUnfocusedActive = sys::ImGuiCol_TabUnfocusedActive,
#[cfg(feature = "docking")]
DockingPreview = sys::ImGuiCol_DockingPreview,
#[cfg(feature = "docking")]
DockingEmptyBg = sys::ImGuiCol_DockingEmptyBg,
PlotLines = sys::ImGuiCol_PlotLines,
PlotLinesHovered = sys::ImGuiCol_PlotLinesHovered,
PlotHistogram = sys::ImGuiCol_PlotHistogram,
@ -313,6 +319,10 @@ impl StyleColor {
StyleColor::TabActive,
StyleColor::TabUnfocused,
StyleColor::TabUnfocusedActive,
#[cfg(feature = "docking")]
StyleColor::DockingPreview,
#[cfg(feature = "docking")]
StyleColor::DockingEmptyBg,
StyleColor::PlotLines,
StyleColor::PlotLinesHovered,
StyleColor::PlotHistogram,

View File

@ -627,9 +627,17 @@ impl Ui {
pub fn table_column_name(&mut self) -> &str {
unsafe {
// imgui uses utf8...though that is a continuous process there.
CStr::from_ptr(sys::igTableGetColumnName(-1))
.to_str()
.unwrap()
cfg_if::cfg_if! {
if #[cfg(feature = "docking")] {
CStr::from_ptr(sys::igTableGetColumnNameInt(-1))
.to_str()
.unwrap()
} else {
CStr::from_ptr(sys::igTableGetColumnName(-1))
.to_str()
.unwrap()
}
}
}
}
@ -640,9 +648,17 @@ impl Ui {
pub fn table_column_name_with_column(&mut self, column: usize) -> &str {
unsafe {
// imgui uses utf8...though that is a continuous process there.
CStr::from_ptr(sys::igTableGetColumnName(column as i32))
.to_str()
.unwrap()
cfg_if::cfg_if! {
if #[cfg(feature="docking")] {
CStr::from_ptr(sys::igTableGetColumnNameInt(column as i32))
.to_str()
.unwrap()
} else {
CStr::from_ptr(sys::igTableGetColumnName(column as i32))
.to_str()
.unwrap()
}
}
}
}

View File

@ -107,6 +107,9 @@ bitflags! {
/// Shorthand for `WindowFlags::NO_MOUSE_INPUTS | WindowFlags::NO_NAV_INPUTS |
/// WindowFlags::NO_NAV_FOCUS`.
const NO_INPUTS = sys::ImGuiWindowFlags_NoInputs;
#[cfg(feature="docking")]
const NO_DOCKING = sys::ImGuiWindowFlags_NoDocking;
}
}

View File

@ -2,7 +2,7 @@ use crate::sys;
use crate::Ui;
/// # Window scrolling
impl Ui {
impl<'ui> Ui<'ui> {
/// Returns the horizontal scrolling position.
///
/// Value is between 0.0 and self.scroll_max_x().
@ -34,12 +34,28 @@ impl Ui {
/// Sets the horizontal scrolling position
#[doc(alias = "SetScrollX")]
pub fn set_scroll_x(&self, scroll_x: f32) {
unsafe { sys::igSetScrollX(scroll_x) };
unsafe {
cfg_if::cfg_if! {
if #[cfg(feature = "docking")] {
sys::igSetScrollXFloat(scroll_x);
} else {
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) };
unsafe {
cfg_if::cfg_if! {
if #[cfg(feature = "docking")] {
sys::igSetScrollYFloat(scroll_y);
} else {
sys::igSetScrollY(scroll_y);
}
}
}
}
/// Adjusts the horizontal scroll position to make the current cursor position visible.
///
@ -94,7 +110,15 @@ impl Ui {
/// - `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) };
unsafe {
cfg_if::cfg_if! {
if #[cfg(feature = "docking")] {
sys::igSetScrollFromPosXFloat(local_x, center_x_ratio)
} else {
sys::igSetScrollFromPosX(local_x, center_x_ratio)
}
}
};
}
/// Adjusts the vertical scroll position to make the given position visible
///
@ -113,6 +137,14 @@ impl Ui {
/// - `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) };
unsafe {
cfg_if::cfg_if! {
if #[cfg(feature = "docking")] {
sys::igSetScrollFromPosYFloat(local_y, center_y_ratio);
} else {
sys::igSetScrollFromPosY(local_y, center_y_ratio);
}
}
}
}
}