DatumHueEnterprise v0.0.24datumhue.com
Contents

Handle Back

Escape, gamepad B, a mouse's back button, a browser's Back and a phone's back gesture all reach your app as one cancel request, and you decide what it does.

What makes a request

InputMakes a request
Escapewhile focus navigation acts in your app, and always in a focused text field
Gamepad Bwhile focus navigation acts in your app
A mouse's back button, nativelywhile focus navigation acts in your app
A browser's Back: its button, a mouse's back button, Alt+Leftalways
A phone's back gesturealways
Escape or B at a focused Continue chipalways

Focus navigation acts while your app shows a widget that can take focus and ui.focus_navigation is on (Keyboard and gamepad). So a canvas game with no widgets keeps Escape and B for itself.

Where a request goes

A request goes to the first of these that can take it:

  1. A dialog of the workstation's own: it presses its Cancel.
  2. A Continue chip the workstation shows (Fit any window size): it goes away.
  3. An open menu, or a popover made with light_dismiss = true: it closes, and focus in it goes back to the menu's button, or to what held focus before the popover took it.
  4. A focused text field: it runs its on_cancel and lets go of focus, so the next request goes past it.
  5. From the focused element outward, the first element with an on_cancel handler, or the first router made with pop_on_cancel = true that has a page to go back to. With nothing focused, the router you moved last goes back first.
  6. The window manager that framed your app, which usually takes the person out of your app.

While a modal popover shows, a request starts inside it: with nothing in it focused, the popover's own on_cancel hears it first. A press outside a light_dismiss popover closes it too, but leaves focus where the press puts it.

In a browser, a request nobody takes lets Back leave the site. When something takes a Back and the next one would leave the site, the workstation shows "Press Back again to leave DatumHue".

Clear a field, then go back a page

search.lualua
local ui = datumhue.ui
local token = datumhue.theme.token

local page = ui.root:panel({ width = 480, gap = 12 })
local status = page:label({
    text = "Escape, gamepad B or Back goes back",
    color = token("text_secondary"),
})
local search
search = page:text_input({
    placeholder = "Search fruit",
    on_cancel = function(e)
        search.text = ""
        status.text = "Search cleared by " .. e.source
    end,
})
local router = page:panel({ padding = 0 }):router({
    pop_on_cancel = true,
})

local fruit = router:route(function(p, params)
    p:label({ text = params.name, font_size = "1.5rem" })
end, { title = "Fruit" })

local list = router:route(function(p)
    p:update({ gap = 8 })
    for _, name in ipairs({ "Apple", "Pear", "Plum" }) do
        p:button({
            text = name,
            on_click = function()
                router:push(fruit, { name = name })
            end,
        })
    end
end, { title = "All fruit" })
router:show(list)

In this example: datumhue.ui datumhue.theme.token datumhue.ui.root UiElement:panel UiElement:label UiElement:text_input UiElement.text UiElement:router Router:route UiElement:button Router:push Router:show

  • Escape in the search field runs its on_cancel, which empties it. The field lets go of focus, so the next Escape goes on.
  • e.source names what made the request: the keyboard, a gamepad, a mouse, or the system's Back.
  • Open a fruit, and Escape, B or Back goes back to the list, as Router:pop does. The page's on_leave still has its say.
  • At the list the router has nothing to go back to, so the request goes on to what framed your app.

Take Back for yourself

UiElement:on_cancel makes an element take every request that reaches it: one made while focus is on it or inside it, or, on ui.root, one made with nothing focused. The handler runs once the request is decided. Take only the requests you undo something for: a handler on ui.root keeps Back from ever leaving your app.

Back in a window manager

A request an app leaves reaches the frame its window manager made with wm.wrap_app. Set UiElement:on_cancel on that frame to decide what Back means there, such as showing the workstation. A frame without one hands the request to the window manager's own widgets, and so on up to the root app. wm.send_cancel sends an app a Back, as a phone's back gesture would, for a window manager's own Back button.

See also

Reference used on this page: datumhue.ui datumhue.theme.token datumhue.ui.root UiElement:panel UiElement:label UiElement:text_input UiElement.text UiElement:router Router:route UiElement:button Router:push Router:show datumhue.ui.focus_navigation Router:pop UiElement:on_cancel datumhue.input.is_key_pressed datumhue.wm.wrap_app datumhue.wm.send_cancel ui.CancelSource

datumhue.com

(c) 2026 Shuusei AB. Quote excerpts of this manual, with attribution to DatumHue, in your own documentation, tutorials, course materials, reviews, and other writing or video. Republishing it in whole or in substantial part needs written permission: support@datumhue.com.

Victor Mono is licensed under the SIL Open Font License 1.1
Copyright (c) 2024, Rune Bjørnerås (https://github.com/rubjo)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Try

    ↑↓ selectEnter openTab filter

    Settings

    Theme
    Text
    Print

    Keyboard shortcuts

    / or Ctrl KSearch
    ↑ ↓ EnterPick a result
    TabNext result filter
    j kNext or previous entry
    [ ]Previous or next page
    yCopy a link to the current entry
    ?These shortcuts
    EscClose

    On this page