def test_creation_and_rebuild_with_scrollbar(self, _init_pygame: None, default_ui_manager: UIManager, _display_surface_return_none): default_ui_manager.preload_fonts([{'name': 'fira_code', 'html_size': 4.5, 'style': 'bold'}, {'name': 'fira_code', 'html_size': 4.5, 'style': 'regular'}, {'name': 'fira_code', 'html_size': 2, 'style': 'regular'}, {'name': 'fira_code', 'html_size': 2, 'style': 'italic'}, {'name': 'fira_code', 'html_size': 6, 'style': 'bold'}, {'name': 'fira_code', 'html_size': 6, 'style': 'regular'}, {'name': 'fira_code', 'html_size': 6, 'style': 'bold_italic'}, {'name': 'fira_code', 'html_size': 4, 'style': 'bold'}, {'name': 'fira_code', 'html_size': 4, 'style': 'italic'}, {'name': 'fira_code', 'html_size': 2, 'style': 'bold'}, {'name': 'fira_code', 'html_size': 2, 'style': 'bold_italic'}]) text_box = UITextBox(html_text='' '<font color=regular_text><font color=#E784A2 size=4.5><br><b><u>Lorem</u><br><br><br>' 'ipsum dolor sit amet</b></font>,' ' <b><a href="test">consectetur</a></b> adipiscing elit. in a flibb de dib do ' 'rub a la clob slip the perry tin fo glorp yip dorp' 'skorp si pork flum de dum be dung, slob be robble glurp destination flum kin slum. ' 'Ram slim gordo, fem tulip squirrel slippers save socks certainly.<br>' 'Vestibulum in <i>commodo me</i> tellus in nisi finibus a sodales.<br>Vestibulum' '<font size=2>hendrerit mi <i>sed nulla</i> scelerisque</font>, posuere ullamcorper ' 'sem pulvinar.' 'Nulla at pulvinar a odio, a dictum dolor.<br>Maecenas at <font size=6><b>tellus a' 'tortor. a<br>' 'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><br>' 'In hac a habitasse to platea dictumst.<br>' '<font color=#4CD656 size=4>Vivamus I interdum mollis lacus nec porttitor.<br>Morbi ' 'accumsan, lectus at ' 'tincidunt to dictum, neque <font color=#879AF6>erat tristique erat</font>, ' 'sed a tempus for <b>nunc</b> dolor in nibh.<br>' 'Suspendisse in viverra dui <i>fringilla dolor laoreet</i>, sit amet on pharetra a ante ' 'sollicitudin.</font></font>' '<br><br>' '<b>consectetur</b> adipiscing elit. in a<br>' 'Vestibulum in <i>commodo me</i> tellus in nisi finibus a sodales.<br>' 'Vestibulum <font size=2>hendrerit mi <i>sed nulla</i> scelerisque</font>, ' 'posuere ullamcorper sem pulvinar. ' 'Nulla at pulvinar a odio, a dictum dolor.<br>' 'Maecenas at <font size=6><b>tellus a tortor. a<br>' 'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><br>' 'In hac a habitasse to platea dictumst.<br>' '<font color=#4CD656 size=4>Vivamus I interdum mollis lacus nec porttitor.<br>Morbi ' 'accumsan, lectus at' 'tincidunt to dictum, neque <font color=#879AF6>erat tristique erat</font>, ' 'sed a tempus for <b>nunc</b> dolor in nibh.<br>' 'Suspendisse in viverra dui <i>fringilla dolor laoreet</i>, sit amet on pharetra a ante ' 'sollicitudin.</font></font>', relative_rect=pygame.Rect(100, 100, 200, 300), manager=default_ui_manager) text_box.rebuild() assert text_box.image is not None
class Chat: def __init__(self, app) -> None: self.app = app self.chatbox = None self.ui = pygame_gui.UIManager((SCREEN_WIDTH, SCREEN_HEIGHT)) self.prepare_chatbox() self.prepare_inputbox() @property def is_focused(self): return self.inputbox.is_focused def update(self): self.ui.update(self.app.time_delta) def draw(self): self.ui.draw_ui(self.app.screen) def handle_event(self, event): self.ui.process_events(event) if event.type == 'new_message': self.prepare_chatbox() if event.type == pygame.USEREVENT: if event.user_type == 'ui_text_entry_finished': print('Chat.handle_event', event) self.handle_inputbox_press_enter(event) def handle_inputbox_press_enter(self, event): print('LobbyScene.handle_inputbox_press_enter event', event) text = event.text self.app.messages.append(('regular', self.app.my_name, text)) self.prepare_chatbox() for player in self.app.players.values(): print('LobbyScene.handle_inputbox_press_enter send to', player, text) self.app.network.send( ('tcp', player['ip'], chat_message_packet(self.app.my_name, self.app.network.ip, text))) self.inputbox.set_text('') def show(self): self.chatbox.show() self.inputbox.show() def hide(self): self.chatbox.hide() self.inputbox.hide() def finalize(self): self.chatbox.hide() self.inputbox.hide() self.chatbox.kill() self.inputbox.kill() def prepare_chatbox(self): text = '' for type, auth, txt in self.app.messages: if type == 'regular': text += f"""<font color="{ColorHash(auth).hex}">{auth}</font>: {txt}<br/>""" elif type == 'event': text += f"""<font color="#FAA237">{txt}</font><br/>""" if self.chatbox is None: self.chatbox = UITextBox( text, pygame.Rect((560, 0), (300, SCREEN_HEIGHT - 60)), self.ui) else: self.chatbox.html_text = text self.chatbox.rebuild() if self.chatbox.scroll_bar: scroll_bar = self.chatbox.scroll_bar scroll_bar.scroll_wheel_down = False scroll_bar.scroll_position += (250 * 1) scroll_bar.scroll_position = min( scroll_bar.scroll_position, scroll_bar.bottom_limit - scroll_bar.sliding_button.rect.height) x_pos = scroll_bar.rect.x + scroll_bar.shadow_width + scroll_bar.border_width y_pos = scroll_bar.scroll_position + scroll_bar.rect.y + scroll_bar.shadow_width + \ scroll_bar.border_width + scroll_bar.button_height scroll_bar.sliding_button.set_position( pygame.math.Vector2(x_pos, y_pos)) scroll_bar.start_percentage = scroll_bar.scroll_position / \ scroll_bar.scrollable_height if not scroll_bar.has_moved_recently: scroll_bar.has_moved_recently = True def prepare_inputbox(self): self.inputbox = UITextEntryLine( pygame.Rect((560, SCREEN_HEIGHT - 60), (300, 60)), self.ui)