Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->Linux技术 ->系统管理 ->正文

GTK v1.2 Tutorial(英文)

来源:Linux-cn.com 作者:Webmaster 时间:2007-05-05 点击: [收藏] [投稿]

  As mentioned in Adjustments above, all range widgets are associated with an adjustment object, from which they calculate the length of the slider and its position within the trough. When the user manipulates the slider, the range widget will change the value of the adjustment.

8.1 Scrollbar Widgets

  These are your standard, run-of-the-mill scrollbars. These should be used only for scrolling some other widget, such as a list, a text box, or a viewport (and it's generally easier to use the scrolled window widget in most cases). For other purposes, you should use scale widgets, as they are friendlier and more featureful.

  There are separate types for horizontal and vertical scrollbars. There really isn't much to say about these. You create them with the following functions, defined in <gtk/gtkhscrollbar.h> and <gtk/gtkvscrollbar.h>:


GtkWidget *gtk_hscrollbar_new( GtkAdjustment *adjustment );
GtkWidget *gtk_vscrollbar_new( GtkAdjustment *adjustment );

  and that's about it (if you don't believe me, look in the header files!). The adjustment argument can either be a pointer to an existing Adjustment, or NULL, in which case one will be created for you. Specifying NULL might actually be useful in this case, if you wish to pass the newly-created adjustment to the constructor function of some other widget which will configure it for you, such as a text widget.

8.2 Scale Widgets

  Scale widgets are used to allow the user to visually select and manipulate a value within a specific range. You might want to use a scale widget, for example, to adjust the magnification level on a zoomed preview of a picture, or to control the brightness of a color, or to specify the number of minutes of inactivity before a screensaver takes over the screen.

Creating a Scale Widget

  As with scrollbars, there are separate widget types for horizontal and vertical scale widgets. (Most programmers seem to favour horizontal scale widgets.) Since they work essentially the same way, there's no need to treat them separately here. The following functions, defined in <gtk/gtkvscale.h> and <gtk/gtkhscale.h>, create vertical and horizontal scale widgets, respectively:


GtkWidget *gtk_vscale_new( GtkAdjustment *adjustment );
GtkWidget *gtk_hscale_new( GtkAdjustment *adjustment );

  The adjustment argument can either be an adjustment which has already been created with gtk_adjustment_new(), or NULL, in which case, an anonymous Adjustment is created with all of its values set to 0.0 (which isn't very useful in this case). In order to avoid confusing yourself, you probably want to create your adjustment with a page_size of 0.0 so that its upper value actually corresponds to the highest value the user can select. (If you're already thoroughly confused, read the section on Adjustments again for an explanation of what exactly adjustments do and how to create and manipulate them.)


Functions and Signals (well, functions, at least)

  Scale widgets can display their current value as a number beside the trough. The default behaviour is to show the value, but you can change this with this function:


void gtk_scale_set_draw_value( GtkScale *scale,
gintdraw_value );

  As you might have guessed, draw_value is either TRUE or FALSE, with predictable consequences for either one.

  The value displayed by a scale widget is rounded to one decimal point by default, as is the value field in its GtkAdjustment. You can change this with:


void gtk_scale_set_digits( GtkScale *scale,
gint digits );

  where digits is the number of decimal places you want. You can set digits to anything you like, but no more than 13 decimal places will actually be drawn on screen.

  Finally, the value can be drawn in different positions relative to the trough:


void gtk_scale_set_value_pos( GtkScale*scale,
GtkPositionTypepos );

  The argument pos is of type GtkPositionType, which is defined in <gtk/gtkenums.h>, and can take one of the following values:


GTK_POS_LEFT
GTK_POS_RIGHT
GTK_POS_TOP
GTK_POS_BOTTOM


 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:GTK入门导引   下一篇:GDK Reference Manual

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章