Skip to content

Commit

Permalink
very confident we can get all the logic into the sxnui
Browse files Browse the repository at this point in the history
(cherry picked from commit 57a5327)
  • Loading branch information
zadjii-msft committed Mar 1, 2023
1 parent e2cc278 commit e544871
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
21 changes: 17 additions & 4 deletions src/cascadia/TerminalApp/SuggestionsControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,15 +1051,28 @@ namespace winrt::TerminalApp::implementation
}
}

void SuggestionsControl::Anchor(Windows::Foundation::Point anchor, Windows::Foundation::Size space)
void SuggestionsControl::Anchor(Windows::Foundation::Point anchor,
Windows::Foundation::Size space)
{
_anchor = anchor;
_space = space;

// TODO! do some clamping

const til::size actualSize{ til::math::rounding, ActualWidth(), ActualHeight() };
// First, position horizonally.
//
// We want to align the left edge of the text within the control to the
// cursor position. We'll need to scoot a little to the left, to align
// text with cursor
const auto proposedX = gsl::narrow_cast<int>(_anchor.X - 40);
// If the control is too wide to fit in the window, clamp it fit inside
// the window.
const auto maxX = gsl::narrow_cast<int>(space.Width - actualSize.width);
const auto clampedX = std::clamp(proposedX, 0, maxX);

// // Create a thickness for the new margins
auto newMargin = Windows::UI::Xaml::ThicknessHelper::FromLengths(_anchor.X, 0, 0, 0);
auto newMargin = Windows::UI::Xaml::ThicknessHelper::FromLengths(clampedX, 0, 0, 0);

// // SuggestionsPopup().HorizontalOffset(clampedX);

Expand All @@ -1070,14 +1083,14 @@ namespace winrt::TerminalApp::implementation
// // extending below. This is easy, we can just use the cursor as the
// // origin (more or less)
// // SuggestionsPopup().VerticalOffset(realCursorPos.y + characterSize.Height);
newMargin.Top = (_anchor.Y + 16); // TODO! 16 is cursor height
newMargin.Top = (_anchor.Y);
}
else
{
// // Position at the cursor. The suggestions UI itself will maintian
// // its own offset such that it's always above its origin
// // SuggestionsPopup().VerticalOffset(realCursorPos.y);
newMargin.Top = (_anchor.Y - ActualHeight());
newMargin.Top = (_anchor.Y - actualSize.height);
}
Margin(newMargin);
}
Expand Down
25 changes: 18 additions & 7 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4539,6 +4539,7 @@ namespace winrt::TerminalApp::implementation
const auto controlTransform = control.TransformToVisual(this->Root());
const til::point controlOrigin{ til::math::rounding, controlTransform.TransformPoint(Windows::Foundation::Point{ 0, 0 }) };
const til::point realCursorPos = controlOrigin + cursorPos;
// const til::point anchor = realCursorPos + til::point{ 0, characterSize.Height };

const auto currentWindow = CoreWindow::GetForCurrentThread();
const auto currentWindowBounds = currentWindow.Bounds();
Expand All @@ -4550,18 +4551,28 @@ namespace winrt::TerminalApp::implementation
const til::size windowDimensions{ til::math::rounding, ActualWidth(), ActualHeight() };

// Is there space in the window below the cursor to open the menu downwards?
const bool canOpenDownwards = ((realCursorPos.y) + characterSize.Height + maxSize.Height) < windowDimensions.height;

const auto direction = canOpenDownwards ? TerminalApp::SuggestionsDirection::TopDown :
TerminalApp::SuggestionsDirection::BottomUp;

sxnUi.Direction(direction);
sxnUi.Anchor(realCursorPos.to_winrt_point(), windowDimensions.to_winrt_size());
// const bool canOpenDownwards = ((realCursorPos.y) + characterSize.Height + maxSize.Height) < windowDimensions.height;

// const auto direction = canOpenDownwards ? TerminalApp::SuggestionsDirection::TopDown :
// TerminalApp::SuggestionsDirection::BottomUp;
const til::size actualSuggestionsSizeBefore{ til::math::rounding, sxnUi.ActualWidth(), sxnUi.ActualHeight() };
actualSuggestionsSizeBefore;
// sxnUi.Direction(direction);
// sxnUi.Anchor(realCursorPos.to_winrt_point(), windowDimensions.to_winrt_size());
sxnUi.Mode(mode);

// SuggestionsPopup().IsOpen(true);
sxnUi.SetCommands(commandsCollection);
sxnUi.Visibility(commandsCollection.Size() > 0 ? Visibility::Visible : Visibility::Collapsed);
const til::size actualSuggestionsSizeAfter{ til::math::rounding, sxnUi.ActualWidth(), sxnUi.ActualHeight() };
actualSuggestionsSizeAfter;

const bool canOpenDownwards = ((realCursorPos.y) + characterSize.Height + actualSuggestionsSizeAfter.height) < windowDimensions.height;
const auto direction = canOpenDownwards ? TerminalApp::SuggestionsDirection::TopDown :
TerminalApp::SuggestionsDirection::BottomUp;
const auto anchor = realCursorPos + til::point{ til::math::rounding, 0.0f, canOpenDownwards ? characterSize.Height : 0 };
sxnUi.Anchor(anchor.to_winrt_point(), windowDimensions.to_winrt_size());
sxnUi.Direction(direction);

// // Position the suggestions UI relative to the actual term control.
// //
Expand Down

0 comments on commit e544871

Please sign in to comment.