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

Page.design property #2607

Merged
merged 10 commits into from
Feb 13, 2024
Merged

Page.design property #2607

merged 10 commits into from
Feb 13, 2024

Conversation

FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented Feb 12, 2024

Close #2588

Test code:

import logging

import flet as ft

# logging.basicConfig(level=logging.DEBUG)


def main(page):
    page.appbar = ft.CupertinoAppBar(
        leading=ft.TextButton("Edit"),
        middle=ft.Text("Some sample settings"),
        trailing=ft.CupertinoButton(ft.Icon(ft.cupertino_icons.ADD), padding=0),
        bgcolor=ft.colors.with_opacity(0.04, ft.cupertino_colors.SYSTEM_BACKGROUND),
    )

    page.navigation_bar = ft.NavigationBar(
        destinations=[
            ft.NavigationDestination(icon=ft.icons.EXPLORE, label="Explore"),
            ft.NavigationDestination(icon=ft.icons.COMMUTE, label="Commute"),
            ft.NavigationDestination(
                icon=ft.icons.BOOKMARK_BORDER,
                selected_icon=ft.icons.BOOKMARK,
                label="Explore",
            ),
        ],
        # bgcolor=ft.colors.with_opacity(0.1, ft.cupertino_colors.SYSTEM_GREY2),
    )

    page.window_width = 393
    page.window_height = 700
    page.theme_mode = ft.ThemeMode.LIGHT
    page.design = ft.PageDesign.ADAPTIVE
    page.theme = ft.Theme(
        color_scheme_seed=ft.colors.YELLOW,
        scrollbar_theme=ft.ScrollbarTheme(thumb_visibility=True, thickness=0),
    )
    # page.theme = ft.Theme(color_scheme=ft.ColorScheme(primary=ft.colors.BLUE))
    # page.bgcolor = ft.colors.YELLOW

    def dark_light_mode_changed(e):
        if page.theme_mode == ft.ThemeMode.LIGHT:
            page.theme_mode = ft.ThemeMode.DARK
        else:
            page.theme_mode = ft.ThemeMode.LIGHT
        page.update()

    dark_mode_checkbox = ft.Checkbox(
        value=False, label="Dark Mode", on_change=dark_light_mode_changed
    )

    print("Media:", page.media)
    page.on_media_change = lambda e: print("Page media changed:", e)
    page.on_resize = lambda e: print("Page resize:", page.width, page.height)

    # page.padding = 0
    page.scroll = ft.ScrollMode.ADAPTIVE
    page.padding = ft.padding.only(left=10, right=10)
    page.add(
        ft.SafeArea(
            ft.Column(
                [
                    ft.Text("Line longer than others", size=20),
                    ft.Text("Line 2"),
                    ft.Text("Line 3"),
                    dark_mode_checkbox,
                    ft.Switch(label="Something"),
                    ft.FilledButton(content=ft.Text("Just a button")),
                    ft.TextField(keyboard_type=ft.KeyboardType.TEXT),
                    ft.Text("Line 4"),
                    ft.Text("Line 3"),
                    ft.Text("Line 3"),
                    ft.Text("Line 3"),
                    ft.Text("Line 3"),
                    ft.Text("Line 3"),
                    ft.Text("Line 4"),
                    ft.Text("Line 30"),
                    ft.Text("Line 3"),
                    ft.Text("Line 3"),
                    ft.Text("Line 3"),
                    ft.Text("Line 4"),
                    ft.Text("Line 30"),
                    ft.Text("Line 3"),
                    ft.Text("Line 4"),
                    ft.Text("Line 3"),
                    ft.Text("Line 3"),
                    ft.Text("Line 3"),
                    ft.Text("Line 3"),
                    ft.Text("Line 3"),
                    ft.Text("Line 4"),
                    ft.Text("Line 30"),
                    ft.Text("Line 3"),
                    ft.Text("Line 3"),
                    ft.Text("Line 3"),
                    ft.Text("Line 4"),
                    ft.Text("Line 30"),
                    ft.Text("Line 3"),
                ]
            )
        )
    )


ft.app(target=main)

@FeodorFitsner FeodorFitsner merged commit 24b8004 into main Feb 13, 2024
2 checks passed
@FeodorFitsner FeodorFitsner deleted the page-design branch February 13, 2024 03:35
zrr1999 pushed a commit to zrr1999/flet that referenced this pull request Jul 17, 2024
* Introduced page.design, added adaptive to some controls

* parseCupertinoTheme()

* Page.design complete

* Pagelet.design

* Fix page theme

* Cleanup

* Use CupertinoApp and figured out theme overrides

* `page.media` property and `page.on_media_change` event (flet-dev#2613)

* `page.media` property and `page.on_media_change` event

* Cleanup

* Replace `PageMediaInsetsData` with `Padding`

* Updated changelog for 0.20.0
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.

Create page.design property with values Material (default), Cupertino, Adaptive
1 participant