Gtk.Level_Bar

Entities

Tagged Types

Access Types

Constants

Subprograms

Generic Instantiations

Description

The Gtk.Level_Bar.Gtk_Level_Bar 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.Level_Bar.Set_Value to set the current value, and Gtk.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-style: 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.Set_Min_Value and Gtk.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 GTK_LEVEL_BAR_MODE_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 was introduced in GTK+ 3.6.

# 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.

"+"

function "+"
  (Widget : access Gtk_Level_Bar_Record'Class)
return Gtk.Buildable.Gtk_Buildable
Parameters
Widget
Return Value

"+"

function "+"
  (Widget : access Gtk_Level_Bar_Record'Class)
return Gtk.Orientable.Gtk_Orientable
Parameters
Widget
Return Value

"-"

function "-"
  (Interf : Gtk.Buildable.Gtk_Buildable)
return Gtk_Level_Bar
Parameters
Interf
Return Value

"-"

function "-"
  (Interf : Gtk.Orientable.Gtk_Orientable)
return Gtk_Level_Bar
Parameters
Interf
Return Value

Add_Offset_Value

procedure Add_Offset_Value
   (Self  : not null access Gtk_Level_Bar_Record;
    Name  : UTF8_String;
    Value : Gdouble)

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 Gtk.Level_Bar.Gtk_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. Since: gtk+ 3.6

Parameters
Self
Name

the name of the new offset

Value

the value for the new offset

Cb_GObject_UTF8_String_Void

type Cb_GObject_UTF8_String_Void is not null access procedure
  (Self : access Glib.Object.GObject_Record'Class;
   Name : UTF8_String);
Parameters
Self
Name

Cb_Gtk_Level_Bar_UTF8_String_Void

type Cb_Gtk_Level_Bar_UTF8_String_Void is not null access procedure
  (Self : access Gtk_Level_Bar_Record'Class;
   Name : UTF8_String);
Parameters
Self
Name

Get_Inverted

function Get_Inverted
   (Self : not null access Gtk_Level_Bar_Record) return Boolean

Return the value of the Gtk.Level_Bar.Gtk_Level_Bar:inverted property. Since: gtk+ 3.8

Parameters
Self
Return Value

True if the level bar is inverted

Get_Max_Value

function Get_Max_Value
   (Self : not null access Gtk_Level_Bar_Record) return Gdouble

Returns the value of the Gtk.Level_Bar.Gtk_Level_Bar:max-value property. Since: gtk+ 3.6

Parameters
Self
Return Value

a positive value

Get_Min_Value

function Get_Min_Value
   (Self : not null access Gtk_Level_Bar_Record) return Gdouble

Returns the value of the Gtk.Level_Bar.Gtk_Level_Bar:min-value property. Since: gtk+ 3.6

Parameters
Self
Return Value

a positive value

Get_Mode

function Get_Mode
   (Self : not null access Gtk_Level_Bar_Record)
    return Gtk.Enums.Gtk_Level_Bar_Mode

Returns the value of the Gtk.Level_Bar.Gtk_Level_Bar:mode property. Since: gtk+ 3.6

Parameters
Self
Return Value

a Gtk.Enums.Gtk_Level_Bar_Mode

Get_Offset_Value

function Get_Offset_Value
   (Self  : not null access Gtk_Level_Bar_Record;
    Name  : UTF8_String := "";
    Value : access Gdouble) return Boolean

Fetches the value specified for the offset marker Name in Self, returning True in case an offset named Name was found. Since: gtk+ 3.6

Parameters
Self
Name

the name of an offset in the bar

Value

location where to store the value

Return Value

True if the specified offset is found

Get_Orientation

function Get_Orientation
   (Self : not null access Gtk_Level_Bar_Record)
    return Gtk.Enums.Gtk_Orientation
Parameters
Self
Return Value

Get_Type

function Get_Type return Glib.GType
Return Value

Get_Value

function Get_Value
   (Self : not null access Gtk_Level_Bar_Record) return Gdouble

Returns the value of the Gtk.Level_Bar.Gtk_Level_Bar:value property. Since: gtk+ 3.6

Parameters
Self
Return Value

a value in the interval between Gtk.Level_Bar.Gtk_Level_Bar:min-value and Gtk.Level_Bar.Gtk_Level_Bar:max-value

Gtk_Level_Bar

type Gtk_Level_Bar is access all Gtk_Level_Bar_Record'Class;

Gtk_Level_Bar_New

function Gtk_Level_Bar_New return Gtk_Level_Bar

Creates a new Gtk.Level_Bar.Gtk_Level_Bar. Since: gtk+ 3.6

Return Value

Gtk_Level_Bar_New_For_Interval

function Gtk_Level_Bar_New_For_Interval
   (Min_Value : Gdouble;
    Max_Value : Gdouble) return Gtk_Level_Bar

Utility constructor that creates a new Gtk.Level_Bar.Gtk_Level_Bar for the specified interval. Since: gtk+ 3.6

Parameters
Min_Value

a positive value

Max_Value

a positive value

Return Value

Gtk_Level_Bar_Record

type Gtk_Level_Bar_Record is new Gtk_Widget_Record with null record;

Gtk_New

procedure Gtk_New (Self : out Gtk_Level_Bar)

Creates a new Gtk.Level_Bar.Gtk_Level_Bar. Since: gtk+ 3.6 Initialize does nothing if the object was already created with another call to Initialize* or G_New.

Parameters
Self

Gtk_New_For_Interval

procedure Gtk_New_For_Interval
   (Self      : out Gtk_Level_Bar;
    Min_Value : Gdouble;
    Max_Value : Gdouble)

Utility constructor that creates a new Gtk.Level_Bar.Gtk_Level_Bar for the specified interval. Since: gtk+ 3.6 Initialize_For_Interval does nothing if the object was already created with another call to Initialize* or G_New.

Parameters
Self
Min_Value

a positive value

Max_Value

a positive value

Implements_Gtk_Buildable

package Implements_Gtk_Buildable is new Glib.Types.Implements
  (Gtk.Buildable.Gtk_Buildable, Gtk_Level_Bar_Record, Gtk_Level_Bar);

Implements_Gtk_Orientable

package Implements_Gtk_Orientable is new Glib.Types.Implements
  (Gtk.Orientable.Gtk_Orientable, Gtk_Level_Bar_Record, Gtk_Level_Bar);

Initialize

procedure Initialize (Self : not null access Gtk_Level_Bar_Record'Class)

Creates a new Gtk.Level_Bar.Gtk_Level_Bar. Since: gtk+ 3.6 Initialize does nothing if the object was already created with another call to Initialize* or G_New.

Parameters
Self

Initialize_For_Interval

procedure Initialize_For_Interval
   (Self      : not null access Gtk_Level_Bar_Record'Class;
    Min_Value : Gdouble;
    Max_Value : Gdouble)

Utility constructor that creates a new Gtk.Level_Bar.Gtk_Level_Bar for the specified interval. Since: gtk+ 3.6 Initialize_For_Interval does nothing if the object was already created with another call to Initialize* or G_New.

Parameters
Self
Min_Value

a positive value

Max_Value

a positive value

Inverted_Property

Inverted_Property : constant Glib.Properties.Property_Boolean;

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

Max_Value_Property

Max_Value_Property : constant Glib.Properties.Property_Double;

Type: Gdouble The Gtk.Level_Bar.Gtk_Level_Bar:max-value property determaxes the maximum value of the interval that can be displayed by the bar.

Min_Value_Property

Min_Value_Property : constant Glib.Properties.Property_Double;

Type: Gdouble The Gtk.Level_Bar.Gtk_Level_Bar:min-value property determines the minimum value of the interval that can be displayed by the bar.

Mode_Property

Mode_Property : constant Gtk.Enums.Property_Gtk_Level_Bar_Mode;

The Gtk.Level_Bar.Gtk_Level_Bar:mode property determines the way Gtk.Level_Bar.Gtk_Level_Bar interprets the value properties to draw the level fill area. Specifically, when the value is GTK_LEVEL_BAR_MODE_CONTINUOUS, Gtk.Level_Bar.Gtk_Level_Bar will draw a single block representing the current value in that area; when the value is GTK_LEVEL_BAR_MODE_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 Gtk.Level_Bar.Gtk_Level_Bar:min-value and Gtk.Level_Bar.Gtk_Level_Bar:max-value.

On_Offset_Changed

procedure On_Offset_Changed
   (Self  : not null access Gtk_Level_Bar_Record;
    Call  : Cb_GObject_UTF8_String_Void;
    Slot  : not null access Glib.Object.GObject_Record'Class;
    After : Boolean := False)

Emitted when an offset specified on the bar changes value as an effect to Gtk.Level_Bar.Add_Offset_Value being called.

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.

Parameters
Self
Call
Slot
After

On_Offset_Changed

procedure On_Offset_Changed
   (Self  : not null access Gtk_Level_Bar_Record;
    Call  : Cb_Gtk_Level_Bar_UTF8_String_Void;
    After : Boolean := False)

Emitted when an offset specified on the bar changes value as an effect to Gtk.Level_Bar.Add_Offset_Value being called.

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.

Parameters
Self
Call
After

Remove_Offset_Value

procedure Remove_Offset_Value
   (Self : not null access Gtk_Level_Bar_Record;
    Name : UTF8_String := "")

Removes an offset marker previously added with Gtk.Level_Bar.Add_Offset_Value. Since: gtk+ 3.6

Parameters
Self
Name

the name of an offset in the bar

Set_Inverted

procedure Set_Inverted
   (Self     : not null access Gtk_Level_Bar_Record;
    Inverted : Boolean)

Sets the value of the Gtk.Level_Bar.Gtk_Level_Bar:inverted property. Since: gtk+ 3.8

Parameters
Self
Inverted

True to invert the level bar

Set_Max_Value

procedure Set_Max_Value
   (Self  : not null access Gtk_Level_Bar_Record;
    Value : Gdouble)

Sets the value of the Gtk.Level_Bar.Gtk_Level_Bar:max-value property. You probably want to update preexisting level offsets after calling this function. Since: gtk+ 3.6

Parameters
Self
Value

a positive value

Set_Min_Value

procedure Set_Min_Value
   (Self  : not null access Gtk_Level_Bar_Record;
    Value : Gdouble)

Sets the value of the Gtk.Level_Bar.Gtk_Level_Bar:min-value property. You probably want to update preexisting level offsets after calling this function. Since: gtk+ 3.6

Parameters
Self
Value

a positive value

Set_Mode

procedure Set_Mode
   (Self : not null access Gtk_Level_Bar_Record;
    Mode : Gtk.Enums.Gtk_Level_Bar_Mode)

Sets the value of the Gtk.Level_Bar.Gtk_Level_Bar:mode property. Since: gtk+ 3.6

Parameters
Self
Mode

a Gtk.Enums.Gtk_Level_Bar_Mode

Set_Orientation

procedure Set_Orientation
   (Self        : not null access Gtk_Level_Bar_Record;
    Orientation : Gtk.Enums.Gtk_Orientation)
Parameters
Self
Orientation

Set_Value

procedure Set_Value
   (Self  : not null access Gtk_Level_Bar_Record;
    Value : Gdouble)

Sets the value of the Gtk.Level_Bar.Gtk_Level_Bar:value property. Since: gtk+ 3.6

Parameters
Self
Value

a value in the interval between Gtk.Level_Bar.Gtk_Level_Bar:min-value and Gtk.Level_Bar.Gtk_Level_Bar:max-value

Signal_Offset_Changed

Signal_Offset_Changed : constant Glib.Signal_Name := "offset-changed";

Emitted when an offset specified on the bar changes value as an effect to Gtk.Level_Bar.Add_Offset_Value being called.

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.

Value_Property

Value_Property : constant Glib.Properties.Property_Double;

Type: Gdouble The Gtk.Level_Bar.Gtk_Level_Bar:value property determines the currently filled value of the level bar.