Skip to content

Commit

Permalink
WIP: Need to generalize SetItemHPos
Browse files Browse the repository at this point in the history
  • Loading branch information
MKadaner committed Jan 28, 2024
1 parent 9e85081 commit f2e264e
Showing 1 changed file with 29 additions and 82 deletions.
111 changes: 29 additions & 82 deletions far/vmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2276,20 +2276,7 @@ bool VMenu::ShiftAllItemsHPos(const int Shift)
const auto TextAreaWidth{ CalculateTextAreaWidth() };
if (TextAreaWidth <= 0) return false;

// TBD: Make a testable function
const auto AdjustedShift = [&]
{
if (m_AllItemsBoundaries.second <= 0)
return Shift <= 0 ? 0 : Shift - m_AllItemsBoundaries.second;
if (m_AllItemsBoundaries.first >= TextAreaWidth)
return Shift >= 0 ? 0 : Shift - (m_AllItemsBoundaries.first - TextAreaWidth);
if (Shift <= 0)
return std::max(Shift, 1 - m_AllItemsBoundaries.second);
if (Shift >= 0)
return std::min(Shift, TextAreaWidth - m_AllItemsBoundaries.first - 1);
return Shift;
}();

const auto AdjustedShift{ adjust_hpos_shift(Shift, m_AllItemsBoundaries.first, m_AllItemsBoundaries.second, TextAreaWidth) };
if (!AdjustedShift) return false;

const auto Policy{ CheckFlags(VMENU_ENABLEALIGNANNOTATIONS) ? item_hscroll_policy::unbound : item_hscroll_policy::bound_stick_to_left };
Expand Down Expand Up @@ -2318,96 +2305,56 @@ bool VMenu::AlignAnnotations()
TextAreaWidth);
}







bool VMenu::ShiftAllItemsHPosLimited(const int Shift, const int TextAreaWidth)
bool VMenu::SetCurItemSmartHPos(const int NewHPos)
{
const auto TextAreaWidth{ CalculateTextAreaWidth() };
if (TextAreaWidth <= 0) return false;

const auto Policy{ CheckFlags(VMENU_ENABLEALIGNANNOTATIONS) ? item_hscroll_policy::cling_to_edge : item_hscroll_policy::bound_stick_to_left };

bool NeedRedraw{};
auto& Item{ Items[SelectPos] };

for (auto& Item : Items)
{
if (set_item_hpos(
Item,
[&](int) { return Item.HPos + Shift; },
CheckFlags(VMENU_SHOWAMPERSAND),
TextAreaWidth,
Policy))
{
NeedRedraw = true;
}
}
if (Item.Flags & LIF_SEPARATOR) return false;

return NeedRedraw;
}
const auto ItemLength{ get_item_visual_length(CheckFlags(VMENU_SHOWAMPERSAND), Item.Name) };
if (ItemLength <= 0) return false;

bool VMenu::SetCurItemSmartHPos(const int NewHPos)
{
//const auto TextAreaWidth{ CalculateTextAreaWidth() };
//if (TextAreaWidth <= 0) return false;
const auto HPos{ get_item_smart_hpos(NewHPos, ItemLength, TextAreaWidth, Policy) };

//const auto Policy{ CheckFlags(VMENU_ENABLEALIGNANNOTATIONS) ? item_hscroll_policy::cling_to_edge : item_hscroll_policy::bound_stick_to_left };
UpdateAllItemsBoundaries(HPos, ItemLength);

//auto& Item{ Items[SelectPos] };
if (Item.HPos == HPos) return false;

//if (set_item_hpos(
// Item,
// [=](int ItemLength) { return get_item_smart_hpos(NewHPos, ItemLength, TextAreaWidth); },
// CheckFlags(VMENU_SHOWAMPERSAND),
// TextAreaWidth,
// Policy))
//{
// SetMenuFlags(VMENU_UPDATEREQUIRED);
// return true;
//}
Item.HPos = HPos;

return false;
SetMenuFlags(VMENU_UPDATEREQUIRED);
return true;
}

bool VMenu::ShiftCurItemHPos(const int Shift)
{
//const auto TextAreaWidth{ CalculateTextAreaWidth() };
//if (TextAreaWidth <= 0) return false;
const auto TextAreaWidth{ CalculateTextAreaWidth() };
if (TextAreaWidth <= 0) return false;

//const auto Policy{ CheckFlags(VMENU_ENABLEALIGNANNOTATIONS) ? item_hscroll_policy::cling_to_edge : item_hscroll_policy::bound_stick_to_left };
const auto Policy{ CheckFlags(VMENU_ENABLEALIGNANNOTATIONS) ? item_hscroll_policy::cling_to_edge : item_hscroll_policy::bound_stick_to_left };

//auto& Item{ Items[SelectPos] };
auto& Item{ Items[SelectPos] };

//if (set_item_hpos(
// Item,
// [&](int) { return Item.HPos + Shift; },
// CheckFlags(VMENU_SHOWAMPERSAND),
// TextAreaWidth,
// Policy))
//{
// SetMenuFlags(VMENU_UPDATEREQUIRED);
// return true;
//}
if (Item.Flags & LIF_SEPARATOR) return false;

return false;
}
const auto ItemLength{ get_item_visual_length(CheckFlags(VMENU_SHOWAMPERSAND), Item.Name) };
if (ItemLength <= 0) return false;

bool VMenu::ShiftAllItemsHPosEnBlock(const int Shift, const int TextAreaWidth)
{
//const auto AdjustedShift = EnBlocHScrollDiscriminator
// ? adjust_en_bloc_shift(Shift, EnBlocHScrollDiscriminator.value(), TextAreaWidth)
// : Shift;
//if (!AdjustedShift) return false;
const auto HPos{ get_item_absolute_hpos(Item.HPos + Shift, ItemLength, TextAreaWidth, Policy) };

//const auto [NeedRedraw, HScrollDiscriminator] = set_all_items_en_bloc_hpos(
// Items,
// [=](const auto& Item) { return Item.HPos + AdjustedShift; },
// CheckFlags(VMENU_SHOWAMPERSAND));
UpdateAllItemsBoundaries(HPos, ItemLength);

//EnBlocHScrollDiscriminator = HScrollDiscriminator;
//return NeedRedraw;
if (Item.HPos == HPos) return false;

return false;
Item.HPos = HPos;

SetMenuFlags(VMENU_UPDATEREQUIRED);
return true;
}

void VMenu::Show()
Expand Down

0 comments on commit f2e264e

Please sign in to comment.