PaintableProtocol
public protocol PaintableProtocol
The PaintableProtocol protocol exposes the methods and properties of an underlying GdkPaintable instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see Paintable.
Alternatively, use PaintableRef as a lighweight, unowned reference if you already have an instance you just want to use.
GdkPaintable is a simple interface used by GTK to represent content that
can be painted.
The content of a GdkPaintable can be painted anywhere at any size
without requiring any sort of layout. The interface is inspired by
similar concepts elsewhere, such as
ClutterContent,
HTML/CSS Paint Sources,
or SVG Paint Servers.
A GdkPaintable can be snapshot at any time and size using
[methodGdk.Paintable.snapshot]. How the paintable interprets that size and
if it scales or centers itself into the given rectangle is implementation
defined, though if you are implementing a GdkPaintable and don’t know what
to do, it is suggested that you scale your paintable ignoring any potential
aspect ratio.
The contents that a GdkPaintable produces may depend on the [classGdkSnapshot]
passed to it. For example, paintables may decide to use more detailed images
on higher resolution screens or when OpenGL is available. A GdkPaintable
will however always produce the same output for the same snapshot.
A GdkPaintable may change its contents, meaning that it will now produce
a different output with the same snapshot. Once that happens, it will call
[methodGdk.Paintable.invalidate_contents] which will emit the
[signalGdkPaintable::invalidate-contents] signal. If a paintable is known
to never change its contents, it will set the GDK_PAINTABLE_STATIC_CONTENTS
flag. If a consumer cannot deal with changing contents, it may call
[methodGdk.Paintable.get_current_image] which will return a static
paintable and use that.
A paintable can report an intrinsic (or preferred) size or aspect ratio it
wishes to be rendered at, though it doesn’t have to. Consumers of the interface
can use this information to layout thepaintable appropriately. Just like the
contents, the size of a paintable can change. A paintable will indicate this
by calling [methodGdk.Paintable.invalidate_size] which will emit the
[signalGdkPaintable::invalidate-size] signal. And just like for contents,
if a paintable is known to never change its size, it will set the
GDK_PAINTABLE_STATIC_SIZE flag.
Besides API for applications, there are some functions that are only
useful for implementing subclasses and should not be used by applications:
[methodGdk.Paintable.invalidate_contents],
[methodGdk.Paintable.invalidate_size],
[funcGdk.Paintable.new_empty].
-
Untyped pointer to the underlying
GdkPaintableinstance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get } -
paintable_ptrDefault implementationTyped pointer to the underlying
GdkPaintableinstance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GdkPaintableinstance.Declaration
Swift
var paintable_ptr: UnsafeMutablePointer<GdkPaintable>! { get } -
Required Initialiser for types conforming to
PaintableProtocolDeclaration
Swift
init(raw: UnsafeMutableRawPointer)
-
connect(signal:Extension methodflags: handler: ) Connect a Swift signal handler to the given, typed
PaintableSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: PaintableSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> IntParameters
signalThe signal to connect
flagsThe connection flags to use
dataA pointer to user data to provide to the callback
destroyDataA
GClosureNotifyC function to destroy the data pointed to byuserDatahandlerThe Swift signal handler (function or callback) to invoke on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
connect(signal:Extension methodflags: data: destroyData: signalHandler: ) Connect a C signal handler to the given, typed
PaintableSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: PaintableSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> IntParameters
signalThe signal to connect
flagsThe connection flags to use
dataA pointer to user data to provide to the callback
destroyDataA
GClosureNotifyC function to destroy the data pointed to byuserDatasignalHandlerThe C function to be called on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
onInvalidateContents(flags:Extension methodhandler: ) Emitted when the contents of the
paintablechange.Examples for such an event would be videos changing to the next frame or the icon theme for an icon changing.
Note
This represents the underlyinginvalidate-contentssignalDeclaration
Swift
@discardableResult @inlinable func onInvalidateContents(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: PaintableRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
invalidateContentssignal is emitted -
invalidateContentsSignalExtension methodTyped
invalidate-contentssignal for using theconnect(signal:)methodsDeclaration
Swift
static var invalidateContentsSignal: PaintableSignalName { get } -
onInvalidateSize(flags:Extension methodhandler: ) Emitted when the intrinsic size of the
paintablechanges.This means the values reported by at least one of [method
Gdk.Paintable.get_intrinsic_width], [methodGdk.Paintable.get_intrinsic_height] or [methodGdk.Paintable.get_intrinsic_aspect_ratio] has changed.Examples for such an event would be a paintable displaying the contents of a toplevel surface being resized.
Note
This represents the underlyinginvalidate-sizesignalDeclaration
Swift
@discardableResult @inlinable func onInvalidateSize(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: PaintableRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
invalidateSizesignal is emitted -
invalidateSizeSignalExtension methodTyped
invalidate-sizesignal for using theconnect(signal:)methodsDeclaration
Swift
static var invalidateSizeSignal: PaintableSignalName { get }
-
computeConcreteSize(specifiedWidth:Extension methodspecifiedHeight: defaultWidth: defaultHeight: concreteWidth: concreteHeight: ) Compute a concrete size for the
GdkPaintable.Applies the sizing algorithm outlined in the CSS Image spec to the given
paintable. See that link for more details.It is not necessary to call this function when both
specified_widthandspecified_heightare known, but it is useful to call this function in GtkWidget:measure implementations to compute the other dimension when only one dimension is given.Declaration
Swift
@inlinable func computeConcreteSize(specifiedWidth: CDouble, specifiedHeight: CDouble, defaultWidth: CDouble, defaultHeight: CDouble, concreteWidth: UnsafeMutablePointer<CDouble>!, concreteHeight: UnsafeMutablePointer<CDouble>!) -
getCurrentImage()Extension methodGets an immutable paintable for the current contents displayed by
paintable.This is useful when you want to retain the current state of an animation, for example to take a screenshot of a running animation.
If the
paintableis already immutable, it will return itself.Declaration
Swift
@inlinable func getCurrentImage() -> PaintableRef! -
getFlags()Extension methodGet flags for the paintable.
This is oftentimes useful for optimizations.
See [flags
Gdk.PaintableFlags] for the flags and what they mean.Declaration
Swift
@inlinable func getFlags() -> PaintableFlags -
getIntrinsicAspectRatio()Extension methodGets the preferred aspect ratio the
paintablewould like to be displayed at.The aspect ratio is the width divided by the height, so a value of 0.5 means that the
paintableprefers to be displayed twice as high as it is wide. Consumers of this interface can use this to preserve aspect ratio when displaying the paintable.This is a purely informational value and does not in any way limit the values that may be passed to [method
Gdk.Paintable.snapshot].Usually when a
paintablereturns nonzero values from [methodGdk.Paintable.get_intrinsic_width] and [methodGdk.Paintable.get_intrinsic_height] the aspect ratio should conform to those values, though that is not required.If the
paintabledoes not have a preferred aspect ratio, it returns 0. Negative values are never returned.Declaration
Swift
@inlinable func getIntrinsicAspectRatio() -> CDouble -
getIntrinsicHeight()Extension methodGets the preferred height the
paintablewould like to be displayed at.Consumers of this interface can use this to reserve enough space to draw the paintable.
This is a purely informational value and does not in any way limit the values that may be passed to [method
Gdk.Paintable.snapshot].If the
paintabledoes not have a preferred height, it returns 0. Negative values are never returned.Declaration
Swift
@inlinable func getIntrinsicHeight() -> Int -
getIntrinsicWidth()Extension methodGets the preferred width the
paintablewould like to be displayed at.Consumers of this interface can use this to reserve enough space to draw the paintable.
This is a purely informational value and does not in any way limit the values that may be passed to [method
Gdk.Paintable.snapshot].If the
paintabledoes not have a preferred width, it returns 0. Negative values are never returned.Declaration
Swift
@inlinable func getIntrinsicWidth() -> Int -
invalidateContents()Extension methodCalled by implementations of
GdkPaintableto invalidate their contents.Unless the contents are invalidated, implementations must guarantee that multiple calls of [method
Gdk.Paintable.snapshot] produce the same output.This function will emit the [signal
Gdk.Paintable::invalidate-contents] signal.If a
paintablereports theGDK_PAINTABLE_STATIC_CONTENTSflag, it must not call this function.Declaration
Swift
@inlinable func invalidateContents() -
invalidateSize()Extension methodCalled by implementations of
GdkPaintableto invalidate their size.As long as the size is not invalidated,
paintablemust return the same values for its intrinsic width, height and aspect ratio.This function will emit the [signal
Gdk.Paintable::invalidate-size] signal.If a
paintablereports theGDK_PAINTABLE_STATIC_SIZEflag, it must not call this function.Declaration
Swift
@inlinable func invalidateSize() -
snapshot(snapshot:Extension methodwidth: height: ) Snapshots the given paintable with the given
widthandheight.The paintable is drawn at the current (0,0) offset of the
snapshot. Ifwidthandheightare not larger than zero, this function will do nothing.Declaration
Swift
@inlinable func snapshot<SnapshotT>(snapshot: SnapshotT, width: CDouble, height: CDouble) where SnapshotT : SnapshotProtocol -
currentImageExtension methodGets an immutable paintable for the current contents displayed by
paintable.This is useful when you want to retain the current state of an animation, for example to take a screenshot of a running animation.
If the
paintableis already immutable, it will return itself.Declaration
Swift
@inlinable var currentImage: PaintableRef! { get } -
flagsExtension methodGet flags for the paintable.
This is oftentimes useful for optimizations.
See [flags
Gdk.PaintableFlags] for the flags and what they mean.Declaration
Swift
@inlinable var flags: PaintableFlags { get } -
intrinsicAspectRatioExtension methodGets the preferred aspect ratio the
paintablewould like to be displayed at.The aspect ratio is the width divided by the height, so a value of 0.5 means that the
paintableprefers to be displayed twice as high as it is wide. Consumers of this interface can use this to preserve aspect ratio when displaying the paintable.This is a purely informational value and does not in any way limit the values that may be passed to [method
Gdk.Paintable.snapshot].Usually when a
paintablereturns nonzero values from [methodGdk.Paintable.get_intrinsic_width] and [methodGdk.Paintable.get_intrinsic_height] the aspect ratio should conform to those values, though that is not required.If the
paintabledoes not have a preferred aspect ratio, it returns 0. Negative values are never returned.Declaration
Swift
@inlinable var intrinsicAspectRatio: CDouble { get } -
intrinsicHeightExtension methodGets the preferred height the
paintablewould like to be displayed at.Consumers of this interface can use this to reserve enough space to draw the paintable.
This is a purely informational value and does not in any way limit the values that may be passed to [method
Gdk.Paintable.snapshot].If the
paintabledoes not have a preferred height, it returns 0. Negative values are never returned.Declaration
Swift
@inlinable var intrinsicHeight: Int { get } -
intrinsicWidthExtension methodGets the preferred width the
paintablewould like to be displayed at.Consumers of this interface can use this to reserve enough space to draw the paintable.
This is a purely informational value and does not in any way limit the values that may be passed to [method
Gdk.Paintable.snapshot].If the
paintabledoes not have a preferred width, it returns 0. Negative values are never returned.Declaration
Swift
@inlinable var intrinsicWidth: Int { get }
View on GitHub
Install in Dash
PaintableProtocol Protocol Reference