Skip to content

Build your personal knowledge base with Trilium Notes

style(geomap): tune the zoom controls to say less and stand closer in

Elian Dorandedfc7761b59
diff --git a/apps/client/src/stylesheets/theme-next/base.css b/apps/client/src/stylesheets/theme-next/base.css
index 1e6fde3be1..b75d12fb29 100644
--- a/apps/client/src/stylesheets/theme-next/base.css
+++ b/apps/client/src/stylesheets/theme-next/base.css
@@ -72,6 +72,8 @@
--overlay-button-color: var(--opaque-icon-button-color);
--overlay-button-icon-size: 16px;
--overlay-button-text-size: 14px;
+ /* How far a group of overlay buttons stands off the corner of the content it floats over. */
+ --overlay-button-inset: 10px;
--menu-padding-size: 8px;
--menu-item-icon-vert-offset: -2px;
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 13ec1aed6f..ebe76ba37b 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2749,7 +2749,6 @@
"webgl-unavailable": "This map can't be drawn because WebGL isn't available. Check that hardware acceleration is enabled and that your graphics drivers are up to date.",
"zoom-in": "Zoom in",
"zoom-out": "Zoom out",
- "reset-zoom": "Reset zoom",
"fullscreen": "Fullscreen",
"exit-fullscreen": "Exit fullscreen",
"close-details": "Close",
diff --git a/apps/client/src/widgets/collections/geomap/MapToolbar.css b/apps/client/src/widgets/collections/geomap/MapToolbar.css
index 6cd3b45286..216a2f96af 100644
--- a/apps/client/src/widgets/collections/geomap/MapToolbar.css
+++ b/apps/client/src/widgets/collections/geomap/MapToolbar.css
@@ -34,3 +34,9 @@
opacity: .4;
pointer-events: none;
}
+
+/* The readout between the steps is disabled only to stand inert (see MapToolbar.tsx); it is not a
+ refused action, and does not wear the refused look. */
+.geo-map-container .geo-map-toolbar .geo-map-zoom-level:disabled {
+ opacity: 1;
+}
diff --git a/apps/client/src/widgets/collections/geomap/MapToolbar.spec.tsx b/apps/client/src/widgets/collections/geomap/MapToolbar.spec.tsx
index ca0422ea51..c6dfa0fc4e 100644
--- a/apps/client/src/widgets/collections/geomap/MapToolbar.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/MapToolbar.spec.tsx
@@ -3,7 +3,7 @@
* be dark, dressed in neither Trilium's buttons nor its colors. What is checked here is what they
* did for us: the two steps, a step that would carry the map past either end of the range it is
* allowed being refused rather than merely doing nothing, the readout between the steps saying how
- * close in the map is and taking it back out, and the screen being given and taken back.
+ * close in the map is, and the screen being given and taken back.
*/
import type { Map as MapLibreGLMap } from "maplibre-gl";
import { render } from "preact";
@@ -11,7 +11,7 @@ import { act } from "preact/test-utils";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { renderInto } from "../../../test/render";
-import { DEFAULT_ZOOM, ParentMap } from "./map";
+import { ParentMap } from "./map";
import MapToolbar from "./MapToolbar";
/** The order the group lays its buttons out in — the image viewer's, with the screen at the end. */
@@ -39,8 +39,8 @@ function fakeMap({ zoom = 5, minZoom = 2, maxZoom = 22 } = {}) {
getContainer: () => container,
zoomIn: vi.fn(() => setZoom(zoom + 1)),
zoomOut: vi.fn(() => setZoom(zoom - 1)),
- /** The map being zoomed to a level outright — the readout's reset, or a restored view. */
- zoomTo: vi.fn(setZoom),
+ /** The map being zoomed by something other than these buttons — the wheel, or a pinch. */
+ zoomTo: setZoom,
on: (event: string, listener: () => void) => { if (event === "zoom") listeners.add(listener); },
off: (event: string, listener: () => void) => { if (event === "zoom") listeners.delete(listener); },
get listenerCount() { return listeners.size; }
@@ -109,24 +109,17 @@ describe("geo map MapToolbar", () => {
expect(map.zoomOut).toHaveBeenCalled();
});
- it("says how close in the map is, following the wheel as much as the buttons", () => {
+ it("says how close in the map is, in whole levels, following the wheel as much as the buttons", () => {
const map = fakeMap({ zoom: 5 });
const container = renderToolbar(map);
- expect(buttons(container)[ZOOM_LEVEL].textContent).toBe("5.0");
+ expect(buttons(container)[ZOOM_LEVEL].textContent).toBe("5");
- // As the wheel or a pinch would.
- act(() => map.zoomTo(12.5));
-
- expect(buttons(container)[ZOOM_LEVEL].textContent).toBe("12.5");
- });
-
- it("takes the map back out to the whole world when the readout is pressed", () => {
- const map = fakeMap({ zoom: 15 });
- const container = renderToolbar(map);
-
- press(container, ZOOM_LEVEL);
+ // As the wheel or a pinch would — landing between levels, which the readout does not split.
+ act(() => map.zoomTo(13.6));
- expect(map.zoomTo).toHaveBeenCalledWith(DEFAULT_ZOOM);
+ expect(buttons(container)[ZOOM_LEVEL].textContent).toBe("14");
+ // The readout is told, not asked: unlike the image viewer's, pressing it resets nothing.
+ expect(buttons(container)[ZOOM_LEVEL].disabled).toBe(true);
});
it("disables the step that would carry the map past the range it is allowed", () => {
diff --git a/apps/client/src/widgets/collections/geomap/MapToolbar.tsx b/apps/client/src/widgets/collections/geomap/MapToolbar.tsx
index 1b30241d63..668d2f402d 100644
--- a/apps/client/src/widgets/collections/geomap/MapToolbar.tsx
+++ b/apps/client/src/widgets/collections/geomap/MapToolbar.tsx
@@ -5,7 +5,7 @@ import { useContext, useEffect, useRef, useState } from "preact/hooks";
import { t } from "../../../services/i18n";
import { useFullscreen, useStaticTooltip } from "../../react/hooks";
-import { DEFAULT_ZOOM, ParentMap } from "./map";
+import { ParentMap } from "./map";
/**
* The controls standing in the corner of a geo map: how close in the map is drawn, and how much of
@@ -15,8 +15,9 @@ import { DEFAULT_ZOOM, ParentMap } from "./map";
* `FullscreenControl`), dressed in neither Trilium's buttons nor Trilium's colors — a white box with
* hairline-separated squares in it, on a map that may well be dark. What they do is done here
* instead, on the control group the image viewer's zoom buttons stand on (`tn-overlay-control-group`,
- * see {@link ImageViewer}): a step out, a step in, and between them a readout saying how close in the
- * map is — which, pressed, takes the map back out to the whole world.
+ * see {@link ImageViewer}): a step out, a step in, and between them a readout saying how close in
+ * the map is. The readout only says it — a map has no fitted view to be reset to the way an image
+ * has, and the whole world is a place worth going back to only rarely.
*/
export default function MapToolbar() {
const map = useContext(ParentMap);
@@ -26,14 +27,12 @@ export default function MapToolbar() {
const [ isFullscreen, toggleFullscreen ] = useFullscreen(map?.getContainer());
const zoomOutRef = useRef<HTMLButtonElement>(null);
- const zoomLevelRef = useRef<HTMLButtonElement>(null);
const zoomInRef = useRef<HTMLButtonElement>(null);
const fullscreenRef = useRef<HTMLButtonElement>(null);
// The group stands at the foot of the map, so its tooltips open away from that edge, where
// they would otherwise fall off.
useStaticTooltip(zoomOutRef, { title: t("geo-map.zoom-out"), placement: "top" });
- useStaticTooltip(zoomLevelRef, { title: t("geo-map.reset-zoom"), placement: "top" });
useStaticTooltip(zoomInRef, { title: t("geo-map.zoom-in"), placement: "top" });
useStaticTooltip(fullscreenRef, {
title: isFullscreen ? t("geo-map.exit-fullscreen") : t("geo-map.fullscreen"),
@@ -60,14 +59,17 @@ export default function MapToolbar() {
disabled={current <= map.getMinZoom()}
onClick={() => map.zoomOut()}
/>
+ {/* The readout is told, not asked: the image viewer's presses this to go back to the
+ fitted view, but a map has no such view to offer — so it only says where between the
+ ends the zoom stands, whole levels being all anyone does anything with. Disabled
+ rather than a plain span so it stays a child the group's styling knows; the refused
+ look is taken off it in MapToolbar.css. */}
<button
- ref={zoomLevelRef}
type="button"
className="tn-overlay-text-button geo-map-zoom-level"
- aria-label={t("geo-map.reset-zoom")}
- onClick={() => map.zoomTo(DEFAULT_ZOOM)}
+ disabled
>
- {current.toFixed(1)}
+ {Math.round(current)}
</button>
<button
ref={zoomInRef}
diff --git a/apps/client/src/widgets/collections/geomap/index.css b/apps/client/src/widgets/collections/geomap/index.css
index 9e4e89632d..bed7ad8d1f 100644
--- a/apps/client/src/widgets/collections/geomap/index.css
+++ b/apps/client/src/widgets/collections/geomap/index.css
@@ -19,10 +19,11 @@
}
.geo-map-container {
- /* How far everything standing over the map is held off its edges: the toolbar (see
- MapToolbar.css) and MapLibre's own scale and attribution below. Settled here so that the two
- agree, and matching the room the mind map gives its bars (see MindMap.css). */
- --geo-map-inset: 20px;
+ /* How far everything standing over the map is held off its edges: the zoom controls (see
+ MapToolbar.css), the editing bar, and MapLibre's own scale and attribution below. The very
+ room the image viewer keeps its controls at, taken from the shared name rather than restated
+ (see the overlay buttons in theme-next/base.css), so the two cannot drift apart. */
+ --geo-map-inset: var(--overlay-button-inset, 10px);
/* How tall the controls in the corner stand, which is what anything else opened over that corner
has to end above (see DetailPane.css). The image viewer's zoom controls are the same height,
@@ -63,8 +64,9 @@
position: relative;
}
- /* MapLibre holds its controls 10px off the edge, which is half of what everything else over the
- map keeps to; only the foot of the map carries any (the scale and the attribution). */
+ /* MapLibre spaces its controls off the edge by margins of its own — only the foot of the map
+ carries any (the scale and the attribution). Restated in the shared inset's terms, so they
+ stand where everything else over the map stands and follow it if it ever moves. */
.maplibregl-ctrl-bottom-left .maplibregl-ctrl,
.maplibregl-ctrl-bottom-right .maplibregl-ctrl {
margin-bottom: var(--geo-map-inset);
diff --git a/apps/client/src/widgets/collections/geomap/map.tsx b/apps/client/src/widgets/collections/geomap/map.tsx
index 59074406b0..4508fca08f 100644
--- a/apps/client/src/widgets/collections/geomap/map.tsx
+++ b/apps/client/src/widgets/collections/geomap/map.tsx
@@ -19,8 +19,7 @@ export interface GeoMouseEvent {
export const ParentMap = createContext<MapLibreGLMap | null>(null);
-/** The zoom a map opens at where no view has been saved: far enough out to see the whole world.
- * Also what the zoom readout returns the map to when pressed (see {@link MapToolbar}). */
+/** The zoom a map opens at where no view has been saved: far enough out to see the whole world. */
export const DEFAULT_ZOOM = 2;
/**
diff --git a/apps/client/src/widgets/react/ImageViewer.css b/apps/client/src/widgets/react/ImageViewer.css
index 2e9af76a81..9549dce08d 100644
--- a/apps/client/src/widgets/react/ImageViewer.css
+++ b/apps/client/src/widgets/react/ImageViewer.css
@@ -9,16 +9,16 @@
/* Zoom controls pinned to the bottom-right corner of the viewport. */
.image-viewer-controls {
position: absolute;
- inset-inline-end: 10px;
- bottom: 10px;
+ inset-inline-end: var(--overlay-button-inset, 10px);
+ bottom: var(--overlay-button-inset, 10px);
z-index: 1;
}
/* Shortcut-hints button pinned to the top-right corner of the viewport. */
.image-viewer-hint-button {
position: absolute;
- inset-inline-end: 10px;
- top: 10px;
+ inset-inline-end: var(--overlay-button-inset, 10px);
+ top: var(--overlay-button-inset, 10px);
z-index: 1;
}