Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes to sliders & scrollbars to make it easier to have custom image arrow buttons #652

Merged
merged 3 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion pygame_gui/core/drawable_shapes/drawable_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def build_text_layout(self):
containing_rect_when_text_built = self.containing_rect.copy()
# Draw any text
if 'text' in self.theming and 'font' in self.theming and self.theming['text'] is not None:
# we need two rectangles for the text. One is has actual area the
# we need two rectangles for the text. One has actual area the
# text surface takes up, which may be larger than the displayed area,
# and its position on the final surface. The other is the amount of
# area of the text surface which we blit from, which may be much smaller
Expand Down
15 changes: 7 additions & 8 deletions pygame_gui/data/default_theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,25 @@
{
"prototype": "#no_frills_button"
},
"horizontal_slider.@arrow_button":
{
"font": {
"name": "fira_code_symbols",
"size": "14"
}
},
"horizontal_slider.#left_button":
{
"misc":
{
"text_horiz_alignment_method": "left_triangle"
},
"font": {
"name": "fira_code_symbols",
"size": "14"
}
},
"horizontal_slider.#right_button":
{
"misc":
{
"text_horiz_alignment_method": "right_triangle"
},
"font": {
"name": "fira_code_symbols",
"size": "14"
}
},
"horizontal_slider.#sliding_button":
Expand Down
6 changes: 4 additions & 2 deletions pygame_gui/elements/ui_horizontal_scroll_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def __init__(self,

self.drawable_shape = None
self.shape = 'rectangle'
self.left_arrow_text = '◀'
self.right_arrow_text = '▶'

self.background_rect = None # type: Union[None, pygame.Rect]

Expand Down Expand Up @@ -179,7 +181,7 @@ def rebuild(self):
self.left_button = UIButton(pygame.Rect((0, 0),
(self.arrow_button_width,
self.background_rect.height)),
'◀', self.ui_manager,
self.left_arrow_text, self.ui_manager,
container=self.button_container,
starting_height=1,
parent_element=self,
Expand All @@ -195,7 +197,7 @@ def rebuild(self):
self.right_button = UIButton(pygame.Rect((-self.arrow_button_width, 0),
(self.arrow_button_width,
self.background_rect.height)),
'▶', self.ui_manager,
self.right_arrow_text, self.ui_manager,
container=self.button_container,
starting_height=1,
parent_element=self,
Expand Down
7 changes: 5 additions & 2 deletions pygame_gui/elements/ui_horizontal_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def __init__(self,
self.left_limit_position = 0.0
self.starting_grab_x_difference = 0

self.left_arrow_text = '◀'
self.right_arrow_text = '▶'

if (isinstance(start_value, int) and
isinstance(value_range[0], int) and
isinstance(value_range[1], int)):
Expand Down Expand Up @@ -181,7 +184,7 @@ def rebuild(self):
self.left_button = UIButton(pygame.Rect((0, 0),
(self.arrow_button_width,
self.background_rect.height)),
'◀', self.ui_manager,
self.left_arrow_text, self.ui_manager,
container=self.button_container,
starting_height=1,
parent_element=self,
Expand All @@ -197,7 +200,7 @@ def rebuild(self):
self.right_button = UIButton(pygame.Rect((-self.arrow_button_width, 0),
(self.arrow_button_width,
self.background_rect.height)),
'▶', self.ui_manager,
self.right_arrow_text, self.ui_manager,
container=self.button_container,
starting_height=1,
parent_element=self,
Expand Down
6 changes: 4 additions & 2 deletions pygame_gui/elements/ui_vertical_scroll_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def __init__(self,
self.bottom_button = None
self.sliding_button = None
self.enable_arrow_buttons = True
self.top_arrow_text = '▲'
self.bottom_arrow_text = '▼'

self.rebuild_from_changed_theme_data()

Expand Down Expand Up @@ -175,7 +177,7 @@ def rebuild(self):
self.top_button = UIButton(pygame.Rect((0, 0),
(self.background_rect.width,
self.arrow_button_height)),
'▲', self.ui_manager,
self.top_arrow_text, self.ui_manager,
container=self.button_container,
starting_height=1,
parent_element=self,
Expand All @@ -191,7 +193,7 @@ def rebuild(self):
self.bottom_button = UIButton(pygame.Rect((0, -self.arrow_button_height),
(self.background_rect.width,
self.arrow_button_height)),
'▼', self.ui_manager,
self.bottom_arrow_text, self.ui_manager,
container=self.button_container,
starting_height=1,
parent_element=self,
Expand Down
10 changes: 6 additions & 4 deletions tests/test_windows/test_ui_file_dialog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import platform
from pathlib import Path

import pygame
Expand Down Expand Up @@ -396,12 +397,13 @@ def test_process_event(self, default_ui_manager, _display_surface_return_none):

assert Path(file_dialog.current_directory_path).name == 'images'

file_dialog.file_path_text_line.set_text('/')
if platform.system().upper() == 'WINDOWS':
file_dialog.file_path_text_line.set_text('/')

file_dialog.process_event(pygame.event.Event(UI_TEXT_ENTRY_FINISHED,
{'ui_element': file_dialog.file_path_text_line}))
file_dialog.process_event(pygame.event.Event(UI_TEXT_ENTRY_FINISHED,
{'ui_element': file_dialog.file_path_text_line}))

assert Path(file_dialog.current_directory_path).name == ''
assert Path(file_dialog.current_directory_path).name == ''

def test_show(self, _init_pygame, default_ui_manager, _display_surface_return_none):
file_dialog = UIFileDialog(rect=pygame.Rect(100, 100, 440, 500),
Expand Down
Loading