fix: frame document previews like messages

This commit is contained in:
Tomás Romero committed 2026-10-24 22:19:04 +02:00
1 parent bf1cfde9fb
commit 57586828d9
14 files changed
+148 -71

No files matched your search

+4 -4
View File
@@ -2520,15 +2520,15 @@ msgstr ""
msgid "Select"
msgstr ""
#: ui/components/document-preview.slint:43
#: ui/components/document-preview.slint:17
msgid "Previous page"
msgstr ""
#: ui/components/document-preview.slint:44
#: ui/components/document-preview.slint:18
msgid "Page {} of {}"
msgstr ""
#: ui/components/document-preview.slint:45
#: ui/components/document-preview.slint:19
msgid "Next page"
msgstr ""
@@ -3201,7 +3201,7 @@ msgstr ""
msgid "Download"
msgstr ""
#: ui/dialogs/attachment-preview-dialog.slint:53 ui/views/files-view.slint:477
#: ui/dialogs/attachment-preview-dialog.slint:50 ui/views/files-view.slint:477
msgid "Loading preview…"
msgstr ""
+4 -4
View File
@@ -2525,15 +2525,15 @@ msgstr ""
msgid "Select"
msgstr ""
#: ui/components/document-preview.slint:43
#: ui/components/document-preview.slint:17
msgid "Previous page"
msgstr ""
#: ui/components/document-preview.slint:44
#: ui/components/document-preview.slint:18
msgid "Page {} of {}"
msgstr ""
#: ui/components/document-preview.slint:45
#: ui/components/document-preview.slint:19
msgid "Next page"
msgstr ""
@@ -3208,7 +3208,7 @@ msgstr ""
msgid "Download"
msgstr ""
#: ui/dialogs/attachment-preview-dialog.slint:53 ui/views/files-view.slint:477
#: ui/dialogs/attachment-preview-dialog.slint:50 ui/views/files-view.slint:477
msgid "Loading preview…"
msgstr ""
+4 -4
View File
@@ -2622,15 +2622,15 @@ msgstr "Limpiar selección"
msgid "Select"
msgstr "Seleccionar"
#: ui/components/document-preview.slint:43
#: ui/components/document-preview.slint:17
msgid "Previous page"
msgstr "Página anterior"
#: ui/components/document-preview.slint:44
#: ui/components/document-preview.slint:18
msgid "Page {} of {}"
msgstr "Página {} de {}"
#: ui/components/document-preview.slint:45
#: ui/components/document-preview.slint:19
msgid "Next page"
msgstr "Página siguiente"
@@ -3319,7 +3319,7 @@ msgstr "Ajustar al ancho"
msgid "Download"
msgstr "Descargar"
#: ui/dialogs/attachment-preview-dialog.slint:53 ui/views/files-view.slint:477
#: ui/dialogs/attachment-preview-dialog.slint:50 ui/views/files-view.slint:477
msgid "Loading preview…"
msgstr "Cargando vista previa…"
+5 -4
View File
@@ -2568,15 +2568,16 @@ msgstr ""
msgid "Select"
msgstr ""
#: ui/components/document-preview.slint:43
#: ui/components/document-preview.slint:17
msgid "Previous page"
msgstr ""
#: ui/components/document-preview.slint:44
#: ui/components/document-preview.slint:18
#: ui/components/document-preview.slint:18
msgid "Page {} of {}"
msgstr ""
#: ui/components/document-preview.slint:45
#: ui/components/document-preview.slint:19
msgid "Next page"
msgstr ""
@@ -3305,7 +3306,7 @@ msgstr ""
msgid "Download"
msgstr ""
#: ui/dialogs/attachment-preview-dialog.slint:53 ui/views/files-view.slint:477
#: ui/dialogs/attachment-preview-dialog.slint:50 ui/views/files-view.slint:477
msgid "Loading preview…"
msgstr ""
+4 -4
View File
@@ -3050,17 +3050,17 @@ msgstr "Effacer la sélection"
msgid "Select"
msgstr "Sélectionner"
#: ui/components/document-preview.slint:43
#: ui/components/document-preview.slint:17
#, fuzzy
msgid "Previous page"
msgstr "Page précédente"
#: ui/components/document-preview.slint:44
#: ui/components/document-preview.slint:18
#, fuzzy
msgid "Page {} of {}"
msgstr "Page {} sur {}"
#: ui/components/document-preview.slint:45
#: ui/components/document-preview.slint:19
#, fuzzy
msgid "Next page"
msgstr "Page suivante"
@@ -3879,7 +3879,7 @@ msgstr "Ajuster à la largeur"
msgid "Download"
msgstr "Télécharger"
#: ui/dialogs/attachment-preview-dialog.slint:53 ui/views/files-view.slint:477
#: ui/dialogs/attachment-preview-dialog.slint:50 ui/views/files-view.slint:477
#, fuzzy
msgid "Loading preview…"
msgstr "Chargement de l’aperçu…"
+4 -4
View File
@@ -2520,15 +2520,15 @@ msgstr ""
msgid "Select"
msgstr ""
#: ui/components/document-preview.slint:43
#: ui/components/document-preview.slint:17
msgid "Previous page"
msgstr ""
#: ui/components/document-preview.slint:44
#: ui/components/document-preview.slint:18
msgid "Page {} of {}"
msgstr ""
#: ui/components/document-preview.slint:45
#: ui/components/document-preview.slint:19
msgid "Next page"
msgstr ""
@@ -3201,7 +3201,7 @@ msgstr ""
msgid "Download"
msgstr ""
#: ui/dialogs/attachment-preview-dialog.slint:53 ui/views/files-view.slint:477
#: ui/dialogs/attachment-preview-dialog.slint:50 ui/views/files-view.slint:477
msgid "Loading preview…"
msgstr ""
+4 -4
View File
@@ -2520,15 +2520,15 @@ msgstr ""
msgid "Select"
msgstr ""
#: ui/components/document-preview.slint:43
#: ui/components/document-preview.slint:17
msgid "Previous page"
msgstr ""
#: ui/components/document-preview.slint:44
#: ui/components/document-preview.slint:18
msgid "Page {} of {}"
msgstr ""
#: ui/components/document-preview.slint:45
#: ui/components/document-preview.slint:19
msgid "Next page"
msgstr ""
@@ -3201,7 +3201,7 @@ msgstr ""
msgid "Download"
msgstr ""
#: ui/dialogs/attachment-preview-dialog.slint:53 ui/views/files-view.slint:477
#: ui/dialogs/attachment-preview-dialog.slint:50 ui/views/files-view.slint:477
msgid "Loading preview…"
msgstr ""
+4 -4
View File
@@ -2520,15 +2520,15 @@ msgstr ""
msgid "Select"
msgstr ""
#: ui/components/document-preview.slint:43
#: ui/components/document-preview.slint:17
msgid "Previous page"
msgstr ""
#: ui/components/document-preview.slint:44
#: ui/components/document-preview.slint:18
msgid "Page {} of {}"
msgstr ""
#: ui/components/document-preview.slint:45
#: ui/components/document-preview.slint:19
msgid "Next page"
msgstr ""
@@ -3201,7 +3201,7 @@ msgstr ""
msgid "Download"
msgstr ""
#: ui/dialogs/attachment-preview-dialog.slint:53 ui/views/files-view.slint:477
#: ui/dialogs/attachment-preview-dialog.slint:50 ui/views/files-view.slint:477
msgid "Loading preview…"
msgstr ""
+4 -4
View File
@@ -2598,15 +2598,15 @@ msgstr "Очистить выделение"
msgid "Select"
msgstr "Выбрать"
#: ui/components/document-preview.slint:43
#: ui/components/document-preview.slint:17
msgid "Previous page"
msgstr "Предыдущая страница"
#: ui/components/document-preview.slint:44
#: ui/components/document-preview.slint:18
msgid "Page {} of {}"
msgstr "Страница {} из {}"
#: ui/components/document-preview.slint:45
#: ui/components/document-preview.slint:19
msgid "Next page"
msgstr "Следующая страница"
@@ -3294,7 +3294,7 @@ msgstr "По ширине"
msgid "Download"
msgstr "Скачать"
#: ui/dialogs/attachment-preview-dialog.slint:53 ui/views/files-view.slint:477
#: ui/dialogs/attachment-preview-dialog.slint:50 ui/views/files-view.slint:477
msgid "Loading preview…"
msgstr "Загрузка предпросмотра…"
+4 -4
View File
@@ -2563,15 +2563,15 @@ msgstr "Seçimi temizle"
msgid "Select"
msgstr "Seç"
#: ui/components/document-preview.slint:43
#: ui/components/document-preview.slint:17
msgid "Previous page"
msgstr "Önceki sayfa"
#: ui/components/document-preview.slint:44
#: ui/components/document-preview.slint:18
msgid "Page {} of {}"
msgstr "Sayfa {} / {}"
#: ui/components/document-preview.slint:45
#: ui/components/document-preview.slint:19
msgid "Next page"
msgstr "Sonraki sayfa"
@@ -3255,7 +3255,7 @@ msgstr "Genişliğe sığdır"
msgid "Download"
msgstr "İndir"
#: ui/dialogs/attachment-preview-dialog.slint:53 ui/views/files-view.slint:477
#: ui/dialogs/attachment-preview-dialog.slint:50 ui/views/files-view.slint:477
msgid "Loading preview…"
msgstr "Önizleme yükleniyor…"
+4 -4
View File
@@ -2542,15 +2542,15 @@ msgstr "取消选择"
msgid "Select"
msgstr "选择"
#: ui/components/document-preview.slint:43
#: ui/components/document-preview.slint:17
msgid "Previous page"
msgstr "上一页"
#: ui/components/document-preview.slint:44
#: ui/components/document-preview.slint:18
msgid "Page {} of {}"
msgstr "第 {} 页,共 {} 页"
#: ui/components/document-preview.slint:45
#: ui/components/document-preview.slint:19
msgid "Next page"
msgstr "下一页"
@@ -3228,7 +3228,7 @@ msgstr "适应宽度"
msgid "Download"
msgstr "下载"
#: ui/dialogs/attachment-preview-dialog.slint:53 ui/views/files-view.slint:477
#: ui/dialogs/attachment-preview-dialog.slint:50 ui/views/files-view.slint:477
msgid "Loading preview…"
msgstr "正在加载预览…"
+98 -19
View File
@@ -1,9 +1,24 @@
import { HorizontalBox, VerticalBox, ScrollView } from "std-widgets.slint";
import { ZoomControls, ZoomApi } from "zoom-controls.slint";
import { ToolbarIconButton } from "controls.slint";
import { AppTheme } from "../design-system.slint";
import { AppTheme, LayoutMetrics } from "../design-system.slint";
import { TypeScale } from "../typography.slint";
component PageNavigation inherits HorizontalBox {
in property <bool> compact: false;
in property <bool> busy: false;
in property <int> page: 0;
in property <int> pages: 0;
// A row of its own spreads the arrows to the edges.
in property <bool> fill: false;
callback render-page(int, int);
padding: 0px; spacing: 4px; cross-axis-alignment: center;
horizontal-stretch: root.fill ? 1 : 0;
ToolbarIconButton { compact: root.compact; icon-color: AppTheme.secondary; icon: @image-url("../icons/lucide/outline/chevron-left.svg"); tooltip-text: @tr("Previous page"); interactive: !root.busy && root.page > 0; clicked => { root.render-page(root.page - 1, 200); } }
Text { text: @tr("Page {} of {}", root.page + 1, root.pages); color: AppTheme.secondary; font-size: TypeScale.caption; vertical-alignment: center; horizontal-alignment: center; horizontal-stretch: root.fill ? 1 : 0; }
ToolbarIconButton { compact: root.compact; icon-color: AppTheme.secondary; icon: @image-url("../icons/lucide/outline/chevron-right.svg"); tooltip-text: @tr("Next page"); interactive: !root.busy && root.page + 1 < root.pages; clicked => { root.render-page(root.page + 1, 200); } }
}
export component DocumentPreview inherits Rectangle {
in property <bool> compact: false;
in property <bool> busy: false;
@@ -19,7 +34,9 @@ export component DocumentPreview inherits Rectangle {
private property <int> revision: 0;
private property <float> natural-width: root.source.width / max(0.01, root.raster-zoom);
private property <float> natural-height: root.source.height / max(0.01, root.raster-zoom);
private property <float> zoom: root.fitting ? clamp(canvas.visible-width / 1px / max(1, root.natural-width), 0.1, 3) : root.manual-zoom;
// The page sits as a sheet on the canvas, inset like the email body.
private property <length> sheet-gap: root.compact ? 8px : 16px;
private property <float> zoom: root.fitting ? clamp((canvas.visible-width - 2 * root.sheet-gap) / 1px / max(1, root.natural-width), 0.1, 3) : root.manual-zoom;
changed document-revision => { root.fitting = true; root.manual-zoom = 1; canvas.content-x = 0px; canvas.content-y = 0px; }
changed page => { canvas.content-x = 0px; canvas.content-y = 0px; }
min-width: 0px; min-height: 0px; max-width: 100000px;
@@ -34,27 +51,89 @@ export component DocumentPreview inherits Rectangle {
canvas.content-x = 0px; canvas.content-y = 0px;
}
private property <float> private-zoom: 1;
private property <length> toolbar-inset: 10px;
private property <length> page-button-size: root.compact ? LayoutMetrics.touch-target : LayoutMetrics.desktop-icon-button-size;
// Page navigation shares the zoom row when both fit (four 4px gaps plus
// some room between the groups), and takes its own row on narrow
// screens or with longer translations.
private property <bool> pages-below: root.pages > 0
&& zoom-controls.preferred-width + 2 * root.page-button-size + page-label-probe.preferred-width + 24px
> root.width - 2 * (LayoutMetrics.divider-width + root.toolbar-inset);
page-label-probe := Text {
visible: false; accessible-role: none;
text: @tr("Page {} of {}", root.page + 1, root.pages); font-size: TypeScale.caption;
}
// Framed like the email reader's message card: controls on top, then
// the document on the page background.
background: AppTheme.surface;
border-radius: 8px;
border-width: LayoutMetrics.divider-width;
border-color: AppTheme.border-subtle;
clip: true;
VerticalBox {
width: parent.width; height: parent.height;
padding: 0px; spacing: 8px; cross-axis-alignment: stretch;
ZoomControls { compact: root.compact; zoom: root.zoom; minimum: 0.1; fitting: root.fitting; revision: root.revision; available: root.source.width > 0; command(action) => { root.command(action); } }
if root.pages > 0 : HorizontalBox {
height: root.compact ? 44px : 40px; padding: 0px;
ToolbarIconButton { compact: root.compact; icon-color: AppTheme.secondary; icon: @image-url("../icons/lucide/outline/chevron-left.svg"); tooltip-text: @tr("Previous page"); interactive: !root.busy && root.page > 0; clicked => { root.render-page(root.page - 1, 200); } }
Text { text: @tr("Page {} of {}", root.page + 1, root.pages); color: AppTheme.secondary; font-size: TypeScale.caption; vertical-alignment: center; horizontal-alignment: center; horizontal-stretch: 1; }
ToolbarIconButton { compact: root.compact; icon-color: AppTheme.secondary; icon: @image-url("../icons/lucide/outline/chevron-right.svg"); tooltip-text: @tr("Next page"); interactive: !root.busy && root.page + 1 < root.pages; clicked => { root.render-page(root.page + 1, 200); } }
x: LayoutMetrics.divider-width; y: LayoutMetrics.divider-width;
width: parent.width - 2 * LayoutMetrics.divider-width; height: parent.height - 2 * LayoutMetrics.divider-width;
padding: 0px; spacing: 0px; cross-axis-alignment: stretch;
HorizontalBox {
padding-top: 4px; padding-bottom: root.pages-below ? 0px : 4px; padding-left: root.toolbar-inset; padding-right: root.toolbar-inset;
spacing: 4px; cross-axis-alignment: center;
zoom-controls := ZoomControls { compact: root.compact; zoom: root.zoom; minimum: 0.1; fitting: root.fitting; revision: root.revision; available: root.source.width > 0; command(action) => { root.command(action); } }
Rectangle { horizontal-stretch: 1; }
if root.pages > 0 && !root.pages-below : PageNavigation {
compact: root.compact; busy: root.busy; page: root.page; pages: root.pages;
render-page(page, zoom) => { root.render-page(page, zoom); }
}
}
canvas := ScrollView {
if root.pages-below : PageNavigation {
fill: true;
padding-left: root.toolbar-inset; padding-right: root.toolbar-inset; padding-bottom: 4px;
compact: root.compact; busy: root.busy; page: root.page; pages: root.pages;
render-page(page, zoom) => { root.render-page(page, zoom); }
}
Rectangle { height: LayoutMetrics.divider-width; background: AppTheme.border-subtle; }
Rectangle {
vertical-stretch: 1;
mouse-drag-pan-enabled: true;
content-width: max(self.visible-width, root.natural-width * root.zoom * 1px);
content-height: max(self.visible-height, root.natural-height * root.zoom * 1px);
Image {
source: root.source; image-fit: contain;
x: max(0px, (canvas.visible-width - self.width) / 2);
width: root.natural-width * root.zoom * 1px;
height: root.natural-height * root.zoom * 1px;
background: AppTheme.page-bg;
canvas := ScrollView {
width: parent.width; height: parent.height;
mouse-drag-pan-enabled: true;
content-width: max(self.visible-width, root.natural-width * root.zoom * 1px + 2 * root.sheet-gap);
content-height: max(self.visible-height, root.natural-height * root.zoom * 1px + 2 * root.sheet-gap);
Rectangle {
x: max(root.sheet-gap, (canvas.visible-width - self.width) / 2);
y: root.sheet-gap;
width: root.natural-width * root.zoom * 1px;
height: root.natural-height * root.zoom * 1px;
Image { width: parent.width; height: parent.height; source: root.source; image-fit: contain; }
// The outline lifts the sheet off the canvas.
Rectangle { border-width: LayoutMetrics.divider-width; border-color: AppTheme.border; }
}
}
}
}
}
// Plain-text previews share the document card.
export component TextPreview inherits Rectangle {
in property <string> text;
in property <bool> compact: false;
private property <length> inset: root.compact ? 12px : 16px;
min-width: 0px; min-height: 0px;
horizontal-stretch: 1; vertical-stretch: 1;
background: AppTheme.surface;
border-radius: 8px;
border-width: LayoutMetrics.divider-width;
border-color: AppTheme.border-subtle;
clip: true;
scroll := ScrollView {
x: LayoutMetrics.divider-width; y: LayoutMetrics.divider-width;
width: parent.width - 2 * LayoutMetrics.divider-width; height: parent.height - 2 * LayoutMetrics.divider-width;
content-width: self.visible-width;
content-height: body.height + 2 * root.inset;
body := Text {
x: root.inset; y: root.inset;
width: scroll.visible-width - 2 * root.inset; height: self.preferred-height;
text: root.text; wrap: word-wrap; color: AppTheme.body; font-size: TypeScale.body;
}
}
}
+3 -6
View File
@@ -1,6 +1,6 @@
import { HorizontalBox, StyleMetrics, VerticalBox, ScrollView } from "std-widgets.slint";
import { HorizontalBox, StyleMetrics, VerticalBox } from "std-widgets.slint";
import { MailAttachments } from "../models.slint";
import { DocumentPreview } from "../components/document-preview.slint";
import { DocumentPreview, TextPreview } from "../components/document-preview.slint";
import { ToolbarIconButton } from "../components/controls.slint";
import { AppTheme } from "../design-system.slint";
import { TypeScale } from "../typography.slint";
@@ -46,10 +46,7 @@ export component AttachmentPreviewDialog inherits Rectangle {
raster-zoom: MailAttachments.pages > 0 ? 2 : 1; document-revision: MailAttachments.revision;
render-page(page, zoom) => { MailAttachments.command("page", "" + page); }
}
if !MailAttachments.is-image : ScrollView {
content-width: self.visible-width;
Text { width: parent.visible-width; text: MailAttachments.text; wrap: word-wrap; color: AppTheme.body; }
}
if !MailAttachments.is-image : TextPreview { compact: root.compact; text: MailAttachments.text; }
Text { text: MailAttachments.busy ? @tr("Loading preview…") : MailAttachments.status; wrap: word-wrap; color: AppTheme.secondary; }
}
}
+2 -2
View File
@@ -1,4 +1,4 @@
import { DocumentPreview } from "../components/document-preview.slint";
import { DocumentPreview, TextPreview } from "../components/document-preview.slint";
import { InfiniteScrollController } from "../components/infinite-scroll-controller.slint";
import { ScrollFade } from "../components/scroll-fade.slint";
import { HorizontalBox, VerticalBox, ListView, ScrollView, ComboBox, CheckBox } from "std-widgets.slint";
@@ -483,7 +483,7 @@ export component FilesView inherits Rectangle {
document-revision: FilesUi.selected;
render-page(page, zoom) => { FilesUi.command("pdf-page", "" + page, "200"); }
}
if FilesUi.preview-open && !FilesUi.preview-is-image : ScrollView { vertical-stretch: 1; content-width: self.visible-width; Text { x: 0px; y: 0px; width: parent.width; height: self.preferred-height; text: FilesUi.preview-text; wrap: word-wrap; color: AppTheme.body; font-size: TypeScale.body; } }
if FilesUi.preview-open && !FilesUi.preview-is-image : TextPreview { compact: root.compact; text: FilesUi.preview-text; }
if root.single-surface && FilesUi.preview-open && FilesUi.status != "" : Text { vertical-stretch: 0; text: FilesUi.status; color: AppTheme.secondary; wrap: word-wrap; font-size: TypeScale.caption; }
}
}