rust_widgets 2.5.2

Pure Rust cross-platform native GUI library with hardware-adaptive rendering, 180 widgets, touch/gesture support, i18n, and SVG-pipeline-accurate output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
// SPDX-FileCopyrightText: Copyright (c) 2026 Mike Li/Mikewolfli/Wei Li(mikewolfli@163.com)
// SPDX-License-Identifier: MIT

//! SwipeToDismiss — swipe-to-dismiss/delete gesture widget.
//!
//! Wraps a child widget that can be swiped left/right to reveal an action
//! background (e.g., red "Delete"). When the swipe passes the threshold,
//! the widget emits the `dismissed` signal.

use crate::core::{Color, Font, HorizontalAlignment, Point, Rect};
use crate::event::{Event, EventHandler};
use crate::render::RenderContext;
use crate::signal::Signal1;
use crate::widget::capability::properties_trait::{base_property_get, base_property_set};
use crate::widget::capability::types::{CapabilityAccessError, CapabilityValue};
use crate::widget::capability::WidgetProperties;
use crate::widget::{BaseWidget, Draw, Widget, WidgetKind};
use crate::{impl_widget_property_hooks, property_names_of};

/// Combined trait for widgets that can both be managed and drawn.
pub trait WidgetDraw: Widget + Draw {}
impl<T: Widget + Draw> WidgetDraw for T {}

/// SwipeToDismiss widget — swipe gesture to reveal actions and dismiss.
///
/// Wraps a child widget. The user can drag left/right to reveal an action
/// background behind the child. Releasing past the dismiss threshold emits
/// the `dismissed` signal.
pub struct SwipeToDismiss {
    base: BaseWidget,
    child: Option<Box<dyn WidgetDraw>>,
    /// Distance in pixels the user must swipe to trigger dismissal.
    dismiss_threshold: f32,
    /// Current horizontal swipe offset in pixels.
    swipe_offset: f32,
    /// X position where the active drag began, in the widget's coordinate space.
    /// `None` when no left-button drag is in progress.
    drag_origin_x: Option<f32>,
    /// Whether the widget has been dismissed (one-shot).
    is_dismissed: bool,
    /// Text displayed in the action background (e.g., "Delete").
    action_text: String,
    /// Emitted when the item is dismissed.
    pub dismissed: Signal1<()>,
}

impl SwipeToDismiss {
    /// Creates a new SwipeToDismiss widget with the given geometry.
    pub fn new(geometry: Rect) -> Self {
        let base = BaseWidget::new(WidgetKind::SwipeToDismiss, geometry, "SwipeToDismiss");
        Self {
            base,
            child: None,
            dismiss_threshold: 100.0,
            swipe_offset: 0.0,
            drag_origin_x: None,
            is_dismissed: false,
            action_text: "Delete".to_string(),
            dismissed: Signal1::new(),
        }
    }

    /// Sets the child widget to be wrapped.
    pub fn set_child(&mut self, widget: Box<dyn WidgetDraw>) {
        self.child = Some(widget);
        self.base.request_redraw();
    }

    /// Returns a shared reference to the child widget, if any.
    pub fn child(&self) -> Option<&dyn Widget> {
        self.child.as_deref().map(|c| c as &dyn Widget)
    }

    /// Returns a mutable reference to the child widget, if any.
    pub fn child_mut(&mut self) -> Option<&mut dyn Widget> {
        self.child.as_deref_mut().map(|c| c as &mut dyn Widget)
    }

    /// Sets the dismiss threshold in pixels.
    pub fn set_dismiss_threshold(&mut self, threshold: f32) {
        self.dismiss_threshold = threshold;
    }

    /// Returns the dismiss threshold.
    pub fn dismiss_threshold(&self) -> f32 {
        self.dismiss_threshold
    }

    /// Returns the current swipe offset.
    pub fn swipe_offset(&self) -> f32 {
        self.swipe_offset
    }

    /// Returns whether the widget has been dismissed.
    pub fn is_dismissed(&self) -> bool {
        self.is_dismissed
    }

    /// Sets the action text displayed behind the child.
    pub fn set_action_text(&mut self, text: &str) {
        self.action_text = text.to_string();
        self.base.request_redraw();
    }

    /// Returns the action text.
    pub fn action_text(&self) -> &str {
        &self.action_text
    }

