Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the resize cursor when you reach the resize limit #4275

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions crates/egui/src/containers/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ impl SidePanel {

let available_rect = ui.available_rect_before_wrap();
let mut panel_rect = available_rect;
let mut width = default_width;
{
let mut width = default_width;
if let Some(state) = PanelState::load(ui.ctx(), id) {
width = state.rect.width();
}
Expand All @@ -249,9 +249,8 @@ impl SidePanel {

if is_resizing {
if let Some(pointer) = resize_response.interact_pointer_pos() {
let width = (pointer.x - side.side_x(panel_rect)).abs();
let width =
clamp_to_range(width, width_range).at_most(available_rect.width());
width = (pointer.x - side.side_x(panel_rect)).abs();
width = clamp_to_range(width, width_range).at_most(available_rect.width());
side.set_rect_width(&mut panel_rect, width);
}
}
Expand Down Expand Up @@ -296,7 +295,14 @@ impl SidePanel {
}

if resize_hover || is_resizing {
ui.ctx().set_cursor_icon(CursorIcon::ResizeHorizontal);
let cursor_icon = if width <= width_range.min {
CursorIcon::ResizeEast
} else if width < width_range.max {
CursorIcon::ResizeHorizontal
} else {
CursorIcon::ResizeWest
};
ui.ctx().set_cursor_icon(cursor_icon);
}

PanelState { rect }.store(ui.ctx(), id);
Expand Down Expand Up @@ -684,12 +690,13 @@ impl TopBottomPanel {

let available_rect = ui.available_rect_before_wrap();
let mut panel_rect = available_rect;

let mut height = if let Some(state) = PanelState::load(ui.ctx(), id) {
state.rect.height()
} else {
default_height.unwrap_or_else(|| ui.style().spacing.interact_size.y)
};
{
let mut height = if let Some(state) = PanelState::load(ui.ctx(), id) {
state.rect.height()
} else {
default_height.unwrap_or_else(|| ui.style().spacing.interact_size.y)
};
height = clamp_to_range(height, height_range).at_most(available_rect.height());
side.set_rect_height(&mut panel_rect, height);
ui.ctx()
Expand All @@ -707,8 +714,8 @@ impl TopBottomPanel {

if is_resizing {
if let Some(pointer) = resize_response.interact_pointer_pos() {
let height = (pointer.y - side.side_y(panel_rect)).abs();
let height =
height = (pointer.y - side.side_y(panel_rect)).abs();
height =
clamp_to_range(height, height_range).at_most(available_rect.height());
side.set_rect_height(&mut panel_rect, height);
}
Expand Down Expand Up @@ -755,7 +762,14 @@ impl TopBottomPanel {
}

if resize_hover || is_resizing {
ui.ctx().set_cursor_icon(CursorIcon::ResizeVertical);
let cursor_icon = if height <= height_range.min {
CursorIcon::ResizeSouth
} else if height < height_range.max {
CursorIcon::ResizeVertical
} else {
CursorIcon::ResizeNorth
};
ui.ctx().set_cursor_icon(cursor_icon);
}

PanelState { rect }.store(ui.ctx(), id);
Expand Down
1 change: 1 addition & 0 deletions crates/egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ impl ResizeInteraction {
let top = self.top.any();
let bottom = self.bottom.any();

// TODO(emilk): use one-sided cursors for when we reached the min/max size.
if (left && top) || (right && bottom) {
ctx.set_cursor_icon(CursorIcon::ResizeNwSe);
} else if (right && top) || (left && bottom) {
Expand Down
12 changes: 10 additions & 2 deletions crates/egui/src/widgets/drag_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,16 @@ impl<'a> Widget for DragValue<'a> {
.sense(Sense::click_and_drag())
.min_size(ui.spacing().interact_size); // TODO(emilk): find some more generic solution to `min_size`

let cursor_icon = if value <= *clamp_range.start() {
CursorIcon::ResizeEast
} else if value < *clamp_range.end() {
CursorIcon::ResizeHorizontal
} else {
CursorIcon::ResizeWest
};

let response = ui.add(button);
let mut response = response.on_hover_cursor(CursorIcon::ResizeHorizontal);
let mut response = response.on_hover_cursor(cursor_icon);

if ui.style().explanation_tooltips {
response = response.on_hover_text(format!(
Expand All @@ -552,7 +560,7 @@ impl<'a> Widget for DragValue<'a> {
)));
state.store(ui.ctx(), response.id);
} else if response.dragged() {
ui.ctx().set_cursor_icon(CursorIcon::ResizeHorizontal);
ui.ctx().set_cursor_icon(cursor_icon);

let mdelta = response.drag_delta();
let delta_points = mdelta.x - mdelta.y; // Increase to the right and up
Expand Down
Loading