@@ -53,22 +53,29 @@ pub fn draw_from_graph<G, C>(context: Context,
53
53
54
54
// If the current widget is some scrollable widget, we need to add a context
55
55
// for it to the top of the stack.
56
- if let Some ( scrolling) = container. maybe_scrolling {
57
- let context = crop_context ( context, scrolling. visible ) ;
56
+ //
57
+ // TODO: Make this more generic than just "if scrolling crop to kid_area".
58
+ if container. maybe_x_scroll_state . is_some ( )
59
+ || container. maybe_y_scroll_state . is_some ( ) {
60
+ let context = crop_context ( context, container. kid_area . rect ) ;
58
61
scroll_stack. push ( context) ;
59
62
}
60
63
}
61
64
} ,
62
65
63
66
Visitable :: Scrollbar ( idx) => {
64
- if let Some ( scrolling ) = graph. widget_scroll_state ( idx) {
67
+ if let Some ( widget ) = graph. widget ( idx) {
65
68
66
69
// Now that we've come across a scrollbar, we'll pop its Context from the
67
70
// scroll_stack and draw it if necessary.
68
71
let context = scroll_stack. pop ( ) . unwrap_or ( context) ;
69
72
70
73
// Draw the scrollbar(s)!
71
- draw_scrolling ( & context, graphics, scrolling) ;
74
+ draw_scrolling ( & context,
75
+ graphics,
76
+ widget. kid_area . rect ,
77
+ widget. maybe_x_scroll_state ,
78
+ widget. maybe_y_scroll_state ) ;
72
79
}
73
80
}
74
81
@@ -174,10 +181,6 @@ pub fn draw_from_container<G, C>(context: &Context,
174
181
ShapeStyle :: Fill ( _) => {
175
182
let color = rectangle. style . get_color ( theme) ;
176
183
draw_rectangle ( context, graphics, container. rect , color) ;
177
- // let (l, b, w, h) = container.rect.l_b_w_h();
178
- // let lbwh = [l, b, w, h];
179
- // let rectangle = graphics::Rectangle::new(color);
180
- // rectangle.draw(lbwh, &context.draw_state, context.transform, graphics);
181
184
} ,
182
185
ShapeStyle :: Outline ( line_style) => {
183
186
let ( l, r, b, t) = container. rect . l_r_b_t ( ) ;
@@ -350,48 +353,48 @@ pub fn draw_lines<G, I>(context: &Context,
350
353
/// Draw the scroll bars (if necessary) for the given widget's scroll state.
351
354
pub fn draw_scrolling < G > ( context : & Context ,
352
355
graphics : & mut G ,
353
- scroll_state : & widget:: scroll:: State )
356
+ kid_area_rect : Rect ,
357
+ maybe_x_scroll_state : Option < widget:: scroll:: StateX > ,
358
+ maybe_y_scroll_state : Option < widget:: scroll:: StateY > )
354
359
where G : Graphics ,
355
360
{
356
361
use widget:: scroll;
357
362
358
- let color = scroll_state. color ;
359
- let track_color = color. alpha ( 0.2 ) ;
360
- let thickness = scroll_state. thickness ;
361
- let visible = scroll_state. visible ;
362
-
363
- let draw_bar = |g : & mut G , bar : scroll:: Bar , track : Rect , handle : Rect | {
364
- // We only want to see the scrollbar if it's highlighted or clicked.
365
- if let scroll:: Interaction :: Normal = bar. interaction {
366
- return ;
367
- }
368
- let color = bar. interaction . color ( color) ;
369
- draw_rectangle ( context, g, track, track_color) ;
370
- draw_rectangle ( context, g, handle, color) ;
371
- } ;
372
-
373
- // The element for a vertical scroll Bar.
374
- let vertical = |g : & mut G , bar : scroll:: Bar | {
375
- let track = scroll:: vertical_track ( visible, thickness) ;
376
- let handle = scroll:: vertical_handle ( & bar, track, scroll_state. total_dim [ 1 ] ) ;
377
- draw_bar ( g, bar, track, handle) ;
378
- } ;
363
+ fn draw_axis < G , A > ( context : & Context ,
364
+ graphics : & mut G ,
365
+ kid_area_rect : Rect ,
366
+ scroll_state : & scroll:: State < A > )
367
+ where G : Graphics ,
368
+ A : scroll:: Axis ,
369
+ {
370
+ use widget:: scroll:: Elem :: { Handle , Track } ;
371
+ use widget:: scroll:: Interaction :: { Highlighted , Clicked } ;
372
+
373
+ let color = scroll_state. color ;
374
+ let track_color = match scroll_state. interaction {
375
+ Clicked ( Track ) => color. highlighted ( ) ,
376
+ Highlighted ( _) | Clicked ( _) => color,
377
+ _ if scroll_state. is_scrolling => color,
378
+ _ => return ,
379
+ } . alpha ( 0.2 ) ;
380
+ let handle_color = match scroll_state. interaction {
381
+ Clicked ( Handle ( _) ) => color. clicked ( ) ,
382
+ Highlighted ( _) | Clicked ( _) => color,
383
+ _ if scroll_state. is_scrolling => color,
384
+ _ => return ,
385
+ } ;
386
+ let thickness = scroll_state. thickness ;
387
+ let track = scroll:: track :: < A > ( kid_area_rect, thickness) ;
388
+ let handle = scroll:: handle :: < A > ( track, & scroll_state) ;
389
+ draw_rectangle ( context, graphics, track, track_color) ;
390
+ draw_rectangle ( context, graphics, handle, handle_color) ;
391
+ }
379
392
380
- // An element for a horizontal scroll Bar.
381
- let horizontal = |g : & mut G , bar : scroll:: Bar | {
382
- let track = scroll:: horizontal_track ( visible, thickness) ;
383
- let handle = scroll:: horizontal_handle ( & bar, track, scroll_state. total_dim [ 0 ] ) ;
384
- draw_bar ( g, bar, track, handle) ;
385
- } ;
393
+ if let Some ( ref scroll_state) = maybe_y_scroll_state {
394
+ draw_axis :: < G , scroll:: Y > ( context, graphics, kid_area_rect, scroll_state)
395
+ }
386
396
387
- // Whether we draw horizontal or vertical or both depends on our state.
388
- match ( scroll_state. maybe_vertical , scroll_state. maybe_horizontal ) {
389
- ( Some ( v_bar) , Some ( h_bar) ) => {
390
- horizontal ( graphics, h_bar) ;
391
- vertical ( graphics, v_bar) ;
392
- } ,
393
- ( Some ( bar) , None ) => vertical ( graphics, bar) ,
394
- ( None , Some ( bar) ) => horizontal ( graphics, bar) ,
395
- ( None , None ) => ( ) ,
397
+ if let Some ( ref scroll_state) = maybe_x_scroll_state {
398
+ draw_axis :: < G , scroll:: X > ( context, graphics, kid_area_rect, scroll_state)
396
399
}
397
400
}
0 commit comments