    /// Resets the swipe offset (e.g., when dismissing fails or is undone).
    pub fn reset_swipe(&mut self) {
        self.swipe_offset = 0.0;
        self.is_dismissed = false;
        self.base.request_redraw();
    }

    /// Programmatically triggers the dismiss.
    pub fn dismiss(&mut self) {
        if !self.is_dismissed {
            self.is_dismissed = true;
            self.swipe_offset = 0.0;
            self.dismissed.emit(());
            self.base.request_redraw();
        }
    }
}

impl Widget for SwipeToDismiss {
    fn base(&self) -> &BaseWidget {
        &self.base
    }

    fn base_mut(&mut self) -> &mut BaseWidget {
        &mut self.base
    }

    fn size_hint(&self) -> crate::core::Size {
        crate::core::Size::new(400, 60)
    }

    fn kind(&self) -> WidgetKind {
        WidgetKind::SwipeToDismiss
    }
    impl_draw_bridge!();
    impl_widget_property_hooks!();
}

/// `SwipeToDismiss`'s property contract.
///
/// Read/write semantics are carried over unchanged from the centralised
/// `access_read_other.in.rs` / `access_write_other.in.rs` dispatch: reading
/// `is_dismissed` works, and writing it answers `UnsupportedOnWidget` because
/// dismissal is a one-shot gesture result rather than settable state.
impl WidgetProperties for SwipeToDismiss {
    fn get(&self, name: &str) -> Result<CapabilityValue, CapabilityAccessError> {
        match name {
            "is_dismissed" => Ok(CapabilityValue::Bool(self.is_dismissed())),
            _ => base_property_get(self, name),
        }
    }

    fn set(&mut self, name: &str, value: CapabilityValue) -> Result<(), CapabilityAccessError> {
        match name {
            // Dismissal is owned by the gesture recogniser, not by an external
            // writer, so the name exists but refuses writes. Reporting
            // `UnsupportedOnWidget` here would claim the control has no such
            // property at all, which is not true — `get` answers it.
            "is_dismissed" => Err(CapabilityAccessError::ReadOnlyProperty),
            _ => base_property_set(self, name, value),
        }
    }

    fn property_names(&self) -> &'static [&'static str] {
        property_names_of!["is_dismissed", BASE_PROPERTY_NAMES]
    }
}

impl Draw for SwipeToDismiss {
    fn draw(&mut self, context: &mut RenderContext) {
        let rect = self.geometry();

        if self.is_dismissed {
            // Dismissed state: just fill transparent so it's hidden
            context.fill_rect(rect, Color::rgba(0, 0, 0, 0));
            return;
        }

        // The child is mounted by this control, so this control is the one that has to
        // theme it. The census themes the top-level control it creates and nothing
        // below it (`render_one` draws the tree exactly as `Widget::draw` walks it), and
        // the factory that builds this wrapper does not call `apply_active_theme`
        // either — so a bare child label kept its own hardcoded ink and the wrapper's
        // dominant colour was that literal in both appearances. Ordering it on every
        // draw rather than only at `set_child` is the stronger guarantee: a child
        // swapped in by a later `set_child` is themed too, and the stylesheet layer
        // still wins because `merge_theme` only replaces what the theme itself wrote.
        if let Some(child) = self.child.as_deref_mut().map(|c| c as &mut dyn Widget) {
            crate::theme::apply_theme_to_widget(child);
        }

        // ── Action background revealed behind the child as it slides ──
        if self.swipe_offset.abs() > 2.0 {
            let bg_rect = if self.swipe_offset < 0.0 {
                // Swiping left: reveal action on the right side
                let reveal_w = (-self.swipe_offset) as u32;
                Rect::new(
                    rect.x + rect.width as i32 - reveal_w as i32,
                    rect.y,
                    reveal_w,
                    rect.height,
                )
            } else {
                // Swiping right: reveal action on the left side
                let reveal_w = self.swipe_offset as u32;
                Rect::new(rect.x, rect.y, reveal_w, rect.height)
            };

            // The action background is SEMANTIC colour, not chrome: the red *encodes* "this
            // swipe deletes", so it reads the theme's error token rather than `style.*`. The
            // literal it used to be stays as the `unwrap_or` fallback, so a build or theme
            // with no palette still gets the iOS red this control has always painted.
            let destructive = crate::style::semantic_color(crate::style::SemanticColor::Error)
                .unwrap_or(Color::rgba(255, 59, 48, 255));
            context.fill_rect(bg_rect, destructive);

            // Action text centered in revealed area
            if !self.action_text.is_empty() {
                let font = Font::new("sans-serif", 16.0, false, false);
                let metrics = context.measure_text(&self.action_text, &font);
                let text_x = bg_rect.x + (bg_rect.width as i32 - metrics.width as i32) / 2;
                let text_y = bg_rect.y + (bg_rect.height as i32 / 2) + (metrics.ascent as i32 / 2)
                    - (metrics.descent as i32 / 2);
                context.draw_text(
                    Point::new(text_x, text_y),
                    &self.action_text,
                    &font,
                    // Picked for legibility on whichever red the theme resolves, rather
                    // than assuming the light-theme red and hardcoding white.
                    destructive.contrast_color(),
                    HorizontalAlignment::Left,
                );
            }
        }

        // ── Draw the child widget offset by the swipe amount ──
        if let Some(child) = &mut self.child {
            // Save the original child geometry, offset it, draw, then restore
            let original_geom = child.geometry();
            let offset_x = self.swipe_offset as i32;
            let translated_rect = Rect::new(rect.x + offset_x, rect.y, rect.width, rect.height);
            child.set_geometry(translated_rect);
            child.draw(context);
            child.set_geometry(original_geom);
        }

        // ── Draw a subtle shadow line at the child edge when swiped ──
        if self.swipe_offset.abs() > 5.0 {
            let edge_x = if self.swipe_offset < 0.0 {
                rect.x + rect.width as i32 + self.swipe_offset as i32
            } else {
                rect.x + self.swipe_offset as i32
            };
            context.draw_line(
                Point::new(edge_x, rect.y),
                Point::new(edge_x, rect.y + rect.height as i32),
                Color::rgba(0, 0, 0, 40),
            );
        }
    }
}

