@@ -583,6 +583,7 @@ impl<'open> Window<'open> {
583
583
outer_rect,
584
584
frame_stroke,
585
585
window_frame. rounding ,
586
+ resize_interaction,
586
587
) ;
587
588
588
589
// END FRAME --------------------------------
@@ -651,29 +652,30 @@ fn paint_resize_corner(
651
652
outer_rect : Rect ,
652
653
stroke : impl Into < Stroke > ,
653
654
rounding : impl Into < Rounding > ,
655
+ i : ResizeInteraction ,
654
656
) {
655
- let stroke = stroke. into ( ) ;
657
+ let inactive_stroke = stroke. into ( ) ;
656
658
let rounding = rounding. into ( ) ;
657
- let ( corner, radius) = if possible. resize_right && possible. resize_bottom {
658
- ( Align2 :: RIGHT_BOTTOM , rounding. se )
659
+ let ( corner, radius, corner_response ) = if possible. resize_right && possible. resize_bottom {
660
+ ( Align2 :: RIGHT_BOTTOM , rounding. se , i . right & i . bottom )
659
661
} else if possible. resize_left && possible. resize_bottom {
660
- ( Align2 :: LEFT_BOTTOM , rounding. sw )
662
+ ( Align2 :: LEFT_BOTTOM , rounding. sw , i . left & i . bottom )
661
663
} else if possible. resize_left && possible. resize_top {
662
- ( Align2 :: LEFT_TOP , rounding. nw )
664
+ ( Align2 :: LEFT_TOP , rounding. nw , i . left & i . top )
663
665
} else if possible. resize_right && possible. resize_top {
664
- ( Align2 :: RIGHT_TOP , rounding. ne )
666
+ ( Align2 :: RIGHT_TOP , rounding. ne , i . right & i . top )
665
667
} else {
666
668
// We're not in two directions, but it is still nice to tell the user
667
669
// we're resizable by painting the resize corner in the expected place
668
670
// (i.e. for windows only resizable in one direction):
669
671
if possible. resize_right || possible. resize_bottom {
670
- ( Align2 :: RIGHT_BOTTOM , rounding. se )
672
+ ( Align2 :: RIGHT_BOTTOM , rounding. se , i . right & i . bottom )
671
673
} else if possible. resize_left || possible. resize_bottom {
672
- ( Align2 :: LEFT_BOTTOM , rounding. sw )
674
+ ( Align2 :: LEFT_BOTTOM , rounding. sw , i . left & i . bottom )
673
675
} else if possible. resize_left || possible. resize_top {
674
- ( Align2 :: LEFT_TOP , rounding. nw )
676
+ ( Align2 :: LEFT_TOP , rounding. nw , i . left & i . top )
675
677
} else if possible. resize_right || possible. resize_top {
676
- ( Align2 :: RIGHT_TOP , rounding. ne )
678
+ ( Align2 :: RIGHT_TOP , rounding. ne , i . right & i . top )
677
679
} else {
678
680
return ;
679
681
}
@@ -683,6 +685,14 @@ fn paint_resize_corner(
683
685
let offset =
684
686
( ( 2.0_f32 . sqrt ( ) * ( 1.0 + radius) - radius) * 45.0_f32 . to_radians ( ) . cos ( ) ) . max ( 2.0 ) ;
685
687
688
+ let stroke = if corner_response. drag {
689
+ ui. visuals ( ) . widgets . active . fg_stroke
690
+ } else if corner_response. hover {
691
+ ui. visuals ( ) . widgets . hovered . fg_stroke
692
+ } else {
693
+ inactive_stroke
694
+ } ;
695
+
686
696
let corner_size = Vec2 :: splat ( ui. visuals ( ) . resize_corner_size ) ;
687
697
let corner_rect = corner. align_size_within_rect ( corner_size, outer_rect) ;
688
698
let corner_rect = corner_rect. translate ( -offset * corner. to_sign ( ) ) ; // move away from corner
@@ -744,6 +754,17 @@ impl SideResponse {
744
754
}
745
755
}
746
756
757
+ impl std:: ops:: BitAnd for SideResponse {
758
+ type Output = Self ;
759
+
760
+ fn bitand ( self , rhs : Self ) -> Self :: Output {
761
+ Self {
762
+ hover : self . hover && rhs. hover ,
763
+ drag : self . drag && rhs. drag ,
764
+ }
765
+ }
766
+ }
767
+
747
768
impl std:: ops:: BitOrAssign for SideResponse {
748
769
fn bitor_assign ( & mut self , rhs : Self ) {
749
770
* self = Self {
@@ -849,7 +870,7 @@ fn resize_interaction(
849
870
} ;
850
871
}
851
872
852
- let is_dragging = |rect, id| {
873
+ let side_response = |rect, id| {
853
874
let response = ctx. create_widget (
854
875
WidgetRect {
855
876
layer_id,
@@ -872,6 +893,12 @@ fn resize_interaction(
872
893
let side_grab_radius = ctx. style ( ) . interaction . resize_grab_radius_side ;
873
894
let corner_grab_radius = ctx. style ( ) . interaction . resize_grab_radius_corner ;
874
895
896
+ let vetrtical_rect = |a : Pos2 , b : Pos2 | {
897
+ Rect :: from_min_max ( a, b) . expand2 ( vec2 ( side_grab_radius, -corner_grab_radius) )
898
+ } ;
899
+ let horizontal_rect = |a : Pos2 , b : Pos2 | {
900
+ Rect :: from_min_max ( a, b) . expand2 ( vec2 ( -corner_grab_radius, side_grab_radius) )
901
+ } ;
875
902
let corner_rect =
876
903
|center : Pos2 | Rect :: from_center_size ( center, Vec2 :: splat ( 2.0 * corner_grab_radius) ) ;
877
904
@@ -882,59 +909,80 @@ fn resize_interaction(
882
909
// Check sides first, so that corners are on top, covering the sides (i.e. corners have priority)
883
910
884
911
if possible. resize_right {
885
- let response = is_dragging (
886
- Rect :: from_min_max ( rect. right_top ( ) , rect. right_bottom ( ) ) . expand ( side_grab_radius ) ,
912
+ let response = side_response (
913
+ vetrtical_rect ( rect. right_top ( ) , rect. right_bottom ( ) ) ,
887
914
id. with ( "right" ) ,
888
915
) ;
889
916
right |= response;
890
917
}
891
918
if possible. resize_left {
892
- let response = is_dragging (
893
- Rect :: from_min_max ( rect. left_top ( ) , rect. left_bottom ( ) ) . expand ( side_grab_radius ) ,
919
+ let response = side_response (
920
+ vetrtical_rect ( rect. left_top ( ) , rect. left_bottom ( ) ) ,
894
921
id. with ( "left" ) ,
895
922
) ;
896
923
left |= response;
897
924
}
898
925
if possible. resize_bottom {
899
- let response = is_dragging (
900
- Rect :: from_min_max ( rect. left_bottom ( ) , rect. right_bottom ( ) ) . expand ( side_grab_radius ) ,
926
+ let response = side_response (
927
+ horizontal_rect ( rect. left_bottom ( ) , rect. right_bottom ( ) ) ,
901
928
id. with ( "bottom" ) ,
902
929
) ;
903
930
bottom |= response;
904
931
}
905
932
if possible. resize_top {
906
- let response = is_dragging (
907
- Rect :: from_min_max ( rect. left_top ( ) , rect. right_top ( ) ) . expand ( side_grab_radius ) ,
933
+ let response = side_response (
934
+ horizontal_rect ( rect. left_top ( ) , rect. right_top ( ) ) ,
908
935
id. with ( "top" ) ,
909
936
) ;
910
937
top |= response;
911
938
}
912
939
913
940
// ----------------------------------------
914
- // Now check corners:
915
-
916
- if possible. resize_right && possible. resize_bottom {
917
- let response = is_dragging ( corner_rect ( rect. right_bottom ( ) ) , id. with ( "right_bottom" ) ) ;
918
- right |= response;
919
- bottom |= response;
941
+ // Now check corners.
942
+ // We check any corner that has either side resizable,
943
+ // because we shrink the side resize handled by the corner width.
944
+ // Also, even if we can only change the width (or height) of a window,
945
+ // we show one of the corners as a grab-handle, so it makes sense that
946
+ // the whole corner is grabbable:
947
+
948
+ if possible. resize_right || possible. resize_bottom {
949
+ let response = side_response ( corner_rect ( rect. right_bottom ( ) ) , id. with ( "right_bottom" ) ) ;
950
+ if possible. resize_right {
951
+ right |= response;
952
+ }
953
+ if possible. resize_bottom {
954
+ bottom |= response;
955
+ }
920
956
}
921
957
922
- if possible. resize_right && possible. resize_top {
923
- let response = is_dragging ( corner_rect ( rect. right_top ( ) ) , id. with ( "right_top" ) ) ;
924
- right |= response;
925
- top |= response;
958
+ if possible. resize_right || possible. resize_top {
959
+ let response = side_response ( corner_rect ( rect. right_top ( ) ) , id. with ( "right_top" ) ) ;
960
+ if possible. resize_right {
961
+ right |= response;
962
+ }
963
+ if possible. resize_top {
964
+ top |= response;
965
+ }
926
966
}
927
967
928
- if possible. resize_left && possible. resize_bottom {
929
- let response = is_dragging ( corner_rect ( rect. left_bottom ( ) ) , id. with ( "left_bottom" ) ) ;
930
- left |= response;
931
- bottom |= response;
968
+ if possible. resize_left || possible. resize_bottom {
969
+ let response = side_response ( corner_rect ( rect. left_bottom ( ) ) , id. with ( "left_bottom" ) ) ;
970
+ if possible. resize_left {
971
+ left |= response;
972
+ }
973
+ if possible. resize_bottom {
974
+ bottom |= response;
975
+ }
932
976
}
933
977
934
- if possible. resize_left && possible. resize_top {
935
- let response = is_dragging ( corner_rect ( rect. left_top ( ) ) , id. with ( "left_top" ) ) ;
936
- left |= response;
937
- top |= response;
978
+ if possible. resize_left || possible. resize_top {
979
+ let response = side_response ( corner_rect ( rect. left_top ( ) ) , id. with ( "left_top" ) ) ;
980
+ if possible. resize_left {
981
+ left |= response;
982
+ }
983
+ if possible. resize_top {
984
+ top |= response;
985
+ }
938
986
}
939
987
940
988
let interaction = ResizeInteraction {
0 commit comments