1use agape_core::GlobalId;
2use thiserror::Error;
3
4#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
5pub enum OverflowAxis {
6 MainAxis,
7 CrossAxis,
8}
9
10impl std::fmt::Display for OverflowAxis {
11 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12 write!(f, "{self:?}")
13 }
14}
15
16#[derive(Debug, Clone, Error, PartialEq, Eq)]
17pub enum LayoutError {
18 #[error("Widget(id:{child_id}) is out of it's parent's (id:{parent_id}) bounds")]
19 OutOfBounds {
20 parent_id: GlobalId,
21 child_id: GlobalId,
22 },
23
24 #[error("Widget(id:{id})'s children have overflown in the {axis}")]
25 Overflow { id: GlobalId, axis: OverflowAxis },
26}
27
28impl LayoutError {
29 pub fn out_of_bound(parent_id: GlobalId, child_id: GlobalId) -> Self {
30 Self::OutOfBounds {
31 parent_id,
32 child_id,
33 }
34 }
35
36 pub fn overflow(id: GlobalId, axis: OverflowAxis) -> Self {
37 Self::Overflow { id, axis }
38 }
39}