Skip to content

Commit

Permalink
Improved paging on DialogBox
Browse files Browse the repository at this point in the history
Added dialog box tests.
  • Loading branch information
vchelaru committed Feb 23, 2024
1 parent 719a42e commit 68f7992
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ protected override void ReactToVisualChanged()
/// <param name="frbLayer">The FlatRedBall Layer to add the DialogBox to. If null, the dialog box will not be layered. This will attempt to use a Gum layer matching the FRB layer. This will automatically work if the Layer has been added through the FlatRedBall Editor.</param>
public void Show(string text, FlatRedBall.Graphics.Layer frbLayer = null)
{
base.Show(frbLayer);
showNextPageOnDismissedPage = true;
ShowInternal(text, forceImmediatePrint:false);
var pages = ConvertToPages(text);
Show(pages, frbLayer);
}

public void Show(IEnumerable<string> pages, FlatRedBall.Graphics.Layer frbLayer = null)
Expand Down Expand Up @@ -206,7 +205,7 @@ public async Task ShowAsync(IEnumerable<DialogPageTask> pageTasks, FlatRedBall.G
// have ShowDialog? Is it
// to match the ShowDialog
// from the base FrameworkElement?
// If so, what's the poinnt because
// If so, what's the point because
// this doesn't override the base parameters.
// It requires pages.
[Obsolete("Use ShowAsync")]
Expand Down Expand Up @@ -404,13 +403,15 @@ private string[] ConvertToPages(string text)
var withRemovedTags = BbCodeParser.RemoveTags(text, foundTagsWithNewlines);

var unlimitedLines = new List<string>();
var oldVerticalMode = this.coreTextObject.TextOverflowVerticalMode;
this.coreTextObject.TextOverflowVerticalMode = RenderingLibrary.Graphics.TextOverflowVerticalMode.SpillOver;
var oldVerticalMode = this.textComponent.TextOverflowVerticalMode;
this.textComponent.TextOverflowVerticalMode = RenderingLibrary.Graphics.TextOverflowVerticalMode.SpillOver;
coreTextObject.RawText = withRemovedTags;
coreTextObject.UpdateLines(unlimitedLines);

this.coreTextObject.TextOverflowVerticalMode = oldVerticalMode;
this.textComponent.TextOverflowVerticalMode = RenderingLibrary.Graphics.TextOverflowVerticalMode.TruncateLine;

this.textComponent.SetProperty("Text", withRemovedTags);
this.textComponent.TextOverflowVerticalMode = oldVerticalMode;

var limitedLines = coreTextObject.WrappedText;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@
<Variable>
<Type>float</Type>
<Name>DialogBoxInstance.X</Name>
<Value xsi:type="xsd:float">12</Value>
<Value xsi:type="xsd:float">325</Value>
<SetsValue>true</SetsValue>
</Variable>
<Variable>
<Type>float</Type>
<Name>DialogBoxInstance.Y</Name>
<Value xsi:type="xsd:float">17</Value>
<Value xsi:type="xsd:float">15</Value>
<SetsValue>true</SetsValue>
</Variable>
<Variable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,26 @@ private void TestDialogBoxPaging()
var dialogBox = Forms.DialogBoxInstance;

var styledString =
"This is [Color= Orange]some really[/ Color] long[Color = Pink] text[/ Color]. [Color= Purple]We[/ Color] want to show long text so that it line wraps[Color = Cyan]and[/ Color] so that it has[Color = Green]enough[/ Color] text to fill an[Color = Yellow]entire page[/ Color]. The DialogBox control should automatically detect if the text is too long for a single page and it should break it up into multiple pages.You can advance this dialog by clicking on it with the[Color = Blue]mouse[/ Color] or by pressing the[Color = Gold]space bar[/ Color] on the keyboard.";
"This is [Color=Orange]some really[/Color] long[Color=Pink] text[/Color]. " +
"[Color=Purple]We[/Color] want to show long text so that it line wraps[Color=Cyan] " +
"and[/Color] so that it has [Color=Green]enough[/Color] text to fill an " +
"[Color=Yellow]entire page[/Color]. The DialogBox control should automatically " +
"detect if the text is too long for a single page and it should break it up into " +
"multiple pages.You can advance this dialog by clicking on it with the " +
"[Color=Blue]mouse[/Color] or by pressing the [Color=Gold]space bar[/Color] " +
"on the keyboard.";
dialogBox.LettersPerSecond = null;

var gumObject = dialogBox.Visual;
var gue = gumObject.GetGraphicalUiElementByName("TextInstance");
gue.TextOverflowVerticalMode = RenderingLibrary.Graphics.TextOverflowVerticalMode.TruncateLine;
dialogBox.Show(styledString);

var gumObject = dialogBox.Visual;
var textRenderable = gumObject.GetGraphicalUiElementByName("TextInstance").Component as RenderingLibrary.Graphics.Text;
// As of Feb 22, 2024 this is an old .glux so it doesn't codegen the height limit:

var textRenderable = gue.Component as RenderingLibrary.Graphics.Text;

textRenderable.WrappedText.Count.ShouldBe(6);
textRenderable.WrappedText.Count.ShouldBe(5);

}

Expand Down Expand Up @@ -185,7 +197,7 @@ private void TestRadioButtonSelected()

void CustomActivity(bool firstTimeCalled)
{
IsActivityFinished = true;
//IsActivityFinished = true;

}

Expand Down

0 comments on commit 68f7992

Please sign in to comment.