Handle different item_spacings when doing hover detection

This commit is contained in:
Emil Ernerfeldt 2020-12-13 00:40:19 +01:00
parent 6ff39d88bf
commit bd192a0374
3 changed files with 12 additions and 3 deletions

View file

@ -179,6 +179,7 @@ impl Prepared {
let move_response = ctx.interact( let move_response = ctx.interact(
layer_id, layer_id,
Rect::everything(), Rect::everything(),
ctx.style().spacing.item_spacing,
state.rect(), state.rect(),
interact_id, interact_id,
Sense::click_and_drag(), Sense::click_and_drag(),

View file

@ -427,11 +427,12 @@ impl Context {
self: &Arc<Self>, self: &Arc<Self>,
layer_id: LayerId, layer_id: LayerId,
clip_rect: Rect, clip_rect: Rect,
item_spacing: Vec2,
rect: Rect, rect: Rect,
id: Option<Id>, id: Option<Id>,
sense: Sense, sense: Sense,
) -> Response { ) -> Response {
let interact_rect = rect.expand2(0.5 * self.style().spacing.item_spacing); // make it easier to click. TODO: nice way to do this let interact_rect = rect.expand2((0.5 * item_spacing).min(Vec2::splat(5.0))); // make it easier to click
let hovered = self.contains_mouse(layer_id, clip_rect, interact_rect); let hovered = self.contains_mouse(layer_id, clip_rect, interact_rect);
let has_kb_focus = id.map(|id| self.memory().has_kb_focus(id)).unwrap_or(false); let has_kb_focus = id.map(|id| self.memory().has_kb_focus(id)).unwrap_or(false);

View file

@ -372,14 +372,21 @@ impl Ui {
/// # Interaction /// # Interaction
impl Ui { impl Ui {
pub fn interact(&self, rect: Rect, id: Id, sense: Sense) -> Response { pub fn interact(&self, rect: Rect, id: Id, sense: Sense) -> Response {
self.ctx() self.ctx().interact(
.interact(self.layer_id(), self.clip_rect(), rect, Some(id), sense) self.layer_id(),
self.clip_rect(),
self.style().spacing.item_spacing,
rect,
Some(id),
sense,
)
} }
pub fn interact_hover(&self, rect: Rect) -> Response { pub fn interact_hover(&self, rect: Rect) -> Response {
self.ctx().interact( self.ctx().interact(
self.layer_id(), self.layer_id(),
self.clip_rect(), self.clip_rect(),
self.style().spacing.item_spacing,
rect, rect,
None, None,
Sense::nothing(), Sense::nothing(),