use rustc_hash::FxHashMap;
use crate::tree::{Axis, Rect};
use super::UiState;
pub const RESIZE_BAND_THICKNESS: f32 = 8.0;
#[derive(Clone, Debug, Default)]
pub(crate) struct ResizeState {
pub(crate) overrides: FxHashMap<String, f32>,
pub(crate) bands: Vec<ResizeBand>,
pub(crate) drag: Option<EdgeResizeDrag>,
pub(crate) hovered_band: Option<String>,
}
#[derive(Clone, Debug)]
pub(crate) struct ResizeBand {
pub(crate) id: String,
pub(crate) key: Option<String>,
pub(crate) container_id: String,
pub(crate) band: Rect,
pub(crate) axis: Axis,
pub(crate) sign: f32,
pub(crate) current: f32,
pub(crate) min: f32,
pub(crate) max: f32,
}
#[derive(Clone, Debug)]
pub(crate) struct EdgeResizeDrag {
pub(crate) id: String,
pub(crate) key: Option<String>,
pub(crate) axis: Axis,
pub(crate) sign: f32,
pub(crate) anchor: f32,
pub(crate) initial: f32,
pub(crate) min: f32,
pub(crate) max: f32,
}
impl UiState {
pub(crate) fn resize_band_at(&self, x: f32, y: f32) -> Option<&ResizeBand> {
self.resize.bands.iter().find(|b| b.band.contains(x, y))
}
pub fn user_size(&self, key: &str) -> Option<f32> {
self.resize.overrides.get(key).copied()
}
pub fn set_user_size(&mut self, key: impl Into<String>, px: f32) {
self.resize.overrides.insert(key.into(), px);
}
pub fn clear_user_size(&mut self, key: &str) {
self.resize.overrides.remove(key);
}
}