gtk4::prelude

Trait SnapshotExt

source
pub trait SnapshotExt:
    IsA<Snapshot>
    + Sealed
    + 'static {
Show 48 methods // Provided methods fn append_cairo(&self, bounds: &Rect) -> Context { ... } fn append_color(&self, color: &RGBA, bounds: &Rect) { ... } fn append_conic_gradient( &self, bounds: &Rect, center: &Point, rotation: f32, stops: &[ColorStop], ) { ... } fn append_fill(&self, path: &Path, fill_rule: FillRule, color: &RGBA) { ... } fn append_inset_shadow( &self, outline: &RoundedRect, color: &RGBA, dx: f32, dy: f32, spread: f32, blur_radius: f32, ) { ... } fn append_layout(&self, layout: &Layout, color: &RGBA) { ... } fn append_linear_gradient( &self, bounds: &Rect, start_point: &Point, end_point: &Point, stops: &[ColorStop], ) { ... } fn append_node(&self, node: impl AsRef<RenderNode>) { ... } fn append_outset_shadow( &self, outline: &RoundedRect, color: &RGBA, dx: f32, dy: f32, spread: f32, blur_radius: f32, ) { ... } fn append_radial_gradient( &self, bounds: &Rect, center: &Point, hradius: f32, vradius: f32, start: f32, end: f32, stops: &[ColorStop], ) { ... } fn append_repeating_linear_gradient( &self, bounds: &Rect, start_point: &Point, end_point: &Point, stops: &[ColorStop], ) { ... } fn append_repeating_radial_gradient( &self, bounds: &Rect, center: &Point, hradius: f32, vradius: f32, start: f32, end: f32, stops: &[ColorStop], ) { ... } fn append_scaled_texture( &self, texture: &impl IsA<Texture>, filter: ScalingFilter, bounds: &Rect, ) { ... } fn append_stroke(&self, path: &Path, stroke: &Stroke, color: &RGBA) { ... } fn append_texture(&self, texture: &impl IsA<Texture>, bounds: &Rect) { ... } fn gl_shader_pop_texture(&self) { ... } fn perspective(&self, depth: f32) { ... } fn pop(&self) { ... } fn push_blend(&self, blend_mode: BlendMode) { ... } fn push_blur(&self, radius: f64) { ... } fn push_clip(&self, bounds: &Rect) { ... } fn push_color_matrix(&self, color_matrix: &Matrix, color_offset: &Vec4) { ... } fn push_cross_fade(&self, progress: f64) { ... } fn push_fill(&self, path: &Path, fill_rule: FillRule) { ... } fn push_gl_shader(&self, shader: &GLShader, bounds: &Rect, take_args: Bytes) { ... } fn push_mask(&self, mask_mode: MaskMode) { ... } fn push_opacity(&self, opacity: f64) { ... } fn push_repeat(&self, bounds: &Rect, child_bounds: Option<&Rect>) { ... } fn push_rounded_clip(&self, bounds: &RoundedRect) { ... } fn push_shadow(&self, shadow: &[Shadow]) { ... } fn push_stroke(&self, path: &Path, stroke: &Stroke) { ... } fn render_background( &self, context: &impl IsA<StyleContext>, x: f64, y: f64, width: f64, height: f64, ) { ... } fn render_focus( &self, context: &impl IsA<StyleContext>, x: f64, y: f64, width: f64, height: f64, ) { ... } fn render_frame( &self, context: &impl IsA<StyleContext>, x: f64, y: f64, width: f64, height: f64, ) { ... } fn render_insertion_cursor( &self, context: &impl IsA<StyleContext>, x: f64, y: f64, layout: &Layout, index: i32, direction: Direction, ) { ... } fn render_layout( &self, context: &impl IsA<StyleContext>, x: f64, y: f64, layout: &Layout, ) { ... } fn restore(&self) { ... } fn rotate(&self, angle: f32) { ... } fn rotate_3d(&self, angle: f32, axis: &Vec3) { ... } fn save(&self) { ... } fn scale(&self, factor_x: f32, factor_y: f32) { ... } fn scale_3d(&self, factor_x: f32, factor_y: f32, factor_z: f32) { ... } fn to_node(self) -> Option<RenderNode> { ... } fn to_paintable(self, size: Option<&Size>) -> Option<Paintable> { ... } fn transform(&self, transform: Option<&Transform>) { ... } fn transform_matrix(&self, matrix: &Matrix) { ... } fn translate(&self, point: &Point) { ... } fn translate_3d(&self, point: &Point3D) { ... }
}
Expand description

