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

Improve tooltip #86

Open
Moosems opened this issue Jul 4, 2022 · 2 comments
Open

Improve tooltip #86

Moosems opened this issue Jul 4, 2022 · 2 comments
Milestone

Comments

@Moosems
Copy link
Collaborator

Moosems commented Jul 4, 2022

Tooltip has some issues on Mac and I have some ideas. First and foremost is the usage of the toplevel:

  1. On mac this makes quite a weird illusion and looks pretty bad. I recommend that we use the button idea and that we just position and un-position as it was initially. My picture of the issue is attached.
  2. I believe that the time for scheduling should be halved to 500 ms instead of a whole second. I also removed the schedule to remove the tooltip after a set time because it seems like it could lead to issues for large amounts of text.
  3. Using newlines makes it look janky because its not an actual button. Image is attached
  4. Users should be able to specify which side the tooltip goes too and I think it would be good if the tooltip keeps the same theming
  5. Make sure that the tooltip keeps the font of the owner widget

Proposed code:

    @classmethod
    def schedule(cls, widget: str) -> None:
        cls._can_show = True

        message = cls._widgets.get(widget)
        if message is None:
            return

        Tcl.call(None, ".tooltip.label", "configure", "-text", message)
        cls._after_id = Tcl.call(str, "after", 500, cls._show_cmd, widget)


    @classmethod
    def show(cls, widget: str) -> None:
        if not cls._can_show:
            return

        owner_x = Tcl.call(int, "winfo", "rootx", widget)
        owner_width = Tcl.call(int, "winfo", "reqwidth", widget)
        tip_width = Tcl.call(int, "winfo", "reqwidth", ".tooltip")
        tip_x = owner_x + owner_width // 2 - tip_width // 2

        owner_y = Tcl.call(int, "winfo", "rooty", widget)
        tip_height = Tcl.call(int, "winfo", "reqheight", ".tooltip")
        tip_y = owner_y - tip_height - 5

        if tip_y <= Tcl.eval(int, f"winfo rooty [winfo toplevel {widget}]"):
            tip_y = owner_y + Tcl.call(int, "winfo", "reqheight", widget) + 5

        Tcl.call(None, "wm", "geometry", ".tooltip", f"+{tip_x}+{tip_y}")
        Tcl.call(None, "wm", "deiconify", ".tooltip")

Images:

  1. Screen Shot 2022-07-03 at 9 24 37 PM

2 . Screen Shot 2022-07-03 at 9 38 19 PM

@rdbende rdbende changed the title Tooltip issues/ideas Improve tooltip Jul 5, 2022
@rdbende
Copy link
Member

rdbende commented Jul 5, 2022

TODO

  • Reduce default tooltip delay
  • Intelligently set delay before disappearance
  • Fix newline problem with Aqua theme
  • Make sure it doesn't go off-screen
  • Specify position of the tooltip (global configuration, through the TooltipProvider class)
  • Make sure it looks right with any theme

@rdbende
Copy link
Member

rdbende commented Oct 31, 2022

image

@rdbende rdbende modified the milestones: 1.0.0, 0.2.0 Nov 2, 2022
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

No branches or pull requests

2 participants