View Issue Details

IDProjectCategoryView StatusLast Update
0001963NoesisGUIC++ SDKpublic2022-11-11 17:48
Reportersfernandez Assigned Tomaherne  
PrioritynormalSeverityfeatureReproducibilityhave not tried
Status resolvedResolutionfixed 
Product Version3.0.11 
Target Version3.1.6Fixed in Version3.1.6 
Summary0001963: Create a RichTextFormatterBehavior or attached property
DescriptionCreate a behavior or attached property that automatically parses an "html" formatted string
"< b >Lorem ipsum dolor sit amet, </ b > consectetur < i >adipiscing</ i > elit."

 and generates the corresponding inlines for a TextBlock.

<TextBlock>
  <Bold>Lorem ipsum dolor sit amet, </Bold> consectetur <Italic>adipiscing</Italic> elit.
</TextBlock>

TagsNo tags attached.
PlatformAny

Relationships

related to 0002355 resolvedmaherne Implement an official localization solution 

Activities

sfernandez

sfernandez

2021-06-17 11:24

manager   ~0007301

Last edited: 2021-06-17 11:33

The easiest and simplest way to expose this is through an attached property. We already provide some extensions in the Text class like noesis:Text.Placeholder, so we can add a new one for this:

<TextBlock noesis:Text.RichText="This is an [b]example[/b] of rich text"/>


sgonchar

sgonchar

2021-09-27 19:24

reporter   ~0007482

Last edited: 2021-09-27 19:25

Hello, wondering if we can get an ETA on this?

jsantos

jsantos

2021-09-28 16:51

manager   ~0007488

We had to remove this from 3.0.X because stabilizing 3.1.X has become the top priority.

Also, this feature is going to be an example in the Application framework, I am not even sure if the syntax we are going to use will be what you need (we are considering using something like markdown) or even if it will have all the features you need.

So probably we could have a call about this, we can provide a minimal template that you can improve.

Or wait for our example, but I am pretty sure you will add modifications.
sfernandez

sfernandez

2021-11-02 11:44

manager   ~0007553

Last edited: 2021-11-02 11:45

The idea is having an attached property:

<TextBlock local:TextHelpers.FormattedText="To [B]shoot[/B] something, hold [INPUT:AIM_WEAPON] and then press [INPUT:FIRE_GUN]."/>


With a property changed callback that processes the original string and generates the corresponding inlines, something like this:

static void OnFormattedTextChanged(DependencyObject* d, const DependencyPropertyChangedEventArgs& e)
{
    TextBlock* textBlock = DynamicCast<TextBlock*>(d);
    if (textBlock != nullptr)
    {
      InlineCollection* inlines = textBlock->GetInlines();
      inlines->Clear();

      const String& str = e.NewValue<String>();
      Vector<Token> tokens = ParseFormattedText(str.Str());
      for (Token token: tokens)
      {
        switch (token.type)
        {
          case TokenType_Run:
            inlines->Add(MakePtr<Run>(token.text.Str()));
            break;
          case TokenType_Bold:
            inlines->Add(MakePtr<Bold>(MakeRun<Run>(token.text.Str())));
            break;
          case TokenType_Image:
            Ptr<Image> image = MakePtr<Image>();
            image->SetSource(token.imageSource);
            inlines->Add(MakePtr<InlineUIContainer>(image));
            break;
          ...
        }
      }
    }
}


sfernandez

sfernandez

2022-05-26 13:20

manager   ~0007942

We can extend this even with support for generating bindings automatically, for example, given the following formatted string:

The cost of fuel is: [b]{Fuel.Cost}[/b]


We can generate something like this:

<TextBlock>
  <Run Text="The cost of fuel is:"/>
  <Bold><Run Text="{Binding Fuel.Cost}"/></Bold>
</TextBlock>


That will automatically bind to the TextBlock data context.
sfernandez

sfernandez

2022-07-01 11:31

manager   ~0008007

Related to this forum post: https://www.noesisengine.com/forums/viewtopic.php?p=14304&hilit=1963#p14253
maherne

maherne

2022-07-11 16:51

developer   ~0008016

We have created an example RichText attached property, which will be included in an upcoming release. I've attached the example here in case you wish to start using it.

This example is ready for use in production, and can be easily modified to support new BBCode tags.

Documentation for use of the attached property, and for extending the BBCode tag support, can be found in comments within the RichText.h and RichText.cpp files.
maherne

maherne

2022-07-12 12:20

developer   ~0008017

Updated example, with an XML namespace correction.

Issue History

Date Modified Username Field Change
2021-04-09 18:20 sfernandez New Issue
2021-04-09 18:20 sfernandez Assigned To => jsantos
2021-04-09 18:20 sfernandez Status new => assigned
2021-04-09 18:20 sfernandez Description Updated
2021-04-12 10:52 jsantos Target Version => 3.0.12
2021-05-04 02:41 jsantos Target Version 3.0.12 => 3.0.13
2021-06-17 11:24 sfernandez Note Added: 0007301
2021-06-17 11:33 sfernandez Note Edited: 0007301
2021-09-27 19:24 sgonchar Note Added: 0007482
2021-09-27 19:25 sgonchar Note Edited: 0007482
2021-09-28 16:51 jsantos Note Added: 0007488
2021-09-28 16:52 jsantos Status assigned => feedback
2021-11-02 11:44 sfernandez Note Added: 0007553
2021-11-02 11:44 sfernandez Status feedback => assigned
2021-11-02 11:45 sfernandez Note Edited: 0007553
2021-11-02 11:45 sfernandez Note Edited: 0007553
2022-05-26 13:20 sfernandez Note Added: 0007942
2022-07-01 11:31 sfernandez Note Added: 0008007
2022-07-08 14:17 sfernandez Relationship added related to 0002355
2022-07-08 14:17 sfernandez Assigned To jsantos => maherne
2022-07-11 16:51 maherne Note Added: 0008016
2022-07-11 16:51 maherne File Added: RichTextAttachedPropertyExample.zip
2022-07-12 12:19 maherne File Deleted: RichTextAttachedPropertyExample.zip
2022-07-12 12:20 maherne Note Added: 0008017
2022-07-12 12:20 maherne File Added: RichTextAttachedPropertyExample.zip
2022-11-02 11:50 jsantos Target Version => 3.1.6
2022-11-07 17:13 sfernandez Target Version 3.1.6 => 3.1.7
2022-11-07 17:26 sfernandez Target Version 3.1.7 => 3.1.6
2022-11-11 17:48 maherne Fixed in Version => 3.1.6
2022-11-11 17:48 maherne Status assigned => resolved
2022-11-11 17:48 maherne Resolution open => fixed