Skip to content

Commit

Permalink
Any control can be positioned absolutely inside Stack (#60)
Browse files Browse the repository at this point in the history
All visible controls got 4 new properties:
- left
- top
- right
- bottom
  • Loading branch information
FeodorFitsner authored Jul 8, 2022
1 parent b3763a6 commit c7333dc
Show file tree
Hide file tree
Showing 27 changed files with 274 additions and 4 deletions.
26 changes: 24 additions & 2 deletions client/lib/controls/create_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,11 @@ Widget baseControl(Widget widget, Control? parent, Control control) {

Widget constrainedControl(Widget widget, Control? parent, Control control) {
return _expandable(
_sizedControl(
_tooltip(_opacity(widget, parent, control), parent, control),
_positionedControl(
_sizedControl(
_tooltip(_opacity(widget, parent, control), parent, control),
parent,
control),
parent,
control),
parent,
Expand Down Expand Up @@ -282,6 +285,25 @@ Widget _tooltip(Widget widget, Control? parent, Control control) {
: widget;
}

Widget _positionedControl(Widget widget, Control? parent, Control control) {
var left = control.attrDouble("left", null);
var top = control.attrDouble("top", null);
var right = control.attrDouble("right", null);
var bottom = control.attrDouble("bottom", null);

if (left != null || top != null || right != null || bottom != null) {
debugPrint("Positioned");
return Positioned(
left: left,
top: top,
right: right,
bottom: bottom,
child: widget,
);
}
return widget;
}

Widget _sizedControl(Widget widget, Control? parent, Control control) {
var width = control.attrDouble("width", null);
var height = control.attrDouble("height", null);
Expand Down
8 changes: 8 additions & 0 deletions sdk/python/flet/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def __init__(
ref: Ref = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
expand: Union[bool, int] = None,
opacity: OptionalNumber = None,
tooltip: str = None,
Expand All @@ -32,6 +36,10 @@ def __init__(
ref=ref,
width=width,
height=height,
left=left,
top=top,
right=right,
bottom=bottom,
expand=expand,
opacity=opacity,
tooltip=tooltip,
Expand Down
8 changes: 8 additions & 0 deletions sdk/python/flet/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def __init__(
ref: Ref = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
expand: Union[bool, int] = None,
opacity: OptionalNumber = None,
tooltip: str = None,
Expand All @@ -44,6 +48,10 @@ def __init__(
ref=ref,
width=width,
height=height,
left=left,
top=top,
right=right,
bottom=bottom,
expand=expand,
opacity=opacity,
tooltip=tooltip,
Expand Down
8 changes: 8 additions & 0 deletions sdk/python/flet/circle_avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def __init__(
ref: Ref = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
expand: Union[bool, int] = None,
opacity: OptionalNumber = None,
tooltip: str = None,
Expand All @@ -37,6 +41,10 @@ def __init__(
ref=ref,
width=width,
height=height,
left=left,
top=top,
right=right,
bottom=bottom,
expand=expand,
opacity=opacity,
tooltip=tooltip,
Expand Down
8 changes: 8 additions & 0 deletions sdk/python/flet/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def __init__(
ref: Ref = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
expand: Union[bool, int] = None,
opacity: OptionalNumber = None,
visible: bool = None,
Expand All @@ -42,6 +46,10 @@ def __init__(
ref=ref,
width=width,
height=height,
left=left,
top=top,
right=right,
bottom=bottom,
expand=expand,
opacity=opacity,
visible=visible,
Expand Down
52 changes: 50 additions & 2 deletions sdk/python/flet/constrained_control.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Optional, Union
from typing import Union

from beartype import beartype

from flet.control import Control, InputBorder, OptionalNumber
from flet.control import Control, OptionalNumber
from flet.ref import Ref


Expand All @@ -21,6 +21,10 @@ def __init__(
#
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
):
Control.__init__(
self,
Expand All @@ -35,6 +39,10 @@ def __init__(

self.width = width
self.height = height
self.left = left
self.top = top
self.right = right
self.bottom = bottom

# width
@property
Expand All @@ -55,3 +63,43 @@ def height(self) -> OptionalNumber:
@beartype
def height(self, value: OptionalNumber):
self._set_attr("height", value)

# left
@property
def left(self) -> OptionalNumber:
return self._get_attr("left")

@left.setter
@beartype
def left(self, value: OptionalNumber):
self._set_attr("left", value)

# top
@property
def top(self) -> OptionalNumber:
return self._get_attr("top")

@top.setter
@beartype
def top(self, value: OptionalNumber):
self._set_attr("top", value)

# right
@property
def right(self) -> OptionalNumber:
return self._get_attr("right")

@right.setter
@beartype
def right(self, value: OptionalNumber):
self._set_attr("right", value)

# bottom
@property
def bottom(self) -> OptionalNumber:
return self._get_attr("bottom")

@bottom.setter
@beartype
def bottom(self, value: OptionalNumber):
self._set_attr("bottom", value)
8 changes: 8 additions & 0 deletions sdk/python/flet/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def __init__(
ref: Ref = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
expand: Union[bool, int] = None,
opacity: OptionalNumber = None,
tooltip: str = None,
Expand All @@ -52,6 +56,10 @@ def __init__(
ref=ref,
width=width,
height=height,
left=left,
top=top,
right=right,
bottom=bottom,
expand=expand,
opacity=opacity,
tooltip=tooltip,
Expand Down
8 changes: 8 additions & 0 deletions sdk/python/flet/elevated_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def __init__(
ref: Ref = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
expand: Union[bool, int] = None,
opacity: OptionalNumber = None,
tooltip: str = None,
Expand All @@ -37,6 +41,10 @@ def __init__(
ref=ref,
width=width,
height=height,
left=left,
top=top,
right=right,
bottom=bottom,
expand=expand,
opacity=opacity,
tooltip=tooltip,
Expand Down
8 changes: 8 additions & 0 deletions sdk/python/flet/floating_action_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def __init__(
ref: Ref = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
expand: Union[bool, int] = None,
opacity: OptionalNumber = None,
tooltip: str = None,
Expand All @@ -34,6 +38,10 @@ def __init__(
ref=ref,
width=width,
height=height,
left=left,
top=top,
right=right,
bottom=bottom,
expand=expand,
opacity=opacity,
tooltip=tooltip,
Expand Down
8 changes: 8 additions & 0 deletions sdk/python/flet/form_field_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def __init__(
ref: Ref = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
expand: Union[bool, int] = None,
opacity: OptionalNumber = None,
tooltip: str = None,
Expand Down Expand Up @@ -44,6 +48,10 @@ def __init__(
ref=ref,
width=width,
height=height,
left=left,
top=top,
right=right,
bottom=bottom,
expand=expand,
opacity=opacity,
tooltip=tooltip,
Expand Down
8 changes: 8 additions & 0 deletions sdk/python/flet/grid_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def __init__(
ref: Ref = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
expand: Union[bool, int] = None,
opacity: OptionalNumber = None,
visible: bool = None,
Expand All @@ -36,6 +40,10 @@ def __init__(
ref=ref,
width=width,
height=height,
left=left,
top=top,
right=right,
bottom=bottom,
expand=expand,
opacity=opacity,
visible=visible,
Expand Down
8 changes: 8 additions & 0 deletions sdk/python/flet/icon_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def __init__(
ref: Ref = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
expand: Union[bool, int] = None,
opacity: OptionalNumber = None,
tooltip: str = None,
Expand All @@ -35,6 +39,10 @@ def __init__(
ref=ref,
width=width,
height=height,
left=left,
top=top,
right=right,
bottom=bottom,
expand=expand,
opacity=opacity,
tooltip=tooltip,
Expand Down
8 changes: 8 additions & 0 deletions sdk/python/flet/list_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def __init__(
ref: Ref = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
expand: Union[bool, int] = None,
opacity: OptionalNumber = None,
tooltip: str = None,
Expand All @@ -40,6 +44,10 @@ def __init__(
ref=ref,
width=width,
height=height,
left=left,
top=top,
right=right,
bottom=bottom,
expand=expand,
opacity=opacity,
tooltip=tooltip,
Expand Down
8 changes: 8 additions & 0 deletions sdk/python/flet/list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def __init__(
ref: Ref = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
left: OptionalNumber = None,
top: OptionalNumber = None,
right: OptionalNumber = None,
bottom: OptionalNumber = None,
expand: Union[bool, int] = None,
opacity: OptionalNumber = None,
visible: bool = None,
Expand All @@ -36,6 +40,10 @@ def __init__(
ref=ref,
width=width,
height=height,
left=left,
top=top,
right=right,
bottom=bottom,
expand=expand,
opacity=opacity,
visible=visible,
Expand Down
Loading

0 comments on commit c7333dc

Please sign in to comment.