mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 06:53:19 -10:00
FC0a: ui/widgets/virtual_keyboard ports at 0.99371, on raea/feathers (bevy_feathers) and EditableText. raea/feathers carries feathers' dark theme (its palette, semantic colours, surface-level overrides and 150 token assignments, generated from dark_theme.rs and tokens.rs; with no UiTheme every token is FUCHSIA, as Bevy's empty ThemeProps), FeathersButton, VirtualKeyboard and ThemedText: a widget's font and text colour reach only a ThemedText, as feathers' Propagate is filtered With<ThemedText>, so the keyboard's plain Text keys keep Bevy's default font, as Bevy draws them. Feathers' own Fira Sans (four faces) and Fira Mono Medium are bundled whole in core/fonts, and its fonts name them by family. EditableText measures as TextInputMeasure (visible_lines of line height, rounded up; visible_width in ch, the advance of 0) and draws parley's caret, cursor_width of the font size wide, for the first half of each blink period while it has focus. Oklcha gains lighter, darker and with_alpha. 94 of 98 ported examples pass
This commit is contained in:
1 parent
00327576cc
commit
c4e528f56a
30 files changed
+1073
-9
No files matched your search
@@ -97,3 +97,4 @@ ui/widgets/headless_tabs
|
||||
ui/widgets/tab_navigation
|
||||
ui/widgets/viewport_node
|
||||
ui/widgets/vertical_slider
|
||||
ui/widgets/virtual_keyboard
|
||||
@@ -96,3 +96,4 @@ ui/widgets/headless_tabs - 10
|
||||
ui/widgets/tab_navigation - 10
|
||||
ui/widgets/viewport_node - 10
|
||||
ui/widgets/vertical_slider - 10
|
||||
ui/widgets/virtual_keyboard - 10
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,7 +2,9 @@
|
||||
Feature: Bundled fonts for deterministic font aliasing
|
||||
This folder holds the bundled fonts used for deterministic font aliasing (see
|
||||
src/fonts.rs). They are Fontsource latin subsets
|
||||
(`packages/core/src/fonts/fontData.generated.ts`), extracted to woff2 files.
|
||||
(`packages/core/src/fonts/fontData.generated.ts`), extracted to woff2 files. Fira Sans (Regular, Bold, Italic,
|
||||
Bold Italic) and Fira Mono Medium are bevy_feathers 0.20.0's own files (src/assets/fonts), whole, as woff2: feathers'
|
||||
fonts::REGULAR and the rest, which raea/feathers names by family and weight.
|
||||
|
||||
Each family is licensed under the SIL Open Font License 1.1, and the license texts are in licenses/.
|
||||
|
||||
|
||||
+36
-1
@@ -292,5 +292,40 @@
|
||||
"weight": "900",
|
||||
"style": "normal",
|
||||
"file": "poppins-900-normal.woff2"
|
||||
},
|
||||
{
|
||||
"package": "bevy_feathers",
|
||||
"family": "fira-sans",
|
||||
"weight": "400",
|
||||
"style": "normal",
|
||||
"file": "fira-sans-400-normal.woff2"
|
||||
},
|
||||
{
|
||||
"package": "bevy_feathers",
|
||||
"family": "fira-sans",
|
||||
"weight": "700",
|
||||
"style": "normal",
|
||||
"file": "fira-sans-700-normal.woff2"
|
||||
},
|
||||
{
|
||||
"package": "bevy_feathers",
|
||||
"family": "fira-sans",
|
||||
"weight": "400",
|
||||
"style": "italic",
|
||||
"file": "fira-sans-400-italic.woff2"
|
||||
},
|
||||
{
|
||||
"package": "bevy_feathers",
|
||||
"family": "fira-sans",
|
||||
"weight": "700",
|
||||
"style": "italic",
|
||||
"file": "fira-sans-700-italic.woff2"
|
||||
},
|
||||
{
|
||||
"package": "bevy_feathers",
|
||||
"family": "fira-mono",
|
||||
"weight": "500",
|
||||
"style": "normal",
|
||||
"file": "fira-mono-500-normal.woff2"
|
||||
}
|
||||
]
|
||||
]
|
||||
@@ -0,0 +1,93 @@
|
||||
Digitized data copyright (c) 2012-2015, The Mozilla Foundation and Telefonica S.A.
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,93 @@
|
||||
Copyright (c) 2012-2015, The Mozilla Foundation and Telefonica S.A.
|
||||
|
||||
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:
|
||||
https://openfontlicense.org
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
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.
|
||||
@@ -1,5 +1,5 @@
|
||||
//! raea's bundled faces: the Fontsource latin subsets in this folder (index.json), and the aliases that map a requested
|
||||
//! family onto one (a deterministic font set: Helvetica, Arial and SF Pro draw as Inter, Times and Georgia as EB
|
||||
//! raea's bundled faces: the Fontsource latin subsets in this folder (index.json) and bevy_feathers' Fira faces
|
||||
//! (whole), and the aliases that map a requested family onto one (a deterministic font set: Helvetica, Arial and SF Pro draw as Inter, Times and Georgia as EB
|
||||
//! Garamond, Courier and Menlo as JetBrains Mono, ...), so a render looks the same on every machine. Each family is
|
||||
//! under the SIL Open Font License 1.1 (licenses/).
|
||||
|
||||
@@ -10,7 +10,7 @@ pub const ALIASES: &[(&str, &str)] = &[
|
||||
("space mono", "space-mono"), ("ibm plex mono", "ibm-plex-mono"), ("jetbrains mono", "jetbrains-mono"),
|
||||
("eb garamond", "eb-garamond"), ("playfair display", "playfair-display"), ("source code pro", "source-code-pro"),
|
||||
("noto sans jp", "noto-sans-jp"), ("roboto", "roboto"), ("open sans", "open-sans"), ("lato", "lato"),
|
||||
("poppins", "poppins"),
|
||||
("poppins", "poppins"), ("fira sans", "fira-sans"), ("fira mono", "fira-mono"),
|
||||
("helvetica neue", "inter"), ("helvetica", "inter"), ("arial", "inter"), ("helvetica bold", "inter"),
|
||||
("futura", "montserrat"), ("din alternate", "montserrat"), ("arial black", "montserrat"),
|
||||
("bebas neue", "league-gothic"), ("courier new", "jetbrains-mono"), ("courier", "jetbrains-mono"),
|
||||
|
||||
+2
-1
@@ -4,7 +4,7 @@ Bevy v0.20.0's examples against their raea TSX ports (docs/control.feature FC0a)
|
||||
don't edit. An example passes when every probed frame passes pixels (SSIM 0.98 and no 32 px tile off by more than 24 of 255) and cost (batch keys and
|
||||
frame time at most 1.25x the example's). Wall time is one machine's, measured in the same run.
|
||||
|
||||
Examples: **438**, ported **97**, passing **93**, excluded **16** (docs/bevy-parity/excluded.tsv), left **329**.
|
||||
Examples: **438**, ported **98**, passing **94**, excluded **16** (docs/bevy-parity/excluded.tsv), left **328**.
|
||||
|
||||
raea's frame ms is its update's plus the time React takes to step a frame for its 3D (step), which the example
|
||||
doesn't pay.
|
||||
@@ -153,6 +153,7 @@ doesn't pay.
|
||||
| ui/widgets/tab_navigation | 10 | 0.997861 | 4 | 0 / 0 | 500 / 493 | 5 / 7 | 1 / 1 | 40.81 / 2.326 = 2.326 + 0 | yes | |
|
||||
| ui/widgets/viewport_node | 10 | 0.999871 | 0 | 1 / 1 | 446 / 498 | 6 / 8 | 2 / 2 | 38.34 / 2.039 = 2.039 + 0 | yes | |
|
||||
| ui/widgets/vertical_slider | 10 | 0.999004 | 11 | 0 / 0 | 459 / 493 | 5 / 7 | 1 / 1 | 37.247 / 1.764 = 1.764 + 0 | yes | |
|
||||
| ui/widgets/virtual_keyboard | 10 | 0.993705 | 13 | 0 / 0 | 646 / 493 | 5 / 7 | 1 / 1 | 40.167 / 1.441 = 1.441 + 0 | yes | |
|
||||
|
||||
## Excluded
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Bevy v0.20.0 examples/ui/widgets/virtual_keyboard.rs in raea's TSX (docs/control.feature FC0a): under feathers' dark
|
||||
// UiTheme, an absolute full-width row (25 px padding, centred) holding an EditableText 80% wide with a 5 px white
|
||||
// border, 5 px padding and 10 px corners, five 25 px lines high, unwrapped, with AutoFocus, so its white caret (5 px,
|
||||
// cursor_width 0.2 of 25 px) shows at its start for the first half second; and, pinned to the bottom, a navy panel
|
||||
// (5 px white border, 5 px padding and rows, 10 px corners, 25 px margin) of a "virtual keyboard" Text over a
|
||||
// VirtualKeyboard of six rows of keys. Each key is a FeathersButton (24 px high, 8 px sides, 4 px corners, BUTTON_BG)
|
||||
// growing to share its row, its caption a plain Text, which feathers' font doesn't reach (it propagates only to a
|
||||
// ThemedText): Bevy's default font, 20 px white. Keys and typing work only under input. Bevy's Camera2d over the
|
||||
// default clear colour is the layered <Canvas3D>, in Bevy's default 1280 x 720 window.
|
||||
import { AbsoluteFill, Composition, registerRoot } from "raea";
|
||||
import { Canvas3D } from "raea/3d";
|
||||
import { BorderRadius, EditableText, Node, Text, UiRect, percent, px } from "raea/ui";
|
||||
import { UiTheme, VirtualKeyboard, create_dark_theme } from "raea/feathers";
|
||||
import { Srgba } from "raea/color";
|
||||
|
||||
const WHITE = new Srgba(1, 1, 1);
|
||||
const NAVY = new Srgba(0, 0, 0.5019608);
|
||||
|
||||
const KEYS = [
|
||||
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ".", ","],
|
||||
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
||||
["A", "S", "D", "F", "G", "H", "J", "K", "L", "'"],
|
||||
["Z", "X", "C", "V", "B", "N", "M", "-", "/"],
|
||||
["space", "enter", "backspace"],
|
||||
["left", "right", "up", "down", "home", "end"],
|
||||
];
|
||||
|
||||
function Shot() {
|
||||
return (
|
||||
<AbsoluteFill>
|
||||
<Canvas3D layered clearColor="rgb(43, 44, 47)" />
|
||||
<UiTheme theme={create_dark_theme()}>
|
||||
<Node width={percent(100)} padding={UiRect.all(px(25))} position_type="Absolute" align_items="Center" justify_content="Center">
|
||||
<EditableText width={percent(80)} border={UiRect.all(px(5))} padding={UiRect.all(px(5))} flex_grow={0} border_radius={BorderRadius.all(px(10))} border_color={WHITE} visible_lines={5} allow_newlines linebreak="NoWrap" cursor_style={{ color: WHITE }} font_size={{ Px: 25 }} auto_focus />
|
||||
</Node>
|
||||
<Node width={percent(100)} bottom={px(0)} flex_direction="Column" position_type="Absolute" align_items="Center" justify_content="End">
|
||||
<Node flex_direction="Column" border={UiRect.all(px(5))} row_gap={px(5)} padding={UiRect.all(px(5))} align_items="Center" margin={UiRect.all(px(25))} border_radius={BorderRadius.all(px(10))} background_color={NAVY} border_color={WHITE}>
|
||||
<Text>virtual keyboard</Text>
|
||||
<VirtualKeyboard keys={KEYS} />
|
||||
</Node>
|
||||
</Node>
|
||||
</UiTheme>
|
||||
</AbsoluteFill>
|
||||
);
|
||||
}
|
||||
|
||||
registerRoot(() => <Composition id="main" component={Shot} durationInFrames={11} fps={60} width={1280} height={720} />);
|
||||
@@ -0,0 +1,74 @@
|
||||
// docs/control.feature FC0a: bevy_feathers' theme and controls (ui/widgets/virtual_keyboard), and bevy_text's
|
||||
// EditableText on a Node. A feathers widget looks its colours up in the UiTheme around it (FUCHSIA with none, as
|
||||
// Bevy's empty ThemeProps gives), and its font and text colour reach a ThemedText only, as Propagate With<ThemedText>.
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { EditableText, Text } from "raea/ui";
|
||||
import { FeathersButton, ThemedText, UiTheme, VirtualKeyboard, context_color, create_dark_theme, palette, tokens, to_border_radius } from "raea/feathers";
|
||||
import { Oklcha } from "raea/color";
|
||||
import { renderFrame } from "../src/test";
|
||||
|
||||
const html = (el: React.ReactElement, frame = 0) => renderFrame(el, { frame, width: 320, height: 240, fps: 60, durationInFrames: 120 });
|
||||
const hex = (c: { red: number; green: number; blue: number }) => [c.red, c.green, c.blue].map((v) => Math.round(v * 255));
|
||||
|
||||
describe("the dark theme: each token's semantic colour from the palette, a surface level's overrides first", () => {
|
||||
test("a button's background is FILL_SOLID_DEFAULT, GRAY_3 (srgb 70 71 77), and Highest's override lightens it", () => {
|
||||
const dark = create_dark_theme();
|
||||
expect(hex(context_color(dark, tokens.BUTTON_BG))).toEqual([70, 71, 77]);
|
||||
expect(hex(context_color(dark, tokens.BUTTON_BG, "Highest"))).toEqual(hex(palette.GRAY_3.lighter(0.05).to_srgba()));
|
||||
expect(hex(context_color(dark, tokens.BUTTON_TEXT))).toEqual([255, 255, 255]);
|
||||
});
|
||||
test("a theme with no colour for a token gives FUCHSIA", () => {
|
||||
expect(hex(context_color({ semantic_base: {}, semantic_overrides: {}, token_assignments: {} }, tokens.BUTTON_BG))).toEqual([255, 0, 255]);
|
||||
});
|
||||
test("Oklcha's lighter and darker move the lightness within 0..1, as Bevy's Luminance", () => {
|
||||
expect(new Oklcha(0.98, 0.1, 30).lighter(0.05).lightness).toBe(1);
|
||||
expect(new Oklcha(0.02, 0.1, 30).darker(0.05).lightness).toBe(0);
|
||||
expect(new Oklcha(0.5, 0.1, 30).with_alpha(0.25).alpha).toBe(0.25);
|
||||
});
|
||||
});
|
||||
|
||||
describe("FeathersButton and VirtualKeyboard", () => {
|
||||
test("a button is a 24 px row, 8 px each side, 4 px corners, on the theme's colour; with no UiTheme, FUCHSIA", () => {
|
||||
const out = html(<UiTheme theme={create_dark_theme()}><FeathersButton><Text>a</Text></FeathersButton></UiTheme>);
|
||||
expect(out).toMatch(/height:\s*24px/);
|
||||
expect(out).toMatch(/padding-left:\s*8px|padding:\s*0px 8px/);
|
||||
expect(out).toContain("rgba(70, 71, 77, 1)");
|
||||
expect(html(<FeathersButton />)).toContain("rgba(255, 0, 255, 1)");
|
||||
});
|
||||
test("a ThemedText takes feathers' Fira Sans 14 px; a plain Text keeps Bevy's default font", () => {
|
||||
const themed = html(<UiTheme theme={create_dark_theme()}><FeathersButton><ThemedText>a</ThemedText></FeathersButton></UiTheme>);
|
||||
expect(themed).toContain("Fira Sans");
|
||||
expect(themed).toMatch(/font-size:\s*14px/);
|
||||
const plain = html(<UiTheme theme={create_dark_theme()}><FeathersButton><Text>a</Text></FeathersButton></UiTheme>);
|
||||
expect(plain).not.toContain("Fira Sans");
|
||||
expect(plain).toMatch(/font-size:\s*20px/);
|
||||
});
|
||||
test("RoundedCorners rounds the corners named", () => {
|
||||
expect(to_border_radius("Top", 4)).toEqual({ top_left: "4px", top_right: "4px", bottom_right: "0px", bottom_left: "0px" });
|
||||
expect(() => to_border_radius("Middle" as never, 4)).toThrow(/RoundedCorners/);
|
||||
});
|
||||
test("a keyboard is a button a key, in its rows", () => {
|
||||
const out = html(<VirtualKeyboard keys={[["Q", "W"], ["space"]]} />);
|
||||
for (const k of ["Q", "W", "space"]) expect(out).toContain(`>${k}<`);
|
||||
expect(() => html(<VirtualKeyboard keys={["Q"] as never} />)).toThrow(/rows of strings/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("EditableText", () => {
|
||||
test("visible_lines lines of its line height high, rounded up, and visible_width in 0s", () => {
|
||||
expect(html(<EditableText font_size={{ Px: 25 }} visible_lines={5} />)).toMatch(/height:\s*150px/);
|
||||
expect(html(<EditableText font_size={{ Px: 15 }} visible_lines={1} />)).toMatch(/height:\s*18px/);
|
||||
expect(html(<EditableText visible_width={12} />)).toMatch(/width:\s*12ch/);
|
||||
});
|
||||
test("with focus, its caret is cursor_width of the font size wide, shown the first half of each blink period", () => {
|
||||
const at = (frame: number) => html(<EditableText font_size={{ Px: 25 }} auto_focus cursor_style={{ color: "#ffffff" }}>hi</EditableText>, frame);
|
||||
expect(at(10)).toContain("data-raea-caret");
|
||||
expect(at(10)).toMatch(/width:\s*5px/);
|
||||
expect(at(40)).not.toContain("data-raea-caret");
|
||||
expect(at(70)).toContain("data-raea-caret");
|
||||
expect(html(<EditableText>hi</EditableText>)).not.toContain("data-raea-caret");
|
||||
});
|
||||
test("refuses a text that isn't a string, or visible_lines that aren't above 0", () => {
|
||||
expect(() => html(<EditableText visible_lines={0} />)).toThrow(/visible_lines/);
|
||||
});
|
||||
});
|
||||
@@ -10,7 +10,7 @@ const paths = (await Bun.file(join(ROOT, "../tsconfig.base.json")).json()).compi
|
||||
const fileOf = (sub: string) => Bun.resolveSync(`raea/${sub}`, ROOT);
|
||||
|
||||
// Bevy's crates (bevy_ prefix dropped) and raea's own subjects; anything else is an older topic subpath (S7 M5)
|
||||
const BEVY = ["app", "asset", "time", "state", "input", "transform", "math", "color", "mesh", "image", "camera", "light", "pbr", "post_process", "sprite", "text", "ui", "animation", "audio", "picking", "gizmos", "scene", "remote", "dev_tools", "window", "ecs", "prelude"];
|
||||
const BEVY = ["app", "asset", "time", "state", "input", "transform", "math", "color", "mesh", "image", "camera", "light", "pbr", "post_process", "sprite", "text", "ui", "animation", "audio", "picking", "gizmos", "scene", "remote", "dev_tools", "feathers", "window", "ecs", "prelude"];
|
||||
const RAEA = ["video", "physics", "character", "room", "ml"];
|
||||
// modules the guides name whose file isn't sdk/raea/src/<name> (S1f's trim dropped raea/bevy-own for a while)
|
||||
const NAMED = ["bevy-own", "glb", "views", "modelling", "arena", "window", "screen", "asset"];
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// raea/feathers (bevy_feathers, docs/control.feature FC0a): Bevy's widget set, its dark theme and its fonts, drawn by
|
||||
// the page.
|
||||
export { tokens, palette, create_dark_theme, UiTheme, ThemeContext, ThemedText, context_color, useThemeColor, fonts, size, FeathersButton, VirtualKeyboard, to_border_radius } from "@raea/render/feathers";
|
||||
export type { ThemeToken, ThemeProps, SurfaceLevel, ButtonVariant, RoundedCorners, FeathersButtonProps } from "@raea/render/feathers";
|
||||
@@ -14,3 +14,5 @@ export { FontFeatureTag, FontWidth } from "@raea/render/bevy3d";
|
||||
export { GlobalUiDebugOptions, type UiDebugOptions } from "@raea/render/bevy3d";
|
||||
export type { IgnoreScroll } from "@raea/render/bevy3d";
|
||||
export { Scrollbar, ScrollbarThumb, type ScrollbarProps, type ScrollbarThumbProps, type ControlOrientation } from "@raea/render/bevy3d";
|
||||
// bevy_text's EditableText on a Node, its caret drawn while it has focus (docs/control.feature FC0a)
|
||||
export { EditableText, type EditableTextProps, type TextCursorStyle } from "@raea/render/bevy3d";
|
||||
@@ -20,7 +20,8 @@
|
||||
"./three": "./src/three.tsx",
|
||||
"./plugin": "./src/plugin.ts",
|
||||
"./screen": "./src/screen.tsx",
|
||||
"./bevy-own": "./src/bevy-own.gen.tsx"
|
||||
"./bevy-own": "./src/bevy-own.gen.tsx",
|
||||
"./feathers": "./src/feathers.ts"
|
||||
},
|
||||
"raea": {
|
||||
"plugins": {
|
||||
|
||||
@@ -30,6 +30,7 @@ export { Lightmap, type LightmapProps } from "./bevy3d/lightmap";
|
||||
// bevy_ui's Node, Text and TextSpan, and their values, drawn by the page
|
||||
export { Node, GhostNode, Text, TextSpan, TextShadow, Text2d, UiScale, Viewport, UiTargetCamera, FontVariationTag, type NodeProps, type TextProps, type TextStyleProps, type TextRunProps, type Text2dProps } from "./bevy3d/ui";
|
||||
export { UiTexture, targetImage } from "./bevy3d/ui-texture";
|
||||
export { EditableText, type EditableTextProps, type TextCursorStyle } from "./bevy3d/ui-edit";
|
||||
export { ImageNode, InlineImage, ImagePlugin, TextureAtlasLayout, type TextureSlicer, type SliceScaleMode, type ImageNodeProps } from "./bevy3d/ui-image";
|
||||
export { px, percent, vw, vh, vmin, vmax, auto, UiRect, BorderRadius, CornerRadius, Overflow, OverflowClipMargin, type Val } from "./bevy3d/ui-val";
|
||||
export { LinearGradient, RadialGradient, ConicGradient, ColorStop, AngularColorStop, UiPosition, type Gradient, type RadialGradientShape, type InterpolationColorSpace } from "./bevy3d/ui-gradient";
|
||||
|
||||
@@ -58,6 +58,18 @@ export class Oklcha {
|
||||
mix(o: Oklcha, t: number): Oklcha {
|
||||
return new Oklcha(lerp(this.lightness, o.lightness, t), lerp(this.chroma, o.chroma, t), lerpHue(this.hue, o.hue, t), lerp(this.alpha, o.alpha, t));
|
||||
}
|
||||
/** Bevy's Luminance::lighter: the lightness raised by `amount`, at most 1 */
|
||||
lighter(amount: number): Oklcha {
|
||||
return new Oklcha(Math.min(f(this.lightness + amount), 1), this.chroma, this.hue, this.alpha);
|
||||
}
|
||||
/** Bevy's Luminance::darker: the lightness lowered by `amount`, at least 0 */
|
||||
darker(amount: number): Oklcha {
|
||||
return new Oklcha(Math.max(f(this.lightness - amount), 0), this.chroma, this.hue, this.alpha);
|
||||
}
|
||||
/** Bevy's Alpha::with_alpha */
|
||||
with_alpha(alpha: number): Oklcha {
|
||||
return new Oklcha(this.lightness, this.chroma, this.hue, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
/** Bevy's Xyza: CIE 1931 XYZ (D65, as linear sRGB's). */
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// bevy_feathers' constants.rs (docs/control.feature FC0a): its fonts and sizes. Its fonts are its own embedded files,
|
||||
// which raea bundles whole (core/fonts: Fira Sans and Fira Mono, as bevy_feathers 0.20.0 ships them), so each is
|
||||
// named by its family here: Bevy resolves a font handle to its family too, and the TextFont's weight and style pick
|
||||
// the face.
|
||||
import { FontSource } from "../ui-font";
|
||||
import { px } from "../ui-val";
|
||||
|
||||
/** bevy_feathers' fonts, by family (the face by the TextFont's weight and style). @bevy bevy_feathers::constants::fonts */
|
||||
export const fonts = {
|
||||
REGULAR: FontSource.family("Fira Sans"),
|
||||
ITALIC: FontSource.family("Fira Sans"),
|
||||
BOLD: FontSource.family("Fira Sans"),
|
||||
BOLD_ITALIC: FontSource.family("Fira Sans"),
|
||||
MONO: FontSource.family("Fira Mono"),
|
||||
};
|
||||
|
||||
/** bevy_feathers' sizes. @bevy bevy_feathers::constants::size */
|
||||
export const size = {
|
||||
ROW_HEIGHT: px(24),
|
||||
CHECKBOX_SIZE: px(18),
|
||||
HEADER_HEIGHT: px(30),
|
||||
RADIO_SIZE: px(18),
|
||||
TOGGLE_WIDTH: px(32),
|
||||
TOGGLE_HEIGHT: px(18),
|
||||
HEADER_FONT: { Px: 16 },
|
||||
MEDIUM_FONT: { Px: 14 },
|
||||
COMPACT_FONT: { Px: 13 },
|
||||
SMALL_FONT: { Px: 12 },
|
||||
EXTRA_SMALL_FONT: { Px: 11 },
|
||||
} as const;
|
||||
@@ -0,0 +1,87 @@
|
||||
// bevy_feathers' controls (docs/control.feature FC0a): button.rs's FeathersButton and virtual_keyboard.rs's
|
||||
// VirtualKeyboard, as Bevy spawns them, coloured from the UiTheme around them. update_button_styles picks a button's
|
||||
// background by its variant and state; a render has no pointer, so a button is hovered or pressed only under input,
|
||||
// and disabled when InteractionDisabled is given. FocusIndicator's ring is drawn only on the focused entity, and no
|
||||
// button here takes focus.
|
||||
import type { ReactNode } from "react";
|
||||
import { Node, Text, type NodeProps } from "../ui";
|
||||
import { BorderRadius, UiRect, px } from "../ui-val";
|
||||
import { fonts, size } from "./constants";
|
||||
import { InheritableText, useThemeColor } from "./theme";
|
||||
import { tokens } from "./tokens";
|
||||
|
||||
/** a button's look. @bevy bevy_feathers::controls::ButtonVariant */
|
||||
export type ButtonVariant = "Normal" | "Primary" | "Plain";
|
||||
|
||||
/** which corners are rounded. @bevy bevy_feathers::rounded_corners::RoundedCorners */
|
||||
export type RoundedCorners = "None" | "All" | "TopLeft" | "TopRight" | "BottomRight" | "BottomLeft" | "Top" | "Right" | "Bottom" | "Left";
|
||||
|
||||
/** RoundedCorners::to_border_radius: `radius` px on the corners named, 0 on the rest */
|
||||
export function to_border_radius(corners: RoundedCorners, radius: number): BorderRadius {
|
||||
const r = px(radius), z = px(0);
|
||||
const on = (tl: boolean, tr: boolean, br: boolean, bl: boolean) => BorderRadius.new(tl ? r : z, tr ? r : z, br ? r : z, bl ? r : z);
|
||||
const table: Record<RoundedCorners, BorderRadius> = {
|
||||
None: on(false, false, false, false), All: on(true, true, true, true),
|
||||
TopLeft: on(true, false, false, false), TopRight: on(false, true, false, false), BottomRight: on(false, false, true, false), BottomLeft: on(false, false, false, true),
|
||||
Top: on(true, true, false, false), Right: on(false, true, true, false), Bottom: on(false, false, true, true), Left: on(true, false, false, true),
|
||||
};
|
||||
if (!(corners in table)) throw new TypeError(`FeathersButton: corners is a RoundedCorners (All, Top, Left, ...), got ${JSON.stringify(corners)}`);
|
||||
return table[corners];
|
||||
}
|
||||
|
||||
const BG = {
|
||||
Normal: [tokens.BUTTON_BG, tokens.BUTTON_BG_DISABLED],
|
||||
Primary: [tokens.BUTTON_PRIMARY_BG, tokens.BUTTON_PRIMARY_BG_DISABLED],
|
||||
Plain: [tokens.BUTTON_PLAIN_BG, tokens.BUTTON_PLAIN_BG_DISABLED],
|
||||
} as const;
|
||||
const TEXT = {
|
||||
Normal: [tokens.BUTTON_TEXT, tokens.BUTTON_TEXT_DISABLED],
|
||||
Primary: [tokens.BUTTON_PRIMARY_TEXT, tokens.BUTTON_PRIMARY_TEXT_DISABLED],
|
||||
Plain: [tokens.BUTTON_TEXT, tokens.BUTTON_TEXT_DISABLED],
|
||||
} as const;
|
||||
|
||||
export interface FeathersButtonProps extends NodeProps {
|
||||
/** ButtonVariant (Normal by default) */
|
||||
variant?: ButtonVariant;
|
||||
/** RoundedCorners (All by default), each 4 px */
|
||||
corners?: RoundedCorners;
|
||||
/** InteractionDisabled */
|
||||
disabled?: boolean;
|
||||
/** the caption: a <ThemedText> takes the button's font (Fira Sans 14 px) and text colour, a plain <Text> keeps Bevy's */
|
||||
children?: ReactNode;
|
||||
}
|
||||
|
||||
/** A feathers button: a ROW_HEIGHT node, 8 px each side, its corners 4 px, on the theme's button colour; its own Node
|
||||
* fields (flex_grow, a min_width) patch the button's, as a bsn! patch does. @bevy bevy_feathers::controls::FeathersButton */
|
||||
export function FeathersButton({ variant = "Normal", corners = "All", disabled = false, children, ...node }: FeathersButtonProps) {
|
||||
if (!(variant in BG)) throw new TypeError(`FeathersButton: variant is Normal, Primary or Plain, got ${JSON.stringify(variant)}`);
|
||||
const background = useThemeColor(BG[variant][disabled ? 1 : 0]);
|
||||
const color = useThemeColor(TEXT[variant][disabled ? 1 : 0]);
|
||||
return (
|
||||
<Node height={size.ROW_HEIGHT} justify_content="Center" align_items="Center" padding={UiRect.horizontal(px(8))} border_radius={to_border_radius(corners, 4)} background_color={background} {...node}>
|
||||
<InheritableText font={fonts.REGULAR} font_size={size.MEDIUM_FONT} weight={400} color={color}>
|
||||
{children}
|
||||
</InheritableText>
|
||||
</Node>
|
||||
);
|
||||
}
|
||||
|
||||
/** A grid of FeathersButtons, one row of keys a row (4 px apart both ways), each key's caption a plain Text (Bevy's
|
||||
* default font, 20 px white: feathers' font reaches only a ThemedText), each key growing to share its row.
|
||||
* VirtualKeyPressed fires on a key under input. @bevy bevy_feathers::controls::VirtualKeyboard */
|
||||
export function VirtualKeyboard({ keys }: { keys: string[][] }) {
|
||||
if (!Array.isArray(keys) || !keys.every((r) => Array.isArray(r) && r.every((k) => typeof k === "string"))) throw new TypeError(`VirtualKeyboard: keys is rows of strings ([["Q", "W"], ["space"]]), got ${JSON.stringify(keys)}`);
|
||||
return (
|
||||
<Node flex_direction="Column" row_gap={px(4)}>
|
||||
{keys.map((row, i) => (
|
||||
<Node key={i} flex_direction="Row" column_gap={px(4)}>
|
||||
{row.map((key, j) => (
|
||||
<FeathersButton key={j} flex_grow={1}>
|
||||
<Text>{key}</Text>
|
||||
</FeathersButton>
|
||||
))}
|
||||
</Node>
|
||||
))}
|
||||
</Node>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
// bevy_feathers 0.20.0 dark_theme.rs and palette.rs: the dark theme's colours, each semantic colour from the palette,
|
||||
// a surface level's overrides of them, and each design token's semantic colour. Generated from those files; do not edit.
|
||||
import { Oklcha } from "../colorspaces";
|
||||
import { tokens, type ThemeToken } from "./tokens";
|
||||
|
||||
/** bevy_feathers' palette. @bevy bevy_feathers::palette */
|
||||
export const palette = {
|
||||
TRANSPARENT: new Oklcha(0.0, 0.0, 0.0, 0.0),
|
||||
BLACK: new Oklcha(0.0, 0.0, 0.0, 1.0),
|
||||
GRAY_0: new Oklcha(0.2414, 0.0095, 285.67, 1.0),
|
||||
GRAY_1: new Oklcha(0.2866, 0.0072, 285.93, 1.0),
|
||||
GRAY_2: new Oklcha(0.3373, 0.0071, 274.77, 1.0),
|
||||
GRAY_3: new Oklcha(0.3992, 0.0101, 278.38, 1.0),
|
||||
WARM_GRAY_1: new Oklcha(0.3757, 0.0017, 286.32, 1.0),
|
||||
LIGHT_GRAY_1: new Oklcha(0.7607, 0.0014, 286.37, 1.0),
|
||||
LIGHT_GRAY_2: new Oklcha(0.6106, 0.003, 286.31, 1.0),
|
||||
LIGHT_GRAY_MIX: new Oklcha(0.8185, 0.0171, 274.77, 1.0),
|
||||
WHITE: new Oklcha(1.0, 0.000000059604645, 90.0, 1.0),
|
||||
ACCENT: new Oklcha(0.542, 0.1594, 255.4, 1.0),
|
||||
X_AXIS: new Oklcha(0.5232, 0.1404, 13.84, 1.0),
|
||||
Y_AXIS: new Oklcha(0.5866, 0.1543, 129.84, 1.0),
|
||||
Z_AXIS: new Oklcha(0.4847, 0.1249, 253.08, 1.0),
|
||||
W_AXIS: new Oklcha(0.9, 0.01, 95.0, 1.0),
|
||||
};
|
||||
|
||||
/** Color::NONE: transparent black */
|
||||
const NONE = new Oklcha(0, 0, 0, 0);
|
||||
|
||||
/** the theme's surface levels, each a set of overrides of its semantic colours. @bevy bevy_feathers::theme::SurfaceLevel */
|
||||
export type SurfaceLevel = "Base" | "Higher" | "Highest" | "Floating";
|
||||
|
||||
/** a theme: its semantic colours, a surface level's overrides of them, and each token's semantic colour.
|
||||
* @bevy bevy_feathers::theme::ThemeProps */
|
||||
export interface ThemeProps {
|
||||
semantic_base: Record<string, Oklcha>;
|
||||
semantic_overrides: Partial<Record<SurfaceLevel, Record<string, Oklcha>>>;
|
||||
token_assignments: Partial<Record<ThemeToken, string>>;
|
||||
}
|
||||
|
||||
/** bevy_feathers' dark theme. @bevy bevy_feathers::dark_theme::create_dark_theme */
|
||||
export function create_dark_theme(): ThemeProps {
|
||||
return {
|
||||
semantic_base: {
|
||||
SURFACE_WINDOW: palette.GRAY_0,
|
||||
SURFACE_PANE_BODY: palette.GRAY_1,
|
||||
SURFACE_PANE_HEADER: palette.GRAY_0,
|
||||
SURFACE_SUBPANE_BODY: palette.GRAY_1,
|
||||
SURFACE_SUBPANE_HEADER: palette.GRAY_2,
|
||||
SURFACE_GROUP: palette.GRAY_2,
|
||||
SURFACE_DIALOG: palette.GRAY_1,
|
||||
SURFACE_MENU: palette.GRAY_1,
|
||||
BORDER_DEFAULT: palette.WARM_GRAY_1,
|
||||
TEXT_DEFAULT: palette.LIGHT_GRAY_1,
|
||||
TEXT_DIM: palette.LIGHT_GRAY_2,
|
||||
TEXT_DISABLED: palette.LIGHT_GRAY_1.with_alpha(0.4),
|
||||
TEXT_ON_ACCENT: palette.WHITE,
|
||||
FILL_ACCENT_DEFAULT: palette.ACCENT,
|
||||
FILL_ACCENT_HOVER: palette.ACCENT.lighter(0.05),
|
||||
FILL_ACCENT_PRESSED: palette.ACCENT.lighter(0.1),
|
||||
FILL_ACCENT_DISABLED: palette.GRAY_3.with_alpha(0.7),
|
||||
FILL_SOLID_DEFAULT: palette.GRAY_3,
|
||||
FILL_SOLID_HOVER: palette.GRAY_3.lighter(0.05),
|
||||
FILL_SOLID_PRESSED: palette.GRAY_3.lighter(0.1),
|
||||
FILL_SOLID_DISABLED: palette.GRAY_2.with_alpha(0.7),
|
||||
FILL_ITEM_DEFAULT: NONE,
|
||||
FILL_ITEM_HOVER: palette.GRAY_1.lighter(0.05),
|
||||
FILL_ITEM_PRESSED: palette.GRAY_1.lighter(0.1),
|
||||
FILL_FIELD_DEFAULT: palette.GRAY_2,
|
||||
FILL_FIELD_HOVER: palette.GRAY_2.lighter(0.05),
|
||||
FILL_FIELD_PRESSED: palette.GRAY_2.lighter(0.1),
|
||||
FILL_NONE: NONE,
|
||||
AXIS_X: palette.X_AXIS,
|
||||
AXIS_Y: palette.Y_AXIS,
|
||||
AXIS_Z: palette.Z_AXIS,
|
||||
AXIS_W: palette.W_AXIS,
|
||||
FOCUS_RING: palette.ACCENT.with_alpha(0.5),
|
||||
},
|
||||
semantic_overrides: {
|
||||
Highest: {
|
||||
FILL_SOLID_DEFAULT: palette.GRAY_3.lighter(0.05),
|
||||
FILL_SOLID_HOVER: palette.GRAY_3.lighter(0.1),
|
||||
FILL_SOLID_PRESSED: palette.GRAY_3.lighter(0.15),
|
||||
FILL_SOLID_DISABLED: palette.GRAY_3.lighter(0.05).with_alpha(0.7),
|
||||
FILL_FIELD_DEFAULT: palette.GRAY_3,
|
||||
FILL_FIELD_HOVER: palette.GRAY_3.lighter(0.02),
|
||||
FILL_FIELD_PRESSED: palette.GRAY_3.lighter(0.05),
|
||||
FILL_ITEM_HOVER: palette.GRAY_3.lighter(0.05),
|
||||
FILL_ITEM_PRESSED: palette.GRAY_3.lighter(0.1),
|
||||
},
|
||||
Higher: {
|
||||
FILL_FIELD_DEFAULT: palette.GRAY_3,
|
||||
FILL_ITEM_HOVER: palette.GRAY_2.lighter(0.02),
|
||||
FILL_ITEM_PRESSED: palette.GRAY_2.lighter(0.05),
|
||||
},
|
||||
Floating: {
|
||||
FILL_SOLID_DEFAULT: palette.GRAY_3,
|
||||
FILL_FIELD_DEFAULT: palette.GRAY_3,
|
||||
FILL_ITEM_HOVER: palette.GRAY_2.lighter(0.02),
|
||||
FILL_ITEM_PRESSED: palette.GRAY_2.lighter(0.05),
|
||||
},
|
||||
},
|
||||
token_assignments: {
|
||||
[tokens.WINDOW_BG]: "SURFACE_WINDOW",
|
||||
[tokens.FOCUS_RING]: "FOCUS_RING",
|
||||
[tokens.TEXT_MAIN]: "TEXT_DEFAULT",
|
||||
[tokens.TEXT_DIM]: "TEXT_DIM",
|
||||
[tokens.BUTTON_BG]: "FILL_SOLID_DEFAULT",
|
||||
[tokens.BUTTON_BG_HOVER]: "FILL_SOLID_HOVER",
|
||||
[tokens.BUTTON_BG_PRESSED]: "FILL_SOLID_PRESSED",
|
||||
[tokens.BUTTON_BG_DISABLED]: "FILL_SOLID_DISABLED",
|
||||
[tokens.BUTTON_PRIMARY_BG]: "FILL_ACCENT_DEFAULT",
|
||||
[tokens.BUTTON_PRIMARY_BG_HOVER]: "FILL_ACCENT_HOVER",
|
||||
[tokens.BUTTON_PRIMARY_BG_PRESSED]: "FILL_ACCENT_PRESSED",
|
||||
[tokens.BUTTON_PRIMARY_BG_DISABLED]: "FILL_ACCENT_DISABLED",
|
||||
[tokens.BUTTON_PLAIN_BG]: "FILL_NONE",
|
||||
[tokens.BUTTON_PLAIN_BG_HOVER]: "FILL_ITEM_HOVER",
|
||||
[tokens.BUTTON_PLAIN_BG_PRESSED]: "FILL_ITEM_PRESSED",
|
||||
[tokens.BUTTON_PLAIN_BG_DISABLED]: "FILL_NONE",
|
||||
[tokens.BUTTON_TEXT]: "TEXT_ON_ACCENT",
|
||||
[tokens.BUTTON_TEXT_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.BUTTON_PRIMARY_TEXT]: "TEXT_ON_ACCENT",
|
||||
[tokens.BUTTON_PRIMARY_TEXT_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.SLIDER_BG]: "FILL_FIELD_DEFAULT",
|
||||
[tokens.SLIDER_BG_HOVER]: "FILL_FIELD_HOVER",
|
||||
[tokens.SLIDER_BG_PRESSED]: "FILL_FIELD_PRESSED",
|
||||
[tokens.SLIDER_BG_DISABLED]: "FILL_FIELD_DEFAULT",
|
||||
[tokens.SLIDER_BAR]: "FILL_ACCENT_DEFAULT",
|
||||
[tokens.SLIDER_BAR_HOVER]: "FILL_ACCENT_HOVER",
|
||||
[tokens.SLIDER_BAR_PRESSED]: "FILL_ACCENT_HOVER",
|
||||
[tokens.SLIDER_BAR_DISABLED]: "FILL_ACCENT_DISABLED",
|
||||
[tokens.SLIDER_TEXT]: "TEXT_ON_ACCENT",
|
||||
[tokens.SLIDER_TEXT_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.SCROLLBAR_BG]: "FILL_SOLID_DISABLED",
|
||||
[tokens.SCROLLBAR_THUMB]: "FILL_ACCENT_DEFAULT",
|
||||
[tokens.SCROLLBAR_THUMB_HOVER]: "FILL_ACCENT_HOVER",
|
||||
[tokens.CHECKBOX_BG]: "FILL_SOLID_DEFAULT",
|
||||
[tokens.CHECKBOX_BG_HOVER]: "FILL_SOLID_DEFAULT",
|
||||
[tokens.CHECKBOX_BG_PRESSED]: "FILL_SOLID_DEFAULT",
|
||||
[tokens.CHECKBOX_BG_DISABLED]: "FILL_NONE",
|
||||
[tokens.CHECKBOX_BG_CHECKED]: "FILL_ACCENT_DEFAULT",
|
||||
[tokens.CHECKBOX_BG_CHECKED_DISABLED]: "FILL_NONE",
|
||||
[tokens.CHECKBOX_BG_CHECKED_HOVER]: "FILL_ACCENT_HOVER",
|
||||
[tokens.CHECKBOX_BG_CHECKED_PRESSED]: "FILL_ACCENT_PRESSED",
|
||||
[tokens.CHECKBOX_BORDER]: "FILL_SOLID_DEFAULT",
|
||||
[tokens.CHECKBOX_BORDER_HOVER]: "FILL_SOLID_HOVER",
|
||||
[tokens.CHECKBOX_BORDER_PRESSED]: "FILL_SOLID_PRESSED",
|
||||
[tokens.CHECKBOX_BORDER_DISABLED]: "FILL_SOLID_DISABLED",
|
||||
[tokens.CHECKBOX_BORDER_CHECKED]: "FILL_ACCENT_DEFAULT",
|
||||
[tokens.CHECKBOX_BORDER_CHECKED_HOVER]: "FILL_ACCENT_HOVER",
|
||||
[tokens.CHECKBOX_BORDER_CHECKED_PRESSED]: "FILL_ACCENT_PRESSED",
|
||||
[tokens.CHECKBOX_BORDER_CHECKED_DISABLED]: "FILL_ACCENT_DISABLED",
|
||||
[tokens.CHECKBOX_MARK]: "TEXT_ON_ACCENT",
|
||||
[tokens.CHECKBOX_MARK_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.CHECKBOX_TEXT]: "TEXT_DEFAULT",
|
||||
[tokens.CHECKBOX_TEXT_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.RADIO_BG]: "FILL_NONE",
|
||||
[tokens.RADIO_BG_HOVER]: "FILL_NONE",
|
||||
[tokens.RADIO_BG_PRESSED]: "FILL_NONE",
|
||||
[tokens.RADIO_BG_DISABLED]: "FILL_NONE",
|
||||
[tokens.RADIO_BG_CHECKED]: "FILL_NONE",
|
||||
[tokens.RADIO_BG_CHECKED_HOVER]: "FILL_NONE",
|
||||
[tokens.RADIO_BG_CHECKED_PRESSED]: "FILL_NONE",
|
||||
[tokens.RADIO_BG_CHECKED_DISABLED]: "FILL_NONE",
|
||||
[tokens.RADIO_BORDER]: "FILL_SOLID_DEFAULT",
|
||||
[tokens.RADIO_BORDER_HOVER]: "FILL_SOLID_HOVER",
|
||||
[tokens.RADIO_BORDER_PRESSED]: "FILL_SOLID_PRESSED",
|
||||
[tokens.RADIO_BORDER_DISABLED]: "FILL_SOLID_DISABLED",
|
||||
[tokens.RADIO_BORDER_CHECKED]: "FILL_ACCENT_DEFAULT",
|
||||
[tokens.RADIO_BORDER_CHECKED_HOVER]: "FILL_ACCENT_HOVER",
|
||||
[tokens.RADIO_BORDER_CHECKED_PRESSED]: "FILL_ACCENT_PRESSED",
|
||||
[tokens.RADIO_BORDER_CHECKED_DISABLED]: "FILL_ACCENT_DISABLED",
|
||||
[tokens.RADIO_MARK]: "FILL_ACCENT_DEFAULT",
|
||||
[tokens.RADIO_MARK_HOVER]: "FILL_ACCENT_HOVER",
|
||||
[tokens.RADIO_MARK_PRESSED]: "FILL_ACCENT_PRESSED",
|
||||
[tokens.RADIO_MARK_DISABLED]: "FILL_ACCENT_DISABLED",
|
||||
[tokens.RADIO_TEXT]: "TEXT_DEFAULT",
|
||||
[tokens.RADIO_TEXT_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.SWITCH_BG]: "FILL_SOLID_DEFAULT",
|
||||
[tokens.SWITCH_BG_HOVER]: "FILL_SOLID_HOVER",
|
||||
[tokens.SWITCH_BG_PRESSED]: "FILL_SOLID_PRESSED",
|
||||
[tokens.SWITCH_BG_DISABLED]: "FILL_SOLID_DISABLED",
|
||||
[tokens.SWITCH_BG_CHECKED]: "FILL_ACCENT_DEFAULT",
|
||||
[tokens.SWITCH_BG_CHECKED_HOVER]: "FILL_ACCENT_HOVER",
|
||||
[tokens.SWITCH_BG_CHECKED_PRESSED]: "FILL_SOLID_PRESSED",
|
||||
[tokens.SWITCH_BG_CHECKED_DISABLED]: "FILL_ACCENT_DISABLED",
|
||||
[tokens.SWITCH_BORDER]: "FILL_SOLID_DEFAULT",
|
||||
[tokens.SWITCH_BORDER_HOVER]: "FILL_SOLID_HOVER",
|
||||
[tokens.SWITCH_BORDER_PRESSED]: "FILL_SOLID_PRESSED",
|
||||
[tokens.SWITCH_BORDER_DISABLED]: "FILL_SOLID_DEFAULT",
|
||||
[tokens.SWITCH_BORDER_CHECKED]: "FILL_ACCENT_DEFAULT",
|
||||
[tokens.SWITCH_BORDER_CHECKED_HOVER]: "FILL_ACCENT_HOVER",
|
||||
[tokens.SWITCH_BORDER_CHECKED_PRESSED]: "FILL_ACCENT_PRESSED",
|
||||
[tokens.SWITCH_BORDER_CHECKED_DISABLED]: "FILL_SOLID_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BG]: "TEXT_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BG_HOVER]: "TEXT_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BG_PRESSED]: "TEXT_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BG_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.SWITCH_SLIDE_BG_CHECKED]: "TEXT_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BG_CHECKED_HOVER]: "TEXT_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BG_CHECKED_PRESSED]: "TEXT_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BG_CHECKED_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.SWITCH_SLIDE_BORDER]: "TEXT_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BORDER_HOVER]: "TEXT_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BORDER_PRESSED]: "TEXT_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BORDER_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.SWITCH_SLIDE_BORDER_CHECKED]: "TEXT_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BORDER_CHECKED_HOVER]: "TEXT_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BORDER_CHECKED_PRESSED]: "TEXT_DEFAULT",
|
||||
[tokens.SWITCH_SLIDE_BORDER_CHECKED_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.COLOR_PLANE_BG]: "FILL_FIELD_DEFAULT",
|
||||
[tokens.MENU_BG]: "SURFACE_MENU",
|
||||
[tokens.MENU_BORDER]: "BORDER_DEFAULT",
|
||||
[tokens.MENUITEM_BG]: "FILL_ITEM_DEFAULT",
|
||||
[tokens.MENUITEM_BG_HOVER]: "FILL_ITEM_HOVER",
|
||||
[tokens.MENUITEM_BG_PRESSED]: "FILL_ITEM_PRESSED",
|
||||
[tokens.MENUITEM_BG_FOCUSED]: "FILL_ITEM_PRESSED",
|
||||
[tokens.MENUITEM_TEXT]: "TEXT_ON_ACCENT",
|
||||
[tokens.MENUITEM_TEXT_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.TEXT_INPUT_BG]: "FILL_FIELD_DEFAULT",
|
||||
[tokens.TEXT_INPUT_LABEL_BG]: "FILL_SOLID_DEFAULT",
|
||||
[tokens.TEXT_INPUT_TEXT]: "TEXT_ON_ACCENT",
|
||||
[tokens.TEXT_INPUT_TEXT_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.TEXT_INPUT_CURSOR]: "FILL_ACCENT_PRESSED",
|
||||
[tokens.TEXT_INPUT_SELECTION]: "FILL_ACCENT_DEFAULT",
|
||||
[tokens.TEXT_INPUT_SELECTION_UNFOCUSED]: "FILL_NONE",
|
||||
[tokens.TEXT_INPUT_X_AXIS]: "AXIS_X",
|
||||
[tokens.TEXT_INPUT_Y_AXIS]: "AXIS_Y",
|
||||
[tokens.TEXT_INPUT_Z_AXIS]: "AXIS_Z",
|
||||
[tokens.TEXT_INPUT_W_AXIS]: "AXIS_W",
|
||||
[tokens.PANE_HEADER_BG]: "SURFACE_PANE_HEADER",
|
||||
[tokens.PANE_HEADER_BORDER]: "SURFACE_PANE_BODY",
|
||||
[tokens.PANE_HEADER_TEXT]: "TEXT_DEFAULT",
|
||||
[tokens.PANE_HEADER_DIVIDER]: "SURFACE_PANE_BODY",
|
||||
[tokens.PANE_BODY_BG]: "SURFACE_PANE_BODY",
|
||||
[tokens.SUBPANE_HEADER_BG]: "SURFACE_SUBPANE_HEADER",
|
||||
[tokens.SUBPANE_HEADER_BORDER]: "SURFACE_SUBPANE_HEADER",
|
||||
[tokens.SUBPANE_HEADER_TEXT]: "TEXT_DEFAULT",
|
||||
[tokens.SUBPANE_BODY_BG]: "SURFACE_SUBPANE_BODY",
|
||||
[tokens.SUBPANE_BODY_BORDER]: "SURFACE_SUBPANE_HEADER",
|
||||
[tokens.GROUP_BG]: "SURFACE_GROUP",
|
||||
[tokens.GROUP_BORDER]: "SURFACE_GROUP",
|
||||
[tokens.GROUP_HEADER_TEXT]: "TEXT_DEFAULT",
|
||||
[tokens.LISTROW_BG]: "FILL_ITEM_DEFAULT",
|
||||
[tokens.LISTROW_BG_HOVER]: "FILL_ITEM_HOVER",
|
||||
[tokens.LISTROW_BG_SELECTED]: "FILL_ITEM_PRESSED",
|
||||
[tokens.LISTROW_TEXT]: "TEXT_ON_ACCENT",
|
||||
[tokens.LISTROW_TEXT_DISABLED]: "TEXT_DISABLED",
|
||||
[tokens.DIALOG_BG]: "SURFACE_DIALOG",
|
||||
[tokens.DIALOG_BORDER]: "BORDER_DEFAULT",
|
||||
[tokens.DIALOG_HEADER_BG]: "SURFACE_WINDOW",
|
||||
[tokens.DIALOG_TEXT]: "TEXT_DEFAULT",
|
||||
[tokens.DIALOG_HEADER_TEXT]: "TEXT_DEFAULT",
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// bevy_feathers (docs/control.feature FC0a): Bevy's widget set, its theme and fonts, drawn by the page.
|
||||
export { tokens, type ThemeToken } from "./tokens";
|
||||
export { palette, create_dark_theme, type ThemeProps, type SurfaceLevel } from "./dark_theme";
|
||||
export { UiTheme, ThemeContext, ThemedText, context_color, useThemeColor } from "./theme";
|
||||
export { fonts, size } from "./constants";
|
||||
export { FeathersButton, VirtualKeyboard, to_border_radius, type ButtonVariant, type RoundedCorners, type FeathersButtonProps } from "./controls";
|
||||
@@ -0,0 +1,62 @@
|
||||
// bevy_feathers' theme.rs and font_styles.rs (docs/control.feature FC0a): the theme a widget looks its colours up in
|
||||
// (the UiTheme resource, by token and the surface level it sits on), and the font and text colour a widget hands down
|
||||
// to its ThemedText. In Bevy both are Propagate<TextFont> and Propagate<TextColor> filtered With<ThemedText>: only a
|
||||
// ThemedText takes them, so a plain <Text> inside a feathers button keeps Bevy's default font, size and colour, as
|
||||
// Bevy draws it. Here they're React context, read by <ThemedText>.
|
||||
import { createContext, useContext, type ReactNode } from "react";
|
||||
import { Srgba } from "../colors";
|
||||
import { Text, type TextProps, type TextStyleProps } from "../ui";
|
||||
import type { ThemeProps, SurfaceLevel } from "./dark_theme";
|
||||
import type { ThemeToken } from "./tokens";
|
||||
|
||||
/** palettes::basic::FUCHSIA, what a theme gives for a token it has no colour for */
|
||||
const FUCHSIA = new Srgba(1, 0, 1, 1);
|
||||
|
||||
/** ThemeProps::default(): no colours, so every token is FUCHSIA, as Bevy draws a feathers widget with no UiTheme */
|
||||
const EMPTY: ThemeProps = { semantic_base: {}, semantic_overrides: {}, token_assignments: {} };
|
||||
|
||||
const ThemeCx = createContext<ThemeProps>(EMPTY);
|
||||
const LevelCx = createContext<SurfaceLevel>("Base");
|
||||
|
||||
/** Bevy's UiTheme resource: the theme every feathers widget inside looks its colours up in (create_dark_theme()).
|
||||
* @bevy bevy_feathers::theme::UiTheme */
|
||||
export function UiTheme({ theme, children }: { theme: ThemeProps; children?: ReactNode }) {
|
||||
return <ThemeCx.Provider value={theme}>{children}</ThemeCx.Provider>;
|
||||
}
|
||||
|
||||
/** the surface level the widgets inside sit on, which picks the theme's overrides for it.
|
||||
* @bevy bevy_feathers::theme::ThemeContext */
|
||||
export function ThemeContext({ level, children }: { level: SurfaceLevel; children?: ReactNode }) {
|
||||
return <LevelCx.Provider value={level}>{children}</LevelCx.Provider>;
|
||||
}
|
||||
|
||||
/** ThemeProps::context_color: a token's colour on a surface level, the level's override first, FUCHSIA when the theme
|
||||
* has none */
|
||||
export function context_color(theme: ThemeProps, token: ThemeToken, level: SurfaceLevel = "Base"): Srgba {
|
||||
const semantic = theme.token_assignments[token];
|
||||
if (semantic === undefined) return FUCHSIA;
|
||||
const c = theme.semantic_overrides[level]?.[semantic] ?? theme.semantic_base[semantic];
|
||||
return c ? c.to_srgba() : FUCHSIA;
|
||||
}
|
||||
|
||||
/** a token's colour in the UiTheme and surface level around the caller */
|
||||
export function useThemeColor(token: ThemeToken): Srgba {
|
||||
return context_color(useContext(ThemeCx), token, useContext(LevelCx));
|
||||
}
|
||||
|
||||
/** the TextFont and TextColor a widget propagates to its ThemedText (InheritableFont, InheritableThemeTextColor) */
|
||||
type Inherited = Pick<TextStyleProps, "font" | "font_size" | "weight" | "color">;
|
||||
const InheritedCx = createContext<Inherited>({});
|
||||
|
||||
/** InheritableFont and InheritableThemeTextColor on a widget: the font, size, weight and colour its ThemedText take
|
||||
* (each replacing the ThemedText's own, as Propagate inserts the component). */
|
||||
export function InheritableText({ children, ...style }: Inherited & { children?: ReactNode }) {
|
||||
const outer = useContext(InheritedCx);
|
||||
return <InheritedCx.Provider value={{ ...outer, ...Object.fromEntries(Object.entries(style).filter(([, v]) => v !== undefined)) }}>{children}</InheritedCx.Provider>;
|
||||
}
|
||||
|
||||
/** A Text with ThemedText: it takes the font and colour the feathers widget around it propagates.
|
||||
* @bevy bevy_feathers::theme::ThemedText */
|
||||
export function ThemedText(props: TextProps) {
|
||||
return <Text {...props} {...useContext(InheritedCx)} />;
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
// bevy_feathers 0.20.0 tokens.rs: the design tokens a widget names its colours by (ThemeToken), each its id. Generated from
|
||||
// that file; do not edit.
|
||||
/** bevy_feathers' design tokens (ThemeToken ids). @bevy bevy_feathers::tokens */
|
||||
export const tokens = {
|
||||
WINDOW_BG: "feathers.window.bg",
|
||||
FOCUS_RING: "feathers.focus.ring",
|
||||
TEXT_MAIN: "feathers.text.main",
|
||||
TEXT_DIM: "feathers.text.dim",
|
||||
BUTTON_BG: "feathers.button.bg",
|
||||
BUTTON_BG_HOVER: "feathers.button.bg.hover",
|
||||
BUTTON_BG_DISABLED: "feathers.button.bg.disabled",
|
||||
BUTTON_BG_PRESSED: "feathers.button.bg.pressed",
|
||||
BUTTON_TEXT: "feathers.button.txt",
|
||||
BUTTON_TEXT_DISABLED: "feathers.button.txt.disabled",
|
||||
BUTTON_PRIMARY_BG: "feathers.button.primary.bg",
|
||||
BUTTON_PRIMARY_BG_HOVER: "feathers.button.primary.bg.hover",
|
||||
BUTTON_PRIMARY_BG_DISABLED: "feathers.button.primary.bg.disabled",
|
||||
BUTTON_PRIMARY_BG_PRESSED: "feathers.button.primary.bg.pressed",
|
||||
BUTTON_PRIMARY_TEXT: "feathers.button.primary.txt",
|
||||
BUTTON_PRIMARY_TEXT_DISABLED: "feathers.button.primary.txt.disabled",
|
||||
BUTTON_PLAIN_BG: "feathers.button.plain.bg",
|
||||
BUTTON_PLAIN_BG_HOVER: "feathers.button.plain.bg.hover",
|
||||
BUTTON_PLAIN_BG_DISABLED: "feathers.button.plain.bg.disabled",
|
||||
BUTTON_PLAIN_BG_PRESSED: "feathers.button.plain.bg.pressed",
|
||||
SLIDER_BG: "feathers.slider.bg",
|
||||
SLIDER_BG_HOVER: "feathers.slider.bg.hover",
|
||||
SLIDER_BG_PRESSED: "feathers.slider.bg.pressed",
|
||||
SLIDER_BG_DISABLED: "feathers.slider.bg.disabled",
|
||||
SLIDER_BAR: "feathers.slider.bar",
|
||||
SLIDER_BAR_HOVER: "feathers.slider.bar.hover",
|
||||
SLIDER_BAR_PRESSED: "feathers.slider.bar.pressed",
|
||||
SLIDER_BAR_DISABLED: "feathers.slider.bar.disabled",
|
||||
SLIDER_TEXT: "feathers.slider.text",
|
||||
SLIDER_TEXT_DISABLED: "feathers.slider.text.disabled",
|
||||
SCROLLBAR_BG: "feathers.scrollbar.bg",
|
||||
SCROLLBAR_THUMB: "feathers.scrollbar.thumb",
|
||||
SCROLLBAR_THUMB_HOVER: "feathers.scrollbar.thumb.hover",
|
||||
CHECKBOX_BG: "feathers.checkbox.bg",
|
||||
CHECKBOX_BG_HOVER: "feathers.checkbox.bg.hover",
|
||||
CHECKBOX_BG_PRESSED: "feathers.checkbox.bg.pressed",
|
||||
CHECKBOX_BG_DISABLED: "feathers.checkbox.bg.disabled",
|
||||
CHECKBOX_BG_CHECKED: "feathers.checkbox.bg.checked",
|
||||
CHECKBOX_BG_CHECKED_HOVER: "feathers.checkbox.bg.checked.hover",
|
||||
CHECKBOX_BG_CHECKED_PRESSED: "feathers.checkbox.bg.checked.pressed",
|
||||
CHECKBOX_BG_CHECKED_DISABLED: "feathers.checkbox.bg.checked.disabled",
|
||||
CHECKBOX_BORDER: "feathers.checkbox.border",
|
||||
CHECKBOX_BORDER_HOVER: "feathers.checkbox.border.hover",
|
||||
CHECKBOX_BORDER_PRESSED: "feathers.checkbox.border.pressed",
|
||||
CHECKBOX_BORDER_DISABLED: "feathers.checkbox.border.disabled",
|
||||
CHECKBOX_BORDER_CHECKED: "feathers.checkbox.border.checked",
|
||||
CHECKBOX_BORDER_CHECKED_HOVER: "feathers.checkbox.border.checked.hover",
|
||||
CHECKBOX_BORDER_CHECKED_PRESSED: "feathers.checkbox.border.checked.pressed",
|
||||
CHECKBOX_BORDER_CHECKED_DISABLED: "feathers.checkbox.border.checked.disabled",
|
||||
CHECKBOX_MARK: "feathers.checkbox.mark",
|
||||
CHECKBOX_MARK_DISABLED: "feathers.checkbox.mark.disabled",
|
||||
CHECKBOX_TEXT: "feathers.checkbox.text",
|
||||
CHECKBOX_TEXT_DISABLED: "feathers.checkbox.text.disabled",
|
||||
RADIO_BG: "feathers.radio.bg",
|
||||
RADIO_BG_HOVER: "feathers.radio.bg.hover",
|
||||
RADIO_BG_PRESSED: "feathers.radio.bg.pressed",
|
||||
RADIO_BG_DISABLED: "feathers.radio.bg.disabled",
|
||||
RADIO_BG_CHECKED: "feathers.radio.bg.checked",
|
||||
RADIO_BG_CHECKED_HOVER: "feathers.radio.bg.checked.hover",
|
||||
RADIO_BG_CHECKED_PRESSED: "feathers.radio.bg.checked.pressed",
|
||||
RADIO_BG_CHECKED_DISABLED: "feathers.radio.bg.checked.disabled",
|
||||
RADIO_BORDER: "feathers.radio.border",
|
||||
RADIO_BORDER_HOVER: "feathers.radio.border.hover",
|
||||
RADIO_BORDER_PRESSED: "feathers.radio.border.pressed",
|
||||
RADIO_BORDER_DISABLED: "feathers.radio.border.disabled",
|
||||
RADIO_BORDER_CHECKED: "feathers.radio.border.checked",
|
||||
RADIO_BORDER_CHECKED_HOVER: "feathers.radio.border.checked.hover",
|
||||
RADIO_BORDER_CHECKED_PRESSED: "feathers.radio.border.checked.pressed",
|
||||
RADIO_BORDER_CHECKED_DISABLED: "feathers.radio.border.checked.disabled",
|
||||
RADIO_MARK: "feathers.radio.mark",
|
||||
RADIO_MARK_HOVER: "feathers.radio.mark.hover",
|
||||
RADIO_MARK_PRESSED: "feathers.radio.mark.pressed",
|
||||
RADIO_MARK_DISABLED: "feathers.radio.mark.disabled",
|
||||
RADIO_TEXT: "feathers.radio.text",
|
||||
RADIO_TEXT_DISABLED: "feathers.radio.text.disabled",
|
||||
SWITCH_BG: "feathers.switch.bg",
|
||||
SWITCH_BG_HOVER: "feathers.switch.bg.hover",
|
||||
SWITCH_BG_PRESSED: "feathers.switch.bg.pressed",
|
||||
SWITCH_BG_DISABLED: "feathers.switch.bg.disabled",
|
||||
SWITCH_BG_CHECKED: "feathers.switch.bg.checked",
|
||||
SWITCH_BG_CHECKED_HOVER: "feathers.switch.bg.checked.hover",
|
||||
SWITCH_BG_CHECKED_PRESSED: "feathers.switch.bg.checked.pressed",
|
||||
SWITCH_BG_CHECKED_DISABLED: "feathers.switch.bg.checked.disabled",
|
||||
SWITCH_BORDER: "feathers.switch.border",
|
||||
SWITCH_BORDER_HOVER: "feathers.switch.border.hover",
|
||||
SWITCH_BORDER_PRESSED: "feathers.switch.border.hover.pressed",
|
||||
SWITCH_BORDER_DISABLED: "feathers.switch.border.disabled",
|
||||
SWITCH_BORDER_CHECKED: "feathers.switch.border.checked",
|
||||
SWITCH_BORDER_CHECKED_HOVER: "feathers.switch.border.checked.hover",
|
||||
SWITCH_BORDER_CHECKED_PRESSED: "feathers.switch.border.checked.pressed",
|
||||
SWITCH_BORDER_CHECKED_DISABLED: "feathers.switch.border.checked.disabled",
|
||||
SWITCH_SLIDE_BG: "feathers.switch.slide.bg",
|
||||
SWITCH_SLIDE_BG_HOVER: "feathers.switch.slide.bg.hover",
|
||||
SWITCH_SLIDE_BG_PRESSED: "feathers.switch.slide.bg.pressed",
|
||||
SWITCH_SLIDE_BG_DISABLED: "feathers.switch.slide.bg.disabled",
|
||||
SWITCH_SLIDE_BG_CHECKED: "feathers.switch.slide.bg.checked",
|
||||
SWITCH_SLIDE_BG_CHECKED_HOVER: "feathers.switch.slide.bg.checked.hover",
|
||||
SWITCH_SLIDE_BG_CHECKED_PRESSED: "feathers.switch.slide.bg.checked.pressed",
|
||||
SWITCH_SLIDE_BG_CHECKED_DISABLED: "feathers.switch.slide.bg.checked.disabled",
|
||||
SWITCH_SLIDE_BORDER: "feathers.switch.slide.border",
|
||||
SWITCH_SLIDE_BORDER_HOVER: "feathers.switch.slide.border.hover",
|
||||
SWITCH_SLIDE_BORDER_PRESSED: "feathers.switch.slide.border.pressed",
|
||||
SWITCH_SLIDE_BORDER_DISABLED: "feathers.switch.slide.border.disabled",
|
||||
SWITCH_SLIDE_BORDER_CHECKED: "feathers.switch.slide.border.checked",
|
||||
SWITCH_SLIDE_BORDER_CHECKED_HOVER: "feathers.switch.slide.border.checked.hover",
|
||||
SWITCH_SLIDE_BORDER_CHECKED_PRESSED: "feathers.switch.slide.border.checked.pressed",
|
||||
SWITCH_SLIDE_BORDER_CHECKED_DISABLED: "feathers.switch.slide.border.checked.disabled",
|
||||
COLOR_PLANE_BG: "feathers.colorplane.bg",
|
||||
MENU_BG: "feathers.menu.bg",
|
||||
MENU_BORDER: "feathers.menu.border",
|
||||
MENUITEM_BG: "feathers.menuitem.bg",
|
||||
MENUITEM_BG_HOVER: "feathers.menuitem.bg.hover",
|
||||
MENUITEM_BG_PRESSED: "feathers.menuitem.bg.pressed",
|
||||
MENUITEM_BG_FOCUSED: "feathers.menuitem.bg.focused",
|
||||
MENUITEM_TEXT: "feathers.menuitem.text",
|
||||
MENUITEM_TEXT_DISABLED: "feathers.menuitem.text.disabled",
|
||||
TEXT_INPUT_BG: "feathers.textinput.bg",
|
||||
TEXT_INPUT_TEXT: "feathers.textinput.text",
|
||||
TEXT_INPUT_TEXT_DISABLED: "feathers.textinput.text.disabled",
|
||||
TEXT_INPUT_CURSOR: "feathers.textinput.cursor",
|
||||
TEXT_INPUT_SELECTION: "feathers.textinput.selection",
|
||||
TEXT_INPUT_SELECTION_UNFOCUSED: "feathers.textinput.selection.unfocused",
|
||||
TEXT_INPUT_LABEL_BG: "feathers.textinput.label.bg",
|
||||
TEXT_INPUT_X_AXIS: "feathers.textinput.axis.x",
|
||||
TEXT_INPUT_Y_AXIS: "feathers.textinput.axis.y",
|
||||
TEXT_INPUT_Z_AXIS: "feathers.textinput.axis.z",
|
||||
TEXT_INPUT_W_AXIS: "feathers.textinput.axis.w",
|
||||
PANE_HEADER_BG: "feathers.pane.header.bg",
|
||||
PANE_HEADER_BORDER: "feathers.pane.header.border",
|
||||
PANE_HEADER_TEXT: "feathers.pane.header.text",
|
||||
PANE_HEADER_DIVIDER: "feathers.pane.header.divider",
|
||||
PANE_BODY_BG: "feathers.pane.body.bg",
|
||||
SUBPANE_HEADER_BG: "feathers.subpane.header.bg",
|
||||
SUBPANE_HEADER_BORDER: "feathers.subpane.header.border",
|
||||
SUBPANE_HEADER_TEXT: "feathers.subpane.header.text",
|
||||
SUBPANE_BODY_BG: "feathers.subpane.body.bg",
|
||||
SUBPANE_BODY_BORDER: "feathers.subpane.body.border",
|
||||
GROUP_BG: "feathers.group.bg",
|
||||
GROUP_BORDER: "feathers.group.border",
|
||||
GROUP_HEADER_TEXT: "feathers.group.header.text",
|
||||
LISTROW_BG: "feathers.listrow.bg",
|
||||
LISTROW_BG_HOVER: "feathers.listrow.bg.hover",
|
||||
LISTROW_BG_SELECTED: "feathers.listrow.bg.selected",
|
||||
LISTROW_TEXT: "feathers.listrow.text",
|
||||
LISTROW_TEXT_DISABLED: "feathers.listrow.text.disabled",
|
||||
DIALOG_BG: "feathers.dialog.bg",
|
||||
DIALOG_BORDER: "feathers.dialog.border",
|
||||
DIALOG_HEADER_BG: "feathers.dialog.header.bg",
|
||||
DIALOG_TEXT: "feathers.dialog.text",
|
||||
DIALOG_HEADER_TEXT: "feathers.dialog.header.text",
|
||||
} as const;
|
||||
|
||||
/** a design token: one of `tokens`' ids */
|
||||
export type ThemeToken = (typeof tokens)[keyof typeof tokens];
|
||||
@@ -0,0 +1,93 @@
|
||||
// bevy_text's EditableText and TextCursorStyle on a bevy_ui Node (bevy_ui text_input_layout.rs), drawn by the page
|
||||
// (docs/control.feature FC0a). The node measures as Bevy's TextInputMeasure does: visible_lines lines of its line
|
||||
// height high (rounded up), visible_width "0"s wide (CSS's ch is the advance of "0", as Bevy measures it), else the
|
||||
// width it's given. Its text is drawn as a Text's, and the caret, when it has focus, is parley's cursor_geometry: a
|
||||
// bar cursor_width x the font size wide from the caret's x, its line's block high, at the text's end
|
||||
// (EditableText::new queues TextEnd). Bevy blinks it from the moment focus lands: shown for the first half of each
|
||||
// cursor_blink_period, here from frame 0 (AutoFocus). Typing, selection and scrolling need input.
|
||||
import type { CSSProperties, ReactNode } from "react";
|
||||
import { useCurrentFrame, useVideoConfig } from "@raea/app/clock";
|
||||
import { Node, Text, textCss, type NodeProps, type TextStyleProps, type TextProps } from "./ui";
|
||||
import { LinearRgba, Srgba } from "./colors";
|
||||
import { over } from "./ui-val";
|
||||
|
||||
type Color = Srgba | LinearRgba | string;
|
||||
|
||||
/** bevy_text's TextCursorStyle (color: SLATE_700 by default). @bevy bevy_text::TextCursorStyle */
|
||||
export interface TextCursorStyle {
|
||||
color?: Color;
|
||||
selection_color?: Color;
|
||||
unfocused_selection_color?: Color;
|
||||
selected_text_color?: Color;
|
||||
selection_radius?: number;
|
||||
}
|
||||
|
||||
/** tailwind's SLATE_700, TextCursorStyle's default caret */
|
||||
const SLATE_700 = new Srgba(0.2, 0.25490196, 0.33333334, 1);
|
||||
|
||||
export interface EditableTextProps extends NodeProps, TextStyleProps {
|
||||
/** the text it starts with (EditableText::new) */
|
||||
children?: string;
|
||||
/** visible_lines: its height in lines (1 by default; null leaves the height to the layout) */
|
||||
visible_lines?: number | null;
|
||||
/** visible_width: its width in "0"s (None by default: the width it's given) */
|
||||
visible_width?: number | null;
|
||||
/** allow_newlines (false by default): Enter adds a line, under input */
|
||||
allow_newlines?: boolean;
|
||||
/** cursor_width: the caret's width as a share of the font size (0.2 by default) */
|
||||
cursor_width?: number;
|
||||
/** cursor_blink_period in seconds (1 by default) */
|
||||
cursor_blink_period?: number;
|
||||
/** TextCursorStyle */
|
||||
cursor_style?: TextCursorStyle;
|
||||
/** AutoFocus: it has the input focus, so its caret is drawn */
|
||||
auto_focus?: boolean;
|
||||
/** TextLayout's justify and linebreak */
|
||||
justify?: TextProps["justify"];
|
||||
linebreak?: TextProps["linebreak"];
|
||||
}
|
||||
|
||||
/** A text input's text, its caret drawn while it has focus. @bevy bevy_text::EditableText */
|
||||
export function EditableText({ children = "", visible_lines = 1, visible_width = null, allow_newlines = false, cursor_width = 0.2, cursor_blink_period = 1, cursor_style, auto_focus = false, justify, linebreak, font, font_size, weight, style, font_width, color, line_height, font_variations, font_features, letter_spacing, ...node }: EditableTextProps) {
|
||||
if (typeof children !== "string") throw new TypeError(`EditableText: its text is one string, got ${JSON.stringify(children)}`);
|
||||
if (visible_lines !== null && !(visible_lines > 0 && Number.isFinite(visible_lines))) throw new RangeError(`EditableText: visible_lines is above 0 or null, got ${visible_lines}`);
|
||||
if (visible_width !== null && !(visible_width > 0 && Number.isFinite(visible_width))) throw new RangeError(`EditableText: visible_width is above 0 or null, got ${visible_width}`);
|
||||
if (!(cursor_width >= 0 && Number.isFinite(cursor_width))) throw new RangeError(`EditableText: cursor_width is 0 or more, got ${cursor_width}`);
|
||||
if (!(cursor_blink_period > 0 && Number.isFinite(cursor_blink_period))) throw new RangeError(`EditableText: cursor_blink_period is above 0 (seconds), got ${cursor_blink_period}`);
|
||||
void allow_newlines;
|
||||
const textStyle: TextStyleProps = { font, font_size, weight, style, font_width, color, line_height, font_variations, font_features, letter_spacing };
|
||||
const { css } = textCss("EditableText", textStyle);
|
||||
const sizePx = parseFloat(String(css.fontSize));
|
||||
const lh = css.lineHeight;
|
||||
const linePx = typeof lh === "number" ? lh * sizePx : parseFloat(String(lh));
|
||||
const exact = String(css.fontSize).endsWith("px") && Number.isFinite(linePx);
|
||||
// TextInputMeasure: lines x the line height, rounded up (Vec2::ceil)
|
||||
const line = exact ? `${linePx}px` : typeof lh === "number" ? `${lh}em` : String(lh);
|
||||
// the measured box: Bevy's content size (lines x the line height, rounded up; visible_width "0"s, which CSS's ch is
|
||||
// in the box's own font), else the width the node gives it (flex 1 from 0: Bevy's measure takes the available width)
|
||||
const box: CSSProperties = {
|
||||
fontFamily: css.fontFamily, fontSize: css.fontSize, fontWeight: css.fontWeight, fontStyle: css.fontStyle, fontStretch: css.fontStretch,
|
||||
overflow: "hidden", minWidth: 0, ...(visible_width === null ? { flex: "1 1 0px" } : { width: `${visible_width}ch`, flex: "0 0 auto" }),
|
||||
};
|
||||
if (visible_lines !== null) box.height = exact ? `${Math.ceil(visible_lines * linePx)}px` : `calc(${visible_lines} * ${line})`;
|
||||
const frame = useCurrentFrame();
|
||||
const { fps } = useVideoConfig();
|
||||
const shown = auto_focus && (frame / fps) % cursor_blink_period < cursor_blink_period / 2;
|
||||
const caret = shown ? <Caret width={cursor_width * sizePx} height={line} color={cursor_style?.color ?? SLATE_700} /> : null;
|
||||
return (
|
||||
<Node {...node}>
|
||||
<div style={box}>
|
||||
<Text {...textStyle} justify={justify} linebreak={linebreak}>
|
||||
{children}
|
||||
{caret}
|
||||
</Text>
|
||||
</div>
|
||||
</Node>
|
||||
);
|
||||
}
|
||||
|
||||
/** the caret: a bar at the caret's x, its line's block high, taking no room in the line */
|
||||
function Caret({ width, height, color }: { width: number; height: string; color: Color }): ReactNode {
|
||||
const background = over("EditableText", "cursor_style.color", color, undefined).css;
|
||||
return <span data-raea-caret="" style={{ display: "inline-block", width: `${width}px`, height, marginRight: `${-width}px`, verticalAlign: "top", background }} />;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// @raea/render/feathers: bevy_feathers, Bevy's widget set (bevy3d/feathers).
|
||||
export * from "./bevy3d/feathers/index";
|
||||
@@ -41,6 +41,10 @@ with a capital, hooks with `use`. A component's props are in its file.
|
||||
|
||||
`Hsla`, `LinearRgba`, `Oklaba`, `Oklcha`, `Srgba`, `Xyza`, `kelvin`, `toHex`
|
||||
|
||||
## `raea/feathers` (sdk/raea/src/feathers.ts)
|
||||
|
||||
`FeathersButton`, `ThemeContext`, `ThemedText`, `UiTheme`, `VirtualKeyboard`, `context_color`, `create_dark_theme`, `fonts`, `palette`, `size`, `to_border_radius`, `tokens`, `useThemeColor`
|
||||
|
||||
## `raea/gizmos` (sdk/raea/src/gizmos.ts)
|
||||
|
||||
`Gizmo`
|
||||
@@ -99,7 +103,7 @@ with a capital, hooks with `use`. A component's props are in its file.
|
||||
|
||||
## `raea/ui` (sdk/raea/src/ui.ts)
|
||||
|
||||
`AbsoluteFill`, `AngularColorStop`, `BorderRadius`, `BoxShadow`, `ColorStop`, `ConicGradient`, `CornerRadius`, `FontFeatureTag`, `FontSource`, `FontVariationTag`, `FontWidth`, `GhostNode`, `GlobalUiDebugOptions`, `GridPlacement`, `GridTrack`, `ImageNode`, `ImagePlugin`, `InlineImage`, `LinearGradient`, `Node`, `Overflow`, `OverflowClipMargin`, `RadialGradient`, `RepeatedGridTrack`, `Rot2`, `Scrollbar`, `ScrollbarThumb`, `Text`, `Text2d`, `TextShadow`, `TextSpan`, `TextureAtlasLayout`, `UiPosition`, `UiRect`, `UiScale`, `UiTargetCamera`, `UiTexture`, `UiTransform`, `Val2`, `Viewport`, `auto`, `percent`, `px`, `targetImage`, `vh`, `vmax`, `vmin`, `vw`
|
||||
`AbsoluteFill`, `AngularColorStop`, `BorderRadius`, `BoxShadow`, `ColorStop`, `ConicGradient`, `CornerRadius`, `EditableText`, `FontFeatureTag`, `FontSource`, `FontVariationTag`, `FontWidth`, `GhostNode`, `GlobalUiDebugOptions`, `GridPlacement`, `GridTrack`, `ImageNode`, `ImagePlugin`, `InlineImage`, `LinearGradient`, `Node`, `Overflow`, `OverflowClipMargin`, `RadialGradient`, `RepeatedGridTrack`, `Rot2`, `Scrollbar`, `ScrollbarThumb`, `Text`, `Text2d`, `TextShadow`, `TextSpan`, `TextureAtlasLayout`, `UiPosition`, `UiRect`, `UiScale`, `UiTargetCamera`, `UiTexture`, `UiTransform`, `Val2`, `Viewport`, `auto`, `percent`, `px`, `targetImage`, `vh`, `vmax`, `vmin`, `vw`
|
||||
|
||||
## `raea/video` (sdk/raea/src/video.ts)
|
||||
|
||||
|
||||
Reference in new issue
Block a user