從here報價:我如何理解以下內容?
if (to_end)
{
/* If we want to scroll to the end, including horizontal scrolling,
* then we just create a mark with right gravity at the end of the
* buffer. It will stay at the end unless explicitely moved with
* gtk_text_buffer_move_mark.
*/
gtk_text_buffer_create_mark (buffer, "end", &iter, FALSE);
/* Add scrolling timeout. */
return g_timeout_add (50, (GSourceFunc) scroll_to_end, textview);
}
else
{
/* If we want to scroll to the bottom, but not scroll horizontally,
* then an end mark won't do the job. Just create a mark so we can
* use it with gtk_text_view_scroll_mark_onscreen, we'll position it
* explicitely when needed. Use left gravity so the mark stays where
* we put it after inserting new text.
*/
gtk_text_buffer_create_mark (buffer, "scroll", &iter, TRUE);
/* Add scrolling timeout. */
return g_timeout_add (100, (GSourceFunc) scroll_to_bottom, textview);
}
雖然有意見相當多的線,我還是不明白其中的邏輯,特別是,什麼是馬克和滾動的位置之間的關係吧?
UPDATE
看來,我這個評論誤導:
/* and place the mark at iter. the mark will stay there after we
* insert some text at the end because it has right gravity.
*/
說了,scroll
商標已經離開重力,不右重力,是這樣嗎?
但是我沒有看到爲什麼'mark'必須是左**或**右**重力的原因。你能解釋一下嗎? – Gtker 2010-05-01 16:57:57
如果在同一行上添加了文本,「標記」的「重力」控制着「標記」被重新定位到的位置,也就是說,'左'重力將位於文本的左側,而'右'把它放在文本的右邊。就個人而言,似乎是一個相當鈍的命名方案。 – Kitsune 2010-05-01 17:03:38
我不這麼認爲。 'mark'似乎只是緩衝區中的一個點,您可以稍後使用它來滾動(或至少記住以備後用)。 – Kitsune 2010-05-01 17:16:06