【问题标题】:Dynamic text size resizing to fit the entire text line into a text field动态调整文本大小以使整个文本行适合文本字段
【发布时间】:2014-07-17 04:10:43
【问题描述】:

我有大约 640 条不同长度的文本行,它们既可以作为数据网格中的列表查看,也可以在单行视图中查看。在单行视图中,我想调整文本行的字体大小,以便它

  1. 完全适合文本字段

  2. 最大磅数为 24,最小磅数为 10(我已在文本字段中设置了自定义属性)。

我在单行视图卡中使用如下代码:

on resizeText

 ## Check if the text fits in the field
 put the textSize of fld "foneline" into tTextSize
 if the formattedHeight of fld "foneline" > the height of fld "foneline" then

 ## Make the text smaller until it fits
 repeat until the formattedHeight of fld "foneline" <= the height of fld "foneline" 
   subtract 1 from tTextSize

  ## Check that the text size is not less that the minimum size       
  if tTextSize >= the cMinimumTextSize of fld "foneline" then     
       set the textSize of fld "foneline" to tTextSize      
  else         
   exit repeat       
  end if    
  end repeat  
 else if the formattedHeight of fld "foneline" < the height of fld "foneline" then

  ## Make the text as large as possible    
 repeat until the formattedHeight of fld "foneline" >= the height of fld "foneline"      
   add 1 to tTextSize         

  ## Check that the text size is not bigger that the maximum size      
   if tTextSize<= the cMaximumTextSize of fld "foneline" then       
     set the textSize of fld "foneline" to tTextSize      
  else        
    exit repeat       
  end if     
 end repeat  
 end if
end resizeText

以及该卡片上“上一个”和“下一个”按钮的代码中的 resizeText 命令。

但是,显示的代码中存在一些小故障或错误,我希望您可以按照以下步骤复制:

  1. 打开堆栈

  2. 点击“全选”按钮

  3. 点击“线条”按钮

  4. 点击“下一步”按钮,直到看到第 6 行(全长可见)。

  5. 再次单击“下一步”按钮,您将看到第 7 行,但该行不完全可见(您会看到右引号“不存在)

  6. 点击“Next”按钮,然后点击“Previous”按钮 - 这将带您回到现在可以看到完整长度的第 7 行!

  7. 现在点击“Previous”按钮,第 6 行可见,但这次不是完整长度

  8. 点击“上一个”,再次点击“下一个”,现在第 6 行已经全长了

  9. 单击“下一步”,第 7 行再次完全不可见。

如果您无法使用上述行号复制此内容,请尝试继续单击“下一步”按钮,直到遇到缺少结束“引号”的行,这表示该行已被切断。然后按照与上面单击“上一个”和“下一个”按钮相同的过程。这听起来可能很复杂,但是一旦打开堆栈,就很容易找出错误的行为。类似的情况是:83-84-85 行;48-49;51-52。 我的堆栈的链接是DG-only-1.16_cut-off-lines.zip

如何更正代码,使其始终显示每一行而不切断它的结尾?

【问题讨论】:

    标签: textfield livecode text-formatting


    【解决方案1】:

    在您的“resizeText”处理程序中:如果格式化的高度小于该字段,则将文本的大小调整得更大,直到 >= formattedHeight。这意味着当它的高度大于要求时,循环有时会停止。通过在字体大小增加时添加最终高度检查,我们可以避免这种情况;

    on resizeText
       ## Check if the text fits in the field
       put the textSize of fld "foneline" into tTextSize
       put the height of fld "foneline"  into tHeight
    
       if the formattedHeight of fld "foneline" > tHeight then
          ## Make the text smaller until it fits
          repeat until the formattedHeight of fld "foneline" <= tHeight 
             subtract 1 from tTextSize
    
             ## Check that the text size is not less that the minimum size
             if tTextSize >= the cMinimumTextSize of fld "foneline" then
                set the textSize of fld "foneline" to tTextSize
             else
                exit repeat
             end if
          end repeat      
       else if the formattedHeight of fld "foneline" < tHeight then
          ## Make the text as large as possible
          repeat until the formattedHeight of fld "foneline" >= tHeight
             add 1 to tTextSize
    
             ## Check that the text size is not bigger that the maximum size
             if tTextSize<= the cMaximumTextSize of fld "foneline" then
                set the textSize of fld "foneline" to tTextSize
             else
                exit repeat
             end if
          end repeat
    
          # check the final field height
          if the formattedHeight of fld "foneline" > tHeight then
             subtract 1 from tTextSize
             set the textSize of fld "foneline" to tTextSize
          end if
       end if
    end resizeText
    

    【讨论】:

      猜你喜欢
      • 2011-09-03
      • 2015-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-29
      • 1970-01-01
      • 2013-05-31
      • 2011-11-24
      相关资源
      最近更新 更多