Class SpaceDrawer
- All Implemented Interfaces:
Proxy
Represent white space characters with symbols.
GtkSourceSpaceDrawer provides a way to visualize white spaces, by drawing
symbols.
Call View.getSpaceDrawer() to get the GtkSourceSpaceDrawer
instance of a certain View.
By default, no white spaces are drawn because the
SpaceDrawer:enable-matrix is false.
To draw white spaces, setTypesForLocations(Set, Set) can
be called to set the SpaceDrawer:matrix property (by default all
space types are enabled at all locations). Then call
setEnableMatrix(boolean).
For a finer-grained method, there is also the Tag's
Tag:draw-spaces property.
Example
To draw non-breaking spaces everywhere and draw all types of trailing spaces except newlines:
gtk_source_space_drawer_set_types_for_locations (space_drawer,
GTK_SOURCE_SPACE_LOCATION_ALL,
GTK_SOURCE_SPACE_TYPE_NBSP);
gtk_source_space_drawer_set_types_for_locations (space_drawer,
GTK_SOURCE_SPACE_LOCATION_TRAILING,
GTK_SOURCE_SPACE_TYPE_ALL &
~GTK_SOURCE_SPACE_TYPE_NEWLINE);
gtk_source_space_drawer_set_enable_matrix (space_drawer, TRUE);
space_drawer.set_types_for_locations(
locations=GtkSource.SpaceLocationFlags.ALL,
types=GtkSource.SpaceTypeFlags.NBSP,
)
all_types_except_newline = GtkSource.SpaceTypeFlags(
int(GtkSource.SpaceTypeFlags.ALL) & ~int(GtkSource.SpaceTypeFlags.NEWLINE)
)
space_drawer.set_types_for_locations(
locations=GtkSource.SpaceLocationFlags.TRAILING,
types=all_types_except_newline,
)
space_drawer.set_enable_matrix(True)
Use-case: draw unwanted white spaces
A possible use-case is to draw only unwanted white spaces. Examples:
- Draw all trailing spaces.
- If the indentation and alignment must be done with spaces, draw tabs.
And non-breaking spaces can always be drawn, everywhere, to distinguish them from normal spaces.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSpaceDrawer.Builder<B extends SpaceDrawer.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new SpaceDrawer.SpaceDrawer(MemorySegment address) Create a SpaceDrawer instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected SpaceDrawerasParent()Return this instance as if it were its parent type.voidbindMatrixSetting(Settings settings, String key, Set<SettingsBindFlags> flags) Binds theSpaceDrawer:matrixproperty to aSettingskey.voidbindMatrixSetting(Settings settings, String key, SettingsBindFlags... flags) Binds theSpaceDrawer:matrixproperty to aSettingskey.static SpaceDrawer.Builder<? extends SpaceDrawer.Builder> builder()ASpaceDrawer.Builderobject constructs aSpaceDrawerwith the specified properties.booleanGets the value of theSpaceDrawer:matrixproperty, as aGLib.Variant.static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the SpaceDrawer class.getTypesForLocations(Set<SpaceLocationFlags> locations) If only one location is specified, this function returns what kind of white spaces are drawn at that location.getTypesForLocations(SpaceLocationFlags... locations) If only one location is specified, this function returns what kind of white spaces are drawn at that location.voidsetEnableMatrix(boolean enableMatrix) Sets whether theSpaceDrawer:matrixproperty is enabled.voidSets a new value to theSpaceDrawer:matrixproperty, as aGLib.Variant.voidsetTypesForLocations(Set<SpaceLocationFlags> locations, Set<SpaceTypeFlags> types) Modifies theSpaceDrawer:matrixproperty at the specifiedlocations.voidsetTypesForLocations(SpaceLocationFlags locations, SpaceTypeFlags... types) Modifies theSpaceDrawer:matrixproperty at the specifiedlocations.Methods inherited from class GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
SpaceDrawer
Create a SpaceDrawer instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
SpaceDrawer
public SpaceDrawer()Create a new SpaceDrawer.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Return this instance as if it were its parent type. Comparable to the Javasuperkeyword, but ensures the parent typeclass is also used in native code. -
bindMatrixSetting
Binds the
SpaceDrawer:matrixproperty to aSettingskey.The
Settingskey must be of the same type as theSpaceDrawer:matrixproperty, that is,"au".The Settings#bind function cannot be used, because the default GIO mapping functions don't support
GLib.Variantproperties (maybe it will be supported by a future GIO version, in which case this function can be deprecated).- Parameters:
settings- aGSettingsobject.key- thesettingskey to bind.flags- flags for the binding.
-
bindMatrixSetting
Binds the
SpaceDrawer:matrixproperty to aSettingskey.The
Settingskey must be of the same type as theSpaceDrawer:matrixproperty, that is,"au".The Settings#bind function cannot be used, because the default GIO mapping functions don't support
GLib.Variantproperties (maybe it will be supported by a future GIO version, in which case this function can be deprecated).- Parameters:
settings- aGSettingsobject.key- thesettingskey to bind.flags- flags for the binding.
-
getEnableMatrix
public boolean getEnableMatrix() -
getMatrix
Gets the value of the
SpaceDrawer:matrixproperty, as aGLib.Variant.An empty array can be returned in case the matrix is a zero matrix.
The
getTypesForLocations(Set)function may be more convenient to use.- Returns:
- the
GtkSourceSpaceDrawer:matrix value as a new floatingGVariantinstance.
-
getTypesForLocations
If only one location is specified, this function returns what kind of white spaces are drawn at that location.
The value is retrieved from the
SpaceDrawer:matrixproperty.If several locations are specified, this function returns the logical AND for those locations. Which means that if a certain kind of white space is present in the return value, then that kind of white space is drawn at all the specified
locations.- Parameters:
locations- one or severalGtkSourceSpaceLocationFlags.- Returns:
- a combination of
GtkSourceSpaceTypeFlags.
-
getTypesForLocations
If only one location is specified, this function returns what kind of white spaces are drawn at that location.
The value is retrieved from the
SpaceDrawer:matrixproperty.If several locations are specified, this function returns the logical AND for those locations. Which means that if a certain kind of white space is present in the return value, then that kind of white space is drawn at all the specified
locations.- Parameters:
locations- one or severalGtkSourceSpaceLocationFlags.- Returns:
- a combination of
GtkSourceSpaceTypeFlags.
-
setEnableMatrix
public void setEnableMatrix(boolean enableMatrix) Sets whether theSpaceDrawer:matrixproperty is enabled.- Parameters:
enableMatrix- the new value.
-
setMatrix
Sets a new value to the
SpaceDrawer:matrixproperty, as aGLib.Variant.If
matrixisnull, then an empty array is set.If
matrixis floating, it is consumed.The
setTypesForLocations(Set, Set)function may be more convenient to use.- Parameters:
matrix- the new matrix value, ornull.
-
setTypesForLocations
Modifies theSpaceDrawer:matrixproperty at the specifiedlocations.- Parameters:
locations- one or severalGtkSourceSpaceLocationFlags.types- a combination ofGtkSourceSpaceTypeFlags.
-
setTypesForLocations
Modifies theSpaceDrawer:matrixproperty at the specifiedlocations.- Parameters:
locations- one or severalGtkSourceSpaceLocationFlags.types- a combination ofGtkSourceSpaceTypeFlags.
-
builder
ASpaceDrawer.Builderobject constructs aSpaceDrawerwith the specified properties. Use the variousset...()methods to set properties, and finish construction withSpaceDrawer.Builder.build().- Returns:
- the builder object
-