Skip to content

Commit

Permalink
Allow mouse resizing on panes
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed May 18, 2020
1 parent b46d393 commit 2147479
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 30 deletions.
115 changes: 89 additions & 26 deletions src/cascadia/TerminalApp/Pane.cpp
Expand Up @@ -114,14 +114,13 @@ void Pane::Relayout()
// decreasing the size of our first child.
// Return Value:
// - false if we couldn't resize this pane in the given direction, else true.
bool Pane::_Resize(const Direction& direction)
bool Pane::_Resize(const Direction& direction, float amount)
{
if (!DirectionMatchesSplit(direction, _splitState))
{
return false;
}

float amount = .05f;
if (direction == Direction::Right || direction == Direction::Down)
{
amount = -amount;
Expand Down Expand Up @@ -153,9 +152,10 @@ bool Pane::_Resize(const Direction& direction)
// couldn't handle the resize.
// Arguments:
// - direction: The direction to move the separator in.
// - amount: The percentage to resize by (between 0 and 1)
// Return Value:
// - true if we or a child handled this resize request.
bool Pane::ResizePane(const Direction& direction)
bool Pane::ResizePane(const Direction& direction, const float amount)
{
// If we're a leaf, do nothing. We can't possibly have a descendant with a
// separator the correct direction.
Expand All @@ -172,7 +172,7 @@ bool Pane::ResizePane(const Direction& direction)
const bool secondIsFocused = _secondChild->_IsLeaf() && _secondChild->_lastActive;
if (firstIsFocused || secondIsFocused)
{
return _Resize(direction);
return _Resize(direction, amount);
}

// If neither of our children were the focused leaf, then recurse into
Expand All @@ -186,12 +186,12 @@ bool Pane::ResizePane(const Direction& direction)
// either.
if ((!_firstChild->_IsLeaf()) && _firstChild->_HasFocusedChild())
{
return _firstChild->ResizePane(direction) || _Resize(direction);
return _firstChild->ResizePane(direction, amount) || _Resize(direction, amount);
}

if ((!_secondChild->_IsLeaf()) && _secondChild->_HasFocusedChild())
{
return _secondChild->ResizePane(direction) || _Resize(direction);
return _secondChild->ResizePane(direction, amount) || _Resize(direction, amount);
}

return false;
Expand Down Expand Up @@ -867,31 +867,94 @@ void Pane::_UpdateBorders()
// - <none>
void Pane::_ApplySplitDefinitions()
{
if (_splitState == SplitState::Vertical)
if (_splitState == SplitState::Vertical || _splitState == SplitState::Horizontal)
{
Controls::Grid::SetColumn(_firstChild->GetRootElement(), 0);
Controls::Grid::SetColumn(_secondChild->GetRootElement(), 1);
if (_splitState == SplitState::Vertical)
{
Controls::Grid::SetColumn(_firstChild->GetRootElement(), 0);
Controls::Grid::SetColumn(_secondChild->GetRootElement(), 1);

_firstChild->_borders = _borders | Borders::Right;
_secondChild->_borders = _borders | Borders::Left;
_borders = Borders::None;
_firstChild->_borders = _borders | Borders::Right;
_secondChild->_borders = _borders | Borders::Left;
_borders = Borders::None;

_UpdateBorders();
_firstChild->_UpdateBorders();
_secondChild->_UpdateBorders();
}
else if (_splitState == SplitState::Horizontal)
{
Controls::Grid::SetRow(_firstChild->GetRootElement(), 0);
Controls::Grid::SetRow(_secondChild->GetRootElement(), 1);
_UpdateBorders();
_firstChild->_UpdateBorders();
_secondChild->_UpdateBorders();

_firstChild->_borders = _borders | Borders::Bottom;
_secondChild->_borders = _borders | Borders::Top;
_borders = Borders::None;
// Only allow x-axis resizing
_root.ManipulationMode(Xaml::Input::ManipulationModes::TranslateX | Xaml::Input::ManipulationModes::TranslateRailsX);
}
else if (_splitState == SplitState::Horizontal)
{
Controls::Grid::SetRow(_firstChild->GetRootElement(), 0);
Controls::Grid::SetRow(_secondChild->GetRootElement(), 1);

_UpdateBorders();
_firstChild->_UpdateBorders();
_secondChild->_UpdateBorders();
_firstChild->_borders = _borders | Borders::Bottom;
_secondChild->_borders = _borders | Borders::Top;
_borders = Borders::None;

_UpdateBorders();
_firstChild->_UpdateBorders();
_secondChild->_UpdateBorders();

// Only allow y-axis resizing
_root.ManipulationMode(Xaml::Input::ManipulationModes::TranslateY | Xaml::Input::ManipulationModes::TranslateRailsY);
}

// define mouse resize for this split
_root.ManipulationDelta([this](auto&&, auto& args) {
auto delta = args.Delta().Translation;

// Decide on direction based on delta
Direction dir = Direction::None;
if (_splitState == SplitState::Vertical)
{
if (delta.X < 0)
{
dir = Direction::Left;
}
else if (delta.X > 0)
{
dir = Direction::Right;
}
}
else if (_splitState == SplitState::Horizontal)
{
if (delta.Y < 0)
{
dir = Direction::Up;
}
else if (delta.Y > 0)
{
dir = Direction::Down;
}
}

// Resize in the given direction
if (dir != Direction::None)
{
// turn delta into a percentage
base::ClampedNumeric<float> amount;
base::ClampedNumeric<float> actualDimension;
if (dir == Direction::Left || dir == Direction::Right)
{
amount = delta.X;
// TODO CARLOS: something is wrong here
actualDimension = base::ClampedNumeric<float>(_root.ActualWidth());
}
else if (dir == Direction::Up || dir == Direction::Down)
{
amount = delta.Y;
// TODO CARLOS: something is wrong here
actualDimension = base::ClampedNumeric<float>(_root.ActualHeight());
}

amount /= actualDimension;

ResizePane(dir, amount.Abs());
}
});
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/cascadia/TerminalApp/Pane.h
Expand Up @@ -55,7 +55,7 @@ class Pane : public std::enable_shared_from_this<Pane>
const GUID& profile);
void ResizeContent(const winrt::Windows::Foundation::Size& newSize);
void Relayout();
bool ResizePane(const winrt::TerminalApp::Direction& direction);
bool ResizePane(const winrt::TerminalApp::Direction& direction, const float amount = 0.05f);
bool NavigateFocus(const winrt::TerminalApp::Direction& direction);

bool CanSplit(winrt::TerminalApp::SplitState splitType);
Expand Down Expand Up @@ -114,7 +114,7 @@ class Pane : public std::enable_shared_from_this<Pane>
void _ApplySplitDefinitions();
void _UpdateBorders();

bool _Resize(const winrt::TerminalApp::Direction& direction);
bool _Resize(const winrt::TerminalApp::Direction& direction, float amount = 0.05f);
bool _NavigateFocus(const winrt::TerminalApp::Direction& direction);

void _CloseChild(const bool closeFirst);
Expand All @@ -136,8 +136,6 @@ class Pane : public std::enable_shared_from_this<Pane>

winrt::TerminalApp::SplitState _convertAutomaticSplitState(const winrt::TerminalApp::SplitState& splitType) const;

std::optional<winrt::TerminalApp::SplitState> _preCalculateAutoSplit(const std::shared_ptr<Pane> target, const winrt::Windows::Foundation::Size parentSize) const;

// Function Description:
// - Returns true if the given direction can be used with the given split
// type.
Expand Down

1 comment on commit 2147479

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New misspellings found, please review:

  • adb
  • CARLOS
To accept these changes, run the following commands
remove_obsolete_words=$(mktemp)
echo '#!/usr/bin/perl -ni
my $re=join "|", qw('"
bitfield
Emojis
HREF
memcpying
OUTPATHROOT
storageitems
textblock
usr
vpack
"');
next if /^($re)(?:$| .*)/;
print;' > $remove_obsolete_words
chmod +x $remove_obsolete_words
for file in .github/actions/spell-check/whitelist/alphabet.txt .github/actions/spell-check/whitelist/web.txt .github/actions/spell-check/whitelist/whitelist.txt; do $remove_obsolete_words $file; done
rm $remove_obsolete_words
(
echo "
adb
CARLOS
"
) | sort -u -f | perl -ne 'next unless /./; print' > new_whitelist.txt && mv new_whitelist.txt '.github/actions/spell-check/whitelist/21474792a269bb4a481dd868d93fc7ce281244c2.txt'
✏️ Contributor please read this
  • If the items listed above are names, please add them to .github/actions/spell-check/dictionary/names.txt.
  • If they're APIs, you can add them to a file in .github/actions/spell-check/dictionary/.
  • If they're just things you're using, please add them to an appropriate file in .github/actions/spell-check/whitelist/.
  • If you need to use a specific token in one place and it shouldn't generally be used, you can
    add an item in an appropriate file in .github/actions/spell-check/patterns/.

See the README.md in each directory for more information.

⚠️ Reviewers

At present, the action that triggered this message will not show its ❌ in this PR unless the branch is within this repository.
Thus, you should make sure that this comment has been addressed before encouraging the merge bot to merge this PR.

Please sign in to comment.