Media
Five GTK widgets all put something on the screen that is not text laid out by a box: the icon, the picture, the inscription, the video and its controls. They are grouped here rather than with the layout widgets because they are content, and because two of them — the picture and the inscription — have a property that changes what they measure rather than what they draw.
The symbolic icon: a name, resolved against the icon theme, drawn in the colour of whatever contains it. A name the theme cannot resolve draws the missing-image glyph, which is what GTK draws for it — so icon-name is the whole API, along with the size that comes from the icon-size enum rather than from a property of its own.
Gtk.Image is not an image viewer. It draws symbolic icons at theme sizes, which is
why an arbitrary bitmap belongs in Picture instead.
Picture
Section titled “Picture”An image fitted to the box it is given, rather than sized by itself. content-fit
picks one of four modes — contain, cover, fill, scale-down — and those four
are the four CSS object-fit values, including the one GTK added and CSS already
had. can-shrink decides whether it may be smaller than its content, and
alternative-text is what a screen reader hears.
keep-aspect-ratio is deprecated but not inert: writing it sets content-fit to
contain (true) or fill (false), and reading it asks the other question —
is the mode anything but fill — so a cover or scale-down picture reads back
true, because those preserve the ratio just as contain does.
Inscription
Section titled “Inscription”Text laid out to a size in characters and lines rather than to a size in pixels. It is the widget for text whose extent should be the same everywhere: a caption under an icon that must not reflow when the string changes, a placeholder reserving four lines so the page does not jump.
That means it never measures its own content. Gtk.Label asks its text how big it
wants to be; Gtk.Inscription multiplies min-chars by the font’s average character
width and stops there — so the four counters are the size request, and the natural
size is the larger of the minimum and the natural count, never the smaller.
The defaults are the opposite of a label’s, and it is worth knowing them: min-chars
3, min-lines 1, nat-chars and nat-lines 0, xalign 0 and yalign 0.5. So out
of the box an inscription is start-aligned — which is what a caption under a centred
icon wants, with no CSS of its own — and reserves three characters and one line.
wrap-mode also defaults differently, and the reason is the widget’s purpose: a box
of a known character count has to break a word that does not fit it, so the default is
word-char where a label defaults to word. text-overflow is clip, so nothing
disappears without being asked for.
A play surface with three overlay nodes over the frames: an icon, and a controls bar
that reveals itself when you move the pointer and withdraws three seconds after you
stop. It owns no playback — a GtkMediaStream sits behind it and answers every question
of what is playing — so autoplay, loop and graphics-offload are all it has.
The icon is a four-way choice and the order carries meaning: no stream at all draws the eject glyph (there is nothing here to play), a stream with an error draws error, a stream that has ended draws repeat, and anything else draws play. Error is tested before ended, so a stream that both failed and finished shows the error.
There is no pause glyph over the frames. The icon is hidden while the video plays and the controls bar carries the pause button, which is why the two are separate widgets.
Media Controls
Section titled “Media Controls”The transport bar: play, position, duration, volume. It holds exactly one property
and it is an object — media-stream — so every control is a view of the stream it was
handed. The template ships the whole box insensitive, so a bar you have just created is
one you cannot press.
Two details in the time display are easy to get wrong, and both are in the C:
- Which label shows what. The position label shows the elapsed time. The label beside it shows what remains, negatively, and is visible only once a duration is known.
- The remaining count is bumped up by one second, so that
current + remainingequals the total for a whole second rather than being one short at every boundary.
An hours field appears only when there is an hour to show: an eleven-minute video reads
11:03, and only past an hour does it become 1:00:00.
Related
Section titled “Related”- Controls: the entry, the drop down, the checkbox and the switch.
- Indicators: the three ways GTK says how far along something is.
- Adwaita Storybook: the same widgets in a live component browser you can poke at.