Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabView: Add separators and drag/drop support #1113

Merged
merged 4 commits into from
Jul 30, 2019
Merged

Conversation

teaP
Copy link
Contributor

@teaP teaP commented Jul 29, 2019

I added separators between tabs. The line appears at the right end of each tab item, and is covered up by a -1 margin on the left side by the tab next to it.

I also added the TabDraggedOutside event and pass along other drag/drop events from ListView, and a test for that scenario.

@teaP teaP requested a review from a team as a code owner July 29, 2019 18:30
if (args.DropResult() == winrt::DataPackageOperation::None)
{
auto item = args.Items().GetAt(0);
auto tab = ContainerFromItem(item).try_as<winrt::TabViewItem>();
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer locals that save some computation to be defined as const, that way when I see a local used within a scope I can jump to its definition and be sure that I understand its state. Without const I have to check the rest of the code to be sure that there wasn't some if statement that changed the local before the spot I'm interested in got to it. In this case the function is small enough that this isn't a big deal but I still find this patterns a little harder to work with.

I'd suggest doing the computation of the true value of tab within a lambda so that the local within this scope can be const.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't prefer to make lambdas that will only be used in one place, I feel it hinders readability.

Copy link
Member

Choose a reason for hiding this comment

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

I think lambdas for scoping (even when they're used just once) is a very useful tool that can improve readability. @StephenLPeters when giving this feedback could you recommend a rewrite of the function that you think is more readable? I'll agree that it's not obvious that wrapping this whole thing in a lambda would be simpler... which might argue for a helper function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, just did. Helper function would be great too, maybe even better, although I think I like to locality of a lambda a bit more than the readability you get from a helper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do actually use lambdas for scoping in this very file. :) But I disagree that it makes sense here.

@mdtauk
Copy link
Contributor

mdtauk commented Jul 29, 2019

Is there a current up to date design spec to view - or even a final design comp - you are working towards?

Terminal's tabs look very basic - and I have posted ideas for the control myself which use shadow and a current tab indicator to help them stand apart from each other.

TabControl

@DHowett-MSFT
Copy link

I'd be interested in seeing a screenshot of this

@teaP
Copy link
Contributor Author

teaP commented Jul 29, 2019

I'd be interested in seeing a screenshot of this

image

@teaP
Copy link
Contributor Author

teaP commented Jul 29, 2019

Is there a current up to date design spec to view - or even a final design comp - you are working towards?

The design is still forthcoming, but hopefully soon!

@teaP teaP requested review from StephenLPeters and jevansaks July 30, 2019 16:49
if (args.DropResult() == winrt::DataPackageOperation::None)
{
const auto item = args.Items().GetAt(0);
auto tab = ContainerFromItem(item).try_as<winrt::TabViewItem>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
auto tab = ContainerFromItem(item).try_as<winrt::TabViewItem>();
const auto tab = [this, item]()
{
if(const auto tabAsView = ContainerFromItem(item).try_as<winrt::TabViewItem>())
{
return tabAsView;
}
if(const auto tabAsFE = item.try_as<winrt::FrameworkElement>())
{
return tabAsFE;
}
const auto numItems = static_cast<int>(Items().Size());
for (int i = 0; i < numItems; i++)
{
if(const auto tabItem = ContainerFromIndex(i).try_as<winrt::TabViewItem>())
{
if (tabItem.Content() == item)
{
return tabItem;
}
}
}
return nullptr;
}();

Copy link
Contributor

Choose a reason for hiding this comment

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

You might have to static_cast each of the returns to get the compiler to be happy that each branch returns the same type =/

if (args.DropResult() == winrt::DataPackageOperation::None)
{
auto item = args.Items().GetAt(0);
auto tab = ContainerFromItem(item).try_as<winrt::TabViewItem>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, just did. Helper function would be great too, maybe even better, although I think I like to locality of a lambda a bit more than the readability you get from a helper.

@teaP teaP merged commit edafda0 into master Jul 30, 2019
@jevansaks jevansaks added the release note PR that we want to call out in the next release summary label Jul 30, 2019
@msft-github-bot
Copy link
Collaborator

🎉Microsoft.UI.Xaml v2.2.190731001-prerelease has been released which incorporates this pull request.:tada:

Handy links:

@teaP teaP deleted the user/teaP/TabViewDragDrop branch September 17, 2019 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release note PR that we want to call out in the next release summary
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants