【问题标题】:How do I calculate the location of the selectedText with a LiveCode field?如何使用 LiveCode 字段计算 selectedText 的位置?
【发布时间】:2013-03-08 05:52:05
【问题描述】:

我想滚动字段,以便在调整大小后可以看到选择。为此,我需要计算所选字段顶部的高度,然后偏移当前滚动以计算出新滚动。我不能假设一个固定的LineHeight。谁有线索?

【问题讨论】:

  • Gian 感谢您的编辑,但这不是 iOS 特定的。 LiveCode 是跨平台的。不幸的是,还没有 LiveCode 标签。

标签: ios user-experience livecode


【解决方案1】:

在字典中搜索后,我找到了 selectedLoc 函数。我最终在每次调整字段大小后执行了以下代码,这给出了我想要的行为。

   put item 2 of the selectedLoc-the scroll of pField into tSelectionHeight
   if tSelectionHeight > the scroll of pField+the height of pField then
      set the scroll of pField to tSelectionHeight-the height of pField
   end if

【讨论】:

    【解决方案2】:

    如果没有选定的位置,以下方法也有效。我在 PowerDebug 中使用它来将断点或当前代码行置于调试窗口的中心。 (是的,我意识到我假设 lineheight 在现场是一致的)。

    command CenterDebugText pLinesToHilite
      local tLineHeight, tFieldHeight
      local tScroll
    
      lock screen
      set the hilitedlines of field kDebugFieldName of me to pLinesToHilite
      -- center the breakpoint line in the display
    
      -- calculate the number of visible script lines
      put the effective textheight of field kDebugFieldName into tLineHeight
      put the height of field kDebugFieldName into tFieldHeight
    
      put tLineHeight * (item 1 of pLinesToHilite) into tScroll
      subtract tFieldHeight / 2 from tScroll
      set the vscroll of field kDebugFieldName to trunc(tScroll)
      unlock screen
    end CenterDebugText
    

    【讨论】:

    • 技术不错。用listBehavior设置字段的hilitedLines后是否没有selectedLoc?我认为 selectedLines 和 hilitedLines 几乎是同义词(如果 noncontiguousHilites 为真,则行为略有不同)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 2020-04-02
    相关资源
    最近更新 更多