Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
MKadaner committed Jul 10, 2023
1 parent e342ccc commit b8146d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
49 changes: 21 additions & 28 deletions far/vmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,7 @@ void VMenu::DisplayObject()

if (!CheckFlags(VMENU_DISABLEDRAWBACKGROUND) && !CheckFlags(VMENU_LISTBOX))
{
// BUGBUG, dead code
// BUGBUG, dead code -- 2023-07-08 MZK: Is it though? I've got here when pressed hotkey of "Select search area" combobox on "find file" dialog.

if (m_BoxType==SHORT_DOUBLE_BOX || m_BoxType==SHORT_SINGLE_BOX)
{
Expand Down Expand Up @@ -2086,6 +2086,14 @@ void VMenu::DrawTitles() const
}
}

rectangle VMenu::GetClientRect() const noexcept
{
if (m_BoxType == NO_BOX)
return m_Where;

return { m_Where.left + 1, m_Where.top + 1, m_Where.right - 1, m_Where.bottom - 1 };
}

void VMenu::ShowMenu()
{
const auto ServiceAreaSize = GetServiceAreaSize();
Expand All @@ -2097,12 +2105,11 @@ void VMenu::ShowMenu()
return;
}

// 2023-07-09 MZK: Do we need this? Why?
if (CheckFlags(VMENU_LISTBOX))
{
if (!GetShowItemCount())
{
SetScreen(m_Where, L' ', Colors[VMenuColorBody]);
}

if (m_BoxType!=NO_BOX)
Box(m_Where, Colors[VMenuColorBox], m_BoxType);
Expand All @@ -2113,32 +2120,16 @@ void VMenu::ShowMenu()
if (GetShowItemCount() <= 0)
return;

wchar_t BoxChar[2]{};

switch (m_BoxType)
{
case NO_BOX:
*BoxChar=L' ';
break;

case SINGLE_BOX:
case SHORT_SINGLE_BOX:
*BoxChar=BoxSymbols[BS_V1];
break;

case DOUBLE_BOX:
case SHORT_DOUBLE_BOX:
*BoxChar=BoxSymbols[BS_V2];
break;
}

if (CheckFlags(VMENU_AUTOHIGHLIGHT))
AssignHighlights(CheckFlags(VMENU_REVERSEHIGHLIGHT));

const auto ClientRect{ GetClientRect() };

int VisualSelectPos = GetVisualPos(SelectPos);
int VisualTopPos = GetVisualPos(TopPos);

// коррекция Top`а
// 2023-07-09 MZK: What is it? Should it be ClientRect.height() instead of m_Where.height()?
if (VisualTopPos+GetShowItemCount() >= m_Where.height() - 1 && VisualSelectPos == GetShowItemCount()-1)
{
VisualTopPos--;
Expand All @@ -2147,11 +2138,11 @@ void VMenu::ShowMenu()
VisualTopPos=0;
}

VisualTopPos = std::min(VisualTopPos, GetShowItemCount() - (m_Where.height() - 2 - (m_BoxType == NO_BOX ? 2 : 0)));
VisualTopPos = std::min(VisualTopPos, GetShowItemCount() - (ClientRect.height() - 4));

if (VisualSelectPos > VisualTopPos + (m_Where.height() - 1 - (m_BoxType == NO_BOX? 0 : 2)))
if (VisualSelectPos > VisualTopPos + (ClientRect.height() - 1))
{
VisualTopPos = VisualSelectPos - (m_Where.height() - 1 - (m_BoxType == NO_BOX? 0 : 2));
VisualTopPos = VisualSelectPos - (ClientRect.height() - 1);
}

if (VisualSelectPos < VisualTopPos)
Expand All @@ -2170,10 +2161,10 @@ void VMenu::ShowMenu()
if (TopPos<0)
TopPos=0;

for (int Y = m_Where.top + (m_BoxType == NO_BOX? 0 : 1), I = TopPos; Y < m_Where.bottom + (m_BoxType == NO_BOX? 1 : 0); ++Y, ++I)
{
GotoXY(m_Where.left, Y);
string LineBuffer(MaxLineWidth, L' ');

for (int Y = ClientRect.top, I = TopPos; Y <= ClientRect.bottom; ++Y, ++I)
{
if (I < static_cast<int>(Items.size()))
{
if (!ItemIsVisible(Items[I]))
Expand All @@ -2182,6 +2173,7 @@ void VMenu::ShowMenu()
continue;
}

GotoXY(m_Where.left, Y);
if (Items[I].Flags&LIF_SEPARATOR)
{
int SepWidth = m_Where.width();
Expand Down Expand Up @@ -2391,6 +2383,7 @@ void VMenu::ShowMenu()
}
else
{
GotoXY(m_Where.left, Y);
if (m_BoxType!=NO_BOX)
{
SetColor(Colors[VMenuColorBox]);
Expand Down
1 change: 1 addition & 0 deletions far/vmenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ class VMenu final: public Modal
//корректировка текущей позиции и флагов SELECTED
void UpdateSelectPos();
void EnableFilter(bool Enable);
rectangle GetClientRect()const noexcept;

size_t Text(string_view Str) const;
size_t Text(wchar_t Char) const;
Expand Down

0 comments on commit b8146d3

Please sign in to comment.