Class SpaceDrawer

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class SpaceDrawer extends GObject

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.

  • Constructor Details

    • SpaceDrawer

      public SpaceDrawer(MemorySegment address)
      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

      public static @Nullable Type getType()
      Get the GType of the SpaceDrawer class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected SpaceDrawer asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • bindMatrixSetting

      public void bindMatrixSetting(Settings settings, String key, Set<SettingsBindFlags> flags)

      Binds the SpaceDrawer:matrix property to a Settings key.

      The Settings key must be of the same type as the SpaceDrawer:matrix property, that is, "au".

      The Settings#bind function cannot be used, because the default GIO mapping functions don't support GLib.Variant properties (maybe it will be supported by a future GIO version, in which case this function can be deprecated).

      Parameters:
      settings - a GSettings object.
      key - the settings key to bind.
      flags - flags for the binding.
    • bindMatrixSetting

      public void bindMatrixSetting(Settings settings, String key, SettingsBindFlags... flags)

      Binds the SpaceDrawer:matrix property to a Settings key.

      The Settings key must be of the same type as the SpaceDrawer:matrix property, that is, "au".

      The Settings#bind function cannot be used, because the default GIO mapping functions don't support GLib.Variant properties (maybe it will be supported by a future GIO version, in which case this function can be deprecated).

      Parameters:
      settings - a GSettings object.
      key - the settings key to bind.
      flags - flags for the binding.
    • getEnableMatrix

      public boolean getEnableMatrix()
    • getMatrix

      public Variant getMatrix()

      Gets the value of the SpaceDrawer:matrix property, as a GLib.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 floating GVariant instance.
    • getTypesForLocations

      public Set<SpaceTypeFlags> getTypesForLocations(Set<SpaceLocationFlags> locations)

      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:matrix property.

      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 several GtkSourceSpaceLocationFlags.
      Returns:
      a combination of GtkSourceSpaceTypeFlags.
    • getTypesForLocations

      public Set<SpaceTypeFlags> getTypesForLocations(SpaceLocationFlags... locations)

      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:matrix property.

      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 several GtkSourceSpaceLocationFlags.
      Returns:
      a combination of GtkSourceSpaceTypeFlags.
    • setEnableMatrix

      public void setEnableMatrix(boolean enableMatrix)
      Sets whether the SpaceDrawer:matrix property is enabled.
      Parameters:
      enableMatrix - the new value.
    • setMatrix

      public void setMatrix(@Nullable Variant matrix)

      Sets a new value to the SpaceDrawer:matrix property, as a GLib.Variant.

      If matrix is null, then an empty array is set.

      If matrix is floating, it is consumed.

      The setTypesForLocations(Set, Set) function may be more convenient to use.

      Parameters:
      matrix - the new matrix value, or null.
    • setTypesForLocations

      public void setTypesForLocations(Set<SpaceLocationFlags> locations, Set<SpaceTypeFlags> types)
      Modifies the SpaceDrawer:matrix property at the specified locations.
      Parameters:
      locations - one or several GtkSourceSpaceLocationFlags.
      types - a combination of GtkSourceSpaceTypeFlags.
    • setTypesForLocations

      public void setTypesForLocations(SpaceLocationFlags locations, SpaceTypeFlags... types)
      Modifies the SpaceDrawer:matrix property at the specified locations.
      Parameters:
      locations - one or several GtkSourceSpaceLocationFlags.
      types - a combination of GtkSourceSpaceTypeFlags.
    • builder

      public static SpaceDrawer.Builder<? extends SpaceDrawer.Builder> builder()
      A SpaceDrawer.Builder object constructs a SpaceDrawer with the specified properties. Use the various set...() methods to set properties, and finish construction with SpaceDrawer.Builder.build().
      Returns:
      the builder object