@@ -660,6 +660,7 @@ impl Drawable for ExpandingLayer {
660
660
pub struct ScrollView {
661
661
pub view : Rc < View > ,
662
662
pub layer : Rc < ExpandingLayer > ,
663
+ cached_mouse_position : RefCell < Point > ,
663
664
}
664
665
665
666
impl ScrollView {
@@ -679,7 +680,11 @@ impl ScrollView {
679
680
view. set_border_enabled ( false ) ;
680
681
//view.set_border_enabled(false);
681
682
682
- Rc :: new ( Self { view, layer } )
683
+ Rc :: new ( Self {
684
+ view,
685
+ layer,
686
+ cached_mouse_position : RefCell :: new ( Point :: zero ( ) ) ,
687
+ } )
683
688
}
684
689
685
690
pub fn new < F : ' static + Fn ( & View , Size ) -> Rect > ( sizer : F ) -> Rc < Self > {
@@ -693,6 +698,17 @@ impl ScrollView {
693
698
fn scroll_bar_width ( ) -> isize {
694
699
42
695
700
}
701
+
702
+ fn record_mouse_position ( & self , mouse_point : Point ) {
703
+ * self . cached_mouse_position . borrow_mut ( ) = mouse_point;
704
+ }
705
+
706
+ fn scroll_bar_region_contains_mouse ( & self ) -> bool {
707
+ let mouse_position = * self . cached_mouse_position . borrow ( ) ;
708
+ // TODO(PT): Check whether we need to relocate this point to our local coordinate space
709
+ self . scroll_bar_content_frame ( ) . contains ( mouse_position)
710
+ }
711
+
696
712
fn scroll_bar_content_frame ( & self ) -> Rect {
697
713
let ( frame_of_inner_margin, frame_of_content) = compute_inner_margin_and_content_frames (
698
714
self . outer_border_insets ( ) ,
@@ -778,9 +794,14 @@ impl Bordered for ScrollView {
778
794
) ;
779
795
780
796
// Mouse interaction highlight on top of the scroll bar
797
+ let scroll_bar_highlight_color = if self . scroll_bar_region_contains_mouse ( ) {
798
+ Color :: new ( 200 , 200 , 200 )
799
+ } else {
800
+ Color :: new ( 160 , 160 , 160 )
801
+ } ;
781
802
scroll_bar_onto. fill_rect (
782
803
Rect :: from_parts ( scrollbar_attrs. origin , scrollbar_attrs. size ) ,
783
- Color :: new ( 160 , 160 , 160 ) ,
804
+ scroll_bar_highlight_color ,
784
805
StrokeThickness :: Width ( 1 ) ,
785
806
) ;
786
807
@@ -840,6 +861,9 @@ impl UIElement for ScrollView {
840
861
}
841
862
842
863
fn handle_mouse_moved ( & self , mouse_point : Point ) {
864
+ // Keep track of the mouse position, so we can detect whether the mouse is
865
+ // hovering on the scroll bar
866
+ self . record_mouse_position ( mouse_point) ;
843
867
self . view . handle_mouse_moved ( mouse_point)
844
868
}
845
869
0 commit comments