Skip to content

Commit 289fc52

Browse files
authored
library: add Picture Entry (#362)
1 parent 6f4c508 commit 289fc52

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed

src/Library/demos/Picture/keys.png

1.17 MB
Loading

src/Library/demos/Picture/main.blp

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
using Gtk 4.0;
2+
using Adw 1;
3+
4+
Adw.StatusPage {
5+
title: _("Picture");
6+
description: _("Display images at their natural sizes");
7+
8+
child: Box {
9+
orientation: vertical;
10+
spacing: 12;
11+
margin-end: 24;
12+
margin-start: 24;
13+
14+
StackSwitcher {
15+
stack: stack;
16+
halign: center;
17+
}
18+
19+
Stack stack {
20+
21+
StackPage {
22+
title: _("Fill");
23+
24+
child: Box {
25+
spacing: 12;
26+
orientation: vertical;
27+
28+
Picture picture_fill {
29+
halign: center;
30+
valign: center;
31+
can-shrink: true;
32+
content-fit: fill;
33+
}
34+
35+
Label {
36+
label: _("Make the content fill the entire allocation, without taking its aspect ratio in consideration. The resulting content will appear as stretched if its aspect ratio is different from the allocation aspect ratio.");
37+
wrap: true;
38+
margin-bottom: 24;
39+
}
40+
};
41+
}
42+
43+
StackPage {
44+
title: _("Contain");
45+
46+
child: Box {
47+
spacing: 12;
48+
orientation: vertical;
49+
Picture picture_contain {
50+
halign: center;
51+
valign: center;
52+
can-shrink: true;
53+
content-fit: contain;
54+
}
55+
56+
Label {
57+
label: _("Scale the content to fit the allocation, while taking its aspect ratio in consideration. The resulting content will appear as letterboxed if its aspect ratio is different from the allocation aspect ratio.");
58+
wrap: true;
59+
margin-bottom: 24;
60+
}
61+
};
62+
}
63+
64+
StackPage {
65+
title: _("Cover");
66+
67+
child: Box {
68+
spacing: 12;
69+
orientation: vertical;
70+
Picture picture_cover {
71+
halign: center;
72+
valign: center;
73+
can-shrink: true;
74+
content-fit: cover;
75+
}
76+
77+
Label {
78+
label: _("Cover the entire allocation, while taking the content aspect ratio in consideration. The resulting content will appear as clipped if its aspect ratio is different from the allocation aspect ratio.");
79+
wrap: true;
80+
margin-bottom: 24;
81+
}
82+
};
83+
}
84+
85+
StackPage {
86+
title: _("Scale Down");
87+
88+
child: Box {
89+
spacing: 12;
90+
orientation: vertical;
91+
Picture picture_scale_down {
92+
halign: center;
93+
valign: center;
94+
can-shrink: true;
95+
content-fit: scale_down;
96+
}
97+
98+
Label {
99+
label: _("The content is scaled down to fit the allocation, if needed, otherwise its original size is used.");
100+
wrap: true;
101+
margin-bottom: 24;
102+
}
103+
};
104+
}
105+
}
106+
107+
LinkButton {
108+
label: _("API Reference");
109+
uri: "https://docs.gtk.org/gtk4/class.Picture.html";
110+
margin-bottom: 12;
111+
}
112+
};
113+
}

src/Library/demos/Picture/main.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Gio from "gi://Gio";
2+
3+
const picture_fill = workbench.builder.get_object("picture_fill");
4+
const picture_contain = workbench.builder.get_object("picture_contain");
5+
const picture_cover = workbench.builder.get_object("picture_cover");
6+
const picture_scale_down = workbench.builder.get_object("picture_scale_down");
7+
8+
const file = Gio.File.new_for_uri(workbench.resolve("./keys.png"));
9+
10+
picture_fill.file = file;
11+
picture_contain.file = file;
12+
picture_cover.file = file;
13+
picture_scale_down.file = file;
14+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "user_interface",
3+
"description": "Display images at their natural sizes",
4+
"panels": ["ui", "preview"],
5+
"autorun": true
6+
}

0 commit comments

Comments
 (0)