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

Add functional utilities for styles that need numbers #94

Open
JoshKarpel opened this issue Jan 8, 2024 · 0 comments
Open

Add functional utilities for styles that need numbers #94

JoshKarpel opened this issue Jan 8, 2024 · 0 comments
Labels
enhancement New feature or request styles

Comments

@JoshKarpel
Copy link
Owner

JoshKarpel commented Jan 8, 2024

We recently added utilities for positioning that are functions

def relative(x: int = 0, y: int = 0) -> Style:
    return Style(layout=Flex(position=Relative(x=x, y=y)))


def absolute(x: int = 0, y: int = 0) -> Style:
    return Style(layout=Flex(position=Absolute(x=x, y=y)))


def fixed(x: int = 0, y: int = 0) -> Style:
    return Style(layout=Flex(position=Fixed(x=x, y=y)))

We also have older utilities like

gap_children_0 = Style(layout=Flex(gap_children=0))
gap_children_1 = Style(layout=Flex(gap_children=1))
gap_children_2 = Style(layout=Flex(gap_children=2))
gap_children_3 = Style(layout=Flex(gap_children=3))
gap_children_4 = Style(layout=Flex(gap_children=4))
gap_children_5 = Style(layout=Flex(gap_children=5))
gap_children_6 = Style(layout=Flex(gap_children=6))
gap_children_7 = Style(layout=Flex(gap_children=7))
gap_children_8 = Style(layout=Flex(gap_children=8))

These are convenient for small, common numbers, but we should also have

def gap_children(n: int) -> Style:
    return Style(layout=Flex(gap_children=n))

There are a variety of utilities that end with a trailing number, and each should probably have a functional variant as well.

Also, all functional utilities should be cached, so that we re-use Style objects as much as possible (helps style merge caching).

@JoshKarpel JoshKarpel added enhancement New feature or request styles labels Jan 8, 2024
@JoshKarpel JoshKarpel changed the title Function utilities for styles that need numbers Add functional utilities for styles that need numbers Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request styles
Projects
None yet
Development

No branches or pull requests

1 participant