-- bug1.lua   20260503  S. Sieelr
--Purpose: Demonstrate odd text truncation problem

widget = require ("widget")

drills            = {}   -- see build_drills
max_drill_num     = 0    -- see build_drills

-----------------------------------------------------------------
function bh_explain_drill (event)

   local n

   if (event.phase == "ended") then
      n = event.target.n   -- get the drill# to explain

      t_comment.text = drills [n].longdesc

      print ("Note: t_comment.text = " ..  t_comment.text)
   end

   return true

end -- bh_explain_drill proc
-----------------------------------------------------------------
function build_drills ()

   drills = {}
   max_drill_num = 0

   max_drill_num = max_drill_num + 1 
   drills [max_drill_num] =
      {
       longdesc     = "Drill 1  FAILS.........\n" ..
                      "displayed.\n" ..
                      "You have to pick\n" ..
                      "the name of the card.\n" ..
                      "-----------",              -- good
       } 

   max_drill_num = max_drill_num + 1 
   drills [max_drill_num] =
      {
       longdesc     = "Drill 2  FAILS..................\n" ..
                      "Use your intuition to pick the\n" ..
                      "name that corresponds to that card.\n" ..
                      "-----------",               -- BAD
      } 
      -- NOTE: the above is displayed incorrectly on screen!

   max_drill_num = max_drill_num + 1 
   drills [max_drill_num] =
      {
       longdesc     = "Drill 3  FAILS..................\n" ..
                      "Use your intuition to pick the\n" ..
-- "more_text_really_long_123456789\n" ..   -- works
   "more_text_really_long_12345678\n" ..    -- FAILS!
                      "name that corresponds to that card.\n" ..
                      "-----------",               -- BAD
              }
--[[
NOTE: in the above, if you comment out "FAILS" and 
uncomment "works" (which is *longer*), then the 
text displays correctly!  That's *REALLY* weird!
]]

------------------

   max_drill_num = max_drill_num + 1 
   drills [max_drill_num] =
      {
       longdesc     = "Drill 4  works.............\n" ..
                      "is displayed.\n" ..
                      "You have to pick\n" ..
                      "the card (of those shown) that\n" ..
                      "corresponds to that number.\n" ..
                      "-----------",              -- good
       }

   max_drill_num = max_drill_num + 1 
   drills [max_drill_num] =
      {
       longdesc     = "Drill 5  works......\n" ..

--"1234567890123456789012\n" ..   -- doesn't fail
  "123456789012345678901\n" ..    -- doesn't fail

                      "You have to pick the number\n" ..
                      "that corresponds to that card.\n" .. -- BAD (Android, Mac;  'newline' after "to"
                      "-----------",                        -- BAD (Android, Mac; line missing)
      }

   end -- build_drills proc
-----------------------------------------------------------------
function initialize ()

   local x, y, dnum, dname, contH, startX, startY, fsize


   contH = math.floor (display.safeActualContentHeight)  
   startY = math.floor (display.safeScreenOriginY + 0.5) 
   startX = math.floor (display.safeScreenOriginX + 0.5)

   print (contH, startY)

   y = startY + 10  
   x = startX + 30

   fsize = 30

   for dnum = 1, max_drill_num do
      temp = display.newText ("(explain)", 
                              x, y, native.systemFont, fsize)
      temp.n = dnum
      temp:addEventListener ("touch", bh_explain_drill)
      temp.anchorX = 0

      y = y + 50
   end

   y = y + 50         -- small gap after last drill line

   t_comment = display.newText ("(explanation goes here)\n\n" .. 
                                 "Tap on each of the 'explain's!", 
                                x, y, native.systemFont, fsize)
   t_comment.anchorX = 0
   t_comment.anchorY = 0

   y = contH * 0.7 

   t_note = display.newText (
             "Note: *every* explanation\n" ..  
                "should end with a line of\n" .. "dashes!",
             x, y, native.systemFont, 40)
   t_note.anchorX = 0
   t_note.anchorY = 0

   end -- initialize proc
-----------------------------------------------------------------

build_drills ()

initialize ()

-- NOTE: you can comment out the "addEventListenter", and
-- just uncomment the following to see bug.  
-- Then, change "2" to "1" to see correct text.

-- bh_explain_drill ({phase = "ended", target = {n = 2}})

--//
