⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec-spinbuttons.html

📁 gtk 开发手册和参考文档。 包括gtk glib gdk等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<HTML><HEAD><TITLE>Spin Buttons</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="Miscellaneous Widgets"HREF="ch-miscwidgets.html"><LINKREL="PREVIOUS"TITLE="Text Entries"HREF="sec-textentries.html"><LINKREL="NEXT"TITLE="Combo Box"HREF="sec-combobox.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%">  <tr>    <td bgcolor="#FFFFFF" valign=top nowrap>    <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A>      <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR>      </td>  <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="sec-textentries.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 9. Miscellaneous Widgets</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-combobox.html">Next &#62;&#62;&#62;</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-SPINBUTTONS">9.10. Spin Buttons</A></H1><P>The Spin Button widget is generally used to allow the user to select avalue from a range of numeric values. It consists of a textentry box with up and down arrow buttons attached to theside. Selecting one of the buttons causes the value to "spin" up anddown the range of possible values. The entry box may also be editeddirectly to enter a specific value.</P><P>The Spin Button allows the value to have zero or a number of decimalplaces and to be incremented/decremented in configurable steps. Theaction of holding down one of the buttons optionally results in anacceleration of change in the value according to how long it isdepressed.</P><P>The Spin Button uses an <AHREF="ch-adjustments.html">Adjustment</A>object to hold information about the range of values that the spinbutton can take. This makes for a powerful Spin Button widget.</P><P>Recall that an adjustment widget is created with the followingfunction, which illustrates the information that it holds:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkObject *gtk_adjustment_new( gfloat value,                               gfloat lower,                               gfloat upper,                               gfloat step_increment,                               gfloat page_increment,                               gfloat page_size );</PRE></TD></TR></TABLE><P>These attributes of an Adjustment are used by the Spin Button in thefollowing way:</P><P></P><UL><LI><P> <TTCLASS="LITERAL">value</TT>: initial value for the Spin Button</P></LI><LI><P> <TTCLASS="LITERAL">lower</TT>: lower range value</P></LI><LI><P> <TTCLASS="LITERAL">upper</TT>: upper range value</P></LI><LI><P> <TTCLASS="LITERAL">step_increment</TT>: value to increment/decrement when pressingmouse button 1 on a button</P></LI><LI><P> <TTCLASS="LITERAL">page_increment</TT>: value to increment/decrement when pressingmouse button 2 on a button</P></LI><LI><P> <TTCLASS="LITERAL">page_size</TT>: unused</P></LI></UL><P>Additionally, mouse button 3 can be used to jump directly to the<TTCLASS="LITERAL">upper</TT> or <TTCLASS="LITERAL">lower</TT> values when used to select one of thebuttons. Lets look at how to create a Spin Button:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget *gtk_spin_button_new( GtkAdjustment *adjustment,                                gfloat         climb_rate,                                guint          digits );</PRE></TD></TR></TABLE><P>The <TTCLASS="LITERAL">climb_rate</TT> argument take a value between 0.0 and 1.0 andindicates the amount of acceleration that the Spin Button has. The<TTCLASS="LITERAL">digits</TT> argument specifies the number of decimal places to whichthe value will be displayed.</P><P>A Spin Button can be reconfigured after creation using the followingfunction:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_spin_button_configure( GtkSpinButton *spin_button,                                GtkAdjustment *adjustment,                                gfloat         climb_rate,                                guint          digits );</PRE></TD></TR></TABLE><P>The <TTCLASS="LITERAL">spin_button</TT> argument specifies the Spin Button widget that isto be reconfigured. The other arguments are as specified above.</P><P>The adjustment can be set and retrieved independantly using thefollowing two functions:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_spin_button_set_adjustment( GtkSpinButton  *spin_button,                                     GtkAdjustment  *adjustment );GtkAdjustment *gtk_spin_button_get_adjustment( GtkSpinButton *spin_button );</PRE></TD></TR></TABLE><P>The number of decimal places can also be altered using:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_spin_button_set_digits( GtkSpinButton *spin_button,                                 guint          digits) ;</PRE></TD></TR></TABLE><P>The value that a Spin Button is currently displaying can be changedusing the following function:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_spin_button_set_value( GtkSpinButton *spin_button,                                gfloat         value );</PRE></TD></TR></TABLE><P>The current value of a Spin Button can be retrieved as either afloating point or integer value with the following functions:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">gfloat gtk_spin_button_get_value_as_float( GtkSpinButton *spin_button );gint gtk_spin_button_get_value_as_int( GtkSpinButton *spin_button );</PRE></TD></TR></TABLE><P>If you want to alter the value of a Spin Value relative to its currentvalue, then the following function can be used:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_spin_button_spin( GtkSpinButton *spin_button,                           GtkSpinType    direction,                           gfloat         increment );</PRE></TD></TR></TABLE><P>The <TTCLASS="LITERAL">direction</TT> parameter can take one of the following values:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">  GTK_SPIN_STEP_FORWARD  GTK_SPIN_STEP_BACKWARD  GTK_SPIN_PAGE_FORWARD  GTK_SPIN_PAGE_BACKWARD  GTK_SPIN_HOME  GTK_SPIN_END  GTK_SPIN_USER_DEFINED</PRE></TD></TR></TABLE><P>This function packs in quite a bit of functionality, which I willattempt to clearly explain. Many of these settings use values from theAdjustment object that is associated with a Spin Button.</P><P><TTCLASS="LITERAL">GTK_SPIN_STEP_FORWARD</TT> and <TTCLASS="LITERAL">GTK_SPIN_STEP_BACKWARD</TT> change thevalue of the Spin Button by the amount specified by <TTCLASS="LITERAL">increment</TT>,unless <TTCLASS="LITERAL">increment</TT> is equal to 0, in which case the value ischanged by the value of <TTCLASS="LITERAL">step_increment</TT> in theAdjustment.</P

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -