Repository: microsoft/terminal
File: src/cascadia/TerminalApp/SuggestionsControl.cpp (C++)

Code before:
        else // BottomUp
        {
            Controls::Grid::SetRow(_searchBox(), 4);
            controlToMoveToTop = _descriptionsBackdrop();
        }

        assert(controlToMoveToTop);
        const auto& children{ _listAndDescriptionStack().Children() };
        uint32_t index;
        if (children.IndexOf(controlToMoveToTop, index))
        {
            children.Move(index, 0);
        }
    }

    void SuggestionsControl::_recalculateTopMargin()
    {
        auto currentMargin = Margin();
        // Call Measure() on the descriptions backdrop, so that it gets it's new
        // DesiredSize for this new description text.
        //
        // If you forget this, then we _probably_ weren't laid out since
        // updating that text, and the ActualHeight will be the _last_
        // description's height.
        const til::size actualSize{ til::math::rounding, ActualWidth(), ActualHeight() };
        _descriptionsBackdrop().Measure(actualSize.to_winrt_size());

        // 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)
            currentMargin.Top = (_anchor.Y);
        }
        else
        {
            // Bottom Up.

            // This is wackier, because we need to calculate the offset upwards
            // from our anchor. So we need to get the size of our elements:
            const auto backdropHeight = _backdrop().ActualHeight();
            const auto descriptionDesiredHeight = _descriptionsBackdrop().Visibility() == Visibility::Visible ?
                                                      _descriptionsBackdrop().DesiredSize().Height :
                                                      0;

            const auto marginTop = (_anchor.Y - backdropHeight - descriptionDesiredHeight);

            currentMargin.Top = marginTop;
        }
        Margin(currentMargin);

Review comment (suggestion):
We shouldn't cast to `til::size` as an intermediary here. That we do this elsewhere is one of the reasons IMO why we have these tiny pixel shifts and inaccuracies at >100% display scale.

This should IMO be:
```cpp
_descriptionsBackdrop().Measure({
    static_cast<float>(ActualWidth()),
    static_cast<float>(ActualHeight()),
});
```

Apropos, isn't it funny how `winrt::Windows::Foundation::Size` uses `float` while `ActualWidth` and a ton of other functions use `double`? Quite the consistent API...

Code after:
            children.Move(index, 0);
        }
    }

    void SuggestionsControl::_recalculateTopMargin()
    {
        auto currentMargin = Margin();
        // Call Measure() on the descriptions backdrop, so that it gets it's new
        // DesiredSize for this new description text.
        //
        // If you forget this, then we _probably_ weren't laid out since
        // updating that text, and the ActualHeight will be the _last_
        // description's height.
        _descriptionsBackdrop().Measure({
            static_cast<float>(ActualWidth()),
            static_cast<float>(ActualHeight()),
        });

        // 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)
            currentMargin.Top = (_anchor.Y);
        }
        else
        {
            // Bottom Up.

            // This is wackier, because we need to calculate the offset upwards
            // from our anchor. So we need to get the size of our elements:
            const auto backdropHeight = _backdrop().ActualHeight();
            const auto descriptionDesiredHeight = _descriptionsBackdrop().Visibility() == Visibility::Visible ?
                                                      _descriptionsBackdrop().DesiredSize().Height :
                                                      0;

            const auto marginTop = (_anchor.Y - backdropHeight - descriptionDesiredHeight);

            currentMargin.Top = marginTop;
        }
        Margin(currentMargin);
    }

    void SuggestionsControl::Open(TerminalApp::SuggestionsMode mode,
                                  const Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::Command>& commands,
                                  winrt::hstring filter,
                                  Windows::Foundation::Point anchor,
                                  Windows::Foundation::Size space,
                                  float characterHeight)
    {