From c2693bc02a97ee29ee9d2dc2a2f0edc151a0967c Mon Sep 17 00:00:00 2001 From: Harsh Date: Tue, 22 Oct 2019 16:15:13 +1100 Subject: [PATCH 01/10] Added property to change the center of the coordinates --- adafruit_display_text/label.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 1c2838a..5875ae1 100644 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -74,6 +74,8 @@ def __init__(self, font, *, text=None, max_glyphs=None, color=0xffffff, self.height = bounds[1] self._line_spacing = line_spacing self._boundingbox = None + self._cx = None + self._cy = None if text: self._update_text(text) @@ -172,3 +174,19 @@ def text(self): @text.setter def text(self, new_text): self._update_text(new_text) + + @property + def cx(self): + return self.x + self._boundingbox[2] + + @property + def cy(self): + return self.y + self._boundingbox[3] + + @cx.setter + def cx(self,new_cx): + self.x = int(new_cx-(self._boundingbox[2]/2)) + + @cy.setter + def cy(self,new_cy): + self.y = int(new_cy-(self._boundingbox[3]/2)) \ No newline at end of file From 9ce37d2cedb3aa69dbf422b02a2db5238f069b31 Mon Sep 17 00:00:00 2001 From: Harsh Date: Tue, 22 Oct 2019 16:16:59 +1100 Subject: [PATCH 02/10] Added property to change the center of the coordinates --- adafruit_display_text/label.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 5875ae1..1884ca2 100644 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -74,8 +74,6 @@ def __init__(self, font, *, text=None, max_glyphs=None, color=0xffffff, self.height = bounds[1] self._line_spacing = line_spacing self._boundingbox = None - self._cx = None - self._cy = None if text: self._update_text(text) @@ -177,11 +175,11 @@ def text(self, new_text): @property def cx(self): - return self.x + self._boundingbox[2] + return self.x + self._boundingbox[2]/2 @property def cy(self): - return self.y + self._boundingbox[3] + return self.y + self._boundingbox[3]/2 @cx.setter def cx(self,new_cx): From dce386c9c3283148c76452c602715fc882294747 Mon Sep 17 00:00:00 2001 From: Harsh Date: Tue, 22 Oct 2019 16:55:58 +1100 Subject: [PATCH 03/10] Added property to change the center of the coordinates --- adafruit_display_text/label.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 1884ca2..9eef67f 100644 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -175,16 +175,18 @@ def text(self, new_text): @property def cx(self): + """Center X of the Label """ return self.x + self._boundingbox[2]/2 @property def cy(self): + """Center Y of the Label """ return self.y + self._boundingbox[3]/2 @cx.setter - def cx(self,new_cx): + def cx(self, new_cx): self.x = int(new_cx-(self._boundingbox[2]/2)) @cy.setter - def cy(self,new_cy): + def cy(self, new_cy): self.y = int(new_cy-(self._boundingbox[3]/2)) \ No newline at end of file From a507e09991dee42ef89011e4cc4209df8fa03c3a Mon Sep 17 00:00:00 2001 From: Harsh Date: Tue, 22 Oct 2019 17:04:09 +1100 Subject: [PATCH 04/10] Added property to change the center of the coordinates --- adafruit_display_text/label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 9eef67f..d9a73b0 100644 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -181,7 +181,7 @@ def cx(self): @property def cy(self): """Center Y of the Label """ - return self.y + self._boundingbox[3]/2 + return self.y + self._boundingbox[3]/2 @cx.setter def cx(self, new_cx): From 3c1734bb97cc7501bc1860ac1f6ca47ebacd4eb3 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 27 Jan 2020 17:08:21 -0600 Subject: [PATCH 05/10] changing to anchor point moving to anchor point instead of cx and cy --- adafruit_display_text/label.py | 39 ++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index d9a73b0..de2b2d0 100644 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -174,19 +174,26 @@ def text(self, new_text): self._update_text(new_text) @property - def cx(self): - """Center X of the Label """ - return self.x + self._boundingbox[2]/2 - - @property - def cy(self): - """Center Y of the Label """ - return self.y + self._boundingbox[3]/2 - - @cx.setter - def cx(self, new_cx): - self.x = int(new_cx-(self._boundingbox[2]/2)) - - @cy.setter - def cy(self, new_cy): - self.y = int(new_cy-(self._boundingbox[3]/2)) \ No newline at end of file + def anchor_point(self): + """Point that anchored_position moves relative to. + Tuple with decimal percentage of width and height. + (E.g. (0,0) is top left, (1.0, 0.5): is middle right.)""" + return self._anchor_point + + @anchor_point.setter + def anchor_point(self, new_anchor_point): + self._anchor_point = new_anchor_point + + @property + def anchored_position(self): + """Position relative to the anchor_point. Tuple containing x,y + pixel coordinates.""" + _anchored_position = ( + self.x-self._boundingbox[2]*self._anchor_point[0], + self.y-self._boundingbox[3]*self._anchor_point[1]) + return _anchored_position + + @anchored_position.setter + def anchored_position(self, new_position): + self.x = int(new_position[0]-(self._boundingbox[2]*self._anchor_point[0])) + self.y = int(new_position[1]-(self._boundingbox[3]*self._anchor_point[1])) From 2fdd09b0ff8f8e026618b3b735a74f4b63a1f1bb Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 27 Jan 2020 17:24:30 -0600 Subject: [PATCH 06/10] Update label.py fix for missing _anchor_point in init --- adafruit_display_text/label.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index de2b2d0..93126b8 100644 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -65,7 +65,8 @@ def __init__(self, font, *, text=None, max_glyphs=None, color=0xffffff, self.width = max_glyphs self.font = font self._text = None - + self._anchor_point = (0, 0) + self.palette = displayio.Palette(2) self.palette.make_transparent(0) self.palette[1] = color From 12b47af9c2fa23a903d40654c1f10253bceb3f64 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 27 Jan 2020 17:53:19 -0600 Subject: [PATCH 07/10] fix return removing unneeded _anchored_position variable. --- adafruit_display_text/label.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 93126b8..6146cac 100644 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -65,7 +65,6 @@ def __init__(self, font, *, text=None, max_glyphs=None, color=0xffffff, self.width = max_glyphs self.font = font self._text = None - self._anchor_point = (0, 0) self.palette = displayio.Palette(2) self.palette.make_transparent(0) @@ -189,10 +188,8 @@ def anchor_point(self, new_anchor_point): def anchored_position(self): """Position relative to the anchor_point. Tuple containing x,y pixel coordinates.""" - _anchored_position = ( - self.x-self._boundingbox[2]*self._anchor_point[0], - self.y-self._boundingbox[3]*self._anchor_point[1]) - return _anchored_position + return (self.x-self._boundingbox[2]*self._anchor_point[0], + self.y-self._boundingbox[3]*self._anchor_point[1]) @anchored_position.setter def anchored_position(self, new_position): From 7c74bcd8adabd7b758d5869bc75d3ea5afe3e8a1 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 27 Jan 2020 17:58:44 -0600 Subject: [PATCH 08/10] remove whitespace --- adafruit_display_text/label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 6146cac..37bd247 100644 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -65,7 +65,7 @@ def __init__(self, font, *, text=None, max_glyphs=None, color=0xffffff, self.width = max_glyphs self.font = font self._text = None - + self.palette = displayio.Palette(2) self.palette.make_transparent(0) self.palette[1] = color From 344775b34a16140561f2bf190bcab63246d65339 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 27 Jan 2020 18:09:12 -0600 Subject: [PATCH 09/10] pylint fix adding _anchor_point into init --- adafruit_display_text/label.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 37bd247..1f21213 100644 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -65,6 +65,7 @@ def __init__(self, font, *, text=None, max_glyphs=None, color=0xffffff, self.width = max_glyphs self.font = font self._text = None + self._anchor_point = (0, 0) self.palette = displayio.Palette(2) self.palette.make_transparent(0) From 86130b39f2e947a4b5ed0ce01a79a01deeeacf9d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 27 Jan 2020 19:54:29 -0600 Subject: [PATCH 10/10] default x and y inside init tested with simpletest and the anchor point test linked above. --- adafruit_display_text/label.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 1f21213..98e6563 100644 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -66,6 +66,8 @@ def __init__(self, font, *, text=None, max_glyphs=None, color=0xffffff, self.font = font self._text = None self._anchor_point = (0, 0) + self.x = 0 + self.y = 0 self.palette = displayio.Palette(2) self.palette.make_transparent(0)