use super::*;
impl SourceControlPanel {
pub fn click_more(&self, x: u16, y: u16) -> bool {
rect_hit(self.header_more_btn, x, y)
}
pub fn click_discard_action(&self, x: u16, y: u16) -> Option<usize> {
let a = self.last_row_actions?;
rect_hit(a.discard, x, y).then_some(a.entry_idx)
}
pub fn click_stage_action(&self, x: u16, y: u16) -> Option<usize> {
let a = self.last_row_actions?;
rect_hit(a.stage, x, y).then_some(a.entry_idx)
}
pub fn click_unstage_action(&self, x: u16, y: u16) -> Option<usize> {
let a = self.last_row_actions?;
rect_hit(a.unstage, x, y).then_some(a.entry_idx)
}
pub fn click_branch(&self, x: u16, y: u16) -> bool {
rect_hit(self.last_branch_area, x, y)
}
pub fn click_header_refresh(&self, x: u16, y: u16) -> bool {
rect_hit(self.header_refresh_btn, x, y)
}
pub fn click_button(&self, x: u16, y: u16) -> bool {
rect_hit(self.last_button_area, x, y)
}
pub fn click_init_repo_button(&self, x: u16, y: u16) -> bool {
rect_hit(self.last_init_repo_button_area, x, y)
}
pub fn click_nested_repo(&self, x: u16, y: u16) -> Option<std::path::PathBuf> {
self.nested_repo_button_areas
.iter()
.find(|(r, _)| rect_hit(*r, x, y))
.map(|(_, path)| path.clone())
}
}
pub(super) fn rect_hit(rect: Rect, x: u16, y: u16) -> bool {
rect.width > 0
&& rect.height > 0
&& x >= rect.x
&& x < rect.x + rect.width
&& y >= rect.y
&& y < rect.y + rect.height
}