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

Feature/dsl #461

Merged
merged 5 commits into from
Jul 6, 2019
Merged

Feature/dsl #461

merged 5 commits into from
Jul 6, 2019

Conversation

AllanWang
Copy link
Contributor

@AllanWang AllanWang commented Jun 22, 2019

Resolves #457

This is just an example of kotlin dsl, similar to how materialDrawerKt does it.

Example:

fun Context.example(icon: IIcon) {
    iconicsDrawable(icon) {
        sizeX = sizePx(2)
        sizeY = sizeDp(3)
        val getSizeX = sizeX // Fails; only setting allowed
    }
}

The main difference is that setters are done by var access instead of functions, and variations (eg px, dp, res), are done once and shared, rather than with new functions for each field.

As it stands, if you plan on supporting function variants (sizeDp, sizePx, ...) for all fields, the dsl is not really necessary. However, removing such variations would probably make code suggestions easier.

If you plan on keeping your extensions as is, meaning there aren't shortcuts for each field (eg sizeXDp, sizeXPx), then this might be useful.

Stuff like sizePx can be further shortened to px. It's just that res is shared, so I named it sizeRes and added the prefix everywhere to be consistent

@mikepenz mikepenz self-assigned this Jun 22, 2019
@mikepenz
Copy link
Owner

@mikepenz
Copy link
Owner

This looks really nice. I like the property approach which can only be set. it makes it look really concise.

Right now I think we should keep the extension functions for the fields in the IconicsDrawable too as people might not use the DSL, but convenience wise we should also make the DSL as nice as possible

@AllanWang
Copy link
Contributor Author

You can take a look. I added most of the fields, except for shadows since that seems special.

I'm not sure if it's a performance problem that each change causes an invalidation.

Additionally, if certain configurations should not exist along with each other (eg setting icon to IIcon and then setting iconText), then we might want to have multiple dsls.

For now, the icon is the only conflict I see, so I've added them within the initiating functions as opposed to the DSL.

@mikepenz mikepenz merged commit 23b2ab1 into mikepenz:develop Jul 6, 2019
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.

Kotlin DSL
2 participants