Title bar
The window's title bar: its title, its colours, and whether the host draws it or the app does.
import {TitleBar, useTitleBar, useTitleBarMetrics, windowControl} from 'basalt-core';<TitleBar title="Inbox" backgroundColor="#1f1f1f" textColor="#fff" />useTitleBar({title: 'Inbox', backgroundColor: '#1f1f1f'});The component and the hook are the same thing. <TitleBar> renders nothing and
exists because a screen declaring its own header reads better as an element than
as a call.
| option | |
|---|---|
title | the window's title |
style | 'native' or 'hidden' |
backgroundColor | any React Native colour |
textColor | |
borderColor |
Colours are honoured on all three desktops, alpha included on Linux, where a header bar can be translucent in a way a Windows caption cannot.
Requests stack
Exactly as <StatusBar>'s do: the most recently mounted request wins, key by
key, and unmounting one restores what was beneath it. So a screen can colour the
title bar without knowing what the screen behind it asked for, and going back
puts it right.
style: 'hidden'
The system title bar is removed, the app's own content reaches the top of the window, and the host still draws the minimise, maximise and close buttons over the top right corner. What the app then owes is a header of its own, and the marks that say which parts of it drag the window:
const {height, buttonsWidth} = useTitleBarMetrics();
<TitleBar style="hidden" />
<TitleBar.DragRegion style={{height, paddingRight: buttonsWidth}}>
<Text>Inbox</Text>
<TitleBar.NoDragRegion>
<Button title="Compose" />
</TitleBar.NoDragRegion>
</TitleBar.DragRegion>useTitleBarMetrics() answers how much of the window the caption takes:
{height, buttonsWidth, style}, both measurements in layout units. Padding the
header by buttonsWidth is what keeps an app's own controls out from under the
system's.
The caption buttons an app draws for itself act through windowControl:
windowControl.minimize();
windowControl.toggleMaximize();
windowControl.close();All three desktops read the marks and move the window from them, and the rule they apply is the same one: the deepest view under the pointer, then each of its ancestors, and the nearest one marked either way decides. So a label inside a drag region drags without being marked, and a button stays a button once it is marked no-drag.
A press that starts a window drag does not reach your app, which is what the desktop does with a press on its own title bar. On macOS the same press also gets the system's double-click-to-zoom, because the host hands it to AppKit rather than moving the window itself.
On a host that has none
Every call is guarded: on a host with no title bar module, or before it has registered one, a call is ignored and the metrics are all zero. All three desktops do have one, and the guard is what lets the same code run before the host is up without a branch in the app.