rust_widgets 1.1.2

Pure Rust cross-platform native GUI library with hardware-adaptive rendering, 60+ widgets, touch/gesture support, i18n, and SVG-pipeline-accurate output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
[package]
name = "rust_widgets"
version = "1.1.2"
edition = "2021"
description = "Pure Rust cross-platform native GUI library with hardware-adaptive rendering, 60+ widgets, touch/gesture support, i18n, and SVG-pipeline-accurate output"
license = "MIT"
keywords = ["gui", "widget", "cross-platform", "mobile", "wasm"]
categories = ["gui", "rendering", "graphics", "embedded", "wasm"]
authors = ["Mike Wolfli <mikewolfli@gmail.com>"]
readme = "README.md"
homepage = "https://github.com/mikewolfli/rust-widgets"
repository = "https://github.com/mikewolfli/rust-widgets"
rust-version = "1.87"
include = [
    "build.rs",
    "src/**/*",
    "tests/**/*",
    "benches/**/*",
    "examples/**/*",
    "include/**/*",
    "language/**/*",
    "tools/widget_gallery.rs",
    "LICENSE",
    "README.md",
    "README.zh-CN.md",
    "CHANGELOG.md",
    "clippy.toml",
    "rustfmt.toml",
]

[lints.rust]
# `target_os = "ohos"` (HarmonyOS NEXT) is not yet in rustc's built-in
# known target_os list; declare it explicitly so the check stays meaningful.
unexpected_cfgs = { level = "warn", check-cfg = [
    'cfg(target_os, values("ohos"))',
    'cfg(feature, values("cargo-clippy"))',
] }

[lib]
crate-type = ["lib", "cdylib"]

# ═══════════════════════════════════════════════════════════════════════
# Feature System — three independent axes (pick one from each):
#   1. Device Profile (pick ONE)
#   2. OS Backend    (pick ONE or auto)
#   3. Capability    (arbitrary composition)
# ═══════════════════════════════════════════════════════════════════════

[features]
# ── Default is full desktop ──
default = ["desktop"]

# ── Axis 1: DEVICE PROFILES (mutually exclusive) ──

## Full desktop: native platform, GPU, touch, i18n, chart, print, PDF, A11y.
##
## NOTE: `audio-output`, `symphonia-codecs`, `webkit-engine`, and `video-codecs`
## are NOT enabled by default because they pull in large system-library
## dependencies (ALSA, WebKitGTK, FFmpeg, symphonia). Enable them explicitly:
##   cargo build --features "desktop,audio-output,symphonia-codecs,video-codecs"
## Or use the `full` meta-feature for everything.
desktop = [
    "os-auto",
    "cocoa-legacy",
    "desktop-runtime",
    "wgpu",
    "touch",
    "i18n",
    "chart",
    "print",
    "pdf",
    "a11y",
    "quality-management",
    "advanced-widgets",
    "controls-native",
    "controls-custom",
    "image",
    "video",
    "audio",
    "pdf-encryption",
    "js-engine",
    "dep:chrono",
    "serde",
    "serde_json",
]

## Tablet: touch-first, GPU, native controls, no desktop extras.
##
## Shares the desktop UI-compilation surface (JSON, i18n hot-reload watcher,
## chrono-backed widgets, serde) minus print/pdf/chart/a11y/js extras.
tablet = [
    "os-auto",
    "wgpu",
    "touch",
    "i18n",
    "desktop-runtime",
    "serde",
    "serde_json",
    "dep:chrono",
    "quality-management",
    "controls-native",
    "controls-custom",
    "image",
]

## Mobile: touch, GPU, mobile API, native controls.
mobile = [
    "os-auto",
    "wgpu",
    "touch",
    "i18n",
    "desktop-runtime",
    "serde",
    "serde_json",
    "dep:chrono",
    "quality-management",
    "mobile-api",
    "controls-native",
    "controls-custom",
    "image",
]

## Embedded: software raster, no GPU, no touch, low memory.
embedded = ["software", "controls-custom"]

## LVGL-style mini: ~15 core widgets, software raster, no alloc-heavy deps.
mini = [
    "software",
    "controls-custom",
    "dep:heapless",
    "dep:hashbrown",
    "dep:spin",
    "dep:bumpalo",
]


