From 6dd23da911384593e335144d22d5e72a5d75244b Mon Sep 17 00:00:00 2001 From: TheEthicalBoy <98978078+ndonkoHenri@users.noreply.github.com> Date: Mon, 4 Dec 2023 20:47:09 +0100 Subject: [PATCH] Additional props (#2182) * NavigationBar.tooltip * Card.shape * NavRail props * NavRail props * BottomSheet props --- package/lib/src/controls/bottom_sheet.dart | 4 ++ package/lib/src/controls/card.dart | 2 + package/lib/src/controls/navigation_bar.dart | 1 + package/lib/src/controls/navigation_rail.dart | 5 +++ .../flet-core/src/flet_core/bottom_sheet.py | 24 +++++++++++- .../packages/flet-core/src/flet_core/card.py | 13 +++++++ .../flet-core/src/flet_core/navigation_bar.py | 3 +- .../src/flet_core/navigation_rail.py | 38 +++++++++++++++++++ 8 files changed, 88 insertions(+), 2 deletions(-) diff --git a/package/lib/src/controls/bottom_sheet.dart b/package/lib/src/controls/bottom_sheet.dart index db8d059af..f19ac3d4f 100644 --- a/package/lib/src/controls/bottom_sheet.dart +++ b/package/lib/src/controls/bottom_sheet.dart @@ -4,6 +4,7 @@ import '../actions.dart'; import '../flet_app_services.dart'; import '../models/control.dart'; import '../protocol/update_control_props_payload.dart'; +import '../utils/colors.dart'; import 'create_control.dart'; import 'error.dart'; @@ -95,6 +96,9 @@ class _BottomSheetControlState extends State { return content; }, isDismissible: dismissible, + backgroundColor: HexColor.fromString(Theme.of(context), + widget.control.attrString("bgColor", "")!), + elevation: widget.control.attrDouble("elevation"), isScrollControlled: isScrollControlled, enableDrag: enableDrag, showDragHandle: showDragHandle, diff --git a/package/lib/src/controls/card.dart b/package/lib/src/controls/card.dart index 1a69667a8..b88465c8d 100644 --- a/package/lib/src/controls/card.dart +++ b/package/lib/src/controls/card.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import '../models/control.dart'; +import '../utils/borders.dart'; import '../utils/colors.dart'; import '../utils/edge_insets.dart'; import 'create_control.dart'; @@ -31,6 +32,7 @@ class CardControl extends StatelessWidget { context, Card( elevation: control.attrDouble("elevation"), + shape: parseOutlinedBorder(control, "shape"), margin: parseEdgeInsets(control, "margin"), color: HexColor.fromString( Theme.of(context), control.attrString("color", "")!), diff --git a/package/lib/src/controls/navigation_bar.dart b/package/lib/src/controls/navigation_bar.dart index 48172c86e..5bde6cd56 100644 --- a/package/lib/src/controls/navigation_bar.dart +++ b/package/lib/src/controls/navigation_bar.dart @@ -106,6 +106,7 @@ class _NavigationBarControlState extends State { .where((c) => c.name == "selected_icon_content"); return NavigationDestination( + tooltip: destView.control.attrString("tooltip", "")!, icon: iconContentCtrls.isNotEmpty ? createControl(destView.control, iconContentCtrls.first.id, disabled) diff --git a/package/lib/src/controls/navigation_rail.dart b/package/lib/src/controls/navigation_rail.dart index 7fa4ed525..5afb4b1c3 100644 --- a/package/lib/src/controls/navigation_rail.dart +++ b/package/lib/src/controls/navigation_rail.dart @@ -7,6 +7,7 @@ import '../models/app_state.dart'; import '../models/control.dart'; import '../models/controls_view_model.dart'; import '../protocol/update_control_props_payload.dart'; +import '../utils/borders.dart'; import '../utils/colors.dart'; import '../utils/edge_insets.dart'; import '../utils/icons.dart'; @@ -103,12 +104,16 @@ class _NavigationRailControlState extends State { labelType: extended ? NavigationRailLabelType.none : labelType, extended: extended, + elevation: widget.control.attrDouble("elevation", 0), + indicatorShape: parseOutlinedBorder(widget.control, "indicatorShape"), minWidth: widget.control.attrDouble("minWidth"), minExtendedWidth: widget.control.attrDouble("minExtendedWidth"), groupAlignment: widget.control.attrDouble("groupAlignment"), backgroundColor: HexColor.fromString(Theme.of(context), widget.control.attrString("bgColor", "")!), + indicatorColor: HexColor.fromString(Theme.of(context), + widget.control.attrString("indicatorColor", "")!), leading: leadingCtrls.isNotEmpty ? createControl( widget.control, leadingCtrls.first.id, disabled) diff --git a/sdk/python/packages/flet-core/src/flet_core/bottom_sheet.py b/sdk/python/packages/flet-core/src/flet_core/bottom_sheet.py index 73f438ecc..c5b815648 100644 --- a/sdk/python/packages/flet-core/src/flet_core/bottom_sheet.py +++ b/sdk/python/packages/flet-core/src/flet_core/bottom_sheet.py @@ -1,6 +1,6 @@ from typing import Any, List, Optional -from flet_core.control import Control +from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref @@ -60,6 +60,8 @@ def __init__( # Specific # open: bool = False, + elevation: OptionalNumber = None, + bgcolor: Optional[str] = None, dismissible: Optional[bool] = None, enable_drag: Optional[bool] = None, show_drag_handle: Optional[bool] = None, @@ -79,6 +81,8 @@ def __init__( self.__content: Optional[Control] = None self.open = open + self.elevation = elevation + self.bgcolor = bgcolor self.dismissible = dismissible self.enable_drag = enable_drag self.show_drag_handle = show_drag_handle @@ -107,6 +111,24 @@ def open(self) -> Optional[bool]: def open(self, value: Optional[bool]): self._set_attr("open", value) + # elevation + @property + def elevation(self) -> OptionalNumber: + return self._get_attr("elevation") + + @elevation.setter + def elevation(self, value: OptionalNumber): + self._set_attr("elevation", value) + + # bgcolor + @property + def bgcolor(self): + return self._get_attr("bgColor") + + @bgcolor.setter + def bgcolor(self, value): + self._set_attr("bgColor", value) + # dismissible @property def dismissible(self) -> Optional[bool]: diff --git a/sdk/python/packages/flet-core/src/flet_core/card.py b/sdk/python/packages/flet-core/src/flet_core/card.py index ec32e868d..caa2c80d6 100644 --- a/sdk/python/packages/flet-core/src/flet_core/card.py +++ b/sdk/python/packages/flet-core/src/flet_core/card.py @@ -1,5 +1,6 @@ from typing import Any, Optional, Union +from flet_core import OutlinedBorder from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref @@ -93,6 +94,7 @@ def __init__( color: Optional[str] = None, shadow_color: Optional[str] = None, surface_tint_color: Optional[str] = None, + shape: Optional[OutlinedBorder] = None, ): ConstrainedControl.__init__( self, @@ -130,6 +132,7 @@ def __init__( self.color = color self.shadow_color = shadow_color self.surface_tint_color = surface_tint_color + self.shape = shape def _get_control_name(self): return "card" @@ -137,6 +140,7 @@ def _get_control_name(self): def _before_build_command(self): super()._before_build_command() self._set_attr_json("margin", self.__margin) + self._set_attr_json("shape", self.__shape) def _get_children(self): children = [] @@ -190,6 +194,15 @@ def surface_tint_color(self): def surface_tint_color(self, value): self._set_attr("surfaceTintColor", value) + # shape + @property + def shape(self) -> Optional[OutlinedBorder]: + return self.__shape + + @shape.setter + def shape(self, value: Optional[OutlinedBorder]): + self.__shape = value + # content @property def content(self) -> Optional[Control]: diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_bar.py b/sdk/python/packages/flet-core/src/flet_core/navigation_bar.py index 6eafa86d7..12cc08392 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_bar.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_bar.py @@ -45,8 +45,9 @@ def __init__( selected_icon: Optional[str] = None, selected_icon_content: Optional[Control] = None, label: Optional[str] = None, + tooltip: Optional[str] = None, ): - Control.__init__(self, ref=ref) + Control.__init__(self, ref=ref, tooltip=tooltip) self.label = label self.icon = icon self.__icon_content: Optional[Control] = None diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_rail.py b/sdk/python/packages/flet-core/src/flet_core/navigation_rail.py index 2048eaaf0..907a4c008 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_rail.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_rail.py @@ -1,6 +1,7 @@ from enum import Enum from typing import Any, List, Optional, Union +from flet_core import OutlinedBorder from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref @@ -222,10 +223,13 @@ def __init__( # # NavigationRail-specific destinations: Optional[List[NavigationRailDestination]] = None, + elevation: OptionalNumber = None, selected_index: Optional[int] = None, extended: Optional[bool] = None, label_type: Optional[NavigationRailLabelType] = None, bgcolor: Optional[str] = None, + indicator_color: Optional[str] = None, + indicator_shape: Optional[OutlinedBorder] = None, leading: Optional[Control] = None, trailing: Optional[Control] = None, min_width: OptionalNumber = None, @@ -263,9 +267,12 @@ def __init__( self.destinations = destinations self.selected_index = selected_index + self.elevation = elevation self.extended = extended self.label_type = label_type self.bgcolor = bgcolor + self.indicator_color = indicator_color + self.indicator_shape = indicator_shape self.__leading = None self.leading = leading self.__trailing = trailing @@ -278,6 +285,10 @@ def __init__( def _get_control_name(self): return "navigationrail" + def _before_build_command(self): + super()._before_build_command() + self._set_attr_json("indicatorShape", self.__indicator_shape) + def _get_children(self): children = [] if self.__leading: @@ -332,6 +343,24 @@ def label_type(self, value: Optional[NavigationRailLabelType]): def __set_label_type(self, value: NavigationRailLabelTypeString): self._set_attr("labelType", value) + # indicator_shape + @property + def indicator_shape(self) -> Optional[OutlinedBorder]: + return self.__indicator_shape + + @indicator_shape.setter + def indicator_shape(self, value: Optional[OutlinedBorder]): + self.__indicator_shape = value + + # indicator_color + @property + def indicator_color(self): + return self._get_attr("indicatorColor") + + @indicator_color.setter + def indicator_color(self, value): + self._set_attr("indicatorColor", value) + # bgcolor @property def bgcolor(self): @@ -341,6 +370,15 @@ def bgcolor(self): def bgcolor(self, value): self._set_attr("bgcolor", value) + # elevation + @property + def elevation(self) -> OptionalNumber: + return self._get_attr("elevation") + + @elevation.setter + def elevation(self, value: OptionalNumber): + self._set_attr("elevation", value) + # extended @property def extended(self) -> Optional[bool]: