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

Component::applyFallbackStyle helper method #488

Merged
merged 8 commits into from Feb 28, 2022
Merged

Component::applyFallbackStyle helper method #488

merged 8 commits into from Feb 28, 2022

Conversation

rymiel
Copy link
Member

@rymiel rymiel commented Oct 28, 2021

Implements and resolves #486.

EDIT: Method was extensively renamed, see discussion below

Of note: I'm not good with javadocs and the explanation is moot at best, please suggest a better wording to describe this "wrapping" feature.

Also, could there possibly be a default instance method, to allow for mm.wrap(ITALIC.as(false)), or would that be too unclear in its operation?

Copy link
Member

@kezz kezz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final nitpicks :p

api/src/main/java/net/kyori/adventure/text/Component.java Outdated Show resolved Hide resolved
api/src/main/java/net/kyori/adventure/text/Component.java Outdated Show resolved Hide resolved
api/src/main/java/net/kyori/adventure/text/Component.java Outdated Show resolved Hide resolved
@rymiel rymiel requested a review from kezz October 30, 2021 18:25
Copy link
Member

@zml2008 zml2008 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the best solution for this sort of operation. What can this wrap operator do that an appropriate style merge can't do with fewer levels of nesting?

With an alternative API of something like:

interface Component {
  default @NotNull Component applyUnsetStyleFrom(final @NotNull Style /* or StyleBuilderApplicable... */ other) {
    return this.style(this.style().merge(other, Merge.Strategy.IF_ABSENT_ON_TARGET));
  }
}

would there be any limitations compared to this PR? (well, aside from the name)

@kezz
Copy link
Member

kezz commented Dec 22, 2021

Yes, this component wrapping isn't the ideal solution to the problem it solves. However, it is way more intuitive than other solutions. If we can think of a solid name for this apply unset method, I'd be happy to see a PR with that come through too. However, as it stands I think this PR is solid, and introduces a short-hand for a relatively common pattern.

@rymiel
Copy link
Member Author

rymiel commented Feb 14, 2022

Should this PR still be considered for 4.10.0?

@kezz
Copy link
Member

kezz commented Feb 14, 2022

I've changed my mind - I think calling this method wrap is good and clear, but it should be performing a style merge.

Think of the case where someone heads onto webui and makes a non-italic lore item. If a developer wants to make that the default, it would be nice to have this method as a no-op in the case where the user has already made the change, for example.

@rymiel
Copy link
Member Author

rymiel commented Feb 23, 2022

I've made the method perform a style merge as outlined in #488 (review), but now it theoretically no longer contains any "wrapper"s per se, so i'm confused on how to document this, although it accomplishes the same thing

@zml2008
Copy link
Member

zml2008 commented Feb 23, 2022

Component.applyFallbackStyle() maybe?

@kezz
Copy link
Member

kezz commented Feb 24, 2022

Component.applyFallbackStyle() maybe?

Yeah I kiinda like this.

Would this be worth having in StyleSetter instead of Component?

@rymiel rymiel changed the title Component.wrap helper constructor Component::applyFallbackStyle helper method Feb 28, 2022
This was referenced Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add component constructor to "wrap" another component
5 participants