54 views
in GUI Development by
Hi Team,

I want to do a modification to a specific row. It can be done using GetRowString(). After a modification to a specific row, how can we insert that modified row to the actual text?. Please explain.

 

Regards,

Sazna.

1 Answer

0 votes
by

Hello Sazna,

please see the section Arrange other views on the content of the Text view. It explains diverse methods of the Text view you can use to evaluate the text layout and calculate the string portions corresponding to text rows. Especially note the method RowCol2StringIndex(). Using this method you could implement following code to replace the content of some row aRowNo in the text view aTextView. Please note, rows are counted starting with 0:

// Calculate the start/end position for the row in the original string.
var int32  start = aTextView.RowCol2StringIndex( point( 0, aRowNo ));
var int32  end   = aTextView.RowCol2StringIndex( point( 0, aRowNo + 1 ));

// In the original string remove the character sequence representing the
// requested row and then insert at this position the new content. Finally
// assign the result to the Text view.
aTextView.String = aTextView.String.remove( start, end - start ).
                                    insert( aNewString, start );

I hope it helps you further.

Best regards

Paul Banach

by

Hi Paul,

Thank you for the answer. Actually my requirement is to have a set of instructions as a one text view where each instruction should start with a bullet point. The adjacent rows of each row which contains bullet points must align with the previous row's first letter. For this purpose I am using loop to iterate through all rows and adding the modification wherever required. 

Here is the code:

var int32 count = DiscriptionText.GetNoOfRows();
var int32 i;
var string rowString;

for (i = 0 ; i < count ; i++)
{
    rowString =  DiscriptionText.GetRowString( i );

    if (rowString.find( "•", 0 ) < 0)
    {
      rowString = "   " + rowString;
    }
    else
    {
     //do nothing
    }

}

 If I add-in the above implementation you mentioned within this loop it runs continuously. I have added this function for the text view's onUpdate slot method as my application supports for multi language.

Here it is the actual view

 

How this code can be modified with your solution you mentioned above?. Or is there anyway to achieve this feature? Please assist on this.

Regards,

Sazna.

by

Hello Sazna,

You have to assign the resulting string back to the DescriptionText view. This is missing in your actual implementation. From your example I have understood, that you only want to prefix the existing content instead of replacing it. In such case following could be helpful:

rowString =  DiscriptionText.GetRowString( i );

if (rowString.find( "•", 0 ) < 0)
{
  var int32 start = DiscriptionText.RowCol2StringIndex( point( 0, i ));
  DiscriptionText.String = DiscriptionText.String.insert( "   ", start );
}

However, the above solution is unnecessary complicated for your application case. It has also the disadvantage of each modification causing the view to update its layout. In worst case, after you have modified a text row, the layout of following rows may change. This also may affect the number of rows.

From your description I have understood that you want to prefix the bullet points only. In such case I see other approach: Preprocess the original string before it is assigned to the view so that every bullet point sign is prefixed with the desired sequence of white space characters.

I would also recommend other approach using the Attributed Text view. This view is ideal to display structured text. In your case you can consider each text fragment starting with a bullet point as a 'paragraph'. With Attributed Text view you can configure the margins of each paragraph. See also the section Configure paragraph margins.

I hope it helps you further.

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...