Skip to content

Commit

Permalink
POC: We can take it out of the Popup and have it still work
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Feb 24, 2023
1 parent c9e7156 commit 5defde5
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 47 deletions.
40 changes: 37 additions & 3 deletions src/cascadia/TerminalApp/SuggestionsControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ namespace winrt::TerminalApp::implementation
// stays "attached" to the cursor.
if (Visibility() == Visibility::Visible && _direction == TerminalApp::SuggestionsDirection::BottomUp)
{
auto t = this->Translation();
t.y = gsl::narrow_cast<float>(-ActualHeight());
this->Translation(t);
// auto t = this->Translation();
// t.y = gsl::narrow_cast<float>(-ActualHeight());
// this->Translation(t);
auto m = this->Margin();
m.Top = (_anchor.Y - ActualHeight());
this->Margin(m);
}
});

Expand Down Expand Up @@ -1056,4 +1059,35 @@ namespace winrt::TerminalApp::implementation
Controls::Grid::SetRow(_searchBox(), 4);
}
}

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

// TODO! do some clamping

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

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

// // Now, position vertically.
if (_direction == TerminalApp::SuggestionsDirection::TopDown)
{
// // The control should open right below the cursor, with the list
// // 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
}
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());
}
Margin(newMargin);
}
}
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/SuggestionsControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace winrt::TerminalApp::implementation

TerminalApp::SuggestionsMode Mode() const;
void Mode(TerminalApp::SuggestionsMode mode);
void Anchor(Windows::Foundation::Point anchor, Windows::Foundation::Size space);

WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
WINRT_OBSERVABLE_PROPERTY(winrt::hstring, NoMatchesText, _PropertyChangedHandlers);
Expand Down Expand Up @@ -65,6 +66,8 @@ namespace winrt::TerminalApp::implementation
TerminalApp::SuggestionsDirection _direction{ TerminalApp::SuggestionsDirection::TopDown };

bool _lastFilterTextWasEmpty{ true };
Windows::Foundation::Point _anchor;
Windows::Foundation::Size _space;

void _filterTextChanged(const Windows::Foundation::IInspectable& sender,
const Windows::UI::Xaml::RoutedEventArgs& args);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/SuggestionsControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace TerminalApp
void SelectNextItem(Boolean moveDown);

void Direction(SuggestionsDirection direction);
void Anchor(Windows.Foundation.Point anchor, Windows.Foundation.Size space);

event Windows.Foundation.TypedEventHandler<SuggestionsControl, Microsoft.Terminal.Settings.Model.Command> DispatchCommandRequested;
event Windows.Foundation.TypedEventHandler<Object, Microsoft.Terminal.Settings.Model.Command> PreviewAction;
Expand Down
83 changes: 45 additions & 38 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ namespace winrt::TerminalApp::implementation
sxnUi.RegisterPropertyChangedCallback(UIElement::VisibilityProperty(), [this](auto&&, auto&&) {
if (SuggestionsUI().Visibility() == Visibility::Collapsed)
{
SuggestionsPopup().IsOpen(false);
// SuggestionsPopup().IsOpen(false);
_FocusActiveControl(nullptr, nullptr);
}
});
Expand Down Expand Up @@ -4510,7 +4510,7 @@ namespace winrt::TerminalApp::implementation
}
if (commandsCollection.Size() == 0)
{
SuggestionsPopup().IsOpen(false);
// SuggestionsPopup().IsOpen(false);
SuggestionsUI().Visibility(Visibility::Collapsed);

co_return;
Expand Down Expand Up @@ -4556,47 +4556,54 @@ namespace winrt::TerminalApp::implementation
TerminalApp::SuggestionsDirection::BottomUp;

sxnUi.Direction(direction);
sxnUi.Anchor(realCursorPos.to_winrt_point(), windowDimensions.to_winrt_size());
sxnUi.Mode(mode);

SuggestionsPopup().IsOpen(true);
// SuggestionsPopup().IsOpen(true);
sxnUi.SetCommands(commandsCollection);
sxnUi.Visibility(commandsCollection.Size() > 0 ? Visibility::Visible : Visibility::Collapsed);

// Position the suggestions UI relative to the actual term control.
//
// This needs to be done _after_ it is set to be visible. If not, then
// the control won't have an Actual{Width, Height} yet.
const til::size actualSuggestionsSize{ til::math::rounding,
sxnUi.ActualWidth(),
sxnUi.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 = realCursorPos.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>(windowDimensions.width - actualSuggestionsSize.width);
const auto clampedX = std::clamp(proposedX, 0, maxX);

SuggestionsPopup().HorizontalOffset(clampedX);

// Now, position vertically.
if (direction == TerminalApp::SuggestionsDirection::TopDown)
{
// The control should open right below the cursor, with the list
// extending below. This is easy, we can just use the cursor as the
// origin (more or less)
SuggestionsPopup().VerticalOffset(realCursorPos.y + characterSize.Height);
}
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);
}
// // Position the suggestions UI relative to the actual term control.
// //
// // This needs to be done _after_ it is set to be visible. If not, then
// // the control won't have an Actual{Width, Height} yet.
// const til::size actualSuggestionsSize{ til::math::rounding,
// sxnUi.ActualWidth(),
// sxnUi.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 = realCursorPos.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>(windowDimensions.width - actualSuggestionsSize.width);
// const auto clampedX = std::clamp(proposedX, 0, maxX);

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

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

// // Now, position vertically.
// if (direction == TerminalApp::SuggestionsDirection::TopDown)
// {
// // The control should open right below the cursor, with the list
// // 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 = (realCursorPos.y + characterSize.Height);
// }
// 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 = (realCursorPos.y);
// }
// sxnUi.Margin(newMargin);
}

}
14 changes: 8 additions & 6 deletions src/cascadia/TerminalApp/TerminalPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,19 @@
PreviewKeyDown="_KeyDownHandler"
Visibility="Collapsed" />

<Popup x:Name="SuggestionsPopup"
<local:SuggestionsControl x:Name="SuggestionsUI"
Grid.Row="2"
HorizontalAlignment="Left"
VerticalAlignment="Top"
PreviewKeyDown="_KeyDownHandler"
Visibility="Collapsed" />
<!--<Popup x:Name="SuggestionsPopup"
HorizontalOffset="200"
IsOpen="False"
ShouldConstrainToRootBounds="False"
VerticalOffset="200">
<local:SuggestionsControl x:Name="SuggestionsUI"
VerticalAlignment="Stretch"
PreviewKeyDown="_KeyDownHandler"
Visibility="Collapsed" />
</Popup>
</Popup>-->

<!--
A TeachingTip with IsLightDismissEnabled="True" will immediately
Expand Down

0 comments on commit 5defde5

Please sign in to comment.