简体   繁体   English

在NSTextView中为线条片段重画一个矩形

[英]Redrawing a single rect for a line fragment in NSTextView

We have an NSTextView that needs to have single line fragments redrawn on certain events. 我们有一个NSTextView,需要在某些事件上重绘单行片段。

Essentially, it is an outline. 本质上,这是一个轮廓。 So when a particular line gets the message "tab out", we want to move the rect containing the glyphs rather than just inserting the tab key. 因此,当特定行收到消息“跳出”时,我们想移动包含字形的矩形,而不是仅插入跳出键。

Any ideas of how to accomplish this? 关于如何实现此目标的任何想法?

Thanks! 谢谢!

I've watched this for any suggestions but nobody seems to be taking it. 我已经看过了任何建议,但似乎没人接受。

If I understand you correctly, I'd urge you not to try messing around with the text view's drawing routines, especially when the Cocoa text system has so many hooks at so many levels? 如果我对您的理解正确,我敦促您不要尝试弄乱文本视图的绘制例程,尤其是当Cocoa文本系统在这么多层次上有如此多的钩子时?

This is essentially a paragraph-level formatting problem, isn't it? 这本质上是一个段落级的格式化问题,不是吗? Why not just set the paragraph's NSParagraphStyle ? 为什么不只设置段落的NSParagraphStyle呢? You can do this by setting its headIndent, which is the margin ahead of the beginning of the user's language's sweep path (left-to-right, top-to-bottom, etc.). 您可以通过设置其headIndent来做到这一点,headIndent是用户语言的扫描路径(从左到右,从上到下等)开头的边距。

You can intercept -insertTab: and -insertBacktab: using NSTextView's -textView:doCommandBySelector: delegate method and take that as your cue to modify the paragraph style to indent as far as you want. 您可以使用NSTextView的-textView:doCommandBySelector:委托方法截获-insertTab:和-insertBacktab:,并将其作为修改段落样式以尽可能缩进的提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM