max / quasi
| 1 | //! What the app offers on every screen, rather than on one of them. |
| 2 | //! |
| 3 | //! A [`Screen`](crate::Screen) names one place. Everything here outlives any one |
| 4 | //! of them: a command palette reachable from anywhere, a global shortcut, the |
| 5 | //! help overlay that lists the shortcuts. None of that is a fact about the |
| 6 | //! screen the user happens to be on, and describing it per screen means |
| 7 | //! repeating it on every screen or reimplementing it per host. |
| 8 | //! |
| 9 | //! # Why this is not [`RegionKind::Modal`](crate::RegionKind::Modal) |
| 10 | //! |
| 11 | //! That is a modal a screen *contains*, which is how a confirmation is drawn: |
| 12 | //! the screen carries it, and it goes when the screen goes. Chrome belongs to |
| 13 | //! the app, so it is reachable from screens that know nothing about it. The |
| 14 | //! same move [`Screen::notices`](crate::Screen::notices) made one level down, |
| 15 | //! when a notice stopped belonging to a region and started belonging to the |
| 16 | //! screen. |
| 17 | //! |
| 18 | //! # What it costs, and what it does not |
| 19 | //! |
| 20 | //! An overlay's *contents* were always sayable: a query, a result list, a |
| 21 | //! keyboard walk through it, an [`Act`](crate::Act) that navigates. What was |
| 22 | //! missing was a way to say "fetched from a route, and drawn over what is under |
| 23 | //! it", which is [`Outcome::Over`](crate::Outcome::Over) and not a second |
| 24 | //! description tree. So an overlay is a [`Screen`](crate::Screen) like any |
| 25 | //! other, and this module is only the way in. |
| 26 | //! |
| 27 | //! A toast stack needs nothing from here: [`Screen::notices`](crate::Screen::notices) |
| 28 | //! and [`Message`](crate::Message) already carry notices, and how they stack is |
| 29 | //! renderer policy. An app-modal is the overlay case with one region in it. |
| 30 | //! |
| 31 | //! # A panel is chrome too, and is not a region every screen repeats |
| 32 | //! |
| 33 | //! Described per screen it is repeated on every screen, and the screen that |
| 34 | //! forgets it drops the panel, which is the repetition this module exists to |
| 35 | //! end. So [`Chrome::panel`] holds it. |
| 36 | //! |
| 37 | //! Its contents are an ordinary [`Node`](crate::Node), the way an overlay's |
| 38 | //! contents are an ordinary [`Screen`](crate::Screen): a panel with several |
| 39 | //! things in it is a [`Node::Region`](crate::Node::Region), and there is no |
| 40 | //! second description tree here either. |
| 41 | //! |
| 42 | //! Where it sits is the renderer's. A description saying "bottom right, |
| 43 | //! floating" would be naming one host's screen, and a terminal has no floating. |
| 44 | //! Same call as `4453bf82`, where the clock a toast expires on turned out to be |
| 45 | //! the renderer's. |
| 46 | //! |
| 47 | //! ## Dismissal is nobody's, because nothing dismisses one |
| 48 | //! |
| 49 | //! So there is no dismissed state to keep, in the description or in a |
| 50 | //! renderer, and the panel's presence is the app's answer: declare none, or |
| 51 | //! replace its contents through [`Chrome::replace`] the way every other region |
| 52 | //! is replaced. |
| 53 | //! |
| 54 | //! Adding a dismissal later is additive. Inventing one now would be a member |
| 55 | //! three renderers implement for no measured widget. |
| 56 | //! |
| 57 | //! # An app shell is several always-present things, and one of them is not a panel |
| 58 | //! |
| 59 | //! One panel was enough while the only measured consumer was a timer band. It |
| 60 | //! stopped being enough the moment an app wanted a tab bar as well: goingson's |
| 61 | //! shell is three tabs, a sub-nav under the chosen one, a sync indicator and |
| 62 | //! the timer band, and the reason `presenting` replaced rather than appended |
| 63 | //! was that a renderer handed two anonymous panels would place them by |
| 64 | //! declaration order. |
| 65 | //! |
| 66 | //! The answer is two members rather than a longer list of one kind. |
| 67 | //! |
| 68 | //! [`Chrome::nav`] holds the places the app has. A tab bar is not content that |
| 69 | //! happens to be always on screen: it is a set of addresses with names, which is |
| 70 | //! why it is [`Place`] and not a [`Panel`] holding a list. A renderer draws it as |
| 71 | //! a tab bar, a sidebar or a terminal's tab line, and it never has to be told |
| 72 | //! which, because the description never said. |
| 73 | //! |
| 74 | //! [`Chrome::panels`] holds the rest, each carrying a [`Role`]. |
| 75 | //! [`Role::Activity`] is something the app is doing right now and |
| 76 | //! [`Role::Status`] is a standing readout of its condition. The role says what a |
| 77 | //! panel is *for* and still not where it goes. There is no `Role::Navigation`, |
| 78 | //! because navigation is not a panel. |
| 79 | //! |
| 80 | //! ## Which place is current is the screen's to say |
| 81 | //! |
| 82 | //! Chrome is built once, so a `current` flag on a [`Place`] would be frozen at |
| 83 | //! build time and could never point at where the user is. The screen names its |
| 84 | //! own place instead ([`Screen::place`](crate::Screen::place)) and the renderer |
| 85 | //! marks the [`Place`] whose [`key`](Place::key) matches. Exactly the move |
| 86 | //! [`Row::current`](crate::screen::Row::current) makes one level down: the app's |
| 87 | //! own pointer at what is showing, said by the thing that knows. |
| 88 | //! |
| 89 | //! The alternative was the renderer comparing a place's address to the request |
| 90 | //! path, which needs the path in [`Serves`](crate::Screen) and gets fuzzy the |
| 91 | //! first time a screen carries its view on the address. goingson's Timer is |
| 92 | //! `/timer?work=25&days=7` and its place is `/timer`. |
| 93 | |
| 94 | use crate; |
| 95 | |
| 96 | /// The affordances the app offers from every screen. |
| 97 | /// |
| 98 | /// Built once by the app and held beside the [`Router`](crate::Router), never |
| 99 | /// per request. That is what "outlives any one screen" means concretely: a |
| 100 | /// request answers with a screen, and this is not part of that answer. |
| 101 | /// |
| 102 | /// Beside the router rather than inside it, decided while building this: a |
| 103 | /// `Router` is a route table, and a key binding is not a route. The two are |
| 104 | /// held together by whatever the host is, which already holds both. Nothing |
| 105 | /// here would break if it moved inside, so this is a tidiness argument rather |
| 106 | /// than a correctness one. |
| 107 | |
| 108 | |
| 109 | /// The keys that work from anywhere. |
| 110 | pub bindings: , |
| 111 | /// The places the app has, in the order it offers them. |
| 112 | /// |
| 113 | /// One level of nesting is what [`Place::within`] is for, and it is what |
| 114 | /// the measured consumer has. A renderer that cannot draw a second level |
| 115 | /// flattens or ignores it, the same rule [`Binding::key`] states for a key |
| 116 | /// one host names and another has never heard of. |
| 117 | pub nav: , |
| 118 | /// What is on the screen whatever screen is showing. |
| 119 | /// |
| 120 | /// Empty is the app that declares none, and a renderer with nothing here |
| 121 | /// draws nothing extra. |
| 122 | /// |
| 123 | /// Plural, and each carries a [`Role`]. Two anonymous panels would be a |
| 124 | /// renderer placing them by declaration order, which is the guess this was |
| 125 | /// a single slot to avoid; the role is what makes the second one sayable |
| 126 | /// instead. |
| 127 | pub panels: , |
| 128 | /// The header band the app puts above every screen, if it has one. |
| 129 | /// |
| 130 | /// [`nav`](Self::nav) is the places and nothing else, and a real header is |
| 131 | /// a brand mark, a search box and those places sitting together. Described |
| 132 | /// as three separate things they are three elements a renderer places by |
| 133 | /// declaration order, and in a browser they are also three elements a |
| 134 | /// stylesheet cannot make into one bar: MNW's narrow-viewport menu is a |
| 135 | /// checkbox styling its siblings, and siblings that are not siblings match |
| 136 | /// nothing. |
| 137 | /// |
| 138 | /// So the band is what says they are one thing. The nav does not move into |
| 139 | /// it -- an app with places and no band still has places -- and a renderer |
| 140 | /// draws [`nav`](Self::nav) *inside* the band when there is one and on its |
| 141 | /// own when there is not. See [`Band`]. |
| 142 | /// |
| 143 | /// `None` is every app that has never had a header, and it draws exactly |
| 144 | /// what it drew before this member existed. |
| 145 | pub band: , |
| 146 | |
| 147 | |
| 148 | /// The header the app puts above every screen. |
| 149 | /// |
| 150 | /// Named slots rather than a `Vec<Node>` body, which is the shape decided in |
| 151 | /// `93f999c3`. A band holding arbitrary content is a band a renderer cannot |
| 152 | /// read: it could not tell a brand from a heading, so it could not draw the |
| 153 | /// brand large on a phone and the nav behind a control, and every host would |
| 154 | /// be back to being handed markup. Chrome is a fixed vocabulary for the same |
| 155 | /// reason [`Role`] is a closed set. |
| 156 | /// |
| 157 | /// # The nav is not a member here |
| 158 | /// |
| 159 | /// It stays [`Chrome::nav`]. Moving it would mean an app with places and no |
| 160 | /// band had nowhere to put them, and the two facts are independent: the places |
| 161 | /// are what the app has, and the band is whether they are drawn in a bar with |
| 162 | /// a wordmark. A renderer draws the nav inside the band when the app declared |
| 163 | /// one. |
| 164 | /// |
| 165 | /// # Order is the renderer's, and it is the same order everywhere |
| 166 | /// |
| 167 | /// Brand, then the disclosure control, then search, then the nav. Not carried |
| 168 | /// here as a sequence, because a band with a configurable order is a band the |
| 169 | /// app is laying out; the reading order is the same on every host and each |
| 170 | /// renderer writes it once. |
| 171 | |
| 172 | |
| 173 | /// The mark the app is called by, if it shows one. |
| 174 | pub brand: , |
| 175 | /// The box the band offers for searching, if it offers one. |
| 176 | /// |
| 177 | /// A [`Field`], so a search box in the header is the same question a search |
| 178 | /// box in a screen is, and no renderer grows a second field emitter for it. |
| 179 | /// [`Field::writes`](crate::Field::writes) is what says where the query |
| 180 | /// goes, which is the whole of what MNW's header form does today. |
| 181 | /// |
| 182 | /// This is the hole [`Panel`] could not fill: a panel is drawn after the |
| 183 | /// screen, and a search box that lands under the content is not a header. |
| 184 | pub search: , |
| 185 | /// Whether the nav is out at all times or behind a control when there is |
| 186 | /// no room for it. |
| 187 | pub disclose: Disclose, |
| 188 | |
| 189 | |
| 190 | /// The mark an app is called by. |
| 191 | /// |
| 192 | /// A name plus one marked run inside it, which is what a wordmark is and what |
| 193 | /// no member here could say before: MNW's is `Makenot.work` with the dot drawn |
| 194 | /// as a graphic. An [`Image`](crate::Image) could not say it -- the mark is a |
| 195 | /// character of the name rather than a picture beside it -- and a |
| 196 | /// [`Node::Text`](crate::Node::Text) could not either, because nothing in it |
| 197 | /// says which part is the mark. |
| 198 | |
| 199 | |
| 200 | /// The whole name, as it is read. |
| 201 | /// |
| 202 | /// Read whole, including the mark. `Makenot.work` is a domain and a reader |
| 203 | /// hearing "Makenot dot work" has heard the name; hiding the mark from a |
| 204 | /// screen reader would leave "Makenotwork", which is not what the app is |
| 205 | /// called. |
| 206 | pub name: String, |
| 207 | /// The run inside [`name`](Self::name) drawn as the graphic mark. |
| 208 | /// |
| 209 | /// The first occurrence, and no more than one: a wordmark has one mark, |
| 210 | /// and a rule that found every "." would mark both dots of a name that had |
| 211 | /// two. A run this name does not contain marks nothing, which is |
| 212 | /// [`Screen::place`](crate::Screen::place)'s bargain again -- the name is |
| 213 | /// the app's and so is this. |
| 214 | pub mark: , |
| 215 | /// What pressing it calls. Home, for every app that has ever had one. |
| 216 | pub action: Action, |
| 217 | |
| 218 | |
| 219 | /// Whether the band's nav is always out. |
| 220 | /// |
| 221 | /// The narrow-viewport question, named rather than hand-rolled. Every app that |
| 222 | /// has a header has answered it, and every one of them answered it in its own |
| 223 | /// stylesheet with its own checkbox, which is markup in the assembly layer |
| 224 | /// doing what a description should have said. |
| 225 | /// |
| 226 | /// It says *whether*, never *how*. A checkbox and a label is one host's answer |
| 227 | /// and a terminal has neither; what a description can honestly state is that |
| 228 | /// the places are worth hiding when there is no room. |
| 229 | |
| 230 | |
| 231 | /// The nav is out whatever the room. The default, and every app with a |
| 232 | /// handful of places. |
| 233 | |
| 234 | Always, |
| 235 | /// The nav goes behind a control when there is not room for it. |
| 236 | /// |
| 237 | /// A renderer with no notion of "not enough room" -- a terminal draws the |
| 238 | /// width it was given -- ignores this and draws the places, which is the |
| 239 | /// same degrading every renderer does with a key it has never heard of. |
| 240 | Narrow, |
| 241 | |
| 242 | |
| 243 | |
| 244 | /// A band with nothing in it, which is the nav in a bar and no more. |
| 245 | |
| 246 | |
| 247 | Selfdefault |
| 248 | |
| 249 | |
| 250 | /// Show this mark, chaining. |
| 251 | |
| 252 | |
| 253 | self.brand = Some; |
| 254 | self |
| 255 | |
| 256 | |
| 257 | /// Offer this box for searching, chaining. |
| 258 | |
| 259 | |
| 260 | self.search = Some; |
| 261 | self |
| 262 | |
| 263 | |
| 264 | /// Whether the nav goes behind a control when there is no room, chaining. |
| 265 | |
| 266 | pub const |
| 267 | self.disclose = disclose; |
| 268 | self |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | /// The name the app is called by, and what pressing it calls. |
| 274 | |
| 275 | Self |
| 276 | name: name.into, |
| 277 | mark: None, |
| 278 | action, |
| 279 | |
| 280 | |
| 281 | |
| 282 | /// Draw this run of the name as the graphic mark, chaining. |
| 283 | /// |
| 284 | /// The first occurrence. See [`mark`](Self::mark). |
| 285 | |
| 286 | |
| 287 | self.mark = Some; |
| 288 | self |
| 289 | |
| 290 | |
| 291 | /// The name in three parts: before the mark, the mark, and after it. |
| 292 | /// |
| 293 | /// Answered here rather than in each renderer, so a webview, a terminal and |
| 294 | /// an egui host cannot disagree about which run is marked. The whole name |
| 295 | /// comes back as the first part when nothing is marked or when the run is |
| 296 | /// not in the name, which is what makes a renderer's drawing one branch |
| 297 | /// rather than three. |
| 298 | |
| 299 | |
| 300 | let Some = self.mark.as_deref.filter else |
| 301 | return ; |
| 302 | ; |
| 303 | match self.name.find |
| 304 | Some => |
| 305 | &self.name, |
| 306 | &self.name, |
| 307 | &self.name, |
| 308 | , |
| 309 | None => , |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | /// A place the app has, and what going there calls. |
| 315 | /// |
| 316 | /// Not a [`Node`] holding a list of controls: a tab bar is a set of addresses |
| 317 | /// with names, and saying so is what lets a webview draw tabs, a terminal draw |
| 318 | /// a tab line and an egui host draw a toolbar without any of them being told |
| 319 | /// which. |
| 320 | |
| 321 | |
| 322 | /// What a screen names to say it is here. |
| 323 | /// |
| 324 | /// An identifier and not the label, because a label is display text: it is |
| 325 | /// renamed, translated, and reworded to fit, and a pointer that broke when |
| 326 | /// somebody improved the wording would be a pointer nobody trusts. |
| 327 | pub key: String, |
| 328 | /// What it is called. |
| 329 | pub label: String, |
| 330 | /// What going there calls. |
| 331 | /// |
| 332 | /// A place that only groups others still has one: pressing goingson's Work |
| 333 | /// tab means its first sub-place, which is what the shipped tab does. A |
| 334 | /// group with nowhere to go would be a control that does nothing. |
| 335 | pub action: Action, |
| 336 | /// The places inside this one. |
| 337 | /// |
| 338 | /// Empty for a flat nav. One level deep: goingson's pills under its tabs |
| 339 | /// are the measured case, and a renderer meeting a third level flattens it |
| 340 | /// rather than inventing a shape for it. |
| 341 | pub within: , |
| 342 | |
| 343 | |
| 344 | /// What a panel is for. |
| 345 | /// |
| 346 | /// A small closed set the renderers agree on, so that an app with two panels |
| 347 | /// is placing them by what they are rather than by which was declared first. |
| 348 | /// |
| 349 | /// Still not where it goes. A stylesheet, a terminal's layout and an egui |
| 350 | /// host's panel all read this and each answers the placement question its own |
| 351 | /// way, which is the arrangement `4453bf82` settled for the clock a toast |
| 352 | /// expires on. |
| 353 | /// |
| 354 | /// # Why there is no `Navigation` |
| 355 | /// |
| 356 | /// Navigation is [`Chrome::nav`], which is a set of addresses rather than |
| 357 | /// content. A `Role::Navigation` panel would be an app hand-building a tab bar |
| 358 | /// out of controls and every renderer drawing it as content, which is the thing |
| 359 | /// the nav member exists to stop. |
| 360 | |
| 361 | |
| 362 | /// Something the app is doing right now, on screen while it lasts. |
| 363 | /// |
| 364 | /// goingson's running-timer band is the measured one: it is there while a |
| 365 | /// timer runs and absent otherwise, and it is about a thing in progress |
| 366 | /// rather than about the app's condition. |
| 367 | |
| 368 | Activity, |
| 369 | /// A standing readout of the app's condition. |
| 370 | /// |
| 371 | /// goingson's sync indicator is the measured one: always present, saying |
| 372 | /// how the app stands rather than what it is doing. |
| 373 | Status, |
| 374 | |
| 375 | |
| 376 | /// Something the app keeps on screen, whatever screen the user is on. |
| 377 | /// |
| 378 | /// goingson's running-timer widget is the measured one: a task name, an elapsed |
| 379 | /// readout, Stop and Discard, present on every screen while a timer runs. |
| 380 | |
| 381 | |
| 382 | /// The address a fresh answer aims at. |
| 383 | /// |
| 384 | /// A [`Slot::id`](crate::Slot) in everything but the slot: a route that has |
| 385 | /// changed what the panel says names this in |
| 386 | /// [`Response::also`](crate::Response::also) or answers a fragment aimed at |
| 387 | /// it, and the renderers put the new contents in. Without an address the |
| 388 | /// panel could only ever say what it said when the app was built, which for |
| 389 | /// a timer is a readout that never moves. |
| 390 | pub id: String, |
| 391 | /// What it holds. |
| 392 | /// |
| 393 | /// A [`Node`], so a panel is described in the vocabulary every screen is |
| 394 | /// described in. Several things in one panel is a |
| 395 | /// [`Node::Region`](crate::Node::Region), which is what a screen's own |
| 396 | /// grouping already is. |
| 397 | pub content: Node, |
| 398 | /// What it is for, which is how a renderer tells two of them apart. |
| 399 | pub role: Role, |
| 400 | |
| 401 | |
| 402 | |
| 403 | /// A place, by the key a screen names it with and the name a person reads. |
| 404 | |
| 405 | Self |
| 406 | key: key.into, |
| 407 | label: label.into, |
| 408 | action, |
| 409 | within: Vecnew, |
| 410 | |
| 411 | |
| 412 | |
| 413 | /// The places inside this one. |
| 414 | |
| 415 | |
| 416 | self.within.extend; |
| 417 | self |
| 418 | |
| 419 | |
| 420 | /// This place or one inside it, under `key`. |
| 421 | /// |
| 422 | /// One level down and no further, which is the depth [`Self::within`] |
| 423 | /// describes. A renderer marking the current place asks the nav rather than |
| 424 | /// walking it itself, so the three of them cannot disagree about how deep |
| 425 | /// the search goes. |
| 426 | |
| 427 | |
| 428 | self.key == key || self.within.iter.any |
| 429 | |
| 430 | |
| 431 | |
| 432 | /// A key that works from every screen, and what it calls. |
| 433 | |
| 434 | |
| 435 | /// The key, as text. |
| 436 | /// |
| 437 | /// Text rather than a modelled chord — "ctrl+k", "?" — for the reason |
| 438 | /// [`Act::key`](crate::Act::key) is: the vocabulary of keys is the host's, |
| 439 | /// and a description that modelled it would be naming one host's keyboard. |
| 440 | /// A renderer that does not know a name ignores it, which is what a webview |
| 441 | /// does with a key a terminal wants. |
| 442 | pub key: String, |
| 443 | /// What a shortcuts list shows for it. |
| 444 | /// |
| 445 | /// The reason this is a struct and not a `(String, Action)` pair. A help |
| 446 | /// overlay that lists the bindings is otherwise a second, hand-written copy |
| 447 | /// of them, free to drift from what the keys actually do. |
| 448 | pub label: String, |
| 449 | /// What pressing it calls. |
| 450 | /// |
| 451 | /// Ordinarily a route answering with [`Response::over`](crate::Response::over), |
| 452 | /// which is what makes the palette an overlay rather than a navigation. It |
| 453 | /// is not required to: a binding that navigates is a binding that navigates. |
| 454 | pub action: Action, |
| 455 | /// The heading this binding sits under in a listing, if the app gave it one. |
| 456 | /// |
| 457 | /// A listing fact and nothing else: no renderer changes what a key *does* |
| 458 | /// because of it. It exists because [`label`](Self::label)'s own argument |
| 459 | /// runs out at length — a table that exists once is worth having, and a |
| 460 | /// flat table of thirteen rows is a wall rather than a reference. |
| 461 | /// audiofiles' shipped shortcuts tab sorts twenty-six rows into seven |
| 462 | /// hand-written arrays, which is the evidence that somebody already |
| 463 | /// thought so before this member existed. |
| 464 | /// |
| 465 | /// Said by the app, never derived. Sorting by key puts "Toggle the sidebar" |
| 466 | /// next to "Show this help" because both start with a letter the app did |
| 467 | /// not choose for that reason, and deriving a group from the address prefix |
| 468 | /// is the same guess wearing a path: `/panels/sidebar` and `/forge` are both |
| 469 | /// Toggles to a reader and are siblings in nothing. |
| 470 | /// |
| 471 | /// Free text rather than a modelled set, for [`key`](Self::key)'s reason. |
| 472 | /// What the groups of an app are is the app's, and a vocabulary that |
| 473 | /// enumerated them would be naming one app's help screen. |
| 474 | /// |
| 475 | /// [`Chrome::grouped`] is how a listing reads it, so the three renderers |
| 476 | /// and every app that draws its own shortcuts table cannot disagree about |
| 477 | /// what order the groups come in. |
| 478 | pub group: , |
| 479 | |
| 480 | |
| 481 | |
| 482 | /// No chrome. What an app that declares none has. |
| 483 | |
| 484 | |
| 485 | Selfdefault |
| 486 | |
| 487 | |
| 488 | /// Offer a place, with whatever places sit inside it. |
| 489 | /// |
| 490 | /// Appends, because a nav is a sequence and the order it is declared in is |
| 491 | /// the order it is offered in. Nothing here refuses a repeated key: two |
| 492 | /// places with one key is an app pointing at itself twice, and the renderer |
| 493 | /// marking both is a truthful drawing of it. |
| 494 | |
| 495 | |
| 496 | self.nav.push; |
| 497 | self |
| 498 | |
| 499 | |
| 500 | /// Put a header band above every screen. |
| 501 | /// |
| 502 | /// Replaces rather than adds, because an app has one header. See |
| 503 | /// [`band`](Self::band). |
| 504 | |
| 505 | |
| 506 | self.band = Some; |
| 507 | self |
| 508 | |
| 509 | |
| 510 | /// Add a key that works from every screen. |
| 511 | |
| 512 | |
| 513 | mut self, |
| 514 | key: impl , |
| 515 | label: impl , |
| 516 | action: Action, |
| 517 | |
| 518 | self.bindings.push |
| 519 | key: key.into, |
| 520 | label: label.into, |
| 521 | action, |
| 522 | group: None, |
| 523 | ; |
| 524 | self |
| 525 | |
| 526 | |
| 527 | /// Add a key that works from every screen, under the heading a listing |
| 528 | /// shows it beneath. |
| 529 | /// |
| 530 | /// A second constructor rather than a fourth argument on |
| 531 | /// [`bind`](Self::bind): every app in the tree binds ungrouped keys and |
| 532 | /// most of them will go on doing it, so the group belongs on the call that |
| 533 | /// wants one. See [`Binding::group`]. |
| 534 | |
| 535 | |
| 536 | mut self, |
| 537 | group: impl , |
| 538 | key: impl , |
| 539 | label: impl , |
| 540 | action: Action, |
| 541 | |
| 542 | self.bindings.push |
| 543 | key: key.into, |
| 544 | label: label.into, |
| 545 | action, |
| 546 | group: Some, |
| 547 | ; |
| 548 | self |
| 549 | |
| 550 | |
| 551 | /// Keep this on screen, whatever screen is showing. |
| 552 | /// |
| 553 | /// Appends since `71aa29b4`. It replaced until then, and the reason was |
| 554 | /// that two anonymous panels would be a renderer deciding which of them is |
| 555 | /// where. [`Role`] is what answers that instead, so a second panel is now a |
| 556 | /// second panel rather than a lost one. |
| 557 | /// |
| 558 | /// Declaring the same id twice is still one panel's worth of address for |
| 559 | /// two elements, and [`Self::replace`] then fills the first. Not refused |
| 560 | /// here: the router does not police an app's own names, and the failure is |
| 561 | /// visible the first time an answer lands. |
| 562 | |
| 563 | |
| 564 | self.panels.push |
| 565 | id: id.into, |
| 566 | content, |
| 567 | role, |
| 568 | ; |
| 569 | self |
| 570 | |
| 571 | |
| 572 | /// Put new contents in the panel, if this names it. |
| 573 | /// |
| 574 | /// The chrome's half of [`Screen::replace`](crate::Screen::replace), and it |
| 575 | /// answers the same way: `false` when nothing here is called `region`, so a |
| 576 | /// renderer can tell an answer aimed at the panel from one aimed at a |
| 577 | /// region that is not there. |
| 578 | |
| 579 | let Some = self.panels.iter_mut.find else |
| 580 | return false; |
| 581 | ; |
| 582 | panel.content = content; |
| 583 | true |
| 584 | |
| 585 | |
| 586 | /// The panel under this id, if the app declared one. |
| 587 | |
| 588 | |
| 589 | self.panels.iter.find |
| 590 | |
| 591 | |
| 592 | /// What the key calls, if anything claimed it. |
| 593 | /// |
| 594 | /// First match wins, so an app that binds one key twice gets the one it |
| 595 | /// declared first rather than an error. Matching is exact: normalising |
| 596 | /// "ctrl+k" against "Ctrl+K" would be this crate deciding what a key name |
| 597 | /// looks like, which is the host's to decide. |
| 598 | |
| 599 | |
| 600 | self.bindings.iter.find |
| 601 | |
| 602 | |
| 603 | /// The bindings, gathered under their headings, for a listing to draw. |
| 604 | /// |
| 605 | /// Here rather than in each renderer and each app, so a shortcuts table |
| 606 | /// drawn in a terminal and one drawn in a browser cannot come out in two |
| 607 | /// different orders from one description. No renderer draws a shortcuts |
| 608 | /// listing on its own — the help screen is a described screen like any |
| 609 | /// other, which is the whole of what [`Binding::label`] bought — so this |
| 610 | /// is the shared half that stops the three of them each writing it. |
| 611 | /// |
| 612 | /// # The order is the app's |
| 613 | /// |
| 614 | /// Groups come in the order they were first bound, and within a group so do |
| 615 | /// the bindings. Not alphabetical: a help screen's headings are a reading |
| 616 | /// order somebody chose, and sorting them would be this crate overruling it |
| 617 | /// for the sake of a rule nobody asked for. |
| 618 | /// |
| 619 | /// Ungrouped bindings come back under [`None`], in one run, wherever the |
| 620 | /// first of them was bound. An app that groups nothing therefore gets one |
| 621 | /// run holding everything in declaration order, which is exactly the flat |
| 622 | /// list every listing already draws. |
| 623 | |
| 624 | |
| 625 | let mut groups: = Vecnew; |
| 626 | for binding in &self.bindings |
| 627 | let group = binding.group.as_deref; |
| 628 | match groups.iter_mut.find |
| 629 | Some => members.push, |
| 630 | None => groups.push, |
| 631 | |
| 632 | |
| 633 | groups |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | |
| 639 | use *; |
| 640 | |
| 641 | |
| 642 | |
| 643 | // The flat list every listing already draws, and the shape an app that |
| 644 | // says nothing new keeps. |
| 645 | let chrome = new |
| 646 | .bind |
| 647 | .bind; |
| 648 | let grouped = chrome.grouped; |
| 649 | assert_eq!; |
| 650 | assert_eq!; |
| 651 | let keys: = grouped.1.iter.map.collect; |
| 652 | assert_eq!; |
| 653 | |
| 654 | |
| 655 | |
| 656 | |
| 657 | // Two groups declared alternately: the run is what gathers them, and |
| 658 | // the heading order is the one the app wrote rather than the alphabet. |
| 659 | let chrome = new |
| 660 | .bind_in |
| 661 | "Toggles", |
| 662 | "s", |
| 663 | "Toggle the sidebar", |
| 664 | post, |
| 665 | |
| 666 | .bind_in |
| 667 | "Bulk", |
| 668 | "f2", |
| 669 | "Rename the selection", |
| 670 | get, |
| 671 | |
| 672 | .bind_in |
| 673 | "Toggles", |
| 674 | "d", |
| 675 | "Toggle the detail panel", |
| 676 | post, |
| 677 | ; |
| 678 | let grouped = chrome.grouped; |
| 679 | assert_eq!; |
| 680 | assert_eq!; |
| 681 | let toggles: = grouped.1.iter.map.collect; |
| 682 | assert_eq!; |
| 683 | assert_eq!; |
| 684 | assert_eq!; |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | let chrome = new.bind_in; |
| 690 | let bound = chrome.bound.expect; |
| 691 | assert_eq!; |
| 692 | assert_eq!; |
| 693 | // And a key nobody grouped is still found the same way. |
| 694 | assert! |
| 695 | new |
| 696 | .bind |
| 697 | .bound |
| 698 | .is_some |
| 699 | ; |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | let chrome = new; |
| 705 | assert!; |
| 706 | assert!; |
| 707 | // The default has to be the old behaviour, or every renderer draws |
| 708 | // something new the moment this member arrives. |
| 709 | assert!; |
| 710 | assert!; |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | let chrome = new.presenting; |
| 716 | let panel = chrome.panel.expect; |
| 717 | assert_eq!; |
| 718 | assert_eq!; |
| 719 | assert_eq!; |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | // It replaced rather than appended until `71aa29b4`, because two |
| 725 | // anonymous panels would be a renderer placing them by declaration |
| 726 | // order. The role is what answers that, so the second one survives now. |
| 727 | let chrome = new |
| 728 | .presenting |
| 729 | .presenting; |
| 730 | assert_eq!; |
| 731 | assert_eq! |
| 732 | chrome.panel.expect.role, |
| 733 | Activity |
| 734 | ; |
| 735 | assert_eq!; |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | // The distinction the member exists for: a renderer reads places and |
| 741 | // draws a tab bar, a sidebar or a tab line without being told which. |
| 742 | let chrome = new |
| 743 | .offering |
| 744 | new, |
| 745 | new, |
| 746 | ] |
| 747 | .offering; |
| 748 | |
| 749 | assert_eq!; |
| 750 | assert_eq!; |
| 751 | // Order is declaration order, because that is the order it is offered. |
| 752 | assert_eq!; |
| 753 | // A group still goes somewhere: pressing it means its first sub-place. |
| 754 | assert_eq!; |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | let deep = new.within |
| 760 | "tasks", |
| 761 | "Tasks", |
| 762 | get, |
| 763 | |
| 764 | .within]; |
| 765 | |
| 766 | assert!; |
| 767 | assert!; |
| 768 | // One level is the depth `within` describes, and the three renderers |
| 769 | // ask this rather than each walking the tree to a depth of its own. |
| 770 | assert!; |
| 771 | |
| 772 | |
| 773 | |
| 774 | |
| 775 | let mut chrome = new |
| 776 | .presenting |
| 777 | .presenting; |
| 778 | |
| 779 | assert!; |
| 780 | assert_eq! |
| 781 | chrome.panel.map, |
| 782 | Some |
| 783 | ; |
| 784 | // And leaves the other alone, which is the whole reason they are two. |
| 785 | assert_eq! |
| 786 | chrome.panel.map, |
| 787 | Some |
| 788 | ; |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | let mut chrome = new.presenting; |
| 794 | assert!; |
| 795 | assert_eq! |
| 796 | chrome.panel.map, |
| 797 | Some |
| 798 | ; |
| 799 | // Not the panel, so the renderer can say so rather than swallowing it. |
| 800 | assert!; |
| 801 | assert!; |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | // The default has to be the old behaviour, or every renderer draws a |
| 807 | // header the moment this member arrives. |
| 808 | assert!; |
| 809 | assert! |
| 810 | new |
| 811 | .offering |
| 812 | .band |
| 813 | .is_none, |
| 814 | "places without a band are still places" |
| 815 | ; |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | let chrome = new |
| 821 | .offering |
| 822 | .banded |
| 823 | new |
| 824 | .branded |
| 825 | .disclosing, |
| 826 | ; |
| 827 | let band = chrome.band.as_ref.expect; |
| 828 | assert_eq!; |
| 829 | // The places did not move into it. An app with a nav and no band still |
| 830 | // has a nav, which is why they are two members. |
| 831 | assert_eq!; |
| 832 | assert!; |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | let brand = new.marking; |
| 838 | assert_eq!; |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | // One answer for all three renderers, so a webview, a terminal and an |
| 844 | // egui host cannot disagree about which run is marked. |
| 845 | let plain = new; |
| 846 | assert_eq!; |
| 847 | // A run the name does not contain marks nothing rather than failing: |
| 848 | // the name is the app's and so is this. |
| 849 | let wrong = new.marking; |
| 850 | assert_eq!; |
| 851 | // And an empty mark is the same as no mark, rather than an empty span |
| 852 | // in front of the name. |
| 853 | let empty = new.marking; |
| 854 | assert_eq!; |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | // A wordmark has one mark. A rule that found every "." would mark both |
| 860 | // dots of a name that had two. |
| 861 | let brand = new.marking; |
| 862 | assert_eq!; |
| 863 | |
| 864 | |
| 865 | |
| 866 | |
| 867 | // The whole of what typing it as a `Field` buys: no renderer grows a |
| 868 | // second field emitter for a box that happens to be in the header. |
| 869 | let field = new; |
| 870 | let band = new.searching; |
| 871 | assert_eq!; |
| 872 | assert_eq!; |
| 873 | |
| 874 | |
| 875 | |
| 876 | |
| 877 | let chrome = new |
| 878 | .bind |
| 879 | .bind; |
| 880 | let found = chrome.bound.expect; |
| 881 | assert_eq!; |
| 882 | assert_eq!; |
| 883 | assert_eq!; |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | let chrome = new.bind; |
| 889 | // Exact match: normalising case or modifier order would be this crate |
| 890 | // deciding what a key name looks like. |
| 891 | assert!; |
| 892 | assert!; |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | let chrome = new |
| 898 | .bind |
| 899 | .bind; |
| 900 | assert_eq!; |
| 901 | |
| 902 | |
| 903 |