Trait containing all Snapshot methods.

§Implementors

Snapshot

Provided Methods§

source

fn append_cairo(&self, bounds: &Rect) -> Context

Creates a new gsk::CairoNode and appends it to the current render node of @self, without changing the current node.

§bounds

the bounds for the new node

§Returns

a cairo::Context suitable for drawing the contents of the newly created render node

source

fn append_color(&self, color: &RGBA, bounds: &Rect)

Creates a new render node drawing the @color into the given @bounds and appends it to the current render node of @self.

You should try to avoid calling this function if @color is transparent.

§color

the color to draw

§bounds

the bounds for the new node

source

fn append_conic_gradient( &self, bounds: &Rect, center: &Point, rotation: f32, stops: &[ColorStop], )

Appends a conic gradient node with the given stops to @self.

§bounds

the rectangle to render the gradient into

§center

the center point of the conic gradient

§rotation

the clockwise rotation in degrees of the starting angle. 0 means the starting angle is the top.

§stops

the color stops defining the gradient

source

fn append_fill(&self, path: &Path, fill_rule: FillRule, color: &RGBA)

Available on crate feature v4_14 only.

A convenience method to fill a path with a color.

See push_fill() if you need to fill a path with more complex content than a color.

§path

The path describing the area to fill

§fill_rule

The fill rule to use

§color

the color to fill the path with

source

fn append_inset_shadow( &self, outline: &RoundedRect, color: &RGBA, dx: f32, dy: f32, spread: f32, blur_radius: f32, )

Appends an inset shadow into the box given by @outline.

§outline

outline of the region surrounded by shadow

§color

color of the shadow

§dx

horizontal offset of shadow

§dy

vertical offset of shadow

§spread

how far the shadow spreads towards the inside

§blur_radius

how much blur to apply to the shadow

source

fn append_layout(&self, layout: &Layout, color: &RGBA)

Creates render nodes for rendering @layout in the given foregound @color and appends them to the current node of @self without changing the current node. The current theme’s foreground color for a widget can be obtained with WidgetExt::color().

Note that if the layout does not produce any visible output, then nodes may not be added to the @self.

§layout

the pango::Layout to render

§color

the foreground color to render the layout in

source

fn append_linear_gradient( &self, bounds: &Rect, start_point: &Point, end_point: &Point, stops: &[ColorStop], )

Appends a linear gradient node with the given stops to @self.

§bounds

the rectangle to render the linear gradient into

§start_point

the point at which the linear gradient will begin

§end_point

the point at which the linear gradient will finish

§stops

the color stops defining the gradient

source

fn append_node(&self, node: impl AsRef<RenderNode>)

Appends @node to the current render node of @self, without changing the current node.

If @self does not have a current node yet, @node will become the initial node.

§node

a gsk::RenderNode

source

fn append_outset_shadow( &self, outline: &RoundedRect, color: &RGBA, dx: f32, dy: f32, spread: f32, blur_radius: f32, )

Appends an outset shadow node around the box given by @outline.

§outline

outline of the region surrounded by shadow

§color

color of the shadow

§dx

horizontal offset of shadow

§dy

vertical offset of shadow

§spread

how far the shadow spreads towards the outside

§blur_radius

how much blur to apply to the shadow

source

fn append_radial_gradient( &self, bounds: &Rect, center: &Point, hradius: f32, vradius: f32, start: f32, end: f32, stops: &[ColorStop], )

Appends a radial gradient node with the given stops to @self.

§bounds

the rectangle to render the readial gradient into

§center

the center point for the radial gradient

§hradius

the horizontal radius

§vradius

the vertical radius

§start

the start position (on the horizontal axis)

§end

the end position (on the horizontal axis)

§stops

the color stops defining the gradient

source

fn append_repeating_linear_gradient( &self, bounds: &Rect, start_point: &Point, end_point: &Point, stops: &[ColorStop], )

Appends a repeating linear gradient node with the given stops to @self.

