Replies: 3 comments 3 replies
-
I'm looking for something similar. For me personally also having it as part of the FormattedText Span implementation would be preferable, but having it as part of HtmlText would be workable. |
Beta Was this translation helpful? Give feedback.
-
Whilst this enhancement proposal/request is easily understood, enhancing Label would almost definitely require a non trivial change. If you read the Label documentation https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/label?view=net-maui-8.0 it describes the HTML limitations and it offers alternatives: Important Displaying HTML in a Label is limited to the HTML tags that are supported by the underlying platform. For example, Android supports only a subset of HTML tags, focusing on basic styling and formatting for block level elements such as Here's a <WebView HeightRequest="50">
<WebView.Source>
<HtmlWebViewSource Html="<sup>1</sup>Almost every developer's favorite molecule is C<sub>8</sub>H<sub>10</sub>N<sub>4</sub>O<sub>2</sub>, also known as "caffeine."" />
</WebView.Source>
</WebView> Here's a <Label>
<Label.FormattedText>
<FormattedString>
<Span FontSize="12">1</Span>
<Span>Almost every developer's favorite molecule is C</Span>
<Span FontSize="12">8</Span>
<Span>H</Span>
<Span FontSize="12">10</Span>
<Span>N</Span>
<Span FontSize="12">4</Span>
<Span>O</Span>
<Span FontSize="12">2</Span>
<Span>, also known as "caffeine."</Span>
</FormattedString>
</Label.FormattedText>
</Label> Here's an example of <FlexLayout>
<FlexLayout.Resources>
<ResourceDictionary>
<Style TargetType="Label">
<Setter Property="FontSize" Value="12" />
</Style>
<Style x:Key="sub" TargetType="Label">
<Setter Property="FontSize" Value="10" />
<Setter Property="VerticalOptions" Value="End" />
<Setter Property="TranslationY" Value="4" />
</Style>
<Style x:Key="sup" TargetType="Label">
<Setter Property="FontSize" Value="10" />
<Setter Property="VerticalOptions" Value="Start" />
<Setter Property="TranslationY" Value="-4" />
</Style>
</ResourceDictionary>
</FlexLayout.Resources>
<Label Style="{StaticResource sup}" Text="1" />
<Label Text="Almost every developer's favorite molecule is C" />
<Label Style="{StaticResource sub}" Text="8" />
<Label Text="H" />
<Label Style="{StaticResource sub}" Text="10" />
<Label Text="N" />
<Label Style="{StaticResource sub}" Text="4" />
<Label Text="O" />
<Label Style="{StaticResource sub}" Text="2" />
<Label Text=", also known as "caffeine."" />
</FlexLayout> |
Beta Was this translation helpful? Give feedback.
-
Unicode has blocks for superscripts and subscripts.
with a single <Label Text="¹Almost every developer's favorite molecule is C₈H₁₀N₄O₂ also known as "caffeine."" /> To get an idea of how you may generalize this for maths, is you can write public static char Sup(char ch) => ch switch
{
'0' => '⁰',
'1' => '¹',
'2' => '²',
'3' => '³',
'4' => '⁴',
'5' => '⁵',
'6' => '⁶',
'7' => '⁷',
'8' => '⁸',
'9' => '⁹',
_ => ch
};
public static char Sub(char ch) => ch switch
{
'0' => '₀',
'1' => '₁',
'2' => '₂',
'3' => '₃',
'4' => '₄',
'5' => '₅',
'6' => '₆',
'7' => '₇',
'8' => '₈',
'9' => '₉',
_ => ch
}; While every digit is covered, as shown above, when it comes to the alphabet there were intentional gaps in the Unicode blocks meaning that you're not guaranteed that every character in the alphabet has a superscript or subscript. Therefore, this strategy may or may not work for you. [Added/Remove/Added again] The other idea I had was 3 fonts. One which is the normal font. Another is a font containing the alphanumerics positioned in a superscript way. And lastly a set of alphanumerics position in a subscript way. |
Beta Was this translation helpful? Give feedback.
-
Description
It would be really nice if XAML labels supported the HTML tags sub and sup. This is essential in technical apps in particular.
Public API Changes
Intended Use-Case
I am creating an app for complex calculations for a customer and the known names almost always have subscripts.
Beta Was this translation helpful? Give feedback.
All reactions