ags icon indicating copy to clipboard operation
ags copied to clipboard

fix isHovered bounds calculation

Open sl33nyc opened this issue 1 year ago • 2 comments

This should fix #372. Is isHovered() even necessary?

sl33nyc avatar Apr 28 '24 16:04 sl33nyc

isHovered() is a fix for nested eventboxes, see this example

const { Window, Box, EventBox, Label } = Widget
const hovered1 = "background-color: red"
const hovered2 = "background-color: blue"
const nonhovered = "background-color: transparent"

const _with = Box({
  css: "margin: 10px;",
  child: EventBox({
    on_hover: self => self.css = hovered1,
    on_hover_lost: self => self.css = nonhovered,
    child: Box({
      css: "padding: 20px;",
      child: EventBox({
        on_hover: self => self.css = hovered2,
        on_hover_lost: self => self.css = nonhovered,
        child: Box({
          css: "padding: 20px;",
          child: Label("with")
        })
      })
    })
  })
})

const _without = Box({
  css: "margin: 10px;",
  child: EventBox({
    setup: self => self
      .on('leave-notify-event', () => self.css = hovered1)
      .on('enter-notify-event', () => self.css = nonhovered),
    child: Box({
      css: "padding: 20px;",
      child: EventBox({
        setup: self => self
          .on('leave-notify-event', () => self.css = hovered2)
          .on('enter-notify-event', () => self.css = nonhovered),
        child: Box({
          css: "padding: 20px;",
          child: Label("without")
        })
      })
    })
  })
})

Window({
  child: Box([_with, _without])
})

and this PR breaks this fix

Aylur avatar Apr 29 '24 11:04 Aylur

Ahh, I get what you're going after. BTW, for _without, the leave => hovered[12] and enter => nonhovered seemed flipped. For _without, you're expecting the onHover and onHoverLost to passthrough from the top-most box to the bottom one. However, Gtk carves out the intersection area, so only the topmost box's hover is respected.

I haven't had a chance to rework your example, but would it be more reasonable to use an Overlay instead? I don't know the equivalent of "zIndex" is in GTK, but I would hope that it works for your use case. Then, AGS wouldn't have to overlay "is my pointer in the region of interest" logic for hover purposes when I'd expect GTK to handle for you.

sl33nyc avatar May 03 '24 12:05 sl33nyc

its fixed in v2!

Aylur avatar Nov 13 '24 22:11 Aylur