# ── Axis 2: OS BACKENDS (composable; `os-auto` picks by target_os) ──

os-auto = []
macos = [
    "dep:objc2",
    "dep:objc2-foundation",
    "dep:objc2-app-kit",
    "dep:objc2-core-graphics",
    # The objc2 backend's handle types derive Serialize/Deserialize and its state
    # snapshot returns `serde_json::Error`, so these are hard requirements rather
    # than optional extras. They were previously inherited from `desktop`, which
    # made `--features macos` alone fail to compile.
    "serde",
    "serde_json",
]
macos-legacy = ["dep:cocoa", "dep:objc", "dep:objc-foundation"]
ios = [
    "dep:objc2",
    "dep:objc2-foundation",
    "dep:objc2-core-foundation",
    "dep:objc2-core-graphics",
    "dep:objc2-ui-kit",
]
windows = []
linux-gtk = ["dep:gtk"]
linux-wayland = [
    "dep:wayland-client",
    "dep:wayland-protocols",
    "dep:wayland-cursor",
    "dep:libc",
]
linux-a11y = ["dep:zbus", "dep:pollster"]
android = ["dep:jni"]
# Explicit `jni` feature name so `--features jni` (documented by
# `src/bindings/java_jni.rs`) and `cfg(feature = "jni")` work; mirrors the
# `serde`/`dep:serde` pattern.
jni = ["dep:jni"]
wasm = ["dep:wasm-bindgen", "dep:web-sys", "dep:js-sys", "serde"]
harmony = []


# ── Axis 3: CAPABILITIES (arbitrary composition) ──

touch = []
gpu = ["dep:wgpu"]
wgpu = ["gpu"]
software = []
i18n = ["dep:notify", "dep:crossbeam-channel", "dep:serde", "dep:serde_json"]
chart = []
print = []
pdf = []
a11y = []
image = ["dep:miniz_oxide", "image-codecs", "svg-rasterizer"]
image-codecs = ["dep:image-codecs"]
svg-rasterizer = ["dep:resvg"]
# Video frames reuse the image format types (DecodedImage/ImageFormat).
video = ["dep:jpeg-decoder", "image"]
audio = ["dep:minimp3_fixed"]
holographic = []
projection = []


# ── INTERNAL FEATURES (used by profiles, not user-facing) ──

desktop-runtime = ["dep:notify", "dep:crossbeam-channel"]
quality-management = []
mobile-api = []
controls-native = []
controls-custom = []
advanced-widgets = ["dep:dirs"]
# Internal runtime-profile selector referenced by `runtime_profile_name()`
# (`src/lib.rs`); selects the "embedded-mini" profile combination.
profile-embedded-mini = []

# New capability features
# Note: pdf-encryption, audio-output, js-engine are cross-platform (Pure Rust / system-agnostic).
# webkit-engine is Linux-only (webkit2gtk requires GTK+WebKit system libs).
# video-codecs is cross-platform when system FFmpeg is installed.
pdf-encryption = ["aes", "sha2", "cbc"]
audio-output = ["cpal"]
js-engine = ["boa_engine"]
webkit-engine = ["dep:webkit2gtk"]
video-codecs = ["dep:ffmpeg-next"]
web-http = ["dep:ureq"]

# Explicit feature flag so `cfg(feature = "serde")` works with `dep:serde`.
serde = ["dep:serde"]
serde_json = ["dep:serde_json"]

unstable-pipeline-routing = []
unstable-special-widgets = []


# ── AUDIO CODEC FEATURES ──

## Real audio codecs via symphonia (FLAC, OGG Vorbis, AAC, Opus).
## Enables actual PCM decoding instead of synthetic fallback data.
symphonia-codecs = ["symphonia"]


# ── BACKWARD-COMPAT ALIASES ──
# Old feature names used in #[cfg(feature = "...")] throughout the codebase.
# These forward to the new names above.

# Old OS backends
objc2-macos = ["macos"]
cocoa-legacy = ["macos-legacy"]
ios-uikit-ffi = ["ios"]
gtk-native = ["linux-gtk"]
wayland-native = ["linux-wayland"]
android-jni = ["android", "jni"]

# Old capability names
gpu-wgpu = ["gpu", "dep:pollster"]