§bounds

the rectangle to render the linear gradient into

§start_point

the point at which the linear gradient will begin

§end_point

the point at which the linear gradient will finish

§stops

the color stops defining the gradient

source

fn append_repeating_radial_gradient( &self, bounds: &Rect, center: &Point, hradius: f32, vradius: f32, start: f32, end: f32, stops: &[ColorStop], )

Appends a repeating radial gradient node with the given stops to @self.

§bounds

the rectangle to render the readial gradient into

§center

the center point for the radial gradient

§hradius

the horizontal radius

§vradius

the vertical radius

§start

the start position (on the horizontal axis)

§end

the end position (on the horizontal axis)

§stops

the color stops defining the gradient

source

fn append_scaled_texture( &self, texture: &impl IsA<Texture>, filter: ScalingFilter, bounds: &Rect, )

Available on crate feature v4_10 only.

Creates a new render node drawing the @texture into the given @bounds and appends it to the current render node of @self.

In contrast to append_texture(), this function provides control about how the filter that is used when scaling.

§texture

the texture to render

§filter

the filter to use

§bounds

the bounds for the new node

source

fn append_stroke(&self, path: &Path, stroke: &Stroke, color: &RGBA)

Available on crate feature v4_14 only.

A convenience method to stroke a path with a color.

See push_stroke() if you need to stroke a path with more complex content than a color.

§path

The path describing the area to fill

§stroke

The stroke attributes

§color

the color to fill the path with

source

fn append_texture(&self, texture: &impl IsA<Texture>, bounds: &Rect)

Creates a new render node drawing the @texture into the given @bounds and appends it to the current render node of @self.

If the texture needs to be scaled to fill @bounds, linear filtering is used. See append_scaled_texture() if you need other filtering, such as nearest-neighbour.

§texture

the texture to render

§bounds

the bounds for the new node

source

fn gl_shader_pop_texture(&self)

👎Deprecated: Since 4.16

Removes the top element from the stack of render nodes and adds it to the nearest gsk::GLShaderNode below it.

This must be called the same number of times as the number of textures is needed for the shader in push_gl_shader().

§Deprecated since 4.16

GTK’s new Vulkan-focused rendering does not support this feature. Use GLArea for OpenGL rendering.

source

fn perspective(&self, depth: f32)

Applies a perspective projection transform.

See gsk::Transform::perspective() for a discussion on the details.

§depth

distance of the z=0 plane

source

fn pop(&self)

Removes the top element from the stack of render nodes, and appends it to the node underneath it.

source

fn push_blend(&self, blend_mode: BlendMode)

Blends together two images with the given blend mode.

Until the first call to pop(), the bottom image for the blend operation will be recorded. After that call, the top image to be blended will be recorded until the second call to pop().

Calling this function requires two subsequent calls to pop().

§blend_mode

blend mode to use

source

fn push_blur(&self, radius: f64)

Blurs an image.

The image is recorded until the next call to pop().

§radius

the blur radius to use. Must be positive

source

fn push_clip(&self, bounds: &Rect)

Clips an image to a rectangle.

The image is recorded until the next call to pop().

§bounds

the rectangle to clip to

source

fn push_color_matrix(&self, color_matrix: &Matrix, color_offset: &Vec4)

Modifies the colors of an image by applying an affine transformation in RGB space.

In particular, the colors will be transformed by applying

pixel = transpose(color_matrix) * pixel + color_offset

for every pixel. The transformation operates on unpremultiplied colors, with color components ordered R, G, B, A.

The image is recorded until the next call to pop().

§color_matrix

the color matrix to use

§color_offset

the color offset to use

source

fn push_cross_fade(&self, progress: f64)

Snapshots a cross-fade operation between two images with the given @progress.

Until the first call to pop(), the start image will be snapshot. After that call, the end image will be recorded until the second call to pop().

Calling this function requires two subsequent calls to pop().

§progress

progress between 0.0 and 1.0

source

fn push_fill(&self, path: &Path, fill_rule: FillRule)

Available on crate feature v4_14 only.

Fills the area given by @path and @fill_rule with an image and discards everything outside of it.

The image is recorded until the next call to pop().

If you want to fill the path with a color, append_fill() may be more convenient.

