ratatui_toolkit/primitives/button/methods/is_clicked.rs
1use crate::primitives::button::Button;
2
3impl Button {
4 /// Checks if a click at the given coordinates is within the button's area.
5 ///
6 /// # Arguments
7 ///
8 /// * `column` - The column (x) coordinate
9 /// * `row` - The row (y) coordinate
10 ///
11 /// # Returns
12 ///
13 /// `true` if the coordinates are within the button's area, `false` otherwise
14 ///
15 /// # Note
16 ///
17 /// Returns `false` if the button has not been rendered yet (no area set)
18 pub fn is_clicked(&self, column: u16, row: u16) -> bool {
19 if let Some(area) = self.area {
20 column >= area.x
21 && column < area.x + area.width
22 && row >= area.y
23 && row < area.y + area.height
24 } else {
25 false
26 }
27 }
28}