Package ch.bailu.gtk.gtk
Class LevelBar
- All Implemented Interfaces:
PointerInterface
`GtkLevelBar` 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](levelbar.png)
Use [method@Gtk.LevelBar.set_value] to set the current value, and
[method@Gtk.LevelBar.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
```c
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 [method@Gtk.LevelBar.set_min_value] and
[method@Gtk.LevelBar.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 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_ACCESSIBLE_ROLE_METER role.
Typical use cases are displaying the strength of a password, or
showing the charge level of a battery.
![An example GtkLevelBar](levelbar.png)
Use [method@Gtk.LevelBar.set_value] to set the current value, and
[method@Gtk.LevelBar.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
```c
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 [method@Gtk.LevelBar.set_min_value] and
[method@Gtk.LevelBar.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 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_ACCESSIBLE_ROLE_METER role.
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.bailu.gtk.gtk.Widget
Widget.OnDestroy, Widget.OnDestroyNotify, Widget.OnDirectionChanged, Widget.OnHide, Widget.OnKeynavFailed, Widget.OnMap, Widget.OnMnemonicActivate, Widget.OnMoveFocus, Widget.OnQueryTooltip, Widget.OnRealize, Widget.OnShow, Widget.OnStateFlagsChanged, Widget.OnTickCallback, Widget.OnUnmap, Widget.OnUnrealize
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gtk.Widget
SIGNAL_ON_DESTROY, SIGNAL_ON_DIRECTION_CHANGED, SIGNAL_ON_HIDE, SIGNAL_ON_KEYNAV_FAILED, SIGNAL_ON_MAP, SIGNAL_ON_MNEMONIC_ACTIVATE, SIGNAL_ON_MOVE_FOCUS, SIGNAL_ON_QUERY_TOOLTIP, SIGNAL_ON_REALIZE, SIGNAL_ON_SHOW, SIGNAL_ON_STATE_FLAGS_CHANGED, SIGNAL_ON_UNMAP, SIGNAL_ON_UNREALIZE
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addOffsetValue
(Str name, double value) Adds a new offset marker on @self at the position specified by @value.void
addOffsetValue
(String name, double value) Adds a new offset marker on @self at the position specified by @value.Implements interfaceAccessible
.Implements interfaceBuildable
.Implements interfaceConstraintTarget
.Implements interfaceOrientable
.static ClassHandler
static int
boolean
Returns whether the levelbar is inverted.double
Returns the `max-value` of the `GtkLevelBar`.double
Returns the `min-value of the `GtkLevelBar`.int
getMode()
Returns the `mode` of the `GtkLevelBar`.static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
double
getValue()
Returns the `value` of the `GtkLevelBar`.static LevelBar
newForIntervalLevelBar
(double min_value, double max_value) Creates a new `GtkLevelBar` for the specified interval.Connect to signal "offset-changed".void
removeOffsetValue
(Str name) Removes an offset marker from a `GtkLevelBar`.void
removeOffsetValue
(String name) Removes an offset marker from a `GtkLevelBar`.void
setInverted
(boolean inverted) Sets whether the `GtkLevelBar` is inverted.void
setMaxValue
(double value) Sets the `max-value` of the `GtkLevelBar`.void
setMinValue
(double value) Sets the `min-value` of the `GtkLevelBar`.void
setMode
(int mode) Sets the `mode` of the `GtkLevelBar`.void
setValue
(double value) Sets the value of the `GtkLevelBar`.Methods inherited from class ch.bailu.gtk.gtk.Widget
actionSetEnabled, actionSetEnabled, activate, activateAction, activateAction, activateActionVariant, activateActionVariant, activateDefault, addController, addCssClass, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, createPangoLayout, disposeTemplate, dragCheckThreshold, errorBell, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getCanFocus, getCanTarget, getChildVisible, getClipboard, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeCssClass, removeMnemonicLabel, removeTickCallback, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setTooltipMarkup, setTooltipMarkup, setTooltipText, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, snapshotChild, triggerTooltipQuery, unmap, unparent, unrealize, unsetStateFlags
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_OFFSET_CHANGED
- See Also:
-
-
Constructor Details
-
LevelBar
-
LevelBar
public LevelBar()Creates a new `GtkLevelBar`.
-
-
Method Details
-
getClassHandler
-
newForIntervalLevelBar
Creates a new `GtkLevelBar` for the specified interval.- Parameters:
min_value
- a positive valuemax_value
- a positive value- Returns:
- a `GtkLevelBar`
-
addOffsetValue
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 [property@Gtk.LevelBar: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:
name
- the name of the new offsetvalue
- the value for the new offset
-
addOffsetValue
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 [property@Gtk.LevelBar: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:
name
- the name of the new offsetvalue
- the value for the new offset
-
getInverted
public boolean getInverted()Returns whether the levelbar is inverted.- Returns:
- %TRUE if the level bar is inverted
-
getMaxValue
public double getMaxValue()Returns the `max-value` of the `GtkLevelBar`.- Returns:
- a positive value
-
getMinValue
public double getMinValue()Returns the `min-value of the `GtkLevelBar`.- Returns:
- a positive value
-
getMode
public int getMode()Returns the `mode` of the `GtkLevelBar`.- Returns:
- a `GtkLevelBarMode`
-
getValue
public double getValue()Returns the `value` of the `GtkLevelBar`.- Returns:
- a value in the interval between [property@Gtk.LevelBar:min-value[ and [property@Gtk.LevelBar:max-value]
-
removeOffsetValue
Removes an offset marker from a `GtkLevelBar`.
The marker must have been previously added with
[method@Gtk.LevelBar.add_offset_value].- Parameters:
name
- the name of an offset in the bar
-
removeOffsetValue
Removes an offset marker from a `GtkLevelBar`.
The marker must have been previously added with
[method@Gtk.LevelBar.add_offset_value].- Parameters:
name
- the name of an offset in the bar
-
setInverted
public void setInverted(boolean inverted) Sets whether the `GtkLevelBar` is inverted.- Parameters:
inverted
- %TRUE to invert the level bar
-
setMaxValue
public void setMaxValue(double value) Sets the `max-value` of the `GtkLevelBar`.
You probably want to update preexisting level offsets after calling
this function.- Parameters:
value
- a positive value
-
setMinValue
public void setMinValue(double value) Sets the `min-value` of the `GtkLevelBar`.
You probably want to update preexisting level offsets after calling
this function.- Parameters:
value
- a positive value
-
setMode
public void setMode(int mode) Sets the `mode` of the `GtkLevelBar`.- Parameters:
mode
- a `GtkLevelBarMode`
-
setValue
public void setValue(double value) Sets the value of the `GtkLevelBar`.- Parameters:
value
- a value in the interval between [property@Gtk.LevelBar:min-value] and [property@Gtk.LevelBar:max-value]
-
onOffsetChanged
Connect to signal "offset-changed".
SeeLevelBar.OnOffsetChanged.onOffsetChanged(ch.bailu.gtk.type.Str)
for signal description.
FieldSIGNAL_ON_OFFSET_CHANGED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
asAccessible
Implements interfaceAccessible
. Call this to get access to interface functions.- Overrides:
asAccessible
in classWidget
- Returns:
Accessible
-
asBuildable
Implements interfaceBuildable
. Call this to get access to interface functions.- Overrides:
asBuildable
in classWidget
- Returns:
Buildable
-
asConstraintTarget
Implements interfaceConstraintTarget
. Call this to get access to interface functions.- Overrides:
asConstraintTarget
in classWidget
- Returns:
ConstraintTarget
-
asOrientable
Implements interfaceOrientable
. Call this to get access to interface functions.- Returns:
Orientable
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-