use ratatui::layout::Rect;
use super::layout_regions::{LayoutRegions, Region};
#[allow(dead_code)]
fn contains(rect: &Rect, x: u16, y: u16) -> bool {
x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height
}
#[allow(dead_code)]
pub fn region_at(regions: &LayoutRegions, x: u16, y: u16) -> Option<Region> {
if let Some(rect) = ®ions.help_popup
&& contains(rect, x, y)
{
return Some(Region::HelpPopup);
}
if let Some(rect) = ®ions.error_overlay
&& contains(rect, x, y)
{
return Some(Region::ErrorOverlay);
}
if let Some(rect) = ®ions.snippet_preview
&& contains(rect, x, y)
{
return Some(Region::SnippetPreview);
}
if let Some(rect) = ®ions.snippet_list
&& contains(rect, x, y)
{
return Some(Region::SnippetList);
}
if let Some(rect) = ®ions.history_popup
&& contains(rect, x, y)
{
return Some(Region::HistoryPopup);
}
if let Some(rect) = ®ions.ai_window
&& contains(rect, x, y)
{
return Some(Region::AiWindow);
}
if let Some(rect) = ®ions.tooltip
&& contains(rect, x, y)
{
return Some(Region::Tooltip);
}
if let Some(rect) = ®ions.autocomplete
&& contains(rect, x, y)
{
return Some(Region::Autocomplete);
}
if let Some(rect) = ®ions.search_bar
&& contains(rect, x, y)
{
return Some(Region::SearchBar);
}
if let Some(rect) = ®ions.input_field
&& contains(rect, x, y)
{
return Some(Region::InputField);
}
if let Some(rect) = ®ions.results_pane
&& contains(rect, x, y)
{
return Some(Region::ResultsPane);
}
None
}