impl EventHandler for SwipeToDismiss {
    fn handle_event(&mut self, event: &Event) {
        if self.is_dismissed {
            return;
        }

        // A disabled container must not be dismissed. Clearing any in-flight drag
        // first matters: disabling mid-gesture used to leave `drag_origin_x` set, so
        // a later `MouseMove` would still move the child content (the pointer was
        // never pressed, yet the offset changed).
        if !self.base.is_enabled() {
            self.drag_origin_x = None;
            self.swipe_offset = 0.0;
            self.base.handle_event(event);
            return;
        }

        match event {
            Event::MousePress { pos, button } => {
                if *button == 1 {
                    // Remember where the drag started; the offset is the delta
                    // from here, so the child only moves as far as the pointer.
                    self.drag_origin_x = Some(pos.x as f32);
                    self.swipe_offset = 0.0;
                }
            }
            #[cfg(feature = "touch")]
            Event::TouchBegin { pos, .. } => {
                // Touch and mouse share the drag path: tablets/mobile report
                // touches, desktops report mouse, and the gesture is identical.
                self.drag_origin_x = Some(pos.x as f32);
                self.swipe_offset = 0.0;
            }
            Event::MouseMove { pos } => {
                if let Some(origin) = self.drag_origin_x {
                    self.swipe_offset = pos.x as f32 - origin;
                    self.base.request_redraw();
                }
            }
            #[cfg(feature = "touch")]
            Event::TouchMove { pos, .. } => {
                if let Some(origin) = self.drag_origin_x {
                    self.swipe_offset = pos.x as f32 - origin;
                    self.base.request_redraw();
                }
            }
            Event::MouseRelease { pos: _, button } => {
                if *button == 1 {
                    self.drag_origin_x = None;
                    if self.swipe_offset.abs() >= self.dismiss_threshold {
                        self.is_dismissed = true;
                        self.dismissed.emit(());
                    }
                    self.swipe_offset = 0.0;
                    self.base.request_redraw();
                }
            }
            #[cfg(feature = "touch")]
            Event::TouchEnd { .. } => {
                self.drag_origin_x = None;
                if self.swipe_offset.abs() >= self.dismiss_threshold {
                    self.is_dismissed = true;
                    self.dismissed.emit(());
                }
                self.swipe_offset = 0.0;
                self.base.request_redraw();
            }
            // Delegate remaining events to child
            evt => {
                if let Some(child) = &mut self.child {
                    child.handle_event(evt);
                } else {
                    self.base.handle_event(evt);
                }
            }
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::render::RenderContext;
    use crate::widget::svg::render_to_svg;
    use std::sync::Arc;

    /// A minimal test child widget used for SwipeToDismiss tests.
    struct TestChild {
        base: BaseWidget,
        draw_called: std::sync::Arc<std::sync::atomic::AtomicBool>,
    }

    impl TestChild {
        fn new(geometry: Rect, flag: std::sync::Arc<std::sync::atomic::AtomicBool>) -> Self {
            Self {
                base: BaseWidget::new(WidgetKind::Label, geometry, "TestChild"),
                draw_called: flag,
            }
        }
    }

    impl Widget for TestChild {
        fn base(&self) -> &BaseWidget {
            &self.base
        }
        fn base_mut(&mut self) -> &mut BaseWidget {
            &mut self.base
        }
    }

    impl Draw for TestChild {
        fn draw(&mut self, context: &mut RenderContext) {
            self.draw_called.store(true, std::sync::atomic::Ordering::SeqCst);
            context.fill_rect(self.geometry(), Color::WHITE);
        }
    }

    impl EventHandler for TestChild {
        fn handle_event(&mut self, event: &Event) {
            self.base.handle_event(event);
        }
    }

    #[test]
    fn swipe_to_dismiss_creation() {
        let sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));
        assert_eq!(sw.kind(), WidgetKind::SwipeToDismiss);
        assert!(!sw.is_dismissed());
        assert_eq!(sw.dismiss_threshold(), 100.0);
        assert_eq!(sw.action_text(), "Delete");
    }

