Skip to main content

egui_pop_viewport/
mounts.rs

1//! What this crate's components need, and what its overlays offer, in
2//! the mount contract's terms (ADR 0013): `docs/hosts.md` and
3//! `AppHandle::where_can` are made from these.
4
5use egui_pop_core::model::mount::{ClaimKey, Display, HostOffer, HostSize, Keyboard, Mountable};
6
7/// The image viewport.
8pub const VIEWPORT: &str = "viewport";
9/// The navigator (a minimap) and zoom control.
10pub const NAVIGATOR: &str = "navigator";
11/// The node graph editor.
12pub const NODE_GRAPH: &str = "node-graph";
13/// The curve editor.
14pub const CURVES: &str = "curves";
15/// The colour wheels.
16pub const WHEELS: &str = "wheels";
17/// The histogram.
18pub const HISTOGRAM: &str = "histogram";
19/// A thumbnail.
20pub const THUMBNAIL: &str = "thumbnail";
21/// The viewport's overlays, as a host.
22pub const OVERLAY: &str = "viewport.overlay";
23
24/// The image viewport: tiles from workers, wide gamut wanted.
25pub fn viewport() -> Mountable {
26    Mountable::new(VIEWPORT, "Image viewport")
27        .crate_name("egui-pop-viewport")
28        .keyboard(Keyboard::Hover)
29        .claims(&[ClaimKey::Space, ClaimKey::Escape])
30        .drag()
31        .wheel()
32        .cursor_images()
33        .bounded_workers()
34        .keep_under_modal()
35        .display(Display::WideWanted)
36        .fills()
37        .role("image")
38}
39
40/// The navigator: a minimap sharing the viewport's state.
41pub fn navigator() -> Mountable {
42    Mountable::new(NAVIGATOR, "Navigator")
43        .crate_name("egui-pop-viewport")
44        .drag()
45        .wheel()
46        .min(120.0, 80.0)
47        .max(320.0, 214.0)
48        .aspect(1.5)
49        .role("image")
50}
51
52/// The node graph editor: wiring is a session.
53pub fn node_graph() -> Mountable {
54    Mountable::new(NODE_GRAPH, "Node graph")
55        .crate_name("egui-pop-viewport")
56        .claims(&[ClaimKey::Escape, ClaimKey::Space])
57        .keymap()
58        .drag()
59        .wheel()
60        .fills()
61        .session()
62        .role("group")
63}
64
65/// The curve editor.
66pub fn curves() -> Mountable {
67    Mountable::new(CURVES, "Curves")
68        .crate_name("egui-pop-viewport")
69        .claims(&[ClaimKey::Escape])
70        .drag()
71        .min(120.0, 120.0)
72        .max(320.0, 320.0)
73        .aspect(1.0)
74        .role("image")
75}
76
77/// The colour wheels.
78pub fn wheels() -> Mountable {
79    Mountable::new(WHEELS, "Wheels")
80        .crate_name("egui-pop-viewport")
81        .claims(&[ClaimKey::Escape])
82        .drag()
83        .min(48.0, 48.0)
84        .preferred(160.0, 160.0)
85        .aspect(1.0)
86        .role("slider")
87}
88
89/// The histogram: read-only unless draggable.
90pub fn histogram() -> Mountable {
91    Mountable::new(HISTOGRAM, "Histogram")
92        .crate_name("egui-pop-viewport")
93        .claims(&[ClaimKey::Escape])
94        .drag()
95        .min(120.0, 40.0)
96        .max(600.0, 200.0)
97        .role("image")
98        .preview()
99}
100
101/// A thumbnail: a texture the application gives, clicked.
102pub fn thumbnail() -> Mountable {
103    Mountable::new(THUMBNAIL, "Thumbnail")
104        .crate_name("egui-pop-viewport")
105        .keyboard(Keyboard::None)
106        .min(16.0, 16.0)
107        .preferred(96.0, 72.0)
108        .role("image")
109        .preview()
110}
111
112/// This crate's components.
113pub fn components() -> Vec<Mountable> {
114    vec![
115        viewport(),
116        navigator(),
117        node_graph(),
118        curves(),
119        wheels(),
120        histogram(),
121        thumbnail(),
122    ]
123}
124
125/// The viewport's overlays: shapes and handles in image coordinates,
126/// data, not a `Ui`.
127pub fn overlay_host() -> HostOffer {
128    HostOffer::new(OVERLAY, "V", "Viewport overlay")
129        .source("egui_pop_viewport::overlay")
130        .size(HostSize::NoUi)
131        .focus(egui_pop_core::model::mount::FocusPolicy::None)
132        .window(egui_pop_core::model::mount::Window::FollowsPanel)
133        .keymap(false)
134        .gives_app(false)
135        .scope(false)
136        .fault_boundary(false)
137}