Skip to content

Commit

Permalink
This change includes the addition of a few new features to UIButton. …
Browse files Browse the repository at this point in the history
…Some functionality deviates from the reference platform, but we feel that it aligns more closely with the default look and feel of Xaml buttons on Windows because buttons 'look' pressed in more cases with these changes, and there are straightforward ways to opt out of this behavior if it's not desired.

**adjustsImageWhenDisabled/adjustsImageWhenHighlighted**:
We're adding WinObjC-specific support for adjustsImageWhenDisabled and adjustsImageWhenHighlighted.  On the reference platform, this tinting/darkening behavior is ONLY applied to the button's background an foreground images, but on our platform, the tintening/darkening is applied to the entire button's bounds (including its background color), but NOT to its label text.  The primary justification for this approach is that there's not a straighforward way to tint Xaml Images on RS1, yet this approach also helps us implement simple SystemButton support and it makes UIButtons appear a bit more 'windows-like' in many cases, since they show more distinct pressed behavior.  The behavior is as follows; if adjustsImageWhenDisabled is set to YES, and if no UIControlStateDisabled properties are set on the button, then the entire button contents (aside from its label) receives a lightening effect.  Similar behavior is implemented for adjustsImageWhenHighlighted.  The way to opt-out of this behavior is to either set a single UIControlStateDisabled/UIControlStateHighlighted property, or to set adjustsImageWhenDisabled/adjustsImageWhenHighlighted to NO.

**SystemButton (aka buttonWithType)**:
We're adding support for UIButtonTypeSystem, which behaves as follows:

	- Default background is white.
	- Receives a default text color of (blue/green) [UIColor colorWithRed:0.0f green:0.47843137f blue:1.0f alpha:1.0f] which applies to all states (unless set otherwise)
	- Default to UIColor lightTextColor for disabled titleLabelColor

**SystemButton - Deviations from the Reference Platform**:
	- When selected, the entire label background turns the default text color (blue/green) [UIColor colorWithRed:0.0f green:0.47843137f blue:1.0f alpha:1.0f], and the text color is changed to white.  This seems like a corner case that we're not implementing until we need to for a customer.

	- When highlighted, the titleLabel contents (its text and any sublayer content) are tinted to a darker/greyed out version of the normal state.
		- Instead of this behavior, we're piggy-backing off of our adjustsImageWhenHighlighted implementation to avoid needing to do this extra work.  The button *looks* highlighted, so we don't have to change the text color.

	- On the reference platform, when disabled, text is grey by default, UNLESS any custom normal or disabled text colors are set.  On our platform, we DEFAULT to disabled to grey text and then you can change it, but changing the normal color won't affect the default color (for the sake of simplicity).

Scrubbed Annotations:
All UIButton annotations have been scrubbed and updated with 'NotInPlan' status as needed.

Fixes microsoft#1442
Fixes microsoft#1885
Fixes microsoft#1671
Fixes microsoft#1671

Fixes VSO 10145069.
Fixes VSO 9533114.
  • Loading branch information
