From 206ec68122bec9dfe9a3a52e175ec1dc35cedb39 Mon Sep 17 00:00:00 2001 From: Dan Lawrence Date: Sun, 23 Apr 2023 18:25:35 +0100 Subject: [PATCH] Expand tool tips to almost every element. --- docs/source/theme_reference/theme_button.rst | 2 +- .../theme_reference/theme_drop_down_menu.rst | 1 + .../theme_horizontal_scroll_bar.rst | 1 + .../theme_horizontal_slider.rst | 1 + docs/source/theme_reference/theme_label.rst | 1 + docs/source/theme_reference/theme_panel.rst | 1 + .../theme_reference/theme_progress_bar.rst | 1 + .../theme_screen_space_health_bar.rst | 1 + .../theme_reference/theme_selection_list.rst | 1 + .../theme_reference/theme_status_bar.rst | 1 + .../source/theme_reference/theme_text_box.rst | 1 + .../theme_reference/theme_text_entry_box.rst | 1 + .../theme_reference/theme_text_entry_line.rst | 1 + docs/source/theme_reference/theme_tooltip.rst | 1 - .../theme_vertical_scroll_bar.rst | 1 + .../theme_world_space_health_bar.rst | 1 + .../core/interfaces/manager_interface.py | 2 + pygame_gui/core/ui_element.py | 55 ++++++++++++++++--- pygame_gui/elements/ui_button.py | 48 ++-------------- pygame_gui/elements/ui_drop_down_menu.py | 5 ++ .../elements/ui_horizontal_scroll_bar.py | 5 ++ pygame_gui/elements/ui_horizontal_slider.py | 5 ++ pygame_gui/elements/ui_image.py | 6 ++ pygame_gui/elements/ui_label.py | 5 ++ pygame_gui/elements/ui_panel.py | 5 ++ pygame_gui/elements/ui_selection_list.py | 5 ++ pygame_gui/elements/ui_status_bar.py | 5 ++ pygame_gui/elements/ui_text_box.py | 5 ++ pygame_gui/elements/ui_text_entry_line.py | 5 ++ pygame_gui/elements/ui_tool_tip.py | 5 ++ pygame_gui/elements/ui_vertical_scroll_bar.py | 5 ++ pygame_gui/elements/ui_window.py | 5 ++ pygame_gui/ui_manager.py | 4 +- 33 files changed, 138 insertions(+), 54 deletions(-) diff --git a/docs/source/theme_reference/theme_button.rst b/docs/source/theme_reference/theme_button.rst index f054855a..99278e3c 100644 --- a/docs/source/theme_reference/theme_button.rst +++ b/docs/source/theme_reference/theme_button.rst @@ -125,7 +125,7 @@ Misc - "**shape_corner_radius**" - Only used if our shape is 'rounded_rectangle'. It sets the radius used for the rounded corners. - "**border_width**" - the width in pixels of the border around the button. Defaults to 1. - "**shadow_width**" - the width in pixels of the shadow behind the button. Defaults to 2. - - "**tool_tip_delay**" - time in seconds before a the buttons tool sip (if it has one) will appear. Default is "1.0". + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". - "**text_horiz_alignment**" - Set to "left", "right" or "center". Controls the horizontal placement of the button text, if this button has any text. Default is "center". - "**text_vert_alignment**" - Set to "top", "bottom or "center". Controls the vertical placement of the button text, if this button has any text. Default is "center". - "**text_horiz_alignment_padding**" - If horizontal alignment is set to 'left' or 'right' this value will control the buffer between the edge of the button and where we start placing the text. Default is "1". diff --git a/docs/source/theme_reference/theme_drop_down_menu.rst b/docs/source/theme_reference/theme_drop_down_menu.rst index efe4c36c..dd47fb76 100644 --- a/docs/source/theme_reference/theme_drop_down_menu.rst +++ b/docs/source/theme_reference/theme_drop_down_menu.rst @@ -40,6 +40,7 @@ Misc - "**border_width**" - the width in pixels of the border around the drop down menu. Defaults to "1". - "**shadow_width**" - the width in pixels of the shadow behind the button. Defaults to "1". - "**open_button_width**" - the width of the open/close button on the right hand side of the drop down. Defaults to "20" (pixels). Set it to "0" to remove the open/close button. + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Sub-elements -------------- diff --git a/docs/source/theme_reference/theme_horizontal_scroll_bar.rst b/docs/source/theme_reference/theme_horizontal_scroll_bar.rst index 54a9a408..85f07ddc 100644 --- a/docs/source/theme_reference/theme_horizontal_scroll_bar.rst +++ b/docs/source/theme_reference/theme_horizontal_scroll_bar.rst @@ -32,6 +32,7 @@ Misc - "**border_width**" - the width in pixels of the border around the bar. Defaults to 1. - "**shadow_width**" - the width in pixels of the shadow behind the bar. Defaults to 1. - "**enable_arrow_buttons**" - Enables or disables the arrow buttons for the scroll bar. "1" is enabled, "0" is disabled. Defaults to "1". + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Sub-elements -------------- diff --git a/docs/source/theme_reference/theme_horizontal_slider.rst b/docs/source/theme_reference/theme_horizontal_slider.rst index a2b92bf1..94993517 100644 --- a/docs/source/theme_reference/theme_horizontal_slider.rst +++ b/docs/source/theme_reference/theme_horizontal_slider.rst @@ -39,6 +39,7 @@ Misc - "**shadow_width**" - the width in pixels of the shadow behind the slider. Defaults to 1. - "**enable_arrow_buttons**" - Enables or disables the arrow buttons for the slider. "1" is enabled, "0" is disabled. Defaults to "1". - "**sliding_button_width**" - Sets the width of the sliding button. Defaults to "20". + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Sub-elements -------------- diff --git a/docs/source/theme_reference/theme_label.rst b/docs/source/theme_reference/theme_label.rst index 28ba2f1e..c4a11d3a 100644 --- a/docs/source/theme_reference/theme_label.rst +++ b/docs/source/theme_reference/theme_label.rst @@ -68,6 +68,7 @@ Misc - "**text_vert_alignment**" - Set to "top", "bottom or "center". Controls the vertical placement of the label text. Default is "center". - "**text_horiz_alignment_padding**" - If horizontal alignment is set to 'left' or 'right' this value will control the buffer between the edge of the label rectangle and where we start placing the text. Default is "0". - "**text_vert_alignment_padding**" - If vertical alignment is set to 'top' or 'bottom' this value will control the buffer between the edge of the label rectangle and where we start placing the text. Default is "0". + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Example ------- diff --git a/docs/source/theme_reference/theme_panel.rst b/docs/source/theme_reference/theme_panel.rst index 099eb89b..cfcdd922 100644 --- a/docs/source/theme_reference/theme_panel.rst +++ b/docs/source/theme_reference/theme_panel.rst @@ -40,6 +40,7 @@ Misc - "**shape_corner_radius**" - Only used if our shape is 'rounded_rectangle'. It sets the radius used for the rounded corners. Defaults to "2". - "**border_width**" - The width of the border around the element in pixels. Defaults to "1". - "**shadow_width**" - The width of the shadow around the element in pixels. Defaults to "2". + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Example diff --git a/docs/source/theme_reference/theme_progress_bar.rst b/docs/source/theme_reference/theme_progress_bar.rst index ab78776e..31cc68d8 100644 --- a/docs/source/theme_reference/theme_progress_bar.rst +++ b/docs/source/theme_reference/theme_progress_bar.rst @@ -38,6 +38,7 @@ Misc - "**shape_corner_radius**" - Only used if our shape is 'rounded_rectangle'. It sets the radius used for the rounded corners. - "**border_width**" - the width in pixels of the border around the bar. Defaults to 1. - "**shadow_width**" - the width in pixels of the shadow behind the bar. Defaults to 1. + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Font diff --git a/docs/source/theme_reference/theme_screen_space_health_bar.rst b/docs/source/theme_reference/theme_screen_space_health_bar.rst index d9afc300..38365422 100644 --- a/docs/source/theme_reference/theme_screen_space_health_bar.rst +++ b/docs/source/theme_reference/theme_screen_space_health_bar.rst @@ -38,6 +38,7 @@ Misc - "**shape_corner_radius**" - Only used if our shape is 'rounded_rectangle'. It sets the radius used for the rounded corners. - "**border_width**" - the width in pixels of the border around the bar. Defaults to 1. - "**shadow_width**" - the width in pixels of the shadow behind the bar. Defaults to 1. + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Font diff --git a/docs/source/theme_reference/theme_selection_list.rst b/docs/source/theme_reference/theme_selection_list.rst index 2d2d3823..492ea4bd 100644 --- a/docs/source/theme_reference/theme_selection_list.rst +++ b/docs/source/theme_reference/theme_selection_list.rst @@ -28,6 +28,7 @@ Misc - "**border_width**" - The width of the border around the element in pixels. Defaults to "1". - "**shadow_width**" - The width of the shadow around the element in pixels. Defaults to "2". - "**list_item_height**" - The pixel height of a the items in the list. Defaults to "20". + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Sub-elements -------------- diff --git a/docs/source/theme_reference/theme_status_bar.rst b/docs/source/theme_reference/theme_status_bar.rst index 05de9bcc..8fb394c9 100644 --- a/docs/source/theme_reference/theme_status_bar.rst +++ b/docs/source/theme_reference/theme_status_bar.rst @@ -28,6 +28,7 @@ Misc - "**follow_sprite_offset**" - The x,y offset values for when the bar follows a sprite. Defaults to "0,0". - "**border_width**" - The width of the border around the health bar. Defaults to "1". Can be "0" to remove the border. - "**shadow_width**" - The width of the border around the health bar. Defaults to "1". Can be "0" to remove the border. + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Example ------- diff --git a/docs/source/theme_reference/theme_text_box.rst b/docs/source/theme_reference/theme_text_box.rst index 15f7af66..4846b423 100644 --- a/docs/source/theme_reference/theme_text_box.rst +++ b/docs/source/theme_reference/theme_text_box.rst @@ -47,6 +47,7 @@ Misc - "**text_horiz_alignment_padding**" - If horizontal alignment is set to 'left' or 'right' this value will control the buffer between the edge of the box padding and where we start placing the text. Default is "0". Using "padding" is better but these parameters are included for completeness. - "**text_vert_alignment_padding**" - If vertical alignment is set to 'top' or 'bottom' this value will control the buffer between the edge of the box padding and where we start placing the text. Default is "0". Using "padding" is better but these parameters are included for completeness. - "**line_spacing**" - Sets the spacing of lines of text. The default is 1.25. + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Sub-elements -------------- diff --git a/docs/source/theme_reference/theme_text_entry_box.rst b/docs/source/theme_reference/theme_text_entry_box.rst index f34d108f..fe3ee415 100644 --- a/docs/source/theme_reference/theme_text_entry_box.rst +++ b/docs/source/theme_reference/theme_text_entry_box.rst @@ -47,6 +47,7 @@ Misc - "**text_horiz_alignment_padding**" - If horizontal alignment is set to 'left' or 'right' this value will control the buffer between the edge of the box padding and where we start placing the text. Default is "0". Using "padding" is better but these parameters are included for completeness. - "**text_vert_alignment_padding**" - If vertical alignment is set to 'top' or 'bottom' this value will control the buffer between the edge of the box padding and where we start placing the text. Default is "0". Using "padding" is better but these parameters are included for completeness. - "**line_spacing**" - Sets the spacing of lines of text. The default is 1.25. + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Sub-elements -------------- diff --git a/docs/source/theme_reference/theme_text_entry_line.rst b/docs/source/theme_reference/theme_text_entry_line.rst index b9fe3dce..c1d88088 100644 --- a/docs/source/theme_reference/theme_text_entry_line.rst +++ b/docs/source/theme_reference/theme_text_entry_line.rst @@ -74,6 +74,7 @@ Misc - "**border_width**" - the width of the border around the element in pixels. Defaults to "1". - "**shadow_width**" - the width of the shadow around the element in pixels. Defaults to "1". - "**padding**" - the horizontal and vertical 'padding' between the border and where we render the text. Defaults to "4,2". + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Example ------- diff --git a/docs/source/theme_reference/theme_tooltip.rst b/docs/source/theme_reference/theme_tooltip.rst index 7afd3e95..19a3f0e1 100644 --- a/docs/source/theme_reference/theme_tooltip.rst +++ b/docs/source/theme_reference/theme_tooltip.rst @@ -19,7 +19,6 @@ Misc - "**rect_width**" - The width of the rectangle around the tool tip in pixels, including any shadows or borders. The height is determined dynamically. - Sub-elements -------------- diff --git a/docs/source/theme_reference/theme_vertical_scroll_bar.rst b/docs/source/theme_reference/theme_vertical_scroll_bar.rst index 6b24cab3..36c6be7f 100644 --- a/docs/source/theme_reference/theme_vertical_scroll_bar.rst +++ b/docs/source/theme_reference/theme_vertical_scroll_bar.rst @@ -38,6 +38,7 @@ Misc - "**border_width**" - the width in pixels of the border around the bar. Defaults to 1. - "**shadow_width**" - the width in pixels of the shadow behind the bar. Defaults to 1. - "**enable_arrow_buttons**" - Enables or disables the arrow buttons for the scroll bar. "1" is enabled, "0" is disabled. Defaults to "1". + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Sub-elements -------------- diff --git a/docs/source/theme_reference/theme_world_space_health_bar.rst b/docs/source/theme_reference/theme_world_space_health_bar.rst index d819b620..41e6f6b7 100644 --- a/docs/source/theme_reference/theme_world_space_health_bar.rst +++ b/docs/source/theme_reference/theme_world_space_health_bar.rst @@ -28,6 +28,7 @@ Misc - "**follow_sprite_offset**" - The x,y offset values the bar relative to the sprite. Defaults to "0,0". - "**border_width**" - The width of the border around the health bar. Defaults to "1". Can be "0" to remove the border. - "**shadow_width**" - The width of the border around the health bar. Defaults to "1". Can be "0" to remove the border. + - "**tool_tip_delay**" - time in seconds before the button's tool tip (if it has one) will appear. Default is "1.0". Example ------- diff --git a/pygame_gui/core/interfaces/manager_interface.py b/pygame_gui/core/interfaces/manager_interface.py index 9a64ec9f..b04cc9a4 100644 --- a/pygame_gui/core/interfaces/manager_interface.py +++ b/pygame_gui/core/interfaces/manager_interface.py @@ -231,6 +231,7 @@ def create_tool_tip(self, parent_element: IUIElementInterface, object_id: ObjectID, *, + wrap_width: Optional[int] = None, text_kwargs: Optional[Dict[str, str]] = None) -> IUITooltipInterface: """ Creates a tool tip ands returns it. @@ -240,6 +241,7 @@ def create_tool_tip(self, :param hover_distance: The distance we should hover away from our target position. :param parent_element: The UIElement that spawned this tool tip. :param object_id: the object_id of the tooltip. + :param wrap_width: an optional width for the tool tip, will overwrite any value from the theme file. :param text_kwargs: a dictionary of variable arguments to pass to the translated string useful when you have multiple translations that need variables inserted in the middle. diff --git a/pygame_gui/core/ui_element.py b/pygame_gui/core/ui_element.py index cf01eb9f..fbaf518a 100644 --- a/pygame_gui/core/ui_element.py +++ b/pygame_gui/core/ui_element.py @@ -148,6 +148,11 @@ def __init__(self, relative_rect: Union[pygame.Rect, Tuple[int, int, int, int]], self.border_width = None # type: Union[None, int] self.shape_corner_radius = None # type: Union[None, int] + self.tool_tip_text = None + self.tool_tip_text_kwargs = None + self.tool_tip_object_id = None + self.tool_tip_delay = 1.0 + self.tool_tip_wrap_width = None self.tool_tip = None self._setup_container(container) @@ -758,6 +763,8 @@ def kill(self): """ Overriding regular sprite kill() method to remove the element from it's container. """ + if self.tool_tip is not None: + self.tool_tip.kill() self.ui_container.remove_element(self) self.remove_element_from_focus_set(self) super().kill() @@ -811,23 +818,42 @@ def on_fresh_drawable_shape_ready(self): def on_hovered(self): """ - A stub to override. Called when this UI element first enters the 'hovered' state. + Called when this UI element first enters the 'hovered' state. """ + self.hover_time = 0.0 def on_unhovered(self): """ - A stub to override. Called when this UI element leaves the 'hovered' state. + Called when this UI element leaves the 'hovered' state. """ + if self.tool_tip is not None: + self.tool_tip.kill() + self.tool_tip = None - def while_hovering(self, time_delta: float, mouse_pos: pygame.math.Vector2): + def while_hovering(self, time_delta: float, + mouse_pos: Union[pygame.math.Vector2, Tuple[int, int], Tuple[float, float]]): """ - A stub method to override. Called when this UI element is currently hovered. + Called while we are in the hover state. It will create a tool tip if we've been in the + hover state for a while, the text exists to create one and we haven't created one already. - :param time_delta: A float, the time in seconds between the last call to this function - and now (roughly). - :param mouse_pos: The current position of the mouse as 2D Vector. + :param time_delta: Time in seconds between calls to update. + :param mouse_pos: The current position of the mouse. """ + if (self.tool_tip is None and self.tool_tip_text is not None and + self.hover_time > self.tool_tip_delay): + hover_height = int(self.rect.height / 2) + self.tool_tip = self.ui_manager.create_tool_tip(text=self.tool_tip_text, + position=(mouse_pos[0], + self.rect.centery), + hover_distance=(0, + hover_height), + parent_element=self, + object_id=self.tool_tip_object_id, + wrap_width=self.tool_tip_wrap_width, + text_kwargs=self.tool_tip_text_kwargs) + + self.hover_time += time_delta def can_hover(self) -> bool: """ @@ -1186,3 +1212,18 @@ def update_theming(self, new_theming_data: str): """ self.ui_theme.update_single_element_theming(self.most_specific_combined_id, new_theming_data) self.rebuild_from_changed_theme_data() + + def set_tooltip(self, text: Optional[str] = None, object_id: Optional[ObjectID] = None, + text_kwargs: Optional[Dict[str, str]] = None, delay: Optional[float] = None, + wrap_width: Optional[int] = None): + self.tool_tip_text = text + self.tool_tip_text_kwargs = {} + if text_kwargs is not None: + self.tool_tip_text_kwargs = text_kwargs + self.tool_tip_object_id = object_id + + if delay is not None: + self.tool_tip_delay = delay + + self.tool_tip_wrap_width = wrap_width + diff --git a/pygame_gui/elements/ui_button.py b/pygame_gui/elements/ui_button.py index 1659ec1d..bfc71146 100644 --- a/pygame_gui/elements/ui_button.py +++ b/pygame_gui/elements/ui_button.py @@ -85,11 +85,7 @@ def __init__(self, relative_rect: Union[pygame.Rect, Tuple[float, float], pygame self.dynamic_dimensions_orig_top_left = rel_rect.topleft # support for an optional 'tool tip' element attached to this button - self.tool_tip_text = tool_tip_text - self.tool_tip_text_kwargs = {} - if tool_tip_text_kwargs is not None: - self.tool_tip_text_kwargs = tool_tip_text_kwargs - self.tool_tip_object_id = tool_tip_object_id + self.set_tooltip(tool_tip_text, tool_tip_object_id, tool_tip_text_kwargs) self.ui_root_container = self.ui_manager.get_root_container() # Some different states our button can be in, could use a state machine for this @@ -100,9 +96,6 @@ def __init__(self, relative_rect: Union[pygame.Rect, Tuple[float, float], pygame # Used to check button pressed without going through pygame.Event system self.pressed_event = False - # time the hovering - self.hover_time = 0.0 - # timer for double clicks self.last_click_button = None self.allow_double_clicks = allow_double_clicks @@ -128,8 +121,6 @@ def __init__(self, relative_rect: Union[pygame.Rect, Tuple[float, float], pygame self.selected_image = None self.disabled_image = None - self.tool_tip_delay = 1.0 - self.text_horiz_alignment = 'center' self.text_vert_alignment = 'center' self.text_horiz_alignment_padding = 0 @@ -202,8 +193,6 @@ def kill(self): Overrides the standard sprite kill method to also kill any tooltips belonging to this button. """ - if self.tool_tip is not None: - self.tool_tip.kill() super().kill() def hover_point(self, hover_x: int, hover_y: int) -> bool: @@ -239,8 +228,8 @@ def on_hovered(self): Called when we enter the hover state, it sets the colours and image of the button to the appropriate values and redraws it. """ + super().on_hovered() self.drawable_shape.set_active_state('hovered') - self.hover_time = 0.0 # old event to remove in 0.8.0 event_data = {'user_type': OldType(UI_BUTTON_ON_HOVERED), @@ -252,40 +241,14 @@ def on_hovered(self): 'ui_object_id': self.most_specific_combined_id} pygame.event.post(pygame.event.Event(UI_BUTTON_ON_HOVERED, event_data)) - def while_hovering(self, time_delta: float, - mouse_pos: Union[pygame.math.Vector2, Tuple[int, int], Tuple[float, float]]): - """ - Called while we are in the hover state. It will create a tool tip if we've been in the - hover state for a while, the text exists to create one and we haven't created one already. - - :param time_delta: Time in seconds between calls to update. - :param mouse_pos: The current position of the mouse. - - """ - if (self.tool_tip is None and self.tool_tip_text is not None and - self.hover_time > self.tool_tip_delay): - hover_height = int(self.rect.height / 2) - self.tool_tip = self.ui_manager.create_tool_tip(text=self.tool_tip_text, - position=(mouse_pos[0], - self.rect.centery), - hover_distance=(0, - hover_height), - parent_element=self, - object_id=self.tool_tip_object_id, - text_kwargs=self.tool_tip_text_kwargs) - - self.hover_time += time_delta - def on_unhovered(self): """ Called when we leave the hover state. Resets the colours and images to normal and kills any tooltip that was created while we were hovering the button. """ + super().on_unhovered() if self.drawable_shape is not None: self.drawable_shape.set_active_state(self._get_appropriate_state_name()) - if self.tool_tip is not None: - self.tool_tip.kill() - self.tool_tip = None # old event to remove in 0.8.0 event_data = {'user_type': OldType(UI_BUTTON_ON_UNHOVERED), @@ -381,10 +344,7 @@ def process_event(self, event: pygame.event.Event) -> bool: self.hovered = False self.on_unhovered() self._set_active() - self.hover_time = 0.0 - if self.tool_tip is not None: - self.tool_tip.kill() - self.tool_tip = None + consumed_event = True if event.type == pygame.MOUSEBUTTONUP and event.button in self.generate_click_events_from: scaled_mouse_pos = self.ui_manager.calculate_scaled_mouse_position(event.pos) diff --git a/pygame_gui/elements/ui_drop_down_menu.py b/pygame_gui/elements/ui_drop_down_menu.py index fd26ee2c..72784ed8 100644 --- a/pygame_gui/elements/ui_drop_down_menu.py +++ b/pygame_gui/elements/ui_drop_down_menu.py @@ -846,6 +846,11 @@ def rebuild_from_changed_theme_data(self): casting_func=int): has_any_changed = True + if self._check_misc_theme_data_changed(attribute_name='tool_tip_delay', + default_value=1.0, + casting_func=float): + has_any_changed = True + if self._check_shape_theming_changed(defaults={'border_width': 1, 'shadow_width': 2, 'shape_corner_radius': 2}): diff --git a/pygame_gui/elements/ui_horizontal_scroll_bar.py b/pygame_gui/elements/ui_horizontal_scroll_bar.py index 7eb596db..18332f6d 100644 --- a/pygame_gui/elements/ui_horizontal_scroll_bar.py +++ b/pygame_gui/elements/ui_horizontal_scroll_bar.py @@ -472,6 +472,11 @@ def parse_to_bool(str_data: str): casting_func=parse_to_bool): has_any_changed = True + if self._check_misc_theme_data_changed(attribute_name='tool_tip_delay', + default_value=1.0, + casting_func=float): + has_any_changed = True + if has_any_changed: self.rebuild() diff --git a/pygame_gui/elements/ui_horizontal_slider.py b/pygame_gui/elements/ui_horizontal_slider.py index d2273d97..894648c2 100644 --- a/pygame_gui/elements/ui_horizontal_slider.py +++ b/pygame_gui/elements/ui_horizontal_slider.py @@ -453,6 +453,11 @@ def parse_to_bool(str_data: str): casting_func=int): has_any_changed = True + if self._check_misc_theme_data_changed(attribute_name='tool_tip_delay', + default_value=1.0, + casting_func=float): + has_any_changed = True + if has_any_changed: self.rebuild() diff --git a/pygame_gui/elements/ui_image.py b/pygame_gui/elements/ui_image.py index 06b5fbaa..5a4e7848 100644 --- a/pygame_gui/elements/ui_image.py +++ b/pygame_gui/elements/ui_image.py @@ -52,6 +52,12 @@ def __init__(self, self.original_image = None self.set_image(image_surface, image_is_alpha_premultiplied) + self.rebuild_from_changed_theme_data() + + def rebuild_from_changed_theme_data(self): + self._check_misc_theme_data_changed(attribute_name='tool_tip_delay', + default_value=1.0, + casting_func=float) def set_dimensions(self, dimensions: Union[pygame.math.Vector2, Tuple[int, int], diff --git a/pygame_gui/elements/ui_label.py b/pygame_gui/elements/ui_label.py index d134b286..96dd837e 100644 --- a/pygame_gui/elements/ui_label.py +++ b/pygame_gui/elements/ui_label.py @@ -227,6 +227,11 @@ def rebuild_from_changed_theme_data(self): casting_func=self.tuple_extract): any_changed = True + if self._check_misc_theme_data_changed(attribute_name='tool_tip_delay', + default_value=1.0, + casting_func=float): + any_changed = True + if self._check_text_alignment_theming(): any_changed = True diff --git a/pygame_gui/elements/ui_panel.py b/pygame_gui/elements/ui_panel.py index e7780cee..dc8a8316 100644 --- a/pygame_gui/elements/ui_panel.py +++ b/pygame_gui/elements/ui_panel.py @@ -250,6 +250,11 @@ def rebuild_from_changed_theme_data(self): 'rounded_rectangle']): has_any_changed = True + if self._check_misc_theme_data_changed(attribute_name='tool_tip_delay', + default_value=1.0, + casting_func=float): + has_any_changed = True + if self._check_shape_theming_changed(defaults={'border_width': 1, 'shadow_width': 2, 'shape_corner_radius': 2}): diff --git a/pygame_gui/elements/ui_selection_list.py b/pygame_gui/elements/ui_selection_list.py index d6f28ad6..abeb993f 100644 --- a/pygame_gui/elements/ui_selection_list.py +++ b/pygame_gui/elements/ui_selection_list.py @@ -620,6 +620,11 @@ def rebuild_from_changed_theme_data(self): casting_func=int): has_any_changed = True + if self._check_misc_theme_data_changed(attribute_name='tool_tip_delay', + default_value=1.0, + casting_func=float): + has_any_changed = True + if has_any_changed: self.rebuild() diff --git a/pygame_gui/elements/ui_status_bar.py b/pygame_gui/elements/ui_status_bar.py index 33a662be..c48533b6 100644 --- a/pygame_gui/elements/ui_status_bar.py +++ b/pygame_gui/elements/ui_status_bar.py @@ -243,6 +243,11 @@ def rebuild_from_changed_theme_data(self): casting_func=int): has_any_changed = True + if self._check_misc_theme_data_changed(attribute_name='tool_tip_delay', + default_value=1.0, + casting_func=float): + has_any_changed = True + border_colour = self.ui_theme.get_colour_or_gradient('normal_border', self.combined_element_ids) if border_colour != self.border_colour: diff --git a/pygame_gui/elements/ui_text_box.py b/pygame_gui/elements/ui_text_box.py index c58d5405..413aadec 100644 --- a/pygame_gui/elements/ui_text_box.py +++ b/pygame_gui/elements/ui_text_box.py @@ -772,6 +772,11 @@ def rebuild_from_changed_theme_data(self): if self._check_misc_theme_data_changed(attribute_name='line_spacing', default_value=1.25, casting_func=float): has_any_changed = True + if self._check_misc_theme_data_changed(attribute_name='tool_tip_delay', + default_value=1.0, + casting_func=float): + has_any_changed = True + # colour parameters background_colour = self.ui_theme.get_colour_or_gradient('dark_bg', self.combined_element_ids) diff --git a/pygame_gui/elements/ui_text_entry_line.py b/pygame_gui/elements/ui_text_entry_line.py index b67c9fb2..01fad4fc 100644 --- a/pygame_gui/elements/ui_text_entry_line.py +++ b/pygame_gui/elements/ui_text_entry_line.py @@ -941,6 +941,11 @@ def rebuild_from_changed_theme_data(self): casting_func=self.tuple_extract): has_any_changed = True + if self._check_misc_theme_data_changed(attribute_name='tool_tip_delay', + default_value=1.0, + casting_func=float): + has_any_changed = True + if self._check_theme_colours_changed(): has_any_changed = True diff --git a/pygame_gui/elements/ui_tool_tip.py b/pygame_gui/elements/ui_tool_tip.py index 0bc2b89c..f2e094fb 100644 --- a/pygame_gui/elements/ui_tool_tip.py +++ b/pygame_gui/elements/ui_tool_tip.py @@ -43,6 +43,7 @@ def __init__(self, object_id: Optional[Union[ObjectID, str]] = None, anchors: Optional[Dict[str, Union[str, UIElement]]] = None, *, + wrap_width: Optional[int] = None, text_kwargs: Dict[str, str] = None): super().__init__(relative_rect=pygame.Rect((0, 0), (-1, -1)), @@ -61,6 +62,7 @@ def __init__(self, self.rect_width = None # type: Optional[int] self.hover_distance_from_target = hover_distance + self.overwrite_theme_wrap_width = wrap_width self.rebuild_from_changed_theme_data() self.text_block = UITextBox(html_text, @@ -161,6 +163,9 @@ def rebuild_from_changed_theme_data(self): casting_func=int): has_any_changed = True + if self.overwrite_theme_wrap_width is not None: + self.rect_width = self.overwrite_theme_wrap_width + if has_any_changed: self.rebuild() diff --git a/pygame_gui/elements/ui_vertical_scroll_bar.py b/pygame_gui/elements/ui_vertical_scroll_bar.py index 3bfd611f..e39ba0d3 100644 --- a/pygame_gui/elements/ui_vertical_scroll_bar.py +++ b/pygame_gui/elements/ui_vertical_scroll_bar.py @@ -424,6 +424,11 @@ def rebuild_from_changed_theme_data(self): 'rounded_rectangle']): has_any_changed = True + if self._check_misc_theme_data_changed(attribute_name='tool_tip_delay', + default_value=1.0, + casting_func=float): + has_any_changed = True + if self._check_shape_theming_changed(defaults={'border_width': 1, 'shadow_width': 2, 'shape_corner_radius': 2}): diff --git a/pygame_gui/elements/ui_window.py b/pygame_gui/elements/ui_window.py index 54a4928d..6fe93f6a 100644 --- a/pygame_gui/elements/ui_window.py +++ b/pygame_gui/elements/ui_window.py @@ -576,6 +576,11 @@ def rebuild_from_changed_theme_data(self): 'rounded_rectangle']): has_any_changed = True + if self._check_misc_theme_data_changed(attribute_name='tool_tip_delay', + default_value=1.0, + casting_func=float): + has_any_changed = True + if self._check_shape_theming_changed(defaults={'border_width': 1, 'shadow_width': 15, 'shape_corner_radius': 2}): diff --git a/pygame_gui/ui_manager.py b/pygame_gui/ui_manager.py index 6ee1adb9..be0cf4db 100644 --- a/pygame_gui/ui_manager.py +++ b/pygame_gui/ui_manager.py @@ -534,6 +534,7 @@ def create_tool_tip(self, parent_element: IUIElementInterface, object_id: ObjectID, *, + wrap_width: Optional[int] = None, text_kwargs: Optional[Dict[str, str]] = None) -> IUITooltipInterface: """ Creates a tool tip ands returns it. Have hidden this away in the manager so we can call it @@ -544,6 +545,7 @@ def create_tool_tip(self, :param hover_distance: The distance we should hover away from our target position. :param parent_element: The UIElement that spawned this tool tip. :param object_id: the object_id of the tooltip. + :param wrap_width: an optional width for the tool tip, will overwrite any value from the theme file. :param text_kwargs: a dictionary of variable arguments to pass to the translated string useful when you have multiple translations that need variables inserted in the middle. @@ -551,7 +553,7 @@ def create_tool_tip(self, :return: A tool tip placed somewhere on the screen. """ tool_tip = UITooltip(text, hover_distance, self, text_kwargs=text_kwargs, - parent_element=parent_element, object_id=object_id) + parent_element=parent_element, object_id=object_id, wrap_width=wrap_width) tool_tip.find_valid_position(pygame.math.Vector2(position[0], position[1])) return tool_tip