Skip to content

Commit

Permalink
TabView continuous expansions fix (#6954)
Browse files Browse the repository at this point in the history
* Reverting product change made for 'TabView gap between active tab and active content fix #6644'

* TabView expansions fix
  • Loading branch information
RBrid authored Apr 12, 2022
1 parent e19d61d commit e5054a8
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 109 deletions.
10 changes: 7 additions & 3 deletions dev/TabView/TabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ static constexpr wstring_view c_tabViewItemMaxWidthName{ L"TabViewItemMaxWidth"s
// TODO: what is the right number and should this be customizable?
static constexpr double c_scrollAmount = 50.0;

// Change to 'true' to turn on debugging outputs in Output window
bool TabViewTrace::s_IsDebugOutputEnabled{ false };
bool TabViewTrace::s_IsVerboseDebugOutputEnabled{ false };

TabView::TabView()
{
__RP_Marker_ClassById(RuntimeProfiler::ProfId_TabView);
Expand Down Expand Up @@ -968,9 +972,9 @@ void TabView::OnScrollIncreaseClick(const winrt::IInspectable&, const winrt::Rou

winrt::Size TabView::MeasureOverride(winrt::Size const& availableSize)
{
if (previousAvailableSize.Width != availableSize.Width)
if (m_previousAvailableSize.Width != availableSize.Width)
{
previousAvailableSize = availableSize;
m_previousAvailableSize = availableSize;
UpdateTabWidths();
}

Expand Down Expand Up @@ -1006,7 +1010,7 @@ void TabView::UpdateTabWidths(bool shouldUpdateWidths, bool fillAllAvailableSpac
if (auto&& tabColumn = m_tabColumn.get())
{
// Note: can be infinite
const auto availableWidth = previousAvailableSize.Width - widthTaken;
const auto availableWidth = m_previousAvailableSize.Width - widthTaken;

// Size can be 0 when window is first created; in that case, skip calculations; we'll get a new size soon
if (availableWidth > 0)
Expand Down
3 changes: 2 additions & 1 deletion dev/TabView/TabView.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "TabViewTabDroppedOutsideEventArgs.g.h"
#include "TabViewTabDragStartingEventArgs.g.h"
#include "TabViewTabDragCompletedEventArgs.g.h"
#include "TabViewTrace.h"
#include "DispatcherHelper.h"

static constexpr double c_tabShadowDepth = 16.0;
Expand Down Expand Up @@ -218,7 +219,7 @@ class TabView :

winrt::hstring m_tabCloseButtonTooltipText{};

winrt::Size previousAvailableSize{};
winrt::Size m_previousAvailableSize{};

bool m_isDragging{ false };
};
1 change: 1 addition & 0 deletions dev/TabView/TabView.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)TabViewItemAutomationPeer.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)TabViewItemTemplateSettings.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)TabViewListView.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)TabViewTrace.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)..\Generated\TabView.properties.cpp" />
Expand Down
9 changes: 6 additions & 3 deletions dev/TabView/TabViewItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ void TabViewItem::OnApplyTemplate()
void TabViewItem::UpdateTabGeometry()
{
auto const templateSettings = winrt::get_self<TabViewItemTemplateSettings>(TabViewTemplateSettings());
auto const scaleFactor = SharedHelpers::Is19H1OrHigher() ?
static_cast<float>(XamlRoot().RasterizationScale()) :
static_cast<float>(winrt::DisplayInformation::GetForCurrentView().RawPixelsPerViewPixel());

auto const height = ActualHeight();
auto const popupRadius = unbox_value<winrt::CornerRadius>(ResourceAccessor::ResourceLookup(*this, box_value(c_overlayCornerRadiusKey)));
Expand All @@ -115,11 +118,11 @@ void TabViewItem::UpdateTabGeometry()

WCHAR strOut[1024];
StringCchPrintf(strOut, ARRAYSIZE(strOut), data,
height - 1,
height - 1.0f / scaleFactor,
leftCorner, leftCorner, leftCorner, leftCorner, leftCorner,
ActualWidth() - (leftCorner + rightCorner),
ActualWidth() - (leftCorner + rightCorner + 1.0f / scaleFactor),
rightCorner, rightCorner, rightCorner, rightCorner,
height - (4 + rightCorner + 1));
height - (4 + rightCorner + 1.0f / scaleFactor));

const auto geometry = winrt::XamlReader::Load(strOut).try_as<winrt::Geometry>();

Expand Down
1 change: 1 addition & 0 deletions dev/TabView/TabViewItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "TabViewItem.properties.h"
#include "TabViewItemAutomationPeer.h"
#include "TabViewItemTemplateSettings.h"
#include "TabViewTrace.h"

class TabViewItem :
public ReferenceTracker<TabViewItem, winrt::implementation::TabViewItemT>,
Expand Down
155 changes: 155 additions & 0 deletions dev/TabView/TabViewTrace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#pragma once

#include "common.h"
#include "TraceLogging.h"
#include "Utils.h"
#include "MUXControlsTestHooks.h"

inline bool IsTabViewTracingEnabled()
{
return g_IsLoggingProviderEnabled &&
g_LoggingProviderLevel >= WINEVENT_LEVEL_INFO &&
(g_LoggingProviderMatchAnyKeyword & KEYWORD_TABVIEW || g_LoggingProviderMatchAnyKeyword == 0);
}

inline bool IsTabViewVerboseTracingEnabled()
{
return g_IsLoggingProviderEnabled &&
g_LoggingProviderLevel >= WINEVENT_LEVEL_VERBOSE &&
(g_LoggingProviderMatchAnyKeyword & KEYWORD_TABVIEW || g_LoggingProviderMatchAnyKeyword == 0);
}

inline bool IsTabViewPerfTracingEnabled()
{
return g_IsPerfProviderEnabled &&
g_PerfProviderLevel >= WINEVENT_LEVEL_INFO &&
(g_PerfProviderMatchAnyKeyword & KEYWORD_TABVIEW || g_PerfProviderMatchAnyKeyword == 0);
}

#define TABVIEW_TRACE_INFO_ENABLED(includeTraceLogging, sender, message, ...) \
TabViewTrace::TraceInfo(includeTraceLogging, sender, message, __VA_ARGS__); \

#define TABVIEW_TRACE_INFO(sender, message, ...) \
if (IsTabViewTracingEnabled()) \
{ \
TABVIEW_TRACE_INFO_ENABLED(true /*includeTraceLogging*/, sender, message, __VA_ARGS__); \
} \
else if (TabViewTrace::s_IsDebugOutputEnabled || TabViewTrace::s_IsVerboseDebugOutputEnabled) \
{ \
TABVIEW_TRACE_INFO_ENABLED(false /*includeTraceLogging*/, sender, message, __VA_ARGS__); \
} \

#define TABVIEW_TRACE_VERBOSE_ENABLED(includeTraceLogging, sender, message, ...) \
TabViewTrace::TraceVerbose(includeTraceLogging, sender, message, __VA_ARGS__); \

#define TABVIEW_TRACE_VERBOSE(sender, message, ...) \
if (IsTabViewVerboseTracingEnabled()) \
{ \
TABVIEW_TRACE_VERBOSE_ENABLED(true /*includeTraceLogging*/, sender, message, __VA_ARGS__); \
} \
else if (TabViewTrace::s_IsVerboseDebugOutputEnabled) \
{ \
TABVIEW_TRACE_VERBOSE_ENABLED(false /*includeTraceLogging*/, sender, message, __VA_ARGS__); \
} \

#define TABVIEW_TRACE_PERF(info) \
if (IsTabViewPerfTracingEnabled()) \
{ \
TabViewTrace::TracePerfInfo(info); \
} \

class TabViewTrace
{
public:
static bool s_IsDebugOutputEnabled;
static bool s_IsVerboseDebugOutputEnabled;

static void TraceInfo(bool includeTraceLogging, const winrt::IInspectable& sender, PCWSTR message, ...) noexcept
{
va_list args;
va_start(args, message);
WCHAR buffer[384]{};
if (SUCCEEDED(StringCchVPrintfW(buffer, ARRAYSIZE(buffer), message, args)))
{
if (includeTraceLogging)
{
// TraceViewers
// http://toolbox/pef
// http://fastetw/index.aspx
TraceLoggingWrite(
g_hLoggingProvider,
"TabViewInfo" /* eventName */,
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
TraceLoggingKeyword(KEYWORD_TABVIEW),
TraceLoggingWideString(buffer, "Message"));
}

if (s_IsDebugOutputEnabled)
{
OutputDebugStringW(buffer);
}

com_ptr<MUXControlsTestHooks> globalTestHooks = MUXControlsTestHooks::GetGlobalTestHooks();

if (globalTestHooks &&
(globalTestHooks->GetLoggingLevelForType(L"TabView") >= WINEVENT_LEVEL_INFO || globalTestHooks->GetLoggingLevelForInstance(sender) >= WINEVENT_LEVEL_INFO))
{
globalTestHooks->LogMessage(sender, buffer, false /*isVerboseLevel*/);
}
}
va_end(args);
}

static void TraceVerbose(bool includeTraceLogging, const winrt::IInspectable& sender, PCWSTR message, ...) noexcept
{
va_list args;
va_start(args, message);
WCHAR buffer[1024]{};
const HRESULT hr = StringCchVPrintfW(buffer, ARRAYSIZE(buffer), message, args);
if (SUCCEEDED(hr) || hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER))
{
if (includeTraceLogging)
{
// TraceViewers
// http://toolbox/pef
// http://fastetw/index.aspx
TraceLoggingWrite(
g_hLoggingProvider,
"TabViewVerbose" /* eventName */,
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(KEYWORD_TABVIEW),
TraceLoggingWideString(buffer, "Message"));
}

if (s_IsDebugOutputEnabled || s_IsVerboseDebugOutputEnabled)
{
OutputDebugStringW(buffer);
}

com_ptr<MUXControlsTestHooks> globalTestHooks = MUXControlsTestHooks::GetGlobalTestHooks();

if (globalTestHooks &&
(globalTestHooks->GetLoggingLevelForType(L"TabView") >= WINEVENT_LEVEL_VERBOSE || globalTestHooks->GetLoggingLevelForInstance(sender) >= WINEVENT_LEVEL_VERBOSE))
{
globalTestHooks->LogMessage(sender, buffer, true /*isVerboseLevel*/);
}
}
va_end(args);
}

static void TracePerfInfo(PCWSTR info) noexcept
{
// TraceViewers
// http://toolbox/pef
// http://fastetw/index.aspx
TraceLoggingWrite(
g_hPerfProvider,
"TabViewPerf" /* eventName */,
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
TraceLoggingKeyword(KEYWORD_TABVIEW),
TraceLoggingWideString(info, "Info"));
}
};
Loading

0 comments on commit e5054a8

Please sign in to comment.