Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Refactored core, renamed material to essentials, added align widget, …
Browse files Browse the repository at this point in the history
…improved overlay widget
  • Loading branch information
breitburg committed Dec 22, 2019
1 parent 50b1eff commit 6b1c590
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 35 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions fluent/widget/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from fluent.render import window
from time import sleep


class Widget:
Expand Down Expand Up @@ -28,7 +27,7 @@ class Widget:

def __init__(self, pressed=None):
self._pressed = pressed # On widget pressed function bindings
self.parent = None # Adding parent property
self.parent = self # Adding dummy parent property

def build(self): # Method that will return a widget
return NotImplemented
Expand Down Expand Up @@ -78,6 +77,7 @@ class GenericWidget(Widget):

def __init__(self, size):
self._size = size # Setting widget size

super(GenericWidget, self).__init__()

def build(self):
Expand Down
2 changes: 1 addition & 1 deletion fluent/widget/layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from fluent.widget.layout.spacer import Spacer
from fluent.widget.layout.stack import Row, Column
from fluent.widget.layout.screen import Screen
from fluent.widget.layout.center import Center
from fluent.widget.layout.align import Align, Center
32 changes: 32 additions & 0 deletions fluent/widget/layout/align.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from fluent.widget.core import GenericWidget
from fluent.render import align


class Align(GenericWidget):
def __init__(self, child, align=(align.top, align.left)):
self.child = child
self.align = align

super(Align, self).__init__(size=(0, 0))

def render(self, xy):
self._size = self.parent.size

horizontal_padding = vertical_padding = 0

if self.align[0] == align.bottom:
vertical_padding = self._size[1] - self.child.size[1]
elif self.align[0] == align.center:
vertical_padding = self._size[1] / 2 - self.child.size[1] / 2

if self.align[1] == align.right:
horizontal_padding = self._size[0] - self.child.size[0]
elif self.align[1] == align.center:
horizontal_padding = self._size[0] / 2 - self.child.size[0] / 2

self.child.render(xy=(int(xy[0] + horizontal_padding), int(xy[1] + vertical_padding)))


class Center(Align):
def __init__(self, child):
super(Center, self).__init__(child=child, align=(align.center, align.center))
14 changes: 0 additions & 14 deletions fluent/widget/layout/center.py

This file was deleted.

21 changes: 5 additions & 16 deletions fluent/widget/layout/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,14 @@


class Overlay(GenericWidget):
def __init__(self, bottom, top, align=(align.top, align.left)):
def __init__(self, bottom, top):
self.bottom = bottom

self.top = top
self.align = align
self.top.parent = self.bottom

super(Overlay, self).__init__(size=self.bottom.size)

def render(self, xy):
self.bottom.render(xy=xy)
horizontal_padding = vertical_padding = 0

if self.align[0] == 'bottom':
vertical_padding = self.bottom.size[1] - self.top.size[1]
elif self.align[0] == 'center':
vertical_padding = self.bottom.size[1] / 2 - self.top.size[1] / 2

if self.align[1] == 'right':
horizontal_padding = self.bottom.size[0] - self.top.size[0]
elif self.align[1] == 'center':
horizontal_padding = self.bottom.size[0] / 2 - self.top.size[0] / 2

self.top.render(xy=(int(xy[0] + horizontal_padding), int(xy[1] + vertical_padding)))
for widget in [self.bottom, self.top]:
widget.render(xy=xy)
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Here is the basic *Hello, world* code example:

```python
from fluent.material import * # Importing library
from fluent.essentials import * # Importing library


# Calling launch method
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fluent.material import * # Importing library
from fluent.essentials import * # Importing library
from fluent.debug import auto_reload


Expand Down

0 comments on commit 6b1c590

Please sign in to comment.