diff --git a/imgui-gfx-renderer/src/lib.rs b/imgui-gfx-renderer/src/lib.rs index 2cd5b33..55bdf26 100644 --- a/imgui-gfx-renderer/src/lib.rs +++ b/imgui-gfx-renderer/src/lib.rs @@ -304,21 +304,21 @@ impl Renderer { self.bundle.slice.start = 0; for cmd in draw_list.cmd_buffer { - let texture_id = cmd.texture_id.into(); + let texture_id = cmd.TextureId.into(); let tex = self .textures .get(texture_id) .ok_or_else(|| RendererError::BadTexture(texture_id))?; - self.bundle.slice.end = self.bundle.slice.start + cmd.elem_count; + self.bundle.slice.end = self.bundle.slice.start + cmd.ElemCount; let scissor = Rect { - x: cmd.clip_rect.x.max(0.0).min(fb_width).round() as u16, - y: cmd.clip_rect.y.max(0.0).min(fb_height).round() as u16, - w: (cmd.clip_rect.z - cmd.clip_rect.x) + x: cmd.ClipRect.x.max(0.0).min(fb_width).round() as u16, + y: cmd.ClipRect.y.max(0.0).min(fb_height).round() as u16, + w: (cmd.ClipRect.z - cmd.ClipRect.x) .abs() .min(fb_width) .round() as u16, - h: (cmd.clip_rect.w - cmd.clip_rect.y) + h: (cmd.ClipRect.w - cmd.ClipRect.y) .abs() .min(fb_height) .round() as u16, diff --git a/imgui-glium-renderer/src/lib.rs b/imgui-glium-renderer/src/lib.rs index e3f3cdd..b3f8579 100644 --- a/imgui-glium-renderer/src/lib.rs +++ b/imgui-glium-renderer/src/lib.rs @@ -134,14 +134,14 @@ impl Renderer { let mut idx_start = 0; for cmd in draw_list.cmd_buffer { - let texture_id = cmd.texture_id.into(); + let texture_id = cmd.TextureId.into(); let texture = self .device_objects .textures .get(texture_id) .ok_or_else(|| RendererError::BadTexture(texture_id))?; - let idx_end = idx_start + cmd.elem_count as usize; + let idx_end = idx_start + cmd.ElemCount as usize; surface.draw( &vtx_buffer, @@ -156,13 +156,13 @@ impl Renderer { &DrawParameters { blend: Blend::alpha_blending(), scissor: Some(Rect { - left: cmd.clip_rect.x.max(0.0).min(fb_width).round() as u32, - bottom: (fb_height - cmd.clip_rect.w).max(0.0).min(fb_width).round() as u32, - width: (cmd.clip_rect.z - cmd.clip_rect.x) + left: cmd.ClipRect.x.max(0.0).min(fb_width).round() as u32, + bottom: (fb_height - cmd.ClipRect.w).max(0.0).min(fb_width).round() as u32, + width: (cmd.ClipRect.z - cmd.ClipRect.x) .abs() .min(fb_width) .round() as u32, - height: (cmd.clip_rect.w - cmd.clip_rect.y) + height: (cmd.ClipRect.w - cmd.ClipRect.y) .abs() .min(fb_height) .round() as u32, diff --git a/imgui-sys/src/lib.rs b/imgui-sys/src/lib.rs index a8d2e16..a45d137 100644 --- a/imgui-sys/src/lib.rs +++ b/imgui-sys/src/lib.rs @@ -13,9 +13,26 @@ mod legacy; mod structs; pub use bindings::{ - igGetIO, CustomRect, ImDrawCallback, ImDrawIdx, ImDrawListSharedData, ImDrawListSplitter, - ImDrawVert, ImFont, ImFontAtlas, ImFontAtlas_AddFont, ImFontAtlas_AddFontDefault, - ImFontAtlas_Clear, ImFontAtlas_GetGlyphRangesChineseFull, + igGetIO, CustomRect, ImDrawCallback, ImDrawChannel, ImDrawCmd, ImDrawData, ImDrawData_Clear, + ImDrawData_DeIndexAllBuffers, ImDrawData_ScaleClipRects, ImDrawIdx, ImDrawList, + ImDrawListSharedData, ImDrawListSplitter, ImDrawList_AddBezierCurve, ImDrawList_AddCallback, + ImDrawList_AddCircle, ImDrawList_AddCircleFilled, ImDrawList_AddConvexPolyFilled, + ImDrawList_AddDrawCmd, ImDrawList_AddImage, ImDrawList_AddImageQuad, + ImDrawList_AddImageRounded, ImDrawList_AddLine, ImDrawList_AddPolyline, ImDrawList_AddQuad, + ImDrawList_AddQuadFilled, ImDrawList_AddRect, ImDrawList_AddRectFilled, + ImDrawList_AddRectFilledMultiColor, ImDrawList_AddText, ImDrawList_AddTextFontPtr, + ImDrawList_AddTriangle, ImDrawList_AddTriangleFilled, ImDrawList_ChannelsMerge, + ImDrawList_ChannelsSetCurrent, ImDrawList_ChannelsSplit, ImDrawList_Clear, + ImDrawList_ClearFreeMemory, ImDrawList_CloneOutput, ImDrawList_ImDrawList, + ImDrawList_PathArcTo, ImDrawList_PathArcToFast, ImDrawList_PathBezierCurveTo, + ImDrawList_PathClear, ImDrawList_PathFillConvex, ImDrawList_PathLineTo, + ImDrawList_PathLineToMergeDuplicate, ImDrawList_PathRect, ImDrawList_PathStroke, + ImDrawList_PopClipRect, ImDrawList_PopTextureID, ImDrawList_PrimQuadUV, ImDrawList_PrimRect, + ImDrawList_PrimRectUV, ImDrawList_PrimReserve, ImDrawList_PrimVtx, ImDrawList_PrimWriteIdx, + ImDrawList_PrimWriteVtx, ImDrawList_PushClipRect, ImDrawList_PushClipRectFullScreen, + ImDrawList_PushTextureID, ImDrawList_UpdateClipRect, ImDrawList_UpdateTextureID, + ImDrawList_destroy, ImDrawVert, ImFont, ImFontAtlas, ImFontAtlas_AddFont, + ImFontAtlas_AddFontDefault, ImFontAtlas_Clear, ImFontAtlas_GetGlyphRangesChineseFull, ImFontAtlas_GetGlyphRangesChineseSimplifiedCommon, ImFontAtlas_GetGlyphRangesCyrillic, ImFontAtlas_GetGlyphRangesDefault, ImFontAtlas_GetGlyphRangesJapanese, ImFontAtlas_GetGlyphRangesKorean, ImFontAtlas_GetGlyphRangesThai, diff --git a/imgui-sys/src/structs.rs b/imgui-sys/src/structs.rs index 03a44d6..04ddc3b 100644 --- a/imgui-sys/src/structs.rs +++ b/imgui-sys/src/structs.rs @@ -1,71 +1,8 @@ -use std::os::raw::{c_char, c_float, c_int, c_uint, c_void}; +use std::os::raw::{c_char, c_float, c_int, c_void}; use std::slice; -use crate::enums::{ImGuiCol, ImGuiDir, ImGuiKey, ImGuiMouseCursor, ImGuiNavInput}; -use crate::flags::{ImDrawCornerFlags, ImDrawListFlags}; -use crate::{ - ImDrawCallback, ImDrawIdx, ImDrawListSharedData, ImDrawListSplitter, ImDrawVert, ImFont, - ImGuiID, ImGuiStorage, ImTextureID, ImU32, ImVec2, ImVec4, -}; - -/// Temporary storage for outputting drawing commands out of order -#[repr(C)] -pub struct ImDrawChannel { - pub cmd_buffer: ImVector, - pub idx_buffer: ImVector, -} - -/// A single draw command within a parent ImDrawList (generally maps to 1 GPU draw call) -#[repr(C)] -pub struct ImDrawCmd { - pub elem_count: c_uint, - pub clip_rect: ImVec4, - pub texture_id: ImTextureID, - pub vtx_offset: c_uint, - pub idx_offset: c_uint, - pub user_callback: ImDrawCallback, - pub user_callback_data: *mut c_void, -} - -/// All draw command lists required to render the frame -#[repr(C)] -pub struct ImDrawData { - pub valid: bool, - pub cmd_lists: *mut *mut ImDrawList, - pub cmd_lists_count: c_int, - pub total_idx_count: c_int, - pub total_vtx_count: c_int, - pub display_pos: ImVec2, - pub display_size: ImVec2, - pub framebuffer_scale: ImVec2, -} - -impl ImDrawData { - pub unsafe fn cmd_lists(&self) -> &[*const ImDrawList] { - let cmd_lists = self.cmd_lists as *const *const ImDrawList; - slice::from_raw_parts(cmd_lists, self.cmd_lists_count as usize) - } -} - -/// A single draw command list (generally one per window) -#[repr(C)] -pub struct ImDrawList { - pub cmd_buffer: ImVector, - pub idx_buffer: ImVector, - pub vtx_buffer: ImVector, - pub flags: ImDrawListFlags, - - data: *const ImDrawListSharedData, - owner_name: *const c_char, - vtx_current_offset: c_uint, - vtx_current_idx: c_uint, - vtx_write_ptr: *mut ImDrawVert, - idx_write_ptr: *mut ImDrawIdx, - clip_rect_stack: ImVector, - texture_id_stack: ImVector, - path: ImVector, - splitter: ImDrawListSplitter, -} +use crate::enums::{ImGuiCol, ImGuiDir}; +use crate::{ImGuiID, ImGuiStorage, ImVec2, ImVec4}; /// Data payload for Drag and Drop operations #[repr(C)] @@ -323,265 +260,3 @@ extern "C" { pub fn ImGuiPayload_IsPreview(this: *mut ImGuiPayload) -> bool; pub fn ImGuiPayload_IsDelivery(this: *mut ImGuiPayload) -> bool; } - -// ImDrawList -extern "C" { - pub fn ImDrawList_PushClipRect( - this: *mut ImDrawList, - clip_rect_min: ImVec2, - clip_rect_max: ImVec2, - intersect_with_current_clip_rect: bool, - ); - pub fn ImDrawList_PushClipRectFullScreen(this: *mut ImDrawList); - pub fn ImDrawList_PopClipRect(this: *mut ImDrawList); - pub fn ImDrawList_PushTextureID(this: *mut ImDrawList, texture_id: ImTextureID); - pub fn ImDrawList_PopTextureID(this: *mut ImDrawList); - pub fn ImDrawList_GetClipRectMin_nonUDT2(this: *mut ImDrawList) -> ImVec2; - pub fn ImDrawList_GetClipRectMax_nonUDT2(this: *mut ImDrawList) -> ImVec2; - - pub fn ImDrawList_AddLine( - this: *mut ImDrawList, - a: ImVec2, - b: ImVec2, - col: ImU32, - thickness: c_float, - ); - pub fn ImDrawList_AddRect( - this: *mut ImDrawList, - a: ImVec2, - b: ImVec2, - col: ImU32, - rounding: c_float, - rounding_corners_flags: ImDrawCornerFlags, - thickness: c_float, - ); - pub fn ImDrawList_AddRectFilled( - this: *mut ImDrawList, - a: ImVec2, - b: ImVec2, - col: ImU32, - rounding: c_float, - rounding_corners_flags: ImDrawCornerFlags, - ); - pub fn ImDrawList_AddRectFilledMultiColor( - this: *mut ImDrawList, - a: ImVec2, - b: ImVec2, - col_upr_left: ImU32, - col_upr_right: ImU32, - col_bot_right: ImU32, - col_bot_left: ImU32, - ); - pub fn ImDrawList_AddQuad( - this: *mut ImDrawList, - a: ImVec2, - b: ImVec2, - c: ImVec2, - d: ImVec2, - col: ImU32, - thickness: c_float, - ); - pub fn ImDrawList_AddQuadFilled( - this: *mut ImDrawList, - a: ImVec2, - b: ImVec2, - c: ImVec2, - d: ImVec2, - col: ImU32, - ); - pub fn ImDrawList_AddTriangle( - this: *mut ImDrawList, - a: ImVec2, - b: ImVec2, - c: ImVec2, - col: ImU32, - thickness: c_float, - ); - pub fn ImDrawList_AddTriangleFilled( - this: *mut ImDrawList, - a: ImVec2, - b: ImVec2, - c: ImVec2, - col: ImU32, - ); - pub fn ImDrawList_AddCircle( - this: *mut ImDrawList, - centre: ImVec2, - radius: c_float, - col: ImU32, - num_segments: c_int, - thickness: c_float, - ); - pub fn ImDrawList_AddCircleFilled( - this: *mut ImDrawList, - centre: ImVec2, - radius: c_float, - col: ImU32, - num_segments: c_int, - ); - pub fn ImDrawList_AddText( - this: *mut ImDrawList, - pos: ImVec2, - col: ImU32, - text_begin: *const c_char, - text_end: *const c_char, - ); - pub fn ImDrawList_AddTextFontPtr( - this: *mut ImDrawList, - font: *const ImFont, - font_size: c_float, - pos: ImVec2, - col: ImU32, - text_begin: *const c_char, - text_end: *const c_char, - wrap_width: c_float, - cpu_fine_clip_rect: *const ImVec4, - ); - pub fn ImDrawList_AddImage( - this: *mut ImDrawList, - user_texture_id: ImTextureID, - a: ImVec2, - b: ImVec2, - uv_a: ImVec2, - uv_b: ImVec2, - col: ImU32, - ); - pub fn ImDrawList_AddImageQuad( - this: *mut ImDrawList, - user_texture_id: ImTextureID, - a: ImVec2, - b: ImVec2, - c: ImVec2, - d: ImVec2, - uv_a: ImVec2, - uv_b: ImVec2, - uv_c: ImVec2, - uv_d: ImVec2, - col: ImU32, - ); - pub fn ImDrawList_AddImageRounded( - this: *mut ImDrawList, - user_texture_id: ImTextureID, - a: ImVec2, - b: ImVec2, - uv_a: ImVec2, - uv_b: ImVec2, - col: ImU32, - rounding: c_float, - rounding_corners: ImDrawCornerFlags, - ); - pub fn ImDrawList_AddPolyLine( - this: *mut ImDrawList, - points: *const ImVec2, - num_points: c_int, - col: ImU32, - closed: bool, - thickness: c_float, - ); - pub fn ImDrawList_AddConvexPolyFilled( - this: *mut ImDrawList, - points: *const ImVec2, - num_points: c_int, - col: ImU32, - ); - pub fn ImDrawList_AddBezierCurve( - this: *mut ImDrawList, - pos0: ImVec2, - cp0: ImVec2, - cp1: ImVec2, - pos1: ImVec2, - col: ImU32, - thickness: c_float, - num_segments: c_int, - ); - - pub fn ImDrawList_PathClear(this: *mut ImDrawList); - pub fn ImDrawList_PathLineTo(this: *mut ImDrawList, pos: ImVec2); - pub fn ImDrawList_PathLineToMergeDuplicate(this: *mut ImDrawList, pos: ImVec2); - pub fn ImDrawList_PathFillConvex(this: *mut ImDrawList, col: ImU32); - pub fn ImDrawList_PathStroke( - this: *mut ImDrawList, - col: ImU32, - closed: bool, - thickness: c_float, - ); - pub fn ImDrawList_PathArcTo( - this: *mut ImDrawList, - centre: ImVec2, - radius: c_float, - a_min: c_float, - a_max: c_float, - num_segments: c_int, - ); - pub fn ImDrawList_PathArcToFast( - this: *mut ImDrawList, - centre: ImVec2, - radius: c_float, - a_min_of_12: c_int, - a_max_of_12: c_int, - ); - pub fn ImDrawList_PathBezierCurveTo( - this: *mut ImDrawList, - p1: ImVec2, - p2: ImVec2, - p3: ImVec2, - num_segments: c_int, - ); - pub fn ImDrawList_PathRect( - this: *mut ImDrawList, - rect_min: ImVec2, - rect_max: ImVec2, - rounding: c_float, - rounding_corners_flags: c_int, - ); - - pub fn ImDrawList_ChannelsSplit(this: *mut ImDrawList, channels_count: c_int); - pub fn ImDrawList_ChannelsMerge(this: *mut ImDrawList); - pub fn ImDrawList_ChannelsSetCurrent(this: *mut ImDrawList, channel_index: c_int); - - pub fn ImDrawList_AddCallback( - this: *mut ImDrawList, - callback: ImDrawCallback, - callback_data: *mut c_void, - ); - pub fn ImDrawList_AddDrawCmd(this: *mut ImDrawList); - - pub fn ImDrawList_CloneOutput(this: *mut ImDrawList) -> *mut ImDrawList; - pub fn ImDrawList_Clear(this: *mut ImDrawList); - pub fn ImDrawList_ClearFreeMemory(this: *mut ImDrawList); - - pub fn ImDrawList_PrimReserve(this: *mut ImDrawList, idx_count: c_int, vtx_count: c_int); - pub fn ImDrawList_PrimRect(this: *mut ImDrawList, a: ImVec2, b: ImVec2, col: ImU32); - pub fn ImDrawList_PrimRectUV( - this: *mut ImDrawList, - a: ImVec2, - b: ImVec2, - uv_a: ImVec2, - uv_b: ImVec2, - col: ImU32, - ); - pub fn ImDrawList_PrimQuadUV( - this: *mut ImDrawList, - a: ImVec2, - b: ImVec2, - c: ImVec2, - d: ImVec2, - uv_a: ImVec2, - uv_b: ImVec2, - uv_c: ImVec2, - uv_d: ImVec2, - col: ImU32, - ); - pub fn ImDrawList_PrimWriteVtx(this: *mut ImDrawList, pos: ImVec2, uv: ImVec2, col: ImU32); - pub fn ImDrawList_PrimWriteIdx(this: *mut ImDrawList, idx: ImDrawIdx); - pub fn ImDrawList_PrimVtx(this: *mut ImDrawList, pos: ImVec2, uv: ImVec2, col: ImU32); - pub fn ImDrawList_UpdateClipRect(this: *mut ImDrawList); - pub fn ImDrawList_UpdateTextureID(this: *mut ImDrawList); -} - -// ImDrawData -extern "C" { - pub fn ImDrawData_Clear(this: *mut ImDrawData); - pub fn ImDrawData_DeIndexAllBuffers(this: *mut ImDrawData); - pub fn ImDrawData_ScaleClipRects(this: *mut ImDrawData, sc: ImVec2); -} diff --git a/src/lib.rs b/src/lib.rs index baf69b2..d0951ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -444,16 +444,16 @@ pub struct DrawData<'a> { impl<'a> DrawData<'a> { pub fn is_valid(&self) -> bool { - self.raw.valid + self.raw.Valid } pub fn draw_list_count(&self) -> usize { - self.raw.cmd_lists_count as usize + self.raw.CmdListsCount as usize } pub fn total_vtx_count(&self) -> usize { - self.raw.total_vtx_count as usize + self.raw.TotalVtxCount as usize } pub fn total_idx_count(&self) -> usize { - self.raw.total_idx_count as usize + self.raw.TotalIdxCount as usize } pub fn deindex_all_buffers(&mut self) { unsafe { @@ -473,8 +473,12 @@ impl<'a> IntoIterator for &'a DrawData<'a> { fn into_iter(self) -> Self::IntoIter { unsafe { + let cmd_lists = slice::from_raw_parts( + self.raw.CmdLists as *const *const sys::ImDrawList, + self.raw.CmdListsCount as usize, + ); DrawListIterator { - iter: self.raw.cmd_lists().iter(), + iter: cmd_lists.iter(), } } } @@ -489,10 +493,16 @@ impl<'a> Iterator for DrawListIterator<'a> { fn next(&mut self) -> Option { self.iter.next().map(|&ptr| unsafe { + let cmd_buffer = + slice::from_raw_parts((*ptr).CmdBuffer.Data, (*ptr).CmdBuffer.Size as usize); + let idx_buffer = + slice::from_raw_parts((*ptr).IdxBuffer.Data, (*ptr).IdxBuffer.Size as usize); + let vtx_buffer = + slice::from_raw_parts((*ptr).VtxBuffer.Data, (*ptr).VtxBuffer.Size as usize); DrawList { - cmd_buffer: (*ptr).cmd_buffer.as_slice(), - idx_buffer: (*ptr).idx_buffer.as_slice(), - vtx_buffer: (*ptr).vtx_buffer.as_slice(), + cmd_buffer, + idx_buffer, + vtx_buffer, } }) } diff --git a/src/window_draw_list.rs b/src/window_draw_list.rs index e181d97..09a4d74 100644 --- a/src/window_draw_list.rs +++ b/src/window_draw_list.rs @@ -423,7 +423,7 @@ impl<'ui> Rect<'ui> { self.p2, self.color.into(), self.rounding, - self.flags, + self.flags.bits(), ); } } else { @@ -434,7 +434,7 @@ impl<'ui> Rect<'ui> { self.p2, self.color.into(), self.rounding, - self.flags, + self.flags.bits(), self.thickness, ); }