gtk.level_bar

Module for [LevelBar] class

Types 3

[gtk.level_bar.LevelBar] is a 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.

!An example GtkLevelBar

Use [gtk.level_bar.LevelBar.setValue] to set the current value, and [gtk.level_bar.LevelBar.addOffsetValue] to set the value offsets at which the bar will be considered in a different state. GTK will add a few offsets by default on the level bar: [gtk.types.LEVEL_BAR_OFFSET_LOW], [gtk.types.LEVEL_BAR_OFFSET_HIGH] and [gtk.types.LEVEL_BAR_OFFSET_FULL], with values 0.25, 0.75 and 1.0 respectively.

Note that it is your responsibility to update preexisting offsets when changing the minimum or maximum value. GTK will simply clamp them to the new range.

Adding a custom offset on the bar

static GtkWidget *
create_level_bar (void)
{
 GtkWidget *widget;
 GtkLevelBar *bar;

 widget = gtk_level_bar_new ();
 bar = GTK_LEVEL_BAR (widget);

 // This changes the value of the default low offset

 gtk_level_bar_add_offset_value (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 CSS like this:
 //
 // levelbar block.my-offset {
 //   background-color: magenta;
 //   border-style: solid;
 //   border-color: black;
 //   border-width: 1px;
 // }

 gtk_level_bar_add_offset_value (bar, "my-offset", 0.60);

 return widget;
}

The default interval of values is between zero and one, but it’s possible to modify the interval using [gtk.level_bar.LevelBar.setMinValue] and [gtk.level_bar.LevelBar.setMaxValue]. 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.types.LevelBarMode.Discrete] is used, the bar level is rendered as a finite 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.

GtkLevelBar as GtkBuildable

The [gtk.level_bar.LevelBar] implementation of the [gtk.buildable.Buildable] interface supports a custom <offsets> element, which can contain any number of <offset> elements, each of which must have "name" and "value" attributes.

CSS nodes

levelbar[.discrete]
╰── trough
   ├── block.filled.level-name
   ┊
   ├── block.empty
   ┊

[gtk.level_bar.LevelBar] has a main CSS node with name levelbar and one of the style classes .discrete or .continuous and a subnode with name trough. Below the trough node are a number of nodes with name block and style class .filled or .empty. In continuous mode, there is exactly one node of each, in discrete mode, the number of filled and unfilled nodes corresponds to blocks that are drawn. The block.filled nodes also get a style class .level-name corresponding to the level for the current value.

In horizontal orientation, the nodes are always arranged from left to right, regardless of text direction.

Accessibility

[gtk.level_bar.LevelBar] uses the [gtk.types.AccessibleRole.Meter] role.

Methods
GType _gType() @property
LevelBar self()Returns `this`, for use in `with` statements.
LevelBarGidBuilder builder()Get builder for [gtk.level_bar.LevelBar] Returns: New builder object
bool inverted() @propertyGet `inverted` property. Returns: Whether the `GtkLeveBar` is inverted.
void inverted(bool propval) @propertySet `inverted` property. Params: propval = Whether the `GtkLeveBar` is inverted.
double maxValue() @propertyGet `maxValue` property. Returns: Determines the maximum value of the interval that can be displayed by the bar.
void maxValue(double propval) @propertySet `maxValue` property. Params: propval = Determines the maximum value of the interval that can be displayed by the bar.
double minValue() @propertyGet `minValue` property. Returns: Determines the minimum value of the interval that can be displayed by the bar.
void minValue(double propval) @propertySet `minValue` property. Params: propval = Determines the minimum value of the interval that can be displayed by the bar.
gtk.types.LevelBarMode mode() @propertyGet `mode` property. Returns: Determines the way [gtk.level_bar.LevelBar] interprets the value properties to draw the level fill area.
void mode(gtk.types.LevelBarMode propval) @propertySet `mode` property. Params: propval = Determines the way [gtk.level_bar.LevelBar] interprets the value properties to draw the level fill area.
double value() @propertyGet `value` property. Returns: Determines the currently filled value of the level bar.
void value(double propval) @propertySet `value` property. Params: propval = Determines the currently filled value of the level bar.
gtk.level_bar.LevelBar newForInterval(double minValue, double maxValue)Creates a new [gtk.level_bar.LevelBar] for the specified interval.
void addOffsetValue(string name, double value)Adds a new offset marker on self at the position specified by value.
bool getInverted()Returns whether the levelbar is inverted. Returns: true if the level bar is inverted
double getMaxValue()Returns the `max-value` of the [gtk.level_bar.LevelBar]. Returns: a positive value
double getMinValue()Returns the `min-value` of the [gtk.level_bar.LevelBar]. Returns: a positive value
gtk.types.LevelBarMode getMode()Returns the `mode` of the [gtk.level_bar.LevelBar]. Returns: a [gtk.types.LevelBarMode]
bool getOffsetValue(string name, out double value)Fetches the value specified for the offset marker name in self.
double getValue()Returns the `value` of the [gtk.level_bar.LevelBar]. Returns: a value in the interval between `propertyGtk.LevelBar:min-value` and `propertyGtk.LevelBar:max-value`
void removeOffsetValue(string name = null)Removes an offset marker from a [gtk.level_bar.LevelBar].
void setInverted(bool inverted)Sets whether the [gtk.level_bar.LevelBar] is inverted.
void setMaxValue(double value)Sets the `max-value` of the [gtk.level_bar.LevelBar].
void setMinValue(double value)Sets the `min-value` of the [gtk.level_bar.LevelBar].
void setMode(gtk.types.LevelBarMode mode)Sets the `mode` of the [gtk.level_bar.LevelBar].
void setValue(double value)Sets the value of the [gtk.level_bar.LevelBar].
gulong connectOffsetChanged(T)(string detail = null, T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == string))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.level_bar.LevelBar))) && Parameters!T.length < 3)Connect to `OffsetChanged` signal.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a new [gtk.levelbar.LevelBar]. Returns: a [gtk.levelbar.LevelBar].
Methods
T inverted(bool propval)Set `inverted` property. Params: propval = Whether the `GtkLeveBar` is inverted.
T maxValue(double propval)Set `maxValue` property. Params: propval = Determines the maximum value of the interval that can be displayed by the bar. Returns: Builder instance for fluent chaining
T minValue(double propval)Set `minValue` property. Params: propval = Determines the minimum value of the interval that can be displayed by the bar. Returns: Builder instance for fluent chaining
T mode(gtk.types.LevelBarMode propval)Set `mode` property. Params: propval = Determines the way [gtk.level_bar.LevelBar] interprets the value properties to draw the level fill area.
T value(double propval)Set `value` property. Params: propval = Determines the currently filled value of the level bar. Returns: Builder instance for fluent chaining

Fluent builder for [gtk.level_bar.LevelBar]

Methods