ppizarror / pygame-menu

A menu for pygame. Simple, and easy to use
https://pygame-menu.readthedocs.io/
Other
555 stars 141 forks source link

Added multilabel support #413

Closed ppizarror closed 2 years ago

ppizarror commented 2 years ago
codecov[bot] commented 2 years ago

Codecov Report

Merging #413 (aabc84f) into master (eef45cc) will increase coverage by 0.01%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #413      +/-   ##
==========================================
+ Coverage   97.25%   97.26%   +0.01%     
==========================================
  Files          49       49              
  Lines       12152    12230      +78     
==========================================
+ Hits        11818    11896      +78     
  Misses        334      334              
Impacted Files Coverage Δ
pygame_menu/widgets/core/widget.py 97.76% <100.00%> (+<0.01%) :arrow_up:
pygame_menu/widgets/widget/label.py 100.00% <100.00%> (ø)
pygame_menu/widgets/widget/textinput.py 88.04% <100.00%> (ø)
pygame_menu/menu.py 96.59% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update eef45cc...aabc84f. Read the comment docs.

vnmabus commented 2 years ago

I think _get_nlines is not used right now, is it? I planned to use that to allow the user to fix the maximum number of lines. In case that the text needs more lines, the remaining test should not be shown, but the information of the start position of the remaining text should be stored, so that a subclass can use that information to show the next page of text.

ppizarror commented 2 years ago

I think _get_nlines is not used right now, is it? I planned to use that to allow the user to fix the maximum number of lines. In case that the text needs more lines, the remaining test should not be shown, but the information of the start position of the remaining text should be stored, so that a subclass can use that information to show the next page of text.

Ok I'll fix that. Just copied the code you provided me, I had the same doubt

ppizarror commented 2 years ago

@vnmabus I've added two new methods to lines. get_lines and get_overflow_lines. The first returns a list of currently displayed lines on the widget, and the latter return the lines not shown because of overflow.

Let me know what you think.

Example (see tests):

s = 'lorem ipsum dolor sit amet this was very important nice a test is required ' \
    'lorem ipsum dolor sit amet this was very important nice a test is required'
label = menu.add.label(s, wordwrap=True, max_nlines=3)  # Maximum number of lines

self.assertEqual(len(label.get_lines()), 3) # The widget needs 4 lines, but maximum is 3
self.assertEqual(label.get_height(), 131)
self.assertEqual(label.get_overflow_lines(), ['important nice a test is required']) # The overflowed text
self.assertEqual(' '.join(label.get_lines() + label.get_overflow_lines()), s) # The sum of lines and overflow should be the same as s
vnmabus commented 2 years ago

It seems that we are going in the right direction, but there are still issues. The size of the label with wordwrap is still a bit larger than the available size. For example, if you allow scrollbars, a horizontal scrollbar will be added.

I think that being able to choose the alignment of the text inside the label would be useful (and easy to implement). Currently the text is aligned to the left, but allowing it to be centered (not justified) or right-aligned could be easily done adjusting the x-position where each subsurface will be blitted.

I still have to try if the current implementation allows me to implement the subclass I wanted. I will try when I have time.

ppizarror commented 2 years ago

@vnmabus can you provide a MWE to test The size of the label with wordwrap is still a bit larger than the available size. For example, if you allow scrollbars, a horizontal scrollbar will be added. I'll try to code the alignment in my free time, that might happen in the next two weeks.

ppizarror commented 2 years ago

Hi! I'll merge this and continue the work on text alignment. greetings!