Skip to content

Commit d6192fb

Browse files
committed
Fix UI Rendering Issue (Issue #693)
Fixed issue where the last item in menu lists doesn't render properly:\n- Added bounds checking for item height and width\n- Fixed image rectangle dimensions for last items\n- Added proper clipping to prevent drawing outside item boundaries\n- Ensured valid dimensions for all menu item parts
1 parent 907277d commit d6192fb

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/dll/src/ContextMenu.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include <pch.h>
32
#include "Include/Theme.h"
43
#include "Include/ContextMenu.h"
@@ -2175,6 +2174,11 @@ namespace Nilesoft
21752174
rcblock.top += _theme.back.margin.top;
21762175
rcblock.bottom -= _theme.back.margin.bottom;
21772176

2177+
// Ensure we have at least minimal height for the item
2178+
if (rcblock.height() < 4) {
2179+
rcblock.bottom = rcblock.top + 4;
2180+
}
2181+
21782182
if(mii->cch > 0 || !menu->has_col)
21792183
{
21802184
rcblock.left += _theme.back.margin.left;
@@ -2186,6 +2190,11 @@ namespace Nilesoft
21862190
rcblock.right -= _theme.back.margin.right + dpi(3);
21872191
}
21882192

2193+
// Ensure proper width for the item
2194+
if (rcblock.width() <= 0) {
2195+
rcblock.right = rcblock.left + 10;
2196+
}
2197+
21892198
const auto width = rcblock.width();
21902199
const auto height = rcblock.height();
21912200

@@ -2195,6 +2204,14 @@ namespace Nilesoft
21952204
rcimg.top = rcblock.top + ((height - image_size) / 2);
21962205
rcimg.bottom = rcimg.top + image_size;
21972206

2207+
// Fix for last item - ensure image rectangle has valid dimensions
2208+
if (rcimg.bottom > rc->bottom) {
2209+
rcimg.bottom = rc->bottom - 1;
2210+
if (rcimg.height() < 4) {
2211+
rcimg.top = rcimg.bottom - 4;
2212+
}
2213+
}
2214+
21982215
if(mii->cch > 0 || !menu->has_col)
21992216
{
22002217
if(mii->cch == 0)
@@ -2233,6 +2250,11 @@ namespace Nilesoft
22332250
border_color = _theme.back.border.nor_dis;
22342251
}
22352252

2253+
// Ensure we don't draw outside the item's rectangle
2254+
RECT clipRect = *rc;
2255+
dc.save_dc();
2256+
dc.intersect_clip_rect(clipRect);
2257+
22362258
//dc.draw_fill_rounded_rect(rcblock, _theme.back.radius+2, 0,0);
22372259
//draw_rect(&dc, rcblock.point(), { width, height }, 0xff000000, {}, _theme.back.radius);
22382260
//draw_rect(&dc, rcblock.point(), { width, height }, _theme.background.color, {}, _theme.back.radius);
@@ -2241,6 +2263,8 @@ namespace Nilesoft
22412263
back_color.a = op;
22422264
draw_rect(&dc, rcblock.point(), { width, height }, back_color, border_color, _theme.back.radius);
22432265
}
2266+
2267+
dc.restore_dc();
22442268
}
22452269

22462270
auto has_checked_image = menu->draw.checks && menu->draw.images && (_theme.image.display >= 2);
@@ -3588,7 +3612,7 @@ namespace Nilesoft
35883612

35893613
//New feature "showdelay" to change the menu show delay time and it is applied immediately without saving the value in the registry.
35903614
//Gets or sets the time, in milliseconds, that the system waits before displaying a shortcut menu when the mouse cursor is over a submenu item.
3591-
//New-Item -Path HKCU:\Software\Control Panel\Desktop -Name MenuShowDelay -Force -Value 200
3615+
//New-Item -Path "HKCU:\Software\Control Panel\Desktop" -Name MenuShowDelay -Force -Value 200
35923616
if(_context.eval_number(sets->showdelay, obj))
35933617
{
35943618
::SystemParametersInfoW(SPI_GETMENUSHOWDELAY, 0, &_showdelay[0], 0);

0 commit comments

Comments
 (0)