# ── META FEATURES ──

## Everything (not for production — pick a specific device profile).
full = [
    "desktop",
    "macos",
    "macos-legacy",
    "ios",
    "linux-gtk",
    "linux-wayland",
    "linux-a11y",
    "android",
    "wasm",
    "harmony",
    "holographic",
    "projection",
    "unstable-pipeline-routing",
    "unstable-special-widgets",
    "pdf-encryption",
    "symphonia-codecs",
    "audio-output",
    "js-engine",
    "webkit-engine",
    "video-codecs",
]


# ═══════════════════════════════════════════════════════════════════════
# DEPENDENCIES
# ═══════════════════════════════════════════════════════════════════════

[dependencies]
serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = { version = "1.0", optional = true }
crossbeam-channel = { version = "0.5", optional = true }
font8x8 = "0.2.7"
pollster = { version = "0.4", optional = true }
chrono = { version = "0.4", optional = true }
notify = { version = "7.0", optional = true }
dirs = { version = "6.0", optional = true }
log = "0.4"
minimp3_fixed = { version = "0.5", optional = true }
miniz_oxide = { version = "0.8", optional = true }
# NOTE: AVIF uses the pure-Rust `avif` codec (ravif), not `avif-native`.
# `avif-native` pulls in `dav1d-sys`, a system C library that requires a
# pkg-config cross sysroot. That made every cross target (Android/iOS/wasm)
# fail to compile for the `mobile`/`tablet`/`desktop` profiles. The pure-Rust
# codec keeps AVIF support while remaining cross-compilable everywhere.
image-codecs = { package = "image", version = "0.25.10", optional = true, default-features = false, features = [
    "gif",
    "webp",
    "tiff",
    "avif",
    "ico",
] }
resvg = { version = "0.48.1", optional = true }
jpeg-decoder = { version = "0.3", optional = true }
ureq = { version = "3.0", optional = true, features = [] }
symphonia = { version = "0.5", default-features = false, features = [
    "all",
], optional = true }


# Audio/video codecs
aes = { version = "0.8", optional = true }
sha2 = { version = "0.10", optional = true }
cbc = { version = "0.1", optional = true }
# Note: On Linux, requires `libasound2-dev` package for ALSA backend.
# On macOS, uses CoreAudio; on Windows, uses WASAPI.
cpal = { version = "0.15", optional = true }
boa_engine = { version = "0.19", optional = true }

wgpu = { version = "30.0.1", optional = true }

wasm-bindgen = { version = "0.2", optional = true }
js-sys = { version = "0.3", optional = true }
# Cross-platform FFmpeg (system lib). On Linux: apt install libav*-dev,
# macOS: brew install ffmpeg, Windows: vcpkg install ffmpeg.
ffmpeg-next = { version = "9.0", optional = true }

web-sys = { version = "0.3", features = [
    "Window",
    "Document",
    "Element",
    "HtmlElement",
    "Node",
    "Event",
    "MouseEvent",
    "KeyboardEvent",
    "console",
    "HtmlCanvasElement",
    "CanvasRenderingContext2d",
    "Clipboard",
    "Navigator",
    "Location",
], optional = true }

jni = { version = "0.21", features = ["invocation"], optional = true }

heapless = { version = "0.8", optional = true }
hashbrown = { version = "0.15", optional = true, default-features = false, features = [
    "alloc",
] }
spin = { version = "0.9", optional = true }
bumpalo = { version = "3.17", optional = true, default-features = false }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = [
    "winuser",
    "commctrl",
    "commdlg",
    "winbase",
    "synchapi",
    "wingdi",
    "shellapi",
    "ole2",
    "combaseapi",
    "objbase",
    "knownfolders",
    "shlobj",
    "shobjidl",
    "winerror",
    "errhandlingapi",
    "libloaderapi",
    # `GlobalMemoryStatusEx` (sysinfoapi) and `GetProcessMemoryInfo` (psapi)
    # back `Platform::total_memory_mb` / `Platform::process_memory_utilization`
    # in the Windows backend.
    "sysinfoapi",
    "psapi",
] }

