Skip to content

Commit b9cd31b

Browse files
committed
Highlight resize-corner when hovered
1 parent 127acd0 commit b9cd31b

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

crates/egui/src/containers/window.rs

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ impl<'open> Window<'open> {
583583
outer_rect,
584584
frame_stroke,
585585
window_frame.rounding,
586+
resize_interaction,
586587
);
587588

588589
// END FRAME --------------------------------
@@ -651,29 +652,30 @@ fn paint_resize_corner(
651652
outer_rect: Rect,
652653
stroke: impl Into<Stroke>,
653654
rounding: impl Into<Rounding>,
655+
i: ResizeInteraction,
654656
) {
655-
let stroke = stroke.into();
657+
let inactive_stroke = stroke.into();
656658
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)
659661
} else if possible.resize_left && possible.resize_bottom {
660-
(Align2::LEFT_BOTTOM, rounding.sw)
662+
(Align2::LEFT_BOTTOM, rounding.sw, i.left & i.bottom)
661663
} else if possible.resize_left && possible.resize_top {
662-
(Align2::LEFT_TOP, rounding.nw)
664+
(Align2::LEFT_TOP, rounding.nw, i.left & i.top)
663665
} else if possible.resize_right && possible.resize_top {
664-
(Align2::RIGHT_TOP, rounding.ne)
666+
(Align2::RIGHT_TOP, rounding.ne, i.right & i.top)
665667
} else {
666668
// We're not in two directions, but it is still nice to tell the user
667669
// we're resizable by painting the resize corner in the expected place
668670
// (i.e. for windows only resizable in one direction):
669671
if possible.resize_right || possible.resize_bottom {
670-
(Align2::RIGHT_BOTTOM, rounding.se)
672+
(Align2::RIGHT_BOTTOM, rounding.se, i.right & i.bottom)
671673
} else if possible.resize_left || possible.resize_bottom {
672-
(Align2::LEFT_BOTTOM, rounding.sw)
674+
(Align2::LEFT_BOTTOM, rounding.sw, i.left & i.bottom)
673675
} else if possible.resize_left || possible.resize_top {
674-
(Align2::LEFT_TOP, rounding.nw)
676+
(Align2::LEFT_TOP, rounding.nw, i.left & i.top)
675677
} else if possible.resize_right || possible.resize_top {
676-
(Align2::RIGHT_TOP, rounding.ne)
678+
(Align2::RIGHT_TOP, rounding.ne, i.right & i.top)
677679
} else {
678680
return;
679681
}
@@ -683,6 +685,14 @@ fn paint_resize_corner(
683685
let offset =
684686
((2.0_f32.sqrt() * (1.0 + radius) - radius) * 45.0_f32.to_radians().cos()).max(2.0);
685687

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+
686696
let corner_size = Vec2::splat(ui.visuals().resize_corner_size);
687697
let corner_rect = corner.align_size_within_rect(corner_size, outer_rect);
688698
let corner_rect = corner_rect.translate(-offset * corner.to_sign()); // move away from corner
@@ -744,6 +754,17 @@ impl SideResponse {
744754
}
745755
}
746756

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+
747768
impl std::ops::BitOrAssign for SideResponse {
748769
fn bitor_assign(&mut self, rhs: Self) {
749770
*self = Self {
@@ -927,41 +948,41 @@ fn resize_interaction(
927948
if possible.resize_right || possible.resize_bottom {
928949
let response = side_response(corner_rect(rect.right_bottom()), id.with("right_bottom"));
929950
if possible.resize_right {
930-
right |= response;
951+
right |= response;
931952
}
932953
if possible.resize_bottom {
933-
bottom |= response;
934-
}
954+
bottom |= response;
955+
}
935956
}
936957

937958
if possible.resize_right || possible.resize_top {
938959
let response = side_response(corner_rect(rect.right_top()), id.with("right_top"));
939960
if possible.resize_right {
940-
right |= response;
961+
right |= response;
941962
}
942963
if possible.resize_top {
943-
top |= response;
944-
}
964+
top |= response;
965+
}
945966
}
946967

947968
if possible.resize_left || possible.resize_bottom {
948969
let response = side_response(corner_rect(rect.left_bottom()), id.with("left_bottom"));
949970
if possible.resize_left {
950-
left |= response;
971+
left |= response;
951972
}
952973
if possible.resize_bottom {
953-
bottom |= response;
954-
}
974+
bottom |= response;
975+
}
955976
}
956977

957978
if possible.resize_left || possible.resize_top {
958979
let response = side_response(corner_rect(rect.left_top()), id.with("left_top"));
959980
if possible.resize_left {
960-
left |= response;
981+
left |= response;
961982
}
962983
if possible.resize_top {
963-
top |= response;
964-
}
984+
top |= response;
985+
}
965986
}
966987

967988
let interaction = ResizeInteraction {

0 commit comments

Comments
 (0)