• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

examples/H29-Aug-2020-277218

src/H29-Aug-2020-8,4337,028

Cargo.tomlH A D03-May-2022951 3632

README.mdH A D29-Aug-20204 KiB10473

README.md

1# widgetry notes
2
3Rustwarts School of Glitchcraft and Widgetry.
4
5This is a GUI + 2D drawing + data viz library I've built up for A/B Street. I'm
6considering cleaning up the API surface and making it a proper standalone crate.
7
8## Running the demo
9
10[Example code](examples/demo.rs)
11
12```
13git clone https://github.com/dabreegster/abstreet.git
14cd abstreet/widgetry
15cargo run --example demo
16
17# Or for web
18cargo web start --target wasm32-unknown-unknown --no-default-features --features wasm-backend --example demo
19```
20
21![demo](demo.gif)
22
23If you want a more thorough idea of what this crate can do, see
24[A/B Street](https://abstreet.org).
25
26## Features
27
28### Runs in lots of places
29
30Runs on Linux, Mac, Windows via [glow](https://github.com/grovesNL/glow/). Also
31works in the browser using WebAssembly, but text support still coming in
32[a few months](https://github.com/RazrFalcon/resvg/issues/229).
33
34Why OpenGL? My requirements are super simple; I don't need the power of Vulkan
35or other new stuff. I want something simple that runs everywhere. If you want to
36make this work with WGPU or something else, it should be easy. The backends are
37a few hundred lines -- [Glow](src/backend_glow.rs) running either
38[on native](src/backend_glow_native.rs) or [on wasm](src/backend_glow_wasm.rs).
39
40### 2D drawing
41
42Everything is a colored polygon. Upload stuff once, redraw many times with a
43simple camera transform. Panning and smooth zooming. One extremely simple
44shader.
45
46Thanks to [usvg](https://github.com/RazrFalcon/resvg) and
47[lyon](https://github.com/nical/lyon/), SVGs and text are transformed into
48colored polygons. Programatically swap colors, rotate, scale stuff. Find bounds
49for precise mouseover.
50
51### GUI
52
53Widgets like buttons (with keybindings), checkboxes, sliders, pop-up menus, text
54entry, and some data viz things. You can combine these in `Panel`s to dispatch
55event handling and drawing. Styling (background colors, outline, padding) and
56Flexbox-ish layouting via [stretch](https://vislyhq.github.io/stretch/).
57
58The API / programming style is kind of funny; see the [demo](examples/demo.rs)
59to get a sense of it. No callbacks. You manually feed events into your `Panel`s
60of widgets and ask about what happened. There's no smart diffing of widget
61trees; most of the time it's fine to completely recreate a `Panel` from scratch
62when something changes, or replace a single widget in an existing `Panel`.
63
64(This is not a performance critical library. The perf bottlenecks in A/B Street
65are not in the GUI, and I probably won't invest much time speeding things up
66here until they are. (Or if somebody else winds up using this library and hits a
67problem.))
68
69### Data visualization
70
71Not exactly sure how this wound up in here too, but at some point I needed
72histograms and line plots that update live over time and show some info when you
73mouseover points, so here it is.
74
75## Big problems to solve before release
76
77When you ask a `Panel` what action happened (what button was clicked), it hands
78you back `Option<String>`. Not so typesafe. How boilerplatey is it to associate
79buttons with a user-provided enum?
80
81There are hardcoded colors / padding in lots of places. Need to make style
82easily configurable, with good defaults.
83
84The error handling is pretty bad; lots of unwraps and panics to clean up.
85
86## Why another Rust GUI library?
87
88When I started, nothing did what I needed, or it required awkward callbacks.
89Today, [iced](https://github.com/hecrj/iced) looks awesome, but wgpu doesn't
90work on my laptop. This is a dealbreaker -- I want to build stuff that runs
91~anywhere. I looked into adding an OpenGL backend, but the current structure of
92iced has a
93[huge](https://github.com/hecrj/iced/blob/master/native/src/renderer/null.rs)
94API surface to implement for a new backend.
95
96For the moment, I don't have enough time to get something else on-par with this
97library and port A/B Street over, so I'll continue to invest in this library. If
98there's lots of interest in other people using this library, I'll invest much
99more and make it a real contender.
100
101## Future work
102
103- Draggable panels
104