[target.'cfg(target_os = "macos")'.dependencies]
objc = { version = "0.2", optional = true }
objc-foundation = { version = "0.1", optional = true }
objc2 = { version = "0.6", optional = true }
objc2-foundation = { version = "0.3", optional = true }
objc2-app-kit = { version = "0.3", optional = true }
objc2-core-graphics = { version = "0.3", optional = true }
cocoa = { version = "0.25", optional = true }

[target.'cfg(target_os = "ios")'.dependencies]
objc2 = { version = "0.6", optional = true }
objc2-foundation = { version = "0.3", optional = true }
objc2-core-foundation = { version = "0.3", optional = true }
objc2-core-graphics = { version = "0.3", optional = true }
objc2-ui-kit = { version = "0.3", optional = true }

[target.'cfg(target_os = "linux")'.dependencies]
gtk = { version = "0.18", optional = true }
# Used by the Wayland backend to poll() the compositor socket in the native
# event loop (the crate is already in the dependency graph transitively).
libc = { version = "0.2", optional = true }
wayland-client = { version = "0.31", optional = true }
wayland-protocols = { version = "0.32", features = [
    "staging",
    "client",
], optional = true }
wayland-cursor = { version = "0.31", optional = true }
zbus = { version = "5", optional = true }
webkit2gtk = { version = "2.0", optional = true }

[target.'cfg(target_os = "harmony")'.dependencies]

# `wasm32-unknown-unknown` has no OS entropy source, so `getrandom` refuses to
# build unless its `js` feature is on. The dependency reaches us transitively
# through the JavaScript engine (`boa_engine` -> `rand` 0.8 -> `rand_core` 0.6 ->
# `getrandom` 0.2), so the fix has to be applied from the top of the graph: the
# `js` feature below is unified with whatever `boa_engine` requests, which is what
# unlocks the wasm32 backend.
#
# This is a pure build-configuration fix — no source change — matching the
# existing note above the `dev-dependencies` section, where the same constraint
# is why criterion/tempfile/proptest are gated off wasm32.
[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom02 = { package = "getrandom", version = "0.2", features = ["js"] }

# `getrandom` 0.3 removed the browser backend from the default build and renamed
# the opt-in feature: 0.2's `js` became 0.3's `wasm_js` (verified in the crate's
# own manifest, not assumed). It arrives via `rand` 0.9 in the dev-dependency
# tree, so declaring it keeps `--all-features --target wasm32` compiling too.
getrandom03 = { package = "getrandom", version = "0.3", features = ["wasm_js"] }

[dev-dependencies]
# NOTE: criterion (benchmark harness), tempfile (filesystem tests) and proptest
# (property tests) do not support wasm32 (no OS/FS/threads and their transitive
# deps — wait-timeout, getrandom — cannot compile there). They are therefore
# gated off the wasm32 targets; the tests that use them carry matching
# `#[cfg(not(target_arch = "wasm32"))]` gates.

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
criterion = "0.8.2"
tempfile = "3.14"
proptest = "1.6"

[package.metadata.docs.rs]
features = ["full", "touch", "holographic", "projection"]
rustc-args = ["--cfg", "docsrs"]

[badges]
maintenance = { status = "actively-developed" }

[profile.release]
opt-level = 3
lto = "fat"
codegen-units = 1

[profile.release-embedded]
inherits = "release"
opt-level = "s"
lto = true
codegen-units = 1
strip = true
panic = "abort"

[profile.release-mini]
inherits = "release"
opt-level = "z"
lto = true
codegen-units = 1
strip = true
panic = "abort"

[[bench]]
name = "render_bench"
harness = false

[[bench]]
name = "signal_bench"
harness = false

[[bench]]
name = "layout_bench"
harness = false

[[bench]]
name = "json_bench"
harness = false

[[bench]]
name = "event_bench"
harness = false

[[example]]
name = "widget_gallery"
path = "tools/widget_gallery.rs"

# `menu_shortcut_runtime` drives `rust_widgets::app` (macOS AppKit main-thread
# probe). The `app` module is gated on `full_widgets` — a device profile without
# `mini`/`embedded` — so the example must declare that requirement. Without this,
# `--all-targets` on a stripped profile tries to build it and fails on the
# missing `app` module instead of simply skipping it.
[[example]]
name = "menu_shortcut_runtime"
required-features = ["desktop"]