-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added HtmlHxText elements, Added HtmlSelect/HtmlOption elements
- Loading branch information
1 parent
56d812b
commit 2a74183
Showing
6 changed files
with
511 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
using Windows.Foundation; | ||
using Windows.UI; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Media; | ||
using Uno.Extensions; | ||
using Uno.UI.Runtime.WebAssembly; | ||
|
||
namespace HtmlControls | ||
{ | ||
[HtmlElement("h1")] | ||
public partial class HtmlH1Text : FrameworkElement | ||
{ | ||
public HtmlH1Text() | ||
{ | ||
// Set a background to ensure pointer events are allowed | ||
Background = new SolidColorBrush(Colors.Transparent); | ||
|
||
// Avoid flicking while we're measuring the element | ||
this.SetCssStyle("overflow", "hidden"); | ||
} | ||
|
||
public static readonly DependencyProperty TextProperty = DependencyProperty.Register( | ||
"Text", typeof(string), typeof(HtmlH1Text), new PropertyMetadata("", propertyChangedCallback: OnTextChanged)); | ||
|
||
public string Text | ||
{ | ||
get => (string)GetValue(TextProperty); | ||
set => SetValue(TextProperty, value); | ||
} | ||
|
||
private static void OnTextChanged(DependencyObject o, DependencyPropertyChangedEventArgs args) | ||
{ | ||
if (o is HtmlH1Text element && args.NewValue is string text) | ||
{ | ||
element.SetHtmlContent(text); | ||
element.InvalidateMeasure(); | ||
} | ||
} | ||
|
||
protected override Size MeasureOverride(Size availableSize) | ||
{ | ||
// Delegate measurement to Html <progress> element | ||
return this.MeasureHtmlView(availableSize, false); | ||
} | ||
} | ||
|
||
[HtmlElement("h2")] | ||
public partial class HtmlH2Text : FrameworkElement | ||
{ | ||
public HtmlH2Text() | ||
{ | ||
// Set a background to ensure pointer events are allowed | ||
Background = new SolidColorBrush(Colors.Transparent); | ||
|
||
// Avoid flicking while we're measuring the element | ||
this.SetCssStyle("overflow", "hidden"); | ||
} | ||
|
||
public static readonly DependencyProperty TextProperty = DependencyProperty.Register( | ||
"Text", typeof(string), typeof(HtmlH2Text), new PropertyMetadata("", propertyChangedCallback: OnTextChanged)); | ||
|
||
public string Text | ||
{ | ||
get => (string)GetValue(TextProperty); | ||
set => SetValue(TextProperty, value); | ||
} | ||
|
||
private static void OnTextChanged(DependencyObject o, DependencyPropertyChangedEventArgs args) | ||
{ | ||
if (o is HtmlH2Text element && args.NewValue is string text) | ||
{ | ||
element.SetHtmlContent(text); | ||
element.InvalidateMeasure(); | ||
} | ||
} | ||
|
||
protected override Size MeasureOverride(Size availableSize) | ||
{ | ||
// Delegate measurement to Html <progress> element | ||
return this.MeasureHtmlView(availableSize, false); | ||
} | ||
} | ||
|
||
[HtmlElement("h3")] | ||
public partial class HtmlH3Text : FrameworkElement | ||
{ | ||
public HtmlH3Text() | ||
{ | ||
// Set a background to ensure pointer events are allowed | ||
Background = new SolidColorBrush(Colors.Transparent); | ||
|
||
// Avoid flicking while we're measuring the element | ||
this.SetCssStyle("overflow", "hidden"); | ||
} | ||
|
||
public static readonly DependencyProperty TextProperty = DependencyProperty.Register( | ||
"Text", typeof(string), typeof(HtmlH3Text), new PropertyMetadata("", propertyChangedCallback: OnTextChanged)); | ||
|
||
public string Text | ||
{ | ||
get => (string)GetValue(TextProperty); | ||
set => SetValue(TextProperty, value); | ||
} | ||
|
||
private static void OnTextChanged(DependencyObject o, DependencyPropertyChangedEventArgs args) | ||
{ | ||
if (o is HtmlH3Text element && args.NewValue is string text) | ||
{ | ||
element.SetHtmlContent(text); | ||
element.InvalidateMeasure(); | ||
} | ||
} | ||
|
||
protected override Size MeasureOverride(Size availableSize) | ||
{ | ||
// Delegate measurement to Html <progress> element | ||
return this.MeasureHtmlView(availableSize, false); | ||
} | ||
} | ||
|
||
[HtmlElement("h4")] | ||
public partial class HtmlH4Text : FrameworkElement | ||
{ | ||
public HtmlH4Text() | ||
{ | ||
// Set a background to ensure pointer events are allowed | ||
Background = new SolidColorBrush(Colors.Transparent); | ||
|
||
// Avoid flicking while we're measuring the element | ||
this.SetCssStyle("overflow", "hidden"); | ||
} | ||
|
||
public static readonly DependencyProperty TextProperty = DependencyProperty.Register( | ||
"Text", typeof(string), typeof(HtmlH4Text), new PropertyMetadata("", propertyChangedCallback: OnTextChanged)); | ||
|
||
public string Text | ||
{ | ||
get => (string)GetValue(TextProperty); | ||
set => SetValue(TextProperty, value); | ||
} | ||
|
||
private static void OnTextChanged(DependencyObject o, DependencyPropertyChangedEventArgs args) | ||
{ | ||
if (o is HtmlH4Text element && args.NewValue is string text) | ||
{ | ||
element.SetHtmlContent(text); | ||
element.InvalidateMeasure(); | ||
} | ||
} | ||
|
||
protected override Size MeasureOverride(Size availableSize) | ||
{ | ||
// Delegate measurement to Html <progress> element | ||
return this.MeasureHtmlView(availableSize, false); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Runtime.CompilerServices; | ||
using Windows.Foundation; | ||
using Windows.UI; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Media; | ||
using Uno.Extensions; | ||
using Uno.UI.Runtime.WebAssembly; | ||
|
||
namespace HtmlControls | ||
{ | ||
[HtmlElement("meter")] | ||
public partial class HtmlMeter : FrameworkElement | ||
{ | ||
public HtmlMeter() | ||
{ | ||
// Set a background to ensure pointer events are allowed | ||
Background = new SolidColorBrush(Colors.Transparent); | ||
} | ||
|
||
public static readonly DependencyProperty MinProperty = DependencyProperty.Register( | ||
"Min", typeof(double), typeof(HtmlMeter), new PropertyMetadata(0d, propertyChangedCallback: OnMinChanged)); | ||
|
||
public double Min | ||
{ | ||
get => (double)GetValue(MinProperty); | ||
set => SetValue(MinProperty, value); | ||
} | ||
|
||
private static void OnMinChanged(DependencyObject o, DependencyPropertyChangedEventArgs args) | ||
{ | ||
if (o is HtmlMeter meter && args.NewValue is double min) | ||
{ | ||
meter.SetAttribute("min", min.ToStringInvariant()); | ||
} | ||
} | ||
|
||
public static readonly DependencyProperty MaxProperty = DependencyProperty.Register( | ||
"Max", typeof(double), typeof(HtmlMeter), new PropertyMetadata(1.0d, propertyChangedCallback: OnMaxChanged)); | ||
|
||
public double Max | ||
{ | ||
get => (double)GetValue(MaxProperty); | ||
set => SetValue(MaxProperty, value); | ||
} | ||
|
||
private static void OnMaxChanged(DependencyObject o, DependencyPropertyChangedEventArgs args) | ||
{ | ||
if (o is HtmlMeter meter && args.NewValue is double max) | ||
{ | ||
meter.SetAttribute("max", max.ToStringInvariant()); | ||
} | ||
} | ||
|
||
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register( | ||
"Value", typeof(double), typeof(HtmlMeter), new PropertyMetadata(default(double), propertyChangedCallback: OnValueChanged)); | ||
|
||
public double Value | ||
{ | ||
get => (double)GetValue(ValueProperty); | ||
set => SetValue(ValueProperty, value); | ||
} | ||
|
||
private static void OnValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs args) | ||
{ | ||
if (o is HtmlMeter meter && args.NewValue is double value) | ||
{ | ||
meter.SetAttribute("value", value.ToStringInvariant()); | ||
} | ||
} | ||
|
||
protected override Size MeasureOverride(Size availableSize) | ||
{ | ||
// Delegate measurement to Html <meter> element | ||
return this.MeasureHtmlView(availableSize, false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Markup; | ||
using Uno.UI.Runtime.WebAssembly; | ||
|
||
namespace HtmlControls | ||
{ | ||
[HtmlElement("option")] | ||
[ContentProperty(Name = nameof(Content))] | ||
public partial class HtmlOption : UIElement | ||
{ | ||
public static DependencyProperty ContentProperty { get; } = DependencyProperty.Register( | ||
"ContentProperty", typeof(string), typeof(HtmlOption), new PropertyMetadata(null, OnContentChanged)); | ||
|
||
public string Content | ||
{ | ||
get => (string)GetValue(ContentProperty); | ||
set => SetValue(ContentProperty, value); | ||
} | ||
|
||
private static void OnContentChanged(DependencyObject o, DependencyPropertyChangedEventArgs args) | ||
{ | ||
if (o is HtmlOption option) | ||
{ | ||
if (args.NewValue is string str) | ||
{ | ||
option.ClearChildren(); | ||
option.SetHtmlContent(str); | ||
} | ||
} | ||
} | ||
|
||
public static DependencyProperty ValueProperty { get; } = DependencyProperty.Register( | ||
"ValueProperty", typeof(string), typeof(HtmlOption), new PropertyMetadata(null, OnValueChanged)); | ||
|
||
public string Value | ||
{ | ||
get => (string)GetValue(ValueProperty); | ||
set => SetValue(ValueProperty, value); | ||
} | ||
|
||
private static void OnValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs args) | ||
{ | ||
if (o is HtmlOption option) | ||
{ | ||
if (args.NewValue is string str) | ||
{ | ||
option.SetAttribute("value", str); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.