use std::sync::Arc;
use super::types::LayoutRuntime;
use crate::error::PaneError;
use crate::overlay::{self, Overlay, OverlayDef, OverlayId};
use crate::validate::{check_f32_non_negative, float_invalid_to_constraint};
impl LayoutRuntime {
pub fn add_overlay(
&mut self,
kind: impl Into<Arc<str>>,
builder: Overlay,
) -> Result<OverlayId, PaneError> {
crate::runtime_overlay::add_overlay_impl(
&mut self.overlays,
&mut self.overlay_index,
&mut self.overlay_gen,
kind.into(),
builder,
)
}
pub fn remove_overlay(&mut self, kind: &str) {
crate::runtime_overlay::remove_overlay_impl(
&mut self.overlays,
&mut self.overlay_index,
kind,
);
}
pub fn set_overlay_visible(&mut self, kind: &str, visible: bool) {
if let Some(&idx) = self.overlay_index.get(kind) {
self.overlays[idx].visible = visible;
}
}
pub fn set_overlay_height(&mut self, kind: &str, h: f32) -> Result<(), PaneError> {
validate_overlay_dimension("overlay_height", h)?;
if let Some(&idx) = self.overlay_index.get(kind) {
self.overlays[idx].height.value = overlay::ExtentValue::Fixed(h);
}
Ok(())
}
pub fn set_overlay_width(&mut self, kind: &str, w: f32) -> Result<(), PaneError> {
validate_overlay_dimension("overlay_width", w)?;
if let Some(&idx) = self.overlay_index.get(kind) {
self.overlays[idx].width.value = overlay::ExtentValue::Fixed(w);
}
Ok(())
}
pub fn overlay(&self, kind: &str) -> Option<&OverlayDef> {
self.overlay_index.get(kind).map(|&idx| &self.overlays[idx])
}
pub fn overlays(&self) -> &[OverlayDef] {
&self.overlays
}
}
fn validate_overlay_dimension(name: &'static str, value: f32) -> Result<(), PaneError> {
check_f32_non_negative(value)
.map_err(|e| PaneError::InvalidConstraint(float_invalid_to_constraint(name, e)))
}