pub struct ButtonTouchState<K> { /* private fields */ }Expand description
Shared touch tracker for a set of buttons.
Implementations§
Source§impl<K: Copy + Eq> ButtonTouchState<K>
impl<K: Copy + Eq> ButtonTouchState<K>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates an empty touch state.
Examples found in repository?
More examples
src/alert_host/presented.rs (line 50)
34 pub(super) fn new<const N: usize>(
35 key: Modal,
36 spec: AlertSpec<'a, N>,
37 ) -> Result<Self, AlertHostError> {
38 let mut actions = Vec::new();
39 for action in spec.actions {
40 actions
41 .push(action)
42 .map_err(|_| AlertHostError::TooManyActions)?;
43 }
44 Ok(Self {
45 key,
46 kind: spec.kind,
47 title: spec.title,
48 message: spec.message,
49 actions,
50 touch_state: ButtonTouchState::new(),
51 })
52 }Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the active button, if any.
Examples found in repository?
More examples
src/containers.rs (line 105)
103 pub fn set_root(&mut self, root: ViewId) {
104 self.nav = StackNav::new(root);
105 self.header_touch.clear();
106 }
107
108 /// Pushes a new view onto the stack.
109 pub fn push_view(&mut self, view: ViewId) -> Result<(), StackError> {
110 self.nav.push(view)
111 }
112
113 /// Pops the current view off the stack.
114 pub fn pop_view(&mut self) -> Result<ViewId, StackError> {
115 self.nav.pop()
116 }
117
118 /// Returns the top-most view identifier.
119 pub fn top_view(&self) -> ViewId {
120 self.nav.top()
121 }
122
123 /// Returns the current stack depth.
124 pub fn depth(&self) -> usize {
125 self.nav.depth()
126 }
127
128 /// Returns whether the stack is animating.
129 pub fn is_animating(&self) -> bool {
130 self.nav.is_animating()
131 }
132
133 /// Advances stack animation state.
134 pub fn advance(&mut self, dt_ms: u32) -> bool {
135 self.nav.advance(dt_ms)
136 }
137
138 /// Builds a navigation view for the supplied frame.
139 pub fn nav_view(&self, frame: Rectangle) -> NavView<'a, ViewId> {
140 self.nav.nav_view(frame, &self.title_for)
141 }
142
143 /// Clears transient header touch state.
144 pub fn clear_touch_state(&mut self) {
145 self.header_touch.clear();
146 }src/stack_view.rs (line 226)
218 pub fn handle_touch(
219 &self,
220 touch_state: &mut ButtonTouchState<NavHeaderAction>,
221 touch: TouchEvent,
222 ) -> ButtonTouchResponse<NavHeaderAction> {
223 if let Some(button) = self.back_button.as_ref() {
224 touch_state.handle_touch(touch, core::slice::from_ref(button))
225 } else {
226 touch_state.clear();
227 ButtonTouchResponse {
228 action: None,
229 captured: false,
230 redraw: false,
231 }
232 }
233 }Sourcepub fn is_highlighted(&self, button: &Button<'_, K>) -> bool
pub fn is_highlighted(&self, button: &Button<'_, K>) -> bool
Returns whether the supplied button is currently highlighted.
Examples found in repository?
src/alert/view.rs (line 122)
62 pub fn draw_state<D>(&self, display: &mut D, panel: Rectangle, theme: &FsTheme, i18n: &I18n<'a>)
63 where
64 D: embedded_graphics::draw_target::DrawTarget<Color = Rgb565>,
65 {
66 let layout = alert_layout_in_panel::<N>(panel, i18n.text(self.spec.message));
67 RoundedRectangle::with_equal_corners(
68 Rectangle::new(panel.top_left + Point::new(6, 8), panel.size),
69 Size::new(22, 22),
70 )
71 .into_styled(PrimitiveStyle::with_fill(theme.dim))
72 .draw(display)
73 .ok();
74
75 let panel_style = PrimitiveStyleBuilder::new()
76 .fill_color(theme.surface)
77 .stroke_color(theme.surface_alt)
78 .stroke_width(2)
79 .build();
80 RoundedRectangle::with_equal_corners(panel, Size::new(22, 22))
81 .into_styled(panel_style)
82 .draw(display)
83 .ok();
84
85 let title_style = MonoTextStyleBuilder::new()
86 .font(&FONT_9X18_BOLD)
87 .text_color(kind_color(self.spec.kind, theme))
88 .build();
89 let message_style = MonoTextStyleBuilder::new()
90 .font(&FONT_7X14)
91 .text_color(theme.text_secondary)
92 .build();
93 let text_style = TextStyleBuilder::new()
94 .alignment(Alignment::Center)
95 .baseline(Baseline::Middle)
96 .build();
97
98 Text::with_text_style(
99 i18n.text(self.spec.title),
100 panel.center() + Point::new(0, -40),
101 title_style,
102 text_style,
103 )
104 .draw(display)
105 .ok();
106 for (index, line) in layout.message_lines.iter().enumerate() {
107 Text::with_text_style(
108 line,
109 Point::new(panel.center().x, message_top(panel) + (index as i32 * 18)),
110 message_style,
111 text_style,
112 )
113 .draw(display)
114 .ok();
115 }
116
117 for button in self.buttons(panel) {
118 button.draw_state(
119 display,
120 theme,
121 i18n,
122 self.touch_state.is_highlighted(&button),
123 );
124 }
125 }More examples
src/alert_host/presented.rs (line 143)
79 pub(super) fn draw<D>(
80 &self,
81 display: &mut D,
82 panel: Rectangle,
83 theme: &FsTheme,
84 i18n: &I18n<'a>,
85 ) where
86 D: UiCanvas,
87 {
88 let layout = alert_layout_in_panel::<1>(panel, i18n.text(self.message));
89 RoundedRectangle::with_equal_corners(
90 Rectangle::new(panel.top_left + Point::new(6, 8), panel.size),
91 Size::new(22, 22),
92 )
93 .into_styled(PrimitiveStyle::with_fill(theme.dim))
94 .draw(display)
95 .ok();
96 RoundedRectangle::with_equal_corners(panel, Size::new(22, 22))
97 .into_styled(
98 PrimitiveStyleBuilder::new()
99 .fill_color(theme.surface)
100 .stroke_color(theme.surface_alt)
101 .stroke_width(2)
102 .build(),
103 )
104 .draw(display)
105 .ok();
106
107 let title_style = MonoTextStyleBuilder::new()
108 .font(&FONT_9X18_BOLD)
109 .text_color(kind_color(self.kind, theme))
110 .build();
111 let message_style = MonoTextStyleBuilder::new()
112 .font(&FONT_7X14)
113 .text_color(theme.text_secondary)
114 .build();
115 let text_style = TextStyleBuilder::new()
116 .alignment(Alignment::Center)
117 .baseline(Baseline::Middle)
118 .build();
119
120 Text::with_text_style(
121 i18n.text(self.title),
122 panel.center() + Point::new(0, -40),
123 title_style,
124 text_style,
125 )
126 .draw(display)
127 .ok();
128 for (index, line) in layout.message_lines.iter().enumerate() {
129 Text::with_text_style(
130 line,
131 Point::new(panel.center().x, message_top(panel) + (index as i32 * 18)),
132 message_style,
133 text_style,
134 )
135 .draw(display)
136 .ok();
137 }
138 for button in self.buttons(panel) {
139 button.draw_state(
140 display,
141 theme,
142 i18n,
143 self.touch_state.is_highlighted(&button),
144 );
145 }
146 }src/stack_view.rs (line 167)
120 pub fn draw_chrome<D>(
121 &self,
122 display: &mut D,
123 theme: &FsTheme,
124 i18n: &I18n<'a>,
125 touch: &ButtonTouchState<NavHeaderAction>,
126 ) where
127 D: DrawTarget<Color = Rgb565>,
128 {
129 let shell = PrimitiveStyleBuilder::new()
130 .fill_color(theme.surface_alt)
131 .stroke_color(theme.surface)
132 .stroke_width(2)
133 .build();
134 self.frame.into_styled(shell).draw(display).ok();
135
136 self.header
137 .into_styled(PrimitiveStyle::with_fill(theme.surface))
138 .draw(display)
139 .ok();
140 Line::new(
141 self.header.top_left + Point::new(0, self.header.size.height as i32),
142 self.header.bottom_right().unwrap_or(self.header.top_left),
143 )
144 .into_styled(PrimitiveStyle::with_stroke(theme.surface_alt, 2))
145 .draw(display)
146 .ok();
147
148 let title_style = MonoTextStyleBuilder::new()
149 .font(&FONT_9X18_BOLD)
150 .text_color(theme.text_primary)
151 .build();
152 let back_style = MonoTextStyleBuilder::new()
153 .font(&FONT_7X14)
154 .text_color(theme.text_primary)
155 .build();
156 let text_style = TextStyleBuilder::new()
157 .alignment(Alignment::Center)
158 .baseline(Baseline::Middle)
159 .build();
160 let settled_back_button = self.back_title.is_some() && self.secondary_title.is_none();
161
162 if settled_back_button {
163 let button = self
164 .back_button
165 .as_ref()
166 .expect("settled stacked headers include a back button");
167 button.draw_state(display, theme, i18n, touch.is_highlighted(button));
168 let arrow = MonoTextStyleBuilder::new()
169 .font(&FONT_7X14)
170 .text_color(theme.text_primary)
171 .build();
172 Text::with_text_style(
173 "<",
174 button.frame.top_left + Point::new(18, (button.frame.size.height / 2) as i32),
175 arrow,
176 TextStyleBuilder::new()
177 .alignment(Alignment::Center)
178 .baseline(Baseline::Middle)
179 .build(),
180 )
181 .draw(display)
182 .ok();
183 }
184
185 let mut header = display.clipped(&self.header);
186 if settled_back_button {
187 let title = self
188 .back_title
189 .expect("settled stacked headers include a back title");
190 Text::with_text_style(
191 i18n.text(title),
192 back_title_center(self.back_button.as_ref()),
193 back_style,
194 text_style,
195 )
196 .draw(&mut header)
197 .ok();
198 }
199 draw_title(
200 &mut header,
201 i18n.text(self.active_title.title),
202 self.active_title.center,
203 title_style,
204 text_style,
205 );
206 if let Some(title) = self.secondary_title {
207 draw_title(
208 &mut header,
209 i18n.text(title.title),
210 title.center,
211 title_style,
212 text_style,
213 );
214 }
215 }Sourcepub fn handle_touch<'a>(
&mut self,
touch: TouchEvent,
buttons: &[Button<'a, K>],
) -> ButtonTouchResponse<K>
pub fn handle_touch<'a>( &mut self, touch: TouchEvent, buttons: &[Button<'a, K>], ) -> ButtonTouchResponse<K>
Applies a touch sample to a button slice.
Examples found in repository?
More examples
src/stack_view.rs (line 224)
218 pub fn handle_touch(
219 &self,
220 touch_state: &mut ButtonTouchState<NavHeaderAction>,
221 touch: TouchEvent,
222 ) -> ButtonTouchResponse<NavHeaderAction> {
223 if let Some(button) = self.back_button.as_ref() {
224 touch_state.handle_touch(touch, core::slice::from_ref(button))
225 } else {
226 touch_state.clear();
227 ButtonTouchResponse {
228 action: None,
229 captured: false,
230 redraw: false,
231 }
232 }
233 }Trait Implementations§
Source§impl<K: Clone> Clone for ButtonTouchState<K>
impl<K: Clone> Clone for ButtonTouchState<K>
Source§fn clone(&self) -> ButtonTouchState<K>
fn clone(&self) -> ButtonTouchState<K>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<K: Debug> Debug for ButtonTouchState<K>
impl<K: Debug> Debug for ButtonTouchState<K>
Source§impl<K: PartialEq> PartialEq for ButtonTouchState<K>
impl<K: PartialEq> PartialEq for ButtonTouchState<K>
impl<K: Copy> Copy for ButtonTouchState<K>
impl<K: Eq> Eq for ButtonTouchState<K>
impl<K> StructuralPartialEq for ButtonTouchState<K>
Auto Trait Implementations§
impl<K> Freeze for ButtonTouchState<K>where
K: Freeze,
impl<K> RefUnwindSafe for ButtonTouchState<K>where
K: RefUnwindSafe,
impl<K> Send for ButtonTouchState<K>where
K: Send,
impl<K> Sync for ButtonTouchState<K>where
K: Sync,
impl<K> Unpin for ButtonTouchState<K>where
K: Unpin,
impl<K> UnsafeUnpin for ButtonTouchState<K>where
K: UnsafeUnpin,
impl<K> UnwindSafe for ButtonTouchState<K>where
K: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.