    #[test]
    fn swipe_to_dismiss_action_text() {
        let mut sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));
        assert_eq!(sw.action_text(), "Delete");

        sw.set_action_text("Archive");
        assert_eq!(sw.action_text(), "Archive");
    }

    #[test]
    fn swipe_to_dismiss_dismiss_threshold() {
        let mut sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));
        sw.set_dismiss_threshold(80.0);
        assert_eq!(sw.dismiss_threshold(), 80.0);
    }

    #[test]
    fn swipe_to_dismiss_set_child_and_draw() {
        let draw_flag = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
        let child = TestChild::new(Rect::new(0, 0, 200, 50), draw_flag.clone());

        let mut sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));
        sw.set_child(Box::new(child));
        assert!(sw.child().is_some());

        let svg = render_to_svg(&mut sw);
        assert!(svg.starts_with("<svg"));
        assert!(draw_flag.load(std::sync::atomic::Ordering::SeqCst));
    }

    #[test]
    fn swipe_to_dismiss_dismiss_programmatic() {
        let mut sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));

        let fired = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
        let f = fired.clone();
        sw.dismissed.connect(move |_: Arc<()>| {
            f.store(true, std::sync::atomic::Ordering::SeqCst);
        });

        sw.dismiss();
        assert!(sw.is_dismissed());
        assert!(fired.load(std::sync::atomic::Ordering::SeqCst));
    }

    #[test]
    fn swipe_to_dismiss_drag_past_threshold_triggers_dismiss() {
        let mut sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));

        let fired = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
        let f = fired.clone();
        sw.dismissed.connect(move |_: Arc<()>| {
            f.store(true, std::sync::atomic::Ordering::SeqCst);
        });

        // A real left drag: press at x=180, move to x=60 (120px left), release.
        // This exercises the production input path; it must not need the
        // private offset field to be written by the test.
        sw.handle_event(&Event::MousePress { pos: Point::new(180, 25), button: 1 });
        sw.handle_event(&Event::MouseMove { pos: Point::new(60, 25) });
        // The offset tracks the pointer delta while the drag is in progress.
        assert_eq!(sw.swipe_offset(), -120.0);
        sw.handle_event(&Event::MouseRelease { pos: Point::new(60, 25), button: 1 });

        assert!(sw.is_dismissed());
        assert!(fired.load(std::sync::atomic::Ordering::SeqCst));
    }

    /// A disabled container must not be dismissible by dragging.
    ///
    /// `handle_event` never consulted `is_enabled()`, so `set_enabled(false)` left the
    /// gesture fully live. The same defect also made a mid-gesture disable dangerous:
    /// the drag origin survived, so a subsequent `MouseMove` — with no button held —
    /// still shifted the child content.
    #[test]
    fn swipe_to_dismiss_disabled_ignores_the_gesture() {
        let mut sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));
        sw.set_enabled(false);

        let fired = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
        let f = fired.clone();
        sw.dismissed.connect(move |_: Arc<()>| {
            f.store(true, std::sync::atomic::Ordering::SeqCst);
        });

        sw.handle_event(&Event::MousePress { pos: Point::new(180, 25), button: 1 });
        sw.handle_event(&Event::MouseMove { pos: Point::new(60, 25) });
        assert_eq!(sw.swipe_offset(), 0.0, "a disabled container must not track the pointer");
        sw.handle_event(&Event::MouseRelease { pos: Point::new(60, 25), button: 1 });

        assert!(!sw.is_dismissed(), "a disabled container must not dismiss");
        assert!(!fired.load(std::sync::atomic::Ordering::SeqCst));
    }

    /// Disabling mid-drag must clear the drag so a later move cannot shift content.
    #[test]
    fn swipe_to_dismiss_disabling_mid_drag_ends_the_gesture() {
        let mut sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));

        sw.handle_event(&Event::MousePress { pos: Point::new(180, 25), button: 1 });
        sw.handle_event(&Event::MouseMove { pos: Point::new(150, 25) });
        assert_eq!(sw.swipe_offset(), -30.0, "the drag is live before disabling");

        sw.set_enabled(false);
        // A stray move arrives with no button held; it must not move anything.
        sw.handle_event(&Event::MouseMove { pos: Point::new(40, 25) });

        assert_eq!(
            sw.swipe_offset(),
            0.0,
            "disabling must end the in-flight drag rather than leave the origin set"
        );
        sw.handle_event(&Event::MouseRelease { pos: Point::new(40, 25), button: 1 });
        assert!(!sw.is_dismissed(), "the gesture was cancelled, not completed");
    }

    #[cfg(feature = "touch")]
    #[test]
    fn swipe_to_dismiss_touch_drag_past_threshold_triggers_dismiss() {
        let mut sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));

        let fired = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
        let f = fired.clone();
        sw.dismissed.connect(move |_: Arc<()>| {
            f.store(true, std::sync::atomic::Ordering::SeqCst);
        });

        // Touch and mouse must share one drag path (tablet/mobile parity).
        sw.handle_event(&Event::TouchBegin { pos: Point::new(180, 25), touch_id: 0 });
        sw.handle_event(&Event::TouchMove { pos: Point::new(50, 25), touch_id: 0 });
        assert_eq!(sw.swipe_offset(), -130.0);
        sw.handle_event(&Event::TouchEnd { pos: Point::new(50, 25), touch_id: 0 });

        assert!(sw.is_dismissed());
        assert!(fired.load(std::sync::atomic::Ordering::SeqCst));
    }

    #[test]
    fn swipe_to_dismiss_drag_below_threshold_no_dismiss() {
        let mut sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));

        let fired = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
        let f = fired.clone();
        sw.dismissed.connect(move |_: Arc<()>| {
            f.store(true, std::sync::atomic::Ordering::SeqCst);
        });

        // Only 50px left: below the 100px threshold, so the swipe must snap back.
        sw.handle_event(&Event::MousePress { pos: Point::new(180, 25), button: 1 });
        sw.handle_event(&Event::MouseMove { pos: Point::new(130, 25) });
        sw.handle_event(&Event::MouseRelease { pos: Point::new(130, 25), button: 1 });

        assert!(!sw.is_dismissed());
        assert!(!fired.load(std::sync::atomic::Ordering::SeqCst));
        assert_eq!(sw.swipe_offset(), 0.0);
    }

    #[test]
    fn swipe_to_dismiss_ignores_move_without_press() {
        // A pointer move with no preceding press is not a drag, so it must not
        // move the child (the offset is a drag delta, not an absolute position).
        let mut sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));
        sw.handle_event(&Event::MouseMove { pos: Point::new(10, 10) });
        assert_eq!(sw.swipe_offset(), 0.0);
    }

    #[test]
    fn swipe_to_dismiss_reset_swipe() {
        let mut sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));
        sw.swipe_offset = -80.0;
        sw.is_dismissed = true;

        sw.reset_swipe();
        assert_eq!(sw.swipe_offset(), 0.0);
        assert!(!sw.is_dismissed());
    }

    #[test]
    fn swipe_to_dismiss_svg_output() {
        let mut sw = SwipeToDismiss::new(Rect::new(0, 0, 200, 50));
        sw.set_action_text("Delete");
        let svg = render_to_svg(&mut sw);
        assert!(svg.starts_with("<svg"));
    }
}