Add View.shader and move decoration Container behind the main content#6123
Open
bl1nch wants to merge 1 commit intoflet-dev:mainfrom
Open
Add View.shader and move decoration Container behind the main content#6123bl1nch wants to merge 1 commit intoflet-dev:mainfrom
bl1nch wants to merge 1 commit intoflet-dev:mainfrom
Conversation
Contributor
|
Can you please share code example to best see the effect of your addition/usecase? |
Contributor
Author
# Base app
import flet as ft
async def before_main(page: ft.Page):
container = ft.Container(
width=500,
height=300,
bgcolor=ft.Colors.SURFACE_CONTAINER,
alignment=ft.Alignment.CENTER,
border_radius=15,
content=ft.Text(
value="Hello World!",
size=26,
weight=ft.FontWeight.W_600,
),
)
view = ft.View(
route="/",
bgcolor=ft.Colors.TRANSPARENT,
vertical_alignment=ft.MainAxisAlignment.CENTER,
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
controls=[container],
)
view.decoration = ft.BoxDecoration(
image=ft.DecorationImage(
src="https://fedoraproject.org/w/uploads/d/de/F34_default_wallpaper_night.jpg",
fit=ft.BoxFit.COVER,
),
)
page.views.clear()
page.views.append(view)
async def main(page: ft.Page):
pass
ft.run(main, before_main=before_main)
# Image is rendering on top of gradient
import flet as ft
async def before_main(page: ft.Page):
container = ft.Container(
width=500,
height=300,
bgcolor=ft.Colors.SURFACE_CONTAINER,
alignment=ft.Alignment.CENTER,
border_radius=15,
content=ft.Text(
value="Hello World!",
size=26,
weight=ft.FontWeight.W_600,
),
)
view = ft.View(
route="/",
bgcolor=ft.Colors.TRANSPARENT,
vertical_alignment=ft.MainAxisAlignment.CENTER,
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
controls=[container],
)
view.decoration = ft.BoxDecoration(
image=ft.DecorationImage(
src="https://fedoraproject.org/w/uploads/d/de/F34_default_wallpaper_night.jpg",
fit=ft.BoxFit.COVER,
),
gradient=ft.RadialGradient(
colors=[
ft.Colors.TRANSPARENT,
ft.Colors.with_opacity(0.9, ft.Colors.RED)
],
stops=[0.1, 1.0],
radius=1,
),
)
page.views.clear()
page.views.append(view)
async def main(page: ft.Page):
pass
ft.run(main, before_main=before_main)
# Gradient is rendering on top of main content (in current flet version)
# Main content is rendering on top of gradient (with PR)
import flet as ft
async def before_main(page: ft.Page):
page.theme_mode = ft.ThemeMode.LIGHT
container = ft.Container(
width=500,
height=300,
bgcolor=ft.Colors.SURFACE_CONTAINER,
alignment=ft.Alignment.CENTER,
border_radius=15,
content=ft.Text(
value="Hello World!",
size=26,
weight=ft.FontWeight.W_600,
),
)
view = ft.View(
route="/",
bgcolor=ft.Colors.TRANSPARENT,
vertical_alignment=ft.MainAxisAlignment.CENTER,
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
controls=[container],
)
view.decoration = ft.BoxDecoration(
image=ft.DecorationImage(
src="https://fedoraproject.org/w/uploads/d/de/F34_default_wallpaper_night.jpg",
fit=ft.BoxFit.COVER,
),
)
view.foreground_decoration = ft.BoxDecoration(
gradient=ft.RadialGradient(
colors=[
ft.Colors.TRANSPARENT,
ft.Colors.with_opacity(0.9, ft.Colors.RED)
],
stops=[0.1, 1.0],
radius=1,
),
)
page.views.clear()
page.views.append(view)
async def main(page: ft.Page):
pass
ft.run(main, before_main=before_main)
# Gradient is rendering on top of main content (with PR)
# (Use View.shader for previous behavior instead of View.foreground_decoration)
import flet as ft
async def before_main(page: ft.Page):
page.theme_mode = ft.ThemeMode.LIGHT
container = ft.Container(
width=500,
height=300,
bgcolor=ft.Colors.SURFACE_CONTAINER,
alignment=ft.Alignment.CENTER,
border_radius=15,
content=ft.Text(
value="Hello World!",
size=26,
weight=ft.FontWeight.W_600,
),
)
view = ft.View(
route="/",
bgcolor=ft.Colors.TRANSPARENT,
vertical_alignment=ft.MainAxisAlignment.CENTER,
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
controls=[container],
)
view.decoration = ft.BoxDecoration(
image=ft.DecorationImage(
src="https://fedoraproject.org/w/uploads/d/de/F34_default_wallpaper_night.jpg",
fit=ft.BoxFit.COVER,
),
)
view.shader = ft.RadialGradient(
colors=[
ft.Colors.TRANSPARENT,
ft.Colors.with_opacity(0.9, ft.Colors.RED)
],
stops=[0.1, 1.0],
radius=1,
)
page.views.clear()
page.views.append(view)
async def main(page: ft.Page):
pass
ft.run(main, before_main=before_main) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
Viewrendering order has been updated so thedecoration containeris moved to the background and is now rendered fully behind the main content, includingforeground_decoration. This fixes issues where decorations could overlap or interfere with content rendering. In addition, a newshaderproperty (with configurableblend_mode) is introduced to preserve the previous behavior whereforeground_decorationwas visually applied on top of all other content.Fixes #6094
Test Code
# Test code for the review of this PRType of change
Checklist
Summary by Sourcery
Adjust View rendering order and add shader support for applying gradient effects over view content.
New Features:
Enhancements: