From 25e39e690734fb01807eeb4eea333623915bc73d Mon Sep 17 00:00:00 2001 From: jswrt <9637399+jswrt@user.noreply.gitee.com> Date: Wed, 27 Apr 2022 05:14:47 +0000 Subject: [PATCH] update web/py_lib/flutter.py. --- web/py_lib/flutter.py | 66 ++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/web/py_lib/flutter.py b/web/py_lib/flutter.py index f4c1ee0..6d7463f 100755 --- a/web/py_lib/flutter.py +++ b/web/py_lib/flutter.py @@ -124,7 +124,7 @@ class Container: self.margin = margin self.boxShadow = boxShadow self.shape = shape - def render(self): + def render(self, parent): style = {} if self.width is not None: style['width'] = f'{self.width}px' if isinstance(self.width, int) else self.width @@ -149,7 +149,8 @@ class Container: if self.child.textAlign is not None: style['text-align'] = self.child.textAlign e = maketag('div', style=style) - e.appendChild(self.child.render()) + parent.appendChild(e) + self.child.render(e) return e class FontWeight: @@ -214,7 +215,7 @@ class Text: self.style = style self.overflow = overflow self.maxLines = maxLines - def render(self): + def render(self, parent): style = {} if self.style is not None: style['font'] = str(self.style) @@ -234,6 +235,7 @@ class Text: style['-webkit-line-clamp'] = self.maxLines style['-webkit-box-orient'] = 'vertical' e = maketag('div', style=style) + parent.appendChild(e) p = javascript.document.createTextNode(self.text) e.appendChild(p) return e @@ -242,8 +244,8 @@ class RichText: def __init__(self, text): assert isinstance(text, TextSpan) self.text = text - def render(self): - return self.text.render() + def render(self, parent): + return self.text.render(parent) class TextSpan: def __init__(self, text=None, color=None, style=None, children=None): @@ -260,7 +262,7 @@ class TextSpan: self.color = color self.style = style self.children = children - def render(self): + def render(self, parent): style = {} if self.style is not None: style['font'] = str(self.style) @@ -274,22 +276,24 @@ class TextSpan: if self.color is not None: style['color'] = self.color e = maketag('span', style=style) + parent.appendChild(e) if self.text is not None: p = javascript.document.createTextNode(self.text) e.appendChild(p) elif self.children is not None: for c in self.children: - e.appendChild(c.render()) + c.render(e) return e class Center: def __init__(self, child): assert hasattr(child, 'render') and callable(child.render) self.child = child - def render(self): + def render(self, parent): e = maketag('div', style={'display': 'flex', 'align-items': 'center', 'justify-content': 'center', 'width': '100%', 'height': '100%'}) - e.appendChild(self.child.render()) + parent.appendChild(e) + self.child.render(e) return e class Stack: @@ -298,10 +302,10 @@ class Stack: for c in children: assert isinstance(c, Positioned) self.children = children - def render(self): + def render(self, parent): e = maketag('div',style={'position':'relative'}) for c in self.children: - e.appendChild(c.render()) + c.render(e) return e class Positioned: @@ -312,11 +316,12 @@ class Positioned: self.child = child self.left = left self.top = top - def render(self): + def render(self, parent): top = f'{self.top}px' if isinstance(self.top, int) else self.top left = f'{self.left}px' if isinstance(self.left, int) else self.left e = maketag('div', style={'position':'absolute','top':top,'left':left}) - e.appendChild(self.child.render()) + parent.appendChild(e) + self.child.render(e) return e class Transform: @@ -327,7 +332,7 @@ class Transform: self.child = child self.rotate = rotate self.scale = scale - def render(self): + def render(self, parent): transform = [] if self.rotate is not None: rotate = f'{self.rotate}deg' if isinstance(self.rotate, int) else self.rotate @@ -335,9 +340,10 @@ class Transform: if self.scale is not None: transform.append(f'scale({self.scale})') e = maketag('div') + parent.appendChild(e) if len(transform)>0: e.style.transform = ' '.join(transform) - e.appendChild(self.child.render()) + self.child.render(e) return e @@ -393,7 +399,7 @@ class Flex: self.mainAxisAlignment = mainAxisAlignment self.crossAxisAlignment = crossAxisAlignment self.mainAxisSize = mainAxisSize - def render(self): + def render(self, parent): style = {'display': 'flex', 'flex-direction': self.direction, 'flex-wrap': 'nowrap', @@ -405,8 +411,9 @@ class Flex: else: style['height'] = '100%' e = maketag('div', style=style) + parent.appendChild(e) for child in self.children: - e.appendChild(child.render()) + child.render(e) return e class Row(Flex): @@ -440,17 +447,18 @@ class Scaffold: assert hasattr(body, 'render') and callable(body.render) self.appBar = appBar self.body = body - def render(self): + def render(self, parent): scafflod_height = javascript.document.documentElement.clientHeight.data() e = maketag('div', style={'display':'flex', 'flex-flow':'column', 'height':f'{scafflod_height}px'}) header = maketag('header', {'class':'mdc-top-app-bar mdc-top-app-bar--fixed'}, style={'flex': '0 1 auto'}) + parent.appendChild(e) e.appendChild(header) main = maketag('header', {'class':'mdc-top-app-bar--fixed-adjust'}, style={'flex': '1 1 auto'}) e.appendChild(main) - header.appendChild(self.appBar.render()) - main.appendChild(self.body.render()) + self.appBar.render(header) + self.body.render(main) self.topAppBar = javascript.mdc.topAppBar.MDCTopAppBar.new(e) return e @@ -467,25 +475,23 @@ class AppBar: self.leading = leading self.title = title self.actions = actions - def render(self): + def render(self, parent): e = maketag('div', {'class':'mdc-top-app-bar__row'}) + parent.appendChild(e) start = maketag('header', {'class':'mdc-top-app-bar__section mdc-top-app-bar__section--align-start'}) e.appendChild(start) end = maketag('header', {'class':'mdc-top-app-bar__section mdc-top-app-bar__section--align-end', 'rule':'toolbar'}) e.appendChild(end) if self.leading is not None: - leading = self.leading.render() + leading = self.leading.render(start) add_class(leading, 'mdc-top-app-bar__navigation-icon') - start.appendChild(leading) if self.title is not None: - title = self.title.render() + title = self.title.render(start) add_class(title, 'mdc-top-app-bar__title') - start.appendChild(title) if self.actions is not None: for action in self.actions: - action = action.render() + action = action.render(end) add_class(action, 'mdc-top-app-bar__action-item') - end.appendChild(action) return e class IconButton: @@ -495,8 +501,9 @@ class IconButton: assert callable(onPressed) self.icon = icon self.onPressed = onPressed - def render(self): + def render(self, parent): e = maketag('button', {'class':'material-icons mdc-top-app-bar__action-item mdc-icon-button'}) + parent.appendChild(e) e.appendChild(javascript.document.createTextNode(self.icon.icon)) if self.onPressed is not None: e.bind('click', self.onPressed) @@ -507,8 +514,9 @@ class Icon: def __init__(self, icon): assert isinstance(icon, str) self.icon = icon - def render(self): + def render(self, parent): e = maketag('span', {'class':'material-icons'}) + parent.appendChild(e) e.appendChild(javascript.document.createTextNode(self.icon)) return e -- Gitee