use crate::render::RenderContext;
use crate::types::Rect;
use super::settings::SeparatorSettings;
use super::style::{SPLIT_PANEL_THICKNESS_HOVER_DRAG, SPLIT_PANEL_THICKNESS_IDLE};
use super::types::{SeparatorOrientation, SeparatorType};
pub struct SeparatorView {
pub kind: SeparatorType,
pub hovered: bool,
pub dragging: bool,
}
pub fn draw_separator(
ctx: &mut dyn RenderContext,
rect: Rect,
view: &SeparatorView,
settings: &SeparatorSettings,
) {
let style = settings.style.as_ref();
let theme = settings.theme.as_ref();
let color = match (&view.kind, view.dragging, view.hovered) {
(SeparatorType::ResizeHandle { .. }, true, _) => theme.handle_active(),
(SeparatorType::ResizeHandle { .. }, false, true) => theme.handle_hover(),
_ => theme.line(),
};
let t = style.thickness();
let m = style.margin();
let line_rect = match view.kind.orientation() {
SeparatorOrientation::Horizontal => Rect::new(
rect.x + m,
rect.y + (rect.height - t) / 2.0,
rect.width - m * 2.0,
t,
),
SeparatorOrientation::Vertical => Rect::new(
rect.x + (rect.width - t) / 2.0,
rect.y + m,
t,
rect.height - m * 2.0,
),
};
ctx.set_fill_color(color);
ctx.fill_rect(line_rect.x, line_rect.y, line_rect.width, line_rect.height);
}
pub fn draw_separator_line(
ctx: &mut dyn RenderContext,
x: f64,
y: f64,
width: f64,
height: f64,
color: &str,
) {
ctx.set_fill_color(color);
ctx.fill_rect(x, y, width, height);
}
pub fn draw_pane_resize_handle(
ctx: &mut dyn RenderContext,
rect: Rect,
settings: &SeparatorSettings,
) {
let theme = settings.theme.as_ref();
let style = settings.style.as_ref();
let t = style.thickness(); let line_y = rect.y + (rect.height - t) / 2.0;
ctx.set_fill_color(theme.pane_handle_idle());
ctx.fill_rect(rect.x, line_y, rect.width, t);
}
pub fn draw_split_panel_handle(
ctx: &mut dyn RenderContext,
position: f64,
start: f64,
length: f64,
orientation: SeparatorOrientation,
hovered: bool,
dragging: bool,
settings: &SeparatorSettings,
) {
let theme = settings.theme.as_ref();
let thickness = if hovered || dragging {
SPLIT_PANEL_THICKNESS_HOVER_DRAG
} else {
SPLIT_PANEL_THICKNESS_IDLE
};
let color = if hovered || dragging {
theme.pane_handle_hover()
} else {
theme.pane_handle_idle()
};
let (rx, ry, rw, rh) = match orientation {
SeparatorOrientation::Vertical => {
let x = position - thickness / 2.0;
(x, start, thickness, length)
}
SeparatorOrientation::Horizontal => {
let y = position - thickness / 2.0;
(start, y, length, thickness)
}
};
ctx.set_fill_color(color);
ctx.fill_rect(rx, ry, rw, rh);
}
pub fn draw_sidebar_handle(
ctx: &mut dyn RenderContext,
x: f64,
y: f64,
height: f64,
settings: &SeparatorSettings,
) {
let theme = settings.theme.as_ref();
ctx.set_stroke_color(theme.sidebar_separator());
ctx.set_stroke_width(1.0);
ctx.begin_path();
ctx.move_to(x, y);
ctx.line_to(x, y + height);
ctx.stroke();
}
pub fn draw_modal_section_divider(
ctx: &mut dyn RenderContext,
x: f64,
y: f64,
width: f64,
settings: &SeparatorSettings,
) {
let theme = settings.theme.as_ref();
ctx.set_stroke_color(theme.modal_divider());
ctx.set_stroke_width(1.0);
ctx.begin_path();
ctx.move_to(x, y);
ctx.line_to(x + width, y);
ctx.stroke();
}