Prepare KSwitcher v0.6.111 with Files navigation and scrollbars

This commit is contained in:
agrynco committed 2026-11-17 15:23:22 +02:00
1 parent e144cd6607
commit d60ef626f0
13 files changed
+504 -107

No files matched your search

+27 -22
View File
@@ -2,6 +2,7 @@
#include "files_text_preferences.h"
#include "files_menu_paint.h"
#include "files_menu_navigation.h"
#include "files_scrollbar.h"
#include "files_history_date.h"
#include "files_text_document.h"
#include "files_text_language.h"
@@ -317,10 +318,17 @@ struct FarPopup
FarDropDownPalette palette;
HFONT font{};
int rowHeight{},inset{},visible{},top{},current{},result=-1;
int dragOffset=-1;
bool done{};
int rowTop() const { return inset+1+rowHeight/2; }
int bottomMargin() const { return inset+1+rowHeight/4; }
ScrollPosition scrollPosition() const {return {static_cast<int>(rows.size()),visible,top};}
RECT scrollTrack(HWND window,RECT bounds) const
{
const LONG right=bounds.right-inset-1;
return {std::max(bounds.left,right-scrollBarWidth(window)),rowTop(),right,rowTop()+visible*rowHeight};
}
void select(int row)
{
@@ -370,8 +378,9 @@ struct FarPopup
SetTextColor(dc,palette.text);
SelectObject(dc,font);
const LONG rowLeft=frame.left+inset;
const LONG scrollWidth=static_cast<int>(rows.size())>visible?rowHeight/2:0;
const LONG rowRight=scrollWidth?bounds.right-scrollWidth:frame.right-1;
const auto position=scrollPosition();
const auto track=scrollTrack(window,bounds);
const LONG rowRight=position.last()?track.left:frame.right-1;
LONG y=rowTop();
for(int offset=0;offset<visible;++offset,y+=rowHeight)
{
@@ -400,22 +409,7 @@ struct FarPopup
DrawTextW(dc,entry.text.data(),static_cast<int>(entry.text.size()),&box,
DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX|DT_END_ELLIPSIS|(entry.index<0?DT_CENTER:DT_LEFT));
}
if(scrollWidth)
{
RECT up{rowRight,rowTop(),bounds.right,rowTop()+rowHeight};
RECT down{rowRight,y-rowHeight,bounds.right,y};
DrawTextW(dc,L"▲",1,&up,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
DrawTextW(dc,L"▼",1,&down,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
RECT track{up.left,up.bottom,up.right,down.top};
for(LONG line=track.top;line<track.bottom;line+=2)
for(LONG x=track.left+(line%4==0?0:1);x<track.right;x+=2)
SetPixelV(dc,x,line,palette.text);
const auto travel=std::max(0L,track.bottom-track.top-rowHeight);
const auto thumbY=track.top+MulDiv(top,travel,static_cast<int>(rows.size())-visible);
RECT thumb{track.left,thumbY,track.right,std::min(track.bottom,thumbY+rowHeight)};
SetDCBrushColor(dc,palette.text);
FillRect(dc,&thumb,brush);
}
if(position.last()) paintScrollBar(dc,track,position,palette.surface);
}
};
@@ -482,17 +476,28 @@ LRESULT CALLBACK farPopupWindow(HWND window,UINT message,WPARAM wp,LPARAM lp)
RECT bounds{};
GetClientRect(window,&bounds);
const POINT point{GET_X_LPARAM(lp),GET_Y_LPARAM(lp)};
const auto position=state->scrollPosition();
const auto track=state->scrollTrack(window,bounds);
if(state->dragOffset>=0)
{
if(message==WM_MOUSEMOVE) state->top=position.drag(track,point.y,state->dragOffset);
if(message==WM_LBUTTONUP) state->dragOffset=-1;
InvalidateRect(window,nullptr,FALSE);
return 0;
}
if(!PtInRect(&bounds,point))
{
if(message==WM_LBUTTONDOWN) state->done=true;
return 0;
}
const auto offset=(point.y-state->rowTop())/state->rowHeight;
const bool scroll=static_cast<int>(state->rows.size())>state->visible &&
point.x>=bounds.right-state->rowHeight/2;
const bool scroll=position.last() && PtInRect(&track,point);
if(scroll && message==WM_LBUTTONDOWN)
state->top=std::clamp(state->top+(offset<state->visible/2?-1:1),0,
static_cast<int>(state->rows.size())-state->visible);
{
const auto thumb=position.thumb(track);
if(PtInRect(&thumb,point)) state->dragOffset=point.y-thumb.top;
else state->top=position.click(track,point.y);
}
if(!scroll && point.y>=state->rowTop() && offset<state->visible)
{
const auto row=state->top+offset;