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

Fix: ScrollArea repeatedly appears and disappears quickly issue. #4658

Closed
wants to merge 7 commits into from
Closed
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
51 changes: 24 additions & 27 deletions crates/egui/src/containers/scroll_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,16 +963,30 @@ impl Prepared {
let inner_margin = show_factor * scroll_style.bar_inner_margin;
let outer_margin = show_factor * scroll_style.bar_outer_margin;

let mut max_cross = outer_rect.max[1 - d] - outer_margin;
if ui.clip_rect().max[1 - d] < max_cross + outer_margin {
// Move the scrollbar so it is visible. This is needed in some cases.
// For instance:
// * When we have a vertical-only scroll area in a top level panel,
// and that panel is not wide enough for the contents.
// * When one ScrollArea is nested inside another, and the outer
// is scrolled so that the scroll-bars of the inner ScrollArea (us)
// is outside the clip rectangle.
// Really this should use the tighter clip_rect that ignores clip_rect_margin, but we don't store that.
// clip_rect_margin is quite a hack. It would be nice to get rid of it.
max_cross = ui.clip_rect().max[1 - d] - outer_margin;
}

// top/bottom of a horizontal scroll (d==0).
// left/rigth of a vertical scroll (d==1).
let mut cross = if scroll_style.floating {
let cross = if scroll_style.floating {
let max_bar_rect = if d == 0 {
outer_rect.with_min_y(outer_rect.max.y - scroll_style.allocated_width())
outer_rect.with_min_y(max_cross - scroll_style.bar_width)
} else {
outer_rect.with_min_x(outer_rect.max.x - scroll_style.allocated_width())
outer_rect.with_min_x(max_cross - scroll_style.bar_width)
};
let is_hovering_bar_area = is_hovering_outer_rect
&& ui.rect_contains_pointer(max_bar_rect)
let is_hovering_bar_area = (is_hovering_outer_rect
&& ui.rect_contains_pointer(max_bar_rect))
|| state.scroll_bar_interaction[d];
let is_hovering_bar_area_t = ui
.ctx()
Expand All @@ -983,39 +997,22 @@ impl Prepared {
is_hovering_bar_area_t,
);

let max_cross = outer_rect.max[1 - d] - outer_margin;
let min_cross = max_cross - width;
Rangef::new(min_cross, max_cross)
} else {
let min_cross = inner_rect.max[1 - d] + inner_margin;
let max_cross = outer_rect.max[1 - d] - outer_margin;
let min_cross = max_cross - scroll_style.bar_width;
Rangef::new(min_cross, max_cross)
};

if ui.clip_rect().max[1 - d] < cross.max + outer_margin {
// Move the scrollbar so it is visible. This is needed in some cases.
// For instance:
// * When we have a vertical-only scroll area in a top level panel,
// and that panel is not wide enough for the contents.
// * When one ScrollArea is nested inside another, and the outer
// is scrolled so that the scroll-bars of the inner ScrollArea (us)
// is outside the clip rectangle.
// Really this should use the tighter clip_rect that ignores clip_rect_margin, but we don't store that.
// clip_rect_margin is quite a hack. It would be nice to get rid of it.
let width = cross.max - cross.min;
cross.max = ui.clip_rect().max[1 - d] - outer_margin;
cross.min = cross.max - width;
}

let outer_scroll_rect = if d == 0 {
Rect::from_min_max(
pos2(inner_rect.left(), cross.min),
pos2(inner_rect.right(), cross.max),
pos2(inner_rect.left(), cross.min - inner_margin),
pos2(inner_rect.right(), cross.max + outer_margin),
)
} else {
Rect::from_min_max(
pos2(cross.min, inner_rect.top()),
pos2(cross.max, inner_rect.bottom()),
pos2(cross.min - inner_margin, inner_rect.top()),
pos2(cross.max + outer_margin, inner_rect.bottom()),
)
};

Expand Down
18 changes: 9 additions & 9 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ pub struct ScrollStyle {
/// When the user hovers the scroll bars they expand to [`Self::bar_width`].
pub floating_width: f32,

/// How much space i allocated for a floating scroll bar?
/// How much space is allocated for a floating scroll bar?
///
/// Normally this is zero, but you could set this to something small
/// like 4.0 and set [`Self::dormant_handle_opacity`] and
Expand Down Expand Up @@ -499,7 +499,7 @@ impl ScrollStyle {
active_background_opacity: 1.0,
active_handle_opacity: 1.0,

// Be tranlucent when expanded so we can see the content
// Be translucent when expanded so we can see the content
interact_background_opacity: 0.6,
interact_handle_opacity: 0.6,

Expand All @@ -514,6 +514,7 @@ impl ScrollStyle {
Self {
floating: true,
bar_width: 10.0,
bar_inner_margin: 0.0,
foreground_color: true,
floating_allocated_width: 0.0,
dormant_background_opacity: 0.0,
Expand Down Expand Up @@ -589,6 +590,10 @@ impl ScrollStyle {
ui.add(DragValue::new(handle_min_length).clamp_range(0.0..=32.0));
ui.label("Minimum handle length");
});
ui.horizontal(|ui| {
ui.add(DragValue::new(bar_inner_margin).clamp_range(0.0..=32.0));
ui.label("Inner margin");
});
ui.horizontal(|ui| {
ui.add(DragValue::new(bar_outer_margin).clamp_range(0.0..=32.0));
ui.label("Outer margin");
Expand Down Expand Up @@ -624,11 +629,6 @@ impl ScrollStyle {
opacity_ui(ui, interact_handle_opacity);
ui.end_row();
});
} else {
ui.horizontal(|ui| {
ui.add(DragValue::new(bar_inner_margin).clamp_range(0.0..=32.0));
ui.label("Inner margin");
});
}
}
}
Expand All @@ -652,7 +652,7 @@ pub struct Interaction {
/// Radius of the interactive area of the corner of a window during drag-to-resize.
pub resize_grab_radius_corner: f32,

/// If `false`, tooltips will show up anytime you hover anything, even is mouse is still moving
/// If `false`, tooltips will show up anytime you hover anything, even if mouse is still moving
pub show_tooltips_only_when_still: bool,

/// Delay in seconds before showing tooltips after the mouse stops moving
Expand Down Expand Up @@ -2118,7 +2118,7 @@ impl HandleShape {
pub enum NumericColorSpace {
/// RGB is 0-255 in gamma space.
///
/// Alpha is 0-255 in linear space .
/// Alpha is 0-255 in linear space.
GammaByte,

/// 0-1 in linear space.
Expand Down
Loading