@@ -112,9 +112,19 @@ pub struct TestHarness {
112
112
title : String ,
113
113
}
114
114
115
+ /// Parameters for creating a [`TestHarness`].
116
+ #[ derive( Debug , Clone , Copy ) ]
117
+ #[ non_exhaustive]
115
118
pub struct TestHarnessParams {
119
+ /// The size of the virtual window the harness renders into for snapshot testing.
120
+ /// Defaults to [`Self::DEFAULT_SIZE`].
116
121
pub window_size : Size ,
122
+ /// The background color of the virtual window.
123
+ /// Defaults to [`Self::DEFAULT_BACKGROUND_COLOR`].
117
124
pub background_color : Color ,
125
+ /// The scale factor widgets are rendered at.
126
+ /// Defaults to 1.0.
127
+ pub scale_factor : f64 ,
118
128
}
119
129
120
130
/// Assert a snapshot of a rendered frame of your app.
@@ -153,6 +163,7 @@ impl Default for TestHarnessParams {
153
163
Self {
154
164
window_size : Self :: DEFAULT_SIZE ,
155
165
background_color : Self :: DEFAULT_BACKGROUND_COLOR ,
166
+ scale_factor : 1.0 ,
156
167
}
157
168
}
158
169
}
@@ -177,7 +188,7 @@ impl TestHarness {
177
188
)
178
189
}
179
190
180
- /// Builds harness with given root widget, canvas size and background color .
191
+ /// Builds harness with given root widget and additional parameters .
181
192
pub fn create_with ( root_widget : impl Widget , params : TestHarnessParams ) -> Self {
182
193
let mouse_state = PointerState :: empty ( ) ;
183
194
let window_size = PhysicalSize :: new (
@@ -204,7 +215,7 @@ impl TestHarness {
204
215
RenderRootOptions {
205
216
use_system_fonts : false ,
206
217
size_policy : WindowSizePolicy :: User ,
207
- scale_factor : 1.0 ,
218
+ scale_factor : params . scale_factor ,
208
219
test_font : Some ( data) ,
209
220
} ,
210
221
) ,
@@ -222,12 +233,10 @@ impl TestHarness {
222
233
}
223
234
224
235
// --- MARK: PROCESS EVENTS ---
225
- // FIXME - The docs for these three functions are copy-pasted. Rewrite them.
226
236
227
237
/// Send a [`WindowEvent`] to the simulated window.
228
238
///
229
- /// If this event triggers rewrite passes, they will also run as normal.
230
- // TODO - Link to tutorial about rewrite passes - See #632
239
+ /// This will run [rewrite passes](crate::doc::doc_05_pass_system#rewrite-passes) after the event is processed.
231
240
pub fn process_window_event ( & mut self , event : WindowEvent ) -> Handled {
232
241
let handled = self . render_root . handle_window_event ( event) ;
233
242
self . process_signals ( ) ;
@@ -236,8 +245,7 @@ impl TestHarness {
236
245
237
246
/// Send a [`PointerEvent`] to the simulated window.
238
247
///
239
- /// If this event triggers rewrite passes, they will also run as normal.
240
- // TODO - Link to tutorial about rewrite passes - See #632
248
+ /// This will run [rewrite passes](crate::doc::doc_05_pass_system#rewrite-passes) after the event is processed.
241
249
pub fn process_pointer_event ( & mut self , event : PointerEvent ) -> Handled {
242
250
let handled = self . render_root . handle_pointer_event ( event) ;
243
251
self . process_signals ( ) ;
@@ -246,8 +254,7 @@ impl TestHarness {
246
254
247
255
/// Send a [`TextEvent`] to the simulated window.
248
256
///
249
- /// If this event triggers rewrite passes, they will also run as normal.
250
- // TODO - Link to tutorial about rewrite passes - See #632
257
+ /// This will run [rewrite passes](crate::doc::doc_05_pass_system#rewrite-passes) after the event is processed.
251
258
pub fn process_text_event ( & mut self , event : TextEvent ) -> Handled {
252
259
let handled = self . render_root . handle_text_event ( event) ;
253
260
self . process_signals ( ) ;
@@ -490,12 +497,11 @@ impl TestHarness {
490
497
}
491
498
}
492
499
493
- /// Sets the focused widget.
500
+ /// Sets the [ focused widget](crate::doc::doc_06_masonry_concepts#text-focus) .
494
501
///
495
502
/// ## Panics
496
503
///
497
504
/// If the widget is not found in the tree or can't be focused.
498
- // TODO - Link to focus definition in tutorial
499
505
#[ track_caller]
500
506
pub fn focus_on ( & mut self , id : Option < WidgetId > ) {
501
507
if let Some ( id) = id {
@@ -547,20 +553,19 @@ impl TestHarness {
547
553
}
548
554
549
555
// TODO - Link to focus definition in tutorial
550
- /// Return a [`WidgetRef`] to the widget that receives keyboard events .
556
+ /// Return a [`WidgetRef`] to the [focused widget](crate::doc::doc_06_masonry_concepts#text-focus) .
551
557
pub fn focused_widget ( & self ) -> Option < WidgetRef < ' _ , dyn Widget > > {
552
558
self . root_widget ( )
553
559
. find_widget_by_id ( self . render_root . global_state . focused_widget ?)
554
560
}
555
561
556
- /// Return a [`WidgetRef`] to the widget which captures pointer events.
557
- // TODO - Link to pointer capture definition in tutorial
562
+ /// Return a [`WidgetRef`] to the widget which [captures pointer events](crate::doc::doc_06_masonry_concepts#pointer-capture).
558
563
pub fn pointer_capture_target ( & self ) -> Option < WidgetRef < ' _ , dyn Widget > > {
559
564
self . render_root
560
565
. get_widget ( self . render_root . global_state . pointer_capture_target ?)
561
566
}
562
567
563
- /// Return the id of the widget which captures pointer events.
568
+ /// Return the id of the widget which [ captures pointer events](crate::doc::doc_06_masonry_concepts#pointer-capture) .
564
569
// TODO - This is kinda redundant with the above
565
570
pub fn pointer_capture_target_id ( & self ) -> Option < WidgetId > {
566
571
self . render_root . global_state . pointer_capture_target
0 commit comments