CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.25k stars 4.11k forks source link

incorrect vertical size of uilist menus #75698

Open db48x opened 4 weeks ago

db48x commented 4 weeks ago

Describe the bug

Every line of text added above or below the menu items in a uilist menu causes the window to be a few pixels too short. This causes the end of the menu to be clipped. The more text there is, the more is clipped.

The uilist measures the text it is given to discover how large the menu should be. Is this some mismatch between how we (or our modified version of ImGui) measures text and how it renders it?

Attach save file

n/a

Steps to reproduce

Acquire multiple activatable objects (such as lamps, cigarettes, etc) and then use the sleep menu.

Expected behavior

I expect the menu to be the right size! Crazy, I know.

Screenshots

Two lines of text, slightly clipped at the bottom:

Screenshot from 2024-08-03 08-19-43

Four lines, more clipping:

Screenshot from 2024-08-03 08-24-58

Versions and configuration

Additional context

No response

db48x commented 4 weeks ago

@katemonster33, do you have any thoughts on this?

qtquazar commented 3 weeks ago

/confirmed

Can confirm this issue, and that it happens on many, many boxes. Especially noted on the bandaging menu that only the very top of the text for 'disinfection' status shows if the 'bandage' status text is also showing.

Box is clearly not wrapping to the actual size of the needed text, and just cuts off wherever. Guessing #75673 broke several things and this was only partially fixed in #75684

edit2: horizontal information like the amount of time a clothing disassembly takes is also completely missing now.

edit3: @db48x maybe i should be login separate bug reports on this... proficiencies also appear to have been broken by the #75673 change. some now display greater than 100% as the 'percent' sign is spilling over onto the next line. unsure if this is cosmetic or changing behaviour, but i'm credited with proficiencies i'm sure i never hit 100% in, but am now showing greater than 100%. also, those over 100% have not disappeared from the list. prof

db48x commented 3 weeks ago

The proficiency list is an interesting bug, but it isn’t drawn using ImGui. Do file that one separately.

The butchery menu is filed as #75813; thanks for reminding me about it.

RenechCDDA commented 1 day ago

Yeah something is screwy here.

image

This actually takes up 170px, but the size allotted by additional_height in uilist::calc_data() is only 150px

RenechCDDA commented 1 day ago

Hm this is... closer? Something's strange. The area for text seems to be drawn about 1 pixel larger (in y) for every line it should have than the calculation provides for. e.g. during testing additional height was calculated as 450px, but drawn as roughly 472px in the y dimension for 21 cigars.

index 9c4768909f..eaadebd435 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -633,7 +633,8 @@ void uilist::calc_data()
     ImVec2 text_size = {};
     if( !text.empty() ) {
         text_size = calc_size( text );
-        text_size.y += s.ItemSpacing.y * 2.0;
+        float expected_num_lines = text_size.y / ImGui::GetTextLineHeightWithSpacing();
+        text_size.y += ( s.ItemSpacing.y * 2.0 * expected_num_lines );
     }

     ImVec2 desc_size = {};

1 cigar: image

6 cigars: image

21 cigars: image

RenechCDDA commented 1 day ago

Better patch where I don't double-count the spacing. No wonder it was screwy!

index 9c4768909f..9cc2ac9e69 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -633,7 +633,8 @@ void uilist::calc_data()
     ImVec2 text_size = {};
     if( !text.empty() ) {
         text_size = calc_size( text );
-        text_size.y += s.ItemSpacing.y * 2.0;
+        float expected_num_lines = text_size.y / ImGui::GetTextLineHeight();
+        text_size.y += ( s.ItemSpacing.y * expected_num_lines ) + ( s.ItemSpacing.y * 2.0 );
     }

     ImVec2 desc_size = {};

1 cigar: image

6 cigars: image

21 cigars: image

41 cigars: image

RenechCDDA commented 1 day ago

Applying that patch to the desc_size footer also seems to resolve the butchery window issue.

before: image

after: image