From 4de9377a67ef2d57b0aa61379ac7d1bf559b0d06 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 29 Apr 2022 17:43:03 -0700 Subject: [PATCH] Icon browser done --- client/lib/controls/text.dart | 2 ++ client/lib/controls/textfield.dart | 10 ++++++++-- docs/roadmap.md | 1 + sdk/python/flet/tabs.py | 3 ++- sdk/python/flet/text.py | 12 ++++++++++++ sdk/python/playground/icons-browser.py | 23 ++++++++++------------- 6 files changed, 35 insertions(+), 16 deletions(-) diff --git a/client/lib/controls/text.dart b/client/lib/controls/text.dart index 388bc645a..3be20069f 100644 --- a/client/lib/controls/text.dart +++ b/client/lib/controls/text.dart @@ -17,6 +17,7 @@ class TextControl extends StatelessWidget { debugPrint("Text build: ${control.id}"); String text = control.attrString("value", "")!; + bool noWrap = control.attrBool("noWrap", false)!; TextStyle? style; var styleName = control.attrString("style", null); @@ -53,6 +54,7 @@ class TextControl extends StatelessWidget { ) : Text( text, + softWrap: !noWrap, style: style, textAlign: textAlign, overflow: overflow, diff --git a/client/lib/controls/textfield.dart b/client/lib/controls/textfield.dart index 0af69c5a7..20fcc156a 100644 --- a/client/lib/controls/textfield.dart +++ b/client/lib/controls/textfield.dart @@ -32,7 +32,7 @@ class _TextFieldControlState extends State { String _value = ""; bool _revealPassword = false; late TextEditingController _controller; - final FocusNode _focusNode = FocusNode(); + late final FocusNode _focusNode = FocusNode(); late final _shiftEnterfocusNode = FocusNode( onKey: (FocusNode node, RawKeyEvent evt) { @@ -138,6 +138,12 @@ class _TextFieldControlState extends State { var textField = TextFormField( autofocus: autofocus, enabled: !disabled, + onFieldSubmitted: (_) { + ws.pageEventFromWeb( + eventTarget: widget.control.id, + eventName: "submit", + eventData: ""); + }, decoration: buildInputDecoration( widget.control, prefixControls.isNotEmpty ? prefixControls.first : null, @@ -154,7 +160,7 @@ class _TextFieldControlState extends State { ? _shiftEnterfocusNode : _focusNode, onChanged: (String value) { - debugPrint(value); + //debugPrint(value); setState(() { _value = value; }); diff --git a/docs/roadmap.md b/docs/roadmap.md index 1edde376b..91f3c03b7 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -599,6 +599,7 @@ TextTheme: https://api.flutter.dev/flutter/material/TextTheme-class.html - overflow - (TextOverflow) `clip`, `ellipsis`, `fade`, `visible` - selectable - tooltip +- noWrap ## Icon diff --git a/sdk/python/flet/tabs.py b/sdk/python/flet/tabs.py index b75e77bef..af5a9e6f2 100644 --- a/sdk/python/flet/tabs.py +++ b/sdk/python/flet/tabs.py @@ -1,6 +1,7 @@ -from typing import List, Optional +from typing import Optional from beartype import beartype +from beartype.typing import List from flet.constrained_control import ConstrainedControl from flet.control import Control, OptionalNumber diff --git a/sdk/python/flet/text.py b/sdk/python/flet/text.py index cfda9d18d..9e8728304 100644 --- a/sdk/python/flet/text.py +++ b/sdk/python/flet/text.py @@ -54,6 +54,7 @@ def __init__( style: str = None, overflow: TextOverflow = None, selectable: bool = None, + no_wrap: bool = None, color: str = None, bgcolor: str = None, ): @@ -76,6 +77,7 @@ def __init__( self.size = size self.weight = weight self.italic = italic + self.no_wrap = no_wrap self.style = style self.overflow = overflow self.selectable = selectable @@ -144,6 +146,16 @@ def italic(self): def italic(self, value: Optional[bool]): self._set_attr("italic", value) + # no_wrap + @property + def no_wrap(self): + return self._get_attr("italic", data_type="noWrap", def_value=False) + + @no_wrap.setter + @beartype + def no_wrap(self, value: Optional[bool]): + self._set_attr("noWrap", value) + # selectable @property def selectable(self): diff --git a/sdk/python/playground/icons-browser.py b/sdk/python/playground/icons-browser.py index 4cd0d3299..aa1f32652 100644 --- a/sdk/python/playground/icons-browser.py +++ b/sdk/python/playground/icons-browser.py @@ -16,6 +16,7 @@ Row, SnackBar, Text, + TextButton, TextField, alignment, border_radius, @@ -43,7 +44,10 @@ def main(page: Page): page.theme_mode = "light" search_txt = TextField( - expand=1, hint_text="Enter keyword and press search button", autofocus=True + expand=1, + hint_text="Enter keyword and press search button", + autofocus=True, + on_submit=lambda e: display_icons(e.control.value), ) search_results = GridView( expand=1, @@ -51,7 +55,7 @@ def main(page: Page): max_extent=150, spacing=5, run_spacing=5, - child_aspect_ratio=2, + child_aspect_ratio=1, ) status_bar = Text() @@ -73,20 +77,17 @@ def display_icons(search_term: str): icon_name = icons_list[i] icon_key = f"icons.{icon_name.upper()}" search_results.controls.append( - OutlinedButton( + TextButton( content=Container( content=Column( [ - Icon( - name=icon_name, - ), + Icon(name=icon_name, size=30), Text( value=icon_name, - size=10, + size=12, width=100, - # selectable=True, + no_wrap=True, text_align="center", - overflow="fade", color=colors.ON_SURFACE_VARIANT, ), ], @@ -95,10 +96,6 @@ def display_icons(search_term: str): horizontal_alignment="center", ), alignment=alignment.center, - padding=padding.only(left=5, right=5), - # border=border.all(1, colors.BLACK26), - # bgcolor="#f0f0f0", - border_radius=border_radius.all(3), ), tooltip=f"{icon_key}\nClick to copy to a clipboard", on_click=copy_to_clipboard,