pub use super::types::PixelRect;
use crate::Color;
#[derive(Clone, Debug)]
pub(crate) enum UiCmd {
Clear { color: Color },
Rect {
rect: PixelRect,
color: Color,
clip: PixelRect,
corner_radius: f32,
},
RectOutline {
rect: PixelRect,
color: Color,
thickness: u32,
clip: PixelRect,
corner_radius: f32,
},
Line {
x0: f32,
y0: f32,
x1: f32,
y1: f32,
color: Color,
thickness: f32,
bounds: PixelRect,
},
RoundedMask {
rect: PixelRect,
radius: f32,
outside: Color,
clip: PixelRect,
},
Triangle {
points: [[f32; 2]; 3],
color: Color,
bounds: PixelRect,
},
CanvasGrid { rect: PixelRect, push: [u32; 30] },
BlitRgba {
src_idx: u32,
src_w: u32,
src_h: u32,
dst_x: i32,
dst_y: i32,
dst_w: u32,
dst_h: u32,
clip: PixelRect,
channel: u32,
},
Heatmap {
values_idx: u32,
rect: PixelRect,
push: [u32; 18],
},
Waveform {
values_idx: u32,
rect: PixelRect,
push: [u32; 14],
},
PlotLine {
values_idx: u32,
count: u32,
rect: PixelRect,
clip: PixelRect,
x_min: f32,
x_max: f32,
y_min: f32,
y_max: f32,
color: Color,
fill: bool,
explicit_xy: bool,
antialias_samples: u32,
line_width: f32,
},
Glyphs {
glyph_idx: u32,
atlas_idx: u32,
count: u32,
dst: Option<PixelRect>,
clip: PixelRect,
atlas_w: u32,
atlas_h: u32,
},
BlitPlanar {
r_idx: u32,
g_idx: u32,
b_idx: u32,
a_idx: u32,
src_w: u32,
src_h: u32,
dst_x: i32,
dst_y: i32,
dtypes: u32,
channels: u32,
dst_w: u32,
dst_h: u32,
clip: PixelRect,
},
RectOutlines {
rect_idx: u32,
count: u32,
dst: PixelRect,
clip: PixelRect,
thickness: u32,
rgba: u32,
},
}
#[derive(Default)]
pub(crate) struct UiCmdList {
pub(crate) cmds: Vec<UiCmd>,
}
impl UiCmdList {
pub(crate) fn clear_all(&mut self) {
self.cmds.clear();
}
pub(crate) fn push(&mut self, cmd: UiCmd) {
self.cmds.push(cmd);
}
}
#[inline]
pub(super) const fn div_ceil(n: u32, d: u32) -> u32 {
n.div_ceil(d)
}
#[inline]
pub(super) fn clip_words(clip: PixelRect) -> [i32; 4] {
[clip.x, clip.y, clip.w as i32, clip.h as i32]
}
pub(super) fn visible_blit_region(
dst_x: i32,
dst_y: i32,
dst_w: u32,
dst_h: u32,
clip: PixelRect,
) -> (u32, u32, u32, u32) {
let clip_x1 = i64::from(clip.x) + i64::from(clip.w);
let clip_y1 = i64::from(clip.y) + i64::from(clip.h);
let vis_x0 = i64::from(dst_x).max(i64::from(clip.x));
let vis_y0 = i64::from(dst_y).max(i64::from(clip.y));
let vis_x1 = (i64::from(dst_x) + i64::from(dst_w)).min(clip_x1);
let vis_y1 = (i64::from(dst_y) + i64::from(dst_h)).min(clip_y1);
if vis_x1 <= vis_x0 || vis_y1 <= vis_y0 {
return (0, 0, 0, 0);
}
(
(vis_x1 - vis_x0) as u32,
(vis_y1 - vis_y0) as u32,
(vis_x0 - i64::from(dst_x)) as u32,
(vis_y0 - i64::from(dst_y)) as u32,
)
}