CtkLevelBar

CtkLevelBar — A bar that can used as a level indicator

Functions

Properties

gboolean inverted Read / Write
double max-value Read / Write
double min-value Read / Write
CtkLevelBarMode mode Read / Write
double value Read / Write

Signals

void offset-changed Has Details

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── CtkWidget
            ╰── CtkLevelBar

Implemented Interfaces

CtkLevelBar implements AtkImplementorIface, CtkBuildable and CtkOrientable.

Includes

#include <ctk/ctk.h>

Description

The CtkLevelBar 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 ctk_level_bar_set_value() to set the current value, and ctk_level_bar_add_offset_value() to set the value offsets at which the bar will be considered in a different state. CTK will add a few offsets by default on the level bar: CTK_LEVEL_BAR_OFFSET_LOW, CTK_LEVEL_BAR_OFFSET_HIGH and CTK_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. CTK+ will simply clamp them to the new range.

Adding a custom offset on the bar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
static CtkWidget *
create_level_bar (void)
{
  CtkWidget *widget;
  CtkLevelBar *bar;

  widget = ctk_level_bar_new ();
  bar = CTK_LEVEL_BAR (widget);

  // This changes the value of the default low offset

  ctk_level_bar_add_offset_value (bar,
                                  CTK_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;
  // }

  ctk_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 ctk_level_bar_set_min_value() and ctk_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 CTK_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.

CtkLevelBar was introduced in CTK+ 3.6.

CtkLevelBar as CtkBuildable

The CtkLevelBar implementation of the CtkBuildable 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

1
2
3
4
5
6
levelbar[.discrete]
╰── trough
    ├── block.filled.level-name
    
    ├── block.empty
    

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

Functions

ctk_level_bar_new ()

CtkWidget *
ctk_level_bar_new (void);

Creates a new CtkLevelBar.

Returns

a CtkLevelBar.

Since: 3.6


ctk_level_bar_new_for_interval ()

CtkWidget *
ctk_level_bar_new_for_interval (gdouble min_value,
                                gdouble max_value);

Utility constructor that creates a new CtkLevelBar for the specified interval.

Parameters

min_value

a positive value

 

max_value

a positive value

 

Returns

a CtkLevelBar

Since: 3.6


ctk_level_bar_set_mode ()

void
ctk_level_bar_set_mode (CtkLevelBar *self,
                        CtkLevelBarMode mode);

Sets the value of the “mode” property.

Parameters

self

a CtkLevelBar

 

mode

a CtkLevelBarMode

 

Since: 3.6


ctk_level_bar_get_mode ()

CtkLevelBarMode
ctk_level_bar_get_mode (CtkLevelBar *self);

Returns the value of the “mode” property.

Parameters

self

a CtkLevelBar

 

Returns

a CtkLevelBarMode

Since: 3.6


ctk_level_bar_set_value ()

void
ctk_level_bar_set_value (CtkLevelBar *self,
                         gdouble value);

Sets the value of the “value” property.

Parameters

self

a CtkLevelBar

 

value

a value in the interval between “min-value” and “max-value”

 

Since: 3.6


ctk_level_bar_get_value ()

gdouble
ctk_level_bar_get_value (CtkLevelBar *self);

Returns the value of the “value” property.

Parameters

self

a CtkLevelBar

 

Returns

a value in the interval between “min-value” and “max-value”

Since: 3.6


ctk_level_bar_set_min_value ()

void
ctk_level_bar_set_min_value (CtkLevelBar *self,
                             gdouble value);

Sets the value of the “min-value” property.

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

Parameters

self

a CtkLevelBar

 

value

a positive value

 

Since: 3.6


ctk_level_bar_get_min_value ()

gdouble
ctk_level_bar_get_min_value (CtkLevelBar *self);

Returns the value of the “min-value” property.

Parameters

self

a CtkLevelBar

 

Returns

a positive value

Since: 3.6


ctk_level_bar_set_max_value ()

void
ctk_level_bar_set_max_value (CtkLevelBar *self,
                             gdouble value);

Sets the value of the “max-value” property.

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

Parameters

self

a CtkLevelBar

 

value

a positive value

 

Since: 3.6


ctk_level_bar_get_max_value ()

gdouble
ctk_level_bar_get_max_value (CtkLevelBar *self);

Returns the value of the “max-value” property.

Parameters

self

a CtkLevelBar

 

Returns

a positive value

Since: 3.6


ctk_level_bar_set_inverted ()

void
ctk_level_bar_set_inverted (CtkLevelBar *self,
                            gboolean inverted);

Sets the value of the “inverted” property.

Parameters

self

a CtkLevelBar

 

inverted

TRUE to invert the level bar

 

Since: 3.8


ctk_level_bar_get_inverted ()

gboolean
ctk_level_bar_get_inverted (CtkLevelBar *self);

Return the value of the “inverted” property.

Parameters

self

a CtkLevelBar

 

Returns

TRUE if the level bar is inverted

Since: 3.8


ctk_level_bar_add_offset_value ()

void
ctk_level_bar_add_offset_value (CtkLevelBar *self,
                                const gchar *name,
                                gdouble 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 “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 .

Parameters

self

a CtkLevelBar

 

name

the name of the new offset

 

value

the value for the new offset

 

Since: 3.6


ctk_level_bar_remove_offset_value ()

void
ctk_level_bar_remove_offset_value (CtkLevelBar *self,
                                   const gchar *name);

Removes an offset marker previously added with ctk_level_bar_add_offset_value().

Parameters

self

a CtkLevelBar

 

name

the name of an offset in the bar.

[allow-none]

Since: 3.6


ctk_level_bar_get_offset_value ()

gboolean
ctk_level_bar_get_offset_value (CtkLevelBar *self,
                                const gchar *name,
                                gdouble *value);

Fetches the value specified for the offset marker name in self , returning TRUE in case an offset named name was found.

Parameters

self

a CtkLevelBar

 

name

the name of an offset in the bar.

[allow-none]

value

location where to store the value.

[out]

Returns

TRUE if the specified offset is found

Since: 3.6

Types and Values

CTK_LEVEL_BAR_OFFSET_LOW

#define CTK_LEVEL_BAR_OFFSET_LOW  "low"

The name used for the stock low offset included by CtkLevelBar.

Since: 3.6


CTK_LEVEL_BAR_OFFSET_HIGH

#define CTK_LEVEL_BAR_OFFSET_HIGH "high"

The name used for the stock high offset included by CtkLevelBar.

Since: 3.6


CTK_LEVEL_BAR_OFFSET_FULL

#define CTK_LEVEL_BAR_OFFSET_FULL "full"

The name used for the stock full offset included by CtkLevelBar.

Since: 3.20


enum CtkLevelBarMode

Describes how CtkLevelBar contents should be rendered. Note that this enumeration could be extended with additional modes in the future.

Members

CTK_LEVEL_BAR_MODE_CONTINUOUS

the bar has a continuous mode

 

CTK_LEVEL_BAR_MODE_DISCRETE

the bar has a discrete mode

 

Since: 3.6


struct CtkLevelBar

struct CtkLevelBar;

Property Details

The “inverted” property

  “inverted”                 gboolean

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

Owner: CtkLevelBar

Flags: Read / Write

Default value: FALSE

Since: 3.8


The “max-value” property

  “max-value”                double

The “max-value” property determaxes the maximum value of the interval that can be displayed by the bar.

Owner: CtkLevelBar

Flags: Read / Write

Allowed values: >= 0

Default value: 1

Since: 3.6


The “min-value” property

  “min-value”                double

The “min-value” property determines the minimum value of the interval that can be displayed by the bar.

Owner: CtkLevelBar

Flags: Read / Write

Allowed values: >= 0

Default value: 0

Since: 3.6


The “mode” property

  “mode”                     CtkLevelBarMode

The “mode” property determines the way CtkLevelBar interprets the value properties to draw the level fill area. Specifically, when the value is CTK_LEVEL_BAR_MODE_CONTINUOUS, CtkLevelBar will draw a single block representing the current value in that area; when the value is CTK_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 “min-value” and “max-value”.

Owner: CtkLevelBar

Flags: Read / Write

Default value: CTK_LEVEL_BAR_MODE_CONTINUOUS

Since: 3.6


The “value” property

  “value”                    double

The “value” property determines the currently filled value of the level bar.

Owner: CtkLevelBar

Flags: Read / Write

Allowed values: >= 0

Default value: 0

Since: 3.6

Signal Details

The “offset-changed” signal

void
user_function (CtkLevelBar *self,
               char        *name,
               gpointer     user_data)

Emitted when an offset specified on the bar changes value as an effect to ctk_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

a CtkLevelBar

 

name

the name of the offset that changed value

 

user_data

user data set when the signal handler was connected.

 

Flags: Has Details

Since: 3.6