jaredhms committed Feb 6, 2017
1 parent 7548ddc commit dd0eef3
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 430 deletions.
4 changes: 3 additions & 1 deletion Frameworks/UIKit.Xaml/Button.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<ControlTemplate TargetType="Button" x:Name="UIKitButtonControlTemplate">
<Canvas x:Name="contentCanvas" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Background="{TemplateBinding Background}">
<Image x:Name="buttonImage" Stretch="Fill" IsHitTestVisible="False" />
<TextBlock x:Name="buttonText" MaxLines="1" TextTrimming="CharacterEllipsis" IsHitTestVisible="False"/>
<Border x:Name="buttonBorder" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" />
<!--TODO: This hits a XamlParseException in some apps; tracked as #1919.
<local:Label x:Name="buttonLabel" IsHitTestVisible="False"/>-->
</Canvas>
</ControlTemplate>
</Button.Template>
Expand Down
21 changes: 7 additions & 14 deletions Frameworks/UIKit.Xaml/Button.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ Windows::Foundation::Size Button::ArrangeOverride(Windows::Foundation::Size fina

void Button::OnApplyTemplate() {
// Call GetTemplateChild to grab references to UIElements in our custom control template
_textBlock = safe_cast<TextBlock^>(GetTemplateChild("buttonText"));
_image = safe_cast<Image^>(GetTemplateChild("buttonImage"));
_border = safe_cast<Border^>(GetTemplateChild("buttonBorder"));
_contentCanvas = safe_cast<Canvas^>(GetTemplateChild(L"contentCanvas"));
}

Expand All @@ -204,28 +204,21 @@ UIKIT_XAML_EXPORT void XamlRemoveLayoutEvent(const ComPtr<IInspectable>& inspect
button->RemoveLayoutEvent();
}

UIKIT_XAML_EXPORT void XamlButtonApplyVisuals(const ComPtr<IInspectable>& inspectableButton,
const ComPtr<IInspectable>& inspectableText,
UIKIT_XAML_EXPORT void XamlButtonApplyVisuals(
const ComPtr<IInspectable>& inspectableButton,
const ComPtr<IInspectable>& inspectableButtonImage,
const ComPtr<IInspectable>& inspectableTitleColor) {

const ComPtr<IInspectable>& inspectableBorderBackgroundBrush) {
auto button = safe_cast<UIKit::Xaml::Button^>(reinterpret_cast<Platform::Object^>(inspectableButton.Get()));
auto title = safe_cast<Platform::String^>(reinterpret_cast<Platform::Object^>(inspectableText.Get()));
auto titleColor = safe_cast<Brush^>(reinterpret_cast<Platform::Object^>(inspectableTitleColor.Get()));
if (!titleColor) {
titleColor = UIKit::Xaml::GetDefaultWhiteForegroundBrush();
}

// Set the Textblock's title and Foreground Brush color
button->_textBlock->Text = title;
button->_textBlock->Foreground = titleColor;

// Set the Button's Image
auto image = safe_cast<Brush^>(reinterpret_cast<Platform::Object^>(inspectableButtonImage.Get()));
if (image) {
ImageBrush^ imageBrush = safe_cast<ImageBrush^>(image);
button->_image->Source = safe_cast<BitmapSource^>(imageBrush->ImageSource);
}

// Set the border background brush (if any)
button->_border->Background = safe_cast<Brush^>(reinterpret_cast<Platform::Object^>(inspectableBorderBackgroundBrush.Get()));
}

UIKIT_XAML_EXPORT void XamlHookButtonPointerEvents(
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/UIKit.Xaml/Button.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public ref class Button sealed : public Private::CoreAnimation::ILayer {
void RemovePointerEvents();
void RemoveLayoutEvent();

Windows::UI::Xaml::Controls::TextBlock^ _textBlock;
Windows::UI::Xaml::Controls::Image^ _image;
Windows::UI::Xaml::Controls::Border^ _border;

private:
Windows::UI::Xaml::Controls::Canvas^ _contentCanvas; // Contains pre-canned button content, as well as any sublayers added by CoreAnimation.
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/UIKit.Xaml/Layer.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ref class Layer sealed : public ILayer {
}

// Allows arbitrary framework elements to opt-into hosting sublayers
static property Windows::UI::Xaml::DependencyProperty^ SublayerCanvasProperty {
static property Windows::UI::Xaml::DependencyProperty^ SublayerCanvasProperty {
Windows::UI::Xaml::DependencyProperty^ get();
}

Expand Down
3 changes: 1 addition & 2 deletions Frameworks/UIKit.Xaml/ObjCXamlControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ enum ControlStates { ControlStateNormal = 0, ControlStateHighlighted = 1 << 0, C
UIKIT_XAML_EXPORT void XamlCreateButton(IInspectable** created);

UIKIT_XAML_EXPORT void XamlButtonApplyVisuals(const Microsoft::WRL::ComPtr<IInspectable>& inspectableButton,
const Microsoft::WRL::ComPtr<IInspectable>& inspectableText,
const Microsoft::WRL::ComPtr<IInspectable>& inspectableImage,
const Microsoft::WRL::ComPtr<IInspectable>& inspectableTitleColor);
const Microsoft::WRL::ComPtr<IInspectable>& inspectableBorderBackgroundBrush);

// Hooks pointer events on a UIKit::Button passed in as IInspectable
UIKIT_XAML_EXPORT void XamlHookButtonPointerEvents(const Microsoft::WRL::ComPtr<IInspectable>& inspectableButton,
Expand Down
Loading

0 comments on commit dd0eef3

Please sign in to comment.