client: add an option to center the content

This commit is contained in:
Adorian Doran 2025-11-07 18:17:28 +02:00
parent 2d03dd22e3
commit fa64ca2c93
9 changed files with 32 additions and 8 deletions

View File

@ -1811,6 +1811,8 @@ body:not(.mobile) #launcher-pane.horizontal .dropdown-submenu > .dropdown-menu {
.note-split {
/* Limits the maximum width of the note */
--max-content-width: var(--preferred-max-content-width);
/* Indicates the inline margin of the content. If set to "auto" the content will be centered. */
--content-margin-inline: var(--preferred-content-margin-inline);
margin-inline-start: auto;
margin-inline-end: auto;

View File

@ -1110,7 +1110,8 @@
"title": "Content Width",
"default_description": "Trilium by default limits max content width to improve readability for maximized screens on wide screens.",
"max_width_label": "Max content width",
"max_width_unit": "pixels"
"max_width_unit": "pixels",
"centerContent": "Keep content centered"
},
"native_title_bar": {
"title": "Native Title Bar (requires app restart)",

View File

@ -1,6 +1,11 @@
.note-list-widget {
min-height: 0;
max-width: var(--max-content-width); /* Inherited from .note-split */
/* Inherited from .note-split */
max-width: var(--max-content-width);
/* Inherited from .note-split. If set to "auto" the list widget will be centered horizontally. */
margin-inline: var(--content-margin-inline);
overflow: auto;
contain: none !important;
}

View File

@ -31,7 +31,7 @@ export default class RootContainer extends FlexContainer<BasicWidget> {
window.visualViewport?.addEventListener("resize", () => this.#onMobileResize());
}
this.#setMaxContentWidth(options.getInt("maxContentWidth") ?? 0);
this.#setMaxContentWidth();
this.#setMotion(options.is("motionEnabled"));
this.#setShadows(options.is("shadowsEnabled"));
this.#setBackdropEffects(options.is("backdropEffectsEnabled"));
@ -54,8 +54,8 @@ export default class RootContainer extends FlexContainer<BasicWidget> {
this.#setBackdropEffects(options.is("backdropEffectsEnabled"));
}
if (loadResults.isOptionReloaded("maxContentWidth")) {
this.#setMaxContentWidth(options.getInt("maxContentWidth") ?? 0);
if (loadResults.isOptionReloaded("maxContentWidth") || loadResults.isOptionReloaded("centerContent")) {
this.#setMaxContentWidth();
}
}
@ -66,9 +66,15 @@ export default class RootContainer extends FlexContainer<BasicWidget> {
this.$widget.toggleClass("virtual-keyboard-opened", isKeyboardOpened);
}
#setMaxContentWidth(width: number) {
width = Math.max(width, 640);
#setMaxContentWidth() {
const width = Math.max(options.getInt("maxContentWidth") || 0, 640);
const centerContent = options.is("centerContent");
document.body.style.setProperty("--preferred-max-content-width", `${width}px`);
// To center the content, "--preferred-content-margin-inline" should be set to "auto".
document.body.style.setProperty("--preferred-content-margin-inline",
(centerContent) ? "auto" : "unset");
}
#setMotion(enabled: boolean) {

View File

@ -40,6 +40,8 @@ const TPL = /*html*/`
<style>
.note-detail {
max-width: var(--max-content-width); /* Inherited from .note-split */
/* Inherited from .note-split. If set to "auto" the note detail widget will be centered horizontally. */
margin-inline: var(--content-margin-inline);
font-family: var(--detail-font-family);
font-size: var(--detail-font-size);
}

View File

@ -284,7 +284,8 @@ function SmoothScrollEnabledOption() {
}
function MaxContentWidth() {
const [ maxContentWidth, setMaxContentWidth ] = useTriliumOption("maxContentWidth");
const [maxContentWidth, setMaxContentWidth] = useTriliumOption("maxContentWidth");
const [centerContent, setCenterContent] = useTriliumOptionBool("centerContent");
return (
<OptionsSection title={t("max_content_width.title")}>
@ -299,6 +300,10 @@ function MaxContentWidth() {
/>
</FormGroup>
</Column>
<FormCheckbox label={t("max_content_width.centerContent")}
currentValue={centerContent}
onChange={setCenterContent} />
</OptionsSection>
)
}

View File

@ -68,6 +68,7 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
"smoothScrollEnabled",
"backdropEffectsEnabled",
"maxContentWidth",
"centerContent",
"compressImages",
"downloadImagesAutomatically",
"minTocHeadings",

View File

@ -117,6 +117,7 @@ const defaultOptions: DefaultOption[] = [
{ name: "weeklyBackupEnabled", value: "true", isSynced: false },
{ name: "monthlyBackupEnabled", value: "true", isSynced: false },
{ name: "maxContentWidth", value: "1200", isSynced: false },
{ name: "centerContent", value: "false", isSynced: false },
{ name: "compressImages", value: "true", isSynced: true },
{ name: "downloadImagesAutomatically", value: "true", isSynced: true },
{ name: "minTocHeadings", value: "5", isSynced: true },

View File

@ -82,6 +82,7 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
autoReadonlySizeText: number;
autoReadonlySizeCode: number;
maxContentWidth: number;
centerContent: boolean;
minTocHeadings: number;
eraseUnusedAttachmentsAfterSeconds: number;
eraseUnusedAttachmentsAfterTimeScale: number;