-- bug1.lua
--Purpose: Demonstrate odd text truncation problem

sversion = "20260502.2"

my_program_name = "bug1"

widget = require ("widget")


-- buttons, images, rectangles, text handles

b_drill           = nil
b_drill_plus      = nil
img_drill_boxes   = {}
t_drills          = {}
t_explain_drill   = nil
t_explain_drills  = {}
t_misc            = nil
t_note            = nil

-- global variables

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

      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
             } 

   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
              }

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

   t_explain_drill.text = drills [dnum].longdesc

   print ("Note: t_explain_drill.text = " ..  t_explain_drill.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

   t_drills = {}
   t_explain_drills = {}

   for dnum = 1, max_drill_num do
      dname = drills [dnum].name

      t_drills [dnum] = display.newText (dname, x, y, native.systemFont, fsize)
      t_drills [dnum].anchorX = 0

      t_drills [dnum].n = dnum

      t_explain_drills [dnum] = display.newText ("(explain)", centerX, y, native.systemFont, fsize)
      t_explain_drills [dnum].n = dnum
      t_explain_drills [dnum]:addEventListener ("touch", bh_explain_drill)
      t_explain_drills [dnum].anchorX = 0

      if dnum == 1 then
         h = t_drills [1].height
      end

      y = y + h + 8
   end

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

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

   y = contH * 0.5 

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

   end -- init_pick_drill proc
-----------------------------------------------------------------

build_drills ()

init_pick_drill ()

--//
