From 9a373a1ecddfc0951e13b3674097abc348e5f098 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Mon, 12 Jun 2023 23:49:35 +0530 Subject: [PATCH 01/26] adding bounding box property --- fury/ui/core.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fury/ui/core.py b/fury/ui/core.py index c0314fd94..867da0190 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -747,6 +747,9 @@ def __init__( self.shadow = shadow self.vertical_justification = vertical_justification self.message = text + lines = self.message.split("\n") + self.boundingbox = [self.position[0], self.position[1], + len(lines[0])*font_size, len(lines)*font_size] def _setup(self): self.actor = TextActor() @@ -785,6 +788,10 @@ def _add_to_scene(self, scene): self.background.resize(size) scene.add(self.background, self.actor) + self.background.resize( + (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1])) + self.background.position = [self.boundingbox[0], self.boundingbox[1]] + @property def message(self): """Get message from the text. From e35ae2ce98c50ddbb2f63adea6c0377412cd26a5 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Mon, 12 Jun 2023 23:51:22 +0530 Subject: [PATCH 02/26] seperating bounding box function --- fury/ui/core.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index 867da0190..18b247b7e 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -747,9 +747,7 @@ def __init__( self.shadow = shadow self.vertical_justification = vertical_justification self.message = text - lines = self.message.split("\n") - self.boundingbox = [self.position[0], self.position[1], - len(lines[0])*font_size, len(lines)*font_size] + self.update_bounding_box() def _setup(self): self.actor = TextActor() @@ -1085,6 +1083,12 @@ def background_color(self, color): self.background.set_visibility(True) self.background.color = color + + def update_bounding_box(self): + lines = self.message.split("\n") + self.boundingbox = [self.position[0], self.position[1], + self.position[0]+len(lines[0])*self.font_size, self.position[1]+len(lines)*self.font_size] + def _set_position(self, position): """Set text actor position. From 868a4e43c2d8eed137c00c2151e017cdc71afde0 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Mon, 12 Jun 2023 23:53:24 +0530 Subject: [PATCH 03/26] updating bbox on message change --- fury/ui/core.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index 18b247b7e..9e9760b91 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -786,9 +786,9 @@ def _add_to_scene(self, scene): self.background.resize(size) scene.add(self.background, self.actor) - self.background.resize( - (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1])) - self.background.position = [self.boundingbox[0], self.boundingbox[1]] + # self.background.resize( + # (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1])) + # self.background.position = [self.boundingbox[0], self.boundingbox[1]] @property def message(self): @@ -811,6 +811,7 @@ def message(self, text): The message to be set. """ self.actor.SetInput(text) + self.update_bounding_box() @property def font_size(self): @@ -1088,6 +1089,8 @@ def update_bounding_box(self): lines = self.message.split("\n") self.boundingbox = [self.position[0], self.position[1], self.position[0]+len(lines[0])*self.font_size, self.position[1]+len(lines)*self.font_size] + self.background.resize( + (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1])) def _set_position(self, position): """Set text actor position. From 9bbe987f027a718d1cdde80c29fd1f8ce76d896c Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Mon, 12 Jun 2023 23:54:05 +0530 Subject: [PATCH 04/26] removing comments --- fury/ui/core.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index 9e9760b91..a5e6eb432 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -786,10 +786,6 @@ def _add_to_scene(self, scene): self.background.resize(size) scene.add(self.background, self.actor) - # self.background.resize( - # (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1])) - # self.background.position = [self.boundingbox[0], self.boundingbox[1]] - @property def message(self): """Get message from the text. @@ -1084,7 +1080,6 @@ def background_color(self, color): self.background.set_visibility(True) self.background.color = color - def update_bounding_box(self): lines = self.message.split("\n") self.boundingbox = [self.position[0], self.position[1], From 08dcc2465f5bc1be06c0738299aa3a5446cb517b Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Thu, 15 Jun 2023 23:56:01 +0530 Subject: [PATCH 05/26] updating alignment --- fury/ui/core.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/fury/ui/core.py b/fury/ui/core.py index a5e6eb432..6615d60a6 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1080,6 +1080,34 @@ def background_color(self, color): self.background.set_visibility(True) self.background.color = color + def update_alignment(self): + + text_position = self.actor.GetPosition() + if self.justification == 'left': + self.actor.SetPosition((self.boundingbox[0], text_position[1])) + elif self.justification == 'center': + self.actor.SetPosition( + (self.boundingbox[0] + (self.boundingbox[2]-self.boundingbox[0])//2, text_position[1])) + elif self.justification == 'right': + self.actor.SetPosition( + (self.boundingbox[0] + self.boundingbox[2]-self.boundingbox[0], text_position[1])) + else: + msg = 'Text can only be justified left, right and center.' + raise ValueError(msg) + + text_position = self.actor.GetPosition() + if self.vertical_justification == 'bottom': + self.actor.SetPosition((text_position[0], self.boundingbox[1])) + elif self.vertical_justification == 'middle': + self.actor.SetPosition( + (text_position[0], self.position[1] + (self.boundingbox[3]-self.boundingbox[1])//2)) + elif self.vertical_justification == 'top': + self.actor.SetPosition( + (text_position[0], self.position[1] + self.boundingbox[3]-self.boundingbox[1])) + else: + msg = 'Vertical justification must be: bottom, middle or top.' + raise ValueError(msg) + def update_bounding_box(self): lines = self.message.split("\n") self.boundingbox = [self.position[0], self.position[1], @@ -1087,6 +1115,8 @@ def update_bounding_box(self): self.background.resize( (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1])) + self.update_alignment() + def _set_position(self, position): """Set text actor position. From 67867f675e441c758b57871284a1fa281034e4da Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Thu, 15 Jun 2023 23:56:49 +0530 Subject: [PATCH 06/26] updating bbox on resize --- fury/ui/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fury/ui/core.py b/fury/ui/core.py index 6615d60a6..03b9abde3 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -768,6 +768,8 @@ def resize(self, size): self.actor.SetTextScaleModeToProp() self.actor.SetPosition2(*size) + self.update_bounding_box() + def _get_actors(self): """Get the actors composing this UI component.""" return [self.actor] + self.background.actors From b703f0aecd84ff1ad8cd2db051d7c286800a1002 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Wed, 5 Jul 2023 16:37:09 +0530 Subject: [PATCH 07/26] adding bounding box and updating alignment --- fury/ui/core.py | 129 +++++++++++++++++------------------------------- 1 file changed, 46 insertions(+), 83 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index 03b9abde3..079368dcb 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -734,20 +734,19 @@ def __init__( super(TextBlock2D, self).__init__(position=position) self.scene = None self.have_bg = bool(bg_color) - if size is not None: - self.resize(size) - else: - self.font_size = font_size self.color = color self.background_color = bg_color self.font_family = font_family - self.justification = justification + self._justification = justification self.bold = bold self.italic = italic self.shadow = shadow - self.vertical_justification = vertical_justification + self._vertical_justification = vertical_justification self.message = text - self.update_bounding_box() + if size is not None: + self.resize(size) + else: + self.font_size = font_size def _setup(self): self.actor = TextActor() @@ -763,12 +762,7 @@ def resize(self, size): size : (int, int) Text bounding box size(width, height) in pixels. """ - if self.have_bg: - self.background.resize(size) - self.actor.SetTextScaleModeToProp() - self.actor.SetPosition2(*size) - - self.update_bounding_box() + self.update_bounding_box(size) def _get_actors(self): """Get the actors composing this UI component.""" @@ -781,11 +775,6 @@ def _add_to_scene(self, scene): ---------- scene : scene """ - self.scene = scene - if self.have_bg and not self.actor.GetTextScaleMode(): - size = np.zeros(2) - self.actor.GetSize(scene, size) - self.background.resize(size) scene.add(self.background, self.actor) @property @@ -834,18 +823,7 @@ def font_size(self, size): self.actor.SetTextScaleModeToNone() self.actor.GetTextProperty().SetFontSize(size) - if self.scene is not None and self.have_bg: - bb_size = np.zeros(2) - self.actor.GetSize(self.scene, bb_size) - bg_size = self.background.size - if bb_size[0] > bg_size[0] or bb_size[1] > bg_size[1]: - warn( - 'Font size exceeds background bounding box.' - ' Font Size will not be updated.', - RuntimeWarning, - ) - self.actor.SetTextScaleModeToProp() - self.actor.SetPosition2(*bg_size) + self.update_bounding_box() @property def font_family(self): @@ -885,13 +863,7 @@ def justification(self): str Text justification. """ - justification = self.actor.GetTextProperty().GetJustificationAsString() - if justification == 'Left': - return 'left' - elif justification == 'Centered': - return 'center' - elif justification == 'Right': - return 'right' + return self._justification @justification.setter def justification(self, justification): @@ -903,16 +875,8 @@ def justification(self, justification): Possible values are left, right, center. """ - text_property = self.actor.GetTextProperty() - if justification == 'left': - text_property.SetJustificationToLeft() - elif justification == 'center': - text_property.SetJustificationToCentered() - elif justification == 'right': - text_property.SetJustificationToRight() - else: - msg = 'Text can only be justified left, right and center.' - raise ValueError(msg) + self._justification = justification + self.update_alignment() @property def vertical_justification(self): @@ -924,14 +888,7 @@ def vertical_justification(self): Text vertical justification. """ - text_property = self.actor.GetTextProperty() - vjustification = text_property.GetVerticalJustificationAsString() - if vjustification == 'Bottom': - return 'bottom' - elif vjustification == 'Centered': - return 'middle' - elif vjustification == 'Top': - return 'top' + return self._vertical_justification @vertical_justification.setter def vertical_justification(self, vertical_justification): @@ -943,16 +900,8 @@ def vertical_justification(self, vertical_justification): Possible values are bottom, middle, top. """ - text_property = self.actor.GetTextProperty() - if vertical_justification == 'bottom': - text_property.SetVerticalJustificationToBottom() - elif vertical_justification == 'middle': - text_property.SetVerticalJustificationToCentered() - elif vertical_justification == 'top': - text_property.SetVerticalJustificationToTop() - else: - msg = 'Vertical justification must be: bottom, middle or top.' - raise ValueError(msg) + self._vertical_justification = vertical_justification + self.update_alignment() @property def bold(self): @@ -1083,39 +1032,53 @@ def background_color(self, color): self.background.color = color def update_alignment(self): - + text_property = self.actor.GetTextProperty() text_position = self.actor.GetPosition() + updated_text_position = [0, 0] + if self.justification == 'left': - self.actor.SetPosition((self.boundingbox[0], text_position[1])) + text_property.SetJustificationToLeft() + updated_text_position[0] = self.boundingbox[0] elif self.justification == 'center': - self.actor.SetPosition( - (self.boundingbox[0] + (self.boundingbox[2]-self.boundingbox[0])//2, text_position[1])) + text_property.SetJustificationToCentered() + updated_text_position[0] = self.boundingbox[0] + \ + (self.boundingbox[2]-self.boundingbox[0])//2 elif self.justification == 'right': - self.actor.SetPosition( - (self.boundingbox[0] + self.boundingbox[2]-self.boundingbox[0], text_position[1])) + text_property.SetJustificationToRight() + updated_text_position[0] = self.boundingbox[0] + \ + self.boundingbox[2]-self.boundingbox[0] else: msg = 'Text can only be justified left, right and center.' raise ValueError(msg) - text_position = self.actor.GetPosition() if self.vertical_justification == 'bottom': - self.actor.SetPosition((text_position[0], self.boundingbox[1])) + text_property.SetVerticalJustificationToBottom() + updated_text_position[1] = self.boundingbox[1] elif self.vertical_justification == 'middle': - self.actor.SetPosition( - (text_position[0], self.position[1] + (self.boundingbox[3]-self.boundingbox[1])//2)) + text_property.SetVerticalJustificationToCentered() + updated_text_position[1] = self.position[1] + \ + (self.boundingbox[3]-self.boundingbox[1])//2 elif self.vertical_justification == 'top': - self.actor.SetPosition( - (text_position[0], self.position[1] + self.boundingbox[3]-self.boundingbox[1])) + text_property.SetVerticalJustificationToTop() + updated_text_position[1] = self.position[1] + \ + self.boundingbox[3]-self.boundingbox[1] else: msg = 'Vertical justification must be: bottom, middle or top.' raise ValueError(msg) - def update_bounding_box(self): - lines = self.message.split("\n") - self.boundingbox = [self.position[0], self.position[1], - self.position[0]+len(lines[0])*self.font_size, self.position[1]+len(lines)*self.font_size] - self.background.resize( - (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1])) + self.actor.SetPosition(updated_text_position) + + def update_bounding_box(self, size=None): + if size is not None: + self.boundingbox = [self.position[0], self.position[1], + self.position[0]+size[0], self.position[1]+size[1]] + self.background.resize(size) + else: + lines = self.message.split("\n") + self.boundingbox = [self.position[0], self.position[1], + self.position[0]+len(lines[0])*self.font_size, self.position[1]+len(lines)*self.font_size] + self.background.resize( + (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1])) self.update_alignment() From 1206b482f52ebfd4a5d5329dceba91687052c464 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Wed, 5 Jul 2023 22:00:46 +0530 Subject: [PATCH 08/26] adding auto_font_scale property to scale font automatically --- fury/ui/core.py | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index 079368dcb..c3e51bf76 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -701,6 +701,7 @@ def __init__( color=(1, 1, 1), bg_color=None, position=(0, 0), + auto_font_scale=False ): """Init class instance. @@ -730,6 +731,8 @@ def __init__( Adds text shadow. size : (int, int) Size (width, height) in pixels of the text bounding box. + auto_font_scale : bool, optional + Automatically scale font according to the text bounding box. """ super(TextBlock2D, self).__init__(position=position) self.scene = None @@ -742,6 +745,9 @@ def __init__( self.italic = italic self.shadow = shadow self._vertical_justification = vertical_justification + self.auto_font_scale = auto_font_scale + if self.auto_font_scale: + self.actor.SetTextScaleModeToProp() self.message = text if size is not None: self.resize(size) @@ -820,8 +826,9 @@ def font_size(self, size): size : int Text font size. """ - self.actor.SetTextScaleModeToNone() - self.actor.GetTextProperty().SetFontSize(size) + if not self.auto_font_scale: + self.actor.SetTextScaleModeToNone() + self.actor.GetTextProperty().SetFontSize(size) self.update_bounding_box() @@ -1080,7 +1087,11 @@ def update_bounding_box(self, size=None): self.background.resize( (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1])) - self.update_alignment() + if self.auto_font_scale: + self.actor.SetPosition2( + self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1]) + else: + self.update_alignment() def _set_position(self, position): """Set text actor position. @@ -1095,22 +1106,7 @@ def _set_position(self, position): self.background.position = position def _get_size(self): - if self.have_bg: - return self.background.size - - if not self.actor.GetTextScaleMode(): - if self.scene is not None: - size = np.zeros(2) - self.actor.GetSize(self.scene, size) - return size - else: - warn( - 'TextBlock2D must be added to the scene before ' - 'querying its size while TextScaleMode is set to None.', - RuntimeWarning, - ) - - return self.actor.GetPosition2() + return (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1]) class Button2D(UI): From 2b5e6c2beb3b456c24e89dde8fad4249573928f2 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Thu, 6 Jul 2023 00:09:00 +0530 Subject: [PATCH 09/26] updating the calculation of the bounding box size --- fury/ui/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index c3e51bf76..c7ffec02a 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1082,8 +1082,9 @@ def update_bounding_box(self, size=None): self.background.resize(size) else: lines = self.message.split("\n") + max_length = max(len(line) for line in lines) self.boundingbox = [self.position[0], self.position[1], - self.position[0]+len(lines[0])*self.font_size, self.position[1]+len(lines)*self.font_size] + self.position[0]+max_length*self.font_size, self.position[1]+len(lines)*self.font_size] self.background.resize( (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1])) From 7648da0dbf512e316e80409a6d2f5969f12c08f2 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Thu, 6 Jul 2023 00:10:19 +0530 Subject: [PATCH 10/26] updating tests --- fury/ui/tests/test_core.py | 62 ++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/fury/ui/tests/test_core.py b/fury/ui/tests/test_core.py index f9bcc4acb..9aee9dd82 100644 --- a/fury/ui/tests/test_core.py +++ b/fury/ui/tests/test_core.py @@ -222,6 +222,7 @@ def _check_property(obj, attr, values): _check_property(text_block, 'bold', [True, False]) _check_property(text_block, 'italic', [True, False]) _check_property(text_block, 'shadow', [True, False]) + _check_property(text_block, 'auto_font_scale', [True, False]) _check_property(text_block, 'font_size', range(100)) _check_property(text_block, 'message', ['', 'Hello World', 'Line\nBreak']) _check_property(text_block, 'justification', ['left', 'center', 'right']) @@ -384,57 +385,46 @@ def test_text_block_2d_justification(): def test_text_block_2d_size(): - text_block_1 = ui.TextBlock2D(position=(50, 50), size=(100, 100)) - npt.assert_equal(text_block_1.actor.GetTextScaleMode(), 1) - npt.assert_equal(text_block_1.size, (100, 100)) + text_block_1 = ui.TextBlock2D() + + npt.assert_equal(text_block_1.actor.GetTextScaleMode(), 0) + npt.assert_equal(text_block_1.size, (len("Text Block") * + text_block_1.font_size, text_block_1.font_size)) text_block_1.font_size = 50 + npt.assert_equal(text_block_1.size, (len("Text Block") * + text_block_1.font_size, text_block_1.font_size)) + text_block_1.resize((500, 200)) npt.assert_equal(text_block_1.actor.GetTextScaleMode(), 0) - npt.assert_equal(text_block_1.font_size, 50) + npt.assert_equal(text_block_1.size, (500, 200)) - text_block_2 = ui.TextBlock2D(position=(50, 50), font_size=50) + text_block_2 = ui.TextBlock2D(text="Just Another Text Block",auto_font_scale=True) - npt.assert_equal(text_block_2.actor.GetTextScaleMode(), 0) - npt.assert_equal(text_block_2.font_size, 50) - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always', RuntimeWarning) - text_block_2.size - npt.assert_equal(len(w), 1) - npt.assert_(issubclass(w[-1].category, RuntimeWarning)) - - text_block_2.resize((100, 100)) + npt.assert_equal(text_block_2.actor.GetTextScaleMode(), 1) + npt.assert_equal(text_block_2.size, (len("Just Another Text Block") * + text_block_2.font_size, text_block_2.font_size)) + text_block_2.resize((500, 200)) npt.assert_equal(text_block_2.actor.GetTextScaleMode(), 1) - npt.assert_equal(text_block_2.size, (100, 100)) + npt.assert_equal(text_block_2.size, (500, 200)) text_block_2.position = (100, 100) npt.assert_equal(text_block_2.position, (100, 100)) - window_size = (700, 700) - show_manager = window.ShowManager(size=window_size) + text_block_3 = ui.TextBlock2D(size=(200, 200)) - text_block_3 = ui.TextBlock2D( - text='FURY\nFURY\nFURY\nHello', - position=(150, 100), - bg_color=(1, 0, 0), - color=(0, 1, 0), - size=(100, 100), - ) + npt.assert_equal(text_block_3.actor.GetTextScaleMode(), 0) + npt.assert_equal(text_block_3.size, (200, 200)) + + text_block_3.resize((500, 200)) + npt.assert_equal(text_block_3.actor.GetTextScaleMode(), 0) + npt.assert_equal(text_block_3.size, (500, 200)) - show_manager.scene.add(text_block_3) - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always', RuntimeWarning) - text_block_3.font_size = 100 - npt.assert_equal(len(w), 1) - npt.assert_(issubclass(w[-1].category, RuntimeWarning)) - npt.assert_equal(text_block_3.size, (100, 100)) - - text_block_3.font_size = 12 - npt.assert_equal(len(w), 1) - npt.assert_(issubclass(w[-1].category, RuntimeWarning)) - npt.assert_equal(text_block_3.font_size, 12) + text_block_3.message = "Hey Trying\nBig Text" + npt.assert_equal(text_block_3.size, (10 * + text_block_3.font_size, 2 * text_block_3.font_size)) # test_ui_button_panel(recording=True) From 2e268d393dc40f677c331fff326c6b0f3993d85a Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Thu, 6 Jul 2023 00:16:04 +0530 Subject: [PATCH 11/26] adding docs --- fury/ui/core.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fury/ui/core.py b/fury/ui/core.py index c7ffec02a..f5ebf8be9 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1039,6 +1039,9 @@ def background_color(self, color): self.background.color = color def update_alignment(self): + """Update Text Alignment. + + """ text_property = self.actor.GetTextProperty() text_position = self.actor.GetPosition() updated_text_position = [0, 0] @@ -1076,6 +1079,15 @@ def update_alignment(self): self.actor.SetPosition(updated_text_position) def update_bounding_box(self, size=None): + """Update Text Bounding Box. + + Parameters + ---------- + size : (int, int) or None + If None, calculates bounding box. + Otherwise, uses the given size. + + """ if size is not None: self.boundingbox = [self.position[0], self.position[1], self.position[0]+size[0], self.position[1]+size[1]] From 3cae30e53e244fc6422f1771e71dacb0f44102e5 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Thu, 20 Jul 2023 17:50:45 +0530 Subject: [PATCH 12/26] updating aligment calculation --- fury/ui/core.py | 9 +++------ fury/ui/elements.py | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index f5ebf8be9..c338753a7 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1043,7 +1043,6 @@ def update_alignment(self): """ text_property = self.actor.GetTextProperty() - text_position = self.actor.GetPosition() updated_text_position = [0, 0] if self.justification == 'left': @@ -1055,8 +1054,7 @@ def update_alignment(self): (self.boundingbox[2]-self.boundingbox[0])//2 elif self.justification == 'right': text_property.SetJustificationToRight() - updated_text_position[0] = self.boundingbox[0] + \ - self.boundingbox[2]-self.boundingbox[0] + updated_text_position[0] = self.boundingbox[2] else: msg = 'Text can only be justified left, right and center.' raise ValueError(msg) @@ -1066,12 +1064,11 @@ def update_alignment(self): updated_text_position[1] = self.boundingbox[1] elif self.vertical_justification == 'middle': text_property.SetVerticalJustificationToCentered() - updated_text_position[1] = self.position[1] + \ + updated_text_position[1] = self.boundingbox[1] + \ (self.boundingbox[3]-self.boundingbox[1])//2 elif self.vertical_justification == 'top': text_property.SetVerticalJustificationToTop() - updated_text_position[1] = self.position[1] + \ - self.boundingbox[3]-self.boundingbox[1] + updated_text_position[1] = self.boundingbox[3] else: msg = 'Vertical justification must be: bottom, middle or top.' raise ValueError(msg) diff --git a/fury/ui/elements.py b/fury/ui/elements.py index debda4dd5..799a2f59f 100644 --- a/fury/ui/elements.py +++ b/fury/ui/elements.py @@ -131,7 +131,7 @@ def _setup(self): Create the TextBlock2D component used for the textbox. """ - self.text = TextBlock2D() + self.text = TextBlock2D(auto_font_scale=1) # Add default events listener for this UI component. self.text.on_left_mouse_button_pressed = self.left_button_press From c95b2492190d191ed6ea7a63cf161ce11a8a83d8 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Thu, 20 Jul 2023 18:19:06 +0530 Subject: [PATCH 13/26] avoiding repetative calculation --- fury/ui/core.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index c338753a7..b8d4c268f 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -749,10 +749,9 @@ def __init__( if self.auto_font_scale: self.actor.SetTextScaleModeToProp() self.message = text + self.font_size = font_size if size is not None: self.resize(size) - else: - self.font_size = font_size def _setup(self): self.actor = TextActor() @@ -1075,6 +1074,11 @@ def update_alignment(self): self.actor.SetPosition(updated_text_position) + def cal_size_from_message(self): + lines = self.message.split("\n") + max_length = max(len(line) for line in lines) + return [max_length*self.font_size, len(lines)*self.font_size] + def update_bounding_box(self, size=None): """Update Text Bounding Box. @@ -1085,17 +1089,12 @@ def update_bounding_box(self, size=None): Otherwise, uses the given size. """ - if size is not None: - self.boundingbox = [self.position[0], self.position[1], - self.position[0]+size[0], self.position[1]+size[1]] - self.background.resize(size) - else: - lines = self.message.split("\n") - max_length = max(len(line) for line in lines) - self.boundingbox = [self.position[0], self.position[1], - self.position[0]+max_length*self.font_size, self.position[1]+len(lines)*self.font_size] - self.background.resize( - (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1])) + if size is None: + size = self.cal_size_from_message() + + self.boundingbox = [self.position[0], self.position[1], + self.position[0]+size[0], self.position[1]+size[1]] + self.background.resize(size) if self.auto_font_scale: self.actor.SetPosition2( From acb3ad45c6a8ef7ab03ad99fb34ac6cac9e1cb4a Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Thu, 20 Jul 2023 20:59:25 +0530 Subject: [PATCH 14/26] removing test changes --- fury/ui/elements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fury/ui/elements.py b/fury/ui/elements.py index 799a2f59f..debda4dd5 100644 --- a/fury/ui/elements.py +++ b/fury/ui/elements.py @@ -131,7 +131,7 @@ def _setup(self): Create the TextBlock2D component used for the textbox. """ - self.text = TextBlock2D(auto_font_scale=1) + self.text = TextBlock2D() # Add default events listener for this UI component. self.text.on_left_mouse_button_pressed = self.left_button_press From 3523a0c4ebcb68fa6a48c413dc8040c133d70827 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Fri, 21 Jul 2023 10:04:11 +0530 Subject: [PATCH 15/26] adding dynamic_bbox property --- fury/ui/core.py | 14 +++++++++++--- fury/ui/elements.py | 9 +++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index b8d4c268f..6d1bcf83d 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -701,7 +701,8 @@ def __init__( color=(1, 1, 1), bg_color=None, position=(0, 0), - auto_font_scale=False + auto_font_scale=False, + dynamic_bbox=False ): """Init class instance. @@ -733,6 +734,8 @@ def __init__( Size (width, height) in pixels of the text bounding box. auto_font_scale : bool, optional Automatically scale font according to the text bounding box. + dynamic_bbox : bool, optional + Automatically reisize the bounding box according to the content. """ super(TextBlock2D, self).__init__(position=position) self.scene = None @@ -748,10 +751,13 @@ def __init__( self.auto_font_scale = auto_font_scale if self.auto_font_scale: self.actor.SetTextScaleModeToProp() + self.dynamic_bbox = dynamic_bbox self.message = text self.font_size = font_size if size is not None: self.resize(size) + elif not self.dynamic_bbox: + raise ValueError("TextBlock size is required as it is not dynamic.") def _setup(self): self.actor = TextActor() @@ -803,7 +809,8 @@ def message(self, text): The message to be set. """ self.actor.SetInput(text) - self.update_bounding_box() + if self.dynamic_bbox: + self.update_bounding_box() @property def font_size(self): @@ -829,7 +836,8 @@ def font_size(self, size): self.actor.SetTextScaleModeToNone() self.actor.GetTextProperty().SetFontSize(size) - self.update_bounding_box() + if self.dynamic_bbox: + self.update_bounding_box() @property def font_family(self): diff --git a/fury/ui/elements.py b/fury/ui/elements.py index debda4dd5..fcc119381 100644 --- a/fury/ui/elements.py +++ b/fury/ui/elements.py @@ -131,7 +131,7 @@ def _setup(self): Create the TextBlock2D component used for the textbox. """ - self.text = TextBlock2D() + self.text = TextBlock2D(dynamic_bbox=True) # Add default events listener for this UI component. self.text.on_left_mouse_button_pressed = self.left_button_press @@ -1445,7 +1445,8 @@ def _setup(self): self.handle.color = self.default_color # Slider Text - self.text = TextBlock2D(justification='center', vertical_justification='middle') + self.text = TextBlock2D(justification='center', + vertical_justification='middle', size=(0, 0)) # Add default events listener for this UI component. self.track.on_left_mouse_button_pressed = self.track_click_callback @@ -2908,7 +2909,7 @@ def _setup(self): """ self.background = Rectangle2D() self.textblock = TextBlock2D( - justification='left', vertical_justification='middle' + justification='left', vertical_justification='middle', size=(0, 0) ) # Add default events listener for this UI component. @@ -3554,7 +3555,7 @@ def mode_selector(i_ren, _obj, btn): self.canvas.add_element(self.mode_panel, (0, -mode_panel_size[1])) self.mode_text = TextBlock2D( - text='Select appropriate drawing mode using below icon' + text='Select appropriate drawing mode using below icon', size=(0, 0) ) self.canvas.add_element(self.mode_text, (0.0, 1.0)) From 537a3f044d58e8c3b296f70d5a66e9b8c870a409 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Fri, 21 Jul 2023 10:09:41 +0530 Subject: [PATCH 16/26] reseting size to zero --- fury/ui/core.py | 3 ++- fury/ui/elements.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index 6d1bcf83d..50deda52f 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -757,7 +757,8 @@ def __init__( if size is not None: self.resize(size) elif not self.dynamic_bbox: - raise ValueError("TextBlock size is required as it is not dynamic.") + # raise ValueError("TextBlock size is required as it is not dynamic.") + self.resize((0, 0)) def _setup(self): self.actor = TextActor() diff --git a/fury/ui/elements.py b/fury/ui/elements.py index fcc119381..46b1b9993 100644 --- a/fury/ui/elements.py +++ b/fury/ui/elements.py @@ -1446,7 +1446,7 @@ def _setup(self): # Slider Text self.text = TextBlock2D(justification='center', - vertical_justification='middle', size=(0, 0)) + vertical_justification='middle') # Add default events listener for this UI component. self.track.on_left_mouse_button_pressed = self.track_click_callback @@ -2909,7 +2909,7 @@ def _setup(self): """ self.background = Rectangle2D() self.textblock = TextBlock2D( - justification='left', vertical_justification='middle', size=(0, 0) + justification='left', vertical_justification='middle' ) # Add default events listener for this UI component. @@ -3555,7 +3555,7 @@ def mode_selector(i_ren, _obj, btn): self.canvas.add_element(self.mode_panel, (0, -mode_panel_size[1])) self.mode_text = TextBlock2D( - text='Select appropriate drawing mode using below icon', size=(0, 0) + text='Select appropriate drawing mode using below icon' ) self.canvas.add_element(self.mode_text, (0.0, 1.0)) From 6cf858dae1d15593cea94332895911947b29537b Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Fri, 21 Jul 2023 10:31:24 +0530 Subject: [PATCH 17/26] updating tests --- fury/ui/tests/test_core.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/fury/ui/tests/test_core.py b/fury/ui/tests/test_core.py index 9aee9dd82..6adc1eb53 100644 --- a/fury/ui/tests/test_core.py +++ b/fury/ui/tests/test_core.py @@ -386,11 +386,23 @@ def test_text_block_2d_justification(): def test_text_block_2d_size(): - text_block_1 = ui.TextBlock2D() + text_block_0 = ui.TextBlock2D() + + npt.assert_equal(text_block_0.actor.GetTextScaleMode(), 0) + npt.assert_equal(text_block_0.size, (0, 0)) + + text_block_0.font_size = 50 + npt.assert_equal(text_block_0.size, (0, 0)) + + text_block_0.resize((500, 200)) + npt.assert_equal(text_block_0.actor.GetTextScaleMode(), 0) + npt.assert_equal(text_block_0.size, (500, 200)) + + text_block_1 = ui.TextBlock2D(dynamic_bbox=True) npt.assert_equal(text_block_1.actor.GetTextScaleMode(), 0) - npt.assert_equal(text_block_1.size, (len("Text Block") * - text_block_1.font_size, text_block_1.font_size)) + npt.assert_equal(text_block_1.size, ((len("Text Block") * + text_block_1.font_size, text_block_1.font_size))) text_block_1.font_size = 50 npt.assert_equal(text_block_1.size, (len("Text Block") * @@ -400,7 +412,8 @@ def test_text_block_2d_size(): npt.assert_equal(text_block_1.actor.GetTextScaleMode(), 0) npt.assert_equal(text_block_1.size, (500, 200)) - text_block_2 = ui.TextBlock2D(text="Just Another Text Block",auto_font_scale=True) + text_block_2 = ui.TextBlock2D( + text="Just Another Text Block", dynamic_bbox=True, auto_font_scale=True) npt.assert_equal(text_block_2.actor.GetTextScaleMode(), 1) npt.assert_equal(text_block_2.size, (len("Just Another Text Block") * @@ -423,8 +436,7 @@ def test_text_block_2d_size(): npt.assert_equal(text_block_3.size, (500, 200)) text_block_3.message = "Hey Trying\nBig Text" - npt.assert_equal(text_block_3.size, (10 * - text_block_3.font_size, 2 * text_block_3.font_size)) + npt.assert_equal(text_block_3.size, (500, 200)) # test_ui_button_panel(recording=True) From 5c9bf87c67059ea6ff8251d875ef8cf9de44f384 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Sat, 22 Jul 2023 22:13:01 +0530 Subject: [PATCH 18/26] updating docs --- fury/ui/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index 50deda52f..d03a4688e 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1048,7 +1048,6 @@ def background_color(self, color): def update_alignment(self): """Update Text Alignment. - """ text_property = self.actor.GetTextProperty() updated_text_position = [0, 0] @@ -1084,6 +1083,7 @@ def update_alignment(self): self.actor.SetPosition(updated_text_position) def cal_size_from_message(self): + "Calculate size of background according to the message it contains." lines = self.message.split("\n") max_length = max(len(line) for line in lines) return [max_length*self.font_size, len(lines)*self.font_size] From 0f1d6c341232d7ffdce08a41b8ffeab4356d543b Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Mon, 24 Jul 2023 20:08:27 +0530 Subject: [PATCH 19/26] updating docs and initializing param --- fury/ui/core.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index d03a4688e..d9193325c 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -685,6 +685,10 @@ class TextBlock2D(UI): Adds text shadow. size : (int, int) Size (width, height) in pixels of the text bounding box. + auto_font_scale : bool + Automatically scale font according to the text bounding box. + dynamic_bbox : bool + Automatically resize the bounding box according to the content. """ def __init__( @@ -735,8 +739,9 @@ def __init__( auto_font_scale : bool, optional Automatically scale font according to the text bounding box. dynamic_bbox : bool, optional - Automatically reisize the bounding box according to the content. + Automatically resize the bounding box according to the content. """ + self.boundingbox = [0, 0, 0, 0] super(TextBlock2D, self).__init__(position=position) self.scene = None self.have_bg = bool(bg_color) From 09189f1fbeb4beb27b3667e07aa6b9b196b28c92 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Wed, 26 Jul 2023 23:03:44 +0530 Subject: [PATCH 20/26] updating font size test --- fury/ui/tests/test_containers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fury/ui/tests/test_containers.py b/fury/ui/tests/test_containers.py index e1b56306f..0f18d9853 100644 --- a/fury/ui/tests/test_containers.py +++ b/fury/ui/tests/test_containers.py @@ -285,9 +285,9 @@ def test_ui_tab_ui(interactive=False): npt.assert_equal(tab_ui.tabs[1].title_color, (.0, 1., .0)) npt.assert_equal(tab_ui.tabs[2].title_color, (.0, .0, 1.)) - npt.assert_equal(tab_ui.tabs[0].title_font_size, 12) - npt.assert_equal(tab_ui.tabs[1].title_font_size, 12) - npt.assert_equal(tab_ui.tabs[2].title_font_size, 12) + npt.assert_equal(tab_ui.tabs[0].title_font_size, 18) + npt.assert_equal(tab_ui.tabs[1].title_font_size, 18) + npt.assert_equal(tab_ui.tabs[2].title_font_size, 18) tab_ui.tabs[0].title_font_size = 10 tab_ui.tabs[1].title_font_size = 20 From 4d017009cc47b28540bb24b2da8dfca676c657a3 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Wed, 26 Jul 2023 23:24:31 +0530 Subject: [PATCH 21/26] updating case checking --- fury/ui/core.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index d9193325c..ae8e978e2 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1057,28 +1057,28 @@ def update_alignment(self): text_property = self.actor.GetTextProperty() updated_text_position = [0, 0] - if self.justification == 'left': + if self.justification.lower() == 'left': text_property.SetJustificationToLeft() updated_text_position[0] = self.boundingbox[0] - elif self.justification == 'center': + elif self.justification.lower() == 'center': text_property.SetJustificationToCentered() updated_text_position[0] = self.boundingbox[0] + \ (self.boundingbox[2]-self.boundingbox[0])//2 - elif self.justification == 'right': + elif self.justification.lower() == 'right': text_property.SetJustificationToRight() updated_text_position[0] = self.boundingbox[2] else: msg = 'Text can only be justified left, right and center.' raise ValueError(msg) - if self.vertical_justification == 'bottom': + if self.vertical_justification.lower() == 'bottom': text_property.SetVerticalJustificationToBottom() updated_text_position[1] = self.boundingbox[1] - elif self.vertical_justification == 'middle': + elif self.vertical_justification.lower() == 'middle': text_property.SetVerticalJustificationToCentered() updated_text_position[1] = self.boundingbox[1] + \ (self.boundingbox[3]-self.boundingbox[1])//2 - elif self.vertical_justification == 'top': + elif self.vertical_justification.lower() == 'top': text_property.SetVerticalJustificationToTop() updated_text_position[1] = self.boundingbox[3] else: From 483ea6442492a765371226562537a0df8a750bec Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Sat, 29 Jul 2023 00:31:51 +0530 Subject: [PATCH 22/26] updating size value --- fury/ui/core.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index ae8e978e2..90f90bb98 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1129,7 +1129,11 @@ def _set_position(self, position): self.background.position = position def _get_size(self): - return (self.boundingbox[2]-self.boundingbox[0], self.boundingbox[3]-self.boundingbox[1]) + bb_size = (self.boundingbox[2]-self.boundingbox[0], + self.boundingbox[3]-self.boundingbox[1]) + if self.dynamic_bbox or self.auto_font_scale or sum(bb_size): + return bb_size + return self.cal_size_from_message() class Button2D(UI): From 9b23d2d68b0ce726b50771047257419ef9b953a6 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Sat, 29 Jul 2023 00:37:50 +0530 Subject: [PATCH 23/26] updating helper --- fury/ui/helpers.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/fury/ui/helpers.py b/fury/ui/helpers.py index b3cd8fd2f..db4e541b5 100644 --- a/fury/ui/helpers.py +++ b/fury/ui/helpers.py @@ -51,7 +51,6 @@ def wrap_overflow(textblock, wrap_width, side='right'): """ original_str = textblock.message str_copy = textblock.message - prev_bg = textblock.have_bg wrap_idxs = [] wrap_idx = check_overflow(textblock, wrap_width, '', side) @@ -72,7 +71,6 @@ def wrap_overflow(textblock, wrap_width, side='right'): original_str = original_str[:idx] + '\n' + original_str[idx:] textblock.message = original_str - textblock.have_bg = prev_bg return textblock.message @@ -99,26 +97,23 @@ def check_overflow(textblock, width, overflow_postfix='', side='right'): start_ptr = 0 mid_ptr = 0 end_ptr = len(original_str) - prev_bg = textblock.have_bg - textblock.have_bg = False if side == 'left': original_str = original_str[::-1] - if textblock.size[0] <= width: - textblock.have_bg = prev_bg + if textblock.cal_size_from_message()[0] <= width: return 0 while start_ptr < end_ptr: mid_ptr = (start_ptr + end_ptr) // 2 textblock.message = original_str[:mid_ptr] + overflow_postfix - if textblock.size[0] < width: + if textblock.cal_size_from_message()[0] < width: start_ptr = mid_ptr - elif textblock.size[0] > width: + elif textblock.cal_size_from_message()[0] > width: end_ptr = mid_ptr - if mid_ptr == (start_ptr + end_ptr) // 2 or textblock.size[0] == width: + if mid_ptr == (start_ptr + end_ptr) // 2 or textblock.cal_size_from_message()[0] == width: if side == 'left': textblock.message = textblock.message[::-1] return mid_ptr From 0f47c833e205116c2617e573b701bb8a2130d7be Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Sat, 29 Jul 2023 00:38:14 +0530 Subject: [PATCH 24/26] updating helper tests --- fury/ui/tests/test_helpers.py | 63 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/fury/ui/tests/test_helpers.py b/fury/ui/tests/test_helpers.py index 9917cac57..3584ee48e 100644 --- a/fury/ui/tests/test_helpers.py +++ b/fury/ui/tests/test_helpers.py @@ -13,89 +13,88 @@ def test_clip_overflow(): - text = ui.TextBlock2D(text='', position=(50, 50), color=(1, 0, 0)) - rectangle = ui.Rectangle2D(position=(50, 50), size=(100, 50)) + text = ui.TextBlock2D(text='', position=(50, 50), color=(1, 0, 0), size=(100, 50)) sm = window.ShowManager() - sm.scene.add(rectangle, text) + sm.scene.add(text) text.message = 'Hello' - clip_overflow(text, rectangle.size[0]) + clip_overflow(text, text.size[0]) npt.assert_equal('Hello', text.message) text.message = 'Hello wassup' - clip_overflow(text, rectangle.size[0]) - npt.assert_equal('Hello was...', text.message) + clip_overflow(text, text.size[0]) + npt.assert_equal('He...', text.message) text.message = 'A very very long message to clip text overflow' - clip_overflow(text, rectangle.size[0]) - npt.assert_equal('A very ve...', text.message) + clip_overflow(text, text.size[0]) + npt.assert_equal('A ...', text.message) text.message = 'Hello' - clip_overflow(text, rectangle.size[0], 'left') + clip_overflow(text, text.size[0], 'left') npt.assert_equal('Hello', text.message) text.message = 'Hello wassup' - clip_overflow(text, rectangle.size[0], 'left') - npt.assert_equal('...lo wassup', text.message) + clip_overflow(text, text.size[0], 'left') + npt.assert_equal('...up', text.message) text.message = 'A very very long message to clip text overflow' - clip_overflow(text, rectangle.size[0], 'left') - npt.assert_equal('... overflow', text.message) + clip_overflow(text, text.size[0], 'left') + npt.assert_equal('...ow', text.message) text.message = 'A very very long message to clip text overflow' - clip_overflow(text, rectangle.size[0], 'LeFT') - npt.assert_equal('... overflow', text.message) + clip_overflow(text, text.size[0], 'LeFT') + npt.assert_equal('...ow', text.message) text.message = 'A very very long message to clip text overflow' - clip_overflow(text, rectangle.size[0], 'RigHT') - npt.assert_equal('A very ve...', text.message) + clip_overflow(text, text.size[0], 'RigHT') + npt.assert_equal('A ...', text.message) - npt.assert_raises(ValueError, clip_overflow, text, rectangle.size[0], 'middle') + npt.assert_raises(ValueError, clip_overflow, text, text.size[0], 'middle') def test_wrap_overflow(): - text = ui.TextBlock2D(text='', position=(50, 50), color=(1, 0, 0)) - rectangle = ui.Rectangle2D(position=(50, 50), size=(100, 50)) + text = ui.TextBlock2D(text='', position=(50, 50), color=(1, 0, 0), size=(100, 50)) sm = window.ShowManager() - sm.scene.add(rectangle, text) + sm.scene.add(text) text.message = 'Hello' - wrap_overflow(text, rectangle.size[0]) + wrap_overflow(text, text.size[0]) npt.assert_equal('Hello', text.message) text.message = 'Hello wassup' - wrap_overflow(text, rectangle.size[0]) - npt.assert_equal('Hello wassu\np', text.message) + wrap_overflow(text, text.size[0]) + npt.assert_equal('Hello\n wass\nup', text.message) text.message = 'A very very long message to clip text overflow' - wrap_overflow(text, rectangle.size[0]) + wrap_overflow(text, text.size[0]) npt.assert_equal( - 'A very very\n long mess\nage to clip \ntext overflo\nw', text.message + 'A ver\ny ver\ny lon\ng mes\nsage \nto cl\nip te\nxt ov\nerflo\nw', text.message ) text.message = 'A very very long message to clip text overflow' wrap_overflow(text, 0) npt.assert_equal(text.message, '') + text.message = 'A very very long message to clip text overflow' wrap_overflow(text, -2 * text.size[0]) npt.assert_equal(text.message, '') def test_check_overflow(): - text = ui.TextBlock2D(text='', position=(50, 50), color=(1, 0, 0)) - rectangle = ui.Rectangle2D(position=(50, 50), size=(100, 50)) + text = ui.TextBlock2D(text='', position=(50, 50), + color=(1, 0, 0), size=(100, 50), bg_color=(.5, .5, .5)) sm = window.ShowManager() - sm.scene.add(rectangle, text) + sm.scene.add(text) text.message = 'A very very long message to clip text overflow' - overflow_idx = check_overflow(text, rectangle.size[0], '~') + overflow_idx = check_overflow(text, 100, '~') - npt.assert_equal(10, overflow_idx) - npt.assert_equal('A very ver~', text.message) + npt.assert_equal(4, overflow_idx) + npt.assert_equal('A ve~', text.message) def test_cal_bounding_box_2d(): From aa566574ec22010ea6b22d53a409b5af7d0aa6ad Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Sat, 29 Jul 2023 00:43:43 +0530 Subject: [PATCH 25/26] updating size for tests --- fury/ui/tests/test_core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fury/ui/tests/test_core.py b/fury/ui/tests/test_core.py index 6adc1eb53..859b0b04b 100644 --- a/fury/ui/tests/test_core.py +++ b/fury/ui/tests/test_core.py @@ -389,10 +389,10 @@ def test_text_block_2d_size(): text_block_0 = ui.TextBlock2D() npt.assert_equal(text_block_0.actor.GetTextScaleMode(), 0) - npt.assert_equal(text_block_0.size, (0, 0)) + npt.assert_equal(text_block_0.size, (180,18)) text_block_0.font_size = 50 - npt.assert_equal(text_block_0.size, (0, 0)) + npt.assert_equal(text_block_0.size, (500, 50)) text_block_0.resize((500, 200)) npt.assert_equal(text_block_0.actor.GetTextScaleMode(), 0) From 0ecdc84e96dd564dcb98bc1f547fc49d44fe5e48 Mon Sep 17 00:00:00 2001 From: Praneeth Shetty Date: Sat, 29 Jul 2023 19:38:41 +0530 Subject: [PATCH 26/26] removing attributes --- fury/ui/core.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index 90f90bb98..d9de2f416 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -685,10 +685,6 @@ class TextBlock2D(UI): Adds text shadow. size : (int, int) Size (width, height) in pixels of the text bounding box. - auto_font_scale : bool - Automatically scale font according to the text bounding box. - dynamic_bbox : bool - Automatically resize the bounding box according to the content. """ def __init__(