dear_imgui_rs/render/draw_data/
cmd.rs1use super::callbacks::{StandardDrawCallback, classify_standard_draw_callback};
2use crate::sys;
3use crate::texture::TextureId;
4use std::slice;
5
6pub struct DrawCmdIterator<'a> {
8 iter: slice::Iter<'a, sys::ImDrawCmd>,
9}
10
11impl<'a> DrawCmdIterator<'a> {
12 pub(super) fn new(iter: slice::Iter<'a, sys::ImDrawCmd>) -> Self {
13 Self { iter }
14 }
15}
16
17impl<'a> Iterator for DrawCmdIterator<'a> {
18 type Item = DrawCmd;
19
20 fn next(&mut self) -> Option<Self::Item> {
21 self.iter.next().map(|cmd| {
22 let cmd_params = DrawCmdParams {
23 clip_rect: [
24 cmd.ClipRect.x,
25 cmd.ClipRect.y,
26 cmd.ClipRect.z,
27 cmd.ClipRect.w,
28 ],
29 texture_id: TextureId::from(cmd.TexRef._TexID),
31 vtx_offset: cmd.VtxOffset as usize,
32 idx_offset: cmd.IdxOffset as usize,
33 };
34
35 match classify_standard_draw_callback(cmd.UserCallback) {
36 Some(StandardDrawCallback::ResetRenderState) => DrawCmd::ResetRenderState,
37 Some(StandardDrawCallback::SetSamplerLinear) => DrawCmd::SetSamplerLinear,
38 Some(StandardDrawCallback::SetSamplerNearest) => DrawCmd::SetSamplerNearest,
39 None => match cmd.UserCallback {
40 Some(raw_callback) => DrawCmd::RawCallback {
41 callback: raw_callback,
42 raw_cmd: cmd,
43 },
44 None => DrawCmd::Elements {
45 count: cmd.ElemCount as usize,
46 cmd_params,
47 raw_cmd: cmd as *const sys::ImDrawCmd,
48 },
49 },
50 }
51 })
52 }
53}
54
55#[derive(Copy, Clone, Debug, PartialEq)]
57pub struct DrawCmdParams {
58 pub clip_rect: [f32; 4],
60 pub texture_id: TextureId,
68 pub vtx_offset: usize,
70 pub idx_offset: usize,
72}
73
74#[derive(Clone, Debug)]
76pub enum DrawCmd {
77 Elements {
79 count: usize,
81 cmd_params: DrawCmdParams,
82 raw_cmd: *const sys::ImDrawCmd,
89 },
90 ResetRenderState,
92 SetSamplerLinear,
94 SetSamplerNearest,
96 RawCallback {
98 callback: unsafe extern "C" fn(*const sys::ImDrawList, cmd: *const sys::ImDrawCmd),
99 raw_cmd: *const sys::ImDrawCmd,
100 },
101}