1use super::Id;
9#[allow(unused)] use crate::Widget;
10use crate::geom::Rect;
11use std::ops::Range;
12
13#[derive(Clone, Debug)]
21pub struct ChildIndices(usize, usize);
22
23impl ChildIndices {
24 #[inline]
28 pub(crate) fn as_range(&self) -> Range<usize> {
29 self.0..self.1
30 }
31}
32
33impl IntoIterator for ChildIndices {
34 type Item = usize;
35 type IntoIter = ChildIndicesIter;
36
37 #[inline]
38 fn into_iter(self) -> ChildIndicesIter {
39 ChildIndicesIter(self.0..self.1)
40 }
41}
42
43impl From<Range<usize>> for ChildIndices {
44 #[inline]
45 fn from(range: Range<usize>) -> Self {
46 ChildIndices(range.start, range.end)
47 }
48}
49
50#[derive(Clone, Debug)]
52pub struct ChildIndicesIter(Range<usize>);
53
54impl Iterator for ChildIndicesIter {
55 type Item = usize;
56
57 #[inline]
58 fn next(&mut self) -> Option<usize> {
59 self.0.next()
60 }
61
62 #[inline]
63 fn size_hint(&self) -> (usize, Option<usize>) {
64 self.0.size_hint()
65 }
66}
67impl ExactSizeIterator for ChildIndicesIter {}
68impl DoubleEndedIterator for ChildIndicesIter {
69 #[inline]
70 fn next_back(&mut self) -> Option<usize> {
71 self.0.next_back()
72 }
73}
74
75#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
79#[cfg_attr(docsrs, doc(cfg(internal_doc)))]
80#[derive(Default, Debug)]
81pub struct DefaultCoreType {
82 pub _rect: Rect,
83 pub _id: Id,
84 #[cfg(debug_assertions)]
85 pub status: WidgetStatus,
86}
87
88impl Clone for DefaultCoreType {
89 fn clone(&self) -> Self {
90 DefaultCoreType {
91 _rect: self._rect,
92 _id: Default::default(),
93 #[cfg(debug_assertions)]
94 status: self.status,
95 }
96 }
97}
98
99#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
107#[cfg_attr(docsrs, doc(cfg(internal_doc)))]
108#[cfg(debug_assertions)]
109#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
110pub enum WidgetStatus {
111 #[default]
112 New,
113 Configured,
114 SizeRulesX,
115 SizeRulesY,
116 SetRect,
117}
118
119#[cfg(debug_assertions)]
120impl WidgetStatus {
121 fn require(&self, id: &Id, expected: Self) {
122 if *self < expected {
123 panic!("WidgetStatus of {id}: require {expected:?}, found {self:?}");
124 }
125 }
126
127 pub fn configure(&mut self, _id: &Id) {
131 *self = (*self).max(WidgetStatus::Configured);
133 }
134
135 pub fn update(&self, id: &Id) {
141 self.require(id, WidgetStatus::Configured);
142
143 }
148
149 pub fn size_rules(&mut self, id: &Id, axis: crate::layout::AxisInfo) {
156 if axis.is_horizontal() {
157 self.require(id, WidgetStatus::Configured);
158 *self = (*self).max(WidgetStatus::SizeRulesX);
159 } else {
160 self.require(id, WidgetStatus::SizeRulesX);
161 *self = (*self).max(WidgetStatus::SizeRulesY);
162 }
163 }
164
165 pub fn set_rect(&mut self, id: &Id) {
170 self.require(id, WidgetStatus::SizeRulesY);
171 *self = WidgetStatus::SetRect;
172 }
173
174 pub fn require_rect(&self, id: &Id) {
176 self.require(id, WidgetStatus::SetRect);
177 }
178}