Bug 4132 - Monotouch.Dialog MultilineElement Cutting Off Last Line
Summary: Monotouch.Dialog MultilineElement Cutting Off Last Line
Status: RESOLVED DUPLICATE of bug 3529
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 5.2
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-03-28 15:12 UTC by Justin Hansen
Modified: 2012-03-29 10:32 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Text that is read into StreamReader. (878 bytes, text/plain)
2012-03-28 15:12 UTC, Justin Hansen
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED DUPLICATE of bug 3529

Description Justin Hansen 2012-03-28 15:12:57 UTC
Created attachment 1593 [details]
Text that is read into StreamReader.

When I read in a text document and display the content in a MultilineElement it cuts off the last line.

  sr = new StreamReader("Terms.txt");
  string termText = sr.ReadToEnd();
  RootElement terms = new RootElement("Terms and Conditions");
  Section termSection = new Section(String.Empty);
  MultilineElement element = new MultilineElement(termText);
  termSection.Add(element);
  terms.Add(termSection);

The text file is attached.
Comment 1 Justin Hansen 2012-03-28 15:19:57 UTC
I am not sure about the exact version number of Monotouch but I know it is the latest stable release.
Comment 2 Sebastien Pouliot 2012-03-28 15:50:13 UTC
FYI the MonoTouch version number is shown in MonoDevelop "Application Output" pad on each build. 

You can also get it (along with the build #) from the terminal using the following command.

    /Developer/MonoTouch/usr/bin/mtouch --version

Finally the most useful is to get it from "MonoDevelop" menu, "About MonoDevelop" item, "Version Info" tab and copy/paste the version informations (at least down to the "Loaded assemblies" section).
Comment 3 Justin Hansen 2012-03-28 15:52:29 UTC
The version is 5.2.10, thanks.
Comment 4 Sebastien Pouliot 2012-03-28 16:37:05 UTC
There's something wrong with the multi-line computations.

The two last words "written permission." are cut from the element when executed on an iPod/iPhone.

However the element is twice the required height when executed on an iPad.
Comment 5 Sebastien Pouliot 2012-03-28 16:57:03 UTC
The issue (for iPod/iPhone) seems to be that the size computation uses "Helvetica" 17.0 for font while the TextLabel.Font is using "Helvetica-Bold" 17.0. Changing the computation to Bold fix the issue (at least for this case).
Comment 6 Sebastien Pouliot 2012-03-28 17:15:40 UTC
The width is hardcoded to 280 pixels when calculating :-) so this expand the height by about 2. I'll cook a patch for both cases later (after diner :-)

Thanks for the report!
Comment 7 Sebastien Pouliot 2012-03-28 19:03:09 UTC
This fix the font (calculated versus rendered), margin difference (iPad versus iPhone) and orientation issues I found.

diff --git a/MonoTouch.Dialog/Elements.cs b/MonoTouch.Dialog/Elements.cs
index ee30808..c6dd278 100644
--- a/MonoTouch.Dialog/Elements.cs
+++ b/MonoTouch.Dialog/Elements.cs
@@ -1017,8 +1017,9 @@ namespace MonoTouch.Dialog
                
                public virtual float GetHeight (UITableView tableView, NSIndexPath indexPath)
                {
-                       SizeF size = new SizeF (280, float.MaxValue);
-                       using (var font = UIFont.FromName ("Helvetica", 17f))
+                       float margin = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone ? 40f : 110f;
+                       SizeF size = new SizeF (tableView.Bounds.Width - margin, float.MaxValue);
+                       using (var font = UIFont.FromName ("Helvetica-Bold", 17f))
                                return tableView.StringSize (Caption, font, size, UILineBreakMode.WordWrap).Height + 10;
                }
        }
Comment 8 Sebastien Pouliot 2012-03-28 20:41:45 UTC
The patch from bug #3529 is a superset of this one.
c.c. Miguel
Comment 9 Justin Hansen 2012-03-28 21:00:17 UTC
I'm currently using the built in Monotouch.Dialog library, do I now need to use the outside one to implement this patch? If not how do I incorporate it?
Comment 10 Sebastien Pouliot 2012-03-29 10:32:41 UTC
Fixed with the patch from bug #3529

Justin, you can either:

a) update to MonoTouch 5.2.11 (stable) when available (or 5.3.3 unstable);

b) use the MT.D code from GIT (the patch for #3529 is already there, 03966b49606e7f1a3cc6a4e8f97c7ba12f5e160c); or 

c) you can create your own, e.g. MyMultilineElement, and override GetHeight to use the code from comment #7.

*** This bug has been marked as a duplicate of bug 3529 ***