pub(crate) fn draw_line(
context: &mut crate::render::RenderContext,
rect: crate::core::Rect,
vertical: bool,
thickness: u32,
color: crate::core::Color,
) {
if rect.width == 0 || rect.height == 0 {
return;
}
let thickness = thickness.max(1);
let half = (thickness / 2) as i32;
if vertical {
let x =
rect.x + (rect.width as i32 / 2).clamp(half, (rect.width as i32 - 1 - half).max(half));
let top = rect.y + half;
let bottom = (rect.y + rect.height as i32 - 1 - half).max(top);
context.draw_line_stroke(
crate::core::Point::new(x, top),
crate::core::Point::new(x, bottom),
color,
thickness,
);
} else {
let y = rect.y
+ (rect.height as i32 / 2).clamp(half, (rect.height as i32 - 1 - half).max(half));
let left = rect.x + half;
let right = (rect.x + rect.width as i32 - 1 - half).max(left);
context.draw_line_stroke(
crate::core::Point::new(left, y),
crate::core::Point::new(right, y),
color,
thickness,
);
}
}
pub(crate) fn draw_shaded_line(
context: &mut crate::render::RenderContext,
rect: crate::core::Rect,
vertical: bool,
color: crate::core::Color,
sunken: bool,
) {
if rect.width == 0 || rect.height == 0 {
return;
}
let highlight = color.blend(&crate::core::Color::WHITE, 0.45);
let shadow = color.blend(&crate::core::Color::BLACK, 0.35);
let (first, second) = if sunken { (shadow, highlight) } else { (highlight, shadow) };
let extent = if vertical { rect.width } else { rect.height };
if extent < 2 {
draw_line(context, rect, vertical, 1, first);
return;
}
if vertical {
let middle = rect.x + rect.width as i32 / 2;
draw_line(
context,
crate::core::Rect::new(middle - 1, rect.y, 1, rect.height),
true,
1,
first,
);
draw_line(context, crate::core::Rect::new(middle, rect.y, 1, rect.height), true, 1, second);
} else {
let middle = rect.y + rect.height as i32 / 2;
draw_line(
context,
crate::core::Rect::new(rect.x, middle - 1, rect.width, 1),
false,
1,
first,
);
draw_line(context, crate::core::Rect::new(rect.x, middle, rect.width, 1), false, 1, second);
}
}