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

widget = require ("widget")

b80_base_filename = "b80_base.png"
b80_over_filename = "b80_over.png"
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

      explain_drill (n)
   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] =
             {
              name         = "GOOD DRILL 1",
              desc         = "Tap name of this card:",
              longdesc     = "The number of a card is\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] =
             {
              name         = "BAD DRILL 2",
              desc         = "Tap name for this card:",
              longdesc     = "The back of a card is displayed.\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] =
             {
              name         = "odd DRILL 3",
              desc         = "Tap name for this card:",
              longdesc     = "The back of a card is displayed.\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!

   end -- build_drills proc
-----------------------------------------------------------------
function explain_drill (dnum)

   t_comment.text = drills [dnum].longdesc

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

end -- explain_drill proc
-----------------------------------------------------------------
function init_pick_drill ()

   local x, y, h, dnum, dname
   local contH, contW, startX, startY, centerX, centerY
   local fsize
   local int


   int = math.floor

   contH = int (display.safeActualContentHeight)   -- was: display.contentHeight
   contW = int (display.safeActualContentWidth)   -- was: display.contentWidth

         -- round up, because rounding down might move off screen
   startY = int (display.safeScreenOriginY + 0.5)   -- typically 0 or 40, sometimes bigger
   startX = int (display.safeScreenOriginX + 0.5)   -- almost always 0

   centerX = int (contW / 2) + int (display.safeScreenOriginX)
   centerY = int (contH / 2) + int (display.safeScreenOriginY)

   print (contH, contW, startY, centerX, centerY)

   fsize= 30

   y = startY + 10   -- can't recall if display.safeScreenOriginY is after the top line of icons/time/battery
   x = startX + 10
   h = 40

   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 + h + 8
   end

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

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

   y = contH * 0.5 

   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 -- init_pick_drill proc
-----------------------------------------------------------------

build_drills ()

init_pick_drill ()

--//
