Package ch.bailu.gtk.gtk
Class Picture
- All Implemented Interfaces:
PointerInterface
The `GtkPicture` widget displays a `GdkPaintable`.
![An example GtkPicture](picture.png)
Many convenience functions are provided to make pictures simple to use.
For example, if you want to load an image from a file, and then display
it, there’s a convenience function to do this:
```c
GtkWidget *widget = gtk_picture_new_for_filename ("myfile.png");
```
If the file isn’t loaded successfully, the picture will contain a
“broken image” icon similar to that used in many web browsers.
If you want to handle errors in loading the file yourself,
for example by displaying an error message, then load the image with
[ctor@Gdk.Texture.new_from_file], then create the `GtkPicture` with
[ctor@Gtk.Picture.new_for_paintable].
Sometimes an application will want to avoid depending on external data
files, such as image files. See the documentation of `GResource` for details.
In this case, [ctor@Gtk.Picture.new_for_resource] and
[method@Gtk.Picture.set_resource] should be used.
`GtkPicture` displays an image at its natural size. See [class@Gtk.Image]
if you want to display a fixed-size image, such as an icon.
## Sizing the paintable
You can influence how the paintable is displayed inside the `GtkPicture`
by changing [property@Gtk.Picture:content-fit]. See [enum@Gtk.ContentFit]
for details. [property@Gtk.Picture:can-shrink] can be unset to make sure
that paintables are never made smaller than their ideal size - but
be careful if you do not know the size of the paintable in use (like
when displaying user-loaded images). This can easily cause the picture to
grow larger than the screen. And [property@GtkWidget:halign] and
[property@GtkWidget:valign] can be used to make sure the paintable doesn't
fill all available space but is instead displayed at its original size.
## CSS nodes
`GtkPicture` has a single CSS node with the name `picture`.
## Accessibility
`GtkPicture` uses the `GTK_ACCESSIBLE_ROLE_IMG` role.
![An example GtkPicture](picture.png)
Many convenience functions are provided to make pictures simple to use.
For example, if you want to load an image from a file, and then display
it, there’s a convenience function to do this:
```c
GtkWidget *widget = gtk_picture_new_for_filename ("myfile.png");
```
If the file isn’t loaded successfully, the picture will contain a
“broken image” icon similar to that used in many web browsers.
If you want to handle errors in loading the file yourself,
for example by displaying an error message, then load the image with
[ctor@Gdk.Texture.new_from_file], then create the `GtkPicture` with
[ctor@Gtk.Picture.new_for_paintable].
Sometimes an application will want to avoid depending on external data
files, such as image files. See the documentation of `GResource` for details.
In this case, [ctor@Gtk.Picture.new_for_resource] and
[method@Gtk.Picture.set_resource] should be used.
`GtkPicture` displays an image at its natural size. See [class@Gtk.Image]
if you want to display a fixed-size image, such as an icon.
## Sizing the paintable
You can influence how the paintable is displayed inside the `GtkPicture`
by changing [property@Gtk.Picture:content-fit]. See [enum@Gtk.ContentFit]
for details. [property@Gtk.Picture:can-shrink] can be unset to make sure
that paintables are never made smaller than their ideal size - but
be careful if you do not know the size of the paintable in use (like
when displaying user-loaded images). This can easily cause the picture to
grow larger than the screen. And [property@GtkWidget:halign] and
[property@GtkWidget:valign] can be used to make sure the paintable doesn't
fill all available space but is instead displayed at its original size.
## CSS nodes
`GtkPicture` has a single CSS node with the name `picture`.
## Accessibility
`GtkPicture` uses the `GTK_ACCESSIBLE_ROLE_IMG` role.
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.bailu.gtk.gtk.Widget
Widget.OnDestroy, Widget.OnDestroyNotify, Widget.OnDirectionChanged, Widget.OnHide, Widget.OnKeynavFailed, Widget.OnMap, Widget.OnMnemonicActivate, Widget.OnMoveFocus, Widget.OnQueryTooltip, Widget.OnRealize, Widget.OnShow, Widget.OnStateFlagsChanged, Widget.OnTickCallback, Widget.OnUnmap, Widget.OnUnrealize
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gtk.Widget
SIGNAL_ON_DESTROY, SIGNAL_ON_DIRECTION_CHANGED, SIGNAL_ON_HIDE, SIGNAL_ON_KEYNAV_FAILED, SIGNAL_ON_MAP, SIGNAL_ON_MNEMONIC_ACTIVATE, SIGNAL_ON_MOVE_FOCUS, SIGNAL_ON_QUERY_TOOLTIP, SIGNAL_ON_REALIZE, SIGNAL_ON_SHOW, SIGNAL_ON_STATE_FLAGS_CHANGED, SIGNAL_ON_UNMAP, SIGNAL_ON_UNREALIZE
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
ConstructorDescriptionPicture()
Creates a new empty `GtkPicture` widget.Picture
(PointerContainer pointer) -
Method Summary
Modifier and TypeMethodDescriptionImplements interfaceAccessible
.Implements interfaceBuildable
.Implements interfaceConstraintTarget
.Gets the alternative textual description of the picture.boolean
Returns whether the `GtkPicture` respects its contents size.static ClassHandler
int
Returns the fit mode for the content of the `GtkPicture`.getFile()
Gets the `GFile` currently displayed if @self is displaying a file.static int
Gets the `GdkPaintable` being displayed by the `GtkPicture`.static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
static Picture
newForFilenamePicture
(Str filename) Creates a new `GtkPicture` displaying the file @filename.static Picture
newForFilenamePicture
(String filename) Creates a new `GtkPicture` displaying the file @filename.static Picture
newForFilePicture
(File file) Creates a new `GtkPicture` displaying the given @file.static Picture
newForPaintablePicture
(Paintable paintable) Creates a new `GtkPicture` displaying @paintable.static Picture
newForPixbufPicture
(Pixbuf pixbuf) Creates a new `GtkPicture` displaying @pixbuf.static Picture
newForResourcePicture
(Str resource_path) Creates a new `GtkPicture` displaying the resource at @resource_path.static Picture
newForResourcePicture
(String resource_path) Creates a new `GtkPicture` displaying the resource at @resource_path.void
setAlternativeText
(Str alternative_text) Sets an alternative textual description for the picture contents.void
setAlternativeText
(String alternative_text) Sets an alternative textual description for the picture contents.void
setCanShrink
(boolean can_shrink) If set to %TRUE, the @self can be made smaller than its contents.void
setContentFit
(int content_fit) Sets how the content should be resized to fit the `GtkPicture`.void
Makes @self load and display @file.void
setFilename
(Str filename) Makes @self load and display the given @filename.void
setFilename
(String filename) Makes @self load and display the given @filename.void
setPaintable
(Paintable paintable) Makes @self display the given @paintable.void
Sets a `GtkPicture` to show a `GdkPixbuf`.void
setResource
(Str resource_path) Makes @self load and display the resource at the given
@resource_path.void
setResource
(String resource_path) Makes @self load and display the resource at the given
@resource_path.Methods inherited from class ch.bailu.gtk.gtk.Widget
actionSetEnabled, actionSetEnabled, activate, activateAction, activateAction, activateActionVariant, activateActionVariant, activateDefault, addController, addCssClass, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, createPangoLayout, disposeTemplate, dragCheckThreshold, errorBell, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getCanFocus, getCanTarget, getChildVisible, getClipboard, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeCssClass, removeMnemonicLabel, removeTickCallback, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setTooltipMarkup, setTooltipMarkup, setTooltipText, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, snapshotChild, triggerTooltipQuery, unmap, unparent, unrealize, unsetStateFlags
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Constructor Details
-
Picture
-
Picture
public Picture()Creates a new empty `GtkPicture` widget.
-
-
Method Details
-
getClassHandler
-
newForFilePicture
Creates a new `GtkPicture` displaying the given @file.
If the file isn’t found or can’t be loaded, the resulting
`GtkPicture` is empty.
If you need to detect failures to load the file, use
[ctor@Gdk.Texture.new_from_file] to load the file yourself,
then create the `GtkPicture` from the texture.- Parameters:
file
- a `GFile`- Returns:
- a new `GtkPicture`
-
newForFilenamePicture
Creates a new `GtkPicture` displaying the file @filename.
This is a utility function that calls [ctor@Gtk.Picture.new_for_file].
See that function for details.- Parameters:
filename
- a filename- Returns:
- a new `GtkPicture`
-
newForFilenamePicture
Creates a new `GtkPicture` displaying the file @filename.
This is a utility function that calls [ctor@Gtk.Picture.new_for_file].
See that function for details.- Parameters:
filename
- a filename- Returns:
- a new `GtkPicture`
-
newForPaintablePicture
Creates a new `GtkPicture` displaying @paintable.
The `GtkPicture` will track changes to the @paintable and update
its size and contents in response to it.- Parameters:
paintable
- a `GdkPaintable`- Returns:
- a new `GtkPicture`
-
newForPixbufPicture
Creates a new `GtkPicture` displaying @pixbuf.
This is a utility function that calls [ctor@Gtk.Picture.new_for_paintable],
See that function for details.
The pixbuf must not be modified after passing it to this function.- Parameters:
pixbuf
- a `GdkPixbuf`- Returns:
- a new `GtkPicture`
-
newForResourcePicture
Creates a new `GtkPicture` displaying the resource at @resource_path.
This is a utility function that calls [ctor@Gtk.Picture.new_for_file].
See that function for details.- Parameters:
resource_path
- resource path to play back- Returns:
- a new `GtkPicture`
-
newForResourcePicture
Creates a new `GtkPicture` displaying the resource at @resource_path.
This is a utility function that calls [ctor@Gtk.Picture.new_for_file].
See that function for details.- Parameters:
resource_path
- resource path to play back- Returns:
- a new `GtkPicture`
-
getAlternativeText
Gets the alternative textual description of the picture.
The returned string will be %NULL if the picture cannot be described textually.- Returns:
- the alternative textual description of @self.
-
getCanShrink
public boolean getCanShrink()Returns whether the `GtkPicture` respects its contents size.- Returns:
- %TRUE if the picture can be made smaller than its contents
-
getContentFit
public int getContentFit()Returns the fit mode for the content of the `GtkPicture`.
See [enum@Gtk.ContentFit] for details.- Returns:
- the content fit mode
-
getFile
Gets the `GFile` currently displayed if @self is displaying a file.
If @self is not displaying a file, for example when
[method@Gtk.Picture.set_paintable] was used, then %NULL is returned.- Returns:
- The `GFile` displayed by @self.
-
getPaintable
Gets the `GdkPaintable` being displayed by the `GtkPicture`.- Returns:
- the displayed paintable
-
setAlternativeText
Sets an alternative textual description for the picture contents.
It is equivalent to the "alt" attribute for images on websites.
This text will be made available to accessibility tools.
If the picture cannot be described textually, set this property to %NULL.- Parameters:
alternative_text
- a textual description of the contents
-
setAlternativeText
Sets an alternative textual description for the picture contents.
It is equivalent to the "alt" attribute for images on websites.
This text will be made available to accessibility tools.
If the picture cannot be described textually, set this property to %NULL.- Parameters:
alternative_text
- a textual description of the contents
-
setCanShrink
public void setCanShrink(boolean can_shrink) If set to %TRUE, the @self can be made smaller than its contents.
The contents will then be scaled down when rendering.
If you want to still force a minimum size manually, consider using
[method@Gtk.Widget.set_size_request].
Also of note is that a similar function for growing does not exist
because the grow behavior can be controlled via
[method@Gtk.Widget.set_halign] and [method@Gtk.Widget.set_valign].- Parameters:
can_shrink
- if @self can be made smaller than its contents
-
setContentFit
public void setContentFit(int content_fit) Sets how the content should be resized to fit the `GtkPicture`.
See [enum@Gtk.ContentFit] for details.- Parameters:
content_fit
- the content fit mode
-
setFile
Makes @self load and display @file.
See [ctor@Gtk.Picture.new_for_file] for details.- Parameters:
file
- a `GFile`
-
setFilename
Makes @self load and display the given @filename.
This is a utility function that calls [method@Gtk.Picture.set_file].- Parameters:
filename
- the filename to play
-
setFilename
Makes @self load and display the given @filename.
This is a utility function that calls [method@Gtk.Picture.set_file].- Parameters:
filename
- the filename to play
-
setPaintable
Makes @self display the given @paintable.
If @paintable is %NULL, nothing will be displayed.
See [ctor@Gtk.Picture.new_for_paintable] for details.- Parameters:
paintable
- a `GdkPaintable`
-
setPixbuf
Sets a `GtkPicture` to show a `GdkPixbuf`.
See [ctor@Gtk.Picture.new_for_pixbuf] for details.
This is a utility function that calls [method@Gtk.Picture.set_paintable].- Parameters:
pixbuf
- a `GdkPixbuf`
-
setResource
Makes @self load and display the resource at the given
@resource_path.
This is a utility function that calls [method@Gtk.Picture.set_file].- Parameters:
resource_path
- the resource to set
-
setResource
Makes @self load and display the resource at the given
@resource_path.
This is a utility function that calls [method@Gtk.Picture.set_file].- Parameters:
resource_path
- the resource to set
-
asAccessible
Implements interfaceAccessible
. Call this to get access to interface functions.- Overrides:
asAccessible
in classWidget
- Returns:
Accessible
-
asBuildable
Implements interfaceBuildable
. Call this to get access to interface functions.- Overrides:
asBuildable
in classWidget
- Returns:
Buildable
-
asConstraintTarget
Implements interfaceConstraintTarget
. Call this to get access to interface functions.- Overrides:
asConstraintTarget
in classWidget
- Returns:
ConstraintTarget
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-