§path

The path describing the area to fill

§fill_rule

The fill rule to use

source

fn push_gl_shader(&self, shader: &GLShader, bounds: &Rect, take_args: Bytes)

👎Deprecated: Since 4.16

Push a gsk::GLShaderNode.

The node uses the given gsk::GLShader and uniform values Additionally this takes a list of @n_children other nodes which will be passed to the gsk::GLShaderNode.

The @take_args argument is a block of data to use for uniform arguments, as per types and offsets defined by the @shader. Normally this is generated by Gsk::GLShader::format_args() or Gsk::ShaderArgsBuilder.

The snapshotter takes ownership of @take_args, so the caller should not free it after this.

If the renderer doesn’t support GL shaders, or if there is any problem when compiling the shader, then the node will draw pink. You should use GLShader::compile() to ensure the @shader will work for the renderer before using it.

If the shader requires textures (see GLShader::n_textures()), then it is expected that you call gl_shader_pop_texture() the number of times that are required. Each of these calls will generate a node that is added as a child to the gsk::GLShaderNode, which in turn will render these offscreen and pass as a texture to the shader.

Once all textures (if any) are pop:ed, you must call the regular pop().

If you want to use pre-existing textures as input to the shader rather than rendering new ones, use append_texture() to push a texture node. These will be used directly rather than being re-rendered.

For details on how to write shaders, see gsk::GLShader.

§Deprecated since 4.16

GTK’s new Vulkan-focused rendering does not support this feature. Use GLArea for OpenGL rendering.

§shader

The code to run

§bounds

the rectangle to render into

§take_args

Data block with arguments for the shader.

source

fn push_mask(&self, mask_mode: MaskMode)

Available on crate feature v4_10 only.

Until the first call to pop(), the mask image for the mask operation will be recorded.

After that call, the source image will be recorded until the second call to pop().

Calling this function requires 2 subsequent calls to gtk_snapshot_pop().

§mask_mode

mask mode to use

source

fn push_opacity(&self, opacity: f64)

Modifies the opacity of an image.

The image is recorded until the next call to pop().

§opacity

the opacity to use

source

fn push_repeat(&self, bounds: &Rect, child_bounds: Option<&Rect>)

Creates a node that repeats the child node.

The child is recorded until the next call to pop().

§bounds

the bounds within which to repeat

§child_bounds

the bounds of the child or None to use the full size of the collected child node

source

fn push_rounded_clip(&self, bounds: &RoundedRect)

Clips an image to a rounded rectangle.

The image is recorded until the next call to pop().

§bounds

the rounded rectangle to clip to

source

fn push_shadow(&self, shadow: &[Shadow])

Applies a shadow to an image.

The image is recorded until the next call to pop().

§shadow

the first shadow specification

source

fn push_stroke(&self, path: &Path, stroke: &Stroke)

Available on crate feature v4_14 only.

Strokes the given @path with the attributes given by @stroke and an image.

The image is recorded until the next call to pop().

Note that the strokes are subject to the same transformation as everything else, so uneven scaling will cause horizontal and vertical strokes to have different widths.

If you want to stroke the path with a color, append_stroke() may be more convenient.

§path

The path to stroke

§stroke

The stroke attributes

source

fn render_background( &self, context: &impl IsA<StyleContext>, x: f64, y: f64, width: f64, height: f64, )

👎Deprecated: Since 4.10

Creates a render node for the CSS background according to @context, and appends it to the current node of @self, without changing the current node.

§Deprecated since 4.10
§context

the style context that defines the background

§x

X origin of the rectangle

§y

Y origin of the rectangle

§width

rectangle width

§height

rectangle height

source

fn render_focus( &self, context: &impl IsA<StyleContext>, x: f64, y: f64, width: f64, height: f64, )

👎Deprecated: Since 4.10

Creates a render node for the focus outline according to @context, and appends it to the current node of @self, without changing the current node.

§Deprecated since 4.10
§context

the style context that defines the focus ring

§x

X origin of the rectangle

§y

Y origin of the rectangle

§width

rectangle width

§height

rectangle height

source

fn render_frame( &self, context: &impl IsA<StyleContext>, x: f64, y: f64, width: f64, height: f64, )

👎Deprecated: Since 4.10

