1.108 <GtkLevelBar>

Class: <GtkLevelBar>

It derives from <GtkWidget>.

Shows a level indicator.

Typical use cases are displaying the strength of a password, or showing the charge level of a battery.

Use level-bar:set-value to set the current value, and level-bar:add-offset-value 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_LEVEL_BAR_OFFSET_LOW, GTK_LEVEL_BAR_OFFSET_HIGH and GTK_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 level-bar:set-min-value and level-bar: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 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 <GtkLevelBar> implementation of the <GtkBuildable> 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
    ┊

<GtkLevelBar> 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

<GtkLevelBar> uses the Gtk.AccessibleRole.meter role.

Properties

Property: level-bar:inverted self

Whether the GtkLeveBar is inverted.

Level bars normally grow from top to bottom or left to right. Inverted level bars grow in the opposite direction.

Its value is a boolean.

Set it with (set! (level-bar:inverted self) value).

Property: level-bar:max-value self

Determines the maximum value of the interval that can be displayed by the bar.

Its value is a real number.

Set it with (set! (level-bar:max-value self) value).

Property: level-bar:min-value self

Determines the minimum value of the interval that can be displayed by the bar.

Its value is a real number.

Set it with (set! (level-bar:min-value self) value).

Property: level-bar:mode self

Determines the way <GtkLevelBar> interprets the value properties to draw the level fill area.

Specifically, when the value is continuous, <GtkLevelBar> will draw a single block representing the current value in that area; when the value is discrete, the widget will draw a succession of separate blocks filling the draw area, with the number of blocks being equal to the units separating the integral roundings of level-bar:min-value and level-bar:max-value.

Its value is a <GtkLevelBarMode> (or, to set it, one of its symbols).

Set it with (set! (level-bar:mode self) value).

Property: level-bar:value self

Determines the currently filled value of the level bar.

Its value is a real number.

Set it with (set! (level-bar:value self) value).

Procedures

Method: level-bar:add-offset-value self name value
Method: add-offset-value self name value

Adds a new offset marker on self at the position specified by value.

When the bar value is in the interval topped by value (or between value and level-bar:max-value in case the offset is the last one on the bar) a style class named level-name will be applied when rendering the level bar fill.

If another offset marker named name exists, its value will be replaced by value.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

name

Passed: a string.

the name of the new offset

value

Passed: a real number.

the value for the new offset

Method: level-bar:get-inverted? self ⇒ %return
Method: get-inverted? self ⇒ %return

Returns whether the levelbar is inverted.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

%return

Returned: a boolean.

#t if the level bar is inverted

Method: level-bar:get-max-value self ⇒ %return
Method: get-max-value self ⇒ %return

Returns the max-value of the <GtkLevelBar>.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

%return

Returned: a real number.

a positive value

Method: level-bar:get-min-value self ⇒ %return
Method: get-min-value self ⇒ %return

Returns the min-value of the <GtkLevelBar>.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

%return

Returned: a real number.

a positive value

Method: level-bar:get-mode self ⇒ %return
Method: get-mode self ⇒ %return

Returns the mode of the <GtkLevelBar>.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

%return

Returned: a <GtkLevelBarMode>.

a <GtkLevelBarMode>

Method: level-bar:get-offset-value self [name] ⇒ %return value
Method: get-offset-value self [name] ⇒ %return value

Fetches the value specified for the offset marker name in self.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

name

Passed, or left out: a string, or #f.

the name of an offset in the bar

%return

Returned: a boolean.

#t if the specified offset is found

value

Returned: a real number.

location where to store the value

Method: level-bar:get-value self ⇒ %return
Method: get-value self ⇒ %return

Returns the value of the <GtkLevelBar>.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

%return

Returned: a real number.

a value in the interval between level-bar:min-value and level-bar:max-value

Procedure: level-bar:new ⇒ %return

Creates a new <GtkLevelBar>.

%return

Returned: a <GtkWidget>.

a <GtkLevelBar>.

Procedure: level-bar:new-for-interval min-value max-value ⇒ %return

Creates a new <GtkLevelBar> for the specified interval.

min-value

Passed: a real number.

a positive value

max-value

Passed: a real number.

a positive value

%return

Returned: a <GtkWidget>.

a <GtkLevelBar>

Method: level-bar:remove-offset-value self [name]
Method: remove-offset-value self [name]

Removes an offset marker from a <GtkLevelBar>.

The marker must have been previously added with level-bar:add-offset-value.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

name

Passed, or left out: a string, or #f.

the name of an offset in the bar

Method: level-bar:set-inverted self inverted
Method: set-inverted self inverted

Sets whether the <GtkLevelBar> is inverted.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

inverted

Passed: a boolean.

#t to invert the level bar

Method: level-bar:set-max-value self value
Method: set-max-value self value

Sets the max-value of the <GtkLevelBar>.

You probably want to update preexisting level offsets after calling this function.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

value

Passed: a real number.

a positive value

Method: level-bar:set-min-value self value
Method: set-min-value self value

Sets the min-value of the <GtkLevelBar>.

You probably want to update preexisting level offsets after calling this function.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

value

Passed: a real number.

a positive value

Method: level-bar:set-mode self mode
Method: set-mode self mode

Sets the mode of the <GtkLevelBar>.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

mode

Passed: a <GtkLevelBarMode>, or one of its symbols.

a <GtkLevelBarMode>

Method: level-bar:set-value self value
Method: set-value self value

Sets the value of the <GtkLevelBar>.

self

Passed: a <GtkLevelBar>.

a <GtkLevelBar>

value

Passed: a real number.

a value in the interval between level-bar:min-value and level-bar:max-value

Signals

Signal: level-bar:offset-changed

Connect a handler with (connect object level-bar:offset-changed handler). It is called as (handler self name).

Emitted when an offset specified on the bar changes value.

This typically is the result of a level-bar:add-offset-value call.

The signal supports detailed connections; you can connect to the detailed signal "changed::x" in order to only receive callbacks when the value of offset "x" changes.

self

Passed: a <GtkLevelBar>.

name

Passed: a string.

the name of the offset that changed value