Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 75 additions & 13 deletions fastplotlib/graphics/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ def __init__(
self,
text: str,
position: Tuple[int] = (0, 0, 0),
size: int = 10,
size: int = 14,
face_color: Union[str, np.ndarray] = "w",
outline_color: Union[str, np.ndarray] = "w",
outline_thickness=0,
name: str = None,
*args,
**kwargs
):
"""
Create a text Graphic
Expand Down Expand Up @@ -43,11 +44,16 @@ def __init__(
name of graphic, passed to Graphic

"""
super(TextGraphic, self).__init__(*args, **kwargs)

super(TextGraphic, self).__init__(name=name)
self._text = text

world_object = pygfx.Text(
pygfx.TextGeometry(text=str(text), font_size=size, screen_space=False),
pygfx.TextGeometry(text=str(text),
Comment thread
clewis7 marked this conversation as resolved.
Outdated
font_size=size,
screen_space=True,
Comment thread
clewis7 marked this conversation as resolved.
Outdated
anchor="middle-center"
Comment thread
clewis7 marked this conversation as resolved.
Outdated
),
pygfx.TextMaterial(
Comment thread
kushalkolar marked this conversation as resolved.
color=face_color,
outline_color=outline_color,
Expand All @@ -59,22 +65,78 @@ def __init__(

self.world_object.position = position

self.name = None
@property
def text(self):
"""Returns the text of this graphic."""
return self._text

def update_text(self, text: str):
self.world_object.geometry.set_text(text)
@text.setter
def text(self, text: str):
"""Set the text of this graphic."""
if not isinstance(text, str):
raise ValueError("Text must be of type str.")

self._text = text
self.world_object.geometry.set_text(self._text)

@property
def text_size(self):
"""Returns the text size of this graphic."""
return self.world_object.geometry.font_size

@text_size.setter
def text_size(self, size: Union[int, float]):
"""Set the text size of this graphic."""
if not (isinstance(size, int) or isinstance(size, float)):
raise ValueError("Text size must be of type int or float")

def update_size(self, size: int):
self.world_object.geometry.font_size = size

def update_face_color(self, color: Union[str, np.ndarray]):
@property
def face_color(self):
"""Returns the face color of this graphic."""
return self.world_object.material.color

@face_color.setter
def face_color(self, color: Union[str, np.ndarray]):
"""Set the face color of this graphic."""
if not (isinstance(color, str) or isinstance(color, np.ndarray)):
Comment thread
clewis7 marked this conversation as resolved.
raise ValueError("Face color must be of type str or np.ndarray")

self.world_object.material.color = color

def update_outline_size(self, size: int):
@property
def outline_size(self):
"""Returns the outline size of this graphic."""
return self.world_object.material.outline_thickness

@outline_size.setter
def outline_size(self, size: Union[int, float]):
"""Set the outline size of this text graphic."""
if not (isinstance(size, int) or isinstance(size, float)):
raise ValueError("Outline size must be of type int or float")

self.world_object.material.outline_thickness = size

def update_outline_color(self, color: Union[str, np.ndarray]):
@property
def outline_color(self):
"""Returns the outline color of this graphic."""
return self.world_object.material.outline_color

@outline_color.setter
def outline_color(self, color: Union[str, np.ndarray]):
Comment thread
clewis7 marked this conversation as resolved.
"""Set the outline color of this graphic"""
if not (isinstance(color, str) or isinstance(color, np.ndarray)):
raise ValueError("Outline color must be of type str or np.ndarray")

self.world_object.material.outline_color = color

def update_position(self, pos: Tuple[int, int, int]):
self.world_object.position.set(*pos)
@property
def text_position(self):
Comment thread
clewis7 marked this conversation as resolved.
Outdated
"""Returns the position of this graphic."""
return self.world_object.local.position

@text_position.setter
def text_position(self, pos: Tuple[int, int, int]):
"""Set the position of this graphic."""
self.world_object.local.position = pos
4 changes: 2 additions & 2 deletions fastplotlib/layouts/_subplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ def set_title(self, text: Any):

text = str(text)
if self._title_graphic is not None:
self._title_graphic.update_text(text)
self._title_graphic.text = text
else:
tg = TextGraphic(text)
tg = TextGraphic(text=text, size=18)
self._title_graphic = tg

self.docks["top"].size = 35
Expand Down