Creates a render node for the CSS border according to @context, and appends it to the current node of @self, without changing the current node.

§Deprecated since 4.10
§context

the style context that defines the frame

§x

X origin of the rectangle

§y

Y origin of the rectangle

§width

rectangle width

§height

rectangle height

source

fn render_insertion_cursor( &self, context: &impl IsA<StyleContext>, x: f64, y: f64, layout: &Layout, index: i32, direction: Direction, )

👎Deprecated: Since 4.10

Draws a text caret using @self at the specified index of @layout.

§Deprecated since 4.10
§context

a StyleContext

§x

X origin

§y

Y origin

§layout

the pango::Layout of the text

§index

the index in the pango::Layout

§direction

the pango::Direction of the text

source

fn render_layout( &self, context: &impl IsA<StyleContext>, x: f64, y: f64, layout: &Layout, )

👎Deprecated: Since 4.10

Creates a render node for rendering @layout according to the style information in @context, and appends it to the current node of @self, without changing the current node.

§Deprecated since 4.10
§context

the style context that defines the text

§x

X origin of the rectangle

§y

Y origin of the rectangle

§layout

the pango::Layout to render

source

fn restore(&self)

Restores @self to the state saved by a preceding call to save() and removes that state from the stack of saved states.

source

fn rotate(&self, angle: f32)

Rotates @@self’s coordinate system by @angle degrees in 2D space - or in 3D speak, rotates around the Z axis. The rotation happens around the origin point of (0, 0) in the @self’s current coordinate system.

To rotate around axes other than the Z axis, use gsk::Transform::rotate_3d().

§angle

the rotation angle, in degrees (clockwise)

source

fn rotate_3d(&self, angle: f32, axis: &Vec3)

Rotates @self’s coordinate system by @angle degrees around @axis.

For a rotation in 2D space, use gsk::Transform::rotate().

§angle

the rotation angle, in degrees (clockwise)

§axis

The rotation axis

source

fn save(&self)

Makes a copy of the current state of @self and saves it on an internal stack.

When restore() is called, @self will be restored to the saved state.

Multiple calls to save() and restore() can be nested; each call to gtk_snapshot_restore() restores the state from the matching paired gtk_snapshot_save().

It is necessary to clear all saved states with corresponding calls to gtk_snapshot_restore().

source

fn scale(&self, factor_x: f32, factor_y: f32)

Scales @self’s coordinate system in 2-dimensional space by the given factors.

Use scale_3d() to scale in all 3 dimensions.

§factor_x

scaling factor on the X axis

§factor_y

scaling factor on the Y axis

source

fn scale_3d(&self, factor_x: f32, factor_y: f32, factor_z: f32)

Scales @self’s coordinate system by the given factors.

§factor_x

scaling factor on the X axis

§factor_y

scaling factor on the Y axis

§factor_z

scaling factor on the Z axis

source

fn to_node(self) -> Option<RenderNode>

Returns the render node that was constructed by @self.

Note that this function may return None if nothing has been added to the snapshot or if its content does not produce pixels to be rendered.

After calling this function, it is no longer possible to add more nodes to @self. The only function that should be called after this is GObject::Object::unref().

§Returns

the constructed gsk::RenderNode or None if there are no nodes to render.

source

fn to_paintable(self, size: Option<&Size>) -> Option<Paintable>

Returns a paintable encapsulating the render node that was constructed by @self.

After calling this function, it is no longer possible to add more nodes to @self. The only function that should be called after this is GObject::Object::unref().

§size

The size of the resulting paintable or None to use the bounds of the snapshot

§Returns

a new gdk::Paintable

source

fn transform(&self, transform: Option<&Transform>)

Transforms @self’s coordinate system with the given @transform.

§transform

the transform to apply

source

fn transform_matrix(&self, matrix: &Matrix)

Transforms @self’s coordinate system with the given @matrix.

§matrix

the matrix to multiply the transform with

source

fn translate(&self, point: &Point)

Translates @self’s coordinate system by @point in 2-dimensional space.

§point

the point to translate the snapshot by

source

fn translate_3d(&self, point: &Point3D)

Translates @self’s coordinate system by @point.

§point

the point to translate the snapshot by

Object Safety§

This trait is not object safe.

Implementors§