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

Fluent API on components #78

Closed
Juke1999 opened this issue Jul 16, 2021 · 5 comments
Closed

Fluent API on components #78

Juke1999 opened this issue Jul 16, 2021 · 5 comments
Labels
enhancement New feature or request staging Changes available on staging branch

Comments

@Juke1999
Copy link

It would be great to have the possibility to use Java's fluent API on all components. If you create a button, you won't have to do:

MFXButton loginButton = new MFXButton();

loginButton.setText("Login");
loginButton.setGraphic(new FontIcon("fas-sign-in-alt"));
loginButton.setButtonType(ButtonType.RAISED);
loginButton.setTranslateY(50);
loginButton.setGraphicTextGap(10);
loginButton.getStyleClass().add("some-class");

but instead:

MFXButton loginButton = new MFXButton()
    .setText("Login")
    .setGraphic(new FontIcon("fas-sign-in-alt"))
    .setButtonType(ButtonType.RAISED)
    .setTranslateY(50)
    .setGraphicTextGap(10)
    .getStyleClass().add("some-class");

This would make the code cleaner and the creation of new elements a lot easier.

@palexdev
Copy link
Owner

Fluent API is more suitable for builders
Using it everywhere would be an anti-pattern
What do you think of a ComponentBuilder which gives instances of other builders for each component, for example:

ComponentBuilder.getButtonBuilder()
        .setText(...)
        .setGraphic(...)
        and so on...

ComponentBuilder.getCheckboxBuilder()
        .setText(...)
       .setSelected(...)
       and so on...

This way would be more clean, but still, a lot of code to write for each component

@Juke1999
Copy link
Author

That should work, indeed.
It was just a suggestion, it more or less works like your code too, that's true.

@palexdev
Copy link
Owner

I'm going to mark this as enhancement then
Hope to get it done for the next version

@palexdev palexdev added the enhancement New feature or request label Jul 17, 2021
palexdev added a commit that referenced this issue Feb 3, 2022
…s, as requested by #78

Signed-off-by: palexdev <alessandro.parisi406@gmail.com>
@palexdev
Copy link
Owner

palexdev commented Feb 3, 2022

Available on staging branch
Hope I didn't forgot anything and that the API is convenient enough

@palexdev palexdev added the staging Changes available on staging branch label Feb 3, 2022
@palexdev
Copy link
Owner

palexdev commented Feb 9, 2022

API available in the latest release

@palexdev palexdev closed this as completed Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request staging Changes available on staging branch
Projects
None yet
Development

No branches or pull requests

2 participants