Skip to content

Commit

Permalink
Work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
MKadaner committed Sep 3, 2023
1 parent d6f9aaf commit fbba1e7
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 49 deletions.
116 changes: 67 additions & 49 deletions far/vmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ void VMenu::DrawTitles() const

void VMenu::ShowMenu()
{
const auto ServiceAreaSize = GetServiceAreaSize();
const auto ServiceAreaSize{ GetServiceAreaSize() };
MaxLineWidth = ServiceAreaSize > static_cast<size_t>(m_Where.width())? 0 : m_Where.width() - ServiceAreaSize;

if (m_Where.right <= m_Where.left || m_Where.bottom <= m_Where.top)
Expand Down Expand Up @@ -2116,50 +2116,22 @@ void VMenu::ShowMenu()
AssignHighlights(CheckFlags(VMENU_REVERSEHIGHLIGHT));

const auto ClientRect{ GetClientRect() };
const auto VisualTopPos{ AdjustTopPos(ClientRect.height()) };

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--;

if (VisualTopPos<0)
VisualTopPos=0;
}

VisualTopPos = std::min(VisualTopPos, GetShowItemCount() - (ClientRect.height() - 4));

if (VisualSelectPos > VisualTopPos + (ClientRect.height() - 1))
{
VisualTopPos = VisualSelectPos - (ClientRect.height() - 1);
}

if (VisualSelectPos < VisualTopPos)
{
TopPos=SelectPos;
VisualTopPos=VisualSelectPos;
}
else
{
TopPos=VisualPosToReal(VisualTopPos);
}

if (VisualTopPos<0)
VisualTopPos=0;
if (ClientRect.width() <= 0)
return;

if (TopPos<0)
TopPos=0;
string LineBuffer(ClientRect.width(), L' ');

for (int Y = ClientRect.top, I = TopPos; Y <= ClientRect.bottom; ++Y, ++I)
{
if (I >= static_cast<int>(Items.size()))
{
LineBuffer.replace(LineBuffer.cbegin(), LineBuffer.cend(), ClientRect.width(), L' ');

SetColor(Colors[VMenuColorText]);
GotoXY(ClientRect.left, Y);
Text(string(ClientRect.width(), L' '));
Text(string(LineBuffer));
continue;
}

Expand All @@ -2183,27 +2155,22 @@ void VMenu::ShowMenu()
continue;
}

LineBuffer.at(0) = GetItemCheckMark(Items[I]);
LineBuffer.replace(LineBuffer.cbegin() + 1, LineBuffer.cend(), ClientRect.width(), L' ');

const auto ItemIndent{ Items[I].Indent() };
const auto ItemHanging{ Items[I].Hanging() };


const auto ColorIndices{ GetItemColors(Items[I]) };

GotoXY(m_Where.left + (m_BoxType == NO_BOX? 0 : 1), Y);

SetColor(Colors[ColorIndices.Normal]);

wchar_t CheckMark = L' ';

if (Items[I].Flags & LIF_CHECKED)
{
if (!(Items[I].Flags & 0x0000FFFF))
CheckMark = 0x221A;
else
CheckMark = static_cast<wchar_t>(Items[I].Flags & 0x0000FFFF);
}

const auto ItemIndent{ Items[I].Indent() };
const auto ItemHanging{ Items[I].Hanging() };

string strMenuLine{ CheckMark };
strMenuLine.push_back(L' '); // left scroller (<<) placeholder
// LineBuffer.at(1) = L' '; // left scroller («) placeholder
const auto LineWidthPlusLeftMargin{ strMenuLine.size() + MaxLineWidth };
strMenuLine.append(ItemIndent, L' ');
const auto PrefixSize = strMenuLine.size();
Expand Down Expand Up @@ -2320,6 +2287,46 @@ rectangle VMenu::GetClientRect() const noexcept
return { m_Where.left + 1, m_Where.top + 1, m_Where.right - 1, m_Where.bottom - 1 };
}

int VMenu::AdjustTopPos(const int ClientHeight)
{
int VisualSelectPos = GetVisualPos(SelectPos);
int VisualTopPos = GetVisualPos(TopPos);

// 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--;

if (VisualTopPos < 0)
VisualTopPos = 0;
}

VisualTopPos = std::min(VisualTopPos, GetShowItemCount() - (ClientHeight - 4));

if (VisualSelectPos > VisualTopPos + (ClientHeight - 1))
{
VisualTopPos = VisualSelectPos - (ClientHeight - 1);
}

if (VisualSelectPos < VisualTopPos)
{
TopPos = SelectPos;
VisualTopPos = VisualSelectPos;
}
else
{
TopPos = VisualPosToReal(VisualTopPos);
}

if (VisualTopPos < 0)
VisualTopPos = 0;

if (TopPos < 0)
TopPos = 0;

return VisualTopPos;
}

void VMenu::ConnectSeparator(size_t CurItem, string& separator) const
{
if (CheckFlags(VMENU_NOMERGEBORDER) || separator.size() <= 3)
Expand Down Expand Up @@ -2366,6 +2373,17 @@ void VMenu::ApplySeparatorName(size_t CurItem, string& separator) const
separator.at(NamePos + NameWidth) = L' ';
}

wchar_t VMenu::GetItemCheckMark(const MenuItemEx& CurItem) const noexcept
{
if (!(CurItem.Flags & LIF_CHECKED))
return L' ';

if (!(CurItem.Flags & 0x0000FFFF))
return 0x221A;

return static_cast<wchar_t>(CurItem.Flags & 0x0000FFFF);
}

VMenu::ItemColorIndicies VMenu::GetItemColors(const MenuItemEx& CurItem) const
{
const auto Selected{ !!(CurItem.Flags & LIF_SELECTED) };
Expand Down
2 changes: 2 additions & 0 deletions far/vmenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ class VMenu final: public Modal

void ShowMenu();
rectangle GetClientRect() const noexcept;
int AdjustTopPos(int ClientHeight);
void ConnectSeparator(size_t CurItem, string& separator) const;
void ApplySeparatorName(size_t CurItem, string& separator) const;
wchar_t GetItemCheckMark(const MenuItemEx& CurItem) const noexcept;
ItemColorIndicies GetItemColors(const MenuItemEx& CurItem) const;
void DrawTitles() const;
int GetItemPosition(int Position) const;
Expand Down

0 comments on commit fbba1e7

Please sign in to comment.