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

Message spoilers #175

Closed
wants to merge 2 commits into from
Closed

Message spoilers #175

wants to merge 2 commits into from

Conversation

tfuxu
Copy link
Contributor

@tfuxu tfuxu commented Oct 11, 2023

This PR implements custom Spoiler widget used as a overlay on messages wrapped in || tags.

Note: Putting this as a draft for now, as there are a couple MarkdownViewer bugs that needs to be fixed beforehand, and the current spoiler style definitely needs some polishing.

Fixes #152

TODO:

  • Make spoiler overlay the same size as the message text
  • Refine spoiler style

Screenshots:

Simple message hidden:

Screenshot from 2023-10-11 19-24-18

Simple message visible:

Screenshot from 2023-10-11 19-25-43

Textblock/multi-line message hidden:

Screenshot from 2023-10-11 19-24-30

tfuxu added 2 commits October 3, 2023 20:50
This commit adds a Spoiler widget, and spoiler support for standard Markdown elements
@diamondburned
Copy link
Owner

Does this not work for inline spoiler tags, e.g. hello ||world||?

@tfuxu
Copy link
Contributor Author

tfuxu commented Oct 12, 2023

Does this not work for inline spoiler tags, e.g. hello ||world||?

Ah, I completely forgot about this 🤦‍♂️️ I'll think of another solution for this, since the overlay probably isn't as flexible to put only on a specific section of the message (at least not with the current implementation).

@diamondburned
Copy link
Owner

diamondburned commented Oct 12, 2023

You can use a hover/tap EventController combined with method.TextView.get_iter_at_position and method.TextView.window_to_buffer_coords to obtain the character mark at the hovering point, then check if it has a spoiler tag and set its opacity to 1 if there is any.

You'll also need to keep a last spoiler tag:

var lastSpoilerTag *gtk.TextTag
func(spoilerTag *gtk.TextTag) { // callback
    if lastSpoilerTag == spoilerTag {
        return
    }

    if lastSpoilerTag != nil {
        lastSpoilerTag.SetProperty("opacity", 0)
    }

    spoilerTag.SetProperty("opacity", 1)
}

@diamondburned
Copy link
Owner

Partially implemented in a52c614.

@tfuxu
Copy link
Contributor Author

tfuxu commented Jun 16, 2024

Cool! Closing as there is a new solution implemented. I've also created a tracking issue for currently unsupported types of spoilers #282

@tfuxu tfuxu closed this Jun 16, 2024
@tfuxu tfuxu deleted the message-spoiler branch June 16, 2024 20:58
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.

Implement message spoilers
2 participants