Gtk.LevelBar
The Gtk.LevelBar is a bar widget that can be used as a level indicator. Typical use cases are displaying the strength of a password, or showing the charge level of a battery.
Use Gtk.set_value to set the current value, and Gtk.add_offset_value to set the value offsets at which the bar will be considered in a different state. GTK will add two offsets by default on the level bar: #GTK_LEVEL_BAR_OFFSET_LOW and #GTK_LEVEL_BAR_OFFSET_HIGH, with values 0.25 and 0.75 respectively.
<example> <title>Adding a custom offset on the bar</title> <programlisting>
static GtkWidget * create_level_bar (void) { GtkWidget *level_bar;
level_bar = gtk_level_bar_new ();
/<!---->* This changes the value of the default low offset *<!---->/ gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (level_bar), GTK_LEVEL_BAR_OFFSET_LOW, 0.10);
/<!---->* This adds a new offset to the bar; the application will * be able to change its color by using the following selector, * either by adding it to its CSS file or using * Gtk.CssProvider.prototype.load_from_data and Gtk.add_provider * * .level-bar.fill-block.level-my-offset { * background-color: green; * border-style: solid; * border-color: black; * border-style: 1px; * } *<!---->/ gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (level_bar), "my-offset", 0.60);
return level_bar; } </programlisting> </example>
The default interval of values is between zero and one, but it's possible to modify the interval using Gtk.set_min_value and Gtk.set_max_value. The value will be always drawn in proportion to the admissible interval, i.e. a value of 15 with a specified interval between 10 and 20 is equivalent to a value of 0.5 with an interval between 0 and 1. When #GTK_LEVEL_BAR_MODE_DISCRETE is used, the bar level is rendered as a finite and number of separated blocks instead of a single one. The number of blocks that will be rendered is equal to the number of units specified by the admissible interval. For instance, to build a bar rendered with five blocks, it's sufficient to set the minimum value to 0 and the maximum value to 5 after changing the indicator mode to discrete.
Hierarchy
-
GObject.Object
-
GObject.InitiallyUnowned
-
Gtk.Widget
- Gtk.LevelBar
-
-
Methods
- Gtk.LevelBar.prototype.add_offset_value
- Gtk.LevelBar.prototype.get_inverted
- Gtk.LevelBar.prototype.get_max_value
- Gtk.LevelBar.prototype.get_min_value
- Gtk.LevelBar.prototype.get_mode
- Gtk.LevelBar.prototype.get_offset_value
- Gtk.LevelBar.prototype.get_value
- Gtk.LevelBar.prototype.remove_offset_value
- Gtk.LevelBar.prototype.set_inverted
- Gtk.LevelBar.prototype.set_max_value
- Gtk.LevelBar.prototype.set_min_value
- Gtk.LevelBar.prototype.set_mode
- Gtk.LevelBar.prototype.set_value