diff --git a/packages/flet/lib/src/controls/create_control.dart b/packages/flet/lib/src/controls/create_control.dart index 13fb624c5..d90cb502f 100644 --- a/packages/flet/lib/src/controls/create_control.dart +++ b/packages/flet/lib/src/controls/create_control.dart @@ -257,6 +257,7 @@ Widget createWidget( children: controlView.children, control: controlView.control, parentDisabled: parentDisabled, + parentAdaptive: parentAdaptive, backend: backend); case "divider": return DividerControl( @@ -1163,11 +1164,11 @@ Widget _scaledControl( Widget _offsetControl( BuildContext context, Widget widget, Control? parent, Control control) { - var offsetDetails = parseOffset(control, "offset"); + var offset = parseOffset(control, "offset"); var animation = parseAnimation(control, "animateOffset"); - if (offsetDetails != null && animation != null) { + if (offset != null && animation != null) { return AnimatedSlide( - offset: Offset(offsetDetails.x, offsetDetails.y), + offset: offset, duration: animation.duration, curve: animation.curve, onEnd: control.attrBool("onAnimationEnd", false)! @@ -1178,9 +1179,8 @@ Widget _offsetControl( } : null, child: widget); - } else if (offsetDetails != null) { - return FractionalTranslation( - translation: Offset(offsetDetails.x, offsetDetails.y), child: widget); + } else if (offset != null) { + return FractionalTranslation(translation: offset, child: widget); } return widget; } diff --git a/packages/flet/lib/src/controls/cupertino_textfield.dart b/packages/flet/lib/src/controls/cupertino_textfield.dart index 5fb242e87..c25cdaeda 100644 --- a/packages/flet/lib/src/controls/cupertino_textfield.dart +++ b/packages/flet/lib/src/controls/cupertino_textfield.dart @@ -11,6 +11,8 @@ import '../utils/edge_insets.dart'; import '../utils/form_field.dart'; import '../utils/gradient.dart'; import '../utils/images.dart'; +import '../utils/others.dart'; +import '../utils/overlay_style.dart'; import '../utils/text.dart'; import '../utils/textfield.dart'; import 'create_control.dart'; @@ -159,11 +161,6 @@ class _CupertinoTextFieldControlState extends State inputFormatters.add(TextCapitalizationFormatter(textCapitalization)); } - TextInputType keyboardType = multiline - ? TextInputType.multiline - : parseTextInputType( - widget.control.attrString("keyboardType"), TextInputType.text)!; - TextAlign textAlign = parseTextAlign( widget.control.attrString("textAlign"), TextAlign.start)!; @@ -171,10 +168,7 @@ class _CupertinoTextFieldControlState extends State bool rtl = widget.control.attrBool("rtl", false)!; bool autocorrect = widget.control.attrBool("autocorrect", true)!; - bool enableSuggestions = - widget.control.attrBool("enableSuggestions", true)!; - bool smartDashesType = widget.control.attrBool("smartDashesType", true)!; - bool smartQuotesType = widget.control.attrBool("smartQuotesType", true)!; + ; FocusNode focusNode = shiftEnter ? _shiftEnterfocusNode : _focusNode; @@ -228,29 +222,25 @@ class _CupertinoTextFieldControlState extends State }), ); } - + var fitParentSize = widget.control.attrBool("fitParentSize", false)!; BoxDecoration? defaultDecoration = const CupertinoTextField().decoration; var gradient = parseGradient(Theme.of(context), widget.control, "gradient"); var blendMode = parseBlendMode(widget.control.attrString("blendMode")); var bgColor = widget.control.attrColor("bgColor", context); - // for adaptive TextField use label for placeholder - var placeholder = widget.control.attrString("placeholderText") ?? - widget.control.attrString("label"); - // for adaptive TextField use labelStyle for placeholderStyle - var placeholderStyle = - parseTextStyle(Theme.of(context), widget.control, "placeholderStyle") ?? - parseTextStyle(Theme.of(context), widget.control, "labelStyle"); + return withPageArgs((context, pageArgs) { - var decorationImage = parseDecorationImage( - Theme.of(context), widget.control, "image", pageArgs); Widget textField = CupertinoTextField( style: textStyle, textAlignVertical: textVerticalAlign != null ? TextAlignVertical(y: textVerticalAlign) : null, - placeholder: placeholder, - placeholderStyle: placeholderStyle, + placeholder: widget.control.attrString("placeholderText") ?? + widget.control.attrString("label"), + // use label for adaptive TextField + placeholderStyle: parseTextStyle(Theme.of(context), widget.control, "placeholderStyle") ?? + parseTextStyle(Theme.of(context), widget.control, "labelStyle"), + // labelStyle for adaptive TextField autofocus: autofocus, enabled: !disabled, onSubmitted: !multiline @@ -262,7 +252,8 @@ class _CupertinoTextFieldControlState extends State decoration: defaultDecoration?.copyWith( color: bgColor, gradient: gradient, - image: decorationImage, + image: parseDecorationImage( + Theme.of(context), widget.control, "image", pageArgs), backgroundBlendMode: bgColor != null || gradient != null ? blendMode : null, border: border, @@ -274,47 +265,54 @@ class _CupertinoTextFieldControlState extends State cursorWidth: widget.control.attrDouble("cursorWidth", 2.0)!, cursorRadius: parseRadius( widget.control, "cursorRadius", const Radius.circular(2.0))!, - keyboardType: keyboardType, + keyboardType: multiline + ? TextInputType.multiline + : parseTextInputType(widget.control.attrString("keyboardType"), + TextInputType.text)!, clearButtonSemanticLabel: widget.control.attrString("clearButtonSemanticsLabel"), autocorrect: autocorrect, - enableSuggestions: enableSuggestions, - smartDashesType: smartDashesType + enableSuggestions: + widget.control.attrBool("enableSuggestions", true)!, + smartDashesType: widget.control.attrBool("smartDashesType", true)! ? SmartDashesType.enabled : SmartDashesType.disabled, - smartQuotesType: smartQuotesType + smartQuotesType: widget.control.attrBool("smartQuotesType", true)! ? SmartQuotesType.enabled : SmartQuotesType.disabled, suffixMode: parseVisibilityMode( - widget.control.attrString("suffixVisibilityMode", "")!), + widget.control.attrString("suffixVisibilityMode"), + OverlayVisibilityMode.always)!, prefixMode: parseVisibilityMode( - widget.control.attrString("prefixVisibilityMode", "")!), + widget.control.attrString("prefixVisibilityMode"), + OverlayVisibilityMode.always)!, textAlign: textAlign, - minLines: minLines, - maxLines: maxLines, + minLines: fitParentSize ? null : minLines, + maxLines: fitParentSize ? null : maxLines, maxLength: maxLength, prefix: prefixControls.isNotEmpty ? createControl(widget.control, prefixControls.first.id, disabled, parentAdaptive: widget.parentAdaptive) : null, - suffix: revealPasswordIcon ?? - (suffixControls.isNotEmpty - ? createControl( - widget.control, suffixControls.first.id, disabled, - parentAdaptive: widget.parentAdaptive) - : null), + suffix: revealPasswordIcon ?? (suffixControls.isNotEmpty ? createControl(widget.control, suffixControls.first.id, disabled, parentAdaptive: widget.parentAdaptive) : null), readOnly: readOnly, textDirection: rtl ? TextDirection.rtl : null, inputFormatters: inputFormatters.isNotEmpty ? inputFormatters : null, obscureText: password && !_revealPassword, - padding: parseEdgeInsets( - widget.control, "padding", const EdgeInsets.all(7.0))!, + padding: parseEdgeInsets(widget.control, "padding", const EdgeInsets.all(7.0))!, scribbleEnabled: widget.control.attrBool("enableScribble", true)!, + scrollPadding: parseEdgeInsets(widget.control, "scrollPadding", const EdgeInsets.all(20.0))!, + obscuringCharacter: widget.control.attrString("obscuringCharacter", '•')!, + cursorOpacityAnimates: widget.control.attrBool("animateCursorOpacity", Theme.of(context).platform == TargetPlatform.iOS)!, + expands: fitParentSize, + enableIMEPersonalizedLearning: widget.control.attrBool("enableIMEPersonalizedLearning", true)!, + clipBehavior: parseClip(widget.control.attrString("clipBehavior"), Clip.hardEdge)!, + cursorColor: cursorColor, autofillHints: parseAutofillHints(widget.control, "autofillHints"), - scrollPadding: parseEdgeInsets( - widget.control, "scrollPadding", const EdgeInsets.all(20.0))!, - obscuringCharacter: - widget.control.attrString("obscuringCharacter", '•')!, + keyboardAppearance: parseBrightness(widget.control.attrString("keyboardBrightness")), + enableInteractiveSelection: widget.control.attrBool("enableInteractiveSelection"), + clearButtonMode: parseVisibilityMode(widget.control.attrString("clearButtonVisibilityMode"), OverlayVisibilityMode.never)!, + strutStyle: parseStrutStyle(widget.control, "strutStyle"), onTap: () { widget.backend.triggerControlEvent(widget.control.id, "click"); }, diff --git a/packages/flet/lib/src/controls/cupertino_timer_picker.dart b/packages/flet/lib/src/controls/cupertino_timer_picker.dart index 7469e6399..bde0d47db 100644 --- a/packages/flet/lib/src/controls/cupertino_timer_picker.dart +++ b/packages/flet/lib/src/controls/cupertino_timer_picker.dart @@ -33,23 +33,16 @@ class _CupertinoTimerPickerControlState int value = widget.control.attrInt("value", 0)!; Duration initialTimerDuration = Duration(seconds: value); - int minuteInterval = - widget.control.attrDouble("minuteInterval", 1)!.toInt(); - int secondInterval = - widget.control.attrDouble("secondInterval", 1)!.toInt(); - CupertinoTimerPickerMode mode = parseCupertinoTimerPickerMode( - widget.control.attrString("mode"), CupertinoTimerPickerMode.hms)!; - - Color? backgroundColor = widget.control.attrColor("bgColor", context); Widget picker = CupertinoTimerPicker( - mode: mode, + mode: parseCupertinoTimerPickerMode( + widget.control.attrString("mode"), CupertinoTimerPickerMode.hms)!, initialTimerDuration: initialTimerDuration, - minuteInterval: minuteInterval, - secondInterval: secondInterval, + minuteInterval: widget.control.attrInt("minuteInterval", 1)!, + secondInterval: widget.control.attrInt("secondInterval", 1)!, itemExtent: widget.control.attrDouble("itemExtent", 32.0)!, alignment: parseAlignment(widget.control, "alignment", Alignment.center)!, - backgroundColor: backgroundColor, + backgroundColor: widget.control.attrColor("bgColor", context), onTimerDurationChanged: (Duration d) { widget.backend.updateControlState( widget.control.id, {"value": d.inSeconds.toString()}); diff --git a/packages/flet/lib/src/controls/date_picker.dart b/packages/flet/lib/src/controls/date_picker.dart index fe9335c77..ff455775f 100644 --- a/packages/flet/lib/src/controls/date_picker.dart +++ b/packages/flet/lib/src/controls/date_picker.dart @@ -32,23 +32,7 @@ class _DatePickerControlState extends State { var open = widget.control.attrBool("open", false)!; DateTime? value = widget.control.attrDateTime("value"); - DateTime? firstDate = widget.control.attrDateTime("firstDate"); - DateTime? lastDate = widget.control.attrDateTime("lastDate"); DateTime? currentDate = widget.control.attrDateTime("currentDate"); - String? helpText = widget.control.attrString("helpText"); - String? cancelText = widget.control.attrString("cancelText"); - String? confirmText = widget.control.attrString("confirmText"); - String? errorFormatText = widget.control.attrString("errorFormatText"); - String? errorInvalidText = widget.control.attrString("errorInvalidText"); - TextInputType keyboardType = parseTextInputType( - widget.control.attrString("keyboardType"), TextInputType.text)!; - DatePickerMode datePickerMode = parseDatePickerMode( - widget.control.attrString("datePickerMode"), DatePickerMode.day)!; - DatePickerEntryMode datePickerEntryMode = parseDatePickerEntryMode( - widget.control.attrString("datePickerEntryMode"), - DatePickerEntryMode.calendar)!; - String? fieldHintText = widget.control.attrString("fieldHintText"); - String? fieldLabelText = widget.control.attrString("fieldLabelText"); IconData? switchToCalendarEntryModeIcon = parseIcon( widget.control.attrString("switchToCalendarEntryModeIcon", "")!); IconData? switchToInputEntryModeIcon = @@ -75,19 +59,23 @@ class _DatePickerControlState extends State { Widget createSelectDateDialog() { Widget dialog = DatePickerDialog( initialDate: value ?? currentDate ?? DateTime.now(), - firstDate: firstDate ?? DateTime(1900), - lastDate: lastDate ?? DateTime(2050), + firstDate: widget.control.attrDateTime("firstDate", DateTime(1900))!, + lastDate: widget.control.attrDateTime("lastDate", DateTime(2050))!, currentDate: currentDate ?? DateTime.now(), - helpText: helpText, - cancelText: cancelText, - confirmText: confirmText, - errorFormatText: errorFormatText, - errorInvalidText: errorInvalidText, - keyboardType: keyboardType, - initialCalendarMode: datePickerMode, - initialEntryMode: datePickerEntryMode, - fieldHintText: fieldHintText, - fieldLabelText: fieldLabelText, + helpText: widget.control.attrString("helpText"), + cancelText: widget.control.attrString("cancelText"), + confirmText: widget.control.attrString("confirmText"), + errorFormatText: widget.control.attrString("errorFormatText"), + errorInvalidText: widget.control.attrString("errorInvalidText"), + keyboardType: parseTextInputType( + widget.control.attrString("keyboardType"), TextInputType.text)!, + initialCalendarMode: parseDatePickerMode( + widget.control.attrString("datePickerMode"), DatePickerMode.day)!, + initialEntryMode: parseDatePickerEntryMode( + widget.control.attrString("datePickerEntryMode"), + DatePickerEntryMode.calendar)!, + fieldHintText: widget.control.attrString("fieldHintText"), + fieldLabelText: widget.control.attrString("fieldLabelText"), onDatePickerModeChange: (DatePickerEntryMode mode) { widget.backend.triggerControlEvent( widget.control.id, "entryModeChange", mode.name); diff --git a/packages/flet/lib/src/controls/draggable.dart b/packages/flet/lib/src/controls/draggable.dart index 8d5f16c4f..c2d763afc 100644 --- a/packages/flet/lib/src/controls/draggable.dart +++ b/packages/flet/lib/src/controls/draggable.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import '../flet_control_backend.dart'; import '../models/control.dart'; +import '../utils/others.dart'; import 'create_control.dart'; import 'error.dart'; @@ -27,6 +28,7 @@ class DraggableControl extends StatelessWidget { @override Widget build(BuildContext context) { debugPrint("DragTarget build: ${control.id}"); + var adaptive = control.isAdaptive ?? parentAdaptive; var group = control.attrString("group", ""); var contentCtrls = @@ -39,18 +41,13 @@ class DraggableControl extends StatelessWidget { Widget? child = contentCtrls.isNotEmpty ? createControl(control, contentCtrls.first.id, disabled, - parentAdaptive: parentAdaptive) - : null; - - Widget? childWhenDragging = contentWhenDraggingCtrls.isNotEmpty - ? createControl(control, contentWhenDraggingCtrls.first.id, disabled, - parentAdaptive: parentAdaptive) + parentAdaptive: adaptive) : null; Widget? childFeedback = contentFeedbackCtrls.isNotEmpty ? createControl(control, contentFeedbackCtrls.first.id, disabled, - parentAdaptive: parentAdaptive) - : null; + parentAdaptive: adaptive) + : Opacity(opacity: 0.5, child: child); if (child == null) { return const ErrorControl( @@ -61,10 +58,16 @@ class DraggableControl extends StatelessWidget { return Draggable( data: data, - childWhenDragging: childWhenDragging, + axis: parseAxis(control.attrString("axis")), + affinity: parseAxis(control.attrString("affinity")), + maxSimultaneousDrags: control.attrInt("maxSimultaneousDrags"), + childWhenDragging: contentWhenDraggingCtrls.isNotEmpty + ? createControl(control, contentWhenDraggingCtrls.first.id, disabled, + parentAdaptive: adaptive) + : null, feedback: MouseRegion( cursor: SystemMouseCursors.grabbing, - child: childFeedback ?? Opacity(opacity: 0.5, child: child), + child: childFeedback, ), onDragStarted: () { debugPrint("Draggable.onDragStarted ${control.id}"); diff --git a/packages/flet/lib/src/controls/dropdown.dart b/packages/flet/lib/src/controls/dropdown.dart index 3f0933a4e..46b3949c3 100644 --- a/packages/flet/lib/src/controls/dropdown.dart +++ b/packages/flet/lib/src/controls/dropdown.dart @@ -147,16 +147,22 @@ class _DropdownControlState extends State with FletStoreMixin { var prefixControls = itemsView.controlViews .where((c) => c.control.name == "prefix" && c.control.isVisible); - var prefixIconControls = - widget.children.where((c) => c.name == "prefixIcon" && c.isVisible); + var prefixIconControls = itemsView.controlViews + .where((c) => c.control.name == "prefix_icon" && c.control.isVisible); var suffixControls = itemsView.controlViews .where((c) => c.control.name == "suffix" && c.control.isVisible); - var suffixIconControls = - widget.children.where((c) => c.name == "suffixIcon" && c.isVisible); - var iconControls = - widget.children.where((c) => c.name == "icon" && c.isVisible); + var suffixIconControls = itemsView.controlViews + .where((c) => c.control.name == "suffix_icon" && c.control.isVisible); var counterControls = itemsView.controlViews .where((c) => c.control.name == "counter" && c.control.isVisible); + var iconControls = itemsView.controlViews + .where((c) => c.control.name == "icon" && c.control.isVisible); + var errorCtrl = itemsView.controlViews + .where((c) => c.control.name == "error" && c.control.isVisible); + var helperCtrl = itemsView.controlViews + .where((c) => c.control.name == "helper" && c.control.isVisible); + var labelCtrl = itemsView.controlViews + .where((c) => c.control.name == "label" && c.control.isVisible); var focusValue = widget.control.attrString("focus"); if (focusValue != null && focusValue != _lastFocusValue) { @@ -195,14 +201,21 @@ class _DropdownControlState extends State with FletStoreMixin { decoration: buildInputDecoration(context, widget.control, prefix: prefixControls.isNotEmpty ? prefixControls.first.control : null, - prefixIcon: prefixIconControls.isNotEmpty ? prefixIconControls.first : null, + prefixIcon: prefixIconControls.isNotEmpty + ? prefixIconControls.first.control + : null, suffix: suffixControls.isNotEmpty ? suffixControls.first.control : null, - suffixIcon: suffixIconControls.isNotEmpty ? suffixIconControls.first : null, - icon: iconControls.isNotEmpty ? iconControls.first : null, + suffixIcon: suffixIconControls.isNotEmpty + ? suffixIconControls.first.control + : null, counter: counterControls.isNotEmpty ? counterControls.first.control : null, + icon: iconControls.isNotEmpty ? iconControls.first.control : null, + error: errorCtrl.isNotEmpty ? errorCtrl.first.control : null, + helper: helperCtrl.isNotEmpty ? helperCtrl.first.control : null, + label: labelCtrl.isNotEmpty ? labelCtrl.first.control : null, customSuffix: null, focused: _focused, disabled: disabled, diff --git a/packages/flet/lib/src/controls/gesture_detector.dart b/packages/flet/lib/src/controls/gesture_detector.dart index 6a4eda115..dca72de04 100644 --- a/packages/flet/lib/src/controls/gesture_detector.dart +++ b/packages/flet/lib/src/controls/gesture_detector.dart @@ -1,12 +1,14 @@ import 'dart:async'; import 'dart:convert'; +import 'package:collection/collection.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import '../flet_control_backend.dart'; import '../models/control.dart'; import '../utils/mouse.dart'; +import '../utils/others.dart'; import 'create_control.dart'; import 'error.dart'; @@ -65,7 +67,7 @@ class _GestureDetectorControlState extends State { widget.children.where((c) => c.name == "content" && c.isVisible); bool disabled = widget.control.isDisabled || widget.parentDisabled; - void sendEvent(String eventName, dynamic eventData) { + void sendEvent(String eventName, [dynamic eventData = ""]) { var d = ""; if (eventData is String) { d = eventData; @@ -300,9 +302,29 @@ class _GestureDetectorControlState extends State { onScaleEnd) ? GestureDetector( behavior: HitTestBehavior.translucent, + excludeFromSemantics: + widget.control.attrBool("excludeFromSemantics", false)!, + trackpadScrollCausesScale: + widget.control.attrBool("trackpadScrollCausesScale", false)!, + supportedDevices: () { + var supportedDevicesString = + widget.control.attrString("allowedDevices"); + var supportedDevicesJson = supportedDevicesString != null + ? jsonDecode(supportedDevicesString) + : null; + if (supportedDevicesJson != null && + (supportedDevicesJson is Iterable && + supportedDevicesJson is! Map)) { + return supportedDevicesJson + .map((d) => parsePointerDeviceKind(d)) + .whereNotNull() + .toSet(); + } + return null; + }(), onTap: onTap ? () { - sendEvent("tap", ""); + sendEvent("tap"); } : null, onTapDown: onTapDown @@ -329,7 +351,7 @@ class _GestureDetectorControlState extends State { : null, onSecondaryTap: onSecondaryTap ? () { - sendEvent("secondary_tap", ""); + sendEvent("secondary_tap"); } : null, onSecondaryTapDown: onSecondaryTapDown @@ -400,7 +422,7 @@ class _GestureDetectorControlState extends State { : null, onDoubleTap: onDoubleTap ? () { - sendEvent("double_tap", ""); + sendEvent("double_tap"); } : null, onDoubleTapDown: onDoubleTapDown @@ -521,7 +543,7 @@ class _GestureDetectorControlState extends State { if (correctNumberOfTouches) { _debounce = Timer(const Duration(milliseconds: 1000), () { - sendEvent("multi_long_press", ""); + sendEvent("multi_long_press"); }); } else if (_debounce?.isActive ?? false) { _debounce!.cancel(); diff --git a/packages/flet/lib/src/controls/icon.dart b/packages/flet/lib/src/controls/icon.dart index 3ce626e5a..d3c9f4065 100644 --- a/packages/flet/lib/src/controls/icon.dart +++ b/packages/flet/lib/src/controls/icon.dart @@ -1,3 +1,4 @@ +import 'package:flet/src/utils/box.dart'; import 'package:flutter/material.dart'; import '../models/control.dart'; @@ -14,18 +15,19 @@ class IconControl extends StatelessWidget { Widget build(BuildContext context) { debugPrint("Icon build: ${control.id}"); - var name = control.attrString("name", "")!; - var size = control.attrDouble("size"); - var semanticsLabel = control.attrString("semanticsLabel"); - var color = control.attrColor("color", context); - return constrainedControl( context, Icon( - parseIcon(name), - size: size, - color: color, - semanticLabel: semanticsLabel, + parseIcon(control.attrString("name", "")!), + size: control.attrDouble("size"), + color: control.attrColor("color", context), + semanticLabel: control.attrString("semanticsLabel"), + applyTextScaling: control.attrBool("applyTextScaling"), + fill: control.attrDouble("fill"), + grade: control.attrDouble("grade"), + weight: control.attrDouble("weight"), + opticalSize: control.attrDouble("opticalSize"), + shadows: parseBoxShadow(Theme.of(context), control, "shadows"), ), parent, control); diff --git a/packages/flet/lib/src/controls/icon_button.dart b/packages/flet/lib/src/controls/icon_button.dart index 9a2117243..3e18b7227 100644 --- a/packages/flet/lib/src/controls/icon_button.dart +++ b/packages/flet/lib/src/controls/icon_button.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import '../flet_control_backend.dart'; import '../models/control.dart'; import '../utils/alignment.dart'; +import '../utils/box.dart'; import '../utils/buttons.dart'; import '../utils/edge_insets.dart'; import '../utils/icons.dart'; @@ -94,6 +95,8 @@ class _IconButtonControlState extends State double? splashRadius = widget.control.attrDouble("splashRadius"); var padding = parseEdgeInsets(widget.control, "padding"); var alignment = parseAlignment(widget.control, "alignment"); + var sizeConstraints = + parseBoxConstraints(widget.control, "sizeConstraints"); var contentCtrls = widget.children.where((c) => c.name == "content" && c.isVisible); bool autofocus = widget.control.attrBool("autofocus", false)!; @@ -156,6 +159,7 @@ class _IconButtonControlState extends State visualDensity: visualDensity, style: style, isSelected: selected, + constraints: sizeConstraints, selectedIcon: selectedIcon != null ? Icon(selectedIcon, color: selectedIconColor) : null, @@ -179,6 +183,7 @@ class _IconButtonControlState extends State visualDensity: visualDensity, style: style, isSelected: selected, + constraints: sizeConstraints, selectedIcon: selectedIcon != null ? Icon(selectedIcon, color: selectedIconColor) : null, diff --git a/packages/flet/lib/src/controls/image.dart b/packages/flet/lib/src/controls/image.dart index 21555494e..d6e00ed1a 100644 --- a/packages/flet/lib/src/controls/image.dart +++ b/packages/flet/lib/src/controls/image.dart @@ -14,6 +14,7 @@ class ImageControl extends StatelessWidget with FletStoreMixin { final List children; final Control control; final bool parentDisabled; + final bool? parentAdaptive; final FletControlBackend backend; static const String svgTag = " xmlns=\"http://www.w3.org/2000/svg\""; @@ -24,6 +25,7 @@ class ImageControl extends StatelessWidget with FletStoreMixin { required this.children, required this.control, required this.parentDisabled, + required this.parentAdaptive, required this.backend}); @override @@ -61,7 +63,8 @@ class ImageControl extends StatelessWidget with FletStoreMixin { disabled: disabled, pageArgs: pageArgs, errorCtrl: errorContentCtrls.isNotEmpty - ? createControl(control, errorContentCtrls.first.id, disabled) + ? createControl(control, errorContentCtrls.first.id, disabled, + parentAdaptive: control.isAdaptive ?? parentAdaptive) : null, ); return constrainedControl( diff --git a/packages/flet/lib/src/controls/interactive_viewer.dart b/packages/flet/lib/src/controls/interactive_viewer.dart index 1a38c7a00..9ea1734b0 100644 --- a/packages/flet/lib/src/controls/interactive_viewer.dart +++ b/packages/flet/lib/src/controls/interactive_viewer.dart @@ -32,7 +32,7 @@ class InteractiveViewerControl extends StatelessWidget { debugPrint("InteractiveViewer build: ${control.id}"); var contentCtrls = children.where((c) => c.isVisible); - bool? adaptive = control.attrBool("adaptive") ?? parentAdaptive; + bool? adaptive = control.isAdaptive ?? parentAdaptive; bool disabled = control.isDisabled || parentDisabled; var interactiveViewer = InteractiveViewer( diff --git a/packages/flet/lib/src/controls/linechart.dart b/packages/flet/lib/src/controls/linechart.dart index b97096bb4..0b69a7e77 100644 --- a/packages/flet/lib/src/controls/linechart.dart +++ b/packages/flet/lib/src/controls/linechart.dart @@ -436,7 +436,7 @@ class _LineChartControlState extends State { parseGradient(theme, dataViewModel.control, "belowLineGradient"); var dashPattern = dataViewModel.control.attrString("dashPattern"); var shadow = - parseBoxShadow(Theme.of(context), dataViewModel.control, "shadow"); + parseBoxShadow(Theme.of(context), dataViewModel.control, "shadow", [])!; Color barColor = dataViewModel.control.attrColor("color", context) ?? Colors.cyan; Gradient? barGradient = diff --git a/packages/flet/lib/src/controls/list_tile.dart b/packages/flet/lib/src/controls/list_tile.dart index 941a6d5a9..e2875882a 100644 --- a/packages/flet/lib/src/controls/list_tile.dart +++ b/packages/flet/lib/src/controls/list_tile.dart @@ -51,132 +51,121 @@ class ListTileControl extends StatelessWidget with FletStoreMixin { @override Widget build(BuildContext context) { debugPrint("ListTile build: ${control.id}"); - return Material( - child: withPagePlatform((context, platform) { - bool? adaptive = control.attrBool("adaptive") ?? parentAdaptive; - if (adaptive == true && - (platform == TargetPlatform.iOS || - platform == TargetPlatform.macOS)) { - return CupertinoListTileControl( - control: control, - parent: parent, - parentDisabled: parentDisabled, - parentAdaptive: adaptive, - children: children, - backend: backend); - } - - var leadingCtrls = - children.where((c) => c.name == "leading" && c.isVisible); - var titleCtrls = children.where((c) => c.name == "title" && c.isVisible); - var subtitleCtrls = - children.where((c) => c.name == "subtitle" && c.isVisible); - var trailingCtrls = - children.where((c) => c.name == "trailing" && c.isVisible); - - var titleAlignment = - parseListTileTitleAlignment(control.attrString("titleAlignment")); - var style = parseListTileStyle(control.attrString("style")); - - bool selected = control.attrBool("selected", false)!; - bool dense = control.attrBool("dense", false)!; - bool isThreeLine = control.attrBool("isThreeLine", false)!; - bool autofocus = control.attrBool("autofocus", false)!; - bool onclick = control.attrBool("onclick", false)!; - bool toggleInputs = control.attrBool("toggleInputs", false)!; - bool onLongPressDefined = control.attrBool("onLongPress", false)!; - bool? enableFeedback = control.attrBool("enableFeedback"); - double? horizontalSpacing = control.attrDouble("horizontalSpacing"); - double? minLeadingWidth = control.attrDouble("minLeadingWidth"); - double? minVerticalPadding = control.attrDouble("minVerticalPadding"); - String url = control.attrString("url", "")!; - String? urlTarget = control.attrString("urlTarget"); - bool disabled = control.isDisabled || parentDisabled; - - Function()? onPressed = - (onclick || toggleInputs || url != "") && !disabled - ? () { - debugPrint("ListTile ${control.id} clicked!"); - if (toggleInputs) { - _clickNotifier.onClick(); - } - if (url != "") { - openWebBrowser(url, webWindowName: urlTarget); - } - if (onclick) { - backend.triggerControlEvent(control.id, "click"); - } + return withPagePlatform((context, platform) { + bool? adaptive = control.isAdaptive ?? parentAdaptive; + if (adaptive == true && + (platform == TargetPlatform.iOS || + platform == TargetPlatform.macOS)) { + return CupertinoListTileControl( + control: control, + parent: parent, + parentDisabled: parentDisabled, + parentAdaptive: adaptive, + children: children, + backend: backend); + } + + var leadingCtrls = + children.where((c) => c.name == "leading" && c.isVisible); + var titleCtrls = children.where((c) => c.name == "title" && c.isVisible); + var subtitleCtrls = + children.where((c) => c.name == "subtitle" && c.isVisible); + var trailingCtrls = + children.where((c) => c.name == "trailing" && c.isVisible); + + bool onclick = control.attrBool("onclick", false)!; + bool toggleInputs = control.attrBool("toggleInputs", false)!; + bool onLongPressDefined = control.attrBool("onLongPress", false)!; + String url = control.attrString("url", "")!; + String? urlTarget = control.attrString("urlTarget"); + bool disabled = control.isDisabled || parentDisabled; + + Function()? onPressed = + (onclick || toggleInputs || url != "") && !disabled + ? () { + debugPrint("ListTile ${control.id} clicked!"); + if (toggleInputs) { + _clickNotifier.onClick(); } - : null; - - Function()? onLongPress = onLongPressDefined && !disabled - ? () { - debugPrint("Button ${control.id} clicked!"); - backend.triggerControlEvent(control.id, "long_press"); - } - : null; - - Widget tile = ListTile( - autofocus: autofocus, - contentPadding: parseEdgeInsets(control, "contentPadding"), - isThreeLine: isThreeLine, - selected: selected, - dense: dense, - onTap: onPressed, - onLongPress: onLongPress, - enabled: !disabled, - horizontalTitleGap: horizontalSpacing, - enableFeedback: enableFeedback, - minLeadingWidth: minLeadingWidth, - minVerticalPadding: minVerticalPadding, - minTileHeight: control.attrDouble("minHeight"), - selectedTileColor: control.attrColor("selectedTileColor", context), - selectedColor: control.attrColor("selectedColor", context), - focusColor: control.attrColor("focusColor", context), - tileColor: control.attrColor("bgcolor", context), - splashColor: control.attrColor("bgcolorActivated", context), - hoverColor: control.attrColor("hoverColor", context), - iconColor: control.attrColor("iconColor", context), - textColor: control.attrColor("textColor", context), - mouseCursor: parseMouseCursor(control.attrString("mouseCursor")), - visualDensity: parseVisualDensity(control.attrString("visualDensity")), - shape: parseOutlinedBorder(control, "shape"), - titleTextStyle: - parseTextStyle(Theme.of(context), control, "titleTextStyle"), - leadingAndTrailingTextStyle: parseTextStyle( - Theme.of(context), control, "leadingAndTrailingTextStyle"), - subtitleTextStyle: - parseTextStyle(Theme.of(context), control, "subtitleTextStyle"), - titleAlignment: titleAlignment, - style: style, - onFocusChange: (bool hasFocus) { - backend.triggerControlEvent(control.id, hasFocus ? "focus" : "blur"); - }, - leading: leadingCtrls.isNotEmpty - ? createControl(control, leadingCtrls.first.id, disabled, - parentAdaptive: adaptive) - : null, - title: titleCtrls.isNotEmpty - ? createControl(control, titleCtrls.first.id, disabled, - parentAdaptive: adaptive) - : null, - subtitle: subtitleCtrls.isNotEmpty - ? createControl(control, subtitleCtrls.first.id, disabled, - parentAdaptive: adaptive) - : null, - trailing: trailingCtrls.isNotEmpty - ? createControl(control, trailingCtrls.first.id, disabled, - parentAdaptive: adaptive) - : null, - ); - - if (toggleInputs) { - tile = ListTileClicks(notifier: _clickNotifier, child: tile); - } - - return constrainedControl(context, tile, parent, control); - })); - + if (url != "") { + openWebBrowser(url, webWindowName: urlTarget); + } + if (onclick) { + backend.triggerControlEvent(control.id, "click"); + } + } + : null; + + Function()? onLongPress = onLongPressDefined && !disabled + ? () { + debugPrint("Button ${control.id} clicked!"); + backend.triggerControlEvent(control.id, "long_press"); + } + : null; + + Widget tile = ListTile( + autofocus: control.attrBool("autofocus", false)!, + contentPadding: parseEdgeInsets(control, "contentPadding"), + isThreeLine: control.attrBool("isThreeLine", false)!, + selected: control.attrBool("selected", false)!, + dense: control.attrBool("dense", false)!, + onTap: onPressed, + onLongPress: onLongPress, + enabled: !disabled, + horizontalTitleGap: control.attrDouble("horizontalSpacing"), + enableFeedback: control.attrBool("enableFeedback"), + minLeadingWidth: control.attrDouble("minLeadingWidth"), + minVerticalPadding: control.attrDouble("minVerticalPadding"), + minTileHeight: control.attrDouble("minHeight"), + selectedTileColor: control.attrColor("selectedTileColor", context), + selectedColor: control.attrColor("selectedColor", context), + focusColor: control.attrColor("focusColor", context), + tileColor: control.attrColor("bgcolor", context), + splashColor: control.attrColor("bgcolorActivated", context), + hoverColor: control.attrColor("hoverColor", context), + iconColor: control.attrColor("iconColor", context), + textColor: control.attrColor("textColor", context), + mouseCursor: parseMouseCursor(control.attrString("mouseCursor")), + visualDensity: parseVisualDensity(control.attrString("visualDensity")), + shape: parseOutlinedBorder(control, "shape"), + titleTextStyle: + parseTextStyle(Theme.of(context), control, "titleTextStyle"), + leadingAndTrailingTextStyle: parseTextStyle( + Theme.of(context), control, "leadingAndTrailingTextStyle"), + subtitleTextStyle: + parseTextStyle(Theme.of(context), control, "subtitleTextStyle"), + titleAlignment: + parseListTileTitleAlignment(control.attrString("titleAlignment")), + style: parseListTileStyle(control.attrString("style")), + onFocusChange: (bool hasFocus) { + backend.triggerControlEvent(control.id, hasFocus ? "focus" : "blur"); + }, + leading: leadingCtrls.isNotEmpty + ? createControl(control, leadingCtrls.first.id, disabled, + parentAdaptive: adaptive) + : null, + title: titleCtrls.isNotEmpty + ? createControl(control, titleCtrls.first.id, disabled, + parentAdaptive: adaptive) + : null, + subtitle: subtitleCtrls.isNotEmpty + ? createControl(control, subtitleCtrls.first.id, disabled, + parentAdaptive: adaptive) + : null, + trailing: trailingCtrls.isNotEmpty + ? createControl(control, trailingCtrls.first.id, disabled, + parentAdaptive: adaptive) + : null, + ); + + if (toggleInputs) { + tile = ListTileClicks(notifier: _clickNotifier, child: tile); + } + + tile = Material(child: tile); + + return constrainedControl(context, tile, parent, control); + }); } } diff --git a/packages/flet/lib/src/controls/menu_bar.dart b/packages/flet/lib/src/controls/menu_bar.dart index 81b458cc9..3b15b3f6b 100644 --- a/packages/flet/lib/src/controls/menu_bar.dart +++ b/packages/flet/lib/src/controls/menu_bar.dart @@ -33,24 +33,23 @@ class _MenuBarControlState extends State { var ctrls = widget.children.where((c) => c.isVisible).toList(); if (ctrls.isEmpty) { return const ErrorControl( - "MenuBar must have at minimum one visible control"); + "MenuBar must have at minimum one visible child control"); } - bool disabled = widget.control.isDisabled || widget.parentDisabled; - var clipBehavior = - parseClip(widget.control.attrString("clipBehavior"), Clip.none)!; - - var style = parseMenuStyle(Theme.of(context), widget.control, "style"); - - MenuBar? menuBar = MenuBar( - style: style, - clipBehavior: clipBehavior, - children: ctrls - .map((c) => createControl(widget.control, c.id, disabled, - parentAdaptive: widget.parentAdaptive)) - .toList(), - ); - - return constrainedControl(context, menuBar, widget.parent, widget.control); + return constrainedControl( + context, + MenuBar( + style: parseMenuStyle(Theme.of(context), widget.control, "style"), + clipBehavior: + parseClip(widget.control.attrString("clipBehavior"), Clip.none)!, + children: ctrls + .map((c) => createControl(widget.control, c.id, + widget.control.isDisabled || widget.parentDisabled, + parentAdaptive: + widget.control.isAdaptive ?? widget.parentAdaptive)) + .toList(), + ), + widget.parent, + widget.control); } } diff --git a/packages/flet/lib/src/controls/menu_item_button.dart b/packages/flet/lib/src/controls/menu_item_button.dart index 02efa9710..79c715922 100644 --- a/packages/flet/lib/src/controls/menu_item_button.dart +++ b/packages/flet/lib/src/controls/menu_item_button.dart @@ -62,9 +62,6 @@ class _MenuItemButtonControlState extends State { var trailing = widget.children.where((c) => c.name == "trailing" && c.isVisible); - var clipBehavior = - parseClip(widget.control.attrString("clipBehavior"), Clip.none)!; - var theme = Theme.of(context); var style = parseButtonStyle(Theme.of(context), widget.control, "style", defaultForegroundColor: theme.colorScheme.primary, @@ -82,9 +79,12 @@ class _MenuItemButtonControlState extends State { bool onClick = widget.control.attrBool("onClick", false)!; bool onHover = widget.control.attrBool("onHover", false)!; + var adaptive = widget.control.isAdaptive ?? widget.parentAdaptive; + var menuItem = MenuItemButton( focusNode: _focusNode, - clipBehavior: clipBehavior, + clipBehavior: + parseClip(widget.control.attrString("clipBehavior"), Clip.none)!, style: style, closeOnActivate: widget.control.attrBool("closeOnClick", true)!, requestFocusOnHover: widget.control.attrBool("focusOnHover", true)!, @@ -104,22 +104,16 @@ class _MenuItemButtonControlState extends State { } : null, leadingIcon: leading.isNotEmpty - ? leading - .map((c) => createControl(widget.control, c.id, disabled, - parentAdaptive: widget.parentAdaptive)) - .first + ? createControl(widget.control, leading.first.id, disabled, + parentAdaptive: adaptive) : null, trailingIcon: trailing.isNotEmpty - ? trailing - .map((c) => createControl(widget.control, c.id, disabled, - parentAdaptive: widget.parentAdaptive)) - .first + ? createControl(widget.control, trailing.first.id, disabled, + parentAdaptive: adaptive) : null, child: content.isNotEmpty - ? content - .map((c) => createControl(widget.control, c.id, disabled, - parentAdaptive: widget.parentAdaptive)) - .first + ? createControl(widget.control, content.first.id, disabled, + parentAdaptive: adaptive) : null, ); diff --git a/packages/flet/lib/src/controls/navigation_bar.dart b/packages/flet/lib/src/controls/navigation_bar.dart index 5f365ff96..0f3d55073 100644 --- a/packages/flet/lib/src/controls/navigation_bar.dart +++ b/packages/flet/lib/src/controls/navigation_bar.dart @@ -103,7 +103,7 @@ class _NavigationBarControlState extends State var destinationAdaptive = destView.control.isAdaptive ?? adaptive; return NavigationDestination( enabled: !destinationDisabled, - tooltip: destView.control.attrString("tooltip") ?? "", + tooltip: destView.control.attrString("tooltip"), icon: iconContentCtrls.isNotEmpty ? createControl(destView.control, iconContentCtrls.first.id, destinationDisabled, diff --git a/packages/flet/lib/src/controls/navigation_drawer.dart b/packages/flet/lib/src/controls/navigation_drawer.dart index 5d3ca42c6..5766219fa 100644 --- a/packages/flet/lib/src/controls/navigation_drawer.dart +++ b/packages/flet/lib/src/controls/navigation_drawer.dart @@ -67,6 +67,7 @@ class _NavigationDrawerControlState extends State var selectedIconContentCtrls = destView.children .where((c) => c.name == "selected_icon_content" && c.isVisible); return NavigationDrawerDestination( + enabled: !(disabled || destView.control.isDisabled), backgroundColor: destView.control.attrColor("bgColor", context), icon: iconContentCtrls.isNotEmpty ? createControl( @@ -104,6 +105,5 @@ class _NavigationDrawerControlState extends State return baseControl(context, drawer, widget.parent, widget.control); }); - } } diff --git a/packages/flet/lib/src/controls/placeholder.dart b/packages/flet/lib/src/controls/placeholder.dart index 42cbcab1e..ada287d4a 100644 --- a/packages/flet/lib/src/controls/placeholder.dart +++ b/packages/flet/lib/src/controls/placeholder.dart @@ -21,8 +21,6 @@ class PlaceholderControl extends StatelessWidget { @override Widget build(BuildContext context) { debugPrint("Placeholder build: ${control.id}"); - bool disabled = control.isDisabled || parentDisabled; - bool? adaptive = control.attrBool("adaptive") ?? parentAdaptive; var contentCtrls = children.where((c) => c.isVisible); return baseControl( @@ -34,8 +32,9 @@ class PlaceholderControl extends StatelessWidget { control.attrColor("color", context, const Color(0xFF455A64))!, strokeWidth: control.attrDouble("strokeWidth", 2.0)!, child: contentCtrls.isNotEmpty - ? createControl(control, contentCtrls.first.id, disabled, - parentAdaptive: adaptive) + ? createControl(control, contentCtrls.first.id, + control.isDisabled || parentDisabled, + parentAdaptive: control.isAdaptive ?? parentAdaptive) : null), parent, control); diff --git a/packages/flet/lib/src/controls/popup_menu_button.dart b/packages/flet/lib/src/controls/popup_menu_button.dart index 1883d4902..e552220fe 100644 --- a/packages/flet/lib/src/controls/popup_menu_button.dart +++ b/packages/flet/lib/src/controls/popup_menu_button.dart @@ -2,7 +2,10 @@ import 'package:flutter/material.dart'; import '../flet_control_backend.dart'; import '../models/control.dart'; +import '../utils/animations.dart'; import '../utils/borders.dart'; +import '../utils/box.dart'; +import '../utils/buttons.dart'; import '../utils/edge_insets.dart'; import '../utils/icons.dart'; import '../utils/mouse.dart'; @@ -30,27 +33,10 @@ class PopupMenuButtonControl extends StatelessWidget with FletStoreMixin { debugPrint("PopupMenuButton build: ${control.id}"); var icon = parseIcon(control.attrString("icon")); - var iconSize = control.attrDouble("iconSize"); - var splashRadius = control.attrDouble("splashRadius"); - var elevation = control.attrDouble("elevation"); - var enableFeedback = control.attrBool("enableFeedback"); - var shape = parseOutlinedBorder(control, "shape") ?? - (Theme.of(context).useMaterial3 - ? RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)) - : null); - var clipBehavior = - parseClip(control.attrString("clipBehavior"), Clip.none)!; - var bgcolor = control.attrColor("bgcolor", context); - var iconColor = control.attrColor("iconColor", context); - var shadowColor = control.attrColor("shadowColor", context); - var surfaceTintColor = control.attrColor("surfaceTintColor", context); var contentCtrls = children.where((c) => c.name == "content" && c.isVisible); bool disabled = control.isDisabled || parentDisabled; - PopupMenuPosition? menuPosition = - parsePopupMenuPosition(control.attrString("menuPosition")); - Widget? child = contentCtrls.isNotEmpty ? createControl(control, contentCtrls.first.id, disabled) : null; @@ -63,18 +49,31 @@ class PopupMenuButtonControl extends StatelessWidget with FletStoreMixin { enabled: !disabled, tooltip: null, icon: icon != null ? Icon(icon) : null, - iconSize: iconSize, - splashRadius: splashRadius, - shadowColor: shadowColor, - surfaceTintColor: surfaceTintColor, - iconColor: iconColor, - elevation: elevation, - enableFeedback: enableFeedback, + iconSize: control.attrDouble("iconSize"), + splashRadius: control.attrDouble("splashRadius"), + shadowColor: control.attrColor("shadowColor", context), + surfaceTintColor: control.attrColor("surfaceTintColor", context), + iconColor: control.attrColor("iconColor", context), + elevation: control.attrDouble("elevation"), + enableFeedback: control.attrBool("enableFeedback"), padding: parseEdgeInsets(control, "padding", const EdgeInsets.all(8))!, - color: bgcolor, - clipBehavior: clipBehavior, - shape: shape, + color: control.attrColor("bgcolor", context), + clipBehavior: + parseClip(control.attrString("clipBehavior"), Clip.none)!, + shape: parseOutlinedBorder(control, "shape") ?? + (Theme.of(context).useMaterial3 + ? RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10)) + : null), + constraints: parseBoxConstraints(control, "sizeConstraints"), + style: parseButtonStyle(Theme.of(context), control, "style"), + popUpAnimationStyle: + parseAnimationStyle(control, "popupAnimationStyle"), + menuPadding: parseEdgeInsets(control, "menuPadding"), + onSelected: (String selection) { + backend.triggerControlEvent(control.id, "select", selection); + }, onCanceled: () { backend.triggerControlEvent(control.id, "cancel"); backend.triggerControlEvent(control.id, "cancelled"); // DEPRECATED @@ -82,7 +81,7 @@ class PopupMenuButtonControl extends StatelessWidget with FletStoreMixin { onOpened: () { backend.triggerControlEvent(control.id, "open"); }, - position: menuPosition, + position: parsePopupMenuPosition(control.attrString("menuPosition")), itemBuilder: (BuildContext context) => viewModel.controlViews.map((cv) { var itemIcon = parseIcon(cv.control.attrString("icon")); @@ -146,8 +145,7 @@ class PopupMenuButtonControl extends StatelessWidget with FletStoreMixin { return constrainedControl( context, TooltipVisibility( - visible: control.attrString("tooltip") == null, - child: popupButton), + visible: control.attrString("tooltip") == null, child: popupButton), parent, control); } diff --git a/packages/flet/lib/src/controls/progress_bar.dart b/packages/flet/lib/src/controls/progress_bar.dart index 2409d85c9..2e477d2d0 100644 --- a/packages/flet/lib/src/controls/progress_bar.dart +++ b/packages/flet/lib/src/controls/progress_bar.dart @@ -15,22 +15,15 @@ class ProgressBarControl extends StatelessWidget { Widget build(BuildContext context) { debugPrint("ProgressBar build: ${control.id}"); - var value = control.attrDouble("value"); - var semanticsValue = control.attrDouble("semanticsValue"); - var semanticsLabel = control.attrString("semanticsLabel"); - var barHeight = control.attrDouble("barHeight", 4)!; - var color = control.attrColor("color", context); - var bgColor = control.attrColor("bgColor", context); - return constrainedControl( context, LinearProgressIndicator( - value: value, - minHeight: barHeight, - color: color, - backgroundColor: bgColor, - semanticsLabel: semanticsLabel, - semanticsValue: semanticsValue.toString(), + value: control.attrDouble("value"), + minHeight: control.attrDouble("minHeight", 4)!, + color: control.attrColor("color", context), + backgroundColor: control.attrColor("bgColor", context), + semanticsLabel: control.attrString("semanticsLabel"), + semanticsValue: control.attrDouble("semanticsValue")?.toString(), borderRadius: parseBorderRadius(control, "borderRadius", BorderRadius.zero)!, ), diff --git a/packages/flet/lib/src/controls/progress_ring.dart b/packages/flet/lib/src/controls/progress_ring.dart index 02c210359..4a992218c 100644 --- a/packages/flet/lib/src/controls/progress_ring.dart +++ b/packages/flet/lib/src/controls/progress_ring.dart @@ -15,26 +15,17 @@ class ProgressRingControl extends StatelessWidget { Widget build(BuildContext context) { debugPrint("ProgressRing build: ${control.id}"); - var value = control.attrDouble("value"); - var semanticsValue = control.attrDouble("semanticsValue"); - var strokeAlign = control.attrDouble("strokeAlign", 0)!; - var semanticsLabel = control.attrString("semanticsLabel"); - var strokeCap = parseStrokeCap(control.attrString("strokeCap")); - var strokeWidth = control.attrDouble("strokeWidth", 4)!; - var color = control.attrColor("color", context); - var bgColor = control.attrColor("bgColor", context); - return constrainedControl( context, CircularProgressIndicator( - value: value, - strokeWidth: strokeWidth, - color: color, - backgroundColor: bgColor, - semanticsLabel: semanticsLabel, - strokeCap: strokeCap, - semanticsValue: semanticsValue.toString(), - strokeAlign: strokeAlign, + value: control.attrDouble("value"), + strokeWidth: control.attrDouble("strokeWidth", 4)!, + color: control.attrColor("color", context), + backgroundColor: control.attrColor("bgColor", context), + semanticsLabel: control.attrString("semanticsLabel"), + strokeCap: parseStrokeCap(control.attrString("strokeCap")), + semanticsValue: control.attrDouble("semanticsValue")?.toString(), + strokeAlign: control.attrDouble("strokeAlign", 0)!, ), parent, control); diff --git a/packages/flet/lib/src/controls/range_slider.dart b/packages/flet/lib/src/controls/range_slider.dart index 08374d82a..58fa7a61d 100644 --- a/packages/flet/lib/src/controls/range_slider.dart +++ b/packages/flet/lib/src/controls/range_slider.dart @@ -62,7 +62,6 @@ class _SliderControlState extends State { double min = widget.control.attrDouble("min", 0)!; double max = widget.control.attrDouble("max", 1)!; - int? divisions = widget.control.attrInt("divisions"); int round = widget.control.attrInt("round", 0)!; debugPrint("SliderControl build: ${widget.control.id}"); @@ -74,7 +73,7 @@ class _SliderControlState extends State { (label).replaceAll("{value}", endValue.toStringAsFixed(round))), min: min, max: max, - divisions: divisions, + divisions: widget.control.attrInt("divisions"), activeColor: widget.control.attrColor("activeColor", context), inactiveColor: widget.control.attrColor("inactiveColor", context), overlayColor: parseWidgetStateColor( diff --git a/packages/flet/lib/src/controls/search_anchor.dart b/packages/flet/lib/src/controls/search_anchor.dart index f62cc00f4..d74032552 100644 --- a/packages/flet/lib/src/controls/search_anchor.dart +++ b/packages/flet/lib/src/controls/search_anchor.dart @@ -105,14 +105,6 @@ class _SearchAnchorControlState extends State { var viewTrailingCtrls = widget.children.where((c) => c.name == "viewTrailing" && c.isVisible); - var viewBgcolor = widget.control.attrColor("viewBgcolor", context); - var dividerColor = widget.control.attrColor("dividerColor", context); - - TextStyle? viewHeaderTextStyle = parseTextStyle( - Theme.of(context), widget.control, "viewHeaderTextStyle"); - TextStyle? viewHintTextStyle = - parseTextStyle(Theme.of(context), widget.control, "viewHintTextStyle"); - var textCapitalization = parseTextCapitalization( widget.control.attrString("textCapitalization")); TextInputType keyboardType = parseTextInputType( @@ -158,13 +150,15 @@ class _SearchAnchorControlState extends State { Widget anchor = SearchAnchor( searchController: _controller, - headerHintStyle: viewHintTextStyle, - headerTextStyle: viewHeaderTextStyle, + headerHintStyle: parseTextStyle( + Theme.of(context), widget.control, "viewHintTextStyle"), + headerTextStyle: parseTextStyle( + Theme.of(context), widget.control, "viewHeaderTextStyle"), viewSide: parseBorderSide(Theme.of(context), widget.control, "viewSide"), isFullScreen: widget.control.attrBool("fullScreen", false), - viewBackgroundColor: viewBgcolor, - dividerColor: dividerColor, + viewBackgroundColor: widget.control.attrColor("viewBgcolor", context), + dividerColor: widget.control.attrColor("dividerColor", context), viewHintText: widget.control.attrString("viewHintText"), viewElevation: widget.control.attrDouble("viewElevation"), headerHeight: widget.control.attrDouble("viewHeaderHeight"), diff --git a/packages/flet/lib/src/controls/segmented_button.dart b/packages/flet/lib/src/controls/segmented_button.dart index 36588410d..a1edeb7a9 100644 --- a/packages/flet/lib/src/controls/segmented_button.dart +++ b/packages/flet/lib/src/controls/segmented_button.dart @@ -119,21 +119,20 @@ class _SegmentedButtonControlState extends State .where((c) => c.name == "icon" && c.isVisible); var labelCtrls = segmentView.children .where((c) => c.name == "label" && c.isVisible); - var enabled = !segmentView.control.attrBool("disabled", false)!; - + var segmentDisabled = segmentView.control.isDisabled || disabled; return ButtonSegment( value: segmentView.control.attrString("value")!, - enabled: enabled, - tooltip: enabled && !disabled + enabled: !segmentDisabled, + tooltip: !segmentDisabled ? segmentView.control.attrString("tooltip") : null, icon: iconCtrls.isNotEmpty - ? createControl( - segmentView.control, iconCtrls.first.id, disabled) + ? createControl(segmentView.control, iconCtrls.first.id, + segmentDisabled) : null, label: labelCtrls.isNotEmpty - ? createControl( - segmentView.control, labelCtrls.first.id, disabled) + ? createControl(segmentView.control, labelCtrls.first.id, + segmentDisabled) : null); }).toList()); }); diff --git a/packages/flet/lib/src/controls/selection_area.dart b/packages/flet/lib/src/controls/selection_area.dart index 22fd37086..d58f48893 100644 --- a/packages/flet/lib/src/controls/selection_area.dart +++ b/packages/flet/lib/src/controls/selection_area.dart @@ -34,13 +34,11 @@ class SelectionAreaControl extends StatelessWidget { } bool disabled = control.isDisabled || parentDisabled; - Widget child = createControl(control, contentCtrls.first.id, disabled, - parentAdaptive: parentAdaptive); - return baseControl( context, SelectionArea( - child: child, + child: createControl(control, contentCtrls.first.id, disabled, + parentAdaptive: parentAdaptive), onSelectionChanged: (selection) { backend.triggerControlEvent( control.id, "change", selection?.plainText ?? ""); diff --git a/packages/flet/lib/src/controls/snack_bar.dart b/packages/flet/lib/src/controls/snack_bar.dart index f9091ee80..5a557e412 100644 --- a/packages/flet/lib/src/controls/snack_bar.dart +++ b/packages/flet/lib/src/controls/snack_bar.dart @@ -55,8 +55,6 @@ class _SnackBarControlState extends State { widget.backend.triggerControlEvent(widget.control.id, "action"); }) : null; - var clipBehavior = - parseClip(widget.control.attrString("clipBehavior"), Clip.hardEdge)!; SnackBarBehavior? behavior = parseSnackBarBehavior(widget.control.attrString("behavior")); @@ -77,7 +75,8 @@ class _SnackBarControlState extends State { return SnackBar( behavior: behavior, - clipBehavior: clipBehavior, + clipBehavior: parseClip( + widget.control.attrString("clipBehavior"), Clip.hardEdge)!, actionOverflowThreshold: widget.control.attrDouble("actionOverflowThreshold"), shape: parseOutlinedBorder(widget.control, "shape"), diff --git a/packages/flet/lib/src/controls/submenu_button.dart b/packages/flet/lib/src/controls/submenu_button.dart index 7263761d9..738f5c335 100644 --- a/packages/flet/lib/src/controls/submenu_button.dart +++ b/packages/flet/lib/src/controls/submenu_button.dart @@ -67,7 +67,7 @@ class _SubMenuButtonControlState extends State { var clipBehavior = parseClip(widget.control.attrString("clipBehavior"), Clip.hardEdge)!; - var offsetDetails = parseOffset(widget.control, "alignmentOffset"); + var offset = parseOffset(widget.control, "alignmentOffset"); var theme = Theme.of(context); var style = parseButtonStyle(Theme.of(context), widget.control, "style", @@ -95,9 +95,7 @@ class _SubMenuButtonControlState extends State { clipBehavior: clipBehavior, style: style, menuStyle: menuStyle, - alignmentOffset: offsetDetails != null - ? Offset(offsetDetails.x, offsetDetails.y) - : null, + alignmentOffset: offset, onClose: onClose && !disabled ? () { widget.backend.triggerControlEvent(widget.control.id, "close"); diff --git a/packages/flet/lib/src/controls/tabs.dart b/packages/flet/lib/src/controls/tabs.dart index 0db47574e..7fbd2e2e5 100644 --- a/packages/flet/lib/src/controls/tabs.dart +++ b/packages/flet/lib/src/controls/tabs.dart @@ -110,8 +110,8 @@ class _TabsControlState extends State } // check if all tabs have no content - bool emptyTabs = !viewModel.controlViews - .any((t) => t.children.any((c) => c.name == "content")); + bool emptyTabs = !viewModel.controlViews.any( + (t) => t.children.any((c) => c.name == "content" && c.isVisible)); var overlayColorStr = widget.control.attrString("overlayColor"); dynamic overlayColor; @@ -200,32 +200,34 @@ class _TabsControlState extends State : TabBarTheme.of(context).indicatorSize; var tabs = viewModel.controlViews.map((tabView) { - var text = tabView.control.attrString("text"); - var icon = parseIcon(tabView.control.attrString("icon")); + var iconString = parseIcon(tabView.control.attrString("icon")); + var iconContentCtrls = tabView.children + .where((c) => c.name == "icon_content" && c.isVisible); + + var icon = iconContentCtrls.isNotEmpty + ? createControl( + widget.control, iconContentCtrls.first.id, disabled, + parentAdaptive: adaptive) + : iconString != null + ? Icon(iconString) + : null; var tabContentCtrls = tabView.children .where((c) => c.name == "tab_content" && c.isVisible); - Widget tabChild; - List widgets = []; if (tabContentCtrls.isNotEmpty) { - tabChild = createControl( - widget.control, tabContentCtrls.first.id, disabled, - parentAdaptive: adaptive); + return Tab( + child: createControl( + widget.control, tabContentCtrls.first.id, disabled, + parentAdaptive: adaptive)); } else { - if (icon != null) { - widgets.add(Icon(icon)); - if (text != null) { - widgets.add(const SizedBox(width: 8)); - } - } - if (text != null) { - widgets.add(Text(text)); - } - tabChild = Row( - mainAxisAlignment: MainAxisAlignment.center, - children: widgets); + return Tab( + text: tabView.control + .attrString("text", icon == null ? "" : null), + icon: icon, + height: tabView.control.attrDouble("height"), + iconMargin: parseEdgeInsets(tabView.control, "iconMargin"), + ); } - return Tab(child: tabChild); }).toList(); TabBar? tabBar; diff --git a/packages/flet/lib/src/controls/text.dart b/packages/flet/lib/src/controls/text.dart index dd191878e..6cf810e94 100644 --- a/packages/flet/lib/src/controls/text.dart +++ b/packages/flet/lib/src/controls/text.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:flutter/material.dart'; import '../flet_control_backend.dart'; @@ -28,6 +30,14 @@ class TextControl extends StatelessWidget with FletStoreMixin { bool disabled = control.isDisabled || parentDisabled; String text = control.attrString("value", "")!; + var selectionCursorColor = + control.attrColor("selectionCursorColor", context); + var selectionCursorWidth = + control.attrDouble("selectionCursorWidth", 2.0)!; + var selectionCursorHeight = control.attrDouble("selectionCursorHeight"); + var showSelectionCursor = control.attrBool("showSelectionCursor", false)!; + var enableInteractiveSelection = + control.attrBool("enableInteractiveSelection", true)!; List? spans = parseTextSpans( Theme.of(context), @@ -98,12 +108,49 @@ class TextControl extends StatelessWidget with FletStoreMixin { TextOverflow overflow = parseTextOverflow(control.attrString("overflow"), TextOverflow.clip)!; + onSelectionChanged( + TextSelection selection, SelectionChangedCause? cause) { + debugPrint("Text ${control.id} selection changed"); + backend.triggerControlEvent( + control.id, + "selection_change", + jsonEncode({ + "text": text ?? "", + "start": selection.start, + "end": selection.end, + "base_offset": selection.baseOffset, + "extent_offset": selection.extentOffset, + "affinity": selection.affinity.name, + "directional": selection.isDirectional, + "collapsed": selection.isCollapsed, + "valid": selection.isValid, + "normalized": selection.isNormalized, + "cause": cause?.name ?? "unknown", + })); + } + + onTap() { + debugPrint("Text ${control.id} selection changed"); + backend.triggerControlEvent( + control.id, + "selection_change", + ); + } + return control.attrBool("selectable", false)! ? (spans.isNotEmpty) ? SelectableText.rich( TextSpan(text: text, style: style, children: spans), maxLines: maxLines, textAlign: textAlign, + cursorColor: selectionCursorColor, + cursorHeight: selectionCursorHeight, + cursorWidth: selectionCursorWidth, + semanticsLabel: semanticsLabel, + showCursor: showSelectionCursor, + enableInteractiveSelection: enableInteractiveSelection, + onSelectionChanged: onSelectionChanged, + onTap: onTap, ) : SelectableText( text, @@ -111,6 +158,13 @@ class TextControl extends StatelessWidget with FletStoreMixin { maxLines: maxLines, style: style, textAlign: textAlign, + cursorColor: selectionCursorColor, + cursorHeight: selectionCursorHeight, + cursorWidth: selectionCursorWidth, + showCursor: showSelectionCursor, + enableInteractiveSelection: enableInteractiveSelection, + onSelectionChanged: onSelectionChanged, + onTap: onTap, ) : (spans.isNotEmpty) ? Text.rich( diff --git a/packages/flet/lib/src/controls/textfield.dart b/packages/flet/lib/src/controls/textfield.dart index ede8c28b6..ecd59d522 100644 --- a/packages/flet/lib/src/controls/textfield.dart +++ b/packages/flet/lib/src/controls/textfield.dart @@ -5,7 +5,11 @@ import '../flet_control_backend.dart'; import '../models/control.dart'; import '../utils/autofill.dart'; import '../utils/borders.dart'; +import '../utils/edge_insets.dart'; import '../utils/form_field.dart'; +import '../utils/mouse.dart'; +import '../utils/others.dart'; +import '../utils/overlay_style.dart'; import '../utils/text.dart'; import '../utils/textfield.dart'; import 'create_control.dart'; @@ -124,15 +128,21 @@ class _TextFieldControlState extends State var prefixControls = widget.children.where((c) => c.name == "prefix" && c.isVisible); var prefixIconControls = - widget.children.where((c) => c.name == "prefixIcon" && c.isVisible); + widget.children.where((c) => c.name == "prefix_icon" && c.isVisible); var suffixControls = widget.children.where((c) => c.name == "suffix" && c.isVisible); var suffixIconControls = - widget.children.where((c) => c.name == "suffixIcon" && c.isVisible); + widget.children.where((c) => c.name == "suffix_icon" && c.isVisible); var iconControls = widget.children.where((c) => c.name == "icon" && c.isVisible); var counterControls = widget.children.where((c) => c.name == "counter" && c.isVisible); + var errorCtrl = + widget.children.where((c) => c.name == "error" && c.isVisible); + var helperCtrl = + widget.children.where((c) => c.name == "helper" && c.isVisible); + var labelCtrl = + widget.children.where((c) => c.name == "label" && c.isVisible); bool shiftEnter = widget.control.attrBool("shiftEnter", false)!; bool multiline = @@ -140,19 +150,12 @@ class _TextFieldControlState extends State int minLines = widget.control.attrInt("minLines", 1)!; int? maxLines = widget.control.attrInt("maxLines", multiline ? null : 1); - bool readOnly = widget.control.attrBool("readOnly", false)!; bool password = widget.control.attrBool("password", false)!; bool canRevealPassword = widget.control.attrBool("canRevealPassword", false)!; - bool onChange = widget.control.attrBool("onChange", false)!; - var cursorColor = widget.control.attrColor("cursorColor", context); var selectionColor = widget.control.attrColor("selectionColor", context); - - int? maxLength = widget.control.attrInt("maxLength"); - var textSize = widget.control.attrDouble("textSize"); - var color = widget.control.attrColor("color", context); var focusedColor = widget.control.attrColor("focusedColor", context); @@ -193,23 +196,9 @@ class _TextFieldControlState extends State }); } - TextInputType keyboardType = multiline - ? TextInputType.multiline - : parseTextInputType( - widget.control.attrString("keyboardType"), TextInputType.text)!; - - TextAlign textAlign = parseTextAlign( - widget.control.attrString("textAlign"), TextAlign.start)!; - double? textVerticalAlign = widget.control.attrDouble("textVerticalAlign"); - bool autocorrect = widget.control.attrBool("autocorrect", true)!; - bool enableSuggestions = - widget.control.attrBool("enableSuggestions", true)!; - bool smartDashesType = widget.control.attrBool("smartDashesType", true)!; - bool smartQuotesType = widget.control.attrBool("smartQuotesType", true)!; - FocusNode focusNode = shiftEnter ? _shiftEnterfocusNode : _focusNode; var focusValue = widget.control.attrString("focus"); @@ -217,6 +206,7 @@ class _TextFieldControlState extends State _lastFocusValue = focusValue; focusNode.requestFocus(); } + var fitParentSize = widget.control.attrBool("fitParentSize", false)!; Widget textField = TextFormField( style: textStyle, @@ -230,12 +220,19 @@ class _TextFieldControlState extends State : null, decoration: buildInputDecoration(context, widget.control, prefix: prefixControls.isNotEmpty ? prefixControls.first : null, - prefixIcon: prefixIconControls.isNotEmpty ? prefixIconControls.first : null, + prefixIcon: prefixIconControls.isNotEmpty + ? prefixIconControls.first + : null, suffix: suffixControls.isNotEmpty ? suffixControls.first : null, - suffixIcon: suffixIconControls.isNotEmpty ? suffixIconControls.first : null, + suffixIcon: suffixIconControls.isNotEmpty + ? suffixIconControls.first + : null, icon: iconControls.isNotEmpty ? iconControls.first : null, counter: counterControls.isNotEmpty ? counterControls.first : null, + error: errorCtrl.isNotEmpty ? errorCtrl.first : null, + helper: helperCtrl.isNotEmpty ? helperCtrl.first : null, + label: labelCtrl.isNotEmpty ? labelCtrl.first : null, customSuffix: revealPasswordIcon, focused: _focused, disabled: disabled, @@ -247,31 +244,64 @@ class _TextFieldControlState extends State cursorHeight: widget.control.attrDouble("cursorHeight"), cursorWidth: widget.control.attrDouble("cursorWidth", 2.0)!, cursorRadius: parseRadius(widget.control, "cursorRadius"), - keyboardType: keyboardType, - autocorrect: autocorrect, - enableSuggestions: enableSuggestions, - smartDashesType: smartDashesType + keyboardType: multiline + ? TextInputType.multiline + : parseTextInputType(widget.control.attrString("keyboardType"), + TextInputType.text)!, + autocorrect: widget.control.attrBool("autocorrect", true)!, + enableSuggestions: + widget.control.attrBool("enableSuggestions", true)!, + smartDashesType: widget.control.attrBool("smartDashesType", true)! ? SmartDashesType.enabled : SmartDashesType.disabled, - smartQuotesType: smartQuotesType + smartQuotesType: widget.control.attrBool("smartQuotesType", true)! ? SmartQuotesType.enabled : SmartQuotesType.disabled, - textAlign: textAlign, - minLines: minLines, - maxLines: maxLines, - maxLength: maxLength, - readOnly: readOnly, + textAlign: parseTextAlign( + widget.control.attrString("textAlign"), TextAlign.start)!, + minLines: fitParentSize ? null : minLines, + maxLines: fitParentSize ? null : maxLines, + maxLength: widget.control.attrInt("maxLength"), + readOnly: widget.control.attrBool("readOnly", false)!, inputFormatters: inputFormatters.isNotEmpty ? inputFormatters : null, obscureText: password && !_revealPassword, controller: _controller, focusNode: focusNode, autofillHints: parseAutofillHints(widget.control, "autofillHints"), + expands: fitParentSize, + enableInteractiveSelection: + widget.control.attrBool("enableInteractiveSelection"), + canRequestFocus: widget.control.attrBool("canRequestFocus", true)!, + clipBehavior: parseClip( + widget.control.attrString("clipBehavior"), Clip.hardEdge)!, + cursorColor: cursorColor, + ignorePointers: widget.control.attrBool("ignorePointers"), + cursorErrorColor: + widget.control.attrColor("cursorErrorColor", context), + scribbleEnabled: widget.control.attrBool("enableScribble", true)!, + scrollPadding: parseEdgeInsets( + widget.control, "scrollPadding", const EdgeInsets.all(20.0))!, + keyboardAppearance: + parseBrightness(widget.control.attrString("keyboardBrightness")), + enableIMEPersonalizedLearning: + widget.control.attrBool("enableIMEPersonalizedLearning", true)!, + obscuringCharacter: + widget.control.attrString("obscuringCharacter", '•')!, + mouseCursor: + parseMouseCursor(widget.control.attrString("mouseCursor")), + cursorOpacityAnimates: widget.control.attrBool("animateCursorOpacity", + Theme.of(context).platform == TargetPlatform.iOS)!, + onTapAlwaysCalled: + widget.control.attrBool("animateCursorOpacity", false)!, + strutStyle: parseStrutStyle(widget.control, "strutStyle"), + onTap: () { + widget.backend.triggerControlEvent(widget.control.id, "click"); + }, onChanged: (String value) { - //debugPrint(value); _value = value; widget.backend .updateControlState(widget.control.id, {"value": value}); - if (onChange) { + if (widget.control.attrBool("onChange", false)!) { widget.backend .triggerControlEvent(widget.control.id, "change", value); } @@ -376,7 +406,8 @@ class CustomNumberFormatter extends TextInputFormatter { CustomNumberFormatter(this.pattern); @override - TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) { + TextEditingValue formatEditUpdate( + TextEditingValue oldValue, TextEditingValue newValue) { final regExp = RegExp(pattern); if (regExp.hasMatch(newValue.text)) { return newValue; @@ -384,4 +415,4 @@ class CustomNumberFormatter extends TextInputFormatter { // If newValue is invalid, keep the old value return oldValue; } -} \ No newline at end of file +} diff --git a/packages/flet/lib/src/controls/vertical_divider.dart b/packages/flet/lib/src/controls/vertical_divider.dart index 06f80b0e7..43e1c0ddf 100644 --- a/packages/flet/lib/src/controls/vertical_divider.dart +++ b/packages/flet/lib/src/controls/vertical_divider.dart @@ -14,20 +14,14 @@ class VerticalDividerControl extends StatelessWidget { Widget build(BuildContext context) { debugPrint("VerticalDivider build: ${control.id}"); - var width = control.attrDouble("width"); - var thickness = control.attrDouble("thickness"); - var leadingIndent = control.attrDouble("leadingIndent"); - var trailingIndent = control.attrDouble("trailingIndent"); - var color = control.attrColor("color", context); - return baseControl( context, VerticalDivider( - width: width, - thickness: thickness, - color: color, - indent: leadingIndent, - endIndent: trailingIndent, + width: control.attrDouble("width"), + thickness: control.attrDouble("thickness"), + color: control.attrColor("color", context), + indent: control.attrDouble("leadingIndent"), + endIndent: control.attrDouble("trailingIndent"), ), parent, control); diff --git a/packages/flet/lib/src/utils/animations.dart b/packages/flet/lib/src/utils/animations.dart index 60e8cf606..5498ef945 100644 --- a/packages/flet/lib/src/utils/animations.dart +++ b/packages/flet/lib/src/utils/animations.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import '../models/control.dart'; import 'numbers.dart'; +import 'time.dart'; ImplicitAnimationDetails? parseAnimation(Control control, String propName, [ImplicitAnimationDetails? defaultValue]) { @@ -130,3 +131,27 @@ Curve? parseCurve(String? value, [Curve? defValue]) { return defValue; } } + +AnimationStyle? parseAnimationStyle(Control control, String propName, + [AnimationStyle? defaultValue]) { + var v = control.attrString(propName, null); + if (v == null) { + return defaultValue; + } + + final j1 = json.decode(v); + return animationStyleFromJSON(j1); +} + +AnimationStyle animationStyleFromJSON(dynamic json, + [AnimationStyle? defaultValue]) { + if (json == null) { + return defaultValue!; + } + + return AnimationStyle( + curve: parseCurve(json["curve"]), + reverseCurve: parseCurve(json["reverse_curve"]), + duration: durationFromJSON(json["duration"]), + reverseDuration: durationFromJSON(json["reverse_duration"])); +} diff --git a/packages/flet/lib/src/utils/box.dart b/packages/flet/lib/src/utils/box.dart index 4d92b7227..e99b3c066 100644 --- a/packages/flet/lib/src/utils/box.dart +++ b/packages/flet/lib/src/utils/box.dart @@ -36,25 +36,27 @@ BoxConstraints? boxConstraintsFromJSON(dynamic json, return BoxConstraints( minHeight: parseDouble(json["min_height"], 0.0)!, minWidth: parseDouble(json["min_width"], 0.0)!, - maxHeight: parseDouble(json["max_height"], 0.0)!, - maxWidth: parseDouble(json["max_width"], 0.0)!, + maxHeight: parseDouble(json["max_height"], double.infinity)!, + maxWidth: parseDouble(json["max_width"], double.infinity)!, ); } -List parseBoxShadow( - ThemeData theme, Control control, String propName) { +List? parseBoxShadow( + ThemeData theme, Control control, String propName, + [List? defValue]) { var v = control.attrString(propName); if (v == null) { - return []; + return defValue; } final j1 = json.decode(v); return boxShadowsFromJSON(theme, j1); } -List boxShadowsFromJSON(ThemeData theme, dynamic json) { +List? boxShadowsFromJSON(ThemeData theme, dynamic json, + [List? defValue]) { if (json == null) { - return []; + return defValue; } if (json is List) { return json.map((e) => boxShadowFromJSON(theme, e)).toList(); @@ -64,7 +66,8 @@ List boxShadowsFromJSON(ThemeData theme, dynamic json) { } BoxShadow boxShadowFromJSON(ThemeData theme, dynamic json) { - var offset = json["offset"] != null ? offsetFromJSON(json["offset"]) : null; + var offset = + json["offset"] != null ? offsetDetailsFromJSON(json["offset"]) : null; return BoxShadow( color: parseColor(theme, json["color"], const Color(0xFF000000))!, offset: offset != null ? Offset(offset.x, offset.y) : Offset.zero, diff --git a/packages/flet/lib/src/utils/buttons.dart b/packages/flet/lib/src/utils/buttons.dart index f35f27722..7424234f5 100644 --- a/packages/flet/lib/src/utils/buttons.dart +++ b/packages/flet/lib/src/utils/buttons.dart @@ -15,15 +15,15 @@ import 'text.dart'; import 'theme.dart'; ButtonStyle? parseButtonStyle(ThemeData theme, Control control, String propName, - {required Color defaultForegroundColor, - required Color defaultBackgroundColor, - required Color defaultOverlayColor, - required Color defaultShadowColor, - required Color defaultSurfaceTintColor, - required double defaultElevation, - required EdgeInsets defaultPadding, - required BorderSide defaultBorderSide, - required OutlinedBorder defaultShape}) { + {Color? defaultForegroundColor, + Color? defaultBackgroundColor, + Color? defaultOverlayColor, + Color? defaultShadowColor, + Color? defaultSurfaceTintColor, + double? defaultElevation, + EdgeInsets? defaultPadding, + BorderSide? defaultBorderSide, + OutlinedBorder? defaultShape}) { var v = control.attrString(propName, null); if (v == null) { return null; @@ -119,10 +119,10 @@ FloatingActionButtonLocation parseFloatingActionButtonLocation( }; try { - OffsetDetails? fabLocationOffsetDetails = parseOffset(control, propName); - if (fabLocationOffsetDetails != null) { + var fabLocationOffset = parseOffset(control, propName); + if (fabLocationOffset != null) { return CustomFloatingActionButtonLocation( - dx: fabLocationOffsetDetails.x, dy: fabLocationOffsetDetails.y); + dx: fabLocationOffset.dx, dy: fabLocationOffset.dy); } else { return defValue; } diff --git a/packages/flet/lib/src/utils/form_field.dart b/packages/flet/lib/src/utils/form_field.dart index 2db9645ea..7b4f4c3f7 100644 --- a/packages/flet/lib/src/utils/form_field.dart +++ b/packages/flet/lib/src/utils/form_field.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:collection/collection.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -5,9 +7,12 @@ import 'package:flutter/material.dart'; import '../controls/create_control.dart'; import '../models/control.dart'; import 'borders.dart'; +import 'box.dart'; import 'edge_insets.dart'; import 'icons.dart'; +import 'numbers.dart'; import 'text.dart'; +import 'time.dart'; enum FormFieldInputBorder { outline, underline, none } @@ -50,29 +55,36 @@ TextInputType? parseTextInputType(String? value, [TextInputType? defValue]) { } } -InputDecoration buildInputDecoration( - BuildContext context, - Control control, +InputDecoration buildInputDecoration(BuildContext context, Control control, {Control? prefix, Control? prefixIcon, Control? suffix, Control? suffixIcon, Control? icon, Control? counter, + Control? error, + Control? helper, + Control? label, Widget? customSuffix, bool focused = false, bool disabled = false, bool? adaptive}) { - String? label = control.attrString("label", "")!; FormFieldInputBorder inputBorder = parseFormFieldInputBorder( control.attrString("border"), FormFieldInputBorder.outline, )!; var iconStr = parseIcon(control.attrString("icon")); - - var prefixIconStr = parseIcon(control.attrString("prefixIcon")); + var prefixIconData = parseIcon(control.attrString("prefixIcon")); + var prefixIconWidget = prefixIcon != null + ? createControl(control, prefixIcon.id, control.isDisabled, + parentAdaptive: adaptive) + : (prefixIconData != null ? Icon(prefixIconData) : null); + var suffixIconData = parseIcon(control.attrString("suffixIcon")); + var suffixIconWidget = suffixIcon != null + ? createControl(control, suffixIcon.id, control.isDisabled, + parentAdaptive: adaptive) + : (suffixIconData != null ? Icon(suffixIconData) : null); var prefixText = control.attrString("prefixText"); - var suffixIconStr = parseIcon(control.attrString("suffixIcon")); var suffixText = control.attrString("suffixText"); var bgcolor = control.attrColor("bgcolor", context); @@ -130,7 +142,10 @@ InputDecoration buildInputDecoration( enabled: !disabled, contentPadding: parseEdgeInsets(control, "contentPadding"), isDense: control.attrBool("dense"), - label: label != "" ? Text(label) : null, + label: label != null + ? createControl(control, label.id, control.isDisabled, + parentAdaptive: adaptive) + : Text(control.attrString("label", "")!), labelStyle: parseTextStyle(Theme.of(context), control, "labelStyle"), border: border, enabledBorder: border, @@ -139,7 +154,9 @@ InputDecoration buildInputDecoration( icon: icon != null ? createControl(control, icon.id, control.isDisabled, parentAdaptive: adaptive) - : iconStr !=null? Icon(iconStr): null, + : iconStr != null + ? Icon(iconStr) + : null, filled: control.attrBool("filled", false)!, fillColor: fillColor ?? (focused ? focusedBgcolor ?? bgcolor : bgcolor), hintText: control.attrString("hintText"), @@ -152,15 +169,31 @@ InputDecoration buildInputDecoration( ? createControl(control, counter.id, control.isDisabled, parentAdaptive: adaptive) : null, - errorText: control.attrString("errorText") != "" - ? control.attrString("errorText") + error: error != null + ? createControl(control, error.id, control.isDisabled, + parentAdaptive: adaptive) + : null, + helper: helper != null + ? createControl(control, helper.id, control.isDisabled, + parentAdaptive: adaptive) : null, + constraints: parseBoxConstraints(control, "sizeConstraints"), + isCollapsed: control.attrBool("collapsed"), + prefixIconConstraints: + parseBoxConstraints(control, "prefixIconConstraints"), + suffixIconConstraints: + parseBoxConstraints(control, "suffixIconConstraints"), + focusColor: control.attrColor("focusColor", context), + errorMaxLines: control.attrInt("errorMaxLines"), + alignLabelWithHint: control.attrBool("alignLabelWithHint"), + errorText: control.attrString("errorText"), errorStyle: parseTextStyle(Theme.of(context), control, "errorStyle"), - prefixIcon: prefixIcon != null - ? createControl(control, prefixIcon.id, control.isDisabled, - parentAdaptive: adaptive) - : prefixIconStr !=null? Icon(prefixIconStr): null, - prefixText: prefixText, + prefixIcon: prefixIconWidget, + prefixText: + prefix == null ? prefixText : null, // ignored if prefix is set + hintFadeDuration: parseDuration(control, "hintFadeDuration"), + hintMaxLines: control.attrInt("hintMaxLines"), + helperMaxLines: control.attrInt("helperMaxLines"), prefixStyle: parseTextStyle(Theme.of(context), control, "prefixStyle"), prefix: prefix != null ? createControl(control, prefix.id, control.isDisabled, @@ -170,17 +203,15 @@ InputDecoration buildInputDecoration( ? createControl(control, suffix.id, control.isDisabled, parentAdaptive: adaptive) : null, - suffixIcon: suffixIcon != null - ? createControl(control, suffixIcon.id, control.isDisabled, - parentAdaptive: adaptive) - : suffixIconStr !=null? Icon(suffixIconStr): customSuffix, - suffixText: suffixText, - suffixStyle: parseTextStyle(Theme.of(context), control, "suffixStyle"), - ); + suffixIcon: suffixIconWidget ?? customSuffix, + suffixText: + suffix == null ? suffixText : null, // ignored if suffix is set + suffixStyle: parseTextStyle(Theme.of(context), control, "suffixStyle")); } -OverlayVisibilityMode parseVisibilityMode(String type) { - switch (type.toLowerCase()) { +OverlayVisibilityMode? parseVisibilityMode(String? type, + [OverlayVisibilityMode? defValue]) { + switch (type?.toLowerCase()) { case "never": return OverlayVisibilityMode.never; case "notediting": @@ -190,5 +221,31 @@ OverlayVisibilityMode parseVisibilityMode(String type) { case "always": return OverlayVisibilityMode.always; } - return OverlayVisibilityMode.always; + return defValue; +} + +StrutStyle? parseStrutStyle(Control control, String propName) { + dynamic j; + var v = control.attrString(propName, null); + if (v == null) { + return null; + } + j = json.decode(v); + return strutStyleFromJson(j); +} + +StrutStyle? strutStyleFromJson(Map? json) { + if (json == null) { + return null; + } + + return StrutStyle( + fontSize: parseDouble(json["size"]), + fontWeight: getFontWeight(json["weight"]), + fontStyle: parseBool(json["italic"], false)! ? FontStyle.italic : null, + fontFamily: json["font_family"], + height: parseDouble(json["height"]), + leading: parseDouble(json["leading"]), + forceStrutHeight: parseBool(json["force_strut_height"]), + ); } diff --git a/packages/flet/lib/src/utils/numbers.dart b/packages/flet/lib/src/utils/numbers.dart index 6ce9d231b..bb3e142b1 100644 --- a/packages/flet/lib/src/utils/numbers.dart +++ b/packages/flet/lib/src/utils/numbers.dart @@ -8,6 +8,8 @@ import 'material_state.dart'; double? parseDouble(dynamic v, [double? defValue]) { if (v is double) { return v; + } else if (v is String && v.toLowerCase() == "inf") { + return double.infinity; } else if (v == null) { return defValue; } else { diff --git a/packages/flet/lib/src/utils/others.dart b/packages/flet/lib/src/utils/others.dart index d49402114..fcde2a1ce 100644 --- a/packages/flet/lib/src/utils/others.dart +++ b/packages/flet/lib/src/utils/others.dart @@ -1,3 +1,5 @@ +import 'dart:ui'; + import 'package:collection/collection.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -237,3 +239,13 @@ Axis? parseAxis(String? value, [Axis? defValue]) { (e) => e.name.toLowerCase() == value.toLowerCase()) ?? defValue; } + +PointerDeviceKind? parsePointerDeviceKind(String? value, + [PointerDeviceKind? defValue]) { + if (value == null) { + return defValue; + } + return PointerDeviceKind.values.firstWhereOrNull( + (e) => e.name.toLowerCase() == value.toLowerCase()) ?? + defValue; +} diff --git a/packages/flet/lib/src/utils/text.dart b/packages/flet/lib/src/utils/text.dart index ac178b5b4..1bb494ab1 100644 --- a/packages/flet/lib/src/utils/text.dart +++ b/packages/flet/lib/src/utils/text.dart @@ -103,6 +103,8 @@ InlineSpan? parseInlineSpan( return TextSpan( text: spanViewModel.control.attrString("text"), style: parseTextStyle(theme, spanViewModel.control, "style"), + spellOut: spanViewModel.control.attrBool("spellOut"), + semanticsLabel: spanViewModel.control.attrString("semanticsLabel"), children: parseTextSpans( theme, spanViewModel, parentDisabled, sendControlEvent), mouseCursor: onClick && !disabled && sendControlEvent != null diff --git a/packages/flet/lib/src/utils/transforms.dart b/packages/flet/lib/src/utils/transforms.dart index ee1554c36..02eb1491e 100644 --- a/packages/flet/lib/src/utils/transforms.dart +++ b/packages/flet/lib/src/utils/transforms.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import '../models/control.dart'; @@ -14,10 +15,13 @@ RotationDetails? parseRotate(Control control, String propName, } final j1 = json.decode(v); - return rotateFromJSON(j1); + return rotateFromJSON(j1, defaultValue); } -RotationDetails rotateFromJSON(dynamic json) { +RotationDetails rotateFromJSON(dynamic json, [RotationDetails? defaultValue]) { + if (json == null) { + return defaultValue!; + } if (json is int || json is double) { return RotationDetails( angle: parseDouble(json, 0)!, alignment: Alignment.center); @@ -34,10 +38,13 @@ ScaleDetails? parseScale(Control control, String propName, } final j1 = json.decode(v); - return scaleFromJSON(j1); + return scaleFromJSON(j1, defaultValue); } -ScaleDetails scaleFromJSON(dynamic json) { +ScaleDetails? scaleFromJSON(dynamic json, [ScaleDetails? defaultValue]) { + if (json == null) { + return defaultValue; + } if (json is int || json is double) { return ScaleDetails( scale: parseDouble(json), @@ -49,31 +56,36 @@ ScaleDetails scaleFromJSON(dynamic json) { return ScaleDetails.fromJson(json); } -OffsetDetails? parseOffset(Control control, String propName, - [OffsetDetails? defaultValue]) { +Offset? parseOffset(Control control, String propName, [Offset? defaultValue]) { var v = control.attrString(propName, null); if (v == null) { return defaultValue; } final j1 = json.decode(v); - return offsetFromJSON(j1); + return offsetFromJSON(j1, defaultValue); +} + +Offset? offsetFromJSON(dynamic json, [Offset? defaultValue]) { + if (json == null) { + return defaultValue; + } + var details = offsetDetailsFromJSON(json); + return Offset(details.x, details.y); } -List? parseOffsetList(Control control, String propName) { +List? parseOffsetList(Control control, String propName, + [List? defaultValue]) { var v = control.attrString(propName, null); if (v == null) { - return null; + return defaultValue; } final j1 = json.decode(v); - return (j1 as List).map((e) { - var d = offsetFromJSON(e); - return Offset(d.x, d.y); - }).toList(); + return (j1 as List).map((e) => offsetFromJSON(e)).whereNotNull().toList(); } -OffsetDetails offsetFromJSON(dynamic json) { +OffsetDetails offsetDetailsFromJSON(dynamic json) { return OffsetDetails.fromJson(json); } diff --git a/sdk/python/packages/flet-core/src/flet_core/__init__.py b/sdk/python/packages/flet-core/src/flet_core/__init__.py index 93ba497c3..942148c97 100644 --- a/sdk/python/packages/flet-core/src/flet_core/__init__.py +++ b/sdk/python/packages/flet-core/src/flet_core/__init__.py @@ -398,6 +398,7 @@ Orientation, PaddingValue, PagePlatform, + PointerDeviceType, ScrollMode, StrokeCap, StrokeJoin, diff --git a/sdk/python/packages/flet-core/src/flet_core/animated_switcher.py b/sdk/python/packages/flet-core/src/flet_core/animated_switcher.py index 3cb4c6aab..f1ac94c75 100644 --- a/sdk/python/packages/flet-core/src/flet_core/animated_switcher.py +++ b/sdk/python/packages/flet-core/src/flet_core/animated_switcher.py @@ -1,14 +1,13 @@ from enum import Enum from typing import Any, Optional, Union -from flet_core.animation import AnimationCurve +from flet_core.animation import AnimationCurve, AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -106,12 +105,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/animation.py b/sdk/python/packages/flet-core/src/flet_core/animation.py index d11bdb2f4..f50787f9f 100644 --- a/sdk/python/packages/flet-core/src/flet_core/animation.py +++ b/sdk/python/packages/flet-core/src/flet_core/animation.py @@ -1,6 +1,8 @@ from dataclasses import dataclass, field from enum import Enum -from typing import Optional +from typing import Optional, Union + +from flet_core.types import DurationValue try: from typing import Literal @@ -59,5 +61,16 @@ class Animation: curve: Optional[AnimationCurve] = field(default=None) +@dataclass +class AnimationStyle: + duration: DurationValue = None + reverse_duration: DurationValue = None + curve: Optional[AnimationCurve] = None + reverse_curve: Optional[AnimationCurve] = None + + def implicit(duration: int, curve: Optional[AnimationCurve] = None): return Animation(duration=duration, curve=curve) + + +AnimationValue = Union[bool, int, Animation] diff --git a/sdk/python/packages/flet-core/src/flet_core/bottom_app_bar.py b/sdk/python/packages/flet-core/src/flet_core/bottom_app_bar.py index 6d426e25b..edab64270 100644 --- a/sdk/python/packages/flet-core/src/flet_core/bottom_app_bar.py +++ b/sdk/python/packages/flet-core/src/flet_core/bottom_app_bar.py @@ -1,18 +1,18 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.types import ( - AnimationValue, ClipBehavior, NotchShape, OffsetValue, + OptionalControlEventCallable, PaddingValue, ResponsiveNumber, RotateValue, ScaleValue, - OptionalControlEventCallable, ) @@ -54,12 +54,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/box.py b/sdk/python/packages/flet-core/src/flet_core/box.py index 80243a52c..703a7da06 100644 --- a/sdk/python/packages/flet-core/src/flet_core/box.py +++ b/sdk/python/packages/flet-core/src/flet_core/box.py @@ -1,17 +1,18 @@ from dataclasses import dataclass, field from enum import Enum -from typing import Optional, List, Union +from typing import List, Optional, Union from flet_core.alignment import Alignment from flet_core.border import Border from flet_core.gradients import Gradient from flet_core.types import ( - OffsetValue, - BorderRadiusValue, BlendMode, + BorderRadiusValue, ImageFit, - OptionalNumber, ImageRepeat, + Number, + OffsetValue, + OptionalNumber, ) @@ -79,7 +80,15 @@ class BoxDecoration: @dataclass class BoxConstraints: - min_width: OptionalNumber = None - min_height: OptionalNumber = None - max_width: OptionalNumber = None - max_height: OptionalNumber = None + min_width: Number = 0 + min_height: Number = 0 + max_width: Number = float("inf") + max_height: Number = float("inf") + + def __post_init__(self): + assert ( + self.min_width <= self.max_width + ), "min_width must be less than or equal to max_width" + assert ( + self.min_height <= self.max_height + ), "min_height must be less than or equal to max_height" diff --git a/sdk/python/packages/flet-core/src/flet_core/buttons.py b/sdk/python/packages/flet-core/src/flet_core/buttons.py index b536aacd6..45cfac8b5 100644 --- a/sdk/python/packages/flet-core/src/flet_core/buttons.py +++ b/sdk/python/packages/flet-core/src/flet_core/buttons.py @@ -1,5 +1,5 @@ -from dataclasses import dataclass, field -from typing import Dict, Optional, Union +from dataclasses import dataclass +from typing import Optional from flet_core.alignment import Alignment from flet_core.border import BorderSide @@ -7,8 +7,9 @@ from flet_core.types import ( BorderRadiusValue, ControlState, + ControlStateValue, MouseCursor, - Number, + OptionalNumber, PaddingValue, VisualDensity, ) @@ -57,26 +58,33 @@ def __post_init__(self): @dataclass class ButtonStyle: - color: Union[None, str, Dict[Union[str, ControlState], str]] = None - bgcolor: Union[None, str, Dict[Union[str, ControlState], str]] = None - overlay_color: Union[None, str, Dict[Union[str, ControlState], str]] = None - shadow_color: Union[None, str, Dict[Union[str, ControlState], str]] = None - surface_tint_color: Union[None, str, Dict[Union[str, ControlState], str]] = None - elevation: Union[ - None, float, int, Dict[Union[str, ControlState], Union[float, int]] - ] = None + color: ControlStateValue[str] = None + bgcolor: ControlStateValue[str] = None + overlay_color: ControlStateValue[str] = None + shadow_color: ControlStateValue[str] = None + surface_tint_color: ControlStateValue[str] = None + elevation: ControlStateValue[OptionalNumber] = None animation_duration: Optional[int] = None - padding: Union[PaddingValue, Dict[Union[str, ControlState], PaddingValue]] = None - side: Union[None, BorderSide, Dict[Union[str, ControlState], BorderSide]] = None - shape: Union[ - None, OutlinedBorder, Dict[Union[str, ControlState], OutlinedBorder] - ] = None + padding: ControlStateValue[PaddingValue] = None + side: ControlStateValue[BorderSide] = None + shape: ControlStateValue[OutlinedBorder] = None alignment: Optional[Alignment] = None enable_feedback: Optional[bool] = None - text_style: Union[None, TextStyle, Dict[Union[str, ControlState], TextStyle]] = None - icon_size: Union[None, Number, Dict[Union[str, ControlState], Number]] = None - icon_color: Union[None, str, Dict[Union[str, ControlState], str]] = None + text_style: ControlStateValue[TextStyle] = None + icon_size: ControlStateValue[OptionalNumber] = None + icon_color: ControlStateValue[str] = None visual_density: Optional[VisualDensity] = None - mouse_cursor: Union[ - None, MouseCursor, Dict[Union[str, ControlState], MouseCursor] - ] = None + mouse_cursor: ControlStateValue[MouseCursor] = None + + def __post_init__(self): + if not isinstance(self.text_style, dict): + self.text_style = {ControlState.DEFAULT: self.text_style} + + if not isinstance(self.padding, dict): + self.padding = {ControlState.DEFAULT: self.padding} + + if not isinstance(self.side, dict): + self.side = {ControlState.DEFAULT: self.side} + + if not isinstance(self.shape, dict): + self.shape = {ControlState.DEFAULT: self.shape} diff --git a/sdk/python/packages/flet-core/src/flet_core/canvas/canvas.py b/sdk/python/packages/flet-core/src/flet_core/canvas/canvas.py index 8a5461614..b09a88791 100644 --- a/sdk/python/packages/flet-core/src/flet_core/canvas/canvas.py +++ b/sdk/python/packages/flet-core/src/flet_core/canvas/canvas.py @@ -1,6 +1,7 @@ import json from typing import Any, List, Optional, Union +from flet_core.animation import AnimationValue from flet_core.canvas.shape import Shape from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber @@ -8,13 +9,12 @@ from flet_core.event_handler import EventHandler from flet_core.ref import Ref from flet_core.types import ( - AnimationValue, OffsetValue, + OptionalControlEventCallable, + OptionalEventCallable, ResponsiveNumber, RotateValue, ScaleValue, - OptionalEventCallable, - OptionalControlEventCallable, ) from flet_core.utils import deprecated @@ -44,12 +44,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, 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 b4356d922..45e6e8f20 100644 --- a/sdk/python/packages/flet-core/src/flet_core/card.py +++ b/sdk/python/packages/flet-core/src/flet_core/card.py @@ -3,13 +3,13 @@ from flet_core import OutlinedBorder from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ClipBehavior, MarginValue, OffsetValue, @@ -100,12 +100,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/charts/bar_chart.py b/sdk/python/packages/flet-core/src/flet_core/charts/bar_chart.py index a077656b1..410180e1c 100644 --- a/sdk/python/packages/flet-core/src/flet_core/charts/bar_chart.py +++ b/sdk/python/packages/flet-core/src/flet_core/charts/bar_chart.py @@ -2,6 +2,7 @@ from enum import Enum from typing import Any, List, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.border import Border, BorderSide from flet_core.charts.bar_chart_group import BarChartGroup @@ -14,7 +15,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, OptionalEventCallable, @@ -27,8 +27,8 @@ class TooltipDirection(Enum): AUTO = "auto" - UP = "below" - DOWN = "above" + TOP = "top" + BOTTOM = "bottom" class BarChart(ConstrainedControl): @@ -36,7 +36,7 @@ def __init__( self, bar_groups: Optional[List[BarChartGroup]] = None, groups_space: OptionalNumber = None, - animate: AnimationValue = None, + animate: Optional[AnimationValue] = None, interactive: Optional[bool] = None, bgcolor: Optional[str] = None, tooltip_bgcolor: Optional[str] = None, @@ -79,12 +79,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/charts/line_chart.py b/sdk/python/packages/flet-core/src/flet_core/charts/line_chart.py index bd98dcf6c..3bdc23019 100644 --- a/sdk/python/packages/flet-core/src/flet_core/charts/line_chart.py +++ b/sdk/python/packages/flet-core/src/flet_core/charts/line_chart.py @@ -1,6 +1,7 @@ import json from typing import Any, List, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.border import Border, BorderSide from flet_core.charts.chart_axis import ChartAxis @@ -13,7 +14,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, OptionalEventCallable, @@ -28,7 +28,7 @@ class LineChart(ConstrainedControl): def __init__( self, data_series: Optional[List[LineChartData]] = None, - animate: AnimationValue = None, + animate: Optional[AnimationValue] = None, interactive: Optional[bool] = None, point_line_start: OptionalNumber = None, point_line_end: OptionalNumber = None, @@ -76,12 +76,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/charts/pie_chart.py b/sdk/python/packages/flet-core/src/flet_core/charts/pie_chart.py index 26cb6d494..10cb39219 100644 --- a/sdk/python/packages/flet-core/src/flet_core/charts/pie_chart.py +++ b/sdk/python/packages/flet-core/src/flet_core/charts/pie_chart.py @@ -2,6 +2,7 @@ from enum import Enum from typing import Any, List, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.charts.pie_chart_section import PieChartSection from flet_core.constrained_control import ConstrainedControl @@ -11,7 +12,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, OptionalEventCallable, @@ -29,7 +29,7 @@ def __init__( center_space_radius: OptionalNumber = None, sections_space: OptionalNumber = None, start_degree_offset: OptionalNumber = None, - animate: AnimationValue = None, + animate: Optional[AnimationValue] = None, on_chart_event: OptionalEventCallable["PieChartEvent"] = None, # # ConstrainedControl @@ -49,12 +49,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/checkbox.py b/sdk/python/packages/flet-core/src/flet_core/checkbox.py index b624da43e..fe865fcac 100644 --- a/sdk/python/packages/flet-core/src/flet_core/checkbox.py +++ b/sdk/python/packages/flet-core/src/flet_core/checkbox.py @@ -1,6 +1,7 @@ -from typing import Any, Dict, Optional, Union +from typing import Any, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.border import BorderSide from flet_core.buttons import OutlinedBorder @@ -10,8 +11,7 @@ from flet_core.text_style import TextStyle from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, - ControlState, + ControlStateValue, LabelPosition, MouseCursor, OffsetValue, @@ -66,8 +66,8 @@ def __init__( label_style: Optional[TextStyle] = None, tristate: Optional[bool] = None, autofocus: Optional[bool] = None, - fill_color: Union[None, str, Dict[ControlState, str]] = None, - overlay_color: Union[None, str, Dict[ControlState, str]] = None, + fill_color: ControlStateValue[str] = None, + overlay_color: ControlStateValue[str] = None, check_color: Optional[str] = None, active_color: Optional[str] = None, hover_color: Optional[str] = None, @@ -75,7 +75,7 @@ def __init__( semantics_label: Optional[str] = None, shape: Optional[OutlinedBorder] = None, splash_radius: OptionalNumber = None, - border_side: Union[None, BorderSide, Dict[ControlState, BorderSide]] = None, + border_side: ControlStateValue[BorderSide] = None, is_error: Optional[bool] = None, visual_density: Union[None, ThemeVisualDensity, VisualDensity] = None, mouse_cursor: Optional[MouseCursor] = None, @@ -101,12 +101,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -177,10 +177,10 @@ def _get_control_name(self): def before_update(self): super().before_update() - self._set_attr_json("fillColor", self.__fill_color) - self._set_attr_json("overlayColor", self.__overlay_color) + self._set_attr_json("fillColor", self.__fill_color, wrap_attr_dict=True) + self._set_attr_json("overlayColor", self.__overlay_color, wrap_attr_dict=True) + self._set_attr_json("borderSide", self.__border_side, wrap_attr_dict=True) self._set_attr_json("shape", self.__shape) - self._set_attr_json("borderSide", self.__border_side) if isinstance(self.__label_style, TextStyle): self._set_attr_json("labelStyle", self.__label_style) @@ -290,20 +290,20 @@ def hover_color(self, value: Optional[str]): # fill_color @property - def fill_color(self) -> Union[None, str, Dict[ControlState, str]]: + def fill_color(self) -> ControlStateValue[str]: return self.__fill_color @fill_color.setter - def fill_color(self, value: Union[None, str, Dict[ControlState, str]]): + def fill_color(self, value: ControlStateValue[str]): self.__fill_color = value # overlay_color @property - def overlay_color(self) -> Union[None, str, Dict[ControlState, str]]: + def overlay_color(self) -> ControlStateValue[str]: return self.__overlay_color @overlay_color.setter - def overlay_color(self, value: Union[None, str, Dict[ControlState, str]]): + def overlay_color(self, value: ControlStateValue[str]): self.__overlay_color = value # label_style @@ -353,13 +353,11 @@ def is_error(self, value: Optional[bool]): # border_side @property - def border_side(self) -> Union[None, BorderSide, Dict[ControlState, BorderSide]]: + def border_side(self) -> ControlStateValue[BorderSide]: return self.__border_side @border_side.setter - def border_side( - self, value: Union[None, BorderSide, Dict[ControlState, BorderSide]] - ): + def border_side(self, value: ControlStateValue[BorderSide]): self.__border_side = value # on_change diff --git a/sdk/python/packages/flet-core/src/flet_core/chip.py b/sdk/python/packages/flet-core/src/flet_core/chip.py index 8aa069a00..f84705d5a 100644 --- a/sdk/python/packages/flet-core/src/flet_core/chip.py +++ b/sdk/python/packages/flet-core/src/flet_core/chip.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.border import BorderSide from flet_core.buttons import OutlinedBorder @@ -9,9 +10,8 @@ from flet_core.text_style import TextStyle from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ClipBehavior, - ControlState, + ControlStateValue, OffsetValue, OptionalControlEventCallable, PaddingValue, @@ -91,7 +91,7 @@ def __init__( selected_shadow_color: Optional[str] = None, autofocus: Optional[bool] = None, surface_tint_color: Optional[str] = None, - color: Union[None, str, Dict[Union[ControlState, str], str]] = None, + color: ControlStateValue[str] = None, click_elevation: OptionalNumber = None, clip_behavior: Optional[ClipBehavior] = None, visual_density: Union[None, ThemeVisualDensity, VisualDensity] = None, @@ -119,12 +119,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -208,7 +208,7 @@ def before_update(self): self._set_attr_json("labelStyle", self.__label_style) self._set_attr_json("padding", self.__padding) self._set_attr_json("shape", self.__shape) - self._set_attr_json("color", self.__color) + self._set_attr_json("color", self.__color, wrap_attr_dict=True) def _get_children(self): self.__label._set_attr_internal("n", "label") @@ -322,11 +322,11 @@ def disabled_color(self, value: Optional[str]): # color @property - def color(self) -> Union[None, str, Dict[ControlState, str]]: + def color(self) -> ControlStateValue[str]: return self.__color @color.setter - def color(self, value: Union[None, str, Dict[ControlState, str]]): + def color(self, value: ControlStateValue[str]): self.__color = value # autofocus diff --git a/sdk/python/packages/flet-core/src/flet_core/circle_avatar.py b/sdk/python/packages/flet-core/src/flet_core/circle_avatar.py index 921b9fc0b..05f44051b 100644 --- a/sdk/python/packages/flet-core/src/flet_core/circle_avatar.py +++ b/sdk/python/packages/flet-core/src/flet_core/circle_avatar.py @@ -1,13 +1,13 @@ import warnings from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -105,12 +105,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/column.py b/sdk/python/packages/flet-core/src/flet_core/column.py index c078aea50..e8eb35f84 100644 --- a/sdk/python/packages/flet-core/src/flet_core/column.py +++ b/sdk/python/packages/flet-core/src/flet_core/column.py @@ -1,21 +1,21 @@ -from typing import Any, Optional, Sequence, Union, Callable +from typing import Any, Callable, Optional, Sequence, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control from flet_core.ref import Ref -from flet_core.scrollable_control import ScrollableControl, OnScrollEvent +from flet_core.scrollable_control import OnScrollEvent, ScrollableControl from flet_core.types import ( - AnimationValue, CrossAxisAlignment, MainAxisAlignment, OffsetValue, + OptionalControlEventCallable, OptionalNumber, ResponsiveNumber, RotateValue, ScaleValue, ScrollMode, - OptionalControlEventCallable, ) from flet_core.utils import deprecated @@ -84,12 +84,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/constrained_control.py b/sdk/python/packages/flet-core/src/flet_core/constrained_control.py index 3a9b2e230..8cf37bdaa 100644 --- a/sdk/python/packages/flet-core/src/flet_core/constrained_control.py +++ b/sdk/python/packages/flet-core/src/flet_core/constrained_control.py @@ -1,11 +1,11 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -42,12 +42,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, ): Control.__init__( @@ -200,56 +200,56 @@ def aspect_ratio(self, value: OptionalNumber): # animate_opacity @property - def animate_opacity(self) -> AnimationValue: + def animate_opacity(self) -> Optional[AnimationValue]: return self.__animate_opacity @animate_opacity.setter - def animate_opacity(self, value: AnimationValue): + def animate_opacity(self, value: Optional[AnimationValue]): self.__animate_opacity = value # animate_size @property - def animate_size(self) -> AnimationValue: + def animate_size(self) -> Optional[AnimationValue]: return self.__animate_size @animate_size.setter - def animate_size(self, value: AnimationValue): + def animate_size(self, value: Optional[AnimationValue]): self.__animate_size = value # animate_position @property - def animate_position(self) -> AnimationValue: + def animate_position(self) -> Optional[AnimationValue]: return self.__animate_position @animate_position.setter - def animate_position(self, value: AnimationValue): + def animate_position(self, value: Optional[AnimationValue]): self.__animate_position = value # animate_rotation @property - def animate_rotation(self) -> AnimationValue: + def animate_rotation(self) -> Optional[AnimationValue]: return self.__animate_rotation @animate_rotation.setter - def animate_rotation(self, value: AnimationValue): + def animate_rotation(self, value: Optional[AnimationValue]): self.__animate_rotation = value # animate_scale @property - def animate_scale(self) -> AnimationValue: + def animate_scale(self) -> Optional[AnimationValue]: return self.__animate_scale @animate_scale.setter - def animate_scale(self, value: AnimationValue): + def animate_scale(self, value: Optional[AnimationValue]): self.__animate_scale = value # animate_offset @property - def animate_offset(self) -> AnimationValue: + def animate_offset(self) -> Optional[AnimationValue]: return self.__animate_offset @animate_offset.setter - def animate_offset(self, value: AnimationValue): + def animate_offset(self, value: Optional[AnimationValue]): self.__animate_offset = value # on_animation_end diff --git a/sdk/python/packages/flet-core/src/flet_core/container.py b/sdk/python/packages/flet-core/src/flet_core/container.py index 8bd0f5a59..3d180fdab 100644 --- a/sdk/python/packages/flet-core/src/flet_core/container.py +++ b/sdk/python/packages/flet-core/src/flet_core/container.py @@ -4,6 +4,7 @@ from flet_core.adaptive_control import AdaptiveControl from flet_core.alignment import Alignment +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.blur import Blur from flet_core.border import Border @@ -23,7 +24,6 @@ from flet_core.theme import Theme from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, BlendMode, BorderRadiusValue, ClipBehavior, @@ -90,7 +90,7 @@ def __init__( ink: Optional[bool] = None, image: Optional[DecorationImage] = None, ink_color: Optional[str] = None, - animate: AnimationValue = None, + animate: Optional[AnimationValue] = None, blur: Union[ None, float, int, Tuple[Union[float, int], Union[float, int]], Blur ] = None, @@ -125,12 +125,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -546,11 +546,11 @@ def ink_color(self, value: Optional[str]): # animate @property - def animate(self) -> AnimationValue: + def animate(self) -> Optional[AnimationValue]: return self.__animate @animate.setter - def animate(self, value: AnimationValue): + def animate(self, value: Optional[AnimationValue]): self.__animate = value # url diff --git a/sdk/python/packages/flet-core/src/flet_core/control.py b/sdk/python/packages/flet-core/src/flet_core/control.py index d8dbb885c..e508624cf 100644 --- a/sdk/python/packages/flet-core/src/flet_core/control.py +++ b/sdk/python/packages/flet-core/src/flet_core/control.py @@ -178,17 +178,11 @@ def _set_attr_internal(self, name: str, value: V, dirty: bool = True) -> None: if orig_val is None or orig_val[0] != value: self.__attrs[name] = (value, dirty) - def _set_attr_json(self, name: str, value: V) -> None: + def _set_attr_json(self, name: str, value: V, wrap_attr_dict: bool = False) -> None: ov = self._get_attr(name) - nv = self._convert_attr_json(value) - if ov != nv: - self._set_attr(name, nv) - - def _set_control_state_attr_json(self, name: str, value: V) -> None: - if value is not None and not isinstance(value, dict): - value = {ControlState.DEFAULT: value} - ov = self._get_attr(name) - nv = self._convert_attr_json(value) + nv = self._convert_attr_json( + self._wrap_attr_dict(value) if wrap_attr_dict else value + ) if ov != nv: self._set_attr(name, nv) @@ -202,7 +196,7 @@ def _convert_attr_json(self, value: V) -> Optional[str]: def _wrap_attr_dict(self, value: Optional[Union[Dict, Any]]) -> Optional[Dict]: if value is None or isinstance(value, Dict): return value - return {"": value} + return {ControlState.DEFAULT: value} # event_handlers @property diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_action_sheet.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_action_sheet.py index 0b6783d7d..6e094f8e4 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_action_sheet.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_action_sheet.py @@ -1,12 +1,12 @@ from typing import Any, List, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -49,12 +49,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_action_sheet_action.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_action_sheet_action.py index bc64189c9..52c3b441c 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_action_sheet_action.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_action_sheet_action.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -50,12 +50,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -145,11 +145,11 @@ def is_destructive_action(self, value: Optional[bool]): # content @property - def content(self) -> Control: + def content(self) -> Optional[Control]: return self.__content @content.setter - def content(self, value: Control): + def content(self, value: Optional[Control]): self.__content = value # on_click diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_activity_indicator.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_activity_indicator.py index b1722ff19..4ae80da1a 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_activity_indicator.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_activity_indicator.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -42,12 +42,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_button.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_button.py index 2bd2d4692..21eee4219 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_button.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_button.py @@ -2,13 +2,13 @@ from typing import Any, Optional, Union from flet_core.alignment import Alignment +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, BorderRadiusValue, OffsetValue, OptionalControlEventCallable, @@ -66,12 +66,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_checkbox.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_checkbox.py index ce009b949..3beac09f5 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_checkbox.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_checkbox.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, LabelPosition, OffsetValue, OptionalControlEventCallable, @@ -73,12 +73,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_date_picker.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_date_picker.py index b03a25b75..88dbbd871 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_date_picker.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_date_picker.py @@ -2,13 +2,13 @@ from enum import Enum from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -73,12 +73,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_list_tile.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_list_tile.py index b7568c356..3bf25dce2 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_list_tile.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_list_tile.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, PaddingValue, @@ -89,12 +89,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_navigation_bar.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_navigation_bar.py index ccf102921..1f04383e4 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_navigation_bar.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_navigation_bar.py @@ -1,17 +1,17 @@ from typing import Any, List, Optional, Union +from flet_core.animation import AnimationValue from flet_core.border import Border from flet_core.constrained_control import ConstrainedControl from flet_core.navigation_bar import NavigationBarDestination from flet_core.ref import Ref from flet_core.types import ( - AnimationValue, OffsetValue, + OptionalControlEventCallable, OptionalNumber, ResponsiveNumber, RotateValue, ScaleValue, - OptionalControlEventCallable, ) @@ -82,12 +82,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_picker.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_picker.py index 2b026eaf5..2e49c6dab 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_picker.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_picker.py @@ -1,12 +1,12 @@ from typing import Any, List, Optional, Sequence, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -56,12 +56,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_radio.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_radio.py index ea8dd9797..d0290c8e2 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_radio.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_radio.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, LabelPosition, OffsetValue, OptionalControlEventCallable, @@ -63,12 +63,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_segmented_button.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_segmented_button.py index 1cafb8117..76ccbdeec 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_segmented_button.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_segmented_button.py @@ -1,12 +1,12 @@ from typing import Any, List, Optional, Sequence, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, PaddingValue, @@ -54,12 +54,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_slider.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_slider.py index 3a377c203..c46c9d460 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_slider.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_slider.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -60,12 +60,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_sliding_segmented_button.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_sliding_segmented_button.py index a39eb6ddd..fa998ad21 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_sliding_segmented_button.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_sliding_segmented_button.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Sequence, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, PaddingValue, @@ -51,12 +51,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_switch.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_switch.py index ca306e651..a3efd8bd1 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_switch.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_switch.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, LabelPosition, OffsetValue, OptionalControlEventCallable, @@ -76,12 +76,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_textfield.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_textfield.py index 7fef26eb5..fe3dfa38e 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_textfield.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_textfield.py @@ -1,20 +1,22 @@ from enum import Enum from typing import Any, List, Optional, Union +from flet_core.animation import AnimationValue from flet_core.autofill_group import AutofillHint from flet_core.badge import BadgeValue from flet_core.border import Border -from flet_core.box import BoxShadow, BoxShape, DecorationImage +from flet_core.box import BoxShadow, DecorationImage from flet_core.control import Control, OptionalNumber from flet_core.gradients import Gradient from flet_core.ref import Ref -from flet_core.text_style import TextStyle +from flet_core.text_style import StrutStyle, TextStyle from flet_core.textfield import InputFilter, KeyboardType, TextCapitalization, TextField from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, BlendMode, BorderRadiusValue, + Brightness, + ClipBehavior, OffsetValue, OptionalControlEventCallable, PaddingValue, @@ -51,13 +53,10 @@ def __init__( shadow: Union[None, BoxShadow, List[BoxShadow]] = None, prefix_visibility_mode: Optional[VisibilityMode] = None, suffix_visibility_mode: Optional[VisibilityMode] = None, + clear_button_visibility_mode: Optional[VisibilityMode] = None, clear_button_semantics_label: Optional[str] = None, image: Optional[DecorationImage] = None, - enable_scribble: Optional[bool] = None, padding: PaddingValue = None, - scroll_padding: PaddingValue = None, - obscuring_character: Optional[str] = None, - on_click: OptionalControlEventCallable = None, # # TextField # @@ -86,10 +85,20 @@ def __init__( selection_color: Optional[str] = None, input_filter: Optional[InputFilter] = None, autofill_hints: Union[None, AutofillHint, List[AutofillHint]] = None, - on_change=None, - on_submit=None, - on_focus=None, - on_blur=None, + enable_scribble: Optional[bool] = None, + scroll_padding: PaddingValue = None, + obscuring_character: Optional[str] = None, + enable_interactive_selection: Optional[bool] = None, + enable_ime_personalized_learning: Optional[bool] = None, + clip_behavior: Optional[ClipBehavior] = None, + keyboard_brightness: Optional[Brightness] = None, + strut_style: Optional[StrutStyle] = None, + animate_cursor_opacity: Optional[bool] = None, + on_click: OptionalControlEventCallable = None, + on_change: OptionalControlEventCallable = None, + on_submit: OptionalControlEventCallable = None, + on_focus: OptionalControlEventCallable = None, + on_blur: OptionalControlEventCallable = None, # # FormField # @@ -108,6 +117,7 @@ def __init__( filled: Optional[bool] = None, prefix: Optional[Control] = None, suffix: Optional[Control] = None, + fit_parent_size: Optional[bool] = None, # # ConstrainedControl # @@ -123,12 +133,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -179,6 +189,7 @@ def __init__( filled=filled, prefix=prefix, suffix=suffix, + fit_parent_size=fit_parent_size, # # TextField # @@ -208,6 +219,16 @@ def __init__( selection_color=selection_color, input_filter=input_filter, autofill_hints=autofill_hints, + enable_scribble=enable_scribble, + scroll_padding=scroll_padding, + obscuring_character=obscuring_character, + enable_interactive_selection=enable_interactive_selection, + enable_ime_personalized_learning=enable_ime_personalized_learning, + clip_behavior=clip_behavior, + keyboard_brightness=keyboard_brightness, + strut_style=strut_style, + animate_cursor_opacity=animate_cursor_opacity, + on_click=on_click, on_change=on_change, on_submit=on_submit, on_focus=on_focus, @@ -224,11 +245,8 @@ def __init__( self.clear_button_semantics_label = clear_button_semantics_label self.border = border self.image = image - self.enable_scribble = enable_scribble self.padding = padding - self.scroll_padding = scroll_padding - self.obscuring_character = obscuring_character - self.on_click = on_click + self.clear_button_visibility_mode = clear_button_visibility_mode def _get_control_name(self): return "cupertinotextfield" @@ -241,7 +259,6 @@ def before_update(self): self._set_attr_json("border", self.__border) self._set_attr_json("image", self.__image) self._set_attr_json("padding", self.__padding) - self._set_attr_json("scrollPadding", self.__scroll_padding) # placeholder_text @property @@ -298,15 +315,6 @@ def image(self) -> Optional[DecorationImage]: def image(self, value: Optional[DecorationImage]): self.__image = value - # shape - @property - def shape(self) -> Optional[BoxShape]: - return self.__shape - - @shape.setter - def shape(self, value: Optional[BoxShape]): - self.__shape = value - # suffix_visibility_mode @property def suffix_visibility_mode(self) -> Optional[VisibilityMode]: @@ -317,6 +325,16 @@ def suffix_visibility_mode(self, value: Optional[VisibilityMode]): self.__suffix_visibility_mode = value self._set_enum_attr("suffixVisibilityMode", value, VisibilityMode) + # clear_button_visibility_mode + @property + def clear_button_visibility_mode(self) -> Optional[VisibilityMode]: + return self.__clear_button_visibility_mode + + @clear_button_visibility_mode.setter + def clear_button_visibility_mode(self, value: Optional[VisibilityMode]): + self.__clear_button_visibility_mode = value + self._set_enum_attr("clearButtonVisibilityMode", value, VisibilityMode) + # prefix_visibility_mode @property def prefix_visibility_mode(self) -> Optional[VisibilityMode]: @@ -336,24 +354,6 @@ def clear_button_semantics_label(self) -> Optional[str]: def clear_button_semantics_label(self, value: Optional[str]): self._set_attr("clearButtonSemanticsLabel", value) - # obscuring_character - @property - def obscuring_character(self) -> Optional[str]: - return self._get_attr("obscuringCharacter") - - @obscuring_character.setter - def obscuring_character(self, value: Optional[str]): - self._set_attr("obscuringCharacter", value) - - # enable_scribble - @property - def enable_scribble(self) -> bool: - return self._get_attr("enableScribble", data_type="bool", def_value=True) - - @enable_scribble.setter - def enable_scribble(self, value: Optional[bool]): - self._set_attr("enableScribble", value) - # padding @property def padding(self) -> PaddingValue: @@ -363,24 +363,6 @@ def padding(self) -> PaddingValue: def padding(self, value: PaddingValue): self.__padding = value - # scroll_padding - @property - def scroll_padding(self) -> PaddingValue: - return self.__scroll_padding - - @scroll_padding.setter - def scroll_padding(self, value: PaddingValue): - self.__scroll_padding = value - - # on_click - @property - def on_click(self): - return self._get_event_handler("click") - - @on_click.setter - def on_click(self, handler: OptionalControlEventCallable): - self._add_event_handler("click", handler) - # border @property def border(self) -> Optional[Border]: diff --git a/sdk/python/packages/flet-core/src/flet_core/cupertino_timer_picker.py b/sdk/python/packages/flet-core/src/flet_core/cupertino_timer_picker.py index b2da845c5..cc12710b5 100644 --- a/sdk/python/packages/flet-core/src/flet_core/cupertino_timer_picker.py +++ b/sdk/python/packages/flet-core/src/flet_core/cupertino_timer_picker.py @@ -2,13 +2,13 @@ from typing import Any, Optional, Union from flet_core.alignment import Alignment +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -63,12 +63,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/datatable.py b/sdk/python/packages/flet-core/src/flet_core/datatable.py index 817022f53..2870fa57e 100644 --- a/sdk/python/packages/flet-core/src/flet_core/datatable.py +++ b/sdk/python/packages/flet-core/src/flet_core/datatable.py @@ -1,6 +1,7 @@ import json -from typing import Any, Dict, List, Optional, Union +from typing import Any, List, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.border import Border, BorderSide from flet_core.constrained_control import ConstrainedControl @@ -13,10 +14,9 @@ from flet_core.text_style import TextStyle from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, BorderRadiusValue, ClipBehavior, - ControlState, + ControlStateValue, MainAxisAlignment, OffsetValue, OptionalControlEventCallable, @@ -246,7 +246,7 @@ class DataRow(Control): def __init__( self, cells: List[DataCell], - color: Union[None, str, Dict[ControlState, str]] = None, + color: ControlStateValue[str] = None, selected: Optional[bool] = None, on_long_press: OptionalControlEventCallable = None, on_select_changed: OptionalControlEventCallable = None, @@ -274,7 +274,7 @@ def before_update(self): assert any( cell.visible for cell in self.__cells ), "cells must contain at minimum one visible DataCell" - self._set_attr_json("color", self.__color) + self._set_attr_json("color", self.__color, wrap_attr_dict=True) def _get_children(self): return self.__cells @@ -293,11 +293,11 @@ def cells(self, value: List[DataCell]): # color @property - def color(self) -> Union[None, str, Dict[ControlState, str]]: + def color(self) -> ControlStateValue[str]: return self.__color @color.setter - def color(self, value: Union[None, str, Dict[ControlState, str]]): + def color(self, value: ControlStateValue[str]): self.__color = value # selected @@ -345,14 +345,14 @@ def __init__( vertical_lines: Optional[BorderSide] = None, checkbox_horizontal_margin: OptionalNumber = None, column_spacing: OptionalNumber = None, - data_row_color: Union[None, str, Dict[ControlState, str]] = None, + data_row_color: ControlStateValue[str] = None, data_row_min_height: OptionalNumber = None, data_row_max_height: OptionalNumber = None, data_text_style: Optional[TextStyle] = None, bgcolor: Optional[str] = None, gradient: Optional[Gradient] = None, divider_thickness: OptionalNumber = None, - heading_row_color: Union[None, str, Dict[ControlState, str]] = None, + heading_row_color: ControlStateValue[str] = None, heading_row_height: OptionalNumber = None, heading_text_style: Optional[TextStyle] = None, horizontal_margin: OptionalNumber = None, @@ -377,12 +377,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -584,11 +584,11 @@ def horizontal_margin(self, value: OptionalNumber): # data_row_color @property - def data_row_color(self) -> Union[None, str, Dict[ControlState, str]]: + def data_row_color(self) -> ControlStateValue[str]: return self.__data_row_color @data_row_color.setter - def data_row_color(self, value: Union[None, str, Dict[ControlState, str]]): + def data_row_color(self, value: ControlStateValue[str]): self.__data_row_color = value # data_row_min_height @@ -638,11 +638,11 @@ def gradient(self, value: Optional[Gradient]): # heading_row_color @property - def heading_row_color(self) -> Union[None, str, Dict[ControlState, str]]: + def heading_row_color(self) -> ControlStateValue[str]: return self.__heading_row_color @heading_row_color.setter - def heading_row_color(self, value: Union[None, str, Dict[ControlState, str]]): + def heading_row_color(self, value: ControlStateValue[str]): self.__heading_row_color = value # heading_row_height diff --git a/sdk/python/packages/flet-core/src/flet_core/dismissible.py b/sdk/python/packages/flet-core/src/flet_core/dismissible.py index eb6c92a24..354f7b2c9 100644 --- a/sdk/python/packages/flet-core/src/flet_core/dismissible.py +++ b/sdk/python/packages/flet-core/src/flet_core/dismissible.py @@ -2,6 +2,7 @@ from typing import Any, Dict, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber @@ -11,7 +12,6 @@ from flet_core.snack_bar import DismissDirection from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, OptionalEventCallable, @@ -68,12 +68,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/draggable.py b/sdk/python/packages/flet-core/src/flet_core/draggable.py index 0010b8ec2..5a5b3c059 100644 --- a/sdk/python/packages/flet-core/src/flet_core/draggable.py +++ b/sdk/python/packages/flet-core/src/flet_core/draggable.py @@ -1,5 +1,6 @@ from typing import Any, Optional +from flet_core.alignment import Axis from flet_core.control import Control from flet_core.ref import Ref from flet_core.types import OptionalControlEventCallable @@ -118,6 +119,9 @@ def __init__( group: Optional[str] = None, content_when_dragging: Optional[Control] = None, content_feedback: Optional[Control] = None, + axis: Optional[Axis] = None, + affinity: Optional[Axis] = None, + max_simultaneous_drags: Optional[int] = None, on_drag_start: OptionalControlEventCallable = None, on_drag_complete: OptionalControlEventCallable = None, # @@ -143,6 +147,9 @@ def __init__( self.content_feedback = content_feedback self.on_drag_start = on_drag_start self.on_drag_complete = on_drag_complete + self.axis = axis + self.affinity = affinity + self.max_simultaneous_drags = max_simultaneous_drags def _get_control_name(self): return "draggable" @@ -200,6 +207,35 @@ def content_feedback(self) -> Optional[Control]: def content_feedback(self, value: Optional[Control]): self.__content_feedback = value + # max_simultaneous_drags + @property + def max_simultaneous_drags(self) -> Optional[int]: + return self._get_attr("maxSimultaneousDrags") + + @max_simultaneous_drags.setter + def max_simultaneous_drags(self, value: Optional[int]): + self._set_attr("maxSimultaneousDrags", value) + + # axis + @property + def axis(self) -> Optional[Axis]: + return self.__axis + + @axis.setter + def axis(self, value: Optional[Axis]): + self.__axis = value + self._set_enum_attr("axis", value, Axis) + + # affinity + @property + def affinity(self) -> Optional[Axis]: + return self.__affinity + + @affinity.setter + def affinity(self, value: Optional[Axis]): + self.__affinity = value + self._set_enum_attr("affinity", value, Axis) + # on_drag_start @property def on_drag_start(self) -> OptionalControlEventCallable: diff --git a/sdk/python/packages/flet-core/src/flet_core/dropdown.py b/sdk/python/packages/flet-core/src/flet_core/dropdown.py index b332f80ad..cae37bdee 100644 --- a/sdk/python/packages/flet-core/src/flet_core/dropdown.py +++ b/sdk/python/packages/flet-core/src/flet_core/dropdown.py @@ -2,7 +2,9 @@ from typing import Any, List, Optional, Union from flet_core.alignment import Alignment +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue +from flet_core.box import BoxConstraints from flet_core.control import Control, OptionalNumber from flet_core.form_field_control import ( FormFieldControl, @@ -13,8 +15,8 @@ from flet_core.text_style import TextStyle from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, BorderRadiusValue, + DurationValue, OffsetValue, OptionalControlEventCallable, PaddingValue, @@ -184,7 +186,7 @@ def __init__( # text_size: OptionalNumber = None, text_style: Optional[TextStyle] = None, - label: Optional[str] = None, + label: Optional[Union[str, Control]] = None, label_style: Optional[TextStyle] = None, icon: Optional[IconValueOrControl] = None, border: Optional[InputBorder] = None, @@ -203,11 +205,13 @@ def __init__( fill_color: Optional[str] = None, hint_text: Optional[str] = None, hint_style: Optional[TextStyle] = None, + helper: Optional[Control] = None, helper_text: Optional[str] = None, helper_style: Optional[TextStyle] = None, counter: Optional[Control] = None, counter_text: Optional[str] = None, counter_style: Optional[TextStyle] = None, + error: Optional[Control] = None, error_text: Optional[str] = None, error_style: Optional[TextStyle] = None, prefix: Optional[Control] = None, @@ -218,6 +222,16 @@ def __init__( suffix_icon: Optional[IconValueOrControl] = None, suffix_text: Optional[str] = None, suffix_style: Optional[TextStyle] = None, + focus_color: Optional[str] = None, + align_label_with_hint: Optional[bool] = None, + hint_fade_duration: DurationValue = None, + hint_max_lines: Optional[int] = None, + helper_max_lines: Optional[int] = None, + error_max_lines: Optional[int] = None, + prefix_icon_size_constraints: Optional[BoxConstraints] = None, + suffix_icon_size_constraints: Optional[BoxConstraints] = None, + size_constraints: Optional[BoxConstraints] = None, + collapsed: Optional[bool] = None, # # ConstrainedControl # @@ -233,12 +247,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -297,10 +311,12 @@ def __init__( hint_text=hint_text, hint_style=hint_style, helper_text=helper_text, + helper=helper, helper_style=helper_style, counter=counter, counter_text=counter_text, counter_style=counter_style, + error=error, error_text=error_text, error_style=error_style, prefix=prefix, @@ -311,9 +327,18 @@ def __init__( suffix_icon=suffix_icon, suffix_text=suffix_text, suffix_style=suffix_style, + focus_color=focus_color, + align_label_with_hint=align_label_with_hint, + hint_fade_duration=hint_fade_duration, + hint_max_lines=hint_max_lines, + helper_max_lines=helper_max_lines, + error_max_lines=error_max_lines, + prefix_icon_size_constraints=prefix_icon_size_constraints, + suffix_icon_size_constraints=suffix_icon_size_constraints, + size_constraints=size_constraints, + collapsed=collapsed, ) - self.__options = [] self.value = value self.autofocus = autofocus self.options = options diff --git a/sdk/python/packages/flet-core/src/flet_core/elevated_button.py b/sdk/python/packages/flet-core/src/flet_core/elevated_button.py index 9663ceb59..e377d8453 100644 --- a/sdk/python/packages/flet-core/src/flet_core/elevated_button.py +++ b/sdk/python/packages/flet-core/src/flet_core/elevated_button.py @@ -2,6 +2,7 @@ from typing import Any, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.buttons import ButtonStyle from flet_core.constrained_control import ConstrainedControl @@ -9,7 +10,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ClipBehavior, OffsetValue, OptionalControlEventCallable, @@ -82,12 +82,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/embed_json_encoder.py b/sdk/python/packages/flet-core/src/flet_core/embed_json_encoder.py index 8002baaa2..7f7e9e4ce 100644 --- a/sdk/python/packages/flet-core/src/flet_core/embed_json_encoder.py +++ b/sdk/python/packages/flet-core/src/flet_core/embed_json_encoder.py @@ -4,6 +4,7 @@ from flet_core.border import Border, BorderSide from flet_core.border_radius import BorderRadius +from flet_core.box import BoxConstraints from flet_core.margin import Margin from flet_core.padding import Padding @@ -11,34 +12,48 @@ class EmbedJsonEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, BorderSide): - return { + obj_as_dict = { "w": obj.width, "c": obj.color, "sa": obj.stroke_align, } elif isinstance(obj, Border): - return { + obj_as_dict = { "l": obj.left, "t": obj.top, "r": obj.right, "b": obj.bottom, } elif isinstance(obj, BorderRadius): - return { + obj_as_dict = { "bl": obj.bottom_left, "br": obj.bottom_right, "tl": obj.top_left, "tr": obj.top_right, } elif isinstance(obj, (Margin, Padding)): - return { + obj_as_dict = { "l": obj.left, "t": obj.top, "r": obj.right, "b": obj.bottom, } + elif isinstance(obj, BoxConstraints): + obj_as_dict = { + "min_width": obj.min_width, + "max_width": obj.max_width, + "min_height": obj.min_height, + "max_height": obj.max_height, + } else: - return self._convert_enums(obj.__dict__) + obj_as_dict = self._convert_enums(obj.__dict__) + + # Convert inf to string "inf" to avoid JSON serialization error + for key, value in obj_as_dict.items(): + if value == float("inf"): + obj_as_dict[key] = "inf" + + return obj_as_dict def encode(self, o): return super().encode(self._convert_enums(o)) diff --git a/sdk/python/packages/flet-core/src/flet_core/expansion_panel.py b/sdk/python/packages/flet-core/src/flet_core/expansion_panel.py index 6de3ca716..d01404cb1 100644 --- a/sdk/python/packages/flet-core/src/flet_core/expansion_panel.py +++ b/sdk/python/packages/flet-core/src/flet_core/expansion_panel.py @@ -1,17 +1,17 @@ from typing import Any, Optional, Sequence, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.types import ( - AnimationValue, OffsetValue, + OptionalControlEventCallable, PaddingValue, ResponsiveNumber, RotateValue, ScaleValue, - OptionalControlEventCallable, ) @@ -50,12 +50,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, @@ -202,12 +202,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/expansion_tile.py b/sdk/python/packages/flet-core/src/flet_core/expansion_tile.py index d4679be9e..1d4bd5f94 100644 --- a/sdk/python/packages/flet-core/src/flet_core/expansion_tile.py +++ b/sdk/python/packages/flet-core/src/flet_core/expansion_tile.py @@ -3,6 +3,7 @@ from flet_core.adaptive_control import AdaptiveControl from flet_core.alignment import Alignment +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.buttons import OutlinedBorder from flet_core.constrained_control import ConstrainedControl @@ -10,7 +11,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ClipBehavior, CrossAxisAlignment, OffsetValue, @@ -87,12 +87,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/flet_app.py b/sdk/python/packages/flet-core/src/flet_core/flet_app.py index c93a42ff9..d4ec2ac53 100644 --- a/sdk/python/packages/flet-core/src/flet_core/flet_app.py +++ b/sdk/python/packages/flet-core/src/flet_core/flet_app.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, RotateValue, @@ -38,12 +38,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/floating_action_button.py b/sdk/python/packages/flet-core/src/flet_core/floating_action_button.py index f615d9e2f..a9e91e617 100644 --- a/sdk/python/packages/flet-core/src/flet_core/floating_action_button.py +++ b/sdk/python/packages/flet-core/src/flet_core/floating_action_button.py @@ -1,5 +1,6 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.buttons import OutlinedBorder from flet_core.constrained_control import ConstrainedControl @@ -7,7 +8,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ClipBehavior, MouseCursor, OffsetValue, @@ -109,12 +109,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/form_field_control.py b/sdk/python/packages/flet-core/src/flet_core/form_field_control.py index 069207ffe..f1ab6392e 100644 --- a/sdk/python/packages/flet-core/src/flet_core/form_field_control.py +++ b/sdk/python/packages/flet-core/src/flet_core/form_field_control.py @@ -1,16 +1,17 @@ from enum import Enum from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue +from flet_core.box import BoxConstraints from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber -from flet_core.icon import Icon from flet_core.ref import Ref from flet_core.text_style import TextStyle from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, BorderRadiusValue, + DurationValue, OffsetValue, OptionalControlEventCallable, PaddingValue, @@ -40,7 +41,7 @@ def __init__( text_size: OptionalNumber = None, text_style: Optional[TextStyle] = None, text_vertical_align: Union[VerticalAlignment, OptionalNumber] = None, - label: Optional[str] = None, + label: Optional[Union[str, Control]] = None, label_style: Optional[TextStyle] = None, icon: Optional[IconValueOrControl] = None, border: Optional[InputBorder] = None, @@ -57,25 +58,37 @@ def __init__( dense: Optional[bool] = None, filled: Optional[bool] = None, fill_color: Optional[str] = None, + focus_color: Optional[str] = None, + align_label_with_hint: Optional[bool] = None, hover_color: Optional[str] = None, hint_text: Optional[str] = None, hint_style: Optional[TextStyle] = None, + hint_fade_duration: DurationValue = None, + hint_max_lines: Optional[int] = None, + helper: Optional[Control] = None, helper_text: Optional[str] = None, helper_style: Optional[TextStyle] = None, + helper_max_lines: Optional[int] = None, counter: Optional[Control] = None, counter_text: Optional[str] = None, counter_style: Optional[TextStyle] = None, + error: Optional[Control] = None, error_text: Optional[str] = None, error_style: Optional[TextStyle] = None, + error_max_lines: Optional[int] = None, prefix: Optional[Control] = None, prefix_icon: Optional[IconValueOrControl] = None, + prefix_icon_size_constraints: Optional[BoxConstraints] = None, prefix_text: Optional[str] = None, prefix_style: Optional[TextStyle] = None, suffix: Optional[Control] = None, suffix_icon: Optional[IconValueOrControl] = None, + suffix_icon_size_constraints: Optional[BoxConstraints] = None, + size_constraints: Optional[BoxConstraints] = None, + collapsed: Optional[bool] = None, + fit_parent_size: Optional[bool] = None, suffix_text: Optional[str] = None, suffix_style: Optional[TextStyle] = None, - rtl: Optional[bool] = None, # # ConstrainedControl # @@ -95,18 +108,19 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, data: Any = None, + rtl: Optional[bool] = None, ): ConstrainedControl.__init__( self, @@ -162,11 +176,13 @@ def __init__( self.dense = dense self.hint_text = hint_text self.hint_style = hint_style + self.helper = helper self.helper_text = helper_text self.helper_style = helper_style self.counter = counter self.counter_text = counter_text self.counter_style = counter_style + self.error = error self.error_text = error_text self.error_style = error_style self.prefix = prefix @@ -179,6 +195,17 @@ def __init__( self.suffix_style = suffix_style self.hover_color = hover_color self.fill_color = fill_color + self.focus_color = focus_color + self.align_label_with_hint = align_label_with_hint + self.hint_fade_duration = hint_fade_duration + self.hint_max_lines = hint_max_lines + self.helper_max_lines = helper_max_lines + self.error_max_lines = error_max_lines + self.prefix_icon_size_constraints = prefix_icon_size_constraints + self.suffix_icon_size_constraints = suffix_icon_size_constraints + self.size_constraints = size_constraints + self.collapsed = collapsed + self.fit_parent_size = fit_parent_size def before_update(self): super().before_update() @@ -192,33 +219,39 @@ def before_update(self): self._set_attr_json("errorStyle", self.__error_style) self._set_attr_json("prefixStyle", self.__prefix_style) self._set_attr_json("suffixStyle", self.__suffix_style) + self._set_attr_json("hintFadeDuration", self.__hint_fade_duration) + self._set_attr_json( + "prefixIconSizeConstraints", self.__prefix_icon_size_constraints + ) + self._set_attr_json( + "suffixIconSizeConstraints", self.__suffix_icon_size_constraints + ) + self._set_attr_json("sizeConstraints", self.__size_constraints) if isinstance(self.__suffix_icon, str): self._set_attr("suffixIcon", self.__suffix_icon) if isinstance(self.__prefix_icon, str): self._set_attr("prefixIcon", self.__prefix_icon) if isinstance(self.__icon, str): self._set_attr("icon", self.__icon) + if isinstance(self.__label, str): + self._set_attr("label", self.__label) def _get_children(self): children = [] - if isinstance(self.__prefix, Control): - self.__prefix._set_attr_internal("n", "prefix") - children.append(self.__prefix) - if isinstance(self.__suffix, Control): - self.__suffix._set_attr_internal("n", "suffix") - children.append(self.__suffix) - if isinstance(self.__suffix_icon, Control): - self.__suffix_icon._set_attr_internal("n", "suffixIcon") - children.append(self.__suffix_icon) - if isinstance(self.__prefix_icon, Control): - self.__prefix_icon._set_attr_internal("n", "prefixIcon") - children.append(self.__prefix_icon) - if isinstance(self.__icon, Control): - self.__icon._set_attr_internal("n", "icon") - children.append(self.__icon) - if isinstance(self.__counter, Control): - self.__counter._set_attr_internal("n", "counter") - children.append(self.__counter) + for control, name in [ + (self.__prefix, "prefix"), + (self.__suffix, "suffix"), + (self.__suffix_icon, "suffix_icon"), + (self.__prefix_icon, "prefix_icon"), + (self.__icon, "icon"), + (self.__counter, "counter"), + (self.__error, "error"), + (self.__helper, "helper"), + (self.__label, "label"), + ]: + if isinstance(control, Control): + control._set_attr_internal("n", name) + children.append(control) return children # text_size @@ -241,12 +274,12 @@ def text_style(self, value: Optional[TextStyle]): # label @property - def label(self) -> Optional[str]: - return self._get_attr("label") + def label(self) -> Optional[Union[str, Control]]: + return self.__label @label.setter - def label(self, value: Optional[str]): - self._set_attr("label", value) + def label(self, value: Optional[Union[str, Control]]): + self.__label = value # label_style @property @@ -285,6 +318,105 @@ def color(self) -> Optional[str]: def color(self, value: Optional[str]): self._set_attr("color", value) + # focus_color + @property + def focus_color(self) -> Optional[str]: + return self._get_attr("focusColor") + + @focus_color.setter + def focus_color(self, value: Optional[str]): + self._set_attr("focusColor", value) + + # align_label_with_hint + @property + def align_label_with_hint(self) -> Optional[bool]: + return self._get_attr("alignLabelWithHint", data_type="bool") + + @align_label_with_hint.setter + def align_label_with_hint(self, value: Optional[bool]): + self._set_attr("alignLabelWithHint", value) + + # fit_parent_size + @property + def fit_parent_size(self) -> Optional[bool]: + return self._get_attr("fitParentSize", data_type="bool", def_value=False) + + @fit_parent_size.setter + def fit_parent_size(self, value: Optional[bool]): + self._set_attr("fitParentSize", value) + + # hint_fade_duration + @property + def hint_fade_duration(self) -> DurationValue: + return self.__hint_fade_duration + + @hint_fade_duration.setter + def hint_fade_duration(self, value: DurationValue): + self.__hint_fade_duration = value + + # hint_max_lines + @property + def hint_max_lines(self) -> Optional[int]: + return self._get_attr("hintMaxLines", data_type="int") + + @hint_max_lines.setter + def hint_max_lines(self, value: Optional[int]): + self._set_attr("hintMaxLines", value) + + # helper_max_lines + @property + def helper_max_lines(self) -> Optional[int]: + return self._get_attr("helperMaxLines", data_type="int") + + @helper_max_lines.setter + def helper_max_lines(self, value: Optional[int]): + self._set_attr("helperMaxLines", value) + + # error_max_lines + @property + def error_max_lines(self) -> Optional[int]: + return self._get_attr("errorMaxLines", data_type="int") + + @error_max_lines.setter + def error_max_lines(self, value: Optional[int]): + self._set_attr("errorMaxLines", value) + + # prefix_icon_size_constraints + @property + def prefix_icon_size_constraints(self) -> Optional[BoxConstraints]: + return self.__prefix_icon_size_constraints + + @prefix_icon_size_constraints.setter + def prefix_icon_size_constraints(self, value: Optional[BoxConstraints]): + self.__prefix_icon_size_constraints = value + + # suffix_icon_size_constraints + @property + def suffix_icon_size_constraints(self) -> Optional[BoxConstraints]: + return self.__suffix_icon_size_constraints + + @suffix_icon_size_constraints.setter + def suffix_icon_size_constraints(self, value: Optional[BoxConstraints]): + self.__suffix_icon_size_constraints = value + + # size_constraints + @property + def size_constraints(self) -> Optional[BoxConstraints]: + return self.__size_constraints + + @size_constraints.setter + def size_constraints(self, value: Optional[BoxConstraints]): + self.__size_constraints = value + + # collapsed + @property + def collapsed(self) -> Optional[bool]: + return self._get_attr("collapsed", data_type="bool") + + @collapsed.setter + def collapsed(self, value: Optional[bool]): + self._set_attr("collapsed", value) + # bgcolor @property def bgcolor(self) -> Optional[str]: @@ -477,6 +609,24 @@ def prefix(self) -> Optional[Control]: def prefix(self, value: Optional[Control]): self.__prefix = value + # error + @property + def error(self) -> Optional[Control]: + return self.__error + + @error.setter + def error(self, value: Optional[Control]): + self.__error = value + + # helper + @property + def helper(self) -> Optional[Control]: + return self.__helper + + @helper.setter + def helper(self, value: Optional[Control]): + self.__helper = value + # counter @property def counter(self) -> Optional[Control]: diff --git a/sdk/python/packages/flet-core/src/flet_core/gesture_detector.py b/sdk/python/packages/flet-core/src/flet_core/gesture_detector.py index e5870c453..0c9eeab8b 100644 --- a/sdk/python/packages/flet-core/src/flet_core/gesture_detector.py +++ b/sdk/python/packages/flet-core/src/flet_core/gesture_detector.py @@ -1,21 +1,22 @@ import json -from typing import Any, Optional, Union +from typing import Any, Optional, Set, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.control_event import ControlEvent from flet_core.event_handler import EventHandler from flet_core.ref import Ref from flet_core.types import ( - AnimationValue, MouseCursor, OffsetValue, + OptionalControlEventCallable, + OptionalEventCallable, + PointerDeviceType, ResponsiveNumber, RotateValue, ScaleValue, - OptionalEventCallable, - OptionalControlEventCallable, ) @@ -75,6 +76,9 @@ def __init__( mouse_cursor: Optional[MouseCursor] = None, drag_interval: Optional[int] = None, hover_interval: Optional[int] = None, + exclude_from_semantics: Optional[bool] = None, + trackpad_scroll_causes_scale: Optional[bool] = None, + allowed_devices: Optional[Set[PointerDeviceType]] = None, on_tap=None, on_tap_down=None, on_tap_up=None, @@ -125,12 +129,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, @@ -317,10 +321,16 @@ def __init__( self.on_enter = on_enter self.on_exit = on_exit self.on_scroll = on_scroll + self.exclude_from_semantics = exclude_from_semantics + self.trackpad_scroll_causes_scale = trackpad_scroll_causes_scale + self.allowed_devices = allowed_devices def _get_control_name(self): return "gesturedetector" + def before_update(self): + self._set_attr_json("allowedDevices", self.__allowed_devices) + def _get_children(self): children = [] if self.__content: @@ -339,7 +349,7 @@ def content(self, value: Optional[Control]): # mouse_cursor @property - def mouse_cursor(self): + def mouse_cursor(self) -> Optional[MouseCursor]: return self.__mouse_cursor @mouse_cursor.setter @@ -350,7 +360,7 @@ def mouse_cursor(self, value: Optional[MouseCursor]): # drag_interval @property def drag_interval(self) -> Optional[int]: - return self._get_attr("dragInterval") + return self._get_attr("dragInterval", data_type="int") @drag_interval.setter def drag_interval(self, value: Optional[int]): @@ -359,12 +369,41 @@ def drag_interval(self, value: Optional[int]): # hover_interval @property def hover_interval(self) -> Optional[int]: - return self._get_attr("hoverInterval") + return self._get_attr("hoverInterval", data_type="int") @hover_interval.setter def hover_interval(self, value: Optional[int]): self._set_attr("hoverInterval", value) + # exclude_from_semantics + @property + def exclude_from_semantics(self) -> Optional[bool]: + return self._get_attr("excludeFromSemantics", data_type="bool", def_value=False) + + @exclude_from_semantics.setter + def exclude_from_semantics(self, value: Optional[bool]): + self._set_attr("excludeFromSemantics", value) + + # trackpad_scroll_causes_scale + @property + def trackpad_scroll_causes_scale(self) -> Optional[bool]: + return self._get_attr( + "trackpadScrollCausesScale", data_type="bool", def_value=False + ) + + @trackpad_scroll_causes_scale.setter + def trackpad_scroll_causes_scale(self, value: Optional[bool]): + self._set_attr("trackpadScrollCausesScale", value) + + # allowed_devices + @property + def allowed_devices(self) -> Optional[Set[PointerDeviceType]]: + return self.__allowed_devices + + @allowed_devices.setter + def allowed_devices(self, value: Optional[Set[PointerDeviceType]]): + self.__allowed_devices = value + # on_tap @property def on_tap(self) -> OptionalControlEventCallable: diff --git a/sdk/python/packages/flet-core/src/flet_core/grid_view.py b/sdk/python/packages/flet-core/src/flet_core/grid_view.py index b6d8338ae..112a997c9 100644 --- a/sdk/python/packages/flet-core/src/flet_core/grid_view.py +++ b/sdk/python/packages/flet-core/src/flet_core/grid_view.py @@ -1,19 +1,19 @@ -from typing import Any, List, Optional, Union, Callable, Sequence +from typing import Any, Callable, List, Optional, Sequence, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref -from flet_core.scrollable_control import ScrollableControl, OnScrollEvent +from flet_core.scrollable_control import OnScrollEvent, ScrollableControl from flet_core.types import ( - AnimationValue, + ClipBehavior, OffsetValue, + OptionalControlEventCallable, PaddingValue, ResponsiveNumber, RotateValue, ScaleValue, - ClipBehavior, - OptionalControlEventCallable, ) from flet_core.utils import deprecated @@ -97,12 +97,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/icon.py b/sdk/python/packages/flet-core/src/flet_core/icon.py index 2ed724673..34d00b3ef 100644 --- a/sdk/python/packages/flet-core/src/flet_core/icon.py +++ b/sdk/python/packages/flet-core/src/flet_core/icon.py @@ -1,12 +1,13 @@ -from typing import Any, Optional, Union +from typing import Any, List, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue +from flet_core.box import BoxShadow from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -52,6 +53,12 @@ def __init__( color: Optional[str] = None, size: OptionalNumber = None, semantics_label: Optional[str] = None, + shadows: Union[BoxShadow, List[BoxShadow], None] = None, + fill: OptionalNumber = None, + apply_text_scaling: Optional[bool] = None, + grade: OptionalNumber = None, + weight: OptionalNumber = None, + optical_size: OptionalNumber = None, # # ConstrainedControl # @@ -65,12 +72,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -108,10 +115,19 @@ def __init__( self.color = color self.size = size self.semantics_label = semantics_label + self.shadows = shadows + self.fill = fill + self.apply_text_scaling = apply_text_scaling + self.grade = grade + self.weight = weight + self.optical_size = optical_size def _get_control_name(self): return "icon" + def before_update(self): + self._set_attr_json("shadows", self.__shadows) + # name @property def name(self) -> Optional[str]: @@ -147,3 +163,57 @@ def semantics_label(self) -> Optional[str]: @semantics_label.setter def semantics_label(self, value: Optional[str]): self._set_attr("semanticsLabel", value) + + # shadows + @property + def shadows(self) -> Union[BoxShadow, List[BoxShadow], None]: + return self.__shadows + + @shadows.setter + def shadows(self, value: Union[BoxShadow, List[BoxShadow], None]): + self.__shadows = value + + # fill + @property + def fill(self) -> OptionalNumber: + return self._get_attr("fill", data_type="float") + + @fill.setter + def fill(self, value: OptionalNumber): + self._set_attr("fill", value) + + # apply_text_scaling + @property + def apply_text_scaling(self) -> Optional[bool]: + return self._get_attr("applyTextScaling", data_type="bool") + + @apply_text_scaling.setter + def apply_text_scaling(self, value: Optional[bool]): + self._set_attr("applyTextScaling", value) + + # grade + @property + def grade(self) -> OptionalNumber: + return self._get_attr("grade", data_type="float") + + @grade.setter + def grade(self, value: OptionalNumber): + self._set_attr("grade", value) + + # weight + @property + def weight(self) -> OptionalNumber: + return self._get_attr("weight", data_type="float") + + @weight.setter + def weight(self, value: OptionalNumber): + self._set_attr("weight", value) + + # optical_size + @property + def optical_size(self) -> OptionalNumber: + return self._get_attr("opticalSize", data_type="float") + + @optical_size.setter + def optical_size(self, value: OptionalNumber): + self._set_attr("opticalSize", value) diff --git a/sdk/python/packages/flet-core/src/flet_core/icon_button.py b/sdk/python/packages/flet-core/src/flet_core/icon_button.py index 37d276ecf..fd9c6e3a5 100644 --- a/sdk/python/packages/flet-core/src/flet_core/icon_button.py +++ b/sdk/python/packages/flet-core/src/flet_core/icon_button.py @@ -3,14 +3,15 @@ from flet_core.adaptive_control import AdaptiveControl from flet_core.alignment import Alignment +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue +from flet_core.box import BoxConstraints from flet_core.buttons import ButtonStyle from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, MouseCursor, OffsetValue, OptionalControlEventCallable, @@ -89,6 +90,7 @@ def __init__( url_target: Optional[UrlTarget] = None, mouse_cursor: Optional[MouseCursor] = None, visual_density: Union[None, ThemeVisualDensity, VisualDensity] = None, + size_constraints: Optional[BoxConstraints] = None, on_click: OptionalControlEventCallable = None, on_focus: OptionalControlEventCallable = None, on_blur: OptionalControlEventCallable = None, @@ -111,12 +113,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -184,6 +186,7 @@ def __init__( self.on_blur = on_blur self.mouse_cursor = mouse_cursor self.visual_density = visual_density + self.size_constraints = size_constraints def _get_control_name(self): return "iconbutton" @@ -197,6 +200,7 @@ def before_update(self): self._set_attr_json("style", self.__style) self._set_attr_json("alignment", self.__alignment) self._set_attr_json("padding", self.__padding) + self._set_attr_json("sizeConstraints", self.__size_constraints) def _get_children(self): if self.__content is None: @@ -333,6 +337,15 @@ def padding(self) -> PaddingValue: def padding(self, value: PaddingValue): self.__padding = value + # size_constraints + @property + def size_constraints(self) -> Optional[BoxConstraints]: + return self.__size_constraints + + @size_constraints.setter + def size_constraints(self, value: Optional[BoxConstraints]): + self.__size_constraints = value + # selected @property def selected(self) -> bool: diff --git a/sdk/python/packages/flet-core/src/flet_core/image.py b/sdk/python/packages/flet-core/src/flet_core/image.py index b1503cec6..e7a933126 100644 --- a/sdk/python/packages/flet-core/src/flet_core/image.py +++ b/sdk/python/packages/flet-core/src/flet_core/image.py @@ -1,5 +1,6 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.box import FilterQuality from flet_core.constrained_control import ConstrainedControl @@ -7,7 +8,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, BlendMode, BorderRadiusValue, ImageFit, @@ -86,12 +86,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/interactive_viewer.py b/sdk/python/packages/flet-core/src/flet_core/interactive_viewer.py index ae4d85de2..5e1f78306 100644 --- a/sdk/python/packages/flet-core/src/flet_core/interactive_viewer.py +++ b/sdk/python/packages/flet-core/src/flet_core/interactive_viewer.py @@ -3,6 +3,7 @@ from flet_core.adaptive_control import AdaptiveControl from flet_core.alignment import Alignment +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber @@ -11,7 +12,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ClipBehavior, MarginValue, Offset, @@ -105,12 +105,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/list_tile.py b/sdk/python/packages/flet-core/src/flet_core/list_tile.py index f25856f5b..e3e6a764d 100644 --- a/sdk/python/packages/flet-core/src/flet_core/list_tile.py +++ b/sdk/python/packages/flet-core/src/flet_core/list_tile.py @@ -2,6 +2,7 @@ from typing import Any, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.buttons import OutlinedBorder from flet_core.constrained_control import ConstrainedControl @@ -10,7 +11,6 @@ from flet_core.text_style import TextStyle from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, MouseCursor, OffsetValue, OptionalControlEventCallable, @@ -133,12 +133,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/list_view.py b/sdk/python/packages/flet-core/src/flet_core/list_view.py index aaccbb88e..a4383ce60 100644 --- a/sdk/python/packages/flet-core/src/flet_core/list_view.py +++ b/sdk/python/packages/flet-core/src/flet_core/list_view.py @@ -1,19 +1,19 @@ -from typing import Any, List, Optional, Union, Callable, Sequence +from typing import Any, Callable, List, Optional, Sequence, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref -from flet_core.scrollable_control import ScrollableControl, OnScrollEvent +from flet_core.scrollable_control import OnScrollEvent, ScrollableControl from flet_core.types import ( - AnimationValue, + ClipBehavior, OffsetValue, + OptionalControlEventCallable, PaddingValue, ResponsiveNumber, RotateValue, ScaleValue, - ClipBehavior, - OptionalControlEventCallable, ) from flet_core.utils import deprecated @@ -95,12 +95,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/lottie.py b/sdk/python/packages/flet-core/src/flet_core/lottie.py index 6ce5ba91f..da5bda475 100644 --- a/sdk/python/packages/flet-core/src/flet_core/lottie.py +++ b/sdk/python/packages/flet-core/src/flet_core/lottie.py @@ -1,5 +1,6 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.box import FilterQuality from flet_core.constrained_control import ConstrainedControl @@ -7,7 +8,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ImageFit, OffsetValue, OptionalControlEventCallable, @@ -56,12 +56,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/map/map.py b/sdk/python/packages/flet-core/src/flet_core/map/map.py index f5d0dacc8..41f7bbd0e 100644 --- a/sdk/python/packages/flet-core/src/flet_core/map/map.py +++ b/sdk/python/packages/flet-core/src/flet_core/map/map.py @@ -3,6 +3,7 @@ from typing import Any, List, Optional, Tuple, Union from flet_core import AnimationCurve +from flet_core.animation import AnimationCurve, AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber @@ -13,7 +14,6 @@ from flet_core.tooltip import TooltipValue from flet_core.transform import Offset from flet_core.types import ( - AnimationValue, ControlEvent, DurationValue, Number, @@ -68,12 +68,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/map/map_configuration.py b/sdk/python/packages/flet-core/src/flet_core/map/map_configuration.py index 9de102088..4f6709f66 100644 --- a/sdk/python/packages/flet-core/src/flet_core/map/map_configuration.py +++ b/sdk/python/packages/flet-core/src/flet_core/map/map_configuration.py @@ -1,12 +1,11 @@ from dataclasses import dataclass, field -from enum import IntFlag +from enum import Enum, EnumMeta, IntFlag from typing import Optional, Union +from warnings import warn from flet_core.animation import AnimationCurve from flet_core.control import OptionalNumber -from flet_core.types import ( - DurationValue, -) +from flet_core.types import DurationValue @dataclass @@ -51,6 +50,34 @@ class MapMultiFingerGesture(IntFlag): ALL = (1 << 0) | (1 << 1) | (1 << 2) +class MapPointerDeviceTypeDeprecated(EnumMeta): + def __getattribute__(self, item): + if item in [ + "TOUCH", + "MOUSE", + "STYLUS", + "INVERTED_STYLUS", + "TRACKPAD", + "UNKNOWN", + ]: + warn( + "MapPointerDeviceType enum is deprecated since version 0.25.0 " + "and will be removed in version 0.28.0. Use PointerDeviceType enum instead.", + DeprecationWarning, + stacklevel=2, + ) + return EnumMeta.__getattribute__(self, item) + + +class MapPointerDeviceType(Enum, metaclass=MapPointerDeviceTypeDeprecated): + TOUCH = "touch" + MOUSE = "mouse" + STYLUS = "stylus" + INVERTED_STYLUS = "invertedStylus" + TRACKPAD = "trackpad" + UNKNOWN = "unknown" + + @dataclass class MapInteractionConfiguration: enable_multi_finger_gesture_race: Optional[bool] = field(default=None) diff --git a/sdk/python/packages/flet-core/src/flet_core/markdown.py b/sdk/python/packages/flet-core/src/flet_core/markdown.py index b2a79595e..02ac633cd 100644 --- a/sdk/python/packages/flet-core/src/flet_core/markdown.py +++ b/sdk/python/packages/flet-core/src/flet_core/markdown.py @@ -1,21 +1,20 @@ -import json import warnings from dataclasses import dataclass -from enum import Enum +from enum import Enum, EnumMeta from typing import Any, Optional, Union, cast +from warnings import warn +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.box import BoxDecoration from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber -from flet_core.control_event import ControlEvent from flet_core.event_handler import EventHandler from flet_core.ref import Ref -from flet_core.text import TextSelection +from flet_core.text import TextSelectionChangeEvent from flet_core.text_style import TextStyle from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, MainAxisAlignment, OffsetValue, OptionalControlEventCallable, @@ -40,7 +39,31 @@ class MarkdownExtensionSet(Enum): GITHUB_FLAVORED = "gitHubFlavored" -class MarkdownSelectionChangeCause(Enum): +class MarkdownSelectionChangeCauseDeprecated(EnumMeta): + def __getattribute__(self, item): + if item in [ + "UNKNOWN", + "TAP", + "DOUBLE_TAP", + "LONG_PRESS", + "FORCE_PRESS", + "KEYBOARD", + "TOOLBAR", + "DRAG", + "SCRIBBLE", + ]: + warn( + "MarkdownSelectionChangeCause enum is deprecated since version 0.25.0 " + "and will be removed in version 0.28.0. Use TextSelectionChangeCause enum instead.", + DeprecationWarning, + stacklevel=2, + ) + return EnumMeta.__getattribute__(self, item) + + +class MarkdownSelectionChangeCause( + Enum, metaclass=MarkdownSelectionChangeCauseDeprecated +): UNKNOWN = "unknown" TAP = "tap" DOUBLE_TAP = "doubleTap" @@ -52,26 +75,9 @@ class MarkdownSelectionChangeCause(Enum): SCRIBBLE = "scribble" -class MarkdownSelectionChangeEvent(ControlEvent): - def __init__(self, e: ControlEvent): - super().__init__(e.target, e.name, e.data, e.control, e.page) - d = json.loads(e.data) - self.text: str = d.get("text") - self.cause = MarkdownSelectionChangeCause(d.get("cause")) - start = d.get("start") - end = d.get("end") - self.selection = TextSelection( - start=start, - end=end, - selection=self.text[start:end] if start != -1 and end != -1 else "", - base_offset=d.get("base_offset"), - extent_offset=d.get("extent_offset"), - affinity=d.get("affinity"), - directional=d.get("directional"), - collapsed=d.get("collapsed"), - valid=d.get("valid"), - normalized=d.get("normalized"), - ) +# deprecated in v0.25.0 and will be removed in v0.28.0 +class MarkdownSelectionChangeEvent(TextSelectionChangeEvent): + pass @dataclass @@ -244,7 +250,9 @@ def __init__( code_style_sheet: Optional[MarkdownStyleSheet] = None, md_style_sheet: Optional[MarkdownStyleSheet] = None, on_tap_text: OptionalControlEventCallable = None, - on_selection_change: OptionalControlEventCallable = None, + on_selection_change: OptionalEventCallable[ + Union[TextSelectionChangeEvent, MarkdownSelectionChangeEvent] + ] = None, on_tap_link: OptionalControlEventCallable = None, # # ConstrainedControl @@ -265,12 +273,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -310,9 +318,7 @@ def __init__( data=data, ) - self.__on_selection_change = EventHandler( - lambda e: MarkdownSelectionChangeEvent(e) - ) + self.__on_selection_change = EventHandler(lambda e: TextSelectionChangeEvent(e)) self._add_event_handler( "selection_change", self.__on_selection_change.get_handler() @@ -507,11 +513,16 @@ def on_tap_text(self, handler: OptionalControlEventCallable): @property def on_selection_change( self, - ) -> OptionalEventCallable[MarkdownSelectionChangeEvent]: + ) -> OptionalEventCallable[ + Union[TextSelectionChangeEvent, MarkdownSelectionChangeEvent] + ]: return self.__on_selection_change.handler @on_selection_change.setter def on_selection_change( - self, handler: OptionalEventCallable[MarkdownSelectionChangeEvent] + self, + handler: OptionalEventCallable[ + Union[TextSelectionChangeEvent, MarkdownSelectionChangeEvent] + ], ): self.__on_selection_change.handler = handler diff --git a/sdk/python/packages/flet-core/src/flet_core/matplotlib_chart.py b/sdk/python/packages/flet-core/src/flet_core/matplotlib_chart.py index 406c765b6..1046cc54d 100644 --- a/sdk/python/packages/flet-core/src/flet_core/matplotlib_chart.py +++ b/sdk/python/packages/flet-core/src/flet_core/matplotlib_chart.py @@ -4,6 +4,7 @@ from typing import Any, Optional, Union from flet_core import alignment +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.container import Container from flet_core.control import OptionalNumber @@ -11,7 +12,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ImageFit, OffsetValue, OptionalControlEventCallable, @@ -88,12 +88,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/menu_bar.py b/sdk/python/packages/flet-core/src/flet_core/menu_bar.py index a032985f8..1279f9216 100644 --- a/sdk/python/packages/flet-core/src/flet_core/menu_bar.py +++ b/sdk/python/packages/flet-core/src/flet_core/menu_bar.py @@ -1,5 +1,5 @@ -from dataclasses import dataclass, field -from typing import Any, Dict, List, Optional, Sequence, Union +from dataclasses import dataclass +from typing import Any, List, Optional, Sequence, Union from flet_core.alignment import Alignment from flet_core.border import BorderSide @@ -9,6 +9,7 @@ from flet_core.types import ( ClipBehavior, ControlState, + ControlStateValue, MouseCursor, OptionalNumber, PaddingValue, @@ -18,29 +19,25 @@ @dataclass class MenuStyle: - alignment: Optional[Alignment] = field(default=None) - bgcolor: Union[None, str, Dict[Union[str, ControlState], str]] = field(default=None) - shadow_color: Union[None, str, Dict[Union[str, ControlState], str]] = field( - default=None - ) - surface_tint_color: Union[None, str, Dict[Union[str, ControlState], str]] = field( - default=None - ) - elevation: Union[ - None, float, int, Dict[Union[str, ControlState], Union[float, int]] - ] = field(default=None) - padding: Union[PaddingValue, Dict[Union[str, ControlState], PaddingValue]] = field( - default=None - ) - side: Union[None, BorderSide, Dict[Union[str, ControlState], BorderSide]] = field( - default=None - ) - shape: Union[ - None, OutlinedBorder, Dict[Union[str, ControlState], OutlinedBorder] - ] = field(default=None) - mouse_cursor: Union[ - None, MouseCursor, Dict[Union[str, ControlState], MouseCursor] - ] = field(default=None) + alignment: Optional[Alignment] = None + bgcolor: ControlStateValue[str] = None + shadow_color: ControlStateValue[str] = None + surface_tint_color: ControlStateValue[str] = None + elevation: ControlStateValue[OptionalNumber] = None + padding: ControlStateValue[PaddingValue] = None + side: ControlStateValue[BorderSide] = None + shape: ControlStateValue[OutlinedBorder] = None + mouse_cursor: ControlStateValue[MouseCursor] = None + + def __post_init__(self): + if not isinstance(self.padding, dict): + self.padding = {ControlState.DEFAULT: self.padding} + + if not isinstance(self.side, dict): + self.side = {ControlState.DEFAULT: self.side} + + if not isinstance(self.shape, dict): + self.shape = {ControlState.DEFAULT: self.shape} class MenuBar(Control): diff --git a/sdk/python/packages/flet-core/src/flet_core/menu_item_button.py b/sdk/python/packages/flet-core/src/flet_core/menu_item_button.py index 7f1c66e6c..45d060529 100644 --- a/sdk/python/packages/flet-core/src/flet_core/menu_item_button.py +++ b/sdk/python/packages/flet-core/src/flet_core/menu_item_button.py @@ -2,6 +2,7 @@ from typing import Any, Optional, Union from flet_core.alignment import Axis +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.buttons import ButtonStyle from flet_core.constrained_control import ConstrainedControl @@ -9,7 +10,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ClipBehavior, OffsetValue, OptionalControlEventCallable, @@ -64,12 +64,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, 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 230da22d6..7879cffc0 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 @@ -1,7 +1,8 @@ from enum import Enum -from typing import Any, Callable, Dict, List, Optional, Union +from typing import Any, Callable, List, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.border import Border from flet_core.buttons import OutlinedBorder @@ -10,8 +11,7 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, - ControlState, + ControlStateValue, OffsetValue, OptionalControlEventCallable, OptionalNumber, @@ -30,7 +30,7 @@ class NavigationBarLabelBehavior(Enum): ONLY_SHOW_SELECTED = "onlyShowSelected" -class NavigationBarDestination(Control): +class NavigationBarDestination(AdaptiveControl, Control): """Defines the appearance of the button items that are arrayed within the navigation bar. The value must be a list of two or more NavigationBarDestination instances.""" @@ -49,15 +49,23 @@ def __init__( ref: Optional[Ref] = None, tooltip: TooltipValue = None, disabled: Optional[bool] = None, + visible: Optional[bool] = None, data: Any = None, + # + # AdaptiveControl + # + adaptive: Optional[bool] = None, ): Control.__init__( self, ref=ref, tooltip=tooltip, disabled=disabled, + visible=visible, data=data, ) + AdaptiveControl.__init__(self, adaptive=adaptive) + self.label = label self.icon = icon self.icon_content = icon_content @@ -219,7 +227,7 @@ def __init__( surface_tint_color: Optional[str] = None, border: Optional[Border] = None, animation_duration: Optional[int] = None, - overlay_color: Union[None, str, Dict[ControlState, str]] = None, + overlay_color: ControlStateValue[str] = None, on_change: OptionalControlEventCallable = None, # # ConstrainedControl and AdaptiveControl @@ -239,12 +247,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: Callable[..., None] = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, @@ -303,7 +311,7 @@ def before_update(self): super().before_update() self._set_attr_json("indicatorShape", self.__indicator_shape) self._set_attr_json("border", self.__border) - self._set_attr_json("overlayColor", self.__overlay_color) + self._set_attr_json("overlayColor", self.__overlay_color, wrap_attr_dict=True) def _get_children(self): return self.__destinations @@ -338,11 +346,11 @@ def label_behavior(self, value: Optional[NavigationBarLabelBehavior]): # overlay_color @property - def overlay_color(self) -> Union[None, str, Dict[ControlState, str]]: + def overlay_color(self) -> ControlStateValue[str]: return self.__overlay_color @overlay_color.setter - def overlay_color(self, value: Union[None, str, Dict[ControlState, str]]): + def overlay_color(self, value: ControlStateValue[str]): self.__overlay_color = value # bgcolor diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index f9b746d76..b70be25af 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -23,9 +23,17 @@ def __init__( # Control # ref: Optional[Ref] = None, - badge: Optional[BadgeValue] = None, + data: Any = None, + disabled: Optional[bool] = None, + visible: Optional[bool] = None, ): - Control.__init__(self, ref=ref, badge=badge) + Control.__init__( + self, + ref=ref, + disabled=disabled, + data=data, + visible=visible, + ) self.label = label self.bgcolor = bgcolor self.icon = icon 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 b9f1df806..c5afe4cfe 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, Callable, List, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.buttons import OutlinedBorder from flet_core.constrained_control import ConstrainedControl @@ -8,7 +9,6 @@ from flet_core.ref import Ref from flet_core.text_style import TextStyle from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, OptionalNumber, @@ -42,14 +42,10 @@ def __init__( # ref: Optional[Ref] = None, disabled: Optional[bool] = None, + visible: Optional[bool] = None, data: Any = None, ) -> None: - Control.__init__( - self, - ref=ref, - disabled=disabled, - data=data, - ) + Control.__init__(self, ref=ref, disabled=disabled, visible=visible, data=data) self.label = label self.icon = icon self.icon_content = icon_content @@ -258,12 +254,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: Callable[..., None] = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/outlined_button.py b/sdk/python/packages/flet-core/src/flet_core/outlined_button.py index 7dfe28d0f..ea5c03943 100644 --- a/sdk/python/packages/flet-core/src/flet_core/outlined_button.py +++ b/sdk/python/packages/flet-core/src/flet_core/outlined_button.py @@ -2,6 +2,7 @@ from typing import Any, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.buttons import ButtonStyle from flet_core.constrained_control import ConstrainedControl @@ -9,7 +10,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ClipBehavior, OffsetValue, OptionalControlEventCallable, @@ -79,12 +79,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/pagelet.py b/sdk/python/packages/flet-core/src/flet_core/pagelet.py index fb9c85590..633470cbe 100644 --- a/sdk/python/packages/flet-core/src/flet_core/pagelet.py +++ b/sdk/python/packages/flet-core/src/flet_core/pagelet.py @@ -1,6 +1,7 @@ from typing import Any, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.app_bar import AppBar from flet_core.badge import BadgeValue from flet_core.bottom_app_bar import BottomAppBar @@ -14,7 +15,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, FloatingActionButtonLocation, OffsetValue, OptionalControlEventCallable, @@ -85,12 +85,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/placeholder.py b/sdk/python/packages/flet-core/src/flet_core/placeholder.py index 104737d2a..00cda7e93 100644 --- a/sdk/python/packages/flet-core/src/flet_core/placeholder.py +++ b/sdk/python/packages/flet-core/src/flet_core/placeholder.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -50,12 +50,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/plotly_chart.py b/sdk/python/packages/flet-core/src/flet_core/plotly_chart.py index cc6d54123..59bd51550 100644 --- a/sdk/python/packages/flet-core/src/flet_core/plotly_chart.py +++ b/sdk/python/packages/flet-core/src/flet_core/plotly_chart.py @@ -3,6 +3,7 @@ from typing import Any, Optional, Union from flet_core import alignment +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.container import Container from flet_core.control import OptionalNumber @@ -10,7 +11,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ImageFit, OffsetValue, OptionalControlEventCallable, @@ -69,12 +69,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/popup_menu_button.py b/sdk/python/packages/flet-core/src/flet_core/popup_menu_button.py index 3f1614565..6d6ddb708 100644 --- a/sdk/python/packages/flet-core/src/flet_core/popup_menu_button.py +++ b/sdk/python/packages/flet-core/src/flet_core/popup_menu_button.py @@ -2,14 +2,15 @@ from enum import Enum from typing import Any, List, Optional, Union +from flet_core.animation import AnimationStyle, AnimationValue from flet_core.badge import BadgeValue -from flet_core.buttons import OutlinedBorder +from flet_core.box import BoxConstraints +from flet_core.buttons import ButtonStyle, OutlinedBorder from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ClipBehavior, MouseCursor, OffsetValue, @@ -207,9 +208,14 @@ def __init__( enable_feedback: Optional[bool] = None, shape: Optional[OutlinedBorder] = None, padding: PaddingValue = None, + menu_padding: PaddingValue = None, + style: Optional[ButtonStyle] = None, + popup_animation_style: Optional[AnimationStyle] = None, + size_constraints: Optional[BoxConstraints] = None, on_cancelled: OptionalControlEventCallable = None, on_open: OptionalControlEventCallable = None, on_cancel: OptionalControlEventCallable = None, + on_select: OptionalControlEventCallable = None, # # ConstrainedControl # @@ -229,12 +235,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, visible: Optional[bool] = None, @@ -279,6 +285,7 @@ def __init__( self.on_open = on_open self.shape = shape self.padding = padding + self.menu_padding = menu_padding self.clip_behavior = clip_behavior self.bgcolor = bgcolor self.icon_color = icon_color @@ -288,9 +295,12 @@ def __init__( self.icon_size = icon_size self.elevation = elevation self.enable_feedback = enable_feedback - self.__content: Optional[Control] = None self.content = content self.menu_position = menu_position + self.style = style + self.popup_animation_style = popup_animation_style + self.size_constraints = size_constraints + self.on_select = on_select def _get_control_name(self): return "popupmenubutton" @@ -306,6 +316,10 @@ def before_update(self): super().before_update() self._set_attr_json("shape", self.__shape) self._set_attr_json("padding", self.__padding) + self._set_attr_json("menuPadding", self.__menu_padding) + self._set_attr_json("style", self.__style) + self._set_attr_json("popupAnimationStyle", self.__popup_animation_style) + self._set_attr_json("sizeConstraints", self.__size_constraints) # items @property @@ -325,6 +339,24 @@ def shape(self) -> Optional[OutlinedBorder]: def shape(self, value: Optional[OutlinedBorder]): self.__shape = value + # size_constraints + @property + def size_constraints(self) -> Optional[BoxConstraints]: + return self.__size_constraints + + @size_constraints.setter + def size_constraints(self, value: Optional[BoxConstraints]): + self.__size_constraints = value + + # menu_padding + @property + def menu_padding(self) -> PaddingValue: + return self.__menu_padding + + @menu_padding.setter + def menu_padding(self, value: PaddingValue): + self.__menu_padding = value + # padding @property def padding(self) -> PaddingValue: @@ -424,13 +456,31 @@ def content(self) -> Optional[Control]: def content(self, value: Optional[Control]): self.__content = value + # style + @property + def style(self) -> Optional[ButtonStyle]: + return self.__style + + @style.setter + def style(self, value: Optional[ButtonStyle]): + self.__style = value + + # popup_animation_style + @property + def popup_animation_style(self) -> Optional[AnimationStyle]: + return self.__popup_animation_style + + @popup_animation_style.setter + def popup_animation_style(self, value: Optional[AnimationStyle]): + self.__popup_animation_style = value + # menu_position @property - def menu_position(self) -> PopupMenuPosition: + def menu_position(self) -> Optional[PopupMenuPosition]: return self.__menu_position @menu_position.setter - def menu_position(self, value: PopupMenuPosition): + def menu_position(self, value: Optional[PopupMenuPosition]): self.__menu_position = value self._set_enum_attr("menuPosition", value, PopupMenuPosition) @@ -483,3 +533,12 @@ def on_open(self) -> OptionalControlEventCallable: @on_open.setter def on_open(self, handler: OptionalControlEventCallable): self._add_event_handler("open", handler) + + # on_select + @property + def on_select(self) -> OptionalControlEventCallable: + return self._get_event_handler("select") + + @on_select.setter + def on_select(self, handler: OptionalControlEventCallable): + self._add_event_handler("select", handler) diff --git a/sdk/python/packages/flet-core/src/flet_core/progress_bar.py b/sdk/python/packages/flet-core/src/flet_core/progress_bar.py index 49ff5a19f..8d702bc3f 100644 --- a/sdk/python/packages/flet-core/src/flet_core/progress_bar.py +++ b/sdk/python/packages/flet-core/src/flet_core/progress_bar.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, BorderRadiusValue, OffsetValue, OptionalControlEventCallable, @@ -80,12 +80,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/progress_ring.py b/sdk/python/packages/flet-core/src/flet_core/progress_ring.py index 9b9a9fff1..91c349a18 100644 --- a/sdk/python/packages/flet-core/src/flet_core/progress_ring.py +++ b/sdk/python/packages/flet-core/src/flet_core/progress_ring.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -83,12 +83,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/radio.py b/sdk/python/packages/flet-core/src/flet_core/radio.py index 30f207543..17b0b9eee 100644 --- a/sdk/python/packages/flet-core/src/flet_core/radio.py +++ b/sdk/python/packages/flet-core/src/flet_core/radio.py @@ -1,6 +1,7 @@ -from typing import Any, Dict, Optional, Union +from typing import Any, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber @@ -8,8 +9,7 @@ from flet_core.text_style import TextStyle from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, - ControlState, + ControlStateValue, LabelPosition, MouseCursor, OffsetValue, @@ -64,9 +64,9 @@ def __init__( label_style: Optional[TextStyle] = None, value: Optional[str] = None, autofocus: Optional[bool] = None, - fill_color: Union[None, str, Dict[ControlState, str]] = None, + fill_color: ControlStateValue[str] = None, active_color: Optional[str] = None, - overlay_color: Union[None, str, Dict[ControlState, str]] = None, + overlay_color: ControlStateValue[str] = None, hover_color: Optional[str] = None, focus_color: Optional[str] = None, splash_radius: OptionalNumber = None, @@ -94,12 +94,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -164,10 +164,9 @@ def _get_control_name(self): def before_update(self): super().before_update() - self._set_attr_json("fillColor", self.__fill_color) - self._set_attr_json("overlayColor", self.__overlay_color) - if isinstance(self.__label_style, TextStyle): - self._set_attr_json("labelStyle", self.__label_style) + self._set_attr_json("fillColor", self.__fill_color, wrap_attr_dict=True) + self._set_attr_json("overlayColor", self.__overlay_color, wrap_attr_dict=True) + self._set_attr_json("labelStyle", self.__label_style) # value @property @@ -264,20 +263,20 @@ def label_style(self, value: Optional[TextStyle]): # fill_color @property - def fill_color(self) -> Union[None, str, Dict[ControlState, str]]: + def fill_color(self) -> ControlStateValue[str]: return self.__fill_color @fill_color.setter - def fill_color(self, value: Union[None, str, Dict[ControlState, str]]): + def fill_color(self, value: ControlStateValue[str]): self.__fill_color = value # overlay_color @property - def overlay_color(self) -> Union[None, str, Dict[ControlState, str]]: + def overlay_color(self) -> ControlStateValue[str]: return self.__overlay_color @overlay_color.setter - def overlay_color(self, value: Union[None, str, Dict[ControlState, str]]): + def overlay_color(self, value: ControlStateValue[str]): self.__overlay_color = value # on_focus diff --git a/sdk/python/packages/flet-core/src/flet_core/range_slider.py b/sdk/python/packages/flet-core/src/flet_core/range_slider.py index 3c6af1bd8..12377d69d 100644 --- a/sdk/python/packages/flet-core/src/flet_core/range_slider.py +++ b/sdk/python/packages/flet-core/src/flet_core/range_slider.py @@ -1,13 +1,13 @@ -from typing import Any, Dict, Optional, Union +from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, - ControlState, + ControlStateValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -87,7 +87,7 @@ def __init__( round: Optional[int] = None, active_color: Optional[str] = None, inactive_color: Optional[str] = None, - overlay_color: Union[None, str, Dict[ControlState, str]] = None, + overlay_color: ControlStateValue[str] = None, on_change: OptionalControlEventCallable = None, on_change_start: OptionalControlEventCallable = None, on_change_end: OptionalControlEventCallable = None, @@ -110,12 +110,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -174,7 +174,7 @@ def _get_control_name(self): def before_update(self): super().before_update() - self._set_attr_json("overlayColor", self.__overlay_color) + self._set_attr_json("overlayColor", self.__overlay_color, wrap_attr_dict=True) # start_value @property @@ -265,11 +265,11 @@ def inactive_color(self, value: Optional[str]): # overlay_color @property - def overlay_color(self) -> Union[None, str, Dict[ControlState, str]]: + def overlay_color(self) -> ControlStateValue[str]: return self.__overlay_color @overlay_color.setter - def overlay_color(self, value: Union[None, str, Dict[ControlState, str]]): + def overlay_color(self, value: ControlStateValue[str]): self.__overlay_color = value # on_change diff --git a/sdk/python/packages/flet-core/src/flet_core/responsive_row.py b/sdk/python/packages/flet-core/src/flet_core/responsive_row.py index bd28b313c..ca3698357 100644 --- a/sdk/python/packages/flet-core/src/flet_core/responsive_row.py +++ b/sdk/python/packages/flet-core/src/flet_core/responsive_row.py @@ -1,18 +1,18 @@ -from typing import Any, Optional, Union, Sequence +from typing import Any, Optional, Sequence, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.types import ( - AnimationValue, CrossAxisAlignment, MainAxisAlignment, OffsetValue, + OptionalControlEventCallable, ResponsiveNumber, RotateValue, ScaleValue, - OptionalControlEventCallable, ) from flet_core.utils import deprecated @@ -77,12 +77,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/rive.py b/sdk/python/packages/flet-core/src/flet_core/rive.py index 0a1860311..6556ec765 100644 --- a/sdk/python/packages/flet-core/src/flet_core/rive.py +++ b/sdk/python/packages/flet-core/src/flet_core/rive.py @@ -1,13 +1,13 @@ from typing import Any, Optional, Union from flet_core.alignment import Alignment +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ImageFit, OffsetValue, OptionalControlEventCallable, @@ -54,12 +54,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/row.py b/sdk/python/packages/flet-core/src/flet_core/row.py index 775ad5b63..4b394813c 100644 --- a/sdk/python/packages/flet-core/src/flet_core/row.py +++ b/sdk/python/packages/flet-core/src/flet_core/row.py @@ -1,22 +1,22 @@ -from typing import Any, List, Optional, Union, Sequence +from typing import Any, List, Optional, Sequence, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control from flet_core.ref import Ref -from flet_core.scrollable_control import ScrollableControl, OnScrollEvent +from flet_core.scrollable_control import OnScrollEvent, ScrollableControl from flet_core.types import ( - AnimationValue, CrossAxisAlignment, MainAxisAlignment, OffsetValue, + OptionalControlEventCallable, + OptionalEventCallable, OptionalNumber, ResponsiveNumber, RotateValue, ScaleValue, ScrollMode, - OptionalEventCallable, - OptionalControlEventCallable, ) from flet_core.utils import deprecated @@ -95,12 +95,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/safe_area.py b/sdk/python/packages/flet-core/src/flet_core/safe_area.py index ad1a80859..79b3b20c4 100644 --- a/sdk/python/packages/flet-core/src/flet_core/safe_area.py +++ b/sdk/python/packages/flet-core/src/flet_core/safe_area.py @@ -2,13 +2,13 @@ from typing import Any, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, PaddingValue, @@ -44,12 +44,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/search_bar.py b/sdk/python/packages/flet-core/src/flet_core/search_bar.py index a357de6e8..1c1d41b15 100644 --- a/sdk/python/packages/flet-core/src/flet_core/search_bar.py +++ b/sdk/python/packages/flet-core/src/flet_core/search_bar.py @@ -2,8 +2,10 @@ from typing import Any, Dict, List, Optional, Sequence, Union from flet_core import BoxConstraints +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.border import BorderSide +from flet_core.box import BoxConstraints from flet_core.buttons import OutlinedBorder from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control @@ -12,8 +14,8 @@ from flet_core.textfield import KeyboardType, TextCapitalization from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ControlState, + ControlStateValue, Number, OffsetValue, OptionalControlEventCallable, @@ -42,8 +44,8 @@ def __init__( bar_leading: Optional[Control] = None, bar_trailing: Optional[List[Control]] = None, bar_hint_text: Optional[str] = None, - bar_bgcolor: Union[None, str, Dict[ControlState, str]] = None, - bar_overlay_color: Union[None, str, Dict[ControlState, str]] = None, + bar_bgcolor: ControlStateValue[str] = None, + bar_overlay_color: ControlStateValue[str] = None, bar_shadow_color: Union[None, str, Dict[ControlState, str]] = None, bar_surface_tint_color: Union[None, str, Dict[ControlState, str]] = None, bar_elevation: Union[OptionalNumber, Dict[ControlState, Number]] = None, @@ -94,12 +96,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -179,20 +181,26 @@ def _get_control_name(self): def before_update(self): super().before_update() - self._set_control_state_attr_json("barBgcolor", self.__bar_bgcolor) - self._set_control_state_attr_json("barOverlayColor", self.__bar_overlay_color) - self._set_control_state_attr_json( - "barHintTextStyle", self.__bar_hint_text_style + self._set_attr_json("barBgcolor", self.__bar_bgcolor, wrap_attr_dict=True) + self._set_attr_json( + "barOverlayColor", self.__bar_overlay_color, wrap_attr_dict=True ) - self._set_control_state_attr_json( - "barSurfaceTintColor", self.__bar_surface_tint_color + self._set_attr_json( + "barHintTextStyle", self.__bar_hint_text_style, wrap_attr_dict=True + ) + self._set_attr_json( + "barSurfaceTintColor", self.__bar_surface_tint_color, wrap_attr_dict=True + ) + self._set_attr_json("barElevation", self.__bar_elevation, wrap_attr_dict=True) + self._set_attr_json( + "barBorderSide", self.__bar_border_side, wrap_attr_dict=True + ) + self._set_attr_json("barShape", self.__bar_shape, wrap_attr_dict=True) + self._set_attr_json("barTextStyle", self.__bar_text_style, wrap_attr_dict=True) + self._set_attr_json("barPadding", self.__bar_padding, wrap_attr_dict=True) + self._set_attr_json( + "barShadowColor", self.__bar_shadow_color, wrap_attr_dict=True ) - self._set_control_state_attr_json("barElevation", self.__bar_elevation) - self._set_control_state_attr_json("barBorderSide", self.__bar_border_side) - self._set_control_state_attr_json("barShape", self.__bar_shape) - self._set_control_state_attr_json("barTextStyle", self.__bar_text_style) - self._set_control_state_attr_json("barPadding", self.__bar_padding) - self._set_control_state_attr_json("barShadowColor", self.__bar_shadow_color) self._set_attr_json("viewShape", self.__view_shape) self._set_attr_json("viewHeaderTextStyle", self.__view_header_text_style) self._set_attr_json("viewHintTextStyle", self.__view_hint_text_style) @@ -278,20 +286,20 @@ def bar_trailing(self, value: Optional[List[Control]]): # bar_bgcolor @property - def bar_bgcolor(self) -> Union[None, str, Dict[ControlState, str]]: + def bar_bgcolor(self) -> ControlStateValue[str]: return self.__bar_bgcolor @bar_bgcolor.setter - def bar_bgcolor(self, value: Union[None, str, Dict[ControlState, str]]): + def bar_bgcolor(self, value: ControlStateValue[str]): self.__bar_bgcolor = value # bar_overlay_color @property - def bar_overlay_color(self) -> Union[None, str, Dict[ControlState, str]]: + def bar_overlay_color(self) -> ControlStateValue[str]: return self.__bar_overlay_color @bar_overlay_color.setter - def bar_overlay_color(self, value: Union[None, str, Dict[ControlState, str]]): + def bar_overlay_color(self, value: ControlStateValue[str]): self.__bar_overlay_color = value # bar_shadow_color diff --git a/sdk/python/packages/flet-core/src/flet_core/segmented_button.py b/sdk/python/packages/flet-core/src/flet_core/segmented_button.py index acffb5631..f5b0bc6d4 100644 --- a/sdk/python/packages/flet-core/src/flet_core/segmented_button.py +++ b/sdk/python/packages/flet-core/src/flet_core/segmented_button.py @@ -1,6 +1,7 @@ import json from typing import Any, List, Optional, Set, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.buttons import ButtonStyle from flet_core.constrained_control import ConstrainedControl @@ -8,7 +9,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -137,12 +137,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, visible: Optional[bool] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/shader_mask.py b/sdk/python/packages/flet-core/src/flet_core/shader_mask.py index 3366df2a1..d0aa8e082 100644 --- a/sdk/python/packages/flet-core/src/flet_core/shader_mask.py +++ b/sdk/python/packages/flet-core/src/flet_core/shader_mask.py @@ -1,5 +1,6 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber @@ -7,7 +8,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, BlendMode, BorderRadiusValue, OffsetValue, @@ -79,12 +79,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/slider.py b/sdk/python/packages/flet-core/src/flet_core/slider.py index 4b5f71049..bc67ccaa2 100644 --- a/sdk/python/packages/flet-core/src/flet_core/slider.py +++ b/sdk/python/packages/flet-core/src/flet_core/slider.py @@ -1,15 +1,15 @@ from enum import Enum -from typing import Any, Dict, Optional, Union +from typing import Any, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, - ControlState, + ControlStateValue, MouseCursor, OffsetValue, OptionalControlEventCallable, @@ -65,7 +65,7 @@ def __init__( thumb_color: Optional[str] = None, interaction: Optional[SliderInteraction] = None, secondary_active_color: Optional[str] = None, - overlay_color: Union[None, str, Dict[ControlState, str]] = None, + overlay_color: ControlStateValue[str] = None, secondary_track_value: OptionalNumber = None, mouse_cursor: Optional[MouseCursor] = None, on_change: OptionalControlEventCallable = None, @@ -92,12 +92,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -175,7 +175,7 @@ def before_update(self): assert ( self.max is None or self.value is None or (self.value <= self.max) ), "value must be less than or equal to max" - self._set_attr_json("overlayColor", self.__overlay_color) + self._set_attr_json("overlayColor", self.__overlay_color, wrap_attr_dict=True) # value @property @@ -270,11 +270,11 @@ def round(self, value: Optional[int]): # overlay_color @property - def overlay_color(self) -> Union[None, str, Dict[ControlState, str]]: + def overlay_color(self) -> ControlStateValue[str]: return self.__overlay_color @overlay_color.setter - def overlay_color(self, value: Union[None, str, Dict[ControlState, str]]): + def overlay_color(self, value: ControlStateValue[str]): self.__overlay_color = value # autofocus diff --git a/sdk/python/packages/flet-core/src/flet_core/stack.py b/sdk/python/packages/flet-core/src/flet_core/stack.py index a3a4e6a90..da91d746a 100644 --- a/sdk/python/packages/flet-core/src/flet_core/stack.py +++ b/sdk/python/packages/flet-core/src/flet_core/stack.py @@ -1,19 +1,19 @@ from enum import Enum -from typing import Any, List, Optional, Union, Sequence +from typing import Any, List, Optional, Sequence, Union from flet_core.adaptive_control import AdaptiveControl from flet_core.alignment import Alignment +from flet_core.animation import AnimationValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.types import ( - AnimationValue, ClipBehavior, OffsetValue, + OptionalControlEventCallable, ResponsiveNumber, RotateValue, ScaleValue, - OptionalControlEventCallable, ) @@ -97,12 +97,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/submenu_button.py b/sdk/python/packages/flet-core/src/flet_core/submenu_button.py index 26fe10644..4d6a1a92d 100644 --- a/sdk/python/packages/flet-core/src/flet_core/submenu_button.py +++ b/sdk/python/packages/flet-core/src/flet_core/submenu_button.py @@ -1,6 +1,7 @@ import time from typing import Any, Optional, Sequence, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.buttons import ButtonStyle from flet_core.constrained_control import ConstrainedControl @@ -9,7 +10,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ClipBehavior, OffsetValue, OptionalControlEventCallable, @@ -63,12 +63,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/switch.py b/sdk/python/packages/flet-core/src/flet_core/switch.py index e78845c3a..d9e2990dd 100644 --- a/sdk/python/packages/flet-core/src/flet_core/switch.py +++ b/sdk/python/packages/flet-core/src/flet_core/switch.py @@ -1,6 +1,7 @@ -from typing import Any, Dict, Optional, Union +from typing import Any, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber @@ -8,8 +9,7 @@ from flet_core.text_style import TextStyle from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, - ControlState, + ControlStateValue, LabelPosition, MouseCursor, OffsetValue, @@ -66,14 +66,14 @@ def __init__( focus_color: Optional[str] = None, inactive_thumb_color: Optional[str] = None, inactive_track_color: Optional[str] = None, - thumb_color: Union[None, str, Dict[ControlState, str]] = None, - thumb_icon: Union[None, str, Dict[ControlState, str]] = None, - track_color: Union[None, str, Dict[ControlState, str]] = None, + thumb_color: ControlStateValue[str] = None, + thumb_icon: ControlStateValue[str] = None, + track_color: ControlStateValue[str] = None, adaptive: Optional[bool] = None, hover_color: Optional[str] = None, splash_radius: OptionalNumber = None, - overlay_color: Union[None, str, Dict[ControlState, str]] = None, - track_outline_color: Union[None, str, Dict[ControlState, str]] = None, + overlay_color: ControlStateValue[str] = None, + track_outline_color: ControlStateValue[str] = None, mouse_cursor: Optional[MouseCursor] = None, on_change: OptionalControlEventCallable = None, on_focus: OptionalControlEventCallable = None, @@ -97,12 +97,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -171,13 +171,14 @@ def _get_control_name(self): def before_update(self): super().before_update() - self._set_attr_json("thumbColor", self.__thumb_color) - self._set_attr_json("overlayColor", self.__overlay_color) - self._set_attr_json("trackOutlineColor", self.__track_outline_color) - self._set_attr_json("thumbIcon", self.__thumb_icon) - self._set_attr_json("trackColor", self.__track_color) - if isinstance(self.__label_style, TextStyle): - self._set_attr_json("labelStyle", self.__label_style) + self._set_attr_json("thumbColor", self.__thumb_color, wrap_attr_dict=True) + self._set_attr_json("overlayColor", self.__overlay_color, wrap_attr_dict=True) + self._set_attr_json( + "trackOutlineColor", self.__track_outline_color, wrap_attr_dict=True + ) + self._set_attr_json("thumbIcon", self.__thumb_icon, wrap_attr_dict=True) + self._set_attr_json("trackColor", self.__track_color, wrap_attr_dict=True) + self._set_attr_json("labelStyle", self.__label_style) # value @property @@ -208,20 +209,20 @@ def hover_color(self, value: Optional[str]): # track_outline_color @property - def track_outline_color(self) -> Union[None, str, Dict[ControlState, str]]: + def track_outline_color(self) -> ControlStateValue[str]: return self.__track_outline_color @track_outline_color.setter - def track_outline_color(self, value: Union[None, str, Dict[ControlState, str]]): + def track_outline_color(self, value: ControlStateValue[str]): self.__track_outline_color = value # overlay_color @property - def overlay_color(self) -> Union[None, str, Dict[ControlState, str]]: + def overlay_color(self) -> ControlStateValue[str]: return self.__overlay_color @overlay_color.setter - def overlay_color(self, value: Union[None, str, Dict[ControlState, str]]): + def overlay_color(self, value: ControlStateValue[str]): self.__overlay_color = value # splash_radius @@ -319,29 +320,29 @@ def inactive_track_color(self, value: Optional[str]): # thumb_color @property - def thumb_color(self) -> Union[None, str, Dict[ControlState, str]]: + def thumb_color(self) -> ControlStateValue[str]: return self.__thumb_color @thumb_color.setter - def thumb_color(self, value: Union[None, str, Dict[ControlState, str]]): + def thumb_color(self, value: ControlStateValue[str]): self.__thumb_color = value # thumb_icon @property - def thumb_icon(self) -> Union[None, str, Dict[ControlState, str]]: + def thumb_icon(self) -> ControlStateValue[str]: return self.__thumb_icon @thumb_icon.setter - def thumb_icon(self, value: Union[None, str, Dict[ControlState, str]]): + def thumb_icon(self, value: ControlStateValue[str]): self.__thumb_icon = value # track_color @property - def track_color(self) -> Union[None, str, Dict[ControlState, str]]: + def track_color(self) -> ControlStateValue[str]: return self.__track_color @track_color.setter - def track_color(self, value: Union[None, str, Dict[ControlState, str]]): + def track_color(self, value: ControlStateValue[str]): self.__track_color = value # on_change diff --git a/sdk/python/packages/flet-core/src/flet_core/tabs.py b/sdk/python/packages/flet-core/src/flet_core/tabs.py index fa1901dbe..5c62106da 100644 --- a/sdk/python/packages/flet-core/src/flet_core/tabs.py +++ b/sdk/python/packages/flet-core/src/flet_core/tabs.py @@ -1,24 +1,25 @@ -from typing import Any, Dict, List, Optional, Union +from typing import Any, List, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.border import BorderSide from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.text_style import TextStyle from flet_core.types import ( - AnimationValue, BorderRadiusValue, ClipBehavior, - ControlState, + ControlStateValue, + MarginValue, MouseCursor, OffsetValue, + OptionalControlEventCallable, PaddingValue, ResponsiveNumber, RotateValue, ScaleValue, TabAlignment, - OptionalControlEventCallable, ) @@ -29,6 +30,9 @@ def __init__( content: Optional[Control] = None, tab_content: Optional[Control] = None, icon: Optional[str] = None, + icon_content: Optional[Control] = None, + height: OptionalNumber = None, + icon_margin: MarginValue = None, # # Control and AdaptiveControl # @@ -41,10 +45,11 @@ def __init__( self.text = text self.icon = icon - self.__content: Optional[Control] = None self.content = content - self.__tab_content: Optional[Control] = None self.tab_content = tab_content + self.height = height + self.icon_margin = icon_margin + self.icon_content = icon_content def _get_control_name(self): return "tab" @@ -57,20 +62,36 @@ def _get_children(self): if self.__content: self.__content._set_attr_internal("n", "content") children.append(self.__content) + if self.__icon_content: + self.__icon_content._set_attr_internal("n", "icon_content") + children.append(self.__icon_content) return children + def before_update(self): + super().before_update() + self._set_attr_json("iconMargin", self.__icon_margin) + # text @property - def text(self): + def text(self) -> Optional[str]: return self._get_attr("text") @text.setter def text(self, value: Optional[str]): self._set_attr("text", value) + # height + @property + def height(self) -> Optional[float]: + return self._get_attr("height", data_type="float") + + @height.setter + def height(self, value: OptionalNumber): + self._set_attr("height", value) + # icon @property - def icon(self): + def icon(self) -> Optional[str]: return self._get_attr("icon") @icon.setter @@ -79,7 +100,7 @@ def icon(self, value: Optional[str]): # tab_content @property - def tab_content(self): + def tab_content(self) -> Optional[Control]: return self.__tab_content @tab_content.setter @@ -88,13 +109,31 @@ def tab_content(self, value: Optional[Control]): # content @property - def content(self): + def content(self) -> Optional[Control]: return self.__content @content.setter def content(self, value: Optional[Control]): self.__content = value + # icon_content + @property + def icon_content(self) -> Optional[Control]: + return self.__icon_content + + @icon_content.setter + def icon_content(self, value: Optional[Control]): + self.__icon_content = value + + # icon_margin + @property + def icon_margin(self) -> MarginValue: + return self.__icon_margin + + @icon_margin.setter + def icon_margin(self, value: MarginValue): + self.__icon_margin = value + class Tabs(ConstrainedControl, AdaptiveControl): """ @@ -161,7 +200,7 @@ def __init__( label_text_style: Optional[TextStyle] = None, unselected_label_color: Optional[str] = None, unselected_label_text_style: Optional[TextStyle] = None, - overlay_color: Union[None, str, Dict[ControlState, str]] = None, + overlay_color: ControlStateValue[str] = None, divider_height: OptionalNumber = None, indicator_thickness: OptionalNumber = None, enable_feedback: Optional[str] = None, @@ -190,12 +229,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, visible: Optional[bool] = None, disabled: Optional[bool] = None, @@ -267,7 +306,7 @@ def _get_control_name(self): def before_update(self): super().before_update() - self._set_attr_json("overlayColor", self.__overlay_color) + self._set_attr_json("overlayColor", self.__overlay_color, wrap_attr_dict=True) self._set_attr_json("indicatorBorderRadius", self.__indicator_border_radius) self._set_attr_json("indicatorBorderSide", self.__indicator_border_side) self._set_attr_json("indicatorPadding", self.__indicator_padding) @@ -466,11 +505,11 @@ def unselected_label_color(self, value: Optional[str]): # overlay_color @property - def overlay_color(self) -> Union[None, str, Dict[ControlState, str]]: + def overlay_color(self) -> ControlStateValue[str]: return self.__overlay_color @overlay_color.setter - def overlay_color(self, value: Union[None, str, Dict[ControlState, str]]): + def overlay_color(self, value: ControlStateValue[str]): self.__overlay_color = value # label_padding diff --git a/sdk/python/packages/flet-core/src/flet_core/text.py b/sdk/python/packages/flet-core/src/flet_core/text.py index 9209cd4b4..aabdacb0c 100644 --- a/sdk/python/packages/flet-core/src/flet_core/text.py +++ b/sdk/python/packages/flet-core/src/flet_core/text.py @@ -1,20 +1,24 @@ +import json from dataclasses import dataclass from enum import Enum from typing import Any, List, Optional, Union from warnings import warn +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber +from flet_core.control_event import ControlEvent +from flet_core.event_handler import EventHandler from flet_core.ref import Ref from flet_core.text_span import TextSpan from flet_core.text_style import TextOverflow, TextStyle, TextThemeStyle from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, FontWeight, OffsetValue, OptionalControlEventCallable, + OptionalEventCallable, ResponsiveNumber, RotateValue, ScaleValue, @@ -46,6 +50,40 @@ class TextSelection: normalized: Optional[bool] = None +class TextSelectionChangeCause(Enum): + UNKNOWN = "unknown" + TAP = "tap" + DOUBLE_TAP = "doubleTap" + LONG_PRESS = "longPress" + FORCE_PRESS = "forcePress" + KEYBOARD = "keyboard" + TOOLBAR = "toolbar" + DRAG = "drag" + SCRIBBLE = "scribble" + + +class TextSelectionChangeEvent(ControlEvent): + def __init__(self, e: ControlEvent): + super().__init__(e.target, e.name, e.data, e.control, e.page) + d = json.loads(e.data) + self.text: str = d.get("text") + self.cause = TextSelectionChangeCause(d.get("cause")) + start = d.get("start") + end = d.get("end") + self.selection = TextSelection( + start=start, + end=end, + selection=self.text[start:end] if (start != -1 and end != -1) else "", + base_offset=d.get("base_offset"), + extent_offset=d.get("extent_offset"), + affinity=d.get("affinity"), + directional=d.get("directional"), + collapsed=d.get("collapsed"), + valid=d.get("valid"), + normalized=d.get("normalized"), + ) + + class Text(ConstrainedControl): """ Text is a control for displaying text. @@ -93,6 +131,13 @@ def __init__( color: Optional[str] = None, bgcolor: Optional[str] = None, semantics_label: Optional[str] = None, + show_selection_cursor: Optional[bool] = None, + enable_interactive_selection: Optional[bool] = None, + selection_cursor_width: OptionalNumber = None, + selection_cursor_height: OptionalNumber = None, + selection_cursor_color: Optional[str] = None, + on_tap: OptionalControlEventCallable = None, + on_selection_change: OptionalEventCallable[TextSelectionChangeEvent] = None, # # ConstrainedControl # @@ -112,12 +157,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -159,6 +204,11 @@ def __init__( rtl=rtl, ) + self.__on_selection_change = EventHandler(lambda e: TextSelectionChangeEvent(e)) + + self._add_event_handler( + "selection_change", self.__on_selection_change.get_handler() + ) self.value = value self.spans = spans self.text_align = text_align @@ -175,6 +225,13 @@ def __init__( self.color = color self.bgcolor = bgcolor self.semantics_label = semantics_label + self.on_tap = on_tap + self.on_selection_change = on_selection_change + self.show_selection_cursor = show_selection_cursor + self.enable_interactive_selection = enable_interactive_selection + self.selection_cursor_width = selection_cursor_width + self.selection_cursor_height = selection_cursor_height + self.selection_cursor_color = selection_cursor_color def _get_control_name(self): return "text" @@ -345,3 +402,72 @@ def semantics_label(self) -> Optional[str]: @semantics_label.setter def semantics_label(self, value: Optional[str]): self._set_attr("semanticsLabel", value) + + # selection_cursor_color + @property + def selection_cursor_color(self) -> Optional[str]: + return self._get_attr("selectionCursorColor") + + @selection_cursor_color.setter + def selection_cursor_color(self, value: Optional[str]): + self._set_attr("selectionCursorColor", value) + + # selection_cursor_height + @property + def selection_cursor_height(self) -> OptionalNumber: + return self._get_attr("selectionCursorHeight", data_type="float") + + @selection_cursor_height.setter + def selection_cursor_height(self, value: OptionalNumber): + self._set_attr("selectionCursorHeight", value) + + # selection_cursor_width + @property + def selection_cursor_width(self) -> OptionalNumber: + return self._get_attr("selectionCursorWidth", data_type="float", def_value=2.0) + + @selection_cursor_width.setter + def selection_cursor_width(self, value: OptionalNumber): + self._set_attr("selectionCursorWidth", value) + + # show_selection_cursor + @property + def show_selection_cursor(self) -> Optional[bool]: + return self._get_attr("showSelectionCursor", data_type="bool", def_value=False) + + @show_selection_cursor.setter + def show_selection_cursor(self, value: Optional[bool]): + self._set_attr("showSelectionCursor", value) + + # enable_interactive_selection + @property + def enable_interactive_selection(self) -> Optional[bool]: + return self._get_attr( + "enableInteractiveSelection", data_type="bool", def_value=True + ) + + @enable_interactive_selection.setter + def enable_interactive_selection(self, value: Optional[bool]): + self._set_attr("enableInteractiveSelection", value) + + # on_tap + @property + def on_tap(self) -> OptionalControlEventCallable: + return self._get_event_handler("tap") + + @on_tap.setter + def on_tap(self, handler: OptionalControlEventCallable): + self._add_event_handler("tap", handler) + + # on_selection_change + @property + def on_selection_change( + self, + ) -> OptionalEventCallable[TextSelectionChangeEvent]: + return self.__on_selection_change.handler + + @on_selection_change.setter + def on_selection_change( + self, handler: OptionalEventCallable[TextSelectionChangeEvent] + ): + self.__on_selection_change.handler = handler diff --git a/sdk/python/packages/flet-core/src/flet_core/text_button.py b/sdk/python/packages/flet-core/src/flet_core/text_button.py index 019e3b3f4..e004543b0 100644 --- a/sdk/python/packages/flet-core/src/flet_core/text_button.py +++ b/sdk/python/packages/flet-core/src/flet_core/text_button.py @@ -2,6 +2,7 @@ from typing import Any, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.buttons import ButtonStyle from flet_core.constrained_control import ConstrainedControl @@ -9,7 +10,6 @@ from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -77,12 +77,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/text_span.py b/sdk/python/packages/flet-core/src/flet_core/text_span.py index 5d5a10f12..fab65f4f8 100644 --- a/sdk/python/packages/flet-core/src/flet_core/text_span.py +++ b/sdk/python/packages/flet-core/src/flet_core/text_span.py @@ -16,6 +16,8 @@ def __init__( spans: Optional[List[InlineSpan]] = None, url: Optional[str] = None, url_target: Optional[UrlTarget] = None, + semantics_label: Optional[str] = None, + spell_out: Optional[bool] = None, on_click: OptionalControlEventCallable = None, on_enter: OptionalControlEventCallable = None, on_exit: OptionalControlEventCallable = None, @@ -36,6 +38,8 @@ def __init__( self.spans = spans self.url = url self.url_target = url_target + self.semantics_label = semantics_label + self.spell_out = spell_out self.on_click = on_click self.on_enter = on_enter self.on_exit = on_exit @@ -59,6 +63,24 @@ def text(self) -> Optional[str]: def text(self, value: Optional[str]): self._set_attr("text", value) + # semantics_label + @property + def semantics_label(self) -> Optional[str]: + return self._get_attr("semanticsLabel") + + @semantics_label.setter + def semantics_label(self, value: Optional[str]): + self._set_attr("semanticsLabel", value) + + # spell_out + @property + def spell_out(self) -> Optional[bool]: + return self._get_attr("spellOut") + + @spell_out.setter + def spell_out(self, value: Optional[bool]): + self._set_attr("spellOut", value) + # style @property def style(self) -> Optional[TextStyle]: diff --git a/sdk/python/packages/flet-core/src/flet_core/text_style.py b/sdk/python/packages/flet-core/src/flet_core/text_style.py index 5499a08b4..73003d30b 100644 --- a/sdk/python/packages/flet-core/src/flet_core/text_style.py +++ b/sdk/python/packages/flet-core/src/flet_core/text_style.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass, field +from dataclasses import dataclass from enum import Enum, IntFlag from typing import List, Optional, Union @@ -54,20 +54,31 @@ class TextDecorationStyle(Enum): @dataclass class TextStyle: - size: OptionalNumber = field(default=None) - height: OptionalNumber = field(default=None) - weight: Optional[FontWeight] = field(default=None) - italic: Optional[bool] = field(default=None) - decoration: Optional[TextDecoration] = field(default=None) - decoration_color: Optional[str] = field(default=None) - decoration_thickness: OptionalNumber = field(default=None) - decoration_style: Optional[TextDecorationStyle] = field(default=None) - font_family: Optional[str] = field(default=None) - color: Optional[str] = field(default=None) - bgcolor: Optional[str] = field(default=None) - shadow: Union[None, BoxShadow, List[BoxShadow]] = field(default=None) - foreground: Optional[Paint] = field(default=None) - letter_spacing: OptionalNumber = field(default=None) - word_spacing: OptionalNumber = field(default=None) - overflow: Optional[TextOverflow] = field(default=None) - baseline: Optional[TextBaseline] = field(default=None) + size: OptionalNumber = None + height: OptionalNumber = None + weight: Optional[FontWeight] = None + italic: Optional[bool] = None + decoration: Optional[TextDecoration] = None + decoration_color: Optional[str] = None + decoration_thickness: OptionalNumber = None + decoration_style: Optional[TextDecorationStyle] = None + font_family: Optional[str] = None + color: Optional[str] = None + bgcolor: Optional[str] = None + shadow: Union[None, BoxShadow, List[BoxShadow]] = None + foreground: Optional[Paint] = None + letter_spacing: OptionalNumber = None + word_spacing: OptionalNumber = None + overflow: Optional[TextOverflow] = None + baseline: Optional[TextBaseline] = None + + +@dataclass +class StrutStyle: + size: OptionalNumber = None + height: OptionalNumber = None + weight: Optional[FontWeight] = None + italic: Optional[bool] = None + font_family: Optional[str] = None + leading: OptionalNumber = None + force_strut_height: Optional[bool] = None diff --git a/sdk/python/packages/flet-core/src/flet_core/textfield.py b/sdk/python/packages/flet-core/src/flet_core/textfield.py index 12975efe2..5c9b19cdf 100644 --- a/sdk/python/packages/flet-core/src/flet_core/textfield.py +++ b/sdk/python/packages/flet-core/src/flet_core/textfield.py @@ -4,8 +4,10 @@ from typing import Any, List, Optional, Union from flet_core.adaptive_control import AdaptiveControl +from flet_core.animation import AnimationValue from flet_core.autofill_group import AutofillHint from flet_core.badge import BadgeValue +from flet_core.box import BoxConstraints from flet_core.control import Control, OptionalNumber from flet_core.form_field_control import ( FormFieldControl, @@ -13,11 +15,14 @@ InputBorder, ) from flet_core.ref import Ref -from flet_core.text_style import TextStyle +from flet_core.text_style import StrutStyle, TextStyle from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, BorderRadiusValue, + Brightness, + ClipBehavior, + DurationValue, + MouseCursor, OffsetValue, OptionalControlEventCallable, PaddingValue, @@ -127,13 +132,28 @@ def __init__( smart_quotes_type: Optional[bool] = None, show_cursor: Optional[bool] = None, cursor_color: Optional[str] = None, + cursor_error_color: Optional[str] = None, cursor_width: OptionalNumber = None, cursor_height: OptionalNumber = None, cursor_radius: OptionalNumber = None, selection_color: Optional[str] = None, input_filter: Optional[InputFilter] = None, + obscuring_character: Optional[str] = None, + enable_interactive_selection: Optional[bool] = None, + enable_ime_personalized_learning: Optional[bool] = None, + can_request_focus: Optional[bool] = None, + ignore_pointers: Optional[bool] = None, + enable_scribble: Optional[bool] = None, + animate_cursor_opacity: Optional[bool] = None, + always_call_on_tap: Optional[bool] = None, + scroll_padding: PaddingValue = None, + clip_behavior: Optional[ClipBehavior] = None, + keyboard_brightness: Optional[Brightness] = None, + mouse_cursor: Optional[MouseCursor] = None, + strut_style: Optional[StrutStyle] = None, autofill_hints: Union[None, AutofillHint, List[AutofillHint]] = None, on_change: OptionalControlEventCallable = None, + on_click: OptionalControlEventCallable = None, on_submit: OptionalControlEventCallable = None, on_focus: OptionalControlEventCallable = None, on_blur: OptionalControlEventCallable = None, @@ -143,7 +163,7 @@ def __init__( text_size: OptionalNumber = None, text_style: Optional[TextStyle] = None, text_vertical_align: Union[VerticalAlignment, OptionalNumber] = None, - label: Optional[str] = None, + label: Optional[Union[str, Control]] = None, label_style: Optional[TextStyle] = None, icon: Optional[IconValueOrControl] = None, border: Optional[InputBorder] = None, @@ -163,11 +183,13 @@ def __init__( hover_color: Optional[str] = None, hint_text: Optional[str] = None, hint_style: Optional[TextStyle] = None, + helper: Optional[Control] = None, helper_text: Optional[str] = None, helper_style: Optional[TextStyle] = None, counter: Optional[Control] = None, counter_text: Optional[str] = None, counter_style: Optional[TextStyle] = None, + error: Optional[Control] = None, error_text: Optional[str] = None, error_style: Optional[TextStyle] = None, prefix: Optional[Control] = None, @@ -178,6 +200,17 @@ def __init__( suffix_icon: Optional[IconValueOrControl] = None, suffix_text: Optional[str] = None, suffix_style: Optional[TextStyle] = None, + focus_color: Optional[str] = None, + align_label_with_hint: Optional[bool] = None, + hint_fade_duration: DurationValue = None, + hint_max_lines: Optional[int] = None, + helper_max_lines: Optional[int] = None, + error_max_lines: Optional[int] = None, + prefix_icon_size_constraints: Optional[BoxConstraints] = None, + suffix_icon_size_constraints: Optional[BoxConstraints] = None, + size_constraints: Optional[BoxConstraints] = None, + collapsed: Optional[bool] = None, + fit_parent_size: Optional[bool] = None, # # ConstrainedControl and AdaptiveControl # @@ -193,12 +226,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, @@ -261,11 +294,13 @@ def __init__( hover_color=hover_color, hint_text=hint_text, hint_style=hint_style, + helper=helper, helper_text=helper_text, helper_style=helper_style, counter=counter, counter_text=counter_text, counter_style=counter_style, + error=error, error_text=error_text, error_style=error_style, prefix=prefix, @@ -276,6 +311,17 @@ def __init__( suffix_icon=suffix_icon, suffix_text=suffix_text, suffix_style=suffix_style, + focus_color=focus_color, + align_label_with_hint=align_label_with_hint, + hint_fade_duration=hint_fade_duration, + hint_max_lines=hint_max_lines, + helper_max_lines=helper_max_lines, + error_max_lines=error_max_lines, + prefix_icon_size_constraints=prefix_icon_size_constraints, + suffix_icon_size_constraints=suffix_icon_size_constraints, + size_constraints=size_constraints, + collapsed=collapsed, + fit_parent_size=fit_parent_size, ) AdaptiveControl.__init__(self, adaptive=adaptive) @@ -310,6 +356,21 @@ def __init__( self.on_submit = on_submit self.on_focus = on_focus self.on_blur = on_blur + self.on_click = on_click + self.obscuring_character = obscuring_character + self.enable_scribble = enable_scribble + self.strut_style = strut_style + self.scroll_padding = scroll_padding + self.cursor_error_color = cursor_error_color + self.keyboard_brightness = keyboard_brightness + self.mouse_cursor = mouse_cursor + self.enable_interactive_selection = enable_interactive_selection + self.enable_ime_personalized_learning = enable_ime_personalized_learning + self.can_request_focus = can_request_focus + self.ignore_pointers = ignore_pointers + self.animate_cursor_opacity = animate_cursor_opacity + self.always_call_on_tap = always_call_on_tap + self.clip_behavior = clip_behavior def _get_control_name(self): return "textfield" @@ -323,6 +384,8 @@ def before_update(self): ), "min_lines can't be greater than max_lines" self._set_attr_json("inputFilter", self.__input_filter) self._set_attr_json("autofillHints", self.__autofill_hints) + self._set_attr_json("scrollPadding", self.__scroll_padding) + self._set_attr_json("strutStyle", self.__strut_style) if ( ( self.bgcolor is not None @@ -354,6 +417,55 @@ def value(self) -> Optional[str]: def value(self, value: Optional[str]): self._set_attr("value", value) + # strut_style + @property + def strut_style(self) -> Optional[TextStyle]: + return self.__strut_style + + @strut_style.setter + def strut_style(self, value: Optional[TextStyle]): + self.__strut_style = value + + # cursor_error_color + @property + def cursor_error_color(self) -> Optional[str]: + return self._get_attr("cursorErrorColor") + + @cursor_error_color.setter + def cursor_error_color(self, value: Optional[str]): + self._set_attr("cursorErrorColor", value) + + # enable_interactive_selection + @property + def enable_interactive_selection(self) -> bool: + return self._get_attr( + "enableInteractiveSelection", data_type="bool", def_value=True + ) + + @enable_interactive_selection.setter + def enable_interactive_selection(self, value: Optional[bool]): + self._set_attr("enableInteractiveSelection", value) + + # enable_ime_personalized_learning + @property + def enable_ime_personalized_learning(self) -> bool: + return self._get_attr( + "enableIMEPersonalizedLearning", data_type="bool", def_value=True + ) + + @enable_ime_personalized_learning.setter + def enable_ime_personalized_learning(self, value: Optional[bool]): + self._set_attr("enableIMEPersonalizedLearning", value) + + # animate_cursor_opacity + @property + def animate_cursor_opacity(self) -> Optional[bool]: + return self._get_attr("animateCursorOpacity", data_type="bool") + + @animate_cursor_opacity.setter + def animate_cursor_opacity(self, value: Optional[bool]): + self._set_attr("animateCursorOpacity", value) + # keyboard_type @property def keyboard_type(self) -> Optional[KeyboardType]: @@ -415,6 +527,90 @@ def max_length(self, value: Optional[int]): ), "max_length must be either equal to -1 or greater than 0" self._set_attr("maxLength", value) + # obscuring_character + @property + def obscuring_character(self) -> Optional[str]: + return self._get_attr("obscuringCharacter", def_value="•") + + @obscuring_character.setter + def obscuring_character(self, value: Optional[str]): + self._set_attr("obscuringCharacter", value) + + # enable_scribble + @property + def enable_scribble(self) -> bool: + return self._get_attr("enableScribble", data_type="bool", def_value=True) + + @enable_scribble.setter + def enable_scribble(self, value: Optional[bool]): + self._set_attr("enableScribble", value) + + # scroll_padding + @property + def scroll_padding(self) -> PaddingValue: + return self.__scroll_padding + + @scroll_padding.setter + def scroll_padding(self, value: PaddingValue): + self.__scroll_padding = value + + # keyboard_brightness + @property + def keyboard_brightness(self) -> Optional[Brightness]: + return self.__keyboard_brightness + + @keyboard_brightness.setter + def keyboard_brightness(self, value: Optional[Brightness]): + self.__keyboard_brightness = value + self._set_enum_attr("keyboardBrightness", value, Brightness) + + # mouse_cursor + @property + def mouse_cursor(self) -> Optional[MouseCursor]: + return self.__mouse_cursor + + @mouse_cursor.setter + def mouse_cursor(self, value: Optional[MouseCursor]): + self.__mouse_cursor = value + self._set_enum_attr("mouseCursor", value, MouseCursor) + + # ignore_pointers + @property + def ignore_pointers(self) -> bool: + return self._get_attr("ignorePointers", data_type="bool", def_value=False) + + @ignore_pointers.setter + def ignore_pointers(self, value: Optional[bool]): + self._set_attr("ignorePointers", value) + + # clip_behavior + @property + def clip_behavior(self) -> Optional[ClipBehavior]: + return self.__clip_behavior + + @clip_behavior.setter + def clip_behavior(self, value: Optional[ClipBehavior]): + self.__clip_behavior = value + self._set_enum_attr("clipBehavior", value, ClipBehavior) + + # can_request_focus + @property + def can_request_focus(self) -> bool: + return self._get_attr("canRequestFocus", data_type="bool", def_value=True) + + @can_request_focus.setter + def can_request_focus(self, value: Optional[bool]): + self._set_attr("canRequestFocus", value) + + # always_call_on_tap + @property + def always_call_on_tap(self) -> bool: + return self._get_attr("alwaysCallOnTap", data_type="bool", def_value=False) + + @always_call_on_tap.setter + def always_call_on_tap(self, value: Optional[bool]): + self._set_attr("alwaysCallOnTap", value) + # read_only @property def read_only(self) -> bool: @@ -624,3 +820,12 @@ def on_blur(self) -> OptionalControlEventCallable: @on_blur.setter def on_blur(self, handler: OptionalControlEventCallable): self._add_event_handler("blur", handler) + + # on_click + @property + def on_click(self): + return self._get_event_handler("click") + + @on_click.setter + def on_click(self, handler: OptionalControlEventCallable): + self._add_event_handler("click", handler) diff --git a/sdk/python/packages/flet-core/src/flet_core/theme.py b/sdk/python/packages/flet-core/src/flet_core/theme.py index 764058caa..a5f507bc5 100644 --- a/sdk/python/packages/flet-core/src/flet_core/theme.py +++ b/sdk/python/packages/flet-core/src/flet_core/theme.py @@ -1,6 +1,6 @@ from dataclasses import dataclass, field from enum import Enum -from typing import Dict, List, Optional, Union +from typing import List, Optional, Union from flet_core.alignment import Alignment from flet_core.border import BorderSide @@ -10,7 +10,6 @@ from flet_core.control import OptionalNumber from flet_core.navigation_bar import NavigationBarLabelBehavior from flet_core.navigation_rail import NavigationRailLabelType -from flet_core.padding import Padding from flet_core.popup_menu_button import PopupMenuPosition from flet_core.snack_bar import DismissDirection, SnackBarBehavior from flet_core.text_style import TextStyle @@ -26,6 +25,7 @@ ThemeVisualDensity, VisualDensity, MainAxisAlignment, + ControlStateValue, ) try: @@ -106,13 +106,13 @@ class TextTheme: @dataclass class ScrollbarTheme: - thumb_visibility: Union[None, bool, Dict[ControlState, bool]] = None - thickness: Union[None, float, Dict[ControlState, float]] = None - track_visibility: Union[None, bool, Dict[ControlState, bool]] = None + thumb_visibility: ControlStateValue[bool] = None + thickness: ControlStateValue[OptionalNumber] = None + track_visibility: ControlStateValue[bool] = None radius: Optional[float] = None - thumb_color: Union[None, str, Dict[ControlState, str]] = None - track_color: Union[None, str, Dict[ControlState, str]] = None - track_border_color: Union[None, str, Dict[ControlState, str]] = None + thumb_color: ControlStateValue[str] = None + track_color: ControlStateValue[str] = None + track_border_color: ControlStateValue[str] = None cross_axis_margin: Optional[float] = None main_axis_margin: Optional[float] = None min_thumb_length: Optional[float] = None @@ -129,8 +129,8 @@ class TabsTheme: indicator_tab_size: Optional[bool] = None label_color: Optional[str] = None unselected_label_color: Optional[str] = None - overlay_color: Union[None, str, Dict[ControlState, str]] = None - mouse_cursor: Union[None, MouseCursor, Dict[ControlState, MouseCursor]] = None + overlay_color: ControlStateValue[str] = None + mouse_cursor: ControlStateValue[MouseCursor] = None label_padding: PaddingValue = None label_text_style: Optional[TextStyle] = None unselected_label_text_style: Optional[TextStyle] = None @@ -274,24 +274,24 @@ class BottomAppBarTheme: @dataclass class RadioTheme: - fill_color: Union[None, str, Dict[ControlState, str]] = None - overlay_color: Union[None, str, Dict[ControlState, str]] = None + fill_color: ControlStateValue[str] = None + overlay_color: ControlStateValue[str] = None splash_radius: OptionalNumber = None height: OptionalNumber = None visual_density: Union[None, ThemeVisualDensity, VisualDensity] = None - mouse_cursor: Union[None, MouseCursor, Dict[ControlState, MouseCursor]] = None + mouse_cursor: ControlStateValue[MouseCursor] = None @dataclass class CheckboxTheme: - overlay_color: Union[None, str, Dict[ControlState, str]] = None - check_color: Union[None, str, Dict[ControlState, str]] = None - fill_color: Union[None, str, Dict[ControlState, str]] = None + overlay_color: ControlStateValue[str] = None + check_color: ControlStateValue[str] = None + fill_color: ControlStateValue[str] = None splash_radius: OptionalNumber = None border_side: Optional[BorderSide] = None visual_density: Union[None, ThemeVisualDensity, VisualDensity] = None shape: Optional[OutlinedBorder] = None - mouse_cursor: Union[None, MouseCursor, Dict[ControlState, MouseCursor]] = None + mouse_cursor: ControlStateValue[MouseCursor] = None @dataclass @@ -308,16 +308,14 @@ class BadgeTheme: @dataclass class SwitchTheme: - thumb_color: Union[None, str, Dict[ControlState, str]] = None - track_color: Union[None, str, Dict[ControlState, str]] = None - overlay_color: Union[None, str, Dict[ControlState, str]] = None - track_outline_color: Union[None, str, Dict[ControlState, str]] = None - thumb_icon: Union[None, str, Dict[ControlState, str]] = None - track_outline_width: Union[ - None, Union[int, float], Dict[ControlState, Union[int, float]] - ] = None + thumb_color: ControlStateValue[str] = None + track_color: ControlStateValue[str] = None + overlay_color: ControlStateValue[str] = None + track_outline_color: ControlStateValue[str] = None + thumb_icon: ControlStateValue[str] = None + track_outline_width: ControlStateValue[OptionalNumber] = None splash_radius: OptionalNumber = None - mouse_cursor: Union[None, MouseCursor, Dict[ControlState, MouseCursor]] = None + mouse_cursor: ControlStateValue[MouseCursor] = None @dataclass @@ -368,12 +366,10 @@ class DatePickerTheme: shadow_color: Optional[str] = None divider_color: Optional[str] = None header_bgcolor: Optional[str] = None - today_bgcolor: Union[None, str, Dict[ControlState, str]] = None - day_bgcolor: Union[None, str, Dict[ControlState, str]] = None - day_overlay_color: Union[None, str, Dict[ControlState, str]] = None - day_foreground_color: Union[None, str, Dict[ControlState, str]] = field( - default=None - ) + today_bgcolor: ControlStateValue[str] = None + day_bgcolor: ControlStateValue[str] = None + day_overlay_color: ControlStateValue[str] = None + day_foreground_color: ControlStateValue[str] = None elevation: OptionalNumber = None range_picker_elevation: OptionalNumber = None day_text_style: Optional[TextStyle] = None @@ -388,17 +384,17 @@ class DatePickerTheme: range_picker_bgcolor: Optional[str] = None range_picker_header_bgcolor: Optional[str] = None range_picker_header_foreground_color: Optional[str] = None - today_foreground_color: Union[None, str, Dict[ControlState, str]] = None + today_foreground_color: ControlStateValue[str] = None range_picker_shape: Optional[OutlinedBorder] = None range_picker_header_help_text_style: Optional[TextStyle] = None range_picker_header_headline_text_style: Optional[TextStyle] = None range_picker_surface_tint_color: Optional[str] = None range_selection_bgcolor: Optional[str] = None - range_selection_overlay_color: Union[None, str, Dict[ControlState, str]] = None + range_selection_overlay_color: ControlStateValue[str] = None today_border_side: Optional[BorderSide] = None - year_bgcolor: Union[None, str, Dict[ControlState, str]] = None - year_foreground_color: Union[None, str, Dict[ControlState, str]] = None - year_overlay_color: Union[None, str, Dict[ControlState, str]] = None + year_bgcolor: ControlStateValue[str] = None + year_foreground_color: ControlStateValue[str] = None + year_overlay_color: ControlStateValue[str] = None @dataclass @@ -504,27 +500,31 @@ class PopupMenuTheme: icon_size: OptionalNumber = None shape: Optional[OutlinedBorder] = None menu_position: Optional[PopupMenuPosition] = None - mouse_cursor: Union[None, MouseCursor, Dict[ControlState, MouseCursor]] = None + mouse_cursor: ControlStateValue[MouseCursor] = None @dataclass class SearchBarTheme: bgcolor: Optional[str] = None text_capitalization: Optional[TextCapitalization] = None - shadow_color: Union[None, str, Dict[ControlState, str]] = None - surface_tint_color: Union[None, str, Dict[ControlState, str]] = None - overlay_color: Union[None, str, Dict[ControlState, str]] = None - elevation: Union[ - None, Union[int, float], Dict[ControlState, Union[int, float]] - ] = None - text_style: Union[None, TextStyle, Dict[ControlState, TextStyle]] = None - hint_style: Union[None, TextStyle, Dict[ControlState, TextStyle]] = None - shape: Union[None, OutlinedBorder, Dict[ControlState, OutlinedBorder]] = None - padding: Union[ - None, - Union[int, float, Padding], - Dict[ControlState, Union[int, float, Padding]], - ] = None + shadow_color: ControlStateValue[str] = None + surface_tint_color: ControlStateValue[str] = None + overlay_color: ControlStateValue[str] = None + elevation: ControlStateValue[OptionalNumber] = None + text_style: ControlStateValue[TextStyle] = None + hint_style: ControlStateValue[TextStyle] = None + shape: ControlStateValue[OutlinedBorder] = None + padding: ControlStateValue[PaddingValue] = None + + def __post_init__(self): + if not isinstance(self.text_style, dict): + self.text_style = {ControlState.DEFAULT: self.text_style} + if not isinstance(self.hint_style, dict): + self.hint_style = {ControlState.DEFAULT: self.hint_style} + if not isinstance(self.shape, dict): + self.shape = {ControlState.DEFAULT: self.shape} + if not isinstance(self.padding, dict): + self.padding = {ControlState.DEFAULT: self.padding} @dataclass @@ -560,9 +560,13 @@ class NavigationDrawerTheme: indicator_color: Optional[str] = None elevation: OptionalNumber = None tile_height: OptionalNumber = None - label_text_style: Union[None, TextStyle, Dict[ControlState, TextStyle]] = None + label_text_style: ControlStateValue[TextStyle] = None indicator_shape: Optional[OutlinedBorder] = None + def __post_init__(self): + if not isinstance(self.label_text_style, dict): + self.label_text_style = {ControlState.DEFAULT: self.label_text_style} + @dataclass class NavigationBarTheme: @@ -570,13 +574,17 @@ class NavigationBarTheme: shadow_color: Optional[str] = None surface_tint_color: Optional[str] = None indicator_color: Optional[str] = None - overlay_color: Union[None, str, Dict[ControlState, str]] = None + overlay_color: ControlStateValue[str] = None elevation: OptionalNumber = None height: OptionalNumber = None - label_text_style: Union[None, TextStyle, Dict[ControlState, TextStyle]] = None + label_text_style: ControlStateValue[TextStyle] = None indicator_shape: Optional[OutlinedBorder] = None label_behavior: Optional[NavigationBarLabelBehavior] = None + def __post_init__(self): + if not isinstance(self.label_text_style, dict): + self.label_text_style = {ControlState.DEFAULT: self.label_text_style} + @dataclass class SegmentedButtonTheme: @@ -603,19 +611,17 @@ class DataTableTheme: column_spacing: OptionalNumber = None data_row_max_height: OptionalNumber = None data_row_min_height: OptionalNumber = None - data_row_color: Union[None, str, Dict[ControlState, str]] = None + data_row_color: ControlStateValue[str] = None data_text_style: Optional[TextStyle] = None divider_thickness: OptionalNumber = None horizontal_margin: OptionalNumber = None heading_text_style: Optional[TextStyle] = None - heading_row_color: Union[None, str, Dict[ControlState, str]] = None + heading_row_color: ControlStateValue[str] = None heading_row_height: OptionalNumber = None - data_row_cursor: Union[None, MouseCursor, Dict[ControlState, MouseCursor]] = None + data_row_cursor: ControlStateValue[MouseCursor] = None decoration: Optional[BoxDecoration] = None heading_row_alignment: Optional[MainAxisAlignment] = None - heading_cell_cursor: Union[ - None, MouseCursor, Dict[ControlState, MouseCursor] - ] = None + heading_cell_cursor: ControlStateValue[MouseCursor] = None @dataclass diff --git a/sdk/python/packages/flet-core/src/flet_core/transparent_pointer.py b/sdk/python/packages/flet-core/src/flet_core/transparent_pointer.py index 7d2e05e14..03386d8ae 100644 --- a/sdk/python/packages/flet-core/src/flet_core/transparent_pointer.py +++ b/sdk/python/packages/flet-core/src/flet_core/transparent_pointer.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, RotateValue, @@ -35,12 +35,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/types.py b/sdk/python/packages/flet-core/src/flet_core/types.py index 353314015..3be566e76 100644 --- a/sdk/python/packages/flet-core/src/flet_core/types.py +++ b/sdk/python/packages/flet-core/src/flet_core/types.py @@ -3,7 +3,6 @@ from typing import Any, Callable, Dict, Optional, Protocol, Tuple, TypeVar, Union from warnings import warn -from flet_core.animation import Animation from flet_core.border_radius import BorderRadius from flet_core.control_event import ControlEvent from flet_core.event import Event @@ -67,8 +66,6 @@ class UrlTarget(Enum): OffsetValue = Optional[Union[Offset, Tuple[Union[float, int], Union[float, int]]]] -AnimationValue = Optional[Union[bool, int, Animation]] - @dataclass class Duration: @@ -360,6 +357,15 @@ class MouseCursor(Enum): ZOOM_OUT = "zoomOut" +class PointerDeviceType(Enum): + TOUCH = "touch" + MOUSE = "mouse" + STYLUS = "stylus" + INVERTED_STYLUS = "invertedStylus" + TRACKPAD = "trackpad" + UNKNOWN = "unknown" + + class StrokeCap(Enum): ROUND = "round" SQUARE = "square" @@ -410,6 +416,9 @@ class VisualDensity(Enum): OptionalEventCallable = Optional[Callable[[EventType], Any]] OptionalControlEventCallable = Optional[Callable[[ControlEvent], Any]] +# ControlState +T = TypeVar("T") +ControlStateValue = Union[None, T, Dict[ControlState, T]] # Wrapper Wrapper = Callable[..., Any] diff --git a/sdk/python/packages/flet-core/src/flet_core/video.py b/sdk/python/packages/flet-core/src/flet_core/video.py index bd534e3ed..7e49df666 100644 --- a/sdk/python/packages/flet-core/src/flet_core/video.py +++ b/sdk/python/packages/flet-core/src/flet_core/video.py @@ -3,6 +3,7 @@ from typing import Any, Dict, List, Optional, Union, cast from flet_core.alignment import Alignment +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.box import FilterQuality from flet_core.constrained_control import ConstrainedControl @@ -11,7 +12,6 @@ from flet_core.text_style import TextStyle from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, ImageFit, OffsetValue, OptionalControlEventCallable, @@ -111,12 +111,12 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/webview.py b/sdk/python/packages/flet-core/src/flet_core/webview.py index 066875a6d..d351a167e 100644 --- a/sdk/python/packages/flet-core/src/flet_core/webview.py +++ b/sdk/python/packages/flet-core/src/flet_core/webview.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -103,12 +103,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/src/flet_core/window_drag_area.py b/sdk/python/packages/flet-core/src/flet_core/window_drag_area.py index 91fbd9443..be39749c8 100644 --- a/sdk/python/packages/flet-core/src/flet_core/window_drag_area.py +++ b/sdk/python/packages/flet-core/src/flet_core/window_drag_area.py @@ -1,12 +1,12 @@ from typing import Any, Optional, Union +from flet_core.animation import AnimationValue from flet_core.badge import BadgeValue from flet_core.constrained_control import ConstrainedControl from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.tooltip import TooltipValue from flet_core.types import ( - AnimationValue, OffsetValue, OptionalControlEventCallable, ResponsiveNumber, @@ -68,12 +68,12 @@ def __init__( scale: ScaleValue = None, offset: OffsetValue = None, aspect_ratio: OptionalNumber = None, - animate_opacity: AnimationValue = None, - animate_size: AnimationValue = None, - animate_position: AnimationValue = None, - animate_rotation: AnimationValue = None, - animate_scale: AnimationValue = None, - animate_offset: AnimationValue = None, + animate_opacity: Optional[AnimationValue] = None, + animate_size: Optional[AnimationValue] = None, + animate_position: Optional[AnimationValue] = None, + animate_rotation: Optional[AnimationValue] = None, + animate_scale: Optional[AnimationValue] = None, + animate_offset: Optional[AnimationValue] = None, on_animation_end: OptionalControlEventCallable = None, tooltip: TooltipValue = None, badge: Optional[BadgeValue] = None, diff --git a/sdk/python/packages/flet-core/tests/test_datatable.py b/sdk/python/packages/flet-core/tests/test_datatable.py index fbeea5599..7078a23f4 100644 --- a/sdk/python/packages/flet-core/tests/test_datatable.py +++ b/sdk/python/packages/flet-core/tests/test_datatable.py @@ -38,7 +38,7 @@ def test_datarow_color_literal_material_state_as_string(): indent=0, name=None, values=["datarow"], - attrs={"color": '"yellow"'}, + attrs={"color": '{"":"yellow"}'}, commands=[], ), Command(indent=2, name=None, values=["datacell"], attrs={}, commands=[]),