如何(编程)滚动到gtktextview / gtksourceview特定行 [英] how to (programmatically) scroll to a specific line in gtktextview/gtksourceview

查看:563
本文介绍了如何(编程)滚动到gtktextview / gtksourceview特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个文本编辑器越来越熟悉C和GTK +的一种方式。我使用GTK + -2.0&安培; gtksourceview-2.0,和gtk_scrolled_window。截至创建跳转功能浏览器第一次尝试我想我只是简单地创建的文档,并在它们发生线中对应的数组中发现一个函数数组。我有多少事。我很惊讶地发现,有没有goto线的能力,我可以在devhelp很容易找到。这听起来像gtk_text_view_scroll_to_mark()就是我想要的(创建一个标记后),但所有的* scroll_to功能需要一个within_margin,这说实话我真的不明白:

I am creating a text editor as a way of getting more familiar with C and gtk+. I am using gtk+-2.0 & gtksourceview-2.0, and gtk_scrolled_window . As a first attempt at creating a goto function browser I thought I would just simply create an array of functions found in the document and a corresponding array of lines on which they occur. I have that much done. I was surprised to find that there is no goto line capability that I can easily find in devhelp. It sounds like gtk_text_view_scroll_to_mark () is what I want (after creating a mark), but all the *scroll_to functions require a within_margin, which to be honest I don't really understand.:

从devhelp:

此功能的目的,有效画面被大小within_margin的大幅降低。

The effective screen for purposes of this function is reduced by a margin of size within_margin.

这是什么意思?

我是差得远了?如何创建这样滚动行号的功能?

Am I even close? How can I create this scroll to line number functionality?

感谢。

更新:下面的三个功能被用来滚动到缓冲区中的一句台词:

UPDATE: The following three functions were used to scroll to a line in the buffer:

gtk_text_iter_set_line (&start, lineNums[9]);
gtk_text_buffer_add_mark (tbuffer, scroll2mark, &start);  
gtk_text_view_scroll_to_mark (text_view, scroll2mark, 0.0, TRUE, 0.0, 0.17);

gtk_text_view_scroll_to_mark的最后一个参数被用于获得目标行号与在缓冲器中的最顶部行排队。我想这个参数不会在所有的屏幕尺寸工作,但我没有测试过。

The last parameter of gtk_text_view_scroll_to_mark was used to get the target line number to line up with the very top line in the buffer. I imagine this parameter will not work on all screen sizes, but I have not tested it.

该gtk_text_view_scroll_mark_onscreen功能让我接近的行号,但它只是一对夫妇超出文本区域的底部线。

The gtk_text_view_scroll_mark_onscreen function got me close to the line number, but it was just a couple of lines off the bottom of the text area.

推荐答案

该within_margin参数控制屏幕的面积在其中滚动到的文本应该出现以上precisely它设置在边界的空间量在该文本不应该出现在屏幕上。

The within_margin parameter controls the area of the screen in which the scrolled-to text should appear or more precisely it sets the amount of space at the border of the screen in which the text should not appear.

这存在,这样,当你设置use_align为false(即你不希望文本在屏幕上的特定位置出现的),你仍然可以确保文本不会在顶部直接出现屏幕(这可能是坏的可读性目的)的底部。

This exists so that when you set use_align to false (i.e. you don't want the text to appear at a specific position on the screen), you can still make sure that the text doesn't appear directly at the top of bottom of the screen (which might be bad for readability purposes).

如果你根本不关心位置,在该文本将出现,你可以使用 g_text_view_scroll_mark_on_screen 其中只需要文本视图和一个标记,并没有进一步的参数。这将始终滚动的最低金额,使文本显示在屏幕上。

If you don't care at all about the position at which the text will appear, you can use g_text_view_scroll_mark_on_screen which only takes the text view and a mark and no further arguments. This will always scroll the minimum amount to make the text appear on screen.

这篇关于如何(编程)滚动到gtktextview / gtksourceview特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