From c7f337baebae7423f1cb04722f167728ea7e7036 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Mon, 8 Aug 2022 21:00:34 -0700 Subject: [PATCH] Fix container blend mode --- client/lib/controls/container.dart | 11 ++++++-- sdk/python/flet/container.py | 14 ++++++++++- sdk/python/flet/control.py | 33 ++++++++++++++++++++++++ sdk/python/flet/shader_mask.py | 40 +----------------------------- 4 files changed, 56 insertions(+), 42 deletions(-) diff --git a/client/lib/controls/container.dart b/client/lib/controls/container.dart index e7fb34406..fa80e50bb 100644 --- a/client/lib/controls/container.dart +++ b/client/lib/controls/container.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'dart:typed_data'; +import 'package:collection/collection.dart'; import 'package:flet_view/utils/animations.dart'; import 'package:flutter/material.dart'; import 'package:flutter_redux/flutter_redux.dart'; @@ -86,11 +87,17 @@ class ContainerControl extends StatelessWidget { opacity: imageOpacity); } + var gradient = parseGradient(Theme.of(context), control, "gradient"); + var blendMode = BlendMode.values.firstWhereOrNull((e) => + e.name.toLowerCase() == + control.attrString("blendMode", "")!.toLowerCase()); + var boxDecor = BoxDecoration( color: bgColor, - gradient: parseGradient(Theme.of(context), control, "gradient"), + gradient: gradient, image: image, - backgroundBlendMode: BlendMode.modulate, + backgroundBlendMode: + bgColor != null || gradient != null ? blendMode : null, border: parseBorder(Theme.of(context), control, "border"), borderRadius: parseBorderRadius(control, "borderRadius")); diff --git a/sdk/python/flet/container.py b/sdk/python/flet/container.py index 7b3699bdb..a1ecd4742 100644 --- a/sdk/python/flet/container.py +++ b/sdk/python/flet/container.py @@ -5,7 +5,7 @@ from flet.alignment import Alignment from flet.border import Border from flet.constrained_control import ConstrainedControl -from flet.control import Control, OptionalNumber +from flet.control import BlendMode, Control, OptionalNumber from flet.gradients import Gradient from flet.image import ImageFit, ImageRepeat from flet.ref import Ref @@ -59,6 +59,7 @@ def __init__( alignment: Alignment = None, bgcolor: str = None, gradient: Gradient = None, + blend_mode: BlendMode = None, border: Border = None, border_radius: BorderRadiusValue = None, image_src: str = None, @@ -104,6 +105,7 @@ def __init__( self.alignment = alignment self.bgcolor = bgcolor self.gradient = gradient + self.blend_mode = blend_mode self.border = border self.border_radius = border_radius self.image_src = image_src @@ -186,6 +188,16 @@ def gradient(self): def gradient(self, value: Optional[Gradient]): self.__gradient = value + # blend_mode + @property + def blend_mode(self): + return self._get_attr("blendMode") + + @blend_mode.setter + @beartype + def blend_mode(self, value: Optional[BlendMode]): + self._set_attr("blendMode", value) + # border @property def border(self): diff --git a/sdk/python/flet/control.py b/sdk/python/flet/control.py index 7bd05f547..b3f7bde05 100644 --- a/sdk/python/flet/control.py +++ b/sdk/python/flet/control.py @@ -49,6 +49,39 @@ ScrollMode = Literal[None, True, False, "none", "auto", "adaptive", "always", "hidden"] +BlendMode = Literal[ + "clear", + "color", + "colorBurn", + "colorDodge", + "darken", + "difference", + "dst", + "dstATop", + "dstIn", + "dstOut", + "dstOver", + "exclusion", + "hardLight", + "hue", + "lighten", + "luminosity", + "modulate", + "multiply", + "overlay", + "plus", + "saturation", + "screen", + "softLight", + "src", + "srcATop", + "srcIn", + "srcOut", + "srcOver", + "values", + "xor", +] + class Control: def __init__( diff --git a/sdk/python/flet/shader_mask.py b/sdk/python/flet/shader_mask.py index a19ae9c63..d99fa0ecb 100644 --- a/sdk/python/flet/shader_mask.py +++ b/sdk/python/flet/shader_mask.py @@ -3,7 +3,7 @@ from beartype import beartype from flet.constrained_control import ConstrainedControl -from flet.control import Control, OptionalNumber +from flet.control import BlendMode, Control, OptionalNumber from flet.gradients import Gradient from flet.ref import Ref from flet.types import ( @@ -14,44 +14,6 @@ ScaleValue, ) -try: - from typing import Literal -except: - from typing_extensions import Literal - -BlendMode = Literal[ - "clear", - "color", - "colorBurn", - "colorDodge", - "darken", - "difference", - "dst", - "dstATop", - "dstIn", - "dstOut", - "dstOver", - "exclusion", - "hardLight", - "hue", - "lighten", - "luminosity", - "modulate", - "multiply", - "overlay", - "plus", - "saturation", - "screen", - "softLight", - "src", - "srcATop", - "srcIn", - "srcOut", - "srcOver", - "values", - "xor", -] - class ShaderMask(ConstrainedControl): def __init__(