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 isHovered bounds calculation #397

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

fix isHovered bounds calculation #397

wants to merge 1 commit into from

Conversation

sl33nyc
Copy link

@sl33nyc sl33nyc commented Apr 28, 2024

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

@Aylur
Copy link
Owner

Aylur commented Apr 29, 2024

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

@sl33nyc sl33nyc changed the title fix isHover bounds calculation fix isHovered bounds calculation Apr 29, 2024
@sl33nyc
Copy link
Author

sl33nyc commented May 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Widgets stay hovered when mouse leaves
2 participants