GutterRenderer
Superclasses: Widget
, InitiallyUnowned
, Object
Subclasses: GutterRendererPixbuf
, GutterRendererText
Implemented Interfaces: Accessible
, Buildable
, ConstraintTarget
Gutter cell renderer.
A GtkSourceGutterRenderer
represents a column in a Gutter
. The
column contains one cell for each visible line of the TextBuffer
. Due to
text wrapping, a cell can thus span multiple lines of the TextView
. In
this case, GutterRendererAlignmentMode
controls the alignment of
the cell.
The gutter renderer is a Widget
and is measured using the normal widget
measurement facilities. The width of the gutter will be determined by the
measurements of the gutter renderers.
The width of a gutter renderer generally takes into account the entire text
buffer. For instance, to display the line numbers, if the buffer contains 100
lines, the gutter renderer will always set its width such as three digits can
be printed, even if only the first 20 lines are shown. Another strategy is to
take into account only the visible lines. In this case, only two digits are
necessary to display the line numbers of the first 20 lines. To take another
example, the gutter renderer for Mark
’s doesn’t need to take
into account the text buffer to announce its width. It only depends on the
icons size displayed in the gutter column.
When the available size to render a cell is greater than the required size to
render the cell contents, the cell contents can be aligned horizontally and
vertically with set_alignment_mode
.
The cells rendering occurs using snapshot
. Implementations
should use gtk_source_gutter_renderer_get_lines()
to retrieve information
about the lines to be rendered. To help with aligning content which takes
into account the padding and alignment of a cell, implementations may call
align_cell
for a given line number with the
width and height measurement of the content they width to render.
Methods
- class GutterRenderer
- activate(iter: TextIter, area: Rectangle, button: int, state: ModifierType, n_presses: int) None
Emits the
activate
signal of the renderer. This is called fromGutter
and should never have to be called manually.- Parameters:
iter – a
TextIter
at the start of the line where the renderer is activatedarea – a
Rectangle
of the cell area where the renderer is activatedbutton – the button that was pressed
state – a
ModifierType
n_presses – the number of button presses
- align_cell(line: int, width: float, height: float) tuple[float, float]
Locates where to render content that is
width
xheight
based on the renderers alignment and padding.The location will be placed into
x
andy
and is relative to the renderer’s coordinates.It is encouraged that renderers use this function when snappshotting to ensure consistent placement of their contents.
- Parameters:
line – the line number for content
width – the width of the content to draw
height – the height of the content to draw
- get_alignment_mode() GutterRendererAlignmentMode
Get the alignment mode.
The alignment mode describes the manner in which the renderer is aligned (see
xalign
andyalign
).
- get_xalign() float
Gets the
xalign
property.This may be used to adjust where within the cell rectangle the renderer will draw.
- get_xpad() int
Gets the
xpad
property.This may be used to adjust the cell rectangle that the renderer will use to draw.
- get_yalign() float
Gets the
yalign
property.This may be used to adjust where within the cell rectangle the renderer will draw.
- get_ypad() int
Gets the
ypad
property.This may be used to adjust the cell rectangle that the renderer will use to draw.
- query_activatable(iter: TextIter, area: Rectangle) bool
Get whether the renderer is activatable at the location provided. This is called from
Gutter
to determine whether a renderer is activatable using the mouse pointer.
- set_alignment_mode(mode: GutterRendererAlignmentMode) None
Set the alignment mode. The alignment mode describes the manner in which the renderer is aligned (see
xalign
andyalign
).- Parameters:
mode – a
GutterRendererAlignmentMode
- set_xalign(xalign: float) None
Adjusts the
xalign
property.This may be used to adjust where within the cell rectangle the renderer will draw.
- Parameters:
xalign – the Y padding for the drawing cell
- set_xpad(xpad: int) None
Adjusts the
xpad
property.This may be used to adjust the cell rectangle that the renderer will use to draw.
- Parameters:
xpad – the Y padding for the drawing cell
Properties
- class GutterRenderer
- props.alignment_mode: GutterRendererAlignmentMode
The alignment mode of the renderer.
This can be used to indicate that in the case a cell spans multiple lines (due to text wrapping) the alignment should work on either the full cell, the first line or the last line.
- props.lines: GutterLines
Contains information about the lines to be rendered.
It should be used by
GutterRenderer
implementations fromsnapshot
.
- props.xalign: float
The horizontal alignment of the renderer.
Set to 0 for a left alignment. 1 for a right alignment. And 0.5 for centering the cells. A value lower than 0 doesn’t modify the alignment.
Signals
- class GutterRenderer.signals
- activate(iter: TextIter, area: Rectangle, button: int, state: ModifierType, n_presses: int) None
The signal is emitted when the renderer is activated.
- Parameters:
iter – a
TextIter
area – a
Rectangle
button – the button that was pressed
state – a
ModifierType
of staten_presses – the number of button presses
Virtual Methods
- class GutterRenderer
- do_activate(iter: TextIter, area: Rectangle, button: int, state: ModifierType, n_presses: int) None
Emits the
activate
signal of the renderer. This is called fromGutter
and should never have to be called manually.- Parameters:
iter – a
TextIter
at the start of the line where the renderer is activatedarea – a
Rectangle
of the cell area where the renderer is activatedbutton – the button that was pressed
state – a
ModifierType
n_presses – the number of button presses
- do_begin(lines: GutterLines) None
- Parameters:
lines
- do_change_buffer(old_buffer: Buffer | None = None) None
This is called when the text buffer changes for
renderer
.- Parameters:
old_buffer – the old
TextBuffer
.
- do_change_view(old_view: View | None = None) None
This is called when the text view changes for
renderer
.- Parameters:
old_view – the old
TextView
.
- do_query_activatable(iter: TextIter, area: Rectangle) bool
Get whether the renderer is activatable at the location provided. This is called from
Gutter
to determine whether a renderer is activatable using the mouse pointer.
- do_query_data(lines: GutterLines, line: int) None
- Parameters:
lines
line
- do_snapshot_line(snapshot: Snapshot, lines: GutterLines, line: int) None
- Parameters:
snapshot
lines
line
Fields
- class GutterRenderer
- parent_instance