Compare commits
13
Commits
a3ff244f97
...
v0.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b9f87791c | ||
|
|
62f9839170
|
||
|
|
bfa2f1908c
|
||
|
|
d3cfff86db
|
||
|
|
d6ddd3c3e1
|
||
|
|
48a66ca6c1
|
||
|
|
ba5c0798cb
|
||
|
|
09d2a6b681
|
||
|
|
f3bf816c40
|
||
|
|
1972bc1d49
|
||
|
|
d84e8265b0
|
||
|
|
d16ba7f9c3
|
||
|
|
d7d59cd10f
|
No files matched your search
@@ -47,7 +47,7 @@ jobs:
|
|||||||
ELY_RELEASE_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
ELY_RELEASE_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
WSLENV: ELY_RELEASE_TOKEN
|
WSLENV: ELY_RELEASE_TOKEN
|
||||||
run: |
|
run: |
|
||||||
wsl -d Ubuntu -- bash -lc '
|
wsl -d Ubuntu --exec bash -lc '
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
dir=$HOME/ely-ci/ElyOffice
|
dir=$HOME/ely-ci/ElyOffice
|
||||||
[ -d "$dir/.git" ] || git clone https://git.zacharyzhang.com/ZacharyZhang-NY/ElyOffice.git "$dir"
|
[ -d "$dir/.git" ] || git clone https://git.zacharyzhang.com/ZacharyZhang-NY/ElyOffice.git "$dir"
|
||||||
|
|||||||
Generated
+11
-3
@@ -1923,6 +1923,7 @@ version = "0.1.3"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"ely-platform",
|
"ely-platform",
|
||||||
"ely-ui",
|
"ely-ui",
|
||||||
|
"embed-resource",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1938,6 +1939,7 @@ dependencies = [
|
|||||||
"ely-office",
|
"ely-office",
|
||||||
"ely-platform",
|
"ely-platform",
|
||||||
"ely-ui",
|
"ely-ui",
|
||||||
|
"embed-resource",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"gpui-pre",
|
"gpui-pre",
|
||||||
"image",
|
"image",
|
||||||
@@ -1964,7 +1966,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ely-gpui-component"
|
name = "ely-gpui-component"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
source = "git+https://git.zacharyzhang.com/ZacharyZhang-NY/Ely-GPUI-Components?rev=5d6efd46ec0c93b381ec7578561a1273c366025b#5d6efd46ec0c93b381ec7578561a1273c366025b"
|
source = "git+https://git.zacharyzhang.com/ZacharyZhang-NY/Ely-GPUI-Components?rev=bd014707fd47cd9d0651a9af8c1db6033718a6ea#bd014707fd47cd9d0651a9af8c1db6033718a6ea"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alacritty_terminal",
|
"alacritty_terminal",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
@@ -2032,6 +2034,7 @@ version = "0.1.3"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"ely-platform",
|
"ely-platform",
|
||||||
"ely-ui",
|
"ely-ui",
|
||||||
|
"embed-resource",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2046,6 +2049,7 @@ dependencies = [
|
|||||||
"ely-platform",
|
"ely-platform",
|
||||||
"ely-ui",
|
"ely-ui",
|
||||||
"ely-web-content",
|
"ely-web-content",
|
||||||
|
"embed-resource",
|
||||||
"futures",
|
"futures",
|
||||||
"gpui-pre",
|
"gpui-pre",
|
||||||
"jiff",
|
"jiff",
|
||||||
@@ -2086,6 +2090,7 @@ dependencies = [
|
|||||||
"ely-pdf-engine",
|
"ely-pdf-engine",
|
||||||
"ely-platform",
|
"ely-platform",
|
||||||
"ely-ui",
|
"ely-ui",
|
||||||
|
"embed-resource",
|
||||||
"gpui-pre",
|
"gpui-pre",
|
||||||
"image",
|
"image",
|
||||||
"log",
|
"log",
|
||||||
@@ -2117,6 +2122,7 @@ dependencies = [
|
|||||||
"core-foundation 0.10.0",
|
"core-foundation 0.10.0",
|
||||||
"core-video",
|
"core-video",
|
||||||
"directories",
|
"directories",
|
||||||
|
"ely-ipc",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"image",
|
"image",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -2151,6 +2157,7 @@ dependencies = [
|
|||||||
"ely-office",
|
"ely-office",
|
||||||
"ely-platform",
|
"ely-platform",
|
||||||
"ely-ui",
|
"ely-ui",
|
||||||
|
"embed-resource",
|
||||||
"gpui-pre",
|
"gpui-pre",
|
||||||
"gpui-pre-platform",
|
"gpui-pre-platform",
|
||||||
"image",
|
"image",
|
||||||
@@ -2169,6 +2176,7 @@ dependencies = [
|
|||||||
"ely-office",
|
"ely-office",
|
||||||
"ely-platform",
|
"ely-platform",
|
||||||
"ely-ui",
|
"ely-ui",
|
||||||
|
"embed-resource",
|
||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
"gpui-pre",
|
"gpui-pre",
|
||||||
"log",
|
"log",
|
||||||
@@ -2180,10 +2188,12 @@ dependencies = [
|
|||||||
name = "ely-tree"
|
name = "ely-tree"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"dunce",
|
||||||
"ely-files",
|
"ely-files",
|
||||||
"ely-gpui-component",
|
"ely-gpui-component",
|
||||||
"ely-platform",
|
"ely-platform",
|
||||||
"ely-ui",
|
"ely-ui",
|
||||||
|
"embed-resource",
|
||||||
"futures",
|
"futures",
|
||||||
"gpui-pre",
|
"gpui-pre",
|
||||||
"jiff",
|
"jiff",
|
||||||
@@ -2957,8 +2967,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "gpui-pre"
|
name = "gpui-pre"
|
||||||
version = "0.3.8"
|
version = "0.3.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d7f0bc3ebba070f8981b3f8e905a12f47d27794a30d029e59cdb9edf7a4b3360"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"accesskit",
|
"accesskit",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
|||||||
+5
-2
@@ -8,16 +8,18 @@ exclude = ["engines", "reference"]
|
|||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.95"
|
rust-version = "1.95"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "MIT"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
|
embed-resource = "=3.0.11"
|
||||||
csv = "1"
|
csv = "1"
|
||||||
encoding_rs = "0.8"
|
encoding_rs = "0.8"
|
||||||
jiff = "0.2"
|
jiff = "0.2"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
directories = "6"
|
directories = "6"
|
||||||
ely-gpui-component = { git = "https://git.zacharyzhang.com/ZacharyZhang-NY/Ely-GPUI-Components", rev = "5d6efd46ec0c93b381ec7578561a1273c366025b" }
|
dunce = "1"
|
||||||
|
ely-gpui-component = { git = "https://git.zacharyzhang.com/ZacharyZhang-NY/Ely-GPUI-Components", rev = "bd014707fd47cd9d0651a9af8c1db6033718a6ea" }
|
||||||
env_logger = "0.11"
|
env_logger = "0.11"
|
||||||
gpui = { package = "gpui-pre", version = "=0.3.8", default-features = false, features = ["stacker"] }
|
gpui = { package = "gpui-pre", version = "=0.3.8", default-features = false, features = ["stacker"] }
|
||||||
gpui_platform = { package = "gpui-pre-platform", version = "=0.3.8", features = ["font-kit"] }
|
gpui_platform = { package = "gpui-pre-platform", version = "=0.3.8", features = ["font-kit"] }
|
||||||
@@ -66,4 +68,5 @@ ely-ui = { path = "crates/ely-ui" }
|
|||||||
all = { level = "warn", priority = -1 }
|
all = { level = "warn", priority = -1 }
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
gpui-pre = { path = "vendor/gpui-pre" }
|
||||||
gpui-pre-windows = { path = "vendor/gpui-pre-windows" }
|
gpui-pre-windows = { path = "vendor/gpui-pre-windows" }
|
||||||
@@ -1,661 +1,21 @@
|
|||||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
MIT License
|
||||||
Version 3, 19 November 2007
|
|
||||||
|
Copyright (c) 2026 Yang Zhang
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this license document, but changing it is not allowed.
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
Preamble
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
The GNU Affero General Public License is a free, copyleft license for
|
furnished to do so, subject to the following conditions:
|
||||||
software and other kinds of works, specifically designed to ensure
|
|
||||||
cooperation with the community in the case of network server software.
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
our General Public Licenses are intended to guarantee your freedom to
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
share and change all versions of a program--to make sure it remains free
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
software for all its users.
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
When we speak of free software, we are referring to freedom, not
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
SOFTWARE.
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
Developers that use our General Public Licenses protect your rights
|
|
||||||
with two steps: (1) assert copyright on the software, and (2) offer
|
|
||||||
you this License which gives you legal permission to copy, distribute
|
|
||||||
and/or modify the software.
|
|
||||||
|
|
||||||
A secondary benefit of defending all users' freedom is that
|
|
||||||
improvements made in alternate versions of the program, if they
|
|
||||||
receive widespread use, become available for other developers to
|
|
||||||
incorporate. Many developers of free software are heartened and
|
|
||||||
encouraged by the resulting cooperation. However, in the case of
|
|
||||||
software used on network servers, this result may fail to come about.
|
|
||||||
The GNU General Public License permits making a modified version and
|
|
||||||
letting the public access it on a server without ever releasing its
|
|
||||||
source code to the public.
|
|
||||||
|
|
||||||
The GNU Affero General Public License is designed specifically to
|
|
||||||
ensure that, in such cases, the modified source code becomes available
|
|
||||||
to the community. It requires the operator of a network server to
|
|
||||||
provide the source code of the modified version running there to the
|
|
||||||
users of that server. Therefore, public use of a modified version, on
|
|
||||||
a publicly accessible server, gives the public access to the source
|
|
||||||
code of the modified version.
|
|
||||||
|
|
||||||
An older license, called the Affero General Public License and
|
|
||||||
published by Affero, was designed to accomplish similar goals. This is
|
|
||||||
a different license, not a version of the Affero GPL, but Affero has
|
|
||||||
released a new version of the Affero GPL which permits relicensing under
|
|
||||||
this license.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, if you modify the
|
|
||||||
Program, your modified version must prominently offer all users
|
|
||||||
interacting with it remotely through a computer network (if your version
|
|
||||||
supports such interaction) an opportunity to receive the Corresponding
|
|
||||||
Source of your version by providing access to the Corresponding Source
|
|
||||||
from a network server at no charge, through some standard or customary
|
|
||||||
means of facilitating copying of software. This Corresponding Source
|
|
||||||
shall include the Corresponding Source for any work covered by version 3
|
|
||||||
of the GNU General Public License that is incorporated pursuant to the
|
|
||||||
following paragraph.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the work with which it is combined will remain governed by version
|
|
||||||
3 of the GNU General Public License.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU Affero General Public License from time to time. Such new versions
|
|
||||||
will be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU Affero General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU Affero General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU Affero General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If your software can interact with users remotely through a computer
|
|
||||||
network, you should also make sure that it provides a way for users to
|
|
||||||
get its source. For example, if your program is a web application, its
|
|
||||||
interface could display a "Source" link that leads users to an archive
|
|
||||||
of the code. There are many ways you could offer source, and different
|
|
||||||
solutions will be better for different programs; see section 13 for the
|
|
||||||
specific requirements.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
|
||||||
<http://www.gnu.org/licenses/>.
|
|
||||||
@@ -757,7 +757,7 @@ Doc、Table、Show 的 PDF 输出由 LOK 完成,不要求安装 ElyPDF。ElyMa
|
|||||||
|
|
||||||
### 21.1 自有代码默认许可
|
### 21.1 自有代码默认许可
|
||||||
|
|
||||||
本 PRD 对新增应用代码采用 AGPL-3.0-or-later 作为发行默认,便于与 MuPDF 的开源使用路线保持一致。Ely GPUI Components 继续保留现有 MIT/Apache-2.0 许可,不因被应用使用而改写其许可证。[S1]
|
本 PRD 对新增应用代码采用 MIT 作为发行默认(用户 2026-10-19 定,原为 AGPL-3.0-or-later)。MIT 只管 Ely 的自有代码:链接 MuPDF 的 ElyPDF 发行包整体仍须按 MuPDF 的 AGPL 条款提供对应源码。Ely GPUI Components 继续保留现有 MIT/Apache-2.0 许可,不因被应用使用而改写其许可证。[S1]
|
||||||
|
|
||||||
第三方代码保持原许可证。不得把 LibreOffice、Git 或其他依赖的版权声明统一替换成 Ely 的声明。最终发行须按实际链接、进程调用、修改和打包方式审查,进程隔离不作为免除许可义务的依据。
|
第三方代码保持原许可证。不得把 LibreOffice、Git 或其他依赖的版权声明统一替换成 Ely 的声明。最终发行须按实际链接、进程调用、修改和打包方式审查,进程隔离不作为免除许可义务的依据。
|
||||||
|
|
||||||
|
|||||||
@@ -44,4 +44,4 @@ Packages: `packaging/macos/release.sh` writes each app's `.app` and `.dmg`, the
|
|||||||
|
|
||||||
## Licence
|
## Licence
|
||||||
|
|
||||||
AGPL-3.0-or-later (`LICENSE`). Third-party components keep their own licences; see `docs/licenses.md`.
|
MIT (`LICENSE`). Third-party components keep their own licences; see `docs/licenses.md`.
|
||||||
@@ -27,7 +27,7 @@ crates/ ely-ui ely-platform ely-ipc(应用与引擎 worker 之间的帧
|
|||||||
reference/ 上游源码,只读,不属于本项目,不审查
|
reference/ 上游源码,只读,不属于本项目,不审查
|
||||||
engines/ 下载的二进制与引擎构建产物,不入库,不审查;mupdf-src 是 reference/mupdf 加 patches/mupdf 的构建副本;content/<应用> 是网页内容的构建产物
|
engines/ 下载的二进制与引擎构建产物,不入库,不审查;mupdf-src 是 reference/mupdf 加 patches/mupdf 的构建副本;content/<应用> 是网页内容的构建产物
|
||||||
patches/ 对上游的补丁,随源码发行(libreoffice、mupdf)
|
patches/ 对上游的补丁,随源码发行(libreoffice、mupdf)
|
||||||
vendor/ crates.io 上游 crate 的副本加本项目的修复,经工作区 `[patch.crates-io]` 换入(gpui-pre-windows);首个提交为原样,其后是修复
|
vendor/ crates.io 上游 crate 的副本加本项目的修复,经工作区 `[patch.crates-io]` 换入(gpui-pre、gpui-pre-windows);首个提交为原样,其后是修复
|
||||||
packaging/ 三端打包脚本,apps.tsv 是八个应用的二进制名、名字、桌面分类与发布批次;icons/ 由图标母版渲染各端格式;libreoffice/ely.xcd 是内核的默认配置层
|
packaging/ 三端打包脚本,apps.tsv 是八个应用的二进制名、名字、桌面分类与发布批次;icons/ 由图标母版渲染各端格式;libreoffice/ely.xcd 是内核的默认配置层
|
||||||
assets/ icons/ 是八个应用的图标母版(SVG)与渲染出的 icns、png、ico,规则见其 README
|
assets/ icons/ 是八个应用的图标母版(SVG)与渲染出的 icns、png、ico,规则见其 README
|
||||||
dist/ 打包产物,不入库
|
dist/ 打包产物,不入库
|
||||||
@@ -40,7 +40,7 @@ site/ 官网(Vite 8、pnpm、TypeScript,无框架;等轴 SVG 积木
|
|||||||
|
|
||||||
## 组件映射
|
## 组件映射
|
||||||
|
|
||||||
依赖 `ely-gpui-component`(pin 5d6efd4,gpui 为 crates.io 的 `gpui-pre` =0.3.8)。名字取自 `reference/Ely-GPUI-Components/src`。gpui 用法规则见该仓库 `AGENTS.md`。`tests/scripts/agents_md.py` 核对下表每个名字都是组件库公开项。
|
依赖 `ely-gpui-component`(pin bd01470,gpui 为 crates.io 的 `gpui-pre` =0.3.8)。名字取自 `reference/Ely-GPUI-Components/src`。gpui 用法规则见该仓库 `AGENTS.md`。`tests/scripts/agents_md.py` 核对下表每个名字都是组件库公开项。
|
||||||
|
|
||||||
| 需要 | 用 |
|
| 需要 | 用 |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
@@ -191,7 +191,7 @@ cargo run -p ely-doc 启动一个应用(ElyDoc 先 cargo build -p ely
|
|||||||
|
|
||||||
## 决策
|
## 决策
|
||||||
|
|
||||||
- 2026-10-01:上游版本以 `scripts/fetch-references.sh` 为准。LibreOffice 26.2.6(8221e31)、MuPDF 1.28.5(8ad45e9)、gpui 为 `gpui-pre` =0.3.8 与 `gpui-pre-platform` =0.3.8(crates.io,2026-10-07 起,随组件库 K01)、组件库 5d6efd4(2026-10-09 起)。
|
- 2026-10-01:上游版本以 `scripts/fetch-references.sh` 为准。LibreOffice 26.2.6(8221e31)、MuPDF 1.28.5(8ad45e9)、gpui 为 `gpui-pre` =0.3.8 与 `gpui-pre-platform` =0.3.8(crates.io,2026-10-07 起,随组件库 K01)、组件库 bd01470(2026-10-11 起)。
|
||||||
- 2026-10-02:组件库 7380afb 起:对话框与面板的 Enter 提交改走字段的 key-down 动作(macOS IME 天然守卫,不再提前提交);面板族文案经组件 `i18n::text`(内建 en/zh-CN,应用目录可覆盖);核心控件带 role/aria;对话框带角色、名称与说明,Cancel/Close 与禁用说明本地化。同仓库 `~/Documents/GitHub/Ely-GPUI-Components` 修复并推送(2026-10-09 起推到 git.zacharyzhang.com,HTTPS,令牌在本机钥匙串)。2026-10-04 组件库 b6cb94c:`NumberInput::on_commit` 只在 Enter、失焦、步进、拖动时触发,键入不触发;改文档的数值框用它,否则每个键入数字都成一条内核命令与一步撤销。同批带入上游的 Checkbox、Switch、Select 等 role/aria 与 RenderSurface。c0f17ee:`ToggleButton::disabled`(不可按、无 Tab 停靠、说明不可用,提示可写原因)。967d1e4:`ContextMenu::manual`(按属主编号的请求在某点打开,右键不开),供行在按下之后才到的菜单,如内核给的拼写建议。
|
- 2026-10-02:组件库 7380afb 起:对话框与面板的 Enter 提交改走字段的 key-down 动作(macOS IME 天然守卫,不再提前提交);面板族文案经组件 `i18n::text`(内建 en/zh-CN,应用目录可覆盖);核心控件带 role/aria;对话框带角色、名称与说明,Cancel/Close 与禁用说明本地化。同仓库 `~/Documents/GitHub/Ely-GPUI-Components` 修复并推送(2026-10-09 起推到 git.zacharyzhang.com,HTTPS,令牌在本机钥匙串)。2026-10-04 组件库 b6cb94c:`NumberInput::on_commit` 只在 Enter、失焦、步进、拖动时触发,键入不触发;改文档的数值框用它,否则每个键入数字都成一条内核命令与一步撤销。同批带入上游的 Checkbox、Switch、Select 等 role/aria 与 RenderSurface。c0f17ee:`ToggleButton::disabled`(不可按、无 Tab 停靠、说明不可用,提示可写原因)。967d1e4:`ContextMenu::manual`(按属主编号的请求在某点打开,右键不开),供行在按下之后才到的菜单,如内核给的拼写建议。
|
||||||
- 2026-10-06:审查者为探针复制的源码树须用自己的 `CARGO_TARGET_DIR`(`scripts/review.sh` 写明);写完结论前删掉这些副本与其构建目录(曾积到 /tmp 近 900 GB,磁盘写满、链接失败):曾编进本仓库 `target/`,ely-lok 里烘焙的源码路径指向已删的副本,单测找不到 worker。
|
- 2026-10-06:审查者为探针复制的源码树须用自己的 `CARGO_TARGET_DIR`(`scripts/review.sh` 写明);写完结论前删掉这些副本与其构建目录(曾积到 /tmp 近 900 GB,磁盘写满、链接失败):曾编进本仓库 `target/`,ely-lok 里烘焙的源码路径指向已删的副本,单测找不到 worker。
|
||||||
- 2026-10-03:每条任务由 `scripts/review.sh` 在 herdr 分栏里交给 codex(gpt-6.1-sol,effort high)审查,最多三轮。此前各轮用 gpt-6-astra xhigh。2026-10-10(用户定):`--yolo`、`service_tier="fast"`、effort xhigh,每条最多五轮;herdr 直接启动 codex 程序,不经 shell 别名。
|
- 2026-10-03:每条任务由 `scripts/review.sh` 在 herdr 分栏里交给 codex(gpt-6.1-sol,effort high)审查,最多三轮。此前各轮用 gpt-6-astra xhigh。2026-10-10(用户定):`--yolo`、`service_tier="fast"`、effort xhigh,每条最多五轮;herdr 直接启动 codex 程序,不经 shell 别名。
|
||||||
@@ -228,7 +228,7 @@ cargo run -p ely-doc 启动一个应用(ElyDoc 先 cargo build -p ely
|
|||||||
- 2026-10-06(用户定):ElyMail 在八个应用里最后做:任务表中 C12 移到 C15 之后、C16 之前;CEF 内容宿主随 ElyMark 先建(C14.0),邮件编号依次前移。
|
- 2026-10-06(用户定):ElyMail 在八个应用里最后做:任务表中 C12 移到 C15 之后、C16 之前;CEF 内容宿主随 ElyMark 先建(C14.0),邮件编号依次前移。
|
||||||
- 2026-10-06(用户定):`ely-office` 的外壳不再只服务 LOK:`Host` 带关联类型 `Engine`(`ely_office::Engine`:后台载入、视图、撤销历史的标记、写出、关闭,视图的落定、编辑计数、待落地、焦点与事件),`Tab` 与 `Core` 按引擎取文档、视图与 worker 类型。LOK 的实现在 `ely_office::lok`(`Lok`、`start`、只对 LOK 的 `Commands` 即 `run_active`/`run_in`;查找替换、面板、图表仍只限 LOK);MuPDF 的在 `apps/ely-pdf/src/engine.rs`(`Pdf`;worker 首次载入才起,`Mupdf::get`)。`Kind::macros` 为 `None` 表示该格式无宏,不扫文件。ElyPDF 每个标签一个 `PdfView` 实体(页面、图块、文字、选择、找到的词都在里面,自己绘制),`Viewer` 只管标签条、书签栏、查找框与状态栏;打开、密码、关闭询问与保存走外壳。外壳的密码框:对话框开着时后到的加锁文件排队(`Core::locked`),对话框关闭(含取消、提交)后下一个再问;每次询问一个身份(按输入框实体),连续询问的 Esc 各归各的;提交时对话框先关、再载入。ElyDoc 的加锁测试原先清的是应用自己的对话框字段,改为清外壳的。
|
- 2026-10-06(用户定):`ely-office` 的外壳不再只服务 LOK:`Host` 带关联类型 `Engine`(`ely_office::Engine`:后台载入、视图、撤销历史的标记、写出、关闭,视图的落定、编辑计数、待落地、焦点与事件),`Tab` 与 `Core` 按引擎取文档、视图与 worker 类型。LOK 的实现在 `ely_office::lok`(`Lok`、`start`、只对 LOK 的 `Commands` 即 `run_active`/`run_in`;查找替换、面板、图表仍只限 LOK);MuPDF 的在 `apps/ely-pdf/src/engine.rs`(`Pdf`;worker 首次载入才起,`Mupdf::get`)。`Kind::macros` 为 `None` 表示该格式无宏,不扫文件。ElyPDF 每个标签一个 `PdfView` 实体(页面、图块、文字、选择、找到的词都在里面,自己绘制),`Viewer` 只管标签条、书签栏、查找框与状态栏;打开、密码、关闭询问与保存走外壳。外壳的密码框:对话框开着时后到的加锁文件排队(`Core::locked`),对话框关闭(含取消、提交)后下一个再问;每次询问一个身份(按输入框实体),连续询问的 Esc 各归各的;提交时对话框先关、再载入。ElyDoc 的加锁测试原先清的是应用自己的对话框字段,改为清外壳的。
|
||||||
- 2026-10-07:本地 Web 内容宿主(C14.0,§17.3)。`crates/ely-web-content`:CEF 154.0.32(Chromium 154.0.8037.58,cef-rs a712ad9,`default-features = false`),`scripts/fetch-cef.sh` 取 minimal 包到 `engines/cef`,`.cargo/config.toml` 的 `CEF_PATH` 让构建用它。进程:应用的 `main` 先调 `ely_web_content::subprocess()`(参数里有 `--type=` 即为 CEF 子进程,载入框架后 `execute_process`,不碰 GPUI);开发构建子进程即应用本身的二进制;macOS 包里是五个辅助应用(`<二进制名> Helper`、`(GPU)`、`(Renderer)`、`(Plugin)`、`(Alerts)`,`Contents/Frameworks`,`LSUIElement`,可执行文件为 `ely-web-helper`),框架在 `Contents/Frameworks`,`packaging/macos/bundle.sh` 对依赖 ely-web-content 的应用自动放入并先签内层;查找次序 `ELY_CEF`、包内、辅助应用所在、构建时的 `engines/cef`。启动:`start` 在 GPUI 里只做准备(载入框架、给 NSApp 的类补上 Chromium 要的 `isHandlingSendEvent`、`setHandlingSendEvent:` 与包住 `sendEvent:`,并加 `CrAppProtocol`、`CrAppControlProtocol`),`initialize` 与建浏览器都在消息泵任务里、GPUI 的更新之外进行(实测:在更新里同步调 CEF,CEF 转动 AppKit 的循环,GPUI 报 RefCell 已借用、整窗不画);浏览器在泵里同步建(`browser_host_create_browser_sync`;原为异步,建好之前视图已释放时浏览器无人关闭),视图要么在建之前已走(不建),要么有浏览器可关。凡在 GPUI 里对 CEF 的调用(输入、焦点、尺寸、脚本、缩放、重新载入、关闭)都排进主线程的队列,由泵在下一轮、更新之外依次执行(实测:在实体释放时同步关浏览器,CEF 转动 AppKit 的循环去校验菜单,GPUI 的菜单回调遇已借用的应用状态而中止,约三成复现)。泵:外部消息泵,按 `on_schedule_message_pump_work` 的时间,另照 cefclient 每轮后以 1/30 秒兜底(实测:只按请求时第一轮后 CEF 再不请求,页面不载入);空闲时 CPU 约 1.5%。离屏渲染须用 Alloy 风格(`runtime_style`;Chrome 风格不出画面)。同一缓存目录只允许一个实例,第二个启动时报出占用它的进程号。画面:`on_paint` 的 BGRA 直接成 GPUI 图像,上一帧在下一次绘制时从图集释放(`drop_image`);光标随页面。输入:鼠标点击、移动、滚轮(行按 40 点),键照 cefclient 的 macOS 做法:键盘按下带字符与系统键码发 `KEYDOWN` 再发 `CHAR`(退格、回车、方向等用 AppKit 的字符),可打出字的键等 GPUI 的输入法回调后以所打的字发同样两个事件,多字或组字经 `ime_commit_text`/`ime_set_composition`(无替换范围时用 CEF 的“无范围”,两端为最大值;传空指针 CEF 不收);松开带同一字符(不带时 Chromium 当作又按一次,实测退格删两个字);拷贝、剪切、粘贴、全选走框架命令。焦点随 GPUI 的焦点给页面。页面与应用之间:CEF 的消息路由,页面调 `window.elyQuery({request, onSuccess, onFailure})`(`onSuccess` 与 `onFailure` 都必须有,缺一路由即不发;页面载入时路由未就绪,早到的查询丢失),应用收到 `Event::Query(请求, 回复)`;应用以 `run_js` 调页面。主题:每次载入与主题变化时把调色板、代码色、字体与字号比例、深浅写成 `:root` 的 `--ely-*` 变量与 `color-scheme`。缩放 `set_zoom(倍数)`。页面只许载入所在内容文件夹里的文件:按真实路径判定(`..`、百分号转义、指向外面的符号链接都算外面,文件须存在),导航与每个资源请求(脚本、图片、样式、请求等)都过这道门,资源另许 `data:` 与本页的 `blob:`,其余一律取消;另在每个 CEF 进程以 `--proxy-server=127.0.0.1:9` 与 `--proxy-bypass-list=<-loopback>` 把一切网络(含本机回环与 WebSocket,后者不经资源回调)送往不通的代理;WebRTC 走 UDP 不经代理,故另以 `--force-webrtc-ip-handling-policy=disable_non_proxied_udp` 只许它经代理,并在每个页面上下文建立时、页面脚本之前删去 `RTCPeerConnection` 等构造(渲染进程的 `on_context_created`);页面的地址由真实路径逐字节转义生成(文件名含 `#`、`?` 照样载入);用户点出的链接以 `Event::Leave` 交给应用;`WebView::open_inert` 开的页面不运行脚本(`BrowserSettings.javascript` 关),ElyMark 的打印与导出 PDF 暂存页用它,文档里的 HTML 脚本不运行(M-15);页面的警告与错误只记行号(警告文字与来源都可由文档伪造,不进日志);页面自己的诊断经 `elyQuery` 交应用记录。载入失败(主框架,停止不算)、渲染进程退出、CEF 起不来都报 `Event::Failed`,页面区改显示组件库的错误视图与“重新载入”(Line truncated
|
- 2026-10-07:本地 Web 内容宿主(C14.0,§17.3)。`crates/ely-web-content`:CEF 154.0.32(Chromium 154.0.8037.58,cef-rs a712ad9,`default-features = false`),`scripts/fetch-cef.sh` 取 minimal 包到 `engines/cef`,`.cargo/config.toml` 的 `CEF_PATH` 让构建用它。进程:应用的 `main` 先调 `ely_web_content::subprocess()`(参数里有 `--type=` 即为 CEF 子进程,载入框架后 `execute_process`,不碰 GPUI);开发构建子进程即应用本身的二进制;macOS 包里是五个辅助应用(`<二进制名> Helper`、`(GPU)`、`(Renderer)`、`(Plugin)`、`(Alerts)`,`Contents/Frameworks`,`LSUIElement`,可执行文件为 `ely-web-helper`),框架在 `Contents/Frameworks`,`packaging/macos/bundle.sh` 对依赖 ely-web-content 的应用自动放入并先签内层;查找次序 `ELY_CEF`、包内、辅助应用所在、构建时的 `engines/cef`。启动:`start` 在 GPUI 里只做准备(载入框架、给 NSApp 的类补上 Chromium 要的 `isHandlingSendEvent`、`setHandlingSendEvent:` 与包住 `sendEvent:`,并加 `CrAppProtocol`、`CrAppControlProtocol`),`initialize` 与建浏览器都在消息泵任务里、GPUI 的更新之外进行(实测:在更新里同步调 CEF,CEF 转动 AppKit 的循环,GPUI 报 RefCell 已借用、整窗不画);浏览器在泵里同步建(`browser_host_create_browser_sync`;原为异步,建好之前视图已释放时浏览器无人关闭),视图要么在建之前已走(不建),要么有浏览器可关。凡在 GPUI 里对 CEF 的调用(输入、焦点、尺寸、脚本、缩放、重新载入、关闭)都排进主线程的队列,由泵在下一轮、更新之外依次执行(实测:在实体释放时同步关浏览器,CEF 转动 AppKit 的循环去校验菜单,GPUI 的菜单回调遇已借用的应用状态而中止,约三成复现)。泵:外部消息泵,按 `on_schedule_message_pump_work` 的时间,另照 cefclient 每轮后以 1/30 秒兜底(实测:只按请求时第一轮后 CEF 再不请求,页面不载入);空闲时 CPU 约 1.5%。离屏渲染须用 Alloy 风格(`runtime_style`;Chrome 风格不出画面)。同一缓存目录只允许一个实例,第二个启动时报出占用它的进程号。画面:`on_paint` 的 BGRA 直接成 GPUI 图像,上一帧在下一次绘制时从图集释放(`drop_image`);光标随页面。输入:鼠标点击、移动、滚轮(行按 40 点),键照 cefclient 的 macOS 做法:键盘按下带字符与系统键码发 `KEYDOWN` 再发 `CHAR`(退格、回车、方向等用 AppKit 的字符),可打出字的键等 GPUI 的输入法回调后以所打的字发同样两个事件,多字或组字经 `ime_commit_text`/`ime_set_composition`(无替换范围时用 CEF 的“无范围”,两端为最大值;传空指针 CEF 不收);松开带同一字符(不带时 Chromium 当作又按一次,实测退格删两个字);拷贝、剪切、粘贴、全选走框架命令。焦点随 GPUI 的焦点给页面。页面与应用之间:CEF 的消息路由,页面调 `window.elyQuery({request, onSuccess, onFailure})`(`onSuccess` 与 `onFailure` 都必须有,缺一路由即不发;页面载入时路由未就绪,早到的查询丢失),应用收到 `Event::Query(请求, 回复)`;应用以 `run_js` 调页面。主题:每次载入与主题变化时把调色板、代码色、字体与字号比例、深浅写成 `:root` 的 `--ely-*` 变量与 `color-scheme`。缩放 `set_zoom(倍数)`。页面只许载入所在内容文件夹里的文件:按真实路径判定(`..`、百分号转义、指向外面的符号链接都算外面,文件须存在),导航与每个资源请求(脚本、图片、样式、请求等)都过这道门,资源另许 `data:` 与本页的 `blob:`,其余一律取消;另在每个 CEF 进程以 `--proxy-server=127.0.0.1:9` 与 `--proxy-bypass-list=<-loopback>` 把一切网络(含本机回环与 WebSocket,后者不经资源回调)送往不通的代理;WebRTC 走 UDP 不经代理,故另以 `--force-webrtc-ip-handling-policy=disable_non_proxied_udp` 只许它经代理,并在每个页面上下文建立时、页面脚本之前删去 `RTCPeerConnection` 等构造(渲染进程的 `on_context_created`);页面的地址由真实路径逐字节转义生成(文件名含 `#`、`?` 照样载入);用户点出的链接以 `Event::Leave` 交给应用;`WebView::open_inert` 开的页面不运行脚本(`BrowserSettings.javascript` 关),ElyMark 的打印与导出 PDF 暂存页用它,文档里的 HTML 脚本不运行(M-15);页面的警告与错误只记行号(警告文字与来源都可由文档伪造,不进日志);页面自己的诊断经 `elyQuery` 交应用记录。载入失败(主框架,停止不算)、渲染进程退出、CEF 起不来都报 `Event::Failed`,页面区改显示组件库的错误视图与“重新载入”(Line truncated
|
||||||
- 2026-10-07:ElyTree 恢复与清理、外部工具、操作规则(C13.6,TREE-13、14,§13.3,QA-19、20)。仓库页第二行:在终端中打开(macOS `open -a Terminal`,其他平台报未构建)、在访达中显示(`reveal_path`)、清理未跟踪的文件…;页底“引用日志”列出 HEAD 最近 200 次移动(`reflog show -z`,位置、Git 写的原因、时间),选中即中间显示该提交(同提交详情,`Whose::Reflog`),上方“在此新建分支…”(找回删掉的分支)与“把当前分支移到此…”:有已暂存的改动即拒绝(`reset --keep` 会丢掉它们,请先提交或取消暂存);否则在后台算出离开该分支的提交,对话框写明分支、从哪到哪、离开的提交(引用日志仍可找回)与“工作区改动保留”,确认后 `reset --keep`(Git 在改动冲突时拒绝;没有任何按钮做硬重置),执行前在写队列里核对 HEAD 仍在预览时的分支(完整引用名,或仍游离)与提交、仍无暂存,任一变了即什么也不做。引用日志的时间是该次移动的时间(`--date=unix` 下的 `%gd`),不是提交时间;选中按事件本身(提交、原因、时间与它在全部引用日志中自最早起的序号,后者新移动不改,同一秒同原因的两次也分得开),同一提交的多条不会一起选中;之后有新的移动时该事件的位置后移,选中与详情跟着它,事件已不在引用日志里即不显示。清理:对话框先由 `git clean -n -d`(勾“包括被忽略的文件”另加 `-x`)得出 Git 会删除的路径(`core.quotePath=false`,其余 C 引号照 Git 规则还原),其中的文件夹当场展开为其中的文件(`ls-files --others`,同一忽略规则,另一仓库不入),对话框逐个列出文件与文件夹;确认后先逐段查每个所列路径:仍在仓库里、途中没有符号链接、文件仍是文件、文件夹仍是文件夹(任一变了即整体拒绝,什么也不删),再以 `git clean -f [-x] -- 所列文件` 删去(只给文件,Git 不递归;此后被跟踪了的文件 Git 留下,也不穿过链接),最后自深而浅删去所列文件夹中已空的(预览后在其中新出现的文件不动,文件夹随之留下),每次都问。文件标题栏多出“在编辑器中打开”(用户在“仓库›选择编辑器…”选的程序,存在数据目录 `tools.json`,字段类型不对与读不出同样报错且不覆盖;macOS 的 .app 经 `open -a`,在后台等它结束,失败即显示其原话;未选时先问)与 Markdown 的“在 ElyMark 中打开”(`ely_platform::apps::open`:按安装布局找同级的应用,macOS 的 `名称.app/Contents/MacOS`,Windows 的 `Ely Office\名称`,开发构建的同一目录;找不到即报错)。锁(§13.3):任何写操作因 Git 的锁文件失败(`….lock': File exists`,或配置文件的 `could not lock config file …: File exists`)时,对话框说明另一个 Git 正在工作、Ely 从不删除锁文件,“重试”把同一写操作重新排队。QA-19:测试都以独立的 Git 命令核对索引、提交、引用与工作区。QA-20:冲突、钩子失败、凭据被拒(本机 401 服务器,显示 Git 的 “terminal prompts disabled” 原话)、锁、变基中断后中止、取消(停止取回)都有窗口测试,结束时仓库状态以 Git 读回核对。切换到系统 Git 目前经 `ELY_GIT`(设置页随 C18.1);状态栏显示所用 Git 的路径与版本。真窗口(macOS):仓库页工具行、清理预览对话框、文件标题栏的编辑器与 ElyMark 按钮,按下后同级的 ely-mark 以该文件启动。未验证:Windows 与 Linux 的终端;ElyMark 打开文件的内容(C14)。
|
- 2026-10-07:ElyTree 恢复与清理、外部工具、操作规则(C13.6,TREE-13、14,§13.3,QA-19、20)。仓库页第二行:在终端中打开(macOS `open -a Terminal`,其他平台报未构建)、在访达中显示(`reveal_path`)、清理未跟踪的文件…;页底“引用日志”列出 HEAD 最近 200 次移动(`reflog show -z`,位置、Git 写的原因、时间),选中即中间显示该提交(同提交详情,`Whose::Reflog`),上方“在此新建分支…”(找回删掉的分支)与“把当前分支移到此…”:有已暂存的改动即拒绝(`reset --keep` 会丢掉它们,请先提交或取消暂存);否则在后台算出离开该分支的提交,对话框写明分支、从哪到哪、离开的提交(引用日志仍可找回)与“工作区改动保留”,确认后 `reset --keep`(Git 在改动冲突时拒绝;没有任何按钮做硬重置),执行前在写队列里核对 HEAD 仍在预览时的分支(完整引用名,或仍游离)与提交、仍无暂存,任一变了即什么也不做。引用日志的时间是该次移动的时间(`--date=unix` 下的 `%gd`),不是提交时间;选中按事件本身(提交、原因、时间与它在全部引用日志中自最早起的序号,后者新移动不改,同一秒同原因的两次也分得开),同一提交的多条不会一起选中;之后有新的移动时该事件的位置后移,选中与详情跟着它,事件已不在引用日志里即不显示。清理:对话框先由 `git clean -n -d`(勾“包括被忽略的文件”另加 `-x`)得出 Git 会删除的路径(`core.quotePath=false`,其余 C 引号照 Git 规则还原),其中的文件夹当场展开为其中的文件(`ls-files --others`,同一忽略规则,另一仓库不入),对话框逐个列出文件与文件夹;确认后先逐段查每个所列路径:仍在仓库里、途中没有符号链接、文件仍是文件、文件夹仍是文件夹(任一变了即整体拒绝,什么也不删),再以 `git clean -f [-x] -- 所列文件` 删去(只给文件,Git 不递归;此后被跟踪了的文件 Git 留下,也不穿过链接),最后自深而浅删去所列文件夹中已空的(预览后在其中新出现的文件不动,文件夹随之留下),每次都问。文件标题栏多出“在编辑器中打开”(用户在“仓库›选择编辑器…”选的程序,存在数据目录 `tools.json`,字段类型不对与读不出同样报错且不覆盖;macOS 的 .app 经 `open -a`,在后台等它结束,失败即显示其原话;未选时先问)与 Markdown 的“在 ElyMark 中打开”(`ely_platform::apps::open`:按安装布局找同级的应用,macOS 的 `名称.app/Contents/MacOS`,Windows 的 `Ely Office\名称`,开发构建的同一目录;找不到即报错)。锁(§13.3):任何写操作因 Git 的锁文件失败(`….lock': File exists`,或配置文件的 `could not lock config file …: File exists`)时,对话框说明另一个 Git 正在工作、Ely 从不删除锁文件,“重试”把同一写操作重新排队。QA-19:测试都以独立的 Git 命令核对索引、提交、引用与工作区。QA-20:冲突、钩子失败、凭据被拒(本机 401 服务器,显示 Git 的 “terminal prompts disabled” 原话)、锁、变基中断后中止、取消(停止取回)都有窗口测试,结束时仓库状态以 Git 读回核对。切换到系统 Git 目前经 `ELY_GIT`(设置页随 C18.1)。真窗口(macOS):仓库页工具行、清理预览对话框、文件标题栏的编辑器与 ElyMark 按钮,按下后同级的 ely-mark 以该文件启动。未验证:Windows 与 Linux 的终端;ElyMark 打开文件的内容(C14)。
|
||||||
- 2026-10-07:ElyTree 储藏、远程、工作树、子模块、LFS(C13.5,TREE-10 至 12,§13.3)。左栏第四页“仓库”:上方取回(`fetch --progress --all`)、拉取(`pull --progress`,照用户的 pull 设置)、推送、强制推送…;储藏(`stash list -z`,新的在前;“储藏改动…”问说明与是否包括未跟踪的文件,`stash push`),远程(名称与地址,`remote` 加 `config --get-regexp` 读出取回与推送地址),工作树(`worktree list --porcelain -z`,行名为文件夹名,有失效的可“清理”即 `worktree prune`),子模块(索引里的 gitlink 与文件夹自身 `.git` 的 HEAD:未检出、在记录的提交上、在别的提交上、冲突),LFS 文件(`git lfs ls-files --long --json`:工作树里是内容、对象在本机而工作树是指针、只有指针而对象不在本机);没有子模块或 LFS 文件时不列。各列表分别读出,一个读不出只在该处显示 Git 原话;切到此页时读,此后每次状态重读时重读,只取最新一次。选中一项,中间显示:储藏为提交详情的同一套(`hist::Picked`,历史与储藏共用读取与面板):改动的文件(对第一个父提交)与储藏的未跟踪文件(第三个父提交,各自对空树),选文件看差异,上方应用、弹出、删除…;远程为地址与推送地址,取回、修改…(改名 `remote rename`、改地址 `remote set-url`)、移除…(先问);工作树为路径与分支或提交、锁定与失效原因,打开(作为标签)、移除…(先问,主工作树与当前的不给);子模块为记录的与检出的提交,“检出记录的提交”(`submodule update --init`,经远程运行)与打开。用户输入的名称、地址、路径前一律加 `--`(推送的远程名同样)。表单与选择对话框(新建分支、标签、改名、身份、储藏、远程、工作树、选远程与上游)记下打开时的仓库,提交时写进那个仓库,不随当前标签变;储藏列表按每条三个字段读(说明可为空)。储藏的应用、弹出、删除按 `stash@{n}` 执行,执行前在写队列里核对它仍是所见的那个储藏(另有储藏插入即拒绝,什么也不做);弹出遇冲突时 Git 保留储藏,对话框显示 Git 原话。删除储藏、移除远程与工作树每次都问。分支页的本地分支多出“设置上游…”(列出远程分支,`branch --set-upstream-to=refs/remotes/名`)与“取消上游”。推送:有上游即 `push --progress`;没有上游时后台读出远程,问推到哪个远程(`push --set-upstream -- 远程 refs/heads/分支:refs/heads/分支`),没有远程或 HEAD 游离即说明。强制推送(§13.3):后台读出当前分支、上游的远程与远端分支、上次取回时远端的提交(租约)、此刻 HEAD 的提交(源)与远端有而源没有的提交,对话框写明远程、分支与将被覆盖的提交(或写明没有),确认后推送的就是所示的源提交(`push --force-with-lease=远端分支:租约提交 -- 远程 源提交:远端分支`),确认前本地分支再动也不改变推送内容;远端自上次取回后变了即被拒绝;没有上游或游离即说明不能。远程命令(取回、拉取、推送、子模块更新)是写队列里的一种(`Write::Remote`),经 `running::Running` 运行:Git 在自己的会话里(`setsid`,SSH 找不到终端,不会挂在终端提示上;凭据照用 credential helper 与 ssh-agent),进度逐行显示在中间上方的提示条,可停止(向整个进程组发 SIGTERM,Git 自行清理;已结束的不再发);用户停止时提示“已停止”、清掉其后的排队写,不当作失败;失败时对话框显示 Git 的 stdout 与 stderr(以回车结尾的进度行被下一行改写,只留最后一次;以换行结尾的行全部保留,钩子的每一行都在);拉取遇冲突照合并类命令判定为停下。关窗与退出时停下所有远程命令与克隆。克隆改用同一运行器。真窗口(macOS):仓库页五类列表、储藏详情与文件、工作树详情、分支行。未验证:Windows 与 Linux(停止远程命令在非 Unix 上报未构建);真实网络与 HTTPS、SSH 凭据;LFS 对象的下载(只显示状态)。
|
- 2026-10-07:ElyTree 储藏、远程、工作树、子模块、LFS(C13.5,TREE-10 至 12,§13.3)。左栏第四页“仓库”:上方取回(`fetch --progress --all`)、拉取(`pull --progress`,照用户的 pull 设置)、推送、强制推送…;储藏(`stash list -z`,新的在前;“储藏改动…”问说明与是否包括未跟踪的文件,`stash push`),远程(名称与地址,`remote` 加 `config --get-regexp` 读出取回与推送地址),工作树(`worktree list --porcelain -z`,行名为文件夹名,有失效的可“清理”即 `worktree prune`),子模块(索引里的 gitlink 与文件夹自身 `.git` 的 HEAD:未检出、在记录的提交上、在别的提交上、冲突),LFS 文件(`git lfs ls-files --long --json`:工作树里是内容、对象在本机而工作树是指针、只有指针而对象不在本机);没有子模块或 LFS 文件时不列。各列表分别读出,一个读不出只在该处显示 Git 原话;切到此页时读,此后每次状态重读时重读,只取最新一次。选中一项,中间显示:储藏为提交详情的同一套(`hist::Picked`,历史与储藏共用读取与面板):改动的文件(对第一个父提交)与储藏的未跟踪文件(第三个父提交,各自对空树),选文件看差异,上方应用、弹出、删除…;远程为地址与推送地址,取回、修改…(改名 `remote rename`、改地址 `remote set-url`)、移除…(先问);工作树为路径与分支或提交、锁定与失效原因,打开(作为标签)、移除…(先问,主工作树与当前的不给);子模块为记录的与检出的提交,“检出记录的提交”(`submodule update --init`,经远程运行)与打开。用户输入的名称、地址、路径前一律加 `--`(推送的远程名同样)。表单与选择对话框(新建分支、标签、改名、身份、储藏、远程、工作树、选远程与上游)记下打开时的仓库,提交时写进那个仓库,不随当前标签变;储藏列表按每条三个字段读(说明可为空)。储藏的应用、弹出、删除按 `stash@{n}` 执行,执行前在写队列里核对它仍是所见的那个储藏(另有储藏插入即拒绝,什么也不做);弹出遇冲突时 Git 保留储藏,对话框显示 Git 原话。删除储藏、移除远程与工作树每次都问。分支页的本地分支多出“设置上游…”(列出远程分支,`branch --set-upstream-to=refs/remotes/名`)与“取消上游”。推送:有上游即 `push --progress`;没有上游时后台读出远程,问推到哪个远程(`push --set-upstream -- 远程 refs/heads/分支:refs/heads/分支`),没有远程或 HEAD 游离即说明。强制推送(§13.3):后台读出当前分支、上游的远程与远端分支、上次取回时远端的提交(租约)、此刻 HEAD 的提交(源)与远端有而源没有的提交,对话框写明远程、分支与将被覆盖的提交(或写明没有),确认后推送的就是所示的源提交(`push --force-with-lease=远端分支:租约提交 -- 远程 源提交:远端分支`),确认前本地分支再动也不改变推送内容;远端自上次取回后变了即被拒绝;没有上游或游离即说明不能。远程命令(取回、拉取、推送、子模块更新)是写队列里的一种(`Write::Remote`),经 `running::Running` 运行:Git 在自己的会话里(`setsid`,SSH 找不到终端,不会挂在终端提示上;凭据照用 credential helper 与 ssh-agent),进度逐行显示在中间上方的提示条,可停止(向整个进程组发 SIGTERM,Git 自行清理;已结束的不再发);用户停止时提示“已停止”、清掉其后的排队写,不当作失败;失败时对话框显示 Git 的 stdout 与 stderr(以回车结尾的进度行被下一行改写,只留最后一次;以换行结尾的行全部保留,钩子的每一行都在);拉取遇冲突照合并类命令判定为停下。关窗与退出时停下所有远程命令与克隆。克隆改用同一运行器。真窗口(macOS):仓库页五类列表、储藏详情与文件、工作树详情、分支行。未验证:Windows 与 Linux(停止远程命令在非 Unix 上报未构建);真实网络与 HTTPS、SSH 凭据;LFS 对象的下载(只显示状态)。
|
||||||
- 2026-10-07(用户定):跟随组件库最新的 main。组件库 K01 把 gpui 从 zed 仓库的提交换成 crates.io 的 `gpui-pre` =0.3.8(`gpui-pre-platform` 同版本),K02 让 Tab 绑在 FocusScope 的 ElyFocus 上下文下、更深的上下文先得;本项目工作区的 `gpui`、`gpui_platform` 随之改为这两个包(以 `package =` 保留原名,源码不变),组件库 pin 到 dabc1eb(其上加本项目一个提交:树与树行的无障碍角色)。升级后全工作区编译无改动。
|
- 2026-10-07(用户定):跟随组件库最新的 main。组件库 K01 把 gpui 从 zed 仓库的提交换成 crates.io 的 `gpui-pre` =0.3.8(`gpui-pre-platform` 同版本),K02 让 Tab 绑在 FocusScope 的 ElyFocus 上下文下、更深的上下文先得;本项目工作区的 `gpui`、`gpui_platform` 随之改为这两个包(以 `package =` 保留原名,源码不变),组件库 pin 到 dabc1eb(其上加本项目一个提交:树与树行的无障碍角色)。升级后全工作区编译无改动。
|
||||||
- 2026-10-08:首版打包(R1.1)。图标(用户定:logo-design 技能出方案,选 C“实心几何”;macOS 标准 squircle,Linux 与 Windows 无底形,八个同一套设计):母版在 `assets/icons`(我按圆角矩形、圆与 30°/45° 斜线在 256 网格上画;每个颜色对白与 `#1E1E1E` 都不低于 3:1,ElyMark 原定的石板灰在深色上 1.75:1,改为琥珀 `#B87A00`;ElyTable 在 48 像素以下用简化的一版),`packaging/icons/build.sh` 以 AppKit 渲染出 icns(macOS)、512 像素 png(Linux 的 AppImage 与桌面文件)、16 至 256 像素 ico(Windows 安装程序、开始菜单快捷方式与卸载项);生成物入库,Linux 与 Windows 构建不需要 macOS。系统交给应用的文件:`ely_ui::run` 收下启动参数与 `on_open_urls`(访达的打开请求,启动前到达的也在内),应用先取 `launch_files`(有则不开空白文档;ElyMark 有则不恢复上次的标签),再以 `on_open` 处理运行中的请求;六个应用都走这一条(ElyDoc、ElyTable、ElyShow 原先不收启动参数)。macOS 包:LOK 应用只带内核,按 LibreOffice 自己的布局并入本应用:内核的库进 `Contents/Frameworks`(合并库构建留下的“invalid - merged lib”占位文件不拷,其余非代码文件即报错),内核的资料进 `Contents/Resources`,另有 `MacOS/ely-lok-worker`;`install_dir` 先找包内(`Frameworks/libmergedlo.dylib`)。不带 `LibreOffice.app` 本身:原先整份嵌入时,其快速查看与聚焦插件、`soffice` 等启动程序与文档类型被系统登记,系统设置里出现“LibreOffice 扩展”(用户发现;已注销本机七处登记);测试也不再运行 LibreOffice 应用(样本改为 `tests/fixtures/office` 的固定文件,运行开发构建的 `soffice` 会让系统重新登记它)。ElyPDF 带 `MacOS/ely-pdf-worker` 与 `Resources/tessdata`(三种语言),OCR 数据先找应用旁再找包内;ElyTree 带 `Resources/git`,其中每个 Mach-O 先签(Git 以 `INSTALL_SYMLINKS` 构建,内建命令是指向同一程序的相对链接;原先是硬链接,拷进包后变成约 150 份副本、689 MB;以 `MACOSX_DEPLOYMENT_TARGET=14.0` 构建,原先随本机 SDK 要求 macOS 27);ElyMark 用同级 ElyTree 包里的 Git。文档类型(`packaging/macos/documents.sh`)一律 `Alternate`,不抢系统默认:Doc 为 docx、odt、doc、rtf;Table 为 xlsx、ods、xls、csv、tsv;Show 为 pptx、odp、ppt;PDF;Markdown;Tree 为文件夹(查看者)。worker、内核、OCR 数据、CEF 与页面的所在路径都写日志,`tests/scripts/release-macos.sh` 据此核对都在包内。许可(§21.2、§21.3):每个包的 `Resources/Licenses` 有 Ely 的 AGPL 全文(仓库根 `LICENSE`)、`rust-crates.txt`(`packaging/crates.py`:本机目标下链进各二进制的全部 crate 与其许可文件,无许可文件的取 `packaging/licenses` 里该表达式的标准文本并写明作者,都没有即失败)与所带引擎的许可:LibreOffice 的 LICENSE、NOTICE、CREDITS;MuPDF 的 COPYING 与其编进去的每个第三方及每组内嵌字体(按构建实际嵌入的)的许可、OpenSSL、tessdata(Apache-2.0,按提交与散列取)、Great Vibes 的 OFL;Git 的 COPYING 与 LGPL-2.1、git-lfs 的 LICENSE.md(发布包里没有,按标签与散列取);CEF 的 LICENSE 与 Chromium 的 CREDITS、页面的第三方通知;缺任何一份即打包失败(`packaging/licenses.sh`)。`release.sh` 另出 `ElyOffice-<版本>-source.tar.gz`:自有源码、锁文件、上游补丁与构建脚本(上游各自钉在提交,取得方式即其中的 fetch 脚本)。正式签名(hardened runtime)时 CEF 的渲染与 GPU 辅助程序带 `allow-jit`,插件辅助程序带 `allow-unsigned-executable-memory` 与 `disable-library-validation`(`packaging/macos/entitlements`;原先不带,V8 保留不到代码区,页面载入失败);`tests/scripts/hardened-macos.sh` 以 `ELY_SIGN_IDENTITY` 签 ElyMark 并核对页面画出。ElyTable 同时收到多个文本文件(访达一次交来多份 CSV)时,读完的导入排队,没有对话框开着才逐个询问(原先后到的一份替换前一份,前一份静默丢失)。`packaging/macos/release.sh` 按 `apps.tsv` 的批次出各应用的 dmg;本机只有 Apple Development 证书,无 Developer ID,未公证。未验证:Intel 包(只建了 arm64)、公证、Linux 与 Windows 的包(本机不能建)。
|
- 2026-10-08:首版打包(R1.1)。图标(用户定:logo-design 技能出方案,选 C“实心几何”;macOS 标准 squircle,Linux 与 Windows 无底形,八个同一套设计):母版在 `assets/icons`(我按圆角矩形、圆与 30°/45° 斜线在 256 网格上画;每个颜色对白与 `#1E1E1E` 都不低于 3:1,ElyMark 原定的石板灰在深色上 1.75:1,改为琥珀 `#B87A00`;ElyTable 在 48 像素以下用简化的一版),`packaging/icons/build.sh` 以 AppKit 渲染出 icns(macOS)、512 像素 png(Linux 的 AppImage 与桌面文件)、16 至 256 像素 ico(Windows 安装程序、开始菜单快捷方式与卸载项);生成物入库,Linux 与 Windows 构建不需要 macOS。系统交给应用的文件:`ely_ui::run` 收下启动参数与 `on_open_urls`(访达的打开请求,启动前到达的也在内),应用先取 `launch_files`(有则不开空白文档;ElyMark 有则不恢复上次的标签),再以 `on_open` 处理运行中的请求;六个应用都走这一条(ElyDoc、ElyTable、ElyShow 原先不收启动参数)。macOS 包:LOK 应用只带内核,按 LibreOffice 自己的布局并入本应用:内核的库进 `Contents/Frameworks`(合并库构建留下的“invalid - merged lib”占位文件不拷,其余非代码文件即报错),内核的资料进 `Contents/Resources`,另有 `MacOS/ely-lok-worker`;`install_dir` 先找包内(`Frameworks/libmergedlo.dylib`)。不带 `LibreOffice.app` 本身:原先整份嵌入时,其快速查看与聚焦插件、`soffice` 等启动程序与文档类型被系统登记,系统设置里出现“LibreOffice 扩展”(用户发现;已注销本机七处登记);测试也不再运行 LibreOffice 应用(样本改为 `tests/fixtures/office` 的固定文件,运行开发构建的 `soffice` 会让系统重新登记它)。ElyPDF 带 `MacOS/ely-pdf-worker` 与 `Resources/tessdata`(三种语言),OCR 数据先找应用旁再找包内;ElyTree 带 `Resources/git`,其中每个 Mach-O 先签(Git 以 `INSTALL_SYMLINKS` 构建,内建命令是指向同一程序的相对链接;原先是硬链接,拷进包后变成约 150 份副本、689 MB;以 `MACOSX_DEPLOYMENT_TARGET=14.0` 构建,原先随本机 SDK 要求 macOS 27);ElyMark 用同级 ElyTree 包里的 Git。文档类型(`packaging/macos/documents.sh`)一律 `Alternate`,不抢系统默认:Doc 为 docx、odt、doc、rtf;Table 为 xlsx、ods、xls、csv、tsv;Show 为 pptx、odp、ppt;PDF;Markdown;Tree 为文件夹(查看者)。worker、内核、OCR 数据、CEF 与页面的所在路径都写日志,`tests/scripts/release-macos.sh` 据此核对都在包内。许可(§21.2、§21.3):每个包的 `Resources/Licenses` 有 Ely 的 AGPL 全文(仓库根 `LICENSE`)、`rust-crates.txt`(`packaging/crates.py`:本机目标下链进各二进制的全部 crate 与其许可文件,无许可文件的取 `packaging/licenses` 里该表达式的标准文本并写明作者,都没有即失败)与所带引擎的许可:LibreOffice 的 LICENSE、NOTICE、CREDITS;MuPDF 的 COPYING 与其编进去的每个第三方及每组内嵌字体(按构建实际嵌入的)的许可、OpenSSL、tessdata(Apache-2.0,按提交与散列取)、Great Vibes 的 OFL;Git 的 COPYING 与 LGPL-2.1、git-lfs 的 LICENSE.md(发布包里没有,按标签与散列取);CEF 的 LICENSE 与 Chromium 的 CREDITS、页面的第三方通知;缺任何一份即打包失败(`packaging/licenses.sh`)。`release.sh` 另出 `ElyOffice-<版本>-source.tar.gz`:自有源码、锁文件、上游补丁与构建脚本(上游各自钉在提交,取得方式即其中的 fetch 脚本)。正式签名(hardened runtime)时 CEF 的渲染与 GPU 辅助程序带 `allow-jit`,插件辅助程序带 `allow-unsigned-executable-memory` 与 `disable-library-validation`(`packaging/macos/entitlements`;原先不带,V8 保留不到代码区,页面载入失败);`tests/scripts/hardened-macos.sh` 以 `ELY_SIGN_IDENTITY` 签 ElyMark 并核对页面画出。ElyTable 同时收到多个文本文件(访达一次交来多份 CSV)时,读完的导入排队,没有对话框开着才逐个询问(原先后到的一份替换前一份,前一份静默丢失)。`packaging/macos/release.sh` 按 `apps.tsv` 的批次出各应用的 dmg;本机只有 Apple Development 证书,无 Developer ID,未公证。未验证:Intel 包(只建了 arm64)、公证、Linux 与 Windows 的包(本机不能建)。
|
||||||
@@ -260,7 +260,7 @@ cargo run -p ely-doc 启动一个应用(ElyDoc 先 cargo build -p ely
|
|||||||
- 2026-10-07:ElyTree 提交、历史、Blame(C13.3,TREE-05、06)。左栏分“改动”与“历史”两页(`navigation::Tabs`)。提交:改动页下方是 `git::CommitInput`(摘要与说明两个框,摘要满 50 变黄、72 变红),上面一行是 Git 设置里的身份(每次状态重读与窗口回到前台时重读,只取最新一次;`user.name <user.email>`,未设即写明,点它开身份对话框:姓名、邮箱(两个输入框以其标签为无障碍名),可勾“用于所有仓库”写 `--global`,否则写本仓库;空着即提示不写)与签名(`commit.gpgsign` 为真时写明以 `gpg.format` 签名,默认 openpgp),签名照用户自己的 Git 与工具,Ely 不另设。提交框按仓库各存一份(换标签时存下当前的、换上另一个的:摘要、说明、修改最近提交与其草稿),提交为 `commit --cleanup=whitespace -F -`(信息经标准输入,`#` 开头的行照留,用户的 `commit.cleanup` 不删它们,不经 shell),“修改最近一次提交”勾上即显示为勾选、读出上次的信息填入(读回前不能提交;先存下已键入的,取消勾选时放回;每次勾选或取消、换仓库都使在途的读取作废,读回时须仍是发起的仓库与那一次),提交成功后只在提交框仍是所提交的内容时清空(提交期间又键入的留着,别的仓库的提交框不动);钩子或签名失败时以对话框显示 Git 的全部原话,不只说失败。提交同其他写操作排队。历史:`log --topo-order --exclude=refs/stash --all`,每页 2000 个,滚到距末尾 20 行内读下一页;每次状态重读后比对 `show-ref --head`,引用变了(含外部提交、切分支、取回)即从头重读;读取期间来的比对记下,读完再比;引用读不出时历史栏显示 Git 的原话,之后读通即重读并清掉;提交图由 `git::lanes` 按已读的全部提交算出;时间按本机时区写到分钟(不用相对时间,长列表不必随时刷新)。搜索:在“提交信息”(`--grep`)、“作者”(`--author`)、“改动的文字”(`-S`)中按字面、不分大小写找,或按提交号(`rev-parse --verify`,前缀可);搜索时不画图。选中一个提交:中间上方是摘要、说明、作者与提交者(不同时才列)、完整提交号、父提交(可点,转到父提交)、签名状态(`%G?` 按字母译出,带签名者)、引用;下方左列是相对第一个父提交改动的文件(`diff --name-status -M` 与 `--numstat`,根提交对空树,空树由 `hash-object -t tree` 算,不写死 SHA-1),右边是所选文件的差异(与改动区同一读法:Git 自己的差异,图片、二进制、非 UTF-8 同样处理,无块的纯重命名显示为无改动)。改动区差异与历史页所选文件的标题栏都有“文件历史”与“逐行追溯”(改动区限已跟踪的文件):文件历史为 `log --follow --numstat -z`,跨重命名,每个提交带当时的路径与行数,选中即显示该提交里这个文件的差异(状态按两侧是否存在判定);逐行追溯为工作树文件的 `blame --porcelain`,未提交的行写“尚未提交”,每段首行可按,转到历史页的该提交;条色按提交时间新旧。读取都在后台,按发起时的仓库、提交与文件核对;文件历史与逐行追溯每次打开有窗口内唯一的序号,迟到的结果即弃。提交详情的作者、提交者、提交号、签名、引用、摘要与说明在 AX 树里有文字。真窗口(macOS)经 AX:历史页、提交图、引用、提交详情、文件列表与差异。未验证:Windows 与 Linux;GPG 与 SSH 实际签名(只读设置,签名由用户的 Git 完成)。
|
- 2026-10-07:ElyTree 提交、历史、Blame(C13.3,TREE-05、06)。左栏分“改动”与“历史”两页(`navigation::Tabs`)。提交:改动页下方是 `git::CommitInput`(摘要与说明两个框,摘要满 50 变黄、72 变红),上面一行是 Git 设置里的身份(每次状态重读与窗口回到前台时重读,只取最新一次;`user.name <user.email>`,未设即写明,点它开身份对话框:姓名、邮箱(两个输入框以其标签为无障碍名),可勾“用于所有仓库”写 `--global`,否则写本仓库;空着即提示不写)与签名(`commit.gpgsign` 为真时写明以 `gpg.format` 签名,默认 openpgp),签名照用户自己的 Git 与工具,Ely 不另设。提交框按仓库各存一份(换标签时存下当前的、换上另一个的:摘要、说明、修改最近提交与其草稿),提交为 `commit --cleanup=whitespace -F -`(信息经标准输入,`#` 开头的行照留,用户的 `commit.cleanup` 不删它们,不经 shell),“修改最近一次提交”勾上即显示为勾选、读出上次的信息填入(读回前不能提交;先存下已键入的,取消勾选时放回;每次勾选或取消、换仓库都使在途的读取作废,读回时须仍是发起的仓库与那一次),提交成功后只在提交框仍是所提交的内容时清空(提交期间又键入的留着,别的仓库的提交框不动);钩子或签名失败时以对话框显示 Git 的全部原话,不只说失败。提交同其他写操作排队。历史:`log --topo-order --exclude=refs/stash --all`,每页 2000 个,滚到距末尾 20 行内读下一页;每次状态重读后比对 `show-ref --head`,引用变了(含外部提交、切分支、取回)即从头重读;读取期间来的比对记下,读完再比;引用读不出时历史栏显示 Git 的原话,之后读通即重读并清掉;提交图由 `git::lanes` 按已读的全部提交算出;时间按本机时区写到分钟(不用相对时间,长列表不必随时刷新)。搜索:在“提交信息”(`--grep`)、“作者”(`--author`)、“改动的文字”(`-S`)中按字面、不分大小写找,或按提交号(`rev-parse --verify`,前缀可);搜索时不画图。选中一个提交:中间上方是摘要、说明、作者与提交者(不同时才列)、完整提交号、父提交(可点,转到父提交)、签名状态(`%G?` 按字母译出,带签名者)、引用;下方左列是相对第一个父提交改动的文件(`diff --name-status -M` 与 `--numstat`,根提交对空树,空树由 `hash-object -t tree` 算,不写死 SHA-1),右边是所选文件的差异(与改动区同一读法:Git 自己的差异,图片、二进制、非 UTF-8 同样处理,无块的纯重命名显示为无改动)。改动区差异与历史页所选文件的标题栏都有“文件历史”与“逐行追溯”(改动区限已跟踪的文件):文件历史为 `log --follow --numstat -z`,跨重命名,每个提交带当时的路径与行数,选中即显示该提交里这个文件的差异(状态按两侧是否存在判定);逐行追溯为工作树文件的 `blame --porcelain`,未提交的行写“尚未提交”,每段首行可按,转到历史页的该提交;条色按提交时间新旧。读取都在后台,按发起时的仓库、提交与文件核对;文件历史与逐行追溯每次打开有窗口内唯一的序号,迟到的结果即弃。提交详情的作者、提交者、提交号、签名、引用、摘要与说明在 AX 树里有文字。真窗口(macOS)经 AX:历史页、提交图、引用、提交详情、文件列表与差异。未验证:Windows 与 Linux;GPG 与 SSH 实际签名(只读设置,签名由用户的 Git 完成)。
|
||||||
- 2026-10-07:ElyTree 差异与暂存(C13.2,TREE-03、04)。差异一律取 Git 自己的输出(`-c diff.suppressBlankEmpty=false diff --no-color --no-ext-diff --no-textconv -U3`,前缀写明 `a/`、`b/`,覆盖用户的 noprefix 等设置;空白的上下文行照样带前导空格):已暂存为 `--cached -M`(HEAD 对索引,即提交前的实际索引内容),改动为索引对工作树,未跟踪为 `--no-index` 对 `/dev/null`(退出码 1 即有差异);Git 的清理过滤(换行转换等)由它自己做,按块、按行暂存的补丁对得上索引。块之间未改动的行从旧侧的 blob 取(`cat-file blob`,已暂存为 `HEAD:旧路径`,改动为 `:路径`),可展开;行号按块头推算,旧文件比差异短即报错。改动的词按每对删去与加入的行标出(Unicode 词)。空白:精确、忽略空白变化(`-b`)、忽略全部空白(`-w`);行内与并排。按块或按行:只在精确比较、且是普通内容改动时(无新建、删除、重命名、复制、权限变化的头),已暂存区为取消暂存(`apply --cached --reverse`),改动区为暂存(`apply --cached`);未跟踪、重命名等整份暂存,界面写明。补丁由所选行切出:暂存时未选的删去行留作上下文、未选的加入行不写;取消暂存时反之;块头按“范围前的行数”换算,空范围照 Git 的写法;“无换行结尾”按切出后两侧的实际行尾:无换行的行在哪一侧后面还有行,那一侧就带上换行(所选的删去或加入行同样),两侧不同的上下文行拆成一删一加;`apply` 带 `--whitespace=nowarn`,用户的 `apply.whitespace` 不改所选的字节。写入前在后台重读同一条差异,与所选时读到的字节不同即拒绝(“文件在显示后改了,未暂存”),索引不动;同一仓库的写仍排队。所选行按住 Shift 取同一块内的范围;差异一变(任何重读得到不同的输出)所选即清空;每次读取有窗口内唯一的序号,换文件后旧文件迟到的读取即弃。图片(png、jpg、gif、webp、bmp、tiff、ico)以 `BeforeAfter` 左右拖动对比,一侧缺失时只显示另一侧;其他二进制文件,以及两侧任一侧不全是 UTF-8 的文件(差异以外的字节也算),显示两侧大小,整份暂存;文件与符号链接互换时 Git 为同一路径打出两段(删去与新增),两段都显示(不折叠:两段没有共同的旧文),整份暂存;工作树侧照 Git 读:符号链接读其自身的路径,不跟随;未跟踪的文件夹与冲突文件(冲突在 C13.4 处理)只说明。单击文件即在中间显示其差异(已忽略的文件以系统程序打开),标题栏另有“打开文件”。外部改动后状态重读,正显示的差异随之重读;文件不再列在原分区即收起。真窗口(macOS):改动区选两行暂存,索引恰为所选,已暂存区显示实际索引内容,并排视图;AX 树中各行、块按钮与分段可按。
|
- 2026-10-07:ElyTree 差异与暂存(C13.2,TREE-03、04)。差异一律取 Git 自己的输出(`-c diff.suppressBlankEmpty=false diff --no-color --no-ext-diff --no-textconv -U3`,前缀写明 `a/`、`b/`,覆盖用户的 noprefix 等设置;空白的上下文行照样带前导空格):已暂存为 `--cached -M`(HEAD 对索引,即提交前的实际索引内容),改动为索引对工作树,未跟踪为 `--no-index` 对 `/dev/null`(退出码 1 即有差异);Git 的清理过滤(换行转换等)由它自己做,按块、按行暂存的补丁对得上索引。块之间未改动的行从旧侧的 blob 取(`cat-file blob`,已暂存为 `HEAD:旧路径`,改动为 `:路径`),可展开;行号按块头推算,旧文件比差异短即报错。改动的词按每对删去与加入的行标出(Unicode 词)。空白:精确、忽略空白变化(`-b`)、忽略全部空白(`-w`);行内与并排。按块或按行:只在精确比较、且是普通内容改动时(无新建、删除、重命名、复制、权限变化的头),已暂存区为取消暂存(`apply --cached --reverse`),改动区为暂存(`apply --cached`);未跟踪、重命名等整份暂存,界面写明。补丁由所选行切出:暂存时未选的删去行留作上下文、未选的加入行不写;取消暂存时反之;块头按“范围前的行数”换算,空范围照 Git 的写法;“无换行结尾”按切出后两侧的实际行尾:无换行的行在哪一侧后面还有行,那一侧就带上换行(所选的删去或加入行同样),两侧不同的上下文行拆成一删一加;`apply` 带 `--whitespace=nowarn`,用户的 `apply.whitespace` 不改所选的字节。写入前在后台重读同一条差异,与所选时读到的字节不同即拒绝(“文件在显示后改了,未暂存”),索引不动;同一仓库的写仍排队。所选行按住 Shift 取同一块内的范围;差异一变(任何重读得到不同的输出)所选即清空;每次读取有窗口内唯一的序号,换文件后旧文件迟到的读取即弃。图片(png、jpg、gif、webp、bmp、tiff、ico)以 `BeforeAfter` 左右拖动对比,一侧缺失时只显示另一侧;其他二进制文件,以及两侧任一侧不全是 UTF-8 的文件(差异以外的字节也算),显示两侧大小,整份暂存;文件与符号链接互换时 Git 为同一路径打出两段(删去与新增),两段都显示(不折叠:两段没有共同的旧文),整份暂存;工作树侧照 Git 读:符号链接读其自身的路径,不跟随;未跟踪的文件夹与冲突文件(冲突在 C13.4 处理)只说明。单击文件即在中间显示其差异(已忽略的文件以系统程序打开),标题栏另有“打开文件”。外部改动后状态重读,正显示的差异随之重读;文件不再列在原分区即收起。真窗口(macOS):改动区选两行暂存,索引恰为所选,已暂存区显示实际索引内容,并排视图;AX 树中各行、块按钮与分段可按。
|
||||||
- 2026-10-07(用户定):ElyTree 的 Git。随包自建钉住的 Git v2.56.0(a018953)加 git-lfs v3.8.0(各平台散列钉在 `scripts/fetch-git-lfs.sh`),`scripts/build-git.sh` 以 RUNTIME_PREFIX 构建到 `engines/git`,LFS 放在 `libexec/git-core`。查找次序:`ELY_GIT`(系统 Git,低于 2.40 即拒绝),否则应用旁或 `Resources/git`,否则本构建的 `engines/git`;没有即报错,不退回别的 Git。每次运行都是参数数组,带 `GIT_OPTIONAL_LOCKS=0`(读取不抢索引锁)、`GIT_TERMINAL_PROMPT=0`(从不在终端问凭据)、`GIT_LITERAL_PATHSPECS=1`(路径不当通配)。
|
- 2026-10-07(用户定):ElyTree 的 Git。随包自建钉住的 Git v2.56.0(a018953)加 git-lfs v3.8.0(各平台散列钉在 `scripts/fetch-git-lfs.sh`),`scripts/build-git.sh` 以 RUNTIME_PREFIX 构建到 `engines/git`,LFS 放在 `libexec/git-core`。查找次序:`ELY_GIT`(系统 Git,低于 2.40 即拒绝),否则应用旁或 `Resources/git`,否则本构建的 `engines/git`;没有即报错,不退回别的 Git。每次运行都是参数数组,带 `GIT_OPTIONAL_LOCKS=0`(读取不抢索引锁)、`GIT_TERMINAL_PROMPT=0`(从不在终端问凭据)、`GIT_LITERAL_PATHSPECS=1`(路径不当通配)。
|
||||||
- 2026-10-07:ElyTree 仓库与工作区(C13.1,TREE-01、02)。窗口经 `ely_ui::tool_root`:“文件”只有新建(选文件夹 `git init`)与打开(可多选文件夹),`commands::menus` 改收各应用自己的文件命令(文档应用照旧六项),保存、另存、导出、打印的动作在工具窗口里不挂;“仓库”菜单:克隆…、关闭仓库(Cmd+W)。每个仓库一个标签,同一工作树(按 `--show-toplevel` 的真实路径)只开一个,再开即切过去;裸仓库拒绝。最近列表在数据目录的 `recent.json`(新的在前,留 20 个),读不出即报错且不覆盖;最近项打不开即移出并说明。克隆:先问地址,再在最近仓库旁问新文件夹(名取地址末段去 `.git`),文件夹非空即拒绝;Git 的进度逐行显示在正中(回车与换行都断行,读到即显示),可停止(SIGTERM,Git 自己删去半成品;已结束的进程不再发信号,免误伤重用的进程号);关窗或退出时停下进行中的克隆。状态读 `status --porcelain=v2 -z --branch --untracked-files=normal --ignored`,未知字母即报错;行数取 `diff --numstat -z`(已暂存与未暂存各一次,二进制不计),未跟踪、冲突、忽略的不计行数。左栏 `git::ChangesList` 分冲突、已暂存、改动、未跟踪、已忽略;单击文件以系统程序打开;暂存(`add --all`)、取消暂存(有提交时 `restore --staged`,首个提交前 `rm --cached -f`:索引与文件不同也照取消,文件不动)、全部暂存(`add --update`)、全部取消(`reset -q`);取消暂存重命名连旧路径,暂存只用新路径(已暂存的重命名再改时旧路径已不在);放弃改动每次都问(已跟踪的 `restore --worktree`,未跟踪的 `clean -f -d` 并写明会删除)。同一仓库的写操作排队、一次一条,失败即清掉其后的排队并报出 Git 原话,关闭标签要等排队写完。外部改动:`notify` 监视工作树、Git 目录与共用目录(`--git-common-dir`;链接的 worktree 的分支与引用在主仓库里),250 毫秒内的一串改动合成一次重读,读取中再来的合成一次;空闲不读。状态栏:分支(游离显示短提交号,无提交写明)、上游与领先落后(上游引用已删即写明不存在,不显示为 0)、真实路径、Git 版本、随附或系统与所用 Git 的路径。中间区在 C13.2 前只显示改动数或“没有要提交的改动”。组件库 4f8f3bd 与 37c5187:`Changed::lines` 可缺。真窗口(macOS):五个分区、行数、状态栏。未验证:Windows 与 Linux(停止克隆在非 Unix 上报未构建);LFS 仓库的克隆。
|
- 2026-10-07:ElyTree 仓库与工作区(C13.1,TREE-01、02)。窗口经 `ely_ui::tool_root`:“文件”只有新建(选文件夹 `git init`)与打开(可多选文件夹),`commands::menus` 改收各应用自己的文件命令(文档应用照旧六项),保存、另存、导出、打印的动作在工具窗口里不挂;“仓库”菜单:克隆…、关闭仓库(Cmd+W)。每个仓库一个标签,同一工作树(按 `--show-toplevel` 的真实路径)只开一个,再开即切过去;裸仓库拒绝。最近列表在数据目录的 `recent.json`(新的在前,留 20 个),读不出即报错且不覆盖;最近项打不开即移出并说明。克隆:先问地址,再在最近仓库旁问新文件夹(名取地址末段去 `.git`),文件夹非空即拒绝;Git 的进度逐行显示在正中(回车与换行都断行,读到即显示),可停止(SIGTERM,Git 自己删去半成品;已结束的进程不再发信号,免误伤重用的进程号);关窗或退出时停下进行中的克隆。状态读 `status --porcelain=v2 -z --branch --untracked-files=normal --ignored`,未知字母即报错;行数取 `diff --numstat -z`(已暂存与未暂存各一次,二进制不计),未跟踪、冲突、忽略的不计行数。左栏 `git::ChangesList` 分冲突、已暂存、改动、未跟踪、已忽略;单击文件以系统程序打开;暂存(`add --all`)、取消暂存(有提交时 `restore --staged`,首个提交前 `rm --cached -f`:索引与文件不同也照取消,文件不动)、全部暂存(`add --update`)、全部取消(`reset -q`);取消暂存重命名连旧路径,暂存只用新路径(已暂存的重命名再改时旧路径已不在);放弃改动每次都问(已跟踪的 `restore --worktree`,未跟踪的 `clean -f -d` 并写明会删除)。同一仓库的写操作排队、一次一条,失败即清掉其后的排队并报出 Git 原话,关闭标签要等排队写完。外部改动:`notify` 监视工作树、Git 目录与共用目录(`--git-common-dir`;链接的 worktree 的分支与引用在主仓库里),250 毫秒内的一串改动合成一次重读,读取中再来的合成一次;空闲不读。状态栏:分支(游离显示短提交号,无提交写明)、上游与领先落后(上游引用已删即写明不存在,不显示为 0)、真实路径(所用 Git 的版本与路径只记日志,2026-10-11 用户定从状态栏去掉)。中间区在 C13.2 前只显示改动数或“没有要提交的改动”。组件库 4f8f3bd 与 37c5187:`Changed::lines` 可缺。真窗口(macOS):五个分区、行数、状态栏。未验证:Windows 与 Linux(停止克隆在非 Unix 上报未构建);LFS 仓库的克隆。
|
||||||
- 2026-10-07:ElyPDF 输出与文件恢复(C11.8,PDF-13、14,QA-13)。“文件›导出…”(Cmd+E)一个对话框三种:页面图片(PNG,72、150、300 dpi,全部或所选页,总是浅色,选文件夹,`名称-序号.png` 按页数补零,先以 `ely_files::claim_all` 占下全部目标,任一失败即删去本次全部);文字(UTF-8,各页以换页符分开,MuPDF 的 stext);优化的 PDF(可看可改的设置:压缩数据流、字体与图片;图片高于某 dpi 降到某 dpi,双三次重采样到确切目标,重压缩:无损的仍无损、有损的保持原格式,默认 300 降到 150;降到的 dpi 须低于阈值,否则不可导出;完成提示写明原文件与新文件大小)。导出图片与文字要“复制”许可,优化副本要“修改”许可。“打印…”(Cmd+P)把文档此刻写成副本(要“打印”许可,worker 的 `PRINT_COPY`)再交系统打印面板(`ely_office::print_later`)。文件恢复:MuPDF 打开时修复了文件结构(`pdf_was_repaired`),worker 即把修复后的文档整份写成临时副本、改开这份副本(日志与快照从此正常;原先修复过的文件不能保存),关闭文档时删去;打开时 MuPDF 的警告记下作修复报告(`ely_open` 期间接管警告回调,照样转给原回调)。外壳的 `Engine::signed` 改为 `Engine::risk`(宏由外壳判,签名、修复由引擎答),加 `Risk::Repaired`:提示条说明打开的是修复的副本、“另存为”写新文件、原件不动,带“报告…”按钮显示 MuPDF 的原话;保存一律另存,另存到原件被拒;签名或修复的文件另存成功后标签记下“待重开”,到内存与文件一致(已保存、无待落地编辑、不在导出)时才按新文件重开;另存期间又有编辑则留着编辑,下一次保存后再重开。MuPDF 有时读到坏对象才修复(尾部完好、某对象偏移坏):打开与解锁后先把每个对象读一遍,并解码图片以外的每个数据流(`ely_scan`,读不出的对象记入报告);MuPDF 修复了结构或读的过程中有任何警告(如内容流解压失败),都当作损坏文件,改开整份写出的副本、报告列出警告、保存一律另存。图片(用户定)在画出时检查:画图块或缩略图时 MuPDF 有警告即为损坏,报告补上警告,标签转为修复风险(保存一律另存);没画过的图片在原位保存(覆盖文件)之前统一解码检查(外壳的 `Engine::unsound`,有问题即转为另存为)。全部解码放在打开时的代价实测:100 张 2000×2000 的 JPEG(281 MB)打开到首块 2.6 秒(release,本机)。导出图片与文字期间 MuPDF 有警告即报错不写(读不全的内容不当作导出)。打印副本不带加密(已核过打印许可;否则系统打印面板打不开加了打开密码的副本),`print_later` 在面板关闭后删去它。导出对话框的降采样数值随键入生效(不等回车或失焦),直接点导出用的是所见的数。补丁 `0005` 见上(保存打不开输出时的保存中标志)。QA-13:worker 改字、加并填文本字段、移页后保存,以 PDFKit(另一阅读器)读回:页序、新字取代旧字、字段值都对(`tests/independent.rs`,只在 macOS);图片编辑在 PDFKit 里未单独核对(PDFKit 无图片清单接口)。组件库 a6b1bb0 的 `init` 改为返回错误(缺资源时),启动时出错即以 `startup::fail` 报出。真窗口(macOS):损坏文件的提示条与“修复的副本”状态、导出对话框。未验证:Windows 与 Linux 的打印(打印面板只在 macOS 实现);真窗口里实际打印。
|
- 2026-10-07:ElyPDF 输出与文件恢复(C11.8,PDF-13、14,QA-13)。“文件›导出…”(Cmd+E)一个对话框三种:页面图片(PNG,72、150、300 dpi,全部或所选页,总是浅色,选文件夹,`名称-序号.png` 按页数补零,先以 `ely_files::claim_all` 占下全部目标,任一失败即删去本次全部);文字(UTF-8,各页以换页符分开,MuPDF 的 stext);优化的 PDF(可看可改的设置:压缩数据流、字体与图片;图片高于某 dpi 降到某 dpi,双三次重采样到确切目标,重压缩:无损的仍无损、有损的保持原格式,默认 300 降到 150;降到的 dpi 须低于阈值,否则不可导出;完成提示写明原文件与新文件大小)。导出图片与文字要“复制”许可,优化副本要“修改”许可。“打印…”(Cmd+P)把文档此刻写成副本(要“打印”许可,worker 的 `PRINT_COPY`)再交系统打印面板(`ely_office::print_later`)。文件恢复:MuPDF 打开时修复了文件结构(`pdf_was_repaired`),worker 即把修复后的文档整份写成临时副本、改开这份副本(日志与快照从此正常;原先修复过的文件不能保存),关闭文档时删去;打开时 MuPDF 的警告记下作修复报告(`ely_open` 期间接管警告回调,照样转给原回调)。外壳的 `Engine::signed` 改为 `Engine::risk`(宏由外壳判,签名、修复由引擎答),加 `Risk::Repaired`:提示条说明打开的是修复的副本、“另存为”写新文件、原件不动,带“报告…”按钮显示 MuPDF 的原话;保存一律另存,另存到原件被拒;签名或修复的文件另存成功后标签记下“待重开”,到内存与文件一致(已保存、无待落地编辑、不在导出)时才按新文件重开;另存期间又有编辑则留着编辑,下一次保存后再重开。MuPDF 有时读到坏对象才修复(尾部完好、某对象偏移坏):打开与解锁后先把每个对象读一遍,并解码图片以外的每个数据流(`ely_scan`,读不出的对象记入报告);MuPDF 修复了结构或读的过程中有任何警告(如内容流解压失败),都当作损坏文件,改开整份写出的副本、报告列出警告、保存一律另存。图片(用户定)在画出时检查:画图块或缩略图时 MuPDF 有警告即为损坏,报告补上警告,标签转为修复风险(保存一律另存);没画过的图片在原位保存(覆盖文件)之前统一解码检查(外壳的 `Engine::unsound`,有问题即转为另存为)。全部解码放在打开时的代价实测:100 张 2000×2000 的 JPEG(281 MB)打开到首块 2.6 秒(release,本机)。导出图片与文字期间 MuPDF 有警告即报错不写(读不全的内容不当作导出)。打印副本不带加密(已核过打印许可;否则系统打印面板打不开加了打开密码的副本),`print_later` 在面板关闭后删去它。导出对话框的降采样数值随键入生效(不等回车或失焦),直接点导出用的是所见的数。补丁 `0005` 见上(保存打不开输出时的保存中标志)。QA-13:worker 改字、加并填文本字段、移页后保存,以 PDFKit(另一阅读器)读回:页序、新字取代旧字、字段值都对(`tests/independent.rs`,只在 macOS);图片编辑在 PDFKit 里未单独核对(PDFKit 无图片清单接口)。组件库 a6b1bb0 的 `init` 改为返回错误(缺资源时),启动时出错即以 `startup::fail` 报出。真窗口(macOS):损坏文件的提示条与“修复的副本”状态、导出对话框。未验证:Windows 与 Linux 的打印(打印面板只在 macOS 实现);真窗口里实际打印。
|
||||||
- 2026-10-06:ElyPDF 密码与签名(C11.7,PDF-11、12,QA-15,§11.4)。权限:worker 记下每个文档的访问(MuPDF 的认证结果,4 为所有者;未加密即全权),`PERMISSIONS` 按 Ely 的位报出(打印、复制、修改、批注、填表、页面与书签、所有者),每个改动请求先按表核对(`secure::needs`:页面增删移转与书签要“页面与书签”或“修改”,内容、链接、属性、附件、OCR 层、删除与清理要“修改”,批注要“批注”,建改字段要修改加批注,填表要填表或批注,提取要复制,改保护要所有者),不许即以 `restricted:名` 报错,客户端转成 `PermissionDenied`,界面按名说明并提示输入所有者密码;复制文字在应用里按位拦(读文字本身不拦)。“文档”菜单“输入所有者密码…”:对时解除限制;错时 MuPDF 已丢了原密钥(RC4 与 AES-128 实测文字读不出),worker 以原密码重新认证。“密码与权限…”只在所有者权限下:写新文件(AES-256,`ely_protect` 经 `ely_save_copy` 带写出选项),打开密码可空,所有者密码必填且须与打开密码不同,六项许可勾选;或不保护(去掉加密)。只凭用户密码打开的文件改保护即拒绝。签名:MuPDF 以 `HAVE_LIBCRYPTO` 构建,worker 另链 `libmupdf-pkcs7.a` 与 OpenSSL 的静态 `libcrypto.a`(pkg-config 给目录)。`SIGNATURES` 按表单字段树列出全部签名字段(不画在页面上的也列,页与框可无;控件无 /P 时从各页 /Annots 找页):已签的给出摘要核对(`pdf_check_widget_digest`:未改、已改、读不出)、其后有无更新与更新是否越出签名所许(`pdf_signature_incremental_change_since_signing`、`pdf_validate_signature`)、签名者(MuPDF 的识别名与通用名)、签名者自称的时间、原因、地点,以及签名里的证书(签名者在前,DER);单个签名读不出只报该项的原因。证书信任由应用交系统判定(`ely_platform::trust`:macOS 用 `SecTrust`、`SecPolicy::create_x509`、禁网,故从不核验吊销;Windows 与 Linux 未构建,报“此平台未构建”)。界面“文档›签名…”对话框逐个列出完整性、证书、吊销(一律“未核验吊销状态”)、时间(带时区)、原因、地点与所在页,不给笼统的“有效”。新签:“以证书签名…”工具,拖出框或点空的签名字段,对话框选 .p12/.pfx、填证书密码、原因、地点,另存:快照副本上建字段(名 `SignatureN` 避开表单已有名)并签,以增量更新写出(旧签名覆盖的字节不动),写完重开核对新签名的摘要,不过即报错删文件;原文档不动;发起时绑定视图版本与所选位置。补丁 `patches/mupdf/0004-signature-reason-and-location.patch`:原因与地点写进签名字典(MuPDF 原只画进外观;签后再改会落到第二个更新段,字节范围算成负数)。外观只画标签、名字与时间(不画空的识别名各栏,不画 MuPDF 标志)。已签文件(`ely_signed` 数表单里有值的签名字段)打开为 `Risk::Signed`:上方提示条说明修改会使签名失效、“另存为”写出未签名副本,带“签名…”按钮;保存不覆盖原文件。外壳的 `risk` 由布尔改为 `Option<Risk>`(宏或签名),`Engine::signed` 由引擎回答。Ely 一切整份写出(保存、另存、提取、删除、清理、保护)在 `ely_save_copy` 里去掉签名值与其外观(字段留下、空着,去掉 AppendOnly 标志):整份重写本就使签名失效,不留假签名。签名核对的是文件,不是编辑中的文档:`SIGNATURES` 带路径,worker 以文档的密码另开该文件读出再关闭;签名列表按标签当前的文件路径读、按路径缓存,保存后重读。已签文件另存为成功后,标签按新文件重新打开(外壳的 `reload`,同冲突时;撤销历史随之重新开始),打开着的文档、签名列表与以后的签名都对应这份未签名的副本;另存失败时标签与签名都仍是原文件。签名对话框每次打开都重读文件,磁盘上被改动即显示已改。去掉签名值时一并去掉该签名字段自身的只读位(签名时由它的锁设下),以便再签;它锁住的其他字段的只读位留着(分不出原本是否只读,已知限制)。补丁 `patches/mupdf/0005-failed-save-clears-save-in-progress.patch`:MuPDF 的 `prepare_for_save` 置起保存中标志、只有写出过程清除它;打不开输出文件时标志留着,此后一切改动绕过日志,编辑没有撤销步(实测:存到不存在的目录后旋转,历史标记仍为 0);补丁让打开输出或预排签名失败时清除它。可视签名(用户定三种来源):“添加可视签名…”对话框,手写(组件库 `SiLine truncated
|
- 2026-10-06:ElyPDF 密码与签名(C11.7,PDF-11、12,QA-15,§11.4)。权限:worker 记下每个文档的访问(MuPDF 的认证结果,4 为所有者;未加密即全权),`PERMISSIONS` 按 Ely 的位报出(打印、复制、修改、批注、填表、页面与书签、所有者),每个改动请求先按表核对(`secure::needs`:页面增删移转与书签要“页面与书签”或“修改”,内容、链接、属性、附件、OCR 层、删除与清理要“修改”,批注要“批注”,建改字段要修改加批注,填表要填表或批注,提取要复制,改保护要所有者),不许即以 `restricted:名` 报错,客户端转成 `PermissionDenied`,界面按名说明并提示输入所有者密码;复制文字在应用里按位拦(读文字本身不拦)。“文档”菜单“输入所有者密码…”:对时解除限制;错时 MuPDF 已丢了原密钥(RC4 与 AES-128 实测文字读不出),worker 以原密码重新认证。“密码与权限…”只在所有者权限下:写新文件(AES-256,`ely_protect` 经 `ely_save_copy` 带写出选项),打开密码可空,所有者密码必填且须与打开密码不同,六项许可勾选;或不保护(去掉加密)。只凭用户密码打开的文件改保护即拒绝。签名:MuPDF 以 `HAVE_LIBCRYPTO` 构建,worker 另链 `libmupdf-pkcs7.a` 与 OpenSSL 的静态 `libcrypto.a`(pkg-config 给目录)。`SIGNATURES` 按表单字段树列出全部签名字段(不画在页面上的也列,页与框可无;控件无 /P 时从各页 /Annots 找页):已签的给出摘要核对(`pdf_check_widget_digest`:未改、已改、读不出)、其后有无更新与更新是否越出签名所许(`pdf_signature_incremental_change_since_signing`、`pdf_validate_signature`)、签名者(MuPDF 的识别名与通用名)、签名者自称的时间、原因、地点,以及签名里的证书(签名者在前,DER);单个签名读不出只报该项的原因。证书信任由应用交系统判定(`ely_platform::trust`:macOS 用 `SecTrust`、`SecPolicy::create_x509`、禁网,故从不核验吊销;Windows 与 Linux 未构建,报“此平台未构建”)。界面“文档›签名…”对话框逐个列出完整性、证书、吊销(一律“未核验吊销状态”)、时间(带时区)、原因、地点与所在页,不给笼统的“有效”。新签:“以证书签名…”工具,拖出框或点空的签名字段,对话框选 .p12/.pfx、填证书密码、原因、地点,另存:快照副本上建字段(名 `SignatureN` 避开表单已有名)并签,以增量更新写出(旧签名覆盖的字节不动),写完重开核对新签名的摘要,不过即报错删文件;原文档不动;发起时绑定视图版本与所选位置。补丁 `patches/mupdf/0004-signature-reason-and-location.patch`:原因与地点写进签名字典(MuPDF 原只画进外观;签后再改会落到第二个更新段,字节范围算成负数)。外观只画标签、名字与时间(不画空的识别名各栏,不画 MuPDF 标志)。已签文件(`ely_signed` 数表单里有值的签名字段)打开为 `Risk::Signed`:上方提示条说明修改会使签名失效、“另存为”写出未签名副本,带“签名…”按钮;保存不覆盖原文件。外壳的 `risk` 由布尔改为 `Option<Risk>`(宏或签名),`Engine::signed` 由引擎回答。Ely 一切整份写出(保存、另存、提取、删除、清理、保护)在 `ely_save_copy` 里去掉签名值与其外观(字段留下、空着,去掉 AppendOnly 标志):整份重写本就使签名失效,不留假签名。签名核对的是文件,不是编辑中的文档:`SIGNATURES` 带路径,worker 以文档的密码另开该文件读出再关闭;签名列表按标签当前的文件路径读、按路径缓存,保存后重读。已签文件另存为成功后,标签按新文件重新打开(外壳的 `reload`,同冲突时;撤销历史随之重新开始),打开着的文档、签名列表与以后的签名都对应这份未签名的副本;另存失败时标签与签名都仍是原文件。签名对话框每次打开都重读文件,磁盘上被改动即显示已改。去掉签名值时一并去掉该签名字段自身的只读位(签名时由它的锁设下),以便再签;它锁住的其他字段的只读位留着(分不出原本是否只读,已知限制)。补丁 `patches/mupdf/0005-failed-save-clears-save-in-progress.patch`:MuPDF 的 `prepare_for_save` 置起保存中标志、只有写出过程清除它;打不开输出文件时标志留着,此后一切改动绕过日志,编辑没有撤销步(实测:存到不存在的目录后旋转,历史标记仍为 0);补丁让打开输出或预排签名失败时清除它。可视签名(用户定三种来源):“添加可视签名…”对话框,手写(组件库 `SiLine truncated
|
||||||
- 2026-10-06:ElyPDF 内容删除与文档清理(C11.6,PDF-09、10,§11.4,QA-14)。标记只在视图里(“标记文字以删除”按所选文字每行一框,“标记区域以删除”拖框,单击已有标记取消;预览为页面上的深色框;任何编辑落地即清空,页码可能已变),文档本身不动。“删除标记的内容…”与“清理文档…”都写新文件:先把文档快照写出、重开副本(`ely_save_copy`,提取与保存同用),在副本上改,再以 `garbage=2` 整份写出(不增量,旧修订不留),写到工作目录、核对通过后经 `ely_files::export` 交到所选位置,工作副本普通删除(对话框写明:原件、旧备份、同步历史与已发出的副本仍可能含有被删内容;不是磁盘级擦除)。删除:先删去碰到区域的批注与字段(MuPDF 的删除只管链接与文本框批注,其他批注的内容、字段的值会留下),字段失去最后一个控件即连同空了的上级一起从表单去掉(否则值留在字段树里);全部区域的删除做完后才建 Redact 批注(否则后一区域会删掉前一区域的标记)并 `pdf_redact_page`(黑框;图片在区域内的像素由 MuPDF 改成白色;碰到区域的线条整条删去,只删被盖满的会留下可复原的路径;碰到的文字删去,含隐藏文字)。有区域的页再过一遍内容(含表单):标记内容的 /ActualText、/Alt、/E 一律去掉,结构树里属于该页的元素(自身或继承的 `Pg`,或子项 MCR、OBJR 的 `Pg` 指向该页,连同其上级)去掉这三项与 /T;整页去掉而不只区域内的,宁多勿漏。页面缩略图 /Thumb 删去(它可引用原图),核对时区域所在页仍有缩略图即失败。写出后重开核对:区域内的字(与删除同一判法:字框各边缩一成后相交)为零;区域内画出来不是黑色的像素为零;逐页以设备重放,落进区域的路径、渐变、图像蒙版除我们的黑框外为零,图片单独画出在区域内只剩白或黑;文件只有一个版本;任一不过即报错并删去输出。确认时绑定标记与文档版本,选完路径后标记或版本变了即不写。清理:先扫出数量(属性与元数据条数、批注、附件含批注里的文件、有隐藏文字的页、脚本入口),勾选后写出:删 Info;其余按一遍遍历全部对象及其中的直接字典与数组:/Metadata 与 /PieceInfo,文件说明的 /EF 与 /RF 及关联文件 /AF,脚本;删批注(链接与字段不算批注,保留),删附件(名称树与文件批注;附件按带 /EF 的文件说明计数,每个一次),隐藏内容为:内容过滤(包住 MuPDF 的 sanitize 过滤器,用途设为 View 才认关着的图层)删去关着的图层里的一切、3 与 7 渲染模式及零透明度的文字,脚本(名称树 JavaScript;任何对象的 /A、/OpenAction、/Next 与 /AA 各项里 S 为 JavaScript 或带 /JS 的动作,从链中摘除,其后的 /Next 链接回原处,非脚本动作保留),带隐藏或不可见标志的批注(含链接与字段控件:链接不在 MuPDF 的批注表里,按页面 /Annots 删;控件删去时字段连同值从表单去掉);有隐藏文字被删的页,标记内容的替代文字照删除的做法去掉。扫描与写出后的核对都在快照副本上跑同一遍清理来计数,所以计数与执行一致;所选类别核对不为零即报错。扫描回来时须仍是当前标签且版本未变,对话框写明文件名。未验证:Windows 与 Linux。
|
- 2026-10-06:ElyPDF 内容删除与文档清理(C11.6,PDF-09、10,§11.4,QA-14)。标记只在视图里(“标记文字以删除”按所选文字每行一框,“标记区域以删除”拖框,单击已有标记取消;预览为页面上的深色框;任何编辑落地即清空,页码可能已变),文档本身不动。“删除标记的内容…”与“清理文档…”都写新文件:先把文档快照写出、重开副本(`ely_save_copy`,提取与保存同用),在副本上改,再以 `garbage=2` 整份写出(不增量,旧修订不留),写到工作目录、核对通过后经 `ely_files::export` 交到所选位置,工作副本普通删除(对话框写明:原件、旧备份、同步历史与已发出的副本仍可能含有被删内容;不是磁盘级擦除)。删除:先删去碰到区域的批注与字段(MuPDF 的删除只管链接与文本框批注,其他批注的内容、字段的值会留下),字段失去最后一个控件即连同空了的上级一起从表单去掉(否则值留在字段树里);全部区域的删除做完后才建 Redact 批注(否则后一区域会删掉前一区域的标记)并 `pdf_redact_page`(黑框;图片在区域内的像素由 MuPDF 改成白色;碰到区域的线条整条删去,只删被盖满的会留下可复原的路径;碰到的文字删去,含隐藏文字)。有区域的页再过一遍内容(含表单):标记内容的 /ActualText、/Alt、/E 一律去掉,结构树里属于该页的元素(自身或继承的 `Pg`,或子项 MCR、OBJR 的 `Pg` 指向该页,连同其上级)去掉这三项与 /T;整页去掉而不只区域内的,宁多勿漏。页面缩略图 /Thumb 删去(它可引用原图),核对时区域所在页仍有缩略图即失败。写出后重开核对:区域内的字(与删除同一判法:字框各边缩一成后相交)为零;区域内画出来不是黑色的像素为零;逐页以设备重放,落进区域的路径、渐变、图像蒙版除我们的黑框外为零,图片单独画出在区域内只剩白或黑;文件只有一个版本;任一不过即报错并删去输出。确认时绑定标记与文档版本,选完路径后标记或版本变了即不写。清理:先扫出数量(属性与元数据条数、批注、附件含批注里的文件、有隐藏文字的页、脚本入口),勾选后写出:删 Info;其余按一遍遍历全部对象及其中的直接字典与数组:/Metadata 与 /PieceInfo,文件说明的 /EF 与 /RF 及关联文件 /AF,脚本;删批注(链接与字段不算批注,保留),删附件(名称树与文件批注;附件按带 /EF 的文件说明计数,每个一次),隐藏内容为:内容过滤(包住 MuPDF 的 sanitize 过滤器,用途设为 View 才认关着的图层)删去关着的图层里的一切、3 与 7 渲染模式及零透明度的文字,脚本(名称树 JavaScript;任何对象的 /A、/OpenAction、/Next 与 /AA 各项里 S 为 JavaScript 或带 /JS 的动作,从链中摘除,其后的 /Next 链接回原处,非脚本动作保留),带隐藏或不可见标志的批注(含链接与字段控件:链接不在 MuPDF 的批注表里,按页面 /Annots 删;控件删去时字段连同值从表单去掉);有隐藏文字被删的页,标记内容的替代文字照删除的做法去掉。扫描与写出后的核对都在快照副本上跑同一遍清理来计数,所以计数与执行一致;所选类别核对不为零即报错。扫描回来时须仍是当前标签且版本未变,对话框写明文件名。未验证:Windows 与 Linux。
|
||||||
@@ -285,4 +285,10 @@ cargo run -p ely-doc 启动一个应用(ElyDoc 先 cargo build -p ely
|
|||||||
- 2026-10-10:Windows 与 Linux 的构建环境(E-01)。Windows:MSVC(VS 2022,v143);MuPDF 由 `build-mupdf.sh` 以 MSBuild 编上游 `platform/win32` 的 `libmupdf`(静态运行库 /MT,同 Rust 的 `crt-static`;`HAVE_LIBCRYPTO`,`libmupdf.lib` 内含第三方、Tesseract 与 PKCS#7);静态 OpenSSL 取自钉在 2026.07.29 的 vcpkg(`engines/vcpkg`,`openssl:x64-windows-static`);Git 为 Git for Windows 的 MinGit 2.56.0(钉散列,`engines/git/cmd/git.exe`,LFS 在 `ucrt64/libexec/git-core`);CEF 照 cef-dll-sys 放在可执行文件旁(Windows、Linux 都是),不另载入;`%TEMP%` 下的程序被系统的应用控制拦下,构建与探针都不放那里;cmake 与 ninja 须在 PATH;LibreOffice 的 configure 只认 VS 自带的 CMake(组件 `VC.CMake.Project`)。仓库与 `reference/` 一律 LF(`core.autocrlf false`、`core.eol lf`;`fetch-references.sh` 对每个上游照设)。Linux:WSL 的 Ubuntu 26.04;静态 libcrypto 另需其 pkg-config 列出的库(jitterentropy、zstd、z)。LibreOffice 在 Linux 照 Collabora 的 LOKit 配置构建(无图形后端、cairo RGBA、自带各库)。
|
- 2026-10-10:Windows 与 Linux 的构建环境(E-01)。Windows:MSVC(VS 2022,v143);MuPDF 由 `build-mupdf.sh` 以 MSBuild 编上游 `platform/win32` 的 `libmupdf`(静态运行库 /MT,同 Rust 的 `crt-static`;`HAVE_LIBCRYPTO`,`libmupdf.lib` 内含第三方、Tesseract 与 PKCS#7);静态 OpenSSL 取自钉在 2026.07.29 的 vcpkg(`engines/vcpkg`,`openssl:x64-windows-static`);Git 为 Git for Windows 的 MinGit 2.56.0(钉散列,`engines/git/cmd/git.exe`,LFS 在 `ucrt64/libexec/git-core`);CEF 照 cef-dll-sys 放在可执行文件旁(Windows、Linux 都是),不另载入;`%TEMP%` 下的程序被系统的应用控制拦下,构建与探针都不放那里;cmake 与 ninja 须在 PATH;LibreOffice 的 configure 只认 VS 自带的 CMake(组件 `VC.CMake.Project`)。仓库与 `reference/` 一律 LF(`core.autocrlf false`、`core.eol lf`;`fetch-references.sh` 对每个上游照设)。Linux:WSL 的 Ubuntu 26.04;静态 libcrypto 另需其 pkg-config 列出的库(jitterentropy、zstd、z)。LibreOffice 在 Linux 照 Collabora 的 LOKit 配置构建(无图形后端、cairo RGBA、自带各库)。
|
||||||
- 2026-10-10:Windows 与 Linux 的内核与 worker(W-01、K-01,用户定:0.1.3 先三端发布)。内核只认合并库(`ffi::KERNEL`:`libmergedlo.dylib`、`libmergedlo.so`、`mergedlo.dll`;`sofficeapp` 在合并构建里是文本占位);Windows 载入时一并搜索该 DLL 所在的 `program/`。查找次序照旧,Windows 与 Linux 的包内位置是应用旁的 `libreoffice/program`,开发构建为 `engines/lo-src/instdir/program`。worker 的主循环:macOS 照旧以 GCD;Linux 以 unipoll,`runLoop` 的轮询回调里每次答一个请求,内核的唤醒回调往同一队列放信号(`worker/unipoll.rs`;回调的数据指针须非空,VCL 见空即不调用);Windows 也以 unipoll:LOK 不另起主线程,worker 的主线程跑 `runLoop`(Windows 的消息循环),请求经只收消息的窗口投到这条线程上执行(`worker/messages.rs`),同 macOS 的 GCD;原先 LOK 自起主线程、worker 在另一线程作答,载入表格即死锁。Windows 的循环不调轮询回调,但须传非空的回调,`isUnipoll` 只看它。补丁 `0043-lok-callbacks-flush-inline-everywhere.patch`:回调队列在各平台都即时冲出(原只 macOS),否则请求里等的命令结果与状态要等下一轮主循环才到。`0042-svx-boost-json-needs-no-library.patch`:svxcore 与 sd 定义 `BOOST_ALL_NO_LIB`,MSVC 不再按 Boost 的自动链接索要 `libboost_json`、`libboost_container`。Linux 的内核以 cairo 画图块(worker 设 `SAL_DISABLESKIA`;构建去掉 `--enable-cairo-rgba`,自带的 cairo 要清掉重建),字节为 BGRA,同 macOS 与 Windows;`getTileMode` 只看 cairo 开关,不可信。worker 启动核对在三端都画一段红字,按 BGRA 找不到红色即拒绝。`scripts/apply-lo-patches.sh` 的临时库设 `core.autocrlf false`(Windows 默认转换使任何前缀都对不上)。Windows 的 LibreOffice 在 Cygwin 下构建(`build-libreoffice.sh` 的 CYGWIN 分支:去掉 Unix 专用开关,加 VS 2022,用 `/opt/lo/bin` 的 make,清掉 Git Bash 带进来的 `MSYSTEM`);构建目录与 Cygwin 排除在 Defender 扫描之外(否则并行 configure 删不掉 `conftest.dir`)。英文词典扩展里的 Lightproof(Python 写的语法检查)在构建后删去:macOS 与 Linux 的内核不带 Python,它本不生效;Windows 必带内置 Python(Cygwin 下 configure 不许去掉),第二次用同一配置启动时初始化它,worker 挂起。worker 以 `SAL_NOLOCK_PROFILE` 运行,`ely.xcd` 关掉 LibreOffice 的文档锁(`Common/Misc/UseLocking`):被强杀的 worker 留下的锁会让下次启动或载入弹出交互而挂起;每个应用只有一个 worker 用自己的配置,冲突由 Ely 自己核对。三端发布(CI-01):`.gitea/workflows/release.yml` 在打标签时于三台运行器上执行 `scripts/ci.sh`:macOS 在 Mac mini 的常驻克隆里按需从零构建引擎,Windows 在本机运行器上把 `engines` 与 `reference` 接到开发克隆,Linux 由同一台 Windows 运行器经 WSL 构建(服务器上的 Linux 运行器是一次性容器,建不了内核);各自打包后上传到该标签的发布。Windows 为 NSIS 安装程序,Linux 为 AppImage,都由 `packaging/stage.sh` 分装引擎;更新清单只含 macOS(Windows 与 Linux 的自动安装未做)。
|
- 2026-10-10:Windows 与 Linux 的内核与 worker(W-01、K-01,用户定:0.1.3 先三端发布)。内核只认合并库(`ffi::KERNEL`:`libmergedlo.dylib`、`libmergedlo.so`、`mergedlo.dll`;`sofficeapp` 在合并构建里是文本占位);Windows 载入时一并搜索该 DLL 所在的 `program/`。查找次序照旧,Windows 与 Linux 的包内位置是应用旁的 `libreoffice/program`,开发构建为 `engines/lo-src/instdir/program`。worker 的主循环:macOS 照旧以 GCD;Linux 以 unipoll,`runLoop` 的轮询回调里每次答一个请求,内核的唤醒回调往同一队列放信号(`worker/unipoll.rs`;回调的数据指针须非空,VCL 见空即不调用);Windows 也以 unipoll:LOK 不另起主线程,worker 的主线程跑 `runLoop`(Windows 的消息循环),请求经只收消息的窗口投到这条线程上执行(`worker/messages.rs`),同 macOS 的 GCD;原先 LOK 自起主线程、worker 在另一线程作答,载入表格即死锁。Windows 的循环不调轮询回调,但须传非空的回调,`isUnipoll` 只看它。补丁 `0043-lok-callbacks-flush-inline-everywhere.patch`:回调队列在各平台都即时冲出(原只 macOS),否则请求里等的命令结果与状态要等下一轮主循环才到。`0042-svx-boost-json-needs-no-library.patch`:svxcore 与 sd 定义 `BOOST_ALL_NO_LIB`,MSVC 不再按 Boost 的自动链接索要 `libboost_json`、`libboost_container`。Linux 的内核以 cairo 画图块(worker 设 `SAL_DISABLESKIA`;构建去掉 `--enable-cairo-rgba`,自带的 cairo 要清掉重建),字节为 BGRA,同 macOS 与 Windows;`getTileMode` 只看 cairo 开关,不可信。worker 启动核对在三端都画一段红字,按 BGRA 找不到红色即拒绝。`scripts/apply-lo-patches.sh` 的临时库设 `core.autocrlf false`(Windows 默认转换使任何前缀都对不上)。Windows 的 LibreOffice 在 Cygwin 下构建(`build-libreoffice.sh` 的 CYGWIN 分支:去掉 Unix 专用开关,加 VS 2022,用 `/opt/lo/bin` 的 make,清掉 Git Bash 带进来的 `MSYSTEM`);构建目录与 Cygwin 排除在 Defender 扫描之外(否则并行 configure 删不掉 `conftest.dir`)。英文词典扩展里的 Lightproof(Python 写的语法检查)在构建后删去:macOS 与 Linux 的内核不带 Python,它本不生效;Windows 必带内置 Python(Cygwin 下 configure 不许去掉),第二次用同一配置启动时初始化它,worker 挂起。worker 以 `SAL_NOLOCK_PROFILE` 运行,`ely.xcd` 关掉 LibreOffice 的文档锁(`Common/Misc/UseLocking`):被强杀的 worker 留下的锁会让下次启动或载入弹出交互而挂起;每个应用只有一个 worker 用自己的配置,冲突由 Ely 自己核对。三端发布(CI-01):`.gitea/workflows/release.yml` 在打标签时于三台运行器上执行 `scripts/ci.sh`:macOS 在 Mac mini 的常驻克隆里按需从零构建引擎,Windows 在本机运行器上把 `engines` 与 `reference` 接到开发克隆,Linux 由同一台 Windows 运行器经 WSL 构建(服务器上的 Linux 运行器是一次性容器,建不了内核);各自打包后上传到该标签的发布。Windows 为 NSIS 安装程序,Linux 为 AppImage,都由 `packaging/stage.sh` 分装引擎;更新清单只含 macOS(Windows 与 Linux 的自动安装未做)。
|
||||||
- 2026-10-11:gpui 的 Windows 窗口关闭(W-03 冒烟查出)。`gpui-pre-windows` 0.3.8 在窗口关闭时报三条错:系统已销毁窗口(ElyTree 的关窗交给系统)后 Drop 仍对旧句柄 `RevokeDragDrop` 与 `DestroyWindow`(拖放处理器因此不释放,连带窗口状态);销毁时的失活回报排在异步任务里,执行时窗口已移除(“window not found”);退出后后台任务向已销毁的平台窗口投递(`Invalid window handle`)。修复在 `vendor/gpui-pre-windows`:`WM_DESTROY` 时记下已销毁、在句柄仍有效时撤销拖放、去掉失活回调,Drop 见已销毁即不再动句柄;平台窗口已不在时投递失败只记 debug(应用已退出),其余投递失败照报。三个应用关窗与退出的日志无错。
|
- 2026-10-11:gpui 的 Windows 窗口关闭(W-03 冒烟查出)。`gpui-pre-windows` 0.3.8 在窗口关闭时报三条错:系统已销毁窗口(ElyTree 的关窗交给系统)后 Drop 仍对旧句柄 `RevokeDragDrop` 与 `DestroyWindow`(拖放处理器因此不释放,连带窗口状态);销毁时的失活回报排在异步任务里,执行时窗口已移除(“window not found”);退出后后台任务向已销毁的平台窗口投递(`Invalid window handle`)。修复在 `vendor/gpui-pre-windows`:`WM_DESTROY` 时记下已销毁、在句柄仍有效时撤销拖放、去掉失活回调,Drop 见已销毁即不再动句柄;平台窗口已不在时投递失败只记 debug(应用已退出),其余投递失败照报。三个应用关窗与退出的日志无错。
|
||||||
|
- 2026-10-11(用户报:Windows 启动带黑色命令行窗口、“打开方式”里无图标、点 X 不退出、表格全黑无网格线):四处根因。命令行窗口:应用是控制台子系统;发行构建改为 `windows_subsystem = "windows"`(开发构建照旧有控制台看日志),子进程(两个 worker、Git、`cmd start`)一律经 `ely_ipc::windowless` 以 `CREATE_NO_WINDOW` 启动。图标:exe 里只有 gpui 的清单资源;各应用共用构建脚本 `packaging/windows/icon.rs`,把 `assets/icons/<应用>.ico` 编成资源 1(gpui 的窗口图标也取资源 1)。点 X 不退出:窗口其实弹了“保存更改”询问。`ely.xcd` 深色方案的 `CalcNotesBackground` 与浅色不同,Calc 在配色变化时改写批注样式并记一步撤销(`ScDetectiveFunc::UpdateAllComments`),未动的表格切到深色即算已修改;两套方案的批注底色改为同一值(LibreOffice 默认的浅黄),切换主题不再改文档,三端同此(`sheet.rs` 的 `a_theme_switch_is_no_edit`)。全黑:Win32 的虚拟设备没有 `SetSizeUsingBuffer`(基类默认返回假,断言在发行构建里不在),给客户缓冲区的设备停在 1×1 像素,Calc 图块只画了一个像素,放映图层同空;补丁 `0044-lok-win32-paints-then-copies.patch` 让 Windows 走 macOS 的路:按全尺寸画进设备,再拷进客户缓冲区(`doc_paintTile` 与 `SlideshowLayerRenderer`)。Writer 自设设备尺寸,原本不受影响。`tests/scripts/lo-patches.sh` 的临时库也设 `core.autocrlf false`(原先在 Windows 上恒失败)。
|
||||||
|
- 2026-10-11(用户报:Windows 上标题栏的最小化、最大化、关闭三个按钮都按不动):gpui 回答系统的命中测试(`WM_NCHITTEST`)时按绘制次序取第一个含指针的窗口控制区,标题栏的拖动区先于其中的按钮画出,按钮上一律答“标题栏”,系统把按下当作拖动窗口的开始,点击到不了按钮。修复在 `vendor/gpui-pre`(原样一个提交,其后是修复):按命中测试的次序取最上层的控制区,且只看未被遮挡的部分(同 `is_hovered`,盖在标题栏上的对话框挡住其下的按钮)。实测(发行构建,DPI 感知的探针移动真实指针):自右向左依次答关闭、最大化、最小化、拖动;按下最小化即最小化,最大化即最大化,关闭即退出、worker 随之结束;v0.1.3 的安装版同一探针处处答拖动。该回调只有 Windows 平台调用。
|
||||||
|
- 2026-10-11:Linux 标题栏按钮(核查 Windows 按钮问题时查出)。macOS 的红绿灯由系统画,不受影响;Linux 为客户端装饰,按钮由组件库画在标题栏的拖动区里,拖动区对任何按下都准备移动窗口,按住按钮时指针动一像素即开始移动窗口,合成器接管指针,松开到不了按钮,点击落空。组件库 3eb4d34:`drag_region` 只在按下未被里面的按钮认领(按钮以 `prevent_default` 认领)时才准备移动;`shell/title_tests.rs` 核对晃动的按下点得动 Linux 的关闭、标题栏空处照样移动窗口(去掉修复时前者失败)。未在真 Linux 桌面上点过。
|
||||||
|
- 2026-10-11(用户报:ElyTree 改动列表里文件名长时盖住行尾的打开按钮):组件库 bd01470:`ChangesList` 行里的文件名原为不缩的盒子,长名越过行宽压在按钮下;现可缩、以省略号结尾,先于按钮让位;`git/tests/narrow.rs` 核对 260 宽时文件名止于按钮之前(原布局时失败)。
|
||||||
|
- 2026-10-11(用户定:ElyTree 状态栏去掉 Git 的版本与路径那一项):所用 Git 的版本与路径只记日志。同时查出 Windows 上 `std::fs::canonicalize` 给出 `\\?\C:\…` 形式,仓库根、Git 目录、工作树与文件的真实路径一律改用 `dunce::canonicalize`(能写成普通路径即普通路径,同一文件仍是同一真实路径),状态栏的仓库路径随之为普通形式;ElyTree 的单测在 Windows 上由 44 个失败降到 8 个,余下 8 个改前同样失败(如写入 Windows 不许的文件名),未处理。
|
||||||
|
- 2026-10-11:ElyMark 的 AppImage(0.1.3 的 Linux 发布查出)。`linuxdeploy` 把可执行文件的 RUNPATH 改成 `$ORIGIN/../lib`,并把它找得到的 `libcef.so` 拷进 `usr/lib`:原先 `libcef.so` 与 CEF 的资料在 `usr/bin`,结果是两份 1.45 GB 的内核、程序载入 `usr/lib` 那份、CEF 在它旁边找不到 ICU 数据而退出(从未在 AppImage 里启动过)。现在 `appimage.sh` 把从 `engines/cef` 分装来的全部条目移进 `usr/lib`(按名字对照 CEF 文件夹,清单仍只在 `stage.sh`),以 `LD_LIBRARY_PATH=AppDir/usr/lib` 运行 `linuxdeploy`,`libcef.so` 只此一份、依赖照样带上,CEF 按所载 `libcef.so` 的文件夹取资料(`ely-web-content` 的 `open`)。ElyMark 的 AppImage 由 715 MB 降到 423 MB;WSL 里启动后 CEF 载入、窗口打开(WSL 里各应用都不出首帧,未在真桌面上验证)。
|
||||||
- 2026-10-09(用户定):代码与发布从 GitHub 搬到自建的 Gitea(git.zacharyzhang.com;GitHub 账号被封,推送与发布都被拒)。公开仓库 `ZacharyZhang-NY/ElyOffice`(原样推上 main、缺陷清单分支与 v0.1.0、v0.1.1 标签),组件库为同站的 `ZacharyZhang-NY/Ely-GPUI-Components`(Cargo 的 git 依赖与 `fetch-references.sh` 随之改址,钉的提交不变)。v0.1.1 的六个 dmg 与两个源码包重新发在 Gitea 的 v0.1.1 发布里。官网的下载与源码链接指向 Gitea(`releases/latest` 会跳到最新发布页)。`.github/workflows` 删去(它们靠 GitHub 的 macOS 机器与 `gh`,发布改在本机以 `packaging/macos/release.sh` 构建、经 Gitea API 上传)。发布视频里写的地址已在源文件改为 Gitea,已发布的成片仍是旧地址,重渲染后才更新。上游项目(LibreOffice、MuPDF、git-lfs、tessdata 等)照旧从它们自己的 GitHub 地址取。
|
- 2026-10-09(用户定):代码与发布从 GitHub 搬到自建的 Gitea(git.zacharyzhang.com;GitHub 账号被封,推送与发布都被拒)。公开仓库 `ZacharyZhang-NY/ElyOffice`(原样推上 main、缺陷清单分支与 v0.1.0、v0.1.1 标签),组件库为同站的 `ZacharyZhang-NY/Ely-GPUI-Components`(Cargo 的 git 依赖与 `fetch-references.sh` 随之改址,钉的提交不变)。v0.1.1 的六个 dmg 与两个源码包重新发在 Gitea 的 v0.1.1 发布里。官网的下载与源码链接指向 Gitea(`releases/latest` 会跳到最新发布页)。`.github/workflows` 删去(它们靠 GitHub 的 macOS 机器与 `gh`,发布改在本机以 `packaging/macos/release.sh` 构建、经 Gitea API 上传)。发布视频里写的地址已在源文件改为 Gitea,已发布的成片仍是旧地址,重渲染后才更新。上游项目(LibreOffice、MuPDF、git-lfs、tessdata 等)照旧从它们自己的 GitHub 地址取。
|
||||||
@@ -5,6 +5,10 @@ edition.workspace = true
|
|||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
|
build = "../../packaging/windows/icon.rs"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embed-resource.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ely-platform.workspace = true
|
ely-platform.workspace = true
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Release builds open no console on Windows.
|
||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
use ely_platform::AppId;
|
use ely_platform::AppId;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ edition.workspace = true
|
|||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
|
build = "../../packaging/windows/icon.rs"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embed-resource.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
csv.workspace = true
|
csv.workspace = true
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Release builds open no console on Windows.
|
||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
mod actions;
|
mod actions;
|
||||||
mod chrome;
|
mod chrome;
|
||||||
mod compare;
|
mod compare;
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ edition.workspace = true
|
|||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
|
build = "../../packaging/windows/icon.rs"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embed-resource.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ely-platform.workspace = true
|
ely-platform.workspace = true
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Release builds open no console on Windows.
|
||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
use ely_platform::AppId;
|
use ely_platform::AppId;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ edition.workspace = true
|
|||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
|
build = "../../packaging/windows/icon.rs"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embed-resource.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Release builds open no console on Windows.
|
||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
mod attach;
|
mod attach;
|
||||||
mod autosave;
|
mod autosave;
|
||||||
mod compare;
|
mod compare;
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ edition.workspace = true
|
|||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
|
build = "../../packaging/windows/icon.rs"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embed-resource.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ely-files.workspace = true
|
ely-files.workspace = true
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Release builds open no console on Windows.
|
||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
mod annotate;
|
mod annotate;
|
||||||
mod ask;
|
mod ask;
|
||||||
mod attach;
|
mod attach;
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ edition.workspace = true
|
|||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
|
build = "../../packaging/windows/icon.rs"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embed-resource.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ely-files.workspace = true
|
ely-files.workspace = true
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Release builds open no console on Windows.
|
||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
mod chart;
|
mod chart;
|
||||||
mod check;
|
mod check;
|
||||||
mod deck;
|
mod deck;
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ edition.workspace = true
|
|||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
|
build = "../../packaging/windows/icon.rs"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embed-resource.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
encoding_rs.workspace = true
|
encoding_rs.workspace = true
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Release builds open no console on Windows.
|
||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
mod analysis;
|
mod analysis;
|
||||||
mod bars;
|
mod bars;
|
||||||
mod book;
|
mod book;
|
||||||
|
|||||||
@@ -5,8 +5,13 @@ edition.workspace = true
|
|||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
|
build = "../../packaging/windows/icon.rs"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embed-resource.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
dunce.workspace = true
|
||||||
ely-files.workspace = true
|
ely-files.workspace = true
|
||||||
ely-gpui-component.workspace = true
|
ely-gpui-component.workspace = true
|
||||||
ely-platform.workspace = true
|
ely-platform.workspace = true
|
||||||
|
|||||||
@@ -6,13 +6,10 @@ use std::{
|
|||||||
process::{Command, Output, Stdio},
|
process::{Command, Output, Stdio},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A Git binary and its version.
|
/// A Git binary whose version was checked.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Git {
|
pub struct Git {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub version: String,
|
|
||||||
/// Ely's own build, not a system Git.
|
|
||||||
pub bundled: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Git {
|
impl Git {
|
||||||
@@ -39,11 +36,7 @@ impl Git {
|
|||||||
path.display(),
|
path.display(),
|
||||||
if bundled { "bundled" } else { "system" }
|
if bundled { "bundled" } else { "system" }
|
||||||
);
|
);
|
||||||
Ok(Git {
|
Ok(Git { path })
|
||||||
path,
|
|
||||||
version,
|
|
||||||
bundled,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs Git in `dir`; failure carries Git's words.
|
/// Runs Git in `dir`; failure carries Git's words.
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Release builds open no console on Windows.
|
||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
mod asks;
|
mod asks;
|
||||||
mod asks_places;
|
mod asks_places;
|
||||||
mod blame;
|
mod blame;
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ pub fn open(git: &Git, path: &Path) -> io::Result<Repo> {
|
|||||||
let common = ["rev-parse", "--path-format=absolute", "--git-common-dir"];
|
let common = ["rev-parse", "--path-format=absolute", "--git-common-dir"];
|
||||||
let common_dir = text(git.run(path, &common)?)?;
|
let common_dir = text(git.run(path, &common)?)?;
|
||||||
let repo = Repo {
|
let repo = Repo {
|
||||||
root: std::fs::canonicalize(root)?,
|
root: dunce::canonicalize(root)?,
|
||||||
git_dir: std::fs::canonicalize(git_dir)?,
|
git_dir: dunce::canonicalize(git_dir)?,
|
||||||
common_dir: std::fs::canonicalize(common_dir)?,
|
common_dir: dunce::canonicalize(common_dir)?,
|
||||||
};
|
};
|
||||||
log::info!("tree: opened {}", repo.root.display());
|
log::info!("tree: opened {}", repo.root.display());
|
||||||
Ok(repo)
|
Ok(repo)
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ pub fn worktrees(git: &Git, root: &Path) -> io::Result<Vec<Worktree>> {
|
|||||||
found.extend(now);
|
found.extend(now);
|
||||||
// Real paths, as the open repository's root is.
|
// Real paths, as the open repository's root is.
|
||||||
for tree in &mut found {
|
for tree in &mut found {
|
||||||
match std::fs::canonicalize(&tree.path) {
|
match dunce::canonicalize(&tree.path) {
|
||||||
Ok(real) => tree.path = real,
|
Ok(real) => tree.path = real,
|
||||||
Err(error) if error.kind() == io::ErrorKind::NotFound => {}
|
Err(error) if error.kind() == io::ErrorKind::NotFound => {}
|
||||||
Err(error) => return Err(error),
|
Err(error) => return Err(error),
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ fn a_repository_opens_from_inside_and_a_bare_one_does_not() {
|
|||||||
let opened = repo::open(&git(), &root.join("deep")).expect("opens");
|
let opened = repo::open(&git(), &root.join("deep")).expect("opens");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
opened.root,
|
opened.root,
|
||||||
std::fs::canonicalize(&root).expect("real"),
|
dunce::canonicalize(&root).expect("real"),
|
||||||
"the real top"
|
"the real top"
|
||||||
);
|
);
|
||||||
assert!(opened.git_dir.ends_with(".git"));
|
assert!(opened.git_dir.ends_with(".git"));
|
||||||
@@ -324,7 +324,7 @@ fn a_gone_upstream_has_no_counts() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn a_linked_file_keeps_its_own_name() {
|
fn a_linked_file_keeps_its_own_name() {
|
||||||
let dir = tempfile::tempdir().expect("a temp dir");
|
let dir = tempfile::tempdir().expect("a temp dir");
|
||||||
let root = std::fs::canonicalize(dir.path()).expect("real");
|
let root = dunce::canonicalize(dir.path()).expect("real");
|
||||||
std::fs::create_dir(root.join("docs")).expect("a folder");
|
std::fs::create_dir(root.join("docs")).expect("a folder");
|
||||||
std::fs::write(root.join("real.md"), "a").expect("a file");
|
std::fs::write(root.join("real.md"), "a").expect("a file");
|
||||||
let outside = tempfile::tempdir().expect("another dir");
|
let outside = tempfile::tempdir().expect("another dir");
|
||||||
|
|||||||
@@ -252,10 +252,10 @@ fn worktrees_list_branches_and_prunable_folders() {
|
|||||||
.expect("adds");
|
.expect("adds");
|
||||||
let list = structure::worktrees(&git(), &root).expect("reads");
|
let list = structure::worktrees(&git(), &root).expect("reads");
|
||||||
assert_eq!(list.len(), 2);
|
assert_eq!(list.len(), 2);
|
||||||
assert_eq!(list[0].path, std::fs::canonicalize(&root).expect("real"));
|
assert_eq!(list[0].path, dunce::canonicalize(&root).expect("real"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(list[1].path.clone(), list[1].branch.as_deref()),
|
(list[1].path.clone(), list[1].branch.as_deref()),
|
||||||
(std::fs::canonicalize(&other).expect("real"), Some("side"))
|
(dunce::canonicalize(&other).expect("real"), Some("side"))
|
||||||
);
|
);
|
||||||
std::fs::remove_dir_all(&other).expect("removes");
|
std::fs::remove_dir_all(&other).expect("removes");
|
||||||
let list = structure::worktrees(&git(), &root).expect("reads");
|
let list = structure::worktrees(&git(), &root).expect("reads");
|
||||||
@@ -497,5 +497,5 @@ fn a_worktree_registered_through_a_link_lists_its_real_path() {
|
|||||||
)
|
)
|
||||||
.expect("writes");
|
.expect("writes");
|
||||||
let list = structure::worktrees(&git(), &root).expect("reads");
|
let list = structure::worktrees(&git(), &root).expect("reads");
|
||||||
assert_eq!(list[1].path, std::fs::canonicalize(&other).expect("real"));
|
assert_eq!(list[1].path, dunce::canonicalize(&other).expect("real"));
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ fn one_tab_per_repository_and_reopening_selects_it() {
|
|||||||
let recent = cx.update(|_, app| tree.read(app).recent.clone());
|
let recent = cx.update(|_, app| tree.read(app).recent.clone());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
recent[0],
|
recent[0],
|
||||||
std::fs::canonicalize(&first).expect("real"),
|
dunce::canonicalize(&first).expect("real"),
|
||||||
"newest first"
|
"newest first"
|
||||||
);
|
);
|
||||||
cx.update(|_, app| tree.update(app, |tree, cx| tree.close_active(cx)));
|
cx.update(|_, app| tree.update(app, |tree, cx| tree.close_active(cx)));
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ pub fn open(app: AppId, window: &mut Window, cx: &mut App) -> Entity<Root> {
|
|||||||
/// `file` as Git names it; a symlink stays itself.
|
/// `file` as Git names it; a symlink stays itself.
|
||||||
pub(crate) fn inside(root: &Path, file: &Path) -> io::Result<String> {
|
pub(crate) fn inside(root: &Path, file: &Path) -> io::Result<String> {
|
||||||
let name = file.file_name().ok_or_else(|| io::Error::other("a path without a name"))?;
|
let name = file.file_name().ok_or_else(|| io::Error::other("a path without a name"))?;
|
||||||
let dir = std::fs::canonicalize(file.parent().unwrap_or(Path::new(".")))?;
|
let dir = dunce::canonicalize(file.parent().unwrap_or(Path::new(".")))?;
|
||||||
let rel = dir.join(name);
|
let rel = dir.join(name);
|
||||||
let rel = rel.strip_prefix(root).map_err(io::Error::other)?;
|
let rel = rel.strip_prefix(root).map_err(io::Error::other)?;
|
||||||
rel.to_str().map(str::to_owned).ok_or_else(|| io::Error::other("a path that is not UTF-8"))
|
rel.to_str().map(str::to_owned).ok_or_else(|| io::Error::other("a path that is not UTF-8"))
|
||||||
|
|||||||
@@ -97,21 +97,6 @@ impl Tree {
|
|||||||
StatusBarItem::new("tree-path").label(opened.repo.root.display().to_string()),
|
StatusBarItem::new("tree-path").label(opened.repo.root.display().to_string()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Ok(git) = &self.git {
|
|
||||||
let key = if git.bundled {
|
|
||||||
"tree.git.bundled"
|
|
||||||
} else {
|
|
||||||
"tree.git.system"
|
|
||||||
};
|
|
||||||
bar = bar.right(StatusBarItem::new("tree-git").label(text(
|
|
||||||
cx,
|
|
||||||
key,
|
|
||||||
&[
|
|
||||||
("version", &git.version),
|
|
||||||
("path", &git.path.display().to_string()),
|
|
||||||
],
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
bar
|
bar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,18 @@ mod relay;
|
|||||||
pub use relay::{Relay, relay};
|
pub use relay::{Relay, relay};
|
||||||
|
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
/// A child that opens no console window on Windows.
|
||||||
|
pub fn windowless(command: &mut Command) -> &mut Command {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
use std::os::windows::process::CommandExt as _;
|
||||||
|
// CREATE_NO_WINDOW
|
||||||
|
command.creation_flags(0x0800_0000);
|
||||||
|
}
|
||||||
|
command
|
||||||
|
}
|
||||||
|
|
||||||
/// A frame: u32 length, u8 tag, u64 request id, payload.
|
/// A frame: u32 length, u8 tag, u64 request id, payload.
|
||||||
pub const MAX_FRAME: usize = 64 * 1024 * 1024;
|
pub const MAX_FRAME: usize = 64 * 1024 * 1024;
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ impl Worker {
|
|||||||
let worker_bin = worker_bin()?;
|
let worker_bin = worker_bin()?;
|
||||||
log::info!("lok: worker from {}", worker_bin.display());
|
log::info!("lok: worker from {}", worker_bin.display());
|
||||||
let mut command = Command::new(worker_bin);
|
let mut command = Command::new(worker_bin);
|
||||||
command
|
ely_ipc::windowless(&mut command)
|
||||||
.arg(install)
|
.arg(install)
|
||||||
.arg(profile_dir)
|
.arg(profile_dir)
|
||||||
.env("SAL_FORCE_HIDPI_SCALING", "1")
|
.env("SAL_FORCE_HIDPI_SCALING", "1")
|
||||||
|
|||||||
@@ -180,3 +180,18 @@ pub(super) fn open_book(text: &str) -> (tempfile::TempDir, Worker, Doc) {
|
|||||||
.expect("the area");
|
.expect("the area");
|
||||||
(dir, worker, doc)
|
(dir, worker, doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_theme_switch_is_no_edit() {
|
||||||
|
if install().is_none() {
|
||||||
|
eprintln!("SKIP: no pinned LOK build");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let (_dir, mut worker, doc) = open_book(FODS);
|
||||||
|
for scheme in ["COLOR_SCHEME_ELY_DARK", "COLOR_SCHEME_ELY_LIGHT"] {
|
||||||
|
worker.run(&doc, "view.theme", &[scheme]).expect("the theme runs");
|
||||||
|
let undo = worker.values(&doc, ".uno:Undo").expect("the undo stack");
|
||||||
|
let undo: serde_json::Value = serde_json::from_str(&undo).expect("undo JSON");
|
||||||
|
assert_eq!(undo["actions"], "", "{scheme} left undo steps");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -103,7 +103,7 @@ impl Worker {
|
|||||||
|
|
||||||
/// Spawns `bin`; one from other sources is refused.
|
/// Spawns `bin`; one from other sources is refused.
|
||||||
pub fn spawn_from(bin: &Path) -> io::Result<Self> {
|
pub fn spawn_from(bin: &Path) -> io::Result<Self> {
|
||||||
let mut child = Command::new(bin)
|
let mut child = ely_ipc::windowless(&mut Command::new(bin))
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ publish.workspace = true
|
|||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
arboard.workspace = true
|
arboard.workspace = true
|
||||||
directories.workspace = true
|
directories.workspace = true
|
||||||
|
ely-ipc.workspace = true
|
||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
image.workspace = true
|
image.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ pub fn open_default(path: &Path) -> io::Result<()> {
|
|||||||
} else {
|
} else {
|
||||||
Command::new("xdg-open")
|
Command::new("xdg-open")
|
||||||
};
|
};
|
||||||
let out = command.arg(path).output()?;
|
let out = ely_ipc::windowless(&mut command).arg(path).output()?;
|
||||||
if !out.status.success() {
|
if !out.status.success() {
|
||||||
let said = String::from_utf8_lossy(&out.stderr).trim().to_owned();
|
let said = String::from_utf8_lossy(&out.stderr).trim().to_owned();
|
||||||
return Err(io::Error::other(said));
|
return Err(io::Error::other(said));
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ pub fn parse_version(text: &str) -> Option<(u32, u32)> {
|
|||||||
|
|
||||||
/// What `git --version` says, once it succeeds.
|
/// What `git --version` says, once it succeeds.
|
||||||
pub fn version_of(path: &Path) -> io::Result<(String, (u32, u32))> {
|
pub fn version_of(path: &Path) -> io::Result<(String, (u32, u32))> {
|
||||||
let output = Command::new(path).arg("--version").output()?;
|
let output = ely_ipc::windowless(&mut Command::new(path)).arg("--version").output()?;
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
let said = String::from_utf8_lossy(&output.stderr).trim().to_string();
|
let said = String::from_utf8_lossy(&output.stderr).trim().to_string();
|
||||||
return Err(io::Error::other(format!("{} --version failed ({}): {said}", path.display(), output.status)));
|
return Err(io::Error::other(format!("{} --version failed ({}): {said}", path.display(), output.status)));
|
||||||
@@ -83,7 +83,7 @@ fn own(dir: &Path) -> PathBuf {
|
|||||||
/// Git at `git` in `dir`, as Ely runs it.
|
/// Git at `git` in `dir`, as Ely runs it.
|
||||||
pub fn command(git: &Path, dir: &Path, args: &[&str]) -> Command {
|
pub fn command(git: &Path, dir: &Path, args: &[&str]) -> Command {
|
||||||
let mut command = Command::new(git);
|
let mut command = Command::new(git);
|
||||||
command
|
ely_ipc::windowless(&mut command)
|
||||||
.args(args)
|
.args(args)
|
||||||
.current_dir(dir)
|
.current_dir(dir)
|
||||||
// Reads never take the index lock from an outside Git.
|
// Reads never take the index lock from an outside Git.
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ pub(super) const EN: &[(&str, &str)] = &[
|
|||||||
("tree.branch.unborn", "{branch}, no commits yet"),
|
("tree.branch.unborn", "{branch}, no commits yet"),
|
||||||
("tree.ahead_behind", "{upstream} ↑{ahead} ↓{behind}"),
|
("tree.ahead_behind", "{upstream} ↑{ahead} ↓{behind}"),
|
||||||
("tree.upstream_gone", "{upstream} is gone"),
|
("tree.upstream_gone", "{upstream} is gone"),
|
||||||
("tree.git.bundled", "{version}, bundled, {path}"),
|
|
||||||
("tree.git.system", "{version}, system, {path}"),
|
|
||||||
("tree.busy", "Wait for this repository's changes to finish."),
|
("tree.busy", "Wait for this repository's changes to finish."),
|
||||||
("tree.gone", "{path} is not on disk."),
|
("tree.gone", "{path} is not on disk."),
|
||||||
("tree.discard.title", "Discard changes to {path}?"),
|
("tree.discard.title", "Discard changes to {path}?"),
|
||||||
@@ -155,8 +153,6 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
|
|||||||
("tree.branch.unborn", "{branch},尚无提交"),
|
("tree.branch.unborn", "{branch},尚无提交"),
|
||||||
("tree.ahead_behind", "{upstream} ↑{ahead} ↓{behind}"),
|
("tree.ahead_behind", "{upstream} ↑{ahead} ↓{behind}"),
|
||||||
("tree.upstream_gone", "{upstream} 已不存在"),
|
("tree.upstream_gone", "{upstream} 已不存在"),
|
||||||
("tree.git.bundled", "{version},随附,{path}"),
|
|
||||||
("tree.git.system", "{version},系统,{path}"),
|
|
||||||
("tree.busy", "请等此仓库的改动完成。"),
|
("tree.busy", "请等此仓库的改动完成。"),
|
||||||
("tree.gone", "{path} 不在磁盘上。"),
|
("tree.gone", "{path} 不在磁盘上。"),
|
||||||
("tree.discard.title", "放弃 {path} 的改动?"),
|
("tree.discard.title", "放弃 {path} 的改动?"),
|
||||||
|
|||||||
+2
-2
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
## 自有代码
|
## 自有代码
|
||||||
|
|
||||||
Ely Office 的自有代码以 AGPL-3.0-or-later 发布,全文在仓库根的 `LICENSE`,并随每个应用包放在 `Resources/Licenses/LICENSE`。组件库 Ely-GPUI-Components 保留其 MIT/Apache-2.0。
|
Ely Office 的自有代码以 MIT 发布,全文在仓库根的 `LICENSE`,并随每个应用包放在 `Resources/Licenses/LICENSE`。随包的引擎不随之改许可:ElyPDF 链接的 MuPDF 是 AGPL-3.0,ElyPDF 的发行包整体须按 AGPL 履行(对应源码见上游源码包);ElyDoc、ElyTable、ElyShow 的 LibreOffice 仍为 MPL-2.0 等;ElyTree 带的 Git 仍为 GPL-2.0。组件库 Ely-GPUI-Components 保留其 MIT/Apache-2.0。
|
||||||
|
|
||||||
## 每个发行版附带
|
## 每个发行版附带
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ Ely Office 的自有代码以 AGPL-3.0-or-later 发布,全文在仓库根的 `
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `ElyOffice-<版本>-source.tar.gz` | 自有源码、`Cargo.lock`、`rust-toolchain.toml`、ElyMark 网页的 `package-lock.json`、上游补丁(`patches/libreoffice`、`patches/mupdf`)、构建与取上游的脚本(各上游钉在提交,脚本里写明地址与散列)、测试、文档 | `packaging/macos/release.sh` |
|
| `ElyOffice-<版本>-source.tar.gz` | 自有源码、`Cargo.lock`、`rust-toolchain.toml`、ElyMark 网页的 `package-lock.json`、上游补丁(`patches/libreoffice`、`patches/mupdf`)、构建与取上游的脚本(各上游钉在提交,脚本里写明地址与散列)、测试、文档 | `packaging/macos/release.sh` |
|
||||||
| `ElyOffice-<版本>-upstream-source.tar.gz` | 实际编译的 MuPDF 源码(钉住的提交加我们的补丁,AGPL)与随包 Git 的源码(v2.56.0,GPLv2) | 同上;`tests/scripts/release-macos.sh` 核对其中是打过补丁的 MuPDF |
|
| `ElyOffice-<版本>-upstream-source.tar.gz` | 实际编译的 MuPDF 源码(钉住的提交加我们的补丁,AGPL)与随包 Git 的源码(v2.56.0,GPLv2) | 同上;`tests/scripts/release-macos.sh` 核对其中是打过补丁的 MuPDF |
|
||||||
| 各应用包 `Resources/Licenses/` | Ely 的 AGPL 全文;`rust-crates.txt`(链进该应用各二进制的全部 crate 与其许可文件,无许可文件的取标准文本并写明作者);所带引擎的许可与通知(见下) | `packaging/licenses.sh`,缺任何一份即打包失败 |
|
| 各应用包 `Resources/Licenses/` | Ely 的 MIT 全文;`rust-crates.txt`(链进该应用各二进制的全部 crate 与其许可文件,无许可文件的取标准文本并写明作者);所带引擎的许可与通知(见下) | `packaging/licenses.sh`,缺任何一份即打包失败 |
|
||||||
|
|
||||||
## 第三方,按应用
|
## 第三方,按应用
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
<node oor:name="Shadow"><prop oor:name="Color"><value>0</value></prop></node>
|
<node oor:name="Shadow"><prop oor:name="Color"><value>0</value></prop></node>
|
||||||
<node oor:name="WriterFieldShadings"><prop oor:name="Color"><value>4144959</value></prop></node>
|
<node oor:name="WriterFieldShadings"><prop oor:name="Color"><value>4144959</value></prop></node>
|
||||||
<node oor:name="WriterIdxShadings"><prop oor:name="Color"><value>4144959</value></prop></node>
|
<node oor:name="WriterIdxShadings"><prop oor:name="Color"><value>4144959</value></prop></node>
|
||||||
<node oor:name="CalcNotesBackground"><prop oor:name="Color"><value>3417617</value></prop></node>
|
<node oor:name="CalcNotesBackground"><prop oor:name="Color"><value>16777152</value></prop></node>
|
||||||
<node oor:name="CalcPageBreak"><prop oor:name="Color"><value>6052440</value></prop></node>
|
<node oor:name="CalcPageBreak"><prop oor:name="Color"><value>6052440</value></prop></node>
|
||||||
<node oor:name="CalcHiddenColRow"><prop oor:name="Color"><value>6052440</value></prop></node>
|
<node oor:name="CalcHiddenColRow"><prop oor:name="Color"><value>6052440</value></prop></node>
|
||||||
<node oor:name="CalcCellFocus"><prop oor:name="Color"><value>6922728</value></prop></node>
|
<node oor:name="CalcCellFocus"><prop oor:name="Color"><value>6922728</value></prop></node>
|
||||||
|
|||||||
@@ -44,10 +44,15 @@ case $slug in
|
|||||||
parts=$(python3 "$root/packaging/windows/mupdf-parts.py" "$root/engines/mupdf-src" parts)
|
parts=$(python3 "$root/packaging/windows/mupdf-parts.py" "$root/engines/mupdf-src" parts)
|
||||||
families=$(python3 "$root/packaging/windows/mupdf-parts.py" "$root/engines/mupdf-src" fonts)
|
families=$(python3 "$root/packaging/windows/mupdf-parts.py" "$root/engines/mupdf-src" fonts)
|
||||||
;;
|
;;
|
||||||
*)
|
Darwin)
|
||||||
parts=$(ls "$root/engines/mupdf-build/thirdparty")
|
parts=$(ls "$root/engines/mupdf-build/thirdparty")
|
||||||
families=$(ls "$root/engines/mupdf-build/generated/resources/fonts")
|
families=$(ls "$root/engines/mupdf-build/generated/resources/fonts")
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
# Linux links the font files in as objects.
|
||||||
|
parts=$(ls "$root/engines/mupdf-build/thirdparty")
|
||||||
|
families=$(ls "$root/engines/mupdf-build/resources/fonts")
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
for name in $parts; do
|
for name in $parts; do
|
||||||
found=$(find "$root/engines/mupdf-src/thirdparty/$name" -maxdepth 1 -type f \
|
found=$(find "$root/engines/mupdf-src/thirdparty/$name" -maxdepth 1 -type f \
|
||||||
@@ -69,7 +74,8 @@ case $slug in
|
|||||||
done
|
done
|
||||||
case $(uname) in
|
case $(uname) in
|
||||||
MINGW* | MSYS*) put OpenSSL "$root/engines/vcpkg/installed/x64-windows-static/share/openssl/copyright" ;;
|
MINGW* | MSYS*) put OpenSSL "$root/engines/vcpkg/installed/x64-windows-static/share/openssl/copyright" ;;
|
||||||
*) put OpenSSL "$(pkg-config --variable=prefix libcrypto)/LICENSE.txt" ;;
|
Darwin) put OpenSSL "$(pkg-config --variable=prefix libcrypto)/LICENSE.txt" ;;
|
||||||
|
*) put OpenSSL /usr/share/doc/libssl-dev/copyright /usr/share/common-licenses/Apache-2.0 ;;
|
||||||
esac
|
esac
|
||||||
put tessdata "${ELY_TESSDATA:-$root/engines/tessdata}/LICENSE"
|
put tessdata "${ELY_TESSDATA:-$root/engines/tessdata}/LICENSE"
|
||||||
put GreatVibes "$root/crates/ely-pdf-engine/fonts/OFL.txt"
|
put GreatVibes "$root/crates/ely-pdf-engine/fonts/OFL.txt"
|
||||||
|
|||||||
@@ -88,11 +88,19 @@ for helper in ely-lok-worker ely-pdf-worker; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ -f "$bin/libcef.so" ]; then
|
if [ -f "$bin/libcef.so" ]; then
|
||||||
deployed+=(--library "$bin/libcef.so")
|
# Binaries here load from usr/lib; CEF's data sits with libcef.
|
||||||
|
cef=${ELY_CEF:-$root/engines/cef}
|
||||||
|
mkdir -p "$appdir/usr/lib"
|
||||||
|
for item in "$bin"/*; do
|
||||||
|
if [ -e "$cef/${item##*/}" ]; then
|
||||||
|
mv "$item" "$appdir/usr/lib/"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
deployed+=(--library "$appdir/usr/lib/libcef.so")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# linuxdeploy bundles libraries and fails on a missing one.
|
# linuxdeploy bundles libraries and fails on a missing one.
|
||||||
"$deploy" --appimage-extract-and-run --appdir "$appdir" "${deployed[@]}" \
|
LD_LIBRARY_PATH=$appdir/usr/lib "$deploy" --appimage-extract-and-run --appdir "$appdir" "${deployed[@]}" \
|
||||||
--desktop-file "$work/$slug.desktop" --icon-file "$icon"
|
--desktop-file "$work/$slug.desktop" --icon-file "$icon"
|
||||||
|
|
||||||
mkdir -p "$dist"
|
mkdir -p "$dist"
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
//! Each app's build script: its icon as resource 1 on Windows.
|
||||||
|
|
||||||
|
use std::{env, fs, path::PathBuf};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let app = env::var("CARGO_PKG_NAME").expect("cargo names the package");
|
||||||
|
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("cargo names the folder"));
|
||||||
|
let icon = root.join("../../assets/icons").join(format!("{app}.ico"));
|
||||||
|
let icon = fs::canonicalize(&icon).unwrap_or_else(|error| panic!("{}: {error}", icon.display()));
|
||||||
|
println!("cargo:rerun-if-changed={}", icon.display());
|
||||||
|
// gpui's window icon is resource 1.
|
||||||
|
let rc = PathBuf::from(env::var("OUT_DIR").expect("cargo gives OUT_DIR")).join("icon.rc");
|
||||||
|
let path = icon.to_str().expect("a UTF-8 path").trim_start_matches(r"\\?\").replace('\\', "/");
|
||||||
|
fs::write(&rc, format!("1 ICON \"{path}\"\n")).expect("the resource script is written");
|
||||||
|
embed_resource::compile(&rc, embed_resource::NONE)
|
||||||
|
.manifest_optional()
|
||||||
|
.expect("the icon resource compiles");
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
LOK: Windows paints tiles and slide layers, then copies
|
||||||
|
|
||||||
|
Win32 virtual devices have no SetSizeUsingBuffer: the base default
|
||||||
|
returns false, so the device for a client buffer stayed 1x1 pixel.
|
||||||
|
Calc tiles came back black with one painted pixel, and slide layers
|
||||||
|
were empty. Take the macOS path there: paint into the device at full
|
||||||
|
size, then copy the pixels into the client buffer.
|
||||||
|
|
||||||
|
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
|
||||||
|
index 39b72fb..253fbc0 100644
|
||||||
|
--- a/desktop/source/lib/init.cxx
|
||||||
|
+++ b/desktop/source/lib/init.cxx
|
||||||
|
@@ -4325,8 +4325,8 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
|
||||||
|
// Set background to transparent by default.
|
||||||
|
pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
|
||||||
|
|
||||||
|
-#if defined(MACOSX)
|
||||||
|
- // Aqua devices cannot paint client buffers: paint, then copy.
|
||||||
|
+#if defined(MACOSX) || defined(_WIN32)
|
||||||
|
+ // No client buffers here: paint, then copy.
|
||||||
|
pDevice->SetOutputSizePixel(Size(nCanvasWidth, nCanvasHeight));
|
||||||
|
#else
|
||||||
|
pDevice->SetOutputSizePixelScaleOffsetAndLOKBuffer(
|
||||||
|
diff --git a/sd/source/ui/tools/SlideshowLayerRenderer.cxx b/sd/source/ui/tools/SlideshowLayerRenderer.cxx
|
||||||
|
index 7ecd4ad..3f3a478 100644
|
||||||
|
--- a/sd/source/ui/tools/SlideshowLayerRenderer.cxx
|
||||||
|
+++ b/sd/source/ui/tools/SlideshowLayerRenderer.cxx
|
||||||
|
@@ -88,7 +88,7 @@ private:
|
||||||
|
|
||||||
|
EEControlBits mnSavedControlBits;
|
||||||
|
Color maSavedBackgroundColor;
|
||||||
|
-#if defined(MACOSX)
|
||||||
|
+#if defined(MACOSX) || defined(_WIN32)
|
||||||
|
unsigned char* mpBuffer;
|
||||||
|
Size maBufferSize;
|
||||||
|
#endif
|
||||||
|
@@ -103,7 +103,7 @@ public:
|
||||||
|
, maVirtualDevice(
|
||||||
|
CoreGraphics::getiOSGraphicsData(pBuffer, rSlideSize.Width(), rSlideSize.Height()),
|
||||||
|
Size(1, 1), DeviceFormat::WITHOUT_ALPHA)
|
||||||
|
-#elif defined(MACOSX)
|
||||||
|
+#elif defined(MACOSX) || defined(_WIN32)
|
||||||
|
, mpBuffer(pBuffer)
|
||||||
|
, maBufferSize(rSlideSize)
|
||||||
|
, maVirtualDevice(DeviceFormat::WITH_ALPHA)
|
||||||
|
@@ -123,8 +123,8 @@ public:
|
||||||
|
|
||||||
|
maVirtualDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
|
||||||
|
|
||||||
|
-#if defined(MACOSX)
|
||||||
|
- // Aqua devices cannot paint client buffers: paint, then copy.
|
||||||
|
+#if defined(MACOSX) || defined(_WIN32)
|
||||||
|
+ // No client buffers here: paint, then copy.
|
||||||
|
(void)rScale;
|
||||||
|
maVirtualDevice->SetOutputSizePixel(rSlideSize);
|
||||||
|
#else
|
||||||
|
@@ -155,7 +155,7 @@ public:
|
||||||
|
#ifdef IOS
|
||||||
|
CoreGraphics::CGContextRelease(maVirtualDevice->GetSystemGfxData().rCGContext);
|
||||||
|
#endif
|
||||||
|
-#if defined(MACOSX)
|
||||||
|
+#if defined(MACOSX) || defined(_WIN32)
|
||||||
|
maVirtualDevice->EnableMapMode(false);
|
||||||
|
vcl::bitmap::fillWithData(mpBuffer,
|
||||||
|
maVirtualDevice->GetBitmap(Point(), maBufferSize));
|
||||||
Regular → Executable
+1
-1
@@ -19,7 +19,7 @@ if [ -n "${ELY_SHARE:-}" ]; then
|
|||||||
for part in engines reference; do
|
for part in engines reference; do
|
||||||
if [ ! -e "$part" ]; then
|
if [ ! -e "$part" ]; then
|
||||||
case $os in
|
case $os in
|
||||||
windows) cmd //c mklink /J "$part" "$(cygpath -w "$ELY_SHARE/$part")" ;;
|
windows) powershell -NoProfile -Command "New-Item -ItemType Junction -Path '$part' -Target '$(cygpath -w "$ELY_SHARE/$part")' | Out-Null" ;;
|
||||||
*) ln -s "$ELY_SHARE/$part" "$part" ;;
|
*) ln -s "$ELY_SHARE/$part" "$part" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ fetch() { # name url rev [sparse paths...]
|
|||||||
echo "fetch $name $rev"
|
echo "fetch $name $rev"
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch Ely-GPUI-Components https://git.zacharyzhang.com/ZacharyZhang-NY/Ely-GPUI-Components.git 5d6efd46ec0c93b381ec7578561a1273c366025b
|
fetch Ely-GPUI-Components https://git.zacharyzhang.com/ZacharyZhang-NY/Ely-GPUI-Components.git bd014707fd47cd9d0651a9af8c1db6033718a6ea
|
||||||
fetch zed https://github.com/zed-industries/zed.git 1a28cff4b409169bac058bca40dfbfeb7621d19b
|
fetch zed https://github.com/zed-industries/zed.git 1a28cff4b409169bac058bca40dfbfeb7621d19b
|
||||||
fetch libreoffice-core https://github.com/LibreOffice/core.git 8221e31b3ac356a1623c672912a3d2b492f7e3d1 \
|
fetch libreoffice-core https://github.com/LibreOffice/core.git 8221e31b3ac356a1623c672912a3d2b492f7e3d1 \
|
||||||
include/LibreOfficeKit libreofficekit desktop/source/lib desktop/inc \
|
include/LibreOfficeKit libreofficekit desktop/source/lib desktop/inc \
|
||||||
|
|||||||
+2
-2
@@ -10,7 +10,7 @@ const en = {
|
|||||||
ElyTree: "Stage lines, commit, read the graph. Git without a terminal.",
|
ElyTree: "Stage lines, commit, read the graph. Git without a terminal.",
|
||||||
ElyMark: "Markdown as you read it. Math and diagrams in place.",
|
ElyMark: "Markdown as you read it. Math and diagrams in place.",
|
||||||
offline: "Works with the network off.",
|
offline: "Works with the network off.",
|
||||||
open: "Open source, under the AGPL.",
|
open: "Open source, under the MIT licence.",
|
||||||
local: "Your files stay in your folders.",
|
local: "Your files stay in your folders.",
|
||||||
download: "Download",
|
download: "Download",
|
||||||
platforms: "Out now for macOS. Windows and Linux are coming soon.",
|
platforms: "Out now for macOS. Windows and Linux are coming soon.",
|
||||||
@@ -46,7 +46,7 @@ const zh: typeof en = {
|
|||||||
ElyTree: "按行暂存、提交、看提交图。不用终端的 Git。",
|
ElyTree: "按行暂存、提交、看提交图。不用终端的 Git。",
|
||||||
ElyMark: "写的就是看到的 Markdown。公式与图表就地显示。",
|
ElyMark: "写的就是看到的 Markdown。公式与图表就地显示。",
|
||||||
offline: "断网照常工作。",
|
offline: "断网照常工作。",
|
||||||
open: "开源,AGPL 许可。",
|
open: "开源,MIT 许可。",
|
||||||
local: "文件留在你自己的文件夹里。",
|
local: "文件留在你自己的文件夹里。",
|
||||||
download: "下载",
|
download: "下载",
|
||||||
platforms: "macOS 版已发布。Windows 与 Linux 版即将推出。",
|
platforms: "macOS 版已发布。Windows 与 Linux 版即将推出。",
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ trap 'rm -rf "$work"' EXIT
|
|||||||
tree=$work/tree
|
tree=$work/tree
|
||||||
mkdir -p "$tree"
|
mkdir -p "$tree"
|
||||||
git -C "$tree" init -q
|
git -C "$tree" init -q
|
||||||
|
# LF, as every tree here; Windows defaults convert.
|
||||||
|
git -C "$tree" config core.autocrlf false
|
||||||
for f in $files; do
|
for f in $files; do
|
||||||
if git -C "$src" cat-file -e "HEAD:$f" 2>/dev/null; then
|
if git -C "$src" cat-file -e "HEAD:$f" 2>/dev/null; then
|
||||||
mkdir -p "$tree/$(dirname "$f")"
|
mkdir -p "$tree/$(dirname "$f")"
|
||||||
|
|||||||
+5167
File diff suppressed because it is too large.
Load diff
Vendored
+683
@@ -0,0 +1,683 @@
|
|||||||
|
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||||
|
#
|
||||||
|
# When uploading crates to the registry Cargo will automatically
|
||||||
|
# "normalize" Cargo.toml files for maximal compatibility
|
||||||
|
# with all versions of Cargo and also rewrite `path` dependencies
|
||||||
|
# to registry (e.g., crates.io) dependencies.
|
||||||
|
#
|
||||||
|
# If you are reading this file be aware that the original Cargo.toml
|
||||||
|
# will likely look very different (and much more reasonable).
|
||||||
|
# See Cargo.toml.orig for the original contents.
|
||||||
|
|
||||||
|
[package]
|
||||||
|
edition = "2024"
|
||||||
|
name = "gpui-pre"
|
||||||
|
version = "0.3.8"
|
||||||
|
authors = ["Nathan Sobo <nathan@zed.dev>"]
|
||||||
|
build = "build.rs"
|
||||||
|
publish = true
|
||||||
|
autolib = false
|
||||||
|
autobins = false
|
||||||
|
autoexamples = false
|
||||||
|
autotests = false
|
||||||
|
autobenches = false
|
||||||
|
description = "Zed's GPU-accelerated UI framework (gpui-pre snapshot of zed@279fe07)"
|
||||||
|
homepage = "https://gpui.rs"
|
||||||
|
readme = "README.md"
|
||||||
|
keywords = [
|
||||||
|
"desktop",
|
||||||
|
"gui",
|
||||||
|
"immediate",
|
||||||
|
]
|
||||||
|
categories = ["gui"]
|
||||||
|
license = "Apache-2.0"
|
||||||
|
repository = "https://github.com/zed-industries/zed"
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
|
[package.metadata.cargo-shear]
|
||||||
|
ignored = [
|
||||||
|
"bindgen",
|
||||||
|
"font-kit",
|
||||||
|
"getrandom",
|
||||||
|
"objc2",
|
||||||
|
"objc2-metal",
|
||||||
|
]
|
||||||
|
ignored-paths = ["src/_ownership_and_data_flow.rs"]
|
||||||
|
|
||||||
|
[package.metadata.gpui-pre]
|
||||||
|
zed-crate = "gpui"
|
||||||
|
zed-version = "0.2.2"
|
||||||
|
zed-rev = "279fe070bb389b79652e52065b2f001edcc0b11b"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
bench = ["bench-support"]
|
||||||
|
bench-support = [
|
||||||
|
"profiler",
|
||||||
|
"dep:criterion",
|
||||||
|
"dep:bench_metrics",
|
||||||
|
]
|
||||||
|
default = [
|
||||||
|
"font-kit",
|
||||||
|
"wayland",
|
||||||
|
"x11",
|
||||||
|
"windows-manifest",
|
||||||
|
]
|
||||||
|
inspector = ["gpui_macros/inspector"]
|
||||||
|
leak-detection = []
|
||||||
|
profiler = ["dep:hdrhistogram"]
|
||||||
|
screen-capture = ["scap"]
|
||||||
|
stacker = ["dep:stacksafe"]
|
||||||
|
test-support = [
|
||||||
|
"collections/test-support",
|
||||||
|
"http_client/test-support",
|
||||||
|
"wayland",
|
||||||
|
"x11",
|
||||||
|
"proptest",
|
||||||
|
]
|
||||||
|
wayland = []
|
||||||
|
windows-manifest = ["dep:embed-resource"]
|
||||||
|
x11 = ["scap?/x11"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "gpui"
|
||||||
|
path = "src/gpui.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "a11y"
|
||||||
|
path = "examples/a11y.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "active_state_bug"
|
||||||
|
path = "examples/active_state_bug.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "anchor"
|
||||||
|
path = "examples/anchor.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "animation"
|
||||||
|
path = "examples/animation.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "data_table"
|
||||||
|
path = "examples/data_table.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "drag_drop"
|
||||||
|
path = "examples/drag_drop.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "focus_visible"
|
||||||
|
path = "examples/focus_visible.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "gif_viewer"
|
||||||
|
path = "examples/gif_viewer.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "gradient"
|
||||||
|
path = "examples/gradient.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "grid_layout"
|
||||||
|
path = "examples/grid_layout.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "hello_world"
|
||||||
|
path = "examples/hello_world.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "image"
|
||||||
|
path = "examples/image/image.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "image_gallery"
|
||||||
|
path = "examples/image_gallery.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "image_loading"
|
||||||
|
path = "examples/image_loading.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "input"
|
||||||
|
path = "examples/input.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "layer_shell"
|
||||||
|
path = "examples/layer_shell.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "list_example"
|
||||||
|
path = "examples/list_example.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "mouse_pressure"
|
||||||
|
path = "examples/mouse_pressure.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "move_entity_between_windows"
|
||||||
|
path = "examples/move_entity_between_windows.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "on_window_close_quit"
|
||||||
|
path = "examples/on_window_close_quit.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "opacity"
|
||||||
|
path = "examples/opacity.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "ownership_post"
|
||||||
|
path = "examples/ownership_post.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "painting"
|
||||||
|
path = "examples/painting.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "paths_bench"
|
||||||
|
path = "examples/paths_bench.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "pattern"
|
||||||
|
path = "examples/pattern.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "popover"
|
||||||
|
path = "examples/popover.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "scrollable"
|
||||||
|
path = "examples/scrollable.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "set_menus"
|
||||||
|
path = "examples/set_menus.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "shadow"
|
||||||
|
path = "examples/shadow.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "svg"
|
||||||
|
path = "examples/svg/svg.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "system_notifications"
|
||||||
|
path = "examples/system_notifications.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "tab_stop"
|
||||||
|
path = "examples/tab_stop.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "testing"
|
||||||
|
path = "examples/testing.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "text"
|
||||||
|
path = "examples/text.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "text_layout"
|
||||||
|
path = "examples/text_layout.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "text_wrapper"
|
||||||
|
path = "examples/text_wrapper.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "toggle_headless"
|
||||||
|
path = "examples/toggle_headless.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "tree"
|
||||||
|
path = "examples/tree.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "uniform_list"
|
||||||
|
path = "examples/uniform_list.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "view_example"
|
||||||
|
path = "examples/view_example/view_example_main.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "window"
|
||||||
|
path = "examples/window.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "window_movable"
|
||||||
|
path = "examples/window_movable.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "window_positioning"
|
||||||
|
path = "examples/window_positioning.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "window_shadow"
|
||||||
|
path = "examples/window_shadow.rs"
|
||||||
|
|
||||||
|
[[test]]
|
||||||
|
name = "action_macros"
|
||||||
|
path = "tests/action_macros.rs"
|
||||||
|
|
||||||
|
[dependencies.accesskit]
|
||||||
|
version = "0.24.0"
|
||||||
|
features = ["enumn"]
|
||||||
|
|
||||||
|
[dependencies.anyhow]
|
||||||
|
version = "1.0.86"
|
||||||
|
|
||||||
|
[dependencies.async-task]
|
||||||
|
version = "4.7"
|
||||||
|
|
||||||
|
[dependencies.backtrace]
|
||||||
|
version = "0.3"
|
||||||
|
|
||||||
|
[dependencies.bench_metrics]
|
||||||
|
version = "=0.3.8"
|
||||||
|
optional = true
|
||||||
|
package = "gpui-pre-bench-metrics"
|
||||||
|
|
||||||
|
[dependencies.bitflags]
|
||||||
|
version = "2.6.0"
|
||||||
|
|
||||||
|
[dependencies.chrono]
|
||||||
|
version = "0.4"
|
||||||
|
features = ["serde"]
|
||||||
|
|
||||||
|
[dependencies.collections]
|
||||||
|
version = "=0.3.8"
|
||||||
|
package = "gpui-pre-collections"
|
||||||
|
|
||||||
|
[dependencies.criterion]
|
||||||
|
version = "0.8.2"
|
||||||
|
features = ["html_reports"]
|
||||||
|
optional = true
|
||||||
|
|
||||||
|
[dependencies.ctor]
|
||||||
|
version = "1.0.12"
|
||||||
|
|
||||||
|
[dependencies.derive_more]
|
||||||
|
version = "2.1.1"
|
||||||
|
features = [
|
||||||
|
"add",
|
||||||
|
"add_assign",
|
||||||
|
"deref",
|
||||||
|
"deref_mut",
|
||||||
|
"display",
|
||||||
|
"from",
|
||||||
|
"from_str",
|
||||||
|
"mul",
|
||||||
|
"mul_assign",
|
||||||
|
"not",
|
||||||
|
]
|
||||||
|
|
||||||
|
[dependencies.etagere]
|
||||||
|
version = "0.2"
|
||||||
|
|
||||||
|
[dependencies.futures]
|
||||||
|
version = "0.3.34"
|
||||||
|
|
||||||
|
[dependencies.futures-concurrency]
|
||||||
|
version = "7.7.1"
|
||||||
|
|
||||||
|
[dependencies.gpui_macros]
|
||||||
|
version = "=0.3.8"
|
||||||
|
package = "gpui-pre-macros"
|
||||||
|
|
||||||
|
[dependencies.gpui_shared_string]
|
||||||
|
version = "=0.3.8"
|
||||||
|
package = "gpui-pre-shared-string"
|
||||||
|
|
||||||
|
[dependencies.gpui_util]
|
||||||
|
version = "=0.3.8"
|
||||||
|
package = "gpui-pre-util"
|
||||||
|
|
||||||
|
[dependencies.hdrhistogram]
|
||||||
|
version = "7"
|
||||||
|
optional = true
|
||||||
|
default-features = false
|
||||||
|
|
||||||
|
[dependencies.heapless]
|
||||||
|
version = "0.9.2"
|
||||||
|
|
||||||
|
[dependencies.http_client]
|
||||||
|
version = "=0.3.8"
|
||||||
|
package = "gpui-pre-http-client"
|
||||||
|
|
||||||
|
[dependencies.image]
|
||||||
|
version = "0.25.1"
|
||||||
|
features = [
|
||||||
|
"bmp",
|
||||||
|
"dds",
|
||||||
|
"exr",
|
||||||
|
"ff",
|
||||||
|
"gif",
|
||||||
|
"hdr",
|
||||||
|
"ico",
|
||||||
|
"jpeg",
|
||||||
|
"png",
|
||||||
|
"pnm",
|
||||||
|
"qoi",
|
||||||
|
"rayon",
|
||||||
|
"tga",
|
||||||
|
"tiff",
|
||||||
|
"webp",
|
||||||
|
]
|
||||||
|
default-features = false
|
||||||
|
|
||||||
|
[dependencies.inventory]
|
||||||
|
version = "0.3.19"
|
||||||
|
|
||||||
|
[dependencies.itertools]
|
||||||
|
version = "0.14.0"
|
||||||
|
|
||||||
|
[dependencies.log]
|
||||||
|
version = "0.4.16"
|
||||||
|
features = [
|
||||||
|
"kv_unstable_serde",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[dependencies.lyon]
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
|
[dependencies.num_cpus]
|
||||||
|
version = "1.13"
|
||||||
|
|
||||||
|
[dependencies.parking]
|
||||||
|
version = "2.0.0"
|
||||||
|
|
||||||
|
[dependencies.parking_lot]
|
||||||
|
version = "0.12.1"
|
||||||
|
|
||||||
|
[dependencies.pin-project]
|
||||||
|
version = "1.1.10"
|
||||||
|
|
||||||
|
[dependencies.pollster]
|
||||||
|
version = "0.4.0"
|
||||||
|
|
||||||
|
[dependencies.postage]
|
||||||
|
version = "0.5"
|
||||||
|
features = ["futures-traits"]
|
||||||
|
|
||||||
|
[dependencies.profiling]
|
||||||
|
version = "1"
|
||||||
|
|
||||||
|
[dependencies.proptest]
|
||||||
|
version = "1"
|
||||||
|
features = ["attr-macro"]
|
||||||
|
optional = true
|
||||||
|
package = "proptest"
|
||||||
|
|
||||||
|
[dependencies.rand]
|
||||||
|
version = "0.9"
|
||||||
|
|
||||||
|
[dependencies.raw-window-handle]
|
||||||
|
version = "0.6"
|
||||||
|
|
||||||
|
[dependencies.refineable]
|
||||||
|
version = "=0.3.8"
|
||||||
|
package = "gpui-pre-refineable"
|
||||||
|
|
||||||
|
[dependencies.regex]
|
||||||
|
version = "1.5"
|
||||||
|
|
||||||
|
[dependencies.resvg]
|
||||||
|
version = "0.46.0"
|
||||||
|
features = [
|
||||||
|
"text",
|
||||||
|
"system-fonts",
|
||||||
|
"memmap-fonts",
|
||||||
|
"raster-images",
|
||||||
|
]
|
||||||
|
default-features = false
|
||||||
|
|
||||||
|
[dependencies.scheduler]
|
||||||
|
version = "=0.3.8"
|
||||||
|
package = "gpui-pre-scheduler"
|
||||||
|
|
||||||
|
[dependencies.schemars]
|
||||||
|
version = "1.0"
|
||||||
|
features = ["indexmap2"]
|
||||||
|
|
||||||
|
[dependencies.seahash]
|
||||||
|
version = "4.1"
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
version = "1.0.221"
|
||||||
|
features = [
|
||||||
|
"derive",
|
||||||
|
"rc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[dependencies.serde_json]
|
||||||
|
version = "1.0.144"
|
||||||
|
features = [
|
||||||
|
"preserve_order",
|
||||||
|
"raw_value",
|
||||||
|
]
|
||||||
|
|
||||||
|
[dependencies.slotmap]
|
||||||
|
version = "1.0.6"
|
||||||
|
|
||||||
|
[dependencies.smallvec]
|
||||||
|
version = "1.6"
|
||||||
|
features = [
|
||||||
|
"union",
|
||||||
|
"const_new",
|
||||||
|
]
|
||||||
|
|
||||||
|
[dependencies.spin]
|
||||||
|
version = "0.10.0"
|
||||||
|
|
||||||
|
[dependencies.stacksafe]
|
||||||
|
version = "1.0"
|
||||||
|
optional = true
|
||||||
|
|
||||||
|
[dependencies.strum]
|
||||||
|
version = "0.28"
|
||||||
|
features = ["derive"]
|
||||||
|
|
||||||
|
[dependencies.sum_tree]
|
||||||
|
version = "=0.3.8"
|
||||||
|
package = "gpui-pre-sum-tree"
|
||||||
|
|
||||||
|
[dependencies.taffy]
|
||||||
|
version = "0.13.0"
|
||||||
|
|
||||||
|
[dependencies.thiserror]
|
||||||
|
version = "2.0.12"
|
||||||
|
|
||||||
|
[dependencies.ttf-parser]
|
||||||
|
version = "0.25"
|
||||||
|
|
||||||
|
[dependencies.url]
|
||||||
|
version = "2.2"
|
||||||
|
|
||||||
|
[dependencies.usvg]
|
||||||
|
version = "0.46.0"
|
||||||
|
default-features = false
|
||||||
|
|
||||||
|
[dependencies.util_macros]
|
||||||
|
version = "=0.3.8"
|
||||||
|
package = "gpui-pre-util-macros"
|
||||||
|
|
||||||
|
[dependencies.uuid]
|
||||||
|
version = "1.1.2"
|
||||||
|
features = [
|
||||||
|
"v4",
|
||||||
|
"v5",
|
||||||
|
"v7",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[dependencies.waker-fn]
|
||||||
|
version = "1.2.0"
|
||||||
|
|
||||||
|
[dependencies.web-time]
|
||||||
|
version = "1.1.0"
|
||||||
|
|
||||||
|
[build-dependencies.embed-resource]
|
||||||
|
version = "3.0"
|
||||||
|
optional = true
|
||||||
|
|
||||||
|
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies.async-channel]
|
||||||
|
version = "2.5.0"
|
||||||
|
default-features = false
|
||||||
|
|
||||||
|
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies.libc]
|
||||||
|
version = "0.2"
|
||||||
|
|
||||||
|
[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "windows"))'.dependencies.scap]
|
||||||
|
version = "0.0.8-zed"
|
||||||
|
optional = true
|
||||||
|
default-features = false
|
||||||
|
package = "zed-scap"
|
||||||
|
|
||||||
|
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.core-video]
|
||||||
|
version = "0.5.2"
|
||||||
|
features = ["metal"]
|
||||||
|
|
||||||
|
[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dependencies.async-channel]
|
||||||
|
version = "2.5.0"
|
||||||
|
|
||||||
|
[target.'cfg(target_family = "wasm")'.dependencies.getrandom]
|
||||||
|
version = "0.3.4"
|
||||||
|
features = ["wasm_js"]
|
||||||
|
|
||||||
|
[target.'cfg(target_family = "wasm")'.dependencies.uuid]
|
||||||
|
version = "1.1.2"
|
||||||
|
features = [
|
||||||
|
"v4",
|
||||||
|
"v5",
|
||||||
|
"v7",
|
||||||
|
"serde",
|
||||||
|
"js",
|
||||||
|
]
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.dependencies.font-kit]
|
||||||
|
version = "0.14.1-zed"
|
||||||
|
optional = true
|
||||||
|
package = "zed-font-kit"
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.dependencies.log]
|
||||||
|
version = "0.4.16"
|
||||||
|
features = [
|
||||||
|
"kv_unstable_serde",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.dependencies.objc2]
|
||||||
|
version = "0.6"
|
||||||
|
optional = true
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.dependencies.objc2-core-foundation]
|
||||||
|
version = "0.3.2"
|
||||||
|
default-features = false
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.dependencies.objc2-core-video]
|
||||||
|
version = "0.3.2"
|
||||||
|
features = [
|
||||||
|
"CVBuffer",
|
||||||
|
"CVImageBuffer",
|
||||||
|
]
|
||||||
|
default-features = false
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.dependencies.objc2-metal]
|
||||||
|
version = "0.3"
|
||||||
|
optional = true
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.build-dependencies.bindgen]
|
||||||
|
version = "0.72"
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "windows")'.dependencies.windows]
|
||||||
|
version = "0.62"
|
||||||
|
features = [
|
||||||
|
"Data_Xml_Dom",
|
||||||
|
"Foundation_Numerics",
|
||||||
|
"Globalization_DateTimeFormatting",
|
||||||
|
"Storage_Search",
|
||||||
|
"Storage_Streams",
|
||||||
|
"System_Threading",
|
||||||
|
"UI_Notifications",
|
||||||
|
"UI_ViewManagement",
|
||||||
|
"Wdk_System_SystemServices",
|
||||||
|
"Win32_Foundation",
|
||||||
|
"Win32_Globalization",
|
||||||
|
"Win32_Graphics_Direct3D",
|
||||||
|
"Win32_Graphics_Direct3D11",
|
||||||
|
"Win32_Graphics_Direct3D_Fxc",
|
||||||
|
"Win32_Graphics_DirectComposition",
|
||||||
|
"Win32_Graphics_DirectWrite",
|
||||||
|
"Win32_Graphics_DirectManipulation",
|
||||||
|
"Win32_Graphics_Dwm",
|
||||||
|
"Win32_Graphics_Dxgi",
|
||||||
|
"Win32_Graphics_Dxgi_Common",
|
||||||
|
"Win32_Graphics_Gdi",
|
||||||
|
"Win32_Graphics_Imaging",
|
||||||
|
"Win32_Graphics_Hlsl",
|
||||||
|
"Win32_Networking_WinSock",
|
||||||
|
"Win32_Security",
|
||||||
|
"Win32_Security_Credentials",
|
||||||
|
"Win32_Security_Cryptography",
|
||||||
|
"Win32_Storage_FileSystem",
|
||||||
|
"Win32_Storage_Packaging_Appx",
|
||||||
|
"Win32_System_Com",
|
||||||
|
"Win32_System_Com_StructuredStorage",
|
||||||
|
"Win32_System_Console",
|
||||||
|
"Win32_System_Diagnostics_Debug",
|
||||||
|
"Win32_System_DataExchange",
|
||||||
|
"Win32_System_IO",
|
||||||
|
"Win32_System_JobObjects",
|
||||||
|
"Win32_System_LibraryLoader",
|
||||||
|
"Win32_System_Memory",
|
||||||
|
"Win32_System_Ole",
|
||||||
|
"Win32_System_Performance",
|
||||||
|
"Win32_System_Pipes",
|
||||||
|
"Win32_System_Power",
|
||||||
|
"Win32_System_RestartManager",
|
||||||
|
"Win32_System_SystemInformation",
|
||||||
|
"Win32_System_SystemServices",
|
||||||
|
"Win32_System_Threading",
|
||||||
|
"Win32_System_Variant",
|
||||||
|
"Win32_System_WinRT",
|
||||||
|
"Win32_UI_Controls",
|
||||||
|
"Win32_UI_HiDpi",
|
||||||
|
"Win32_UI_Input_Ime",
|
||||||
|
"Win32_UI_Input_KeyboardAndMouse",
|
||||||
|
"Win32_UI_Input_Pointer",
|
||||||
|
"Win32_UI_Shell",
|
||||||
|
"Win32_UI_Shell_Common",
|
||||||
|
"Win32_UI_Shell_PropertiesSystem",
|
||||||
|
"Win32_UI_WindowsAndMessaging",
|
||||||
|
"Win32_Media",
|
||||||
|
"Win32_Foundation",
|
||||||
|
"Win32_System_Power",
|
||||||
|
"Win32_System_RemoteDesktop",
|
||||||
|
"Win32_System_Threading",
|
||||||
|
"Win32_System_WindowsProgramming",
|
||||||
|
]
|
||||||
|
|
||||||
|
[lints.clippy]
|
||||||
|
dbg_macro = "deny"
|
||||||
|
declare_interior_mutable_const = "deny"
|
||||||
|
disallowed_methods = "deny"
|
||||||
|
large_enum_variant = "allow"
|
||||||
|
let_underscore_future = "allow"
|
||||||
|
nonminimal_bool = "allow"
|
||||||
|
redundant_clone = "deny"
|
||||||
|
single_range_in_vec_init = "allow"
|
||||||
|
todo = "deny"
|
||||||
|
too_many_arguments = "allow"
|
||||||
|
type_complexity = "allow"
|
||||||
|
|
||||||
|
[lints.clippy.style]
|
||||||
|
level = "allow"
|
||||||
|
priority = -1
|
||||||
|
|
||||||
|
[lints.rust.unexpected_cfgs]
|
||||||
|
level = "allow"
|
||||||
|
priority = 0
|
||||||
+247
@@ -0,0 +1,247 @@
|
|||||||
|
[package]
|
||||||
|
name = "gpui-pre"
|
||||||
|
version = "0.3.8"
|
||||||
|
edition = { workspace = true }
|
||||||
|
authors = ["Nathan Sobo <nathan@zed.dev>"]
|
||||||
|
description = "Zed's GPU-accelerated UI framework (gpui-pre snapshot of zed@279fe07)"
|
||||||
|
repository = "https://github.com/zed-industries/zed"
|
||||||
|
publish = true
|
||||||
|
license = "Apache-2.0"
|
||||||
|
homepage = "https://gpui.rs"
|
||||||
|
readme = "README.md"
|
||||||
|
keywords = ["desktop", "gui", "immediate"]
|
||||||
|
categories = ["gui"]
|
||||||
|
|
||||||
|
[package.metadata.cargo-shear]
|
||||||
|
ignored = ["bindgen", "font-kit", "getrandom", "objc2", "objc2-metal"]
|
||||||
|
ignored-paths = ["src/_ownership_and_data_flow.rs"]
|
||||||
|
|
||||||
|
[package.metadata.gpui-pre]
|
||||||
|
zed-crate = "gpui"
|
||||||
|
zed-version = "0.2.2"
|
||||||
|
zed-rev = "279fe070bb389b79652e52065b2f001edcc0b11b"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/gpui.rs"
|
||||||
|
name = "gpui"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["font-kit", "wayland", "x11", "windows-manifest"]
|
||||||
|
test-support = [
|
||||||
|
"collections/test-support",
|
||||||
|
"http_client/test-support",
|
||||||
|
"wayland",
|
||||||
|
"x11",
|
||||||
|
"proptest",
|
||||||
|
]
|
||||||
|
bench-support = ["profiler", "dep:criterion", "dep:bench_metrics"]
|
||||||
|
bench = ["bench-support"]
|
||||||
|
inspector = ["gpui_macros/inspector"]
|
||||||
|
leak-detection = []
|
||||||
|
wayland = []
|
||||||
|
x11 = ["scap?/x11"]
|
||||||
|
screen-capture = ["scap"]
|
||||||
|
windows-manifest = ["dep:embed-resource"]
|
||||||
|
profiler = ["dep:hdrhistogram"]
|
||||||
|
stacker = ["dep:stacksafe"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
accesskit = { workspace = true }
|
||||||
|
anyhow = { workspace = true }
|
||||||
|
async-task = { workspace = true }
|
||||||
|
backtrace = { workspace = true }
|
||||||
|
bitflags = { workspace = true }
|
||||||
|
collections = { workspace = true }
|
||||||
|
bench_metrics = { workspace = true, optional = true }
|
||||||
|
criterion = { workspace = true, optional = true }
|
||||||
|
ctor = { workspace = true }
|
||||||
|
derive_more = { workspace = true }
|
||||||
|
etagere = { workspace = true }
|
||||||
|
futures = { workspace = true }
|
||||||
|
futures-concurrency = { workspace = true }
|
||||||
|
gpui_macros = { workspace = true }
|
||||||
|
gpui_shared_string = { workspace = true }
|
||||||
|
http_client = { workspace = true }
|
||||||
|
image = { workspace = true }
|
||||||
|
inventory = { workspace = true }
|
||||||
|
itertools = { workspace = true }
|
||||||
|
log = { workspace = true }
|
||||||
|
num_cpus = "1.13"
|
||||||
|
parking = "2.0.0"
|
||||||
|
parking_lot = { workspace = true }
|
||||||
|
postage = { workspace = true }
|
||||||
|
proptest = { workspace = true, optional = true }
|
||||||
|
chrono = { workspace = true }
|
||||||
|
profiling = { workspace = true }
|
||||||
|
rand = { workspace = true }
|
||||||
|
raw-window-handle = { workspace = true }
|
||||||
|
regex = { workspace = true }
|
||||||
|
refineable = { workspace = true }
|
||||||
|
scheduler = { workspace = true }
|
||||||
|
resvg = { workspace = true }
|
||||||
|
usvg = { workspace = true }
|
||||||
|
ttf-parser = "0.25"
|
||||||
|
util_macros = { workspace = true }
|
||||||
|
schemars = { workspace = true }
|
||||||
|
seahash = "4.1"
|
||||||
|
serde = { workspace = true }
|
||||||
|
serde_json = { workspace = true }
|
||||||
|
slotmap = { workspace = true }
|
||||||
|
smallvec = { workspace = true }
|
||||||
|
stacksafe = { workspace = true, optional = true }
|
||||||
|
strum = { workspace = true }
|
||||||
|
sum_tree = { workspace = true }
|
||||||
|
taffy = "0.13.0"
|
||||||
|
thiserror = { workspace = true }
|
||||||
|
gpui_util = { workspace = true }
|
||||||
|
hdrhistogram = { workspace = true, optional = true }
|
||||||
|
waker-fn = "1.2.0"
|
||||||
|
lyon = "1.0"
|
||||||
|
pin-project = "1.1.10"
|
||||||
|
spin = "0.10.0"
|
||||||
|
pollster = { workspace = true }
|
||||||
|
url = { workspace = true }
|
||||||
|
uuid = { workspace = true }
|
||||||
|
web-time = { workspace = true }
|
||||||
|
heapless = { workspace = true }
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embed-resource = { version = "3.0", optional = true }
|
||||||
|
|
||||||
|
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
|
||||||
|
async-channel = { version = "2.5.0", default-features = false }
|
||||||
|
|
||||||
|
[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dependencies]
|
||||||
|
async-channel = { workspace = true }
|
||||||
|
|
||||||
|
[target.'cfg(target_family = "wasm")'.dependencies]
|
||||||
|
getrandom = { version = "0.3.4", features = ["wasm_js"] }
|
||||||
|
uuid = { workspace = true, features = ["js"] }
|
||||||
|
|
||||||
|
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
|
||||||
|
core-video = { workspace = true }
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
|
objc2-core-foundation = { workspace = true }
|
||||||
|
objc2-core-video = { workspace = true }
|
||||||
|
font-kit = { git = "https://github.com/zed-industries/font-kit", rev = "94b0f28166665e8fd2f53ff6d268a14955c82269", package = "zed-font-kit", version = "0.14.1-zed", optional = true }
|
||||||
|
log = { workspace = true }
|
||||||
|
objc2 = { workspace = true, optional = true }
|
||||||
|
objc2-metal = { version = "0.3", optional = true }
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.build-dependencies]
|
||||||
|
bindgen = "0.72"
|
||||||
|
|
||||||
|
[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "windows"))'.dependencies]
|
||||||
|
scap = { workspace = true, optional = true }
|
||||||
|
|
||||||
|
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
|
||||||
|
libc = { workspace = true }
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
|
windows = { workspace = true, features = [
|
||||||
|
"Win32_Foundation",
|
||||||
|
"Win32_System_Power",
|
||||||
|
"Win32_System_RemoteDesktop",
|
||||||
|
"Win32_System_Threading",
|
||||||
|
"Win32_System_WindowsProgramming",
|
||||||
|
] }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "hello_world"
|
||||||
|
path = "examples/hello_world.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "move_entity_between_windows"
|
||||||
|
path = "examples/move_entity_between_windows.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "image"
|
||||||
|
path = "examples/image/image.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "input"
|
||||||
|
path = "examples/input.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "on_window_close_quit"
|
||||||
|
path = "examples/on_window_close_quit.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "window_movable"
|
||||||
|
path = "examples/window_movable.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "opacity"
|
||||||
|
path = "examples/opacity.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "pattern"
|
||||||
|
path = "examples/pattern.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "set_menus"
|
||||||
|
path = "examples/set_menus.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "system_notifications"
|
||||||
|
path = "examples/system_notifications.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "shadow"
|
||||||
|
path = "examples/shadow.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "svg"
|
||||||
|
path = "examples/svg/svg.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "tab_stop"
|
||||||
|
path = "examples/tab_stop.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "text"
|
||||||
|
path = "examples/text.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "text_wrapper"
|
||||||
|
path = "examples/text_wrapper.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "tree"
|
||||||
|
path = "examples/tree.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "uniform_list"
|
||||||
|
path = "examples/uniform_list.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "window_shadow"
|
||||||
|
path = "examples/window_shadow.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "grid_layout"
|
||||||
|
path = "examples/grid_layout.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "list_example"
|
||||||
|
path = "examples/list_example.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "mouse_pressure"
|
||||||
|
path = "examples/mouse_pressure.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "a11y"
|
||||||
|
path = "examples/a11y.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "view_example"
|
||||||
|
path = "examples/view_example/view_example_main.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "toggle_headless"
|
||||||
|
path = "examples/toggle_headless.rs"
|
||||||
Vendored
+222
@@ -0,0 +1,222 @@
|
|||||||
|
Copyright 2022 - 2025 Zed Industries, Inc.
|
||||||
|
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
Vendored
+98
@@ -0,0 +1,98 @@
|
|||||||
|
# Welcome to GPUI!
|
||||||
|
|
||||||
|
GPUI is a hybrid immediate and retained mode, GPU accelerated, UI framework
|
||||||
|
for Rust, designed to support a wide variety of applications.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
GPUI is still in active development as we work on the Zed code editor, and is still pre-1.0. There will often be breaking changes between versions. You'll also need to use the latest version of stable Rust. Add `gpui`, and optionally `gpui_platform`, to your `Cargo.toml`:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
gpui = { version = "*" }
|
||||||
|
gpui_platform = { version = "*", features = ["font-kit", "wayland", "x11"] }
|
||||||
|
```
|
||||||
|
|
||||||
|
Everything in a standalone GPUI app starts with an `Application`. You can create one with `gpui_platform::application()`, which picks the windowing and text backends for the host OS, and kick off your application by passing a callback to `Application::run()`. Inside this callback, you can create a new window with `App::open_window()` and register your first root view.
|
||||||
|
|
||||||
|
```rust,no_run
|
||||||
|
use gpui::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
gpui_platform::application().run(|cx: &mut App| {
|
||||||
|
// ..
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### `gpui_platform`
|
||||||
|
|
||||||
|
The features on `gpui_platform` are platform-specific, so the list above is a safe cross-platform default. If you build for a single platform, you can trim it:
|
||||||
|
|
||||||
|
- **macOS** — Rendering uses Metal and is always available, but glyph rasterization needs `font-kit`. Without it, GPUI falls back to a placeholder text system that lays text out but renders no glyphs.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
gpui_platform = { version = "*", features = ["font-kit"] }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Linux / FreeBSD** — enable at least one windowing backend for desktop windows: `wayland`, `x11`, or both. These features also compile the renderer and text system, so no separate text feature is needed.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
gpui_platform = { version = "*", features = ["wayland", "x11"] }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Windows** — no features are required. Windowing uses Win32 and text uses DirectWrite. `font-kit` has no effect here.
|
||||||
|
|
||||||
|
### Additional Topics
|
||||||
|
|
||||||
|
- [Ownership and data flow](_ownership_and_data_flow)
|
||||||
|
- [Accessibility](_accessibility)
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
|
||||||
|
GPUI has various system dependencies that it needs in order to work.
|
||||||
|
|
||||||
|
#### macOS
|
||||||
|
|
||||||
|
On macOS, GPUI uses Metal for rendering. In order to use Metal, you need to do the following:
|
||||||
|
|
||||||
|
- Install [Xcode](https://apps.apple.com/us/app/xcode/id497799835?mt=12) from the macOS App Store, or from the [Apple Developer](https://developer.apple.com/download/all/) website. Note this requires a developer account.
|
||||||
|
|
||||||
|
> Ensure you launch Xcode after installing, and install the macOS components, which is the default option.
|
||||||
|
|
||||||
|
- Install [Xcode command line tools](https://developer.apple.com/xcode/resources/)
|
||||||
|
|
||||||
|
```sh
|
||||||
|
xcode-select --install
|
||||||
|
```
|
||||||
|
|
||||||
|
- Ensure that the Xcode command line tools are using your newly installed copy of Xcode:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
|
||||||
|
```
|
||||||
|
|
||||||
|
## The Big Picture
|
||||||
|
|
||||||
|
GPUI offers three different [registers](<https://en.wikipedia.org/wiki/Register_(sociolinguistics)>) depending on your needs:
|
||||||
|
|
||||||
|
- State management and communication with `Entity`'s. Whenever you need to store application state that communicates between different parts of your application, you'll want to use GPUI's entities. Entities are owned by GPUI and are only accessible through an owned smart pointer similar to an `Rc`. See the `app::context` module for more information.
|
||||||
|
|
||||||
|
- High level, declarative UI with views. All UI in GPUI starts with a view. A view is simply an `Entity` that can be rendered, by implementing the `Render` trait. At the start of each frame, GPUI will call this render method on the root view of a given window. Views build a tree of `elements`, lay them out and style them with a tailwind-style API, and then give them to GPUI to turn into pixels. See the `div` element for an all purpose swiss-army knife of rendering.
|
||||||
|
|
||||||
|
- Low level, imperative UI with Elements. Elements are the building blocks of UI in GPUI, and they provide a nice wrapper around an imperative API that provides as much flexibility and control as you need. Elements have total control over how they and their child elements are rendered and can be used for making efficient views into large lists, implement custom layouting for a code editor, and anything else you can think of. See the `element` module for more information.
|
||||||
|
|
||||||
|
Each of these registers has one or more corresponding contexts that can be accessed from all GPUI services. This context is your main interface to GPUI, and is used extensively throughout the framework.
|
||||||
|
|
||||||
|
## Other Resources
|
||||||
|
|
||||||
|
In addition to the systems above, GPUI provides a range of smaller services that are useful for building complex applications:
|
||||||
|
|
||||||
|
- Actions are user-defined structs that are used for converting keystrokes into logical operations in your UI. Use this for implementing keyboard shortcuts, such as cmd-q. See the `action` module for more information.
|
||||||
|
|
||||||
|
- Platform services, such as `quit the app` or `open a URL` are available as methods on the `app::App`.
|
||||||
|
|
||||||
|
- An async executor that is integrated with the platform's event loop. See the `executor` module for more information.,
|
||||||
|
|
||||||
|
- The `[gpui::test]` macro provides a convenient way to write tests for your GPUI applications. Tests also have their own kind of context, a `TestAppContext` which provides ways of simulating common platform input. See `app::test_context` and `test` modules for more details.
|
||||||
|
|
||||||
|
Currently, the best way to learn about these APIs is to read the Zed source code or drop a question in the [Zed Discord](https://zed.dev/community-links). We're working on improving the documentation, creating more examples, and will be publishing more guides to GPUI on our [blog](https://zed.dev/blog).
|
||||||
Vendored
+36
@@ -0,0 +1,36 @@
|
|||||||
|
#![allow(clippy::disallowed_methods, reason = "build scripts are exempt")]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(gles)");
|
||||||
|
|
||||||
|
// Leak detection does bookkeeping on every entity handle, so `test-support`
|
||||||
|
// does not enable it: that feature must stay cheap enough to compile into
|
||||||
|
// every build. CI sets `GPUI_LEAK_DETECTION`; the `leak-detection` feature
|
||||||
|
// turns it on explicitly.
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(gpui_leak_detection)");
|
||||||
|
println!("cargo::rerun-if-env-changed=GPUI_LEAK_DETECTION");
|
||||||
|
let requested_by_environment =
|
||||||
|
std::env::var_os("GPUI_LEAK_DETECTION").is_some_and(|value| !value.is_empty());
|
||||||
|
if requested_by_environment || std::env::var_os("CARGO_FEATURE_LEAK_DETECTION").is_some() {
|
||||||
|
println!("cargo::rustc-cfg=gpui_leak_detection");
|
||||||
|
}
|
||||||
|
|
||||||
|
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
|
||||||
|
|
||||||
|
if target_os == "windows" {
|
||||||
|
#[cfg(feature = "windows-manifest")]
|
||||||
|
embed_resource();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "windows-manifest")]
|
||||||
|
fn embed_resource() {
|
||||||
|
let resource_dir = std::path::Path::new("resources/windows");
|
||||||
|
let manifest = resource_dir.join("gpui.manifest.xml");
|
||||||
|
let rc_file = resource_dir.join("gpui.rc");
|
||||||
|
println!("cargo:rerun-if-changed={}", manifest.display());
|
||||||
|
println!("cargo:rerun-if-changed={}", rc_file.display());
|
||||||
|
embed_resource::compile(rc_file, embed_resource::ParamsIncludeDirs([resource_dir]))
|
||||||
|
.manifest_required()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
Vendored
+33
@@ -0,0 +1,33 @@
|
|||||||
|
# Contexts
|
||||||
|
|
||||||
|
GPUI makes extensive use of _context parameters_ (typically named `cx`) to provide access to application state and services. These contexts are references passed to functions, enabling interaction with global state, windows, entities, and system services.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## `App`
|
||||||
|
|
||||||
|
The root context granting access to the application's global state. This context owns all entities' data and can be used to read or update the data referenced by an `Entity<T>`.
|
||||||
|
|
||||||
|
## `Context<T>`
|
||||||
|
|
||||||
|
A context provided when interacting with an `Entity<T>`, with additional methods related to that specific entity such as notifying observers and emitting events. This context dereferences into `App`, meaning any function which can take an `App` reference can also take a `Context<T>` reference, allowing you to access the application's global state.
|
||||||
|
|
||||||
|
## `AsyncApp` and `AsyncWindowContext`
|
||||||
|
|
||||||
|
Whereas the above contexts are always passed to your code as references, you can call `to_async` on the reference to create an async context, which has a static lifetime and can be held across `await` points in async code. When you interact with entities with an async context, the calls become fallible, because the context may outlive the window or even the app itself.
|
||||||
|
|
||||||
|
## `TestAppContext`
|
||||||
|
|
||||||
|
These are similar to the async contexts above, but they panic if you attempt to access a non-existent app or window, and they also contain other features specific to tests.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Non-Context Core Types
|
||||||
|
|
||||||
|
## `Window`
|
||||||
|
|
||||||
|
Provides access to the state of an application window. This type has a root view (an `Entity` implementing `Render`) which it can read/update, but since it is not a context, you must pass a `&mut App` (or a context which dereferences to it) to do so, along with other functions interacting with global state. You can obtain a `Window` from an `WindowHandle` by calling `WindowHandle::update`.
|
||||||
|
|
||||||
|
## `Entity<T>`
|
||||||
|
|
||||||
|
A handle to a structure requiring state. This data is owned by the `App` and can be accessed and modified via references to contexts. If `T` implements `Render`, then the entity is sometimes referred to as a view. Entities can be observed by other entities and windows, allowing a closure to be called when `notify` is called on the entity's `Context`.
|
||||||
Vendored
+100
@@ -0,0 +1,100 @@
|
|||||||
|
# Key Dispatch
|
||||||
|
|
||||||
|
GPUI is designed for keyboard-first interactivity.
|
||||||
|
|
||||||
|
To expose functionality to the mouse, you render a button with a click handler.
|
||||||
|
|
||||||
|
To expose functionality to the keyboard, you bind an _action_ in a _key context_.
|
||||||
|
|
||||||
|
Actions are similar to framework-level events like `MouseDown`, `KeyDown`, etc, but you can define them yourself:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
mod menu {
|
||||||
|
#[gpui::action]
|
||||||
|
struct MoveUp;
|
||||||
|
|
||||||
|
#[gpui::action]
|
||||||
|
struct MoveDown;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Actions are frequently unit structs, for which we have a macro. The above could also be written:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
mod menu {
|
||||||
|
actions!(gpui, [MoveUp, MoveDown]);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Actions can also be more complex types:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
mod menu {
|
||||||
|
#[gpui::action]
|
||||||
|
struct Move {
|
||||||
|
direction: Direction,
|
||||||
|
select: bool,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To bind actions, chain `on_action` on to your element:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
impl Render for Menu {
|
||||||
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.on_action(|this: &mut Menu, move: &MoveUp, window: &mut Window, cx: &mut Context<Menu>| {
|
||||||
|
// ...
|
||||||
|
})
|
||||||
|
.on_action(|this, move: &MoveDown, cx| {
|
||||||
|
// ...
|
||||||
|
})
|
||||||
|
.children(unimplemented!())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
In order to bind keys to actions, you need to declare a _key context_ for part of the element tree by calling `key_context`.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
impl Render for Menu {
|
||||||
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.key_context("menu")
|
||||||
|
.on_action(|this: &mut Menu, move: &MoveUp, window: &mut Window, cx: &mut Context<Menu>| {
|
||||||
|
// ...
|
||||||
|
})
|
||||||
|
.on_action(|this, move: &MoveDown, cx| {
|
||||||
|
// ...
|
||||||
|
})
|
||||||
|
.children(unimplemented!())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Now you can target your context in the keymap. Note how actions are identified in the keymap by their fully-qualified type name.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"context": "menu",
|
||||||
|
"bindings": {
|
||||||
|
"up": "menu::MoveUp",
|
||||||
|
"down": "menu::MoveDown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If you had opted for the more complex type definition, you'd provide the serialized representation of the action alongside the name:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"context": "menu",
|
||||||
|
"bindings": {
|
||||||
|
"up": ["menu::Move", {direction: "up", select: false}]
|
||||||
|
"down": ["menu::Move", {direction: "down", select: false}]
|
||||||
|
"shift-up": ["menu::Move", {direction: "up", select: true}]
|
||||||
|
"shift-down": ["menu::Move", {direction: "down", select: true}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
Vendored
+157
@@ -0,0 +1,157 @@
|
|||||||
|
# GPUI Examples
|
||||||
|
|
||||||
|
Examples can be run from the Zed repository root:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo run -p gpui --example hello_world
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running in a browser
|
||||||
|
|
||||||
|
A selection of these examples is also served by the standalone web gallery:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cd crates/gpui_web/examples/hello_web
|
||||||
|
trunk serve
|
||||||
|
```
|
||||||
|
|
||||||
|
Open <http://localhost:8080/> to choose an example:
|
||||||
|
|
||||||
|
| Path | Example |
|
||||||
|
| --- | --- |
|
||||||
|
| `/hello-world` | Hello world |
|
||||||
|
| `/text` | Styled text |
|
||||||
|
| `/text-layout` | Alignment and decorations |
|
||||||
|
| `/text-wrapper` | Wrapping and truncation |
|
||||||
|
| `/input` | Text input and selection |
|
||||||
|
| `/dynamic-fonts` | Download a font on missing-glyph notifications |
|
||||||
|
| `/prime-sieve` | Background task demo |
|
||||||
|
|
||||||
|
The server supports direct links and reloads at each path. Only the selected
|
||||||
|
example's WASM module is loaded. Follow **All examples** to return to the gallery;
|
||||||
|
navigation reloads the page so the previous app and its workers are released.
|
||||||
|
|
||||||
|
Install [Trunk](https://trunk-rs.github.io/trunk/) if needed. The gallery's toolchain file selects
|
||||||
|
nightly Rust, the WASM target, and `rust-src`. Its Trunk configuration supplies the
|
||||||
|
cross-origin-isolation headers needed for shared memory and watches the GPUI
|
||||||
|
example and renderer sources for automatic rebuilds and browser reloads. Use a
|
||||||
|
browser with WebGPU or WebGL2 support.
|
||||||
|
|
||||||
|
The gallery builds separate Cargo binaries directly from the existing example
|
||||||
|
sources. To add another browser-compatible example, register its binary in the
|
||||||
|
gallery's `Cargo.toml`, add an auxiliary Rust asset in `index.html`, and add its
|
||||||
|
gallery link with the corresponding `data-module` name.
|
||||||
|
|
||||||
|
### Dynamic font loading
|
||||||
|
|
||||||
|
Open `/dynamic-fonts` to see `App::on_missing_glyphs` fetch a versioned
|
||||||
|
[Noto Sans Devanagari TTF](https://fonts.gstatic.com/s/notosansdevanagari/v30/TuGoUUFzXI5FBtUq5a8bjKYTZjtRU6Sgv3NaV_SNmI0b8QQCQmHn6B2OHjbL_08AlXQly-A.ttf)
|
||||||
|
from Google Fonts' CDN. The 219 KB font is licensed under the
|
||||||
|
[SIL Open Font License](https://github.com/google/fonts/blob/main/ofl/notosansdevanagari/OFL.txt).
|
||||||
|
The CDN permits cross-origin requests and caches the font for one year.
|
||||||
|
No sample text is sent to the host.
|
||||||
|
|
||||||
|
The example bundles only IBM Plex Sans, downloads the fallback once on demand,
|
||||||
|
calls `add_fonts`, and refreshes the windows to reshape the text. Emoji continues
|
||||||
|
to use the default Canvas fallback. The page displays loading and failure states;
|
||||||
|
use browser network throttling or block `fonts.gstatic.com` and reload to
|
||||||
|
exercise them. Reload to retry a failed request.
|
||||||
|
|
||||||
|
This is a small script-to-font mapping, not a general font discovery service.
|
||||||
|
For production, host versioned font assets on your own CDN and choose an explicit
|
||||||
|
coverage, caching, and retry policy. Use raw TTF/OTF assets rather than passing
|
||||||
|
Google Fonts CSS or WOFF2 responses directly to `add_fonts`.
|
||||||
|
|
||||||
|
### Canvas font fallback
|
||||||
|
|
||||||
|
The web text system uses browser fonts for eligible missing CJK and emoji
|
||||||
|
graphemes. It renders each complete grapheme independently, retaining the primary
|
||||||
|
font's baseline and line-spacing metrics. Contextual CJK spacing and arbitrary
|
||||||
|
OpenType features are not reproduced. Other scripts remain on Cosmic Text.
|
||||||
|
Browser font availability is assumed stable for the application's lifetime.
|
||||||
|
|
||||||
|
With the gallery server running, a browser smoke test checks native-font
|
||||||
|
preservation, whole-grapheme rendering, emoji atlas reuse, and input/deletion:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
node crates/gpui_web/examples/hello_web/test_canvas_fallback.mjs
|
||||||
|
```
|
||||||
|
|
||||||
|
This requires Node.js 22 or newer and Chrome/Chromium. On macOS it uses the
|
||||||
|
standard Google Chrome application path; elsewhere it uses `chromium`. Set
|
||||||
|
`CHROME` to override the executable, and pass an optional server URL as the first
|
||||||
|
argument. Screenshots and logs are saved under the gallery's ignored `target`
|
||||||
|
directory. The test intercepts clipboard writes rather than modifying the system
|
||||||
|
clipboard.
|
||||||
|
|
||||||
|
## Where to start
|
||||||
|
|
||||||
|
- `hello_world` shows the basic shape of a GPUI application: create an
|
||||||
|
`Application`, open a window, create a root view, and render a `div`.
|
||||||
|
- `input` demonstrates text input, focus, selections, clipboard actions, and
|
||||||
|
keyboard bindings.
|
||||||
|
- `uniform_list` shows how to render a simple virtualized list.
|
||||||
|
- `testing` demonstrates `#[gpui::test]`, `TestAppContext`, actions, focus, and
|
||||||
|
window-based tests.
|
||||||
|
|
||||||
|
## Layout and styling
|
||||||
|
|
||||||
|
- `grid_layout` demonstrates CSS-grid-style layout.
|
||||||
|
- `opacity` demonstrates opacity styling.
|
||||||
|
- `pattern` shows patterned backgrounds.
|
||||||
|
- `shadow` demonstrates box shadows.
|
||||||
|
- `text` shows styled text rendering.
|
||||||
|
- `text_layout` demonstrates text alignment, decoration, weights, and wrapping.
|
||||||
|
- `text_wrapper` shows wrapping text content.
|
||||||
|
|
||||||
|
## Interaction
|
||||||
|
|
||||||
|
- `anchor` demonstrates anchored positioning.
|
||||||
|
- `data_table` combines virtualized list rendering with table-style rows and a
|
||||||
|
custom scrollbar.
|
||||||
|
- `drag_drop` shows draggable elements and drop targets.
|
||||||
|
- `focus_visible` demonstrates keyboard-visible focus styling.
|
||||||
|
- `mouse_pressure` demonstrates pressure-sensitive pointer input where supported.
|
||||||
|
- `popover` shows floating layers with `deferred` and `anchored`.
|
||||||
|
- `scrollable` demonstrates scrollable content.
|
||||||
|
- `tab_stop` shows keyboard tab navigation.
|
||||||
|
|
||||||
|
## Images, drawing, and animation
|
||||||
|
|
||||||
|
- `animation` demonstrates GPUI animations and animated SVG transforms.
|
||||||
|
- `gif_viewer` shows GIF rendering.
|
||||||
|
- `gradient` demonstrates linear gradients and color spaces.
|
||||||
|
- `image` shows local and remote image loading, image sizing, and asset setup.
|
||||||
|
- `image_gallery` demonstrates image caching and loading remote images.
|
||||||
|
- `image_loading` shows image loading states and asset loading.
|
||||||
|
- `painting` demonstrates custom drawing with paths and canvas.
|
||||||
|
- `svg` shows SVG rendering.
|
||||||
|
|
||||||
|
## Windows and application behavior
|
||||||
|
|
||||||
|
- `move_entity_between_windows` shows moving an entity between windows.
|
||||||
|
- `on_window_close_quit` demonstrates quitting when a window closes.
|
||||||
|
- `set_menus` shows application menu setup.
|
||||||
|
- `system_notifications` demonstrates posting, replacing, dismissing, and responding to operating-system notifications.
|
||||||
|
- `window` demonstrates creating normal, dialog, popup, and floating windows.
|
||||||
|
- `window_positioning` demonstrates window bounds and placement.
|
||||||
|
- `window_shadow` demonstrates window shadow styling.
|
||||||
|
|
||||||
|
## Specialized examples
|
||||||
|
|
||||||
|
These examples are useful when working on GPUI itself, but they may not be the
|
||||||
|
best starting point for new applications:
|
||||||
|
|
||||||
|
- `active_state_bug` is a focused active-state reproduction.
|
||||||
|
- `toggle_headless` starts without a display and preserves its app and todo
|
||||||
|
entities while attaching to or detaching from Wayland or X11. Run it on Linux
|
||||||
|
with `cargo run -p gpui --example toggle_headless`; its stdin commands are
|
||||||
|
`ls`, `create [message]`, `open`, `close`, and `quit`. `open` attaches to the
|
||||||
|
display server in the process environment and opens the window; while headless,
|
||||||
|
`open DISPLAY=:1` (or `WAYLAND_DISPLAY=… XDG_RUNTIME_DIR=…`) targets another one.
|
||||||
|
`close` closes the window and returns to headless mode.
|
||||||
|
- `layer_shell` demonstrates Linux layer-shell windows.
|
||||||
|
- `list_example` demonstrates bottom-aligned list state and scrollbar behavior.
|
||||||
|
- `ownership_post` supports the ownership and data-flow documentation.
|
||||||
|
- `paths_bench` is a path rendering benchmark.
|
||||||
|
- `tree` renders a deep tree of nested elements.
|
||||||
Vendored
+272
@@ -0,0 +1,272 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
//! Accessibility (AccessKit) demo app.
|
||||||
|
//!
|
||||||
|
//! Run with: `cargo run -p gpui --example a11y`
|
||||||
|
//!
|
||||||
|
//! Or on Linux: `cargo run -p gpui --features gpui_platform/wayland,gpui_platform/x11 --example a11y`
|
||||||
|
//!
|
||||||
|
//! This app uses GPUI's accessibility APIs to attach structured information to
|
||||||
|
//! the element tree, which allows assistive technology to see and interact with
|
||||||
|
//! the UI programmatically.
|
||||||
|
//!
|
||||||
|
//! The app behaves as follows:
|
||||||
|
//! - It opens a single window.
|
||||||
|
//! - The window's title is "GPUI Accessibility Demo".
|
||||||
|
//! - The window has a sequence of UI elements, stacked vertically:
|
||||||
|
//! - A heading with the text "Accessibility Demo".
|
||||||
|
//! - A row containing two elements:
|
||||||
|
//! - A spin button (role `SpinButton`) labelled "Counter: <n>", where
|
||||||
|
//! `<n>` is the current count. It supports `Increment` and `Decrement`
|
||||||
|
//! accessible actions, and also increments on click. The numeric value
|
||||||
|
//! is clamped to a minimum of 0.
|
||||||
|
//! - A button labelled "Reset counter" that resets the count to 0.
|
||||||
|
//! - A row containing two elements:
|
||||||
|
//! - A switch, that can be toggled, and starts disabled. Toggling the switch
|
||||||
|
//! does nothing.
|
||||||
|
//! - The text "Enable feature".
|
||||||
|
//! - A "to-do" list, with three items, each represented with a `Text` element:
|
||||||
|
//! - "1. Write code"
|
||||||
|
//! - "2. Run tests"
|
||||||
|
//! - "3. Ship it"
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
AccessibleAction, App, Bounds, Context, FocusHandle, KeyBinding, Role, SharedString, Toggled,
|
||||||
|
Window, WindowBounds, WindowOptions, actions, div, prelude::*, px, rgb, size, text,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
actions!(a11y_example, [Tab, TabPrev]);
|
||||||
|
|
||||||
|
struct A11yDemo {
|
||||||
|
focus_handle: FocusHandle,
|
||||||
|
count: i32,
|
||||||
|
enabled: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl A11yDemo {
|
||||||
|
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let focus_handle = cx.focus_handle();
|
||||||
|
window.focus(&focus_handle, cx);
|
||||||
|
Self {
|
||||||
|
focus_handle,
|
||||||
|
count: 0,
|
||||||
|
enabled: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for A11yDemo {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.id("root")
|
||||||
|
.role(Role::Application)
|
||||||
|
.aria_label("Accessibility Demo")
|
||||||
|
.track_focus(&self.focus_handle)
|
||||||
|
.on_action(cx.listener(|_, _: &Tab, window, cx| window.focus_next(cx)))
|
||||||
|
.on_action(cx.listener(|_, _: &TabPrev, window, cx| window.focus_prev(cx)))
|
||||||
|
.size_full()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_4()
|
||||||
|
.p_4()
|
||||||
|
.bg(rgb(0x1e1e2e))
|
||||||
|
.text_color(rgb(0xcdd6f4))
|
||||||
|
// Heading
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("heading")
|
||||||
|
.role(Role::Heading)
|
||||||
|
.aria_level(1)
|
||||||
|
.aria_label("Accessibility Demo")
|
||||||
|
.text_xl()
|
||||||
|
.font_weight(gpui::FontWeight::BOLD)
|
||||||
|
.child(text!("Accessibility Demo")),
|
||||||
|
)
|
||||||
|
// Counter — uses a SpinButton role with Increment/Decrement
|
||||||
|
// actions so screen readers can adjust the value directly.
|
||||||
|
// Click also works via the built-in handler.
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.gap_3()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("counter")
|
||||||
|
.focusable()
|
||||||
|
.tab_stop(true)
|
||||||
|
.role(Role::SpinButton)
|
||||||
|
.aria_label(SharedString::from(format!("Counter: {}", self.count)))
|
||||||
|
.aria_numeric_value(self.count as f64)
|
||||||
|
.aria_min_numeric_value(0.0)
|
||||||
|
.on_a11y_action(AccessibleAction::Increment, {
|
||||||
|
let this = cx.entity().downgrade();
|
||||||
|
move |_, _, cx| {
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.count += 1;
|
||||||
|
cx.notify();
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on_a11y_action(AccessibleAction::Decrement, {
|
||||||
|
let this = cx.entity().downgrade();
|
||||||
|
move |_, _, cx| {
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.count = (this.count - 1).max(0);
|
||||||
|
cx.notify();
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.count += 1;
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.px_3()
|
||||||
|
.py_1()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgb(0x89b4fa))
|
||||||
|
.text_color(rgb(0x1e1e2e))
|
||||||
|
.cursor_pointer()
|
||||||
|
.child(text!(format!("Count: {}", self.count))),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("reset")
|
||||||
|
.focusable()
|
||||||
|
.tab_stop(true)
|
||||||
|
.role(Role::Button)
|
||||||
|
.aria_label("Reset counter")
|
||||||
|
.px_3()
|
||||||
|
.py_1()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgb(0x585b70))
|
||||||
|
.cursor_pointer()
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.count = 0;
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.child(text!("Reset")),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// A toggle switch
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("toggle")
|
||||||
|
.focusable()
|
||||||
|
.tab_stop(true)
|
||||||
|
.role(Role::Switch)
|
||||||
|
.aria_label("Enable feature")
|
||||||
|
.aria_toggled(if self.enabled {
|
||||||
|
Toggled::True
|
||||||
|
} else {
|
||||||
|
Toggled::False
|
||||||
|
})
|
||||||
|
.w(px(44.))
|
||||||
|
.h(px(24.))
|
||||||
|
.rounded_full()
|
||||||
|
.cursor_pointer()
|
||||||
|
.when(self.enabled, |el| el.bg(rgb(0x89b4fa)))
|
||||||
|
.when(!self.enabled, |el| el.bg(rgb(0x585b70)))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.size(px(20.))
|
||||||
|
.rounded_full()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.mt(px(2.))
|
||||||
|
.when(self.enabled, |el| el.ml(px(22.)))
|
||||||
|
.when(!self.enabled, |el| el.ml(px(2.))),
|
||||||
|
)
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.enabled = !this.enabled;
|
||||||
|
cx.notify();
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.child(text!("Enable feature")),
|
||||||
|
)
|
||||||
|
// A short list
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("task-list")
|
||||||
|
.role(Role::List)
|
||||||
|
.aria_label("Tasks")
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_1()
|
||||||
|
.children(
|
||||||
|
["Write code", "Run tests", "Ship it"]
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, label)| {
|
||||||
|
div()
|
||||||
|
.id(("task", i))
|
||||||
|
.role(Role::ListItem)
|
||||||
|
.aria_label(SharedString::from(*label))
|
||||||
|
.aria_position_in_set(i + 1)
|
||||||
|
.aria_size_of_set(3)
|
||||||
|
.py_1()
|
||||||
|
.px_2()
|
||||||
|
// Note: even though this `text!` macro
|
||||||
|
// produces multiple elements, it doesn't
|
||||||
|
// need its own unique ID because the parent
|
||||||
|
// div has different IDs for each string.
|
||||||
|
.child(text!(format!("{}. {}", i + 1, label)))
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.bind_keys([
|
||||||
|
KeyBinding::new("tab", Tab, None),
|
||||||
|
KeyBinding::new("shift-tab", TabPrev, None),
|
||||||
|
]);
|
||||||
|
|
||||||
|
let bounds = Bounds::centered(None, size(px(500.), px(400.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
titlebar: Some(gpui::TitlebarOptions {
|
||||||
|
title: Some("GPUI Accessibility Demo".into()),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|window, cx| cx.new(|cx| A11yDemo::new(window, cx)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
env_logger::builder()
|
||||||
|
.filter_level(log::LevelFilter::Warn)
|
||||||
|
.filter_module("gpui", log::LevelFilter::Info)
|
||||||
|
.init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
/// Click the button — the `.active()` background gets stuck on every other click.
|
||||||
|
use gpui::*;
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct Example;
|
||||||
|
|
||||||
|
impl Render for Example {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
// Colors from Zed's default dark theme
|
||||||
|
let bg = hsla(215. / 360., 0.12, 0.15, 1.);
|
||||||
|
let text = hsla(221. / 360., 0.11, 0.86, 1.);
|
||||||
|
let hover = hsla(225. / 360., 0.118, 0.267, 1.);
|
||||||
|
let active = hsla(220. / 360., 0.118, 0.20, 1.);
|
||||||
|
|
||||||
|
div().bg(bg).size_full().p_1().child(
|
||||||
|
div()
|
||||||
|
.id("button")
|
||||||
|
.px_2()
|
||||||
|
.py_0p5()
|
||||||
|
.rounded_md()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(text)
|
||||||
|
.hover(|s| s.bg(hover))
|
||||||
|
.active(|s| s.bg(active))
|
||||||
|
.on_click(|_, _, _| {})
|
||||||
|
.child("Click me"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
|
||||||
|
None,
|
||||||
|
size(px(200.), px(60.)),
|
||||||
|
cx,
|
||||||
|
))),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| cx.new(|_| Example),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
Vendored
+207
@@ -0,0 +1,207 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
Anchor, AnchoredPositionMode, App, Axis, Bounds, Context, Half as _, InteractiveElement,
|
||||||
|
ParentElement, Pixels, Point, Render, SharedString, Size, Window, WindowBounds, WindowOptions,
|
||||||
|
anchored, deferred, div, point, prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct AnchorDemo {
|
||||||
|
hovered_button: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ButtonDemo {
|
||||||
|
label: SharedString,
|
||||||
|
corner: Option<Anchor>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resolved_position(corner: Anchor, button_size: Size<Pixels>) -> Point<Pixels> {
|
||||||
|
let offset = Point {
|
||||||
|
x: px(0.),
|
||||||
|
y: -button_size.height,
|
||||||
|
};
|
||||||
|
|
||||||
|
offset
|
||||||
|
+ match corner.other_side_along(Axis::Vertical) {
|
||||||
|
Anchor::TopLeft => point(px(0.0), px(0.0)),
|
||||||
|
Anchor::TopCenter => point(button_size.width.half(), px(0.0)),
|
||||||
|
Anchor::TopRight => point(button_size.width, px(0.0)),
|
||||||
|
Anchor::LeftCenter => point(button_size.width, button_size.height.half()),
|
||||||
|
Anchor::RightCenter => point(px(0.), button_size.height.half()),
|
||||||
|
Anchor::BottomLeft => point(px(0.0), button_size.height),
|
||||||
|
Anchor::BottomCenter => point(button_size.width / 2.0, button_size.height),
|
||||||
|
Anchor::BottomRight => point(button_size.width, button_size.height),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AnchorDemo {
|
||||||
|
fn buttons() -> Vec<ButtonDemo> {
|
||||||
|
vec![
|
||||||
|
ButtonDemo {
|
||||||
|
label: "TopLeft".into(),
|
||||||
|
corner: Some(Anchor::TopLeft),
|
||||||
|
},
|
||||||
|
ButtonDemo {
|
||||||
|
label: "TopCenter".into(),
|
||||||
|
corner: Some(Anchor::TopCenter),
|
||||||
|
},
|
||||||
|
ButtonDemo {
|
||||||
|
label: "TopRight".into(),
|
||||||
|
corner: Some(Anchor::TopRight),
|
||||||
|
},
|
||||||
|
ButtonDemo {
|
||||||
|
label: "LeftCenter".into(),
|
||||||
|
corner: Some(Anchor::LeftCenter),
|
||||||
|
},
|
||||||
|
ButtonDemo {
|
||||||
|
label: "Center".into(),
|
||||||
|
corner: None,
|
||||||
|
},
|
||||||
|
ButtonDemo {
|
||||||
|
label: "RightCenter".into(),
|
||||||
|
corner: Some(Anchor::RightCenter),
|
||||||
|
},
|
||||||
|
ButtonDemo {
|
||||||
|
label: "BottomLeft".into(),
|
||||||
|
corner: Some(Anchor::BottomLeft),
|
||||||
|
},
|
||||||
|
ButtonDemo {
|
||||||
|
label: "BottomCenter".into(),
|
||||||
|
corner: Some(Anchor::BottomCenter),
|
||||||
|
},
|
||||||
|
ButtonDemo {
|
||||||
|
label: "BottomRight".into(),
|
||||||
|
corner: Some(Anchor::BottomRight),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for AnchorDemo {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let buttons = Self::buttons();
|
||||||
|
let button_size = size(px(120.0), px(65.0));
|
||||||
|
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.size_full()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.gap_4()
|
||||||
|
.p_10()
|
||||||
|
.child("Popover with Anchor")
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.size_128()
|
||||||
|
.grid()
|
||||||
|
.grid_cols(3)
|
||||||
|
.gap_6()
|
||||||
|
.relative()
|
||||||
|
.children(buttons.iter().enumerate().map(|(index, button)| {
|
||||||
|
let is_hovered = self.hovered_button == Some(index);
|
||||||
|
let is_hoverable = button.corner.is_some();
|
||||||
|
div()
|
||||||
|
.relative()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id(("button", index))
|
||||||
|
.w(button_size.width)
|
||||||
|
.h(button_size.height)
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.when(is_hoverable, |this| {
|
||||||
|
this.border_1()
|
||||||
|
.rounded_lg()
|
||||||
|
.border_color(gpui::black())
|
||||||
|
.hover(|style| {
|
||||||
|
style.bg(gpui::black()).text_color(gpui::white())
|
||||||
|
})
|
||||||
|
.on_hover(cx.listener(
|
||||||
|
move |this, hovered, _window, cx| {
|
||||||
|
if *hovered {
|
||||||
|
this.hovered_button = Some(index);
|
||||||
|
} else if this.hovered_button == Some(index) {
|
||||||
|
this.hovered_button = None;
|
||||||
|
}
|
||||||
|
cx.notify();
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.child(button.label.clone())
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.when_some(self.hovered_button.filter(|_| is_hovered), |this, index| {
|
||||||
|
let button = &buttons[index];
|
||||||
|
let Some(corner) = button.corner else {
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
let position = resolved_position(corner, button_size);
|
||||||
|
this.child(deferred(
|
||||||
|
anchored()
|
||||||
|
.anchor(corner)
|
||||||
|
.position(position)
|
||||||
|
.position_mode(AnchoredPositionMode::Local)
|
||||||
|
.snap_to_window()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.py_0p5()
|
||||||
|
.px_2()
|
||||||
|
.bg(gpui::black().opacity(0.75))
|
||||||
|
.text_color(rgb(0xffffff))
|
||||||
|
.rounded_sm()
|
||||||
|
.shadow_sm()
|
||||||
|
.min_w(px(100.0))
|
||||||
|
.text_sm()
|
||||||
|
.child(button.label.clone()),
|
||||||
|
),
|
||||||
|
))
|
||||||
|
})
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
|
||||||
|
None,
|
||||||
|
size(px(750.), px(600.)),
|
||||||
|
cx,
|
||||||
|
))),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| {
|
||||||
|
cx.new(|_| AnchorDemo {
|
||||||
|
hovered_button: None,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+373
@@ -0,0 +1,373 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use gpui::{
|
||||||
|
Animation, AnimationExt as _, AnimationPhase, App, AssetSource, Bounds, Context, MouseButton,
|
||||||
|
MouseDownEvent, MouseMoveEvent, Pixels, SharedString, SpringAnimation, SpringConfig,
|
||||||
|
Transformation, Window, WindowBounds, WindowOptions, bounce, div, ease_in_out, percentage,
|
||||||
|
prelude::*, px, relative, rgba, size, svg,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct Assets {}
|
||||||
|
|
||||||
|
impl AssetSource for Assets {
|
||||||
|
fn load(&self, path: &str) -> Result<Option<std::borrow::Cow<'static, [u8]>>> {
|
||||||
|
std::fs::read(path)
|
||||||
|
.map(Into::into)
|
||||||
|
.map_err(Into::into)
|
||||||
|
.map(Some)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
|
||||||
|
Ok(std::fs::read_dir(path)?
|
||||||
|
.filter_map(|entry| {
|
||||||
|
Some(SharedString::from(
|
||||||
|
entry.ok()?.path().to_string_lossy().into_owned(),
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ARROW_CIRCLE_SVG: &str = concat!(
|
||||||
|
env!("CARGO_MANIFEST_DIR"),
|
||||||
|
"/examples/image/arrow_circle.svg"
|
||||||
|
);
|
||||||
|
|
||||||
|
struct AnimationExample {
|
||||||
|
spring_phase: u8,
|
||||||
|
spring_damping: f32,
|
||||||
|
spring_damping_drag: Option<(Pixels, f32)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for AnimationExample {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
const MINIMUM_DAMPING: f32 = 2.0;
|
||||||
|
const MAXIMUM_DAMPING: f32 = 32.0;
|
||||||
|
const DAMPING_SLIDER_WIDTH: Pixels = px(224.0);
|
||||||
|
|
||||||
|
let spring_phase = self.spring_phase;
|
||||||
|
let spring_position = px(98.0 * f32::from(spring_phase));
|
||||||
|
let spring_damping = self.spring_damping;
|
||||||
|
let spring = SpringConfig::new(170.0, spring_damping, 1.0);
|
||||||
|
let (_, damping_ratio) = spring.canonical();
|
||||||
|
let damping_fraction =
|
||||||
|
(spring_damping - MINIMUM_DAMPING) / (MAXIMUM_DAMPING - MINIMUM_DAMPING);
|
||||||
|
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.size_full()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.text_color(gpui::black())
|
||||||
|
.justify_around()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.size_full()
|
||||||
|
.justify_around()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("content")
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.h(px(150.))
|
||||||
|
.overflow_y_scroll()
|
||||||
|
.w_full()
|
||||||
|
.flex_1()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.text_xl()
|
||||||
|
.gap_4()
|
||||||
|
.child("Hello Animation")
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("spring-demo")
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_2()
|
||||||
|
.p_2()
|
||||||
|
.w(px(240.0))
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgba(0x00000010))
|
||||||
|
.cursor_pointer()
|
||||||
|
.on_mouse_down(
|
||||||
|
MouseButton::Left,
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.spring_phase = (this.spring_phase + 1) % 3;
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(format!(
|
||||||
|
"Target phase {spring_phase}: click rapidly to redirect momentum"
|
||||||
|
))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("spring-damping-controls")
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_1()
|
||||||
|
.text_sm()
|
||||||
|
.on_click(|_, _, cx| cx.stop_propagation())
|
||||||
|
.child(format!(
|
||||||
|
"Drag damping: {spring_damping:.1} (ζ {damping_ratio:.2})"
|
||||||
|
))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("spring-damping")
|
||||||
|
.relative()
|
||||||
|
.h(px(20.0))
|
||||||
|
.w(DAMPING_SLIDER_WIDTH)
|
||||||
|
.cursor_pointer()
|
||||||
|
.on_mouse_down(
|
||||||
|
MouseButton::Left,
|
||||||
|
cx.listener(
|
||||||
|
|this,
|
||||||
|
event: &MouseDownEvent,
|
||||||
|
_,
|
||||||
|
cx| {
|
||||||
|
this.spring_damping_drag = Some((
|
||||||
|
event.position.x,
|
||||||
|
this.spring_damping,
|
||||||
|
));
|
||||||
|
cx.stop_propagation();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.on_mouse_move(cx.listener(
|
||||||
|
|this,
|
||||||
|
event: &MouseMoveEvent,
|
||||||
|
_,
|
||||||
|
cx| {
|
||||||
|
let Some((
|
||||||
|
start_position,
|
||||||
|
start_damping,
|
||||||
|
)) = this.spring_damping_drag
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let delta = (event.position.x
|
||||||
|
- start_position)
|
||||||
|
/ DAMPING_SLIDER_WIDTH;
|
||||||
|
this.spring_damping = (start_damping
|
||||||
|
+ delta
|
||||||
|
* (MAXIMUM_DAMPING
|
||||||
|
- MINIMUM_DAMPING))
|
||||||
|
.clamp(
|
||||||
|
MINIMUM_DAMPING,
|
||||||
|
MAXIMUM_DAMPING,
|
||||||
|
);
|
||||||
|
cx.stop_propagation();
|
||||||
|
cx.notify();
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.on_mouse_up(
|
||||||
|
MouseButton::Left,
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.spring_damping_drag = None;
|
||||||
|
cx.stop_propagation();
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.on_mouse_up_out(
|
||||||
|
MouseButton::Left,
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.spring_damping_drag = None;
|
||||||
|
cx.stop_propagation();
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.absolute()
|
||||||
|
.top(px(8.0))
|
||||||
|
.h(px(4.0))
|
||||||
|
.w_full()
|
||||||
|
.rounded_full()
|
||||||
|
.bg(rgba(0x00000030)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.absolute()
|
||||||
|
.top(px(8.0))
|
||||||
|
.h(px(4.0))
|
||||||
|
.w(relative(damping_fraction))
|
||||||
|
.rounded_full()
|
||||||
|
.bg(rgba(0x3b82f6ff)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.absolute()
|
||||||
|
.top(px(3.0))
|
||||||
|
.left(relative(damping_fraction))
|
||||||
|
.ml(px(-7.0))
|
||||||
|
.size(px(14.0))
|
||||||
|
.rounded_full()
|
||||||
|
.bg(rgba(0x2563ebff)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div().relative().h(px(32.0)).w_full().child(
|
||||||
|
div()
|
||||||
|
.absolute()
|
||||||
|
.top_1()
|
||||||
|
.size(px(24.0))
|
||||||
|
.rounded_full()
|
||||||
|
.bg(rgba(0x3b82f6ff))
|
||||||
|
.cursor_pointer()
|
||||||
|
.debug_selector(|| "spring-position".into())
|
||||||
|
.with_spring(
|
||||||
|
"spring-position",
|
||||||
|
SpringAnimation::new(spring)
|
||||||
|
.to(spring_position)
|
||||||
|
.with_epsilon(0.25),
|
||||||
|
|this, left| this.left(left),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div().h(px(24.0)).rounded_sm().with_spring(
|
||||||
|
"spring-phase",
|
||||||
|
SpringAnimation::new(spring)
|
||||||
|
.to(AnimationPhase(f32::from(spring_phase)))
|
||||||
|
.with_epsilon(0.001),
|
||||||
|
|this, phase| {
|
||||||
|
let (width, color) = if phase.0 <= 1.0 {
|
||||||
|
(
|
||||||
|
phase.interpolate_between(
|
||||||
|
0.0..=1.0,
|
||||||
|
px(48.0),
|
||||||
|
px(224.0),
|
||||||
|
),
|
||||||
|
phase.interpolate_between_clamped(
|
||||||
|
0.0..=1.0,
|
||||||
|
rgba(0xf97316ff),
|
||||||
|
rgba(0x22c55eff),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
(
|
||||||
|
phase.interpolate_between(
|
||||||
|
1.0..=2.0,
|
||||||
|
px(224.0),
|
||||||
|
px(96.0),
|
||||||
|
),
|
||||||
|
phase.interpolate_between_clamped(
|
||||||
|
1.0..=2.0,
|
||||||
|
rgba(0x22c55eff),
|
||||||
|
rgba(0xa855f7ff),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
this.w(width).bg(color)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
svg()
|
||||||
|
.size_20()
|
||||||
|
.overflow_hidden()
|
||||||
|
.path(ARROW_CIRCLE_SVG)
|
||||||
|
.text_color(gpui::black())
|
||||||
|
.with_animation(
|
||||||
|
"image_circle",
|
||||||
|
Animation::new(Duration::from_secs(2))
|
||||||
|
.repeat()
|
||||||
|
.with_easing(bounce(ease_in_out)),
|
||||||
|
|svg, delta| {
|
||||||
|
svg.with_transformation(Transformation::rotate(
|
||||||
|
percentage(delta),
|
||||||
|
))
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.h(px(64.))
|
||||||
|
.w_full()
|
||||||
|
.p_2()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.border_t_1()
|
||||||
|
.border_color(gpui::black().opacity(0.1))
|
||||||
|
.bg(gpui::black().opacity(0.05))
|
||||||
|
.child("Other Panel"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().with_assets(Assets {}).run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let options = WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
|
||||||
|
None,
|
||||||
|
size(px(300.), px(300.)),
|
||||||
|
cx,
|
||||||
|
))),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
cx.open_window(options, |_, cx| {
|
||||||
|
cx.activate(false);
|
||||||
|
cx.new(|_| AnimationExample {
|
||||||
|
spring_phase: 0,
|
||||||
|
spring_damping: 14.0,
|
||||||
|
spring_damping_drag: None,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(test, feature = "test-support"))]
|
||||||
|
mod tests {
|
||||||
|
use gpui::{Modifiers, TestAppContext};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
fn clicking_spring_position_changes_the_target(cx: &mut TestAppContext) {
|
||||||
|
let (view, cx) = cx.add_window_view(|_, _| AnimationExample {
|
||||||
|
spring_phase: 0,
|
||||||
|
spring_damping: 14.0,
|
||||||
|
spring_damping_drag: None,
|
||||||
|
});
|
||||||
|
cx.simulate_resize(size(px(300.0), px(300.0)));
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
let position_bounds = cx
|
||||||
|
.debug_bounds("spring-position")
|
||||||
|
.expect("spring position should be rendered");
|
||||||
|
let position = position_bounds.center();
|
||||||
|
cx.simulate_mouse_move(position, None, Modifiers::default());
|
||||||
|
cx.simulate_click(position, Modifiers::default());
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
assert_eq!(cx.update(|_, cx| view.read(cx).spring_phase), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
+494
@@ -0,0 +1,494 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use std::{ops::Range, rc::Rc, time::Duration};
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels, Point, Render,
|
||||||
|
SharedString, UniformListScrollHandle, Window, WindowBounds, WindowOptions, canvas, div, point,
|
||||||
|
prelude::*, px, rgb, size, uniform_list,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
const TOTAL_ITEMS: usize = 10000;
|
||||||
|
const SCROLLBAR_THUMB_WIDTH: Pixels = px(8.);
|
||||||
|
const SCROLLBAR_THUMB_HEIGHT: Pixels = px(100.);
|
||||||
|
|
||||||
|
pub struct Quote {
|
||||||
|
name: SharedString,
|
||||||
|
symbol: SharedString,
|
||||||
|
last_done: f64,
|
||||||
|
prev_close: f64,
|
||||||
|
open: f64,
|
||||||
|
high: f64,
|
||||||
|
low: f64,
|
||||||
|
timestamp: Duration,
|
||||||
|
volume: i64,
|
||||||
|
turnover: f64,
|
||||||
|
ttm: f64,
|
||||||
|
market_cap: f64,
|
||||||
|
float_cap: f64,
|
||||||
|
shares: f64,
|
||||||
|
pb: f64,
|
||||||
|
pe: f64,
|
||||||
|
eps: f64,
|
||||||
|
dividend: f64,
|
||||||
|
dividend_yield: f64,
|
||||||
|
dividend_per_share: f64,
|
||||||
|
dividend_date: SharedString,
|
||||||
|
dividend_payment: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Quote {
|
||||||
|
pub fn random() -> Self {
|
||||||
|
use rand::Rng;
|
||||||
|
let mut rng = rand::rng();
|
||||||
|
// simulate a base price in a realistic range
|
||||||
|
let prev_close = rng.random_range(100.0..200.0);
|
||||||
|
let change = rng.random_range(-5.0..5.0);
|
||||||
|
let last_done = prev_close + change;
|
||||||
|
let open = prev_close + rng.random_range(-3.0..3.0);
|
||||||
|
let high = (prev_close + rng.random_range::<f64, _>(0.0..10.0)).max(open);
|
||||||
|
let low = (prev_close - rng.random_range::<f64, _>(0.0..10.0)).min(open);
|
||||||
|
let timestamp = Duration::from_secs(rng.random_range(0..86400));
|
||||||
|
let volume = rng.random_range(1_000_000..100_000_000);
|
||||||
|
let turnover = last_done * volume as f64;
|
||||||
|
let symbol = {
|
||||||
|
let mut ticker = String::new();
|
||||||
|
if rng.random_bool(0.5) {
|
||||||
|
ticker.push_str(&format!(
|
||||||
|
"{:03}.{}",
|
||||||
|
rng.random_range(100..1000),
|
||||||
|
rng.random_range(0..10)
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
ticker.push_str(&format!(
|
||||||
|
"{}{}",
|
||||||
|
rng.random_range('A'..='Z'),
|
||||||
|
rng.random_range('A'..='Z')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
ticker.push_str(&format!(".{}", rng.random_range('A'..='Z')));
|
||||||
|
ticker
|
||||||
|
};
|
||||||
|
let name = format!(
|
||||||
|
"{} {} - #{}",
|
||||||
|
symbol,
|
||||||
|
rng.random_range(1..100),
|
||||||
|
rng.random_range(10000..100000)
|
||||||
|
);
|
||||||
|
let ttm = rng.random_range(0.0..10.0);
|
||||||
|
let market_cap = rng.random_range(1_000_000.0..10_000_000.0);
|
||||||
|
let float_cap = market_cap + rng.random_range(1_000.0..10_000.0);
|
||||||
|
let shares = rng.random_range(100.0..1000.0);
|
||||||
|
let pb = market_cap / shares;
|
||||||
|
let pe = market_cap / shares;
|
||||||
|
let eps = market_cap / shares;
|
||||||
|
let dividend = rng.random_range(0.0..10.0);
|
||||||
|
let dividend_yield = rng.random_range(0.0..10.0);
|
||||||
|
let dividend_per_share = rng.random_range(0.0..10.0);
|
||||||
|
let dividend_date = SharedString::new(format!(
|
||||||
|
"{}-{}-{}",
|
||||||
|
rng.random_range(2000..2023),
|
||||||
|
rng.random_range(1..12),
|
||||||
|
rng.random_range(1..28)
|
||||||
|
));
|
||||||
|
let dividend_payment = rng.random_range(0.0..10.0);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
name: name.into(),
|
||||||
|
symbol: symbol.into(),
|
||||||
|
last_done,
|
||||||
|
prev_close,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
low,
|
||||||
|
timestamp,
|
||||||
|
volume,
|
||||||
|
turnover,
|
||||||
|
pb,
|
||||||
|
pe,
|
||||||
|
eps,
|
||||||
|
ttm,
|
||||||
|
market_cap,
|
||||||
|
float_cap,
|
||||||
|
shares,
|
||||||
|
dividend,
|
||||||
|
dividend_yield,
|
||||||
|
dividend_per_share,
|
||||||
|
dividend_date,
|
||||||
|
dividend_payment,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn change(&self) -> f64 {
|
||||||
|
(self.last_done - self.prev_close) / self.prev_close * 100.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn change_color(&self) -> gpui::Hsla {
|
||||||
|
if self.change() > 0.0 {
|
||||||
|
gpui::green()
|
||||||
|
} else {
|
||||||
|
gpui::red()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn turnover_ratio(&self) -> f64 {
|
||||||
|
self.volume as f64 / self.turnover * 100.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(IntoElement)]
|
||||||
|
struct TableRow {
|
||||||
|
ix: usize,
|
||||||
|
quote: Rc<Quote>,
|
||||||
|
}
|
||||||
|
impl TableRow {
|
||||||
|
fn new(ix: usize, quote: Rc<Quote>) -> Self {
|
||||||
|
Self { ix, quote }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_cell(&self, key: &str, width: Pixels, color: gpui::Hsla) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.whitespace_nowrap()
|
||||||
|
.truncate()
|
||||||
|
.w(width)
|
||||||
|
.px_1()
|
||||||
|
.child(match key {
|
||||||
|
"id" => div().child(format!("{}", self.ix)),
|
||||||
|
"symbol" => div().child(self.quote.symbol.clone()),
|
||||||
|
"name" => div().child(self.quote.name.clone()),
|
||||||
|
"last_done" => div()
|
||||||
|
.text_color(color)
|
||||||
|
.child(format!("{:.3}", self.quote.last_done)),
|
||||||
|
"prev_close" => div()
|
||||||
|
.text_color(color)
|
||||||
|
.child(format!("{:.3}", self.quote.prev_close)),
|
||||||
|
"change" => div()
|
||||||
|
.text_color(color)
|
||||||
|
.child(format!("{:.2}%", self.quote.change())),
|
||||||
|
"timestamp" => div()
|
||||||
|
.text_color(color)
|
||||||
|
.child(format!("{:?}", self.quote.timestamp.as_secs())),
|
||||||
|
"open" => div()
|
||||||
|
.text_color(color)
|
||||||
|
.child(format!("{:.2}", self.quote.open)),
|
||||||
|
"low" => div()
|
||||||
|
.text_color(color)
|
||||||
|
.child(format!("{:.2}", self.quote.low)),
|
||||||
|
"high" => div()
|
||||||
|
.text_color(color)
|
||||||
|
.child(format!("{:.2}", self.quote.high)),
|
||||||
|
"ttm" => div()
|
||||||
|
.text_color(color)
|
||||||
|
.child(format!("{:.2}", self.quote.ttm)),
|
||||||
|
"eps" => div()
|
||||||
|
.text_color(color)
|
||||||
|
.child(format!("{:.2}", self.quote.eps)),
|
||||||
|
"market_cap" => {
|
||||||
|
div().child(format!("{:.2} M", self.quote.market_cap / 1_000_000.0))
|
||||||
|
}
|
||||||
|
"float_cap" => div().child(format!("{:.2} M", self.quote.float_cap / 1_000_000.0)),
|
||||||
|
"turnover" => div().child(format!("{:.2} M", self.quote.turnover / 1_000_000.0)),
|
||||||
|
"volume" => div().child(format!("{:.2} M", self.quote.volume as f64 / 1_000_000.0)),
|
||||||
|
"turnover_ratio" => div().child(format!("{:.2}%", self.quote.turnover_ratio())),
|
||||||
|
"pe" => div().child(format!("{:.2}", self.quote.pe)),
|
||||||
|
"pb" => div().child(format!("{:.2}", self.quote.pb)),
|
||||||
|
"shares" => div().child(format!("{:.2}", self.quote.shares)),
|
||||||
|
"dividend" => div().child(format!("{:.2}", self.quote.dividend)),
|
||||||
|
"yield" => div().child(format!("{:.2}%", self.quote.dividend_yield)),
|
||||||
|
"dividend_per_share" => {
|
||||||
|
div().child(format!("{:.2}", self.quote.dividend_per_share))
|
||||||
|
}
|
||||||
|
"dividend_date" => div().child(format!("{}", self.quote.dividend_date)),
|
||||||
|
"dividend_payment" => div().child(format!("{:.2}", self.quote.dividend_payment)),
|
||||||
|
_ => div().child("--"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const FIELDS: [(&str, f32); 24] = [
|
||||||
|
("id", 64.),
|
||||||
|
("symbol", 64.),
|
||||||
|
("name", 180.),
|
||||||
|
("last_done", 80.),
|
||||||
|
("prev_close", 80.),
|
||||||
|
("open", 80.),
|
||||||
|
("low", 80.),
|
||||||
|
("high", 80.),
|
||||||
|
("ttm", 50.),
|
||||||
|
("market_cap", 96.),
|
||||||
|
("float_cap", 96.),
|
||||||
|
("turnover", 120.),
|
||||||
|
("volume", 100.),
|
||||||
|
("turnover_ratio", 96.),
|
||||||
|
("pe", 64.),
|
||||||
|
("pb", 64.),
|
||||||
|
("eps", 64.),
|
||||||
|
("shares", 96.),
|
||||||
|
("dividend", 64.),
|
||||||
|
("yield", 64.),
|
||||||
|
("dividend_per_share", 64.),
|
||||||
|
("dividend_date", 96.),
|
||||||
|
("dividend_payment", 64.),
|
||||||
|
("timestamp", 120.),
|
||||||
|
];
|
||||||
|
|
||||||
|
impl RenderOnce for TableRow {
|
||||||
|
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
|
||||||
|
let color = self.quote.change_color();
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(rgb(0xE0E0E0))
|
||||||
|
.bg(if self.ix.is_multiple_of(2) {
|
||||||
|
rgb(0xFFFFFF)
|
||||||
|
} else {
|
||||||
|
rgb(0xFAFAFA)
|
||||||
|
})
|
||||||
|
.py_0p5()
|
||||||
|
.px_2()
|
||||||
|
.children(FIELDS.map(|(key, width)| self.render_cell(key, px(width), color)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DataTable {
|
||||||
|
/// Use `Rc` to share the same quote data across multiple items, avoid cloning.
|
||||||
|
quotes: Vec<Rc<Quote>>,
|
||||||
|
visible_range: Range<usize>,
|
||||||
|
scroll_handle: UniformListScrollHandle,
|
||||||
|
/// The position in thumb bounds when dragging start mouse down.
|
||||||
|
drag_position: Option<Point<Pixels>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DataTable {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
quotes: Vec::new(),
|
||||||
|
visible_range: 0..0,
|
||||||
|
scroll_handle: UniformListScrollHandle::new(),
|
||||||
|
drag_position: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate(&mut self) {
|
||||||
|
self.quotes = (0..TOTAL_ITEMS).map(|_| Rc::new(Quote::random())).collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn table_bounds(&self) -> Bounds<Pixels> {
|
||||||
|
self.scroll_handle.0.borrow().base_handle.bounds()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scroll_top(&self) -> Pixels {
|
||||||
|
self.scroll_handle.0.borrow().base_handle.offset().y
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scroll_height(&self) -> Pixels {
|
||||||
|
self.scroll_handle
|
||||||
|
.0
|
||||||
|
.borrow()
|
||||||
|
.last_item_size
|
||||||
|
.unwrap_or_default()
|
||||||
|
.contents
|
||||||
|
.height
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_scrollbar(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let scroll_height = self.scroll_height();
|
||||||
|
let table_bounds = self.table_bounds();
|
||||||
|
let table_height = table_bounds.size.height;
|
||||||
|
if table_height == px(0.) {
|
||||||
|
return div().id("scrollbar");
|
||||||
|
}
|
||||||
|
|
||||||
|
let percentage = -self.scroll_top() / scroll_height;
|
||||||
|
let offset_top = (table_height * percentage).clamp(
|
||||||
|
px(4.),
|
||||||
|
(table_height - SCROLLBAR_THUMB_HEIGHT - px(4.)).max(px(4.)),
|
||||||
|
);
|
||||||
|
let entity = cx.entity();
|
||||||
|
let scroll_handle = self.scroll_handle.0.borrow().base_handle.clone();
|
||||||
|
|
||||||
|
div()
|
||||||
|
.id("scrollbar")
|
||||||
|
.absolute()
|
||||||
|
.top(offset_top)
|
||||||
|
.right_1()
|
||||||
|
.h(SCROLLBAR_THUMB_HEIGHT)
|
||||||
|
.w(SCROLLBAR_THUMB_WIDTH)
|
||||||
|
.bg(rgb(0xC0C0C0))
|
||||||
|
.hover(|this| this.bg(rgb(0xA0A0A0)))
|
||||||
|
.rounded_lg()
|
||||||
|
.child(
|
||||||
|
canvas(
|
||||||
|
|_, _, _| (),
|
||||||
|
move |thumb_bounds, _, window, _| {
|
||||||
|
window.on_mouse_event({
|
||||||
|
let entity = entity.clone();
|
||||||
|
move |ev: &MouseDownEvent, _, _, cx| {
|
||||||
|
if !thumb_bounds.contains(&ev.position) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.update(cx, |this, _| {
|
||||||
|
this.drag_position = Some(
|
||||||
|
ev.position - thumb_bounds.origin - table_bounds.origin,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.on_mouse_event({
|
||||||
|
let entity = entity.clone();
|
||||||
|
move |_: &MouseUpEvent, _, _, cx| {
|
||||||
|
entity.update(cx, |this, _| {
|
||||||
|
this.drag_position = None;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.on_mouse_event(move |ev: &MouseMoveEvent, _, _, cx| {
|
||||||
|
if !ev.dragging() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let Some(drag_pos) = entity.read(cx).drag_position else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let inside_offset = drag_pos.y;
|
||||||
|
let percentage = ((ev.position.y - table_bounds.origin.y
|
||||||
|
+ inside_offset)
|
||||||
|
/ (table_bounds.size.height))
|
||||||
|
.clamp(0., 1.);
|
||||||
|
|
||||||
|
let offset_y = ((scroll_height - table_bounds.size.height)
|
||||||
|
* percentage)
|
||||||
|
.clamp(px(0.), scroll_height - SCROLLBAR_THUMB_HEIGHT);
|
||||||
|
scroll_handle.set_offset(point(px(0.), -offset_y));
|
||||||
|
cx.notify(entity.entity_id());
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.size_full(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for DataTable {
|
||||||
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.text_sm()
|
||||||
|
.size_full()
|
||||||
|
.p_4()
|
||||||
|
.gap_2()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.child(format!(
|
||||||
|
"Total {} items, visible range: {:?}",
|
||||||
|
self.quotes.len(),
|
||||||
|
self.visible_range
|
||||||
|
))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.flex_1()
|
||||||
|
.overflow_hidden()
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(0xE0E0E0))
|
||||||
|
.rounded_sm()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.w_full()
|
||||||
|
.overflow_hidden()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(rgb(0xE0E0E0))
|
||||||
|
.text_color(rgb(0x555555))
|
||||||
|
.bg(rgb(0xF0F0F0))
|
||||||
|
.py_1()
|
||||||
|
.px_2()
|
||||||
|
.text_xs()
|
||||||
|
.children(FIELDS.map(|(key, width)| {
|
||||||
|
div()
|
||||||
|
.whitespace_nowrap()
|
||||||
|
.flex_shrink_0()
|
||||||
|
.truncate()
|
||||||
|
.px_1()
|
||||||
|
.w(px(width))
|
||||||
|
.child(key.replace("_", " ").to_uppercase())
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.relative()
|
||||||
|
.size_full()
|
||||||
|
.child(
|
||||||
|
uniform_list(
|
||||||
|
"items",
|
||||||
|
self.quotes.len(),
|
||||||
|
cx.processor(move |this, range: Range<usize>, _, _| {
|
||||||
|
this.visible_range = range.clone();
|
||||||
|
let mut items = Vec::with_capacity(range.end - range.start);
|
||||||
|
for i in range {
|
||||||
|
if let Some(quote) = this.quotes.get(i) {
|
||||||
|
items.push(TableRow::new(i, quote.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
items
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.size_full()
|
||||||
|
.track_scroll(&self.scroll_handle),
|
||||||
|
)
|
||||||
|
.child(self.render_scrollbar(window, cx)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
focus: true,
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
|
||||||
|
None,
|
||||||
|
size(px(1280.0), px(1000.0)),
|
||||||
|
cx,
|
||||||
|
))),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| {
|
||||||
|
cx.new(|_| {
|
||||||
|
let mut table = DataTable::new();
|
||||||
|
table.generate();
|
||||||
|
table
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+158
@@ -0,0 +1,158 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, Half, Hsla, Pixels, Point, Window, WindowBounds, WindowOptions, div,
|
||||||
|
prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
struct DragInfo {
|
||||||
|
ix: usize,
|
||||||
|
color: Hsla,
|
||||||
|
position: Point<Pixels>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DragInfo {
|
||||||
|
fn new(ix: usize, color: Hsla) -> Self {
|
||||||
|
Self {
|
||||||
|
ix,
|
||||||
|
color,
|
||||||
|
position: Point::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn position(mut self, pos: Point<Pixels>) -> Self {
|
||||||
|
self.position = pos;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for DragInfo {
|
||||||
|
fn render(&mut self, _: &mut Window, _: &mut Context<'_, Self>) -> impl IntoElement {
|
||||||
|
let size = gpui::size(px(120.), px(50.));
|
||||||
|
|
||||||
|
div()
|
||||||
|
.pl(self.position.x - size.width.half())
|
||||||
|
.pt(self.position.y - size.height.half())
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.w(size.width)
|
||||||
|
.h(size.height)
|
||||||
|
.bg(self.color.opacity(0.5))
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.text_xs()
|
||||||
|
.shadow_md()
|
||||||
|
.child(format!("Item {}", self.ix)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DragDrop {
|
||||||
|
drop_on: Option<DragInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DragDrop {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self { drop_on: None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for DragDrop {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let items = [gpui::blue(), gpui::red(), gpui::green()];
|
||||||
|
|
||||||
|
div()
|
||||||
|
.size_full()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_5()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.text_color(rgb(0x333333))
|
||||||
|
.child(div().text_xl().text_center().child("Drop & Drop"))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.w_full()
|
||||||
|
.mb_10()
|
||||||
|
.justify_center()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.gap_4()
|
||||||
|
.items_center()
|
||||||
|
.children(items.into_iter().enumerate().map(|(ix, color)| {
|
||||||
|
let drag_info = DragInfo::new(ix, color);
|
||||||
|
|
||||||
|
div()
|
||||||
|
.id(("item", ix))
|
||||||
|
.size_32()
|
||||||
|
.flex()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.border_2()
|
||||||
|
.border_color(color)
|
||||||
|
.text_color(color)
|
||||||
|
.cursor_move()
|
||||||
|
.hover(|this| this.bg(color.opacity(0.2)))
|
||||||
|
.child(format!("Item ({})", ix))
|
||||||
|
.on_drag(drag_info, |info: &DragInfo, position, _, cx| {
|
||||||
|
cx.new(|_| info.position(position))
|
||||||
|
})
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("drop-target")
|
||||||
|
.w_128()
|
||||||
|
.h_32()
|
||||||
|
.flex()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.border_3()
|
||||||
|
.border_color(self.drop_on.map(|info| info.color).unwrap_or(gpui::black()))
|
||||||
|
.when_some(self.drop_on, |this, info| this.bg(info.color.opacity(0.5)))
|
||||||
|
.on_drop(cx.listener(|this, info: &DragInfo, _, _| {
|
||||||
|
this.drop_on = Some(*info);
|
||||||
|
}))
|
||||||
|
.child("Drop items here"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(800.), px(600.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| cx.new(|_| DragDrop::new()),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use gpui::App;
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
pub fn load_fonts(cx: &App) -> bool {
|
||||||
|
let fonts = [
|
||||||
|
Cow::Borrowed(
|
||||||
|
include_bytes!("../../../../assets/fonts/ibm-plex-sans/IBMPlexSans-Regular.ttf")
|
||||||
|
.as_slice(),
|
||||||
|
),
|
||||||
|
Cow::Borrowed(
|
||||||
|
include_bytes!("../../../../assets/fonts/ibm-plex-sans/IBMPlexSans-Italic.ttf")
|
||||||
|
.as_slice(),
|
||||||
|
),
|
||||||
|
Cow::Borrowed(
|
||||||
|
include_bytes!("../../../../assets/fonts/ibm-plex-sans/IBMPlexSans-SemiBold.ttf")
|
||||||
|
.as_slice(),
|
||||||
|
),
|
||||||
|
Cow::Borrowed(
|
||||||
|
include_bytes!("../../../../assets/fonts/ibm-plex-sans/IBMPlexSans-SemiBoldItalic.ttf")
|
||||||
|
.as_slice(),
|
||||||
|
),
|
||||||
|
Cow::Borrowed(
|
||||||
|
include_bytes!("../../../../assets/fonts/lilex/Lilex-Regular.ttf").as_slice(),
|
||||||
|
),
|
||||||
|
Cow::Borrowed(include_bytes!("../../../../assets/fonts/lilex/Lilex-Bold.ttf").as_slice()),
|
||||||
|
Cow::Borrowed(include_bytes!("../../../../assets/fonts/lilex/Lilex-Italic.ttf").as_slice()),
|
||||||
|
Cow::Borrowed(
|
||||||
|
include_bytes!("../../../../assets/fonts/lilex/Lilex-BoldItalic.ttf").as_slice(),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
if let Err(error) = cx.text_system().add_fonts(fonts.into()) {
|
||||||
|
web_sys::console::error_1(&format!("failed to load application fonts: {error:#}").into());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
pub fn load_fonts(_cx: &App) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
+235
@@ -0,0 +1,235 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, Div, ElementId, FocusHandle, KeyBinding, SharedString, Stateful, Window,
|
||||||
|
WindowBounds, WindowOptions, actions, div, prelude::*, px, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
actions!(example, [Tab, TabPrev, Quit]);
|
||||||
|
|
||||||
|
struct Example {
|
||||||
|
focus_handle: FocusHandle,
|
||||||
|
items: Vec<(FocusHandle, &'static str)>,
|
||||||
|
message: SharedString,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Example {
|
||||||
|
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let items = vec![
|
||||||
|
(
|
||||||
|
cx.focus_handle().tab_index(1).tab_stop(true),
|
||||||
|
"Button with .focus() - always shows border when focused",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
cx.focus_handle().tab_index(2).tab_stop(true),
|
||||||
|
"Button with .focus_visible() - only shows border with keyboard",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
cx.focus_handle().tab_index(3).tab_stop(true),
|
||||||
|
"Button with both .focus() and .focus_visible()",
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
let focus_handle = cx.focus_handle();
|
||||||
|
window.focus(&focus_handle, cx);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
focus_handle,
|
||||||
|
items,
|
||||||
|
message: SharedString::from(
|
||||||
|
"Try clicking vs tabbing! Click shows no border, Tab shows border.",
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_tab(&mut self, _: &Tab, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
window.focus_next(cx);
|
||||||
|
self.message = SharedString::from("Pressed Tab - focus-visible border should appear!");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_tab_prev(&mut self, _: &TabPrev, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
window.focus_prev(cx);
|
||||||
|
self.message =
|
||||||
|
SharedString::from("Pressed Shift-Tab - focus-visible border should appear!");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_quit(&mut self, _: &Quit, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
cx.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for Example {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
fn button_base(id: impl Into<ElementId>, label: &'static str) -> Stateful<Div> {
|
||||||
|
div()
|
||||||
|
.id(id)
|
||||||
|
.h_16()
|
||||||
|
.w_full()
|
||||||
|
.flex()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.bg(gpui::rgb(0x2563eb))
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.rounded_md()
|
||||||
|
.cursor_pointer()
|
||||||
|
.hover(|style| style.bg(gpui::rgb(0x1d4ed8)))
|
||||||
|
.child(label)
|
||||||
|
}
|
||||||
|
|
||||||
|
div()
|
||||||
|
.id("app")
|
||||||
|
.track_focus(&self.focus_handle)
|
||||||
|
.on_action(cx.listener(Self::on_tab))
|
||||||
|
.on_action(cx.listener(Self::on_tab_prev))
|
||||||
|
.on_action(cx.listener(Self::on_quit))
|
||||||
|
.size_full()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.p_8()
|
||||||
|
.gap_6()
|
||||||
|
.bg(gpui::rgb(0xf3f4f6))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_2xl()
|
||||||
|
.font_weight(gpui::FontWeight::BOLD)
|
||||||
|
.text_color(gpui::rgb(0x111827))
|
||||||
|
.child("CSS focus-visible Demo"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.p_4()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(gpui::rgb(0xdbeafe))
|
||||||
|
.text_color(gpui::rgb(0x1e3a8a))
|
||||||
|
.child(self.message.clone()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_4()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.font_weight(gpui::FontWeight::BOLD)
|
||||||
|
.text_color(gpui::rgb(0x374151))
|
||||||
|
.child("1. Regular .focus() - always visible:"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
button_base("button1", self.items[0].1)
|
||||||
|
.track_focus(&self.items[0].0)
|
||||||
|
.focus(|style| {
|
||||||
|
style.border_4().border_color(gpui::rgb(0xfbbf24))
|
||||||
|
})
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.message =
|
||||||
|
"Clicked button 1 - focus border is visible!".into();
|
||||||
|
cx.notify();
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.font_weight(gpui::FontWeight::BOLD)
|
||||||
|
.text_color(gpui::rgb(0x374151))
|
||||||
|
.child("2. New .focus_visible() - only keyboard:"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
button_base("button2", self.items[1].1)
|
||||||
|
.track_focus(&self.items[1].0)
|
||||||
|
.focus_visible(|style| {
|
||||||
|
style.border_4().border_color(gpui::rgb(0x10b981))
|
||||||
|
})
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.message =
|
||||||
|
"Clicked button 2 - no border! Try Tab instead.".into();
|
||||||
|
cx.notify();
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.font_weight(gpui::FontWeight::BOLD)
|
||||||
|
.text_color(gpui::rgb(0x374151))
|
||||||
|
.child(
|
||||||
|
"3. Both .focus() (yellow) and .focus_visible() (green):",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
button_base("button3", self.items[2].1)
|
||||||
|
.track_focus(&self.items[2].0)
|
||||||
|
.focus(|style| {
|
||||||
|
style.border_4().border_color(gpui::rgb(0xfbbf24))
|
||||||
|
})
|
||||||
|
.focus_visible(|style| {
|
||||||
|
style.border_4().border_color(gpui::rgb(0x10b981))
|
||||||
|
})
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.message =
|
||||||
|
"Clicked button 3 - yellow border. Tab shows green!"
|
||||||
|
.into();
|
||||||
|
cx.notify();
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.bind_keys([
|
||||||
|
KeyBinding::new("tab", Tab, None),
|
||||||
|
KeyBinding::new("shift-tab", TabPrev, None),
|
||||||
|
KeyBinding::new("cmd-q", Quit, None),
|
||||||
|
]);
|
||||||
|
|
||||||
|
let bounds = Bounds::centered(None, size(px(800.), px(600.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|window, cx| cx.new(|cx| Example::new(window, cx)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{App, Context, Render, Window, WindowOptions, div, img, prelude::*};
|
||||||
|
use gpui_platform::application;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
struct GifViewer {
|
||||||
|
gif_path: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GifViewer {
|
||||||
|
fn new(gif_path: PathBuf) -> Self {
|
||||||
|
Self { gif_path }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for GifViewer {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div().size_full().child(
|
||||||
|
img(self.gif_path.clone())
|
||||||
|
.size_full()
|
||||||
|
.object_fit(gpui::ObjectFit::Contain)
|
||||||
|
.id("gif"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let gif_path =
|
||||||
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/image/black-cat-typing.gif");
|
||||||
|
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
focus: true,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| cx.new(|_| GifViewer::new(gif_path)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
env_logger::init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
Vendored
+278
@@ -0,0 +1,278 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, ColorSpace, Context, Half, Render, Window, WindowOptions, canvas, div,
|
||||||
|
linear_color_stop, linear_gradient, point, prelude::*, px, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct GradientViewer {
|
||||||
|
color_space: ColorSpace,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GradientViewer {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
color_space: ColorSpace::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for GradientViewer {
|
||||||
|
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let color_space = self.color_space;
|
||||||
|
|
||||||
|
div()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.size_full()
|
||||||
|
.p_4()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_3()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.gap_2()
|
||||||
|
.justify_between()
|
||||||
|
.items_center()
|
||||||
|
.child("Gradient Examples")
|
||||||
|
.child(
|
||||||
|
div().flex().gap_2().items_center().child(
|
||||||
|
div()
|
||||||
|
.id("method")
|
||||||
|
.flex()
|
||||||
|
.px_3()
|
||||||
|
.py_1()
|
||||||
|
.text_sm()
|
||||||
|
.bg(gpui::black())
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.child(format!("{}", color_space))
|
||||||
|
.active(|this| this.opacity(0.8))
|
||||||
|
.on_click(cx.listener(move |this, _, _, cx| {
|
||||||
|
this.color_space = match this.color_space {
|
||||||
|
ColorSpace::Oklab => ColorSpace::Srgb,
|
||||||
|
ColorSpace::Srgb => ColorSpace::Oklab,
|
||||||
|
};
|
||||||
|
cx.notify();
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_1()
|
||||||
|
.gap_3()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.size_full()
|
||||||
|
.rounded_xl()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.bg(gpui::red())
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.child("Solid Color"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.size_full()
|
||||||
|
.rounded_xl()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.bg(gpui::blue())
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.child("Solid Color"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_1()
|
||||||
|
.gap_3()
|
||||||
|
.h_24()
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.child(
|
||||||
|
div().flex_1().rounded_xl().bg(linear_gradient(
|
||||||
|
45.,
|
||||||
|
linear_color_stop(gpui::red(), 0.),
|
||||||
|
linear_color_stop(gpui::blue(), 1.),
|
||||||
|
)
|
||||||
|
.color_space(color_space)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div().flex_1().rounded_xl().bg(linear_gradient(
|
||||||
|
135.,
|
||||||
|
linear_color_stop(gpui::red(), 0.),
|
||||||
|
linear_color_stop(gpui::green(), 1.),
|
||||||
|
)
|
||||||
|
.color_space(color_space)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div().flex_1().rounded_xl().bg(linear_gradient(
|
||||||
|
225.,
|
||||||
|
linear_color_stop(gpui::green(), 0.),
|
||||||
|
linear_color_stop(gpui::blue(), 1.),
|
||||||
|
)
|
||||||
|
.color_space(color_space)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div().flex_1().rounded_xl().bg(linear_gradient(
|
||||||
|
315.,
|
||||||
|
linear_color_stop(gpui::green(), 0.),
|
||||||
|
linear_color_stop(gpui::yellow(), 1.),
|
||||||
|
)
|
||||||
|
.color_space(color_space)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_1()
|
||||||
|
.gap_3()
|
||||||
|
.h_24()
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.child(
|
||||||
|
div().flex_1().rounded_xl().bg(linear_gradient(
|
||||||
|
0.,
|
||||||
|
linear_color_stop(gpui::red(), 0.),
|
||||||
|
linear_color_stop(gpui::white(), 1.),
|
||||||
|
)
|
||||||
|
.color_space(color_space)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div().flex_1().rounded_xl().bg(linear_gradient(
|
||||||
|
90.,
|
||||||
|
linear_color_stop(gpui::blue(), 0.),
|
||||||
|
linear_color_stop(gpui::white(), 1.),
|
||||||
|
)
|
||||||
|
.color_space(color_space)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div().flex_1().rounded_xl().bg(linear_gradient(
|
||||||
|
180.,
|
||||||
|
linear_color_stop(gpui::green(), 0.),
|
||||||
|
linear_color_stop(gpui::white(), 1.),
|
||||||
|
)
|
||||||
|
.color_space(color_space)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div().flex_1().rounded_xl().bg(linear_gradient(
|
||||||
|
360.,
|
||||||
|
linear_color_stop(gpui::yellow(), 0.),
|
||||||
|
linear_color_stop(gpui::white(), 1.),
|
||||||
|
)
|
||||||
|
.color_space(color_space)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div().flex_1().rounded_xl().bg(linear_gradient(
|
||||||
|
0.,
|
||||||
|
linear_color_stop(gpui::green(), 0.05),
|
||||||
|
linear_color_stop(gpui::yellow(), 0.95),
|
||||||
|
)
|
||||||
|
.color_space(color_space)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div().flex_1().rounded_xl().bg(linear_gradient(
|
||||||
|
90.,
|
||||||
|
linear_color_stop(gpui::blue(), 0.05),
|
||||||
|
linear_color_stop(gpui::red(), 0.95),
|
||||||
|
)
|
||||||
|
.color_space(color_space)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_1()
|
||||||
|
.gap_3()
|
||||||
|
.child(
|
||||||
|
div().flex().flex_1().gap_3().child(
|
||||||
|
div().flex_1().rounded_xl().bg(linear_gradient(
|
||||||
|
90.,
|
||||||
|
linear_color_stop(gpui::blue(), 0.5),
|
||||||
|
linear_color_stop(gpui::red(), 0.5),
|
||||||
|
)
|
||||||
|
.color_space(color_space)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div().flex_1().rounded_xl().bg(linear_gradient(
|
||||||
|
180.,
|
||||||
|
linear_color_stop(gpui::green(), 0.),
|
||||||
|
linear_color_stop(gpui::blue(), 0.5),
|
||||||
|
)
|
||||||
|
.color_space(color_space)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(div().h_24().child(canvas(
|
||||||
|
move |_, _, _| {},
|
||||||
|
move |bounds, _, window, _| {
|
||||||
|
let size = size(bounds.size.width * 0.8, px(80.));
|
||||||
|
let square_bounds = Bounds {
|
||||||
|
origin: point(
|
||||||
|
bounds.size.width.half() - size.width.half(),
|
||||||
|
bounds.origin.y,
|
||||||
|
),
|
||||||
|
size,
|
||||||
|
};
|
||||||
|
let height = square_bounds.size.height;
|
||||||
|
let horizontal_offset = height;
|
||||||
|
let vertical_offset = px(30.);
|
||||||
|
let mut builder = gpui::PathBuilder::fill();
|
||||||
|
builder.move_to(square_bounds.bottom_left());
|
||||||
|
builder
|
||||||
|
.line_to(square_bounds.origin + point(horizontal_offset, vertical_offset));
|
||||||
|
builder.line_to(
|
||||||
|
square_bounds.top_right() + point(-horizontal_offset, vertical_offset),
|
||||||
|
);
|
||||||
|
|
||||||
|
builder.line_to(square_bounds.bottom_right());
|
||||||
|
builder.line_to(square_bounds.bottom_left());
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
window.paint_path(
|
||||||
|
path,
|
||||||
|
linear_gradient(
|
||||||
|
180.,
|
||||||
|
linear_color_stop(gpui::red(), 0.),
|
||||||
|
linear_color_stop(gpui::blue(), 1.),
|
||||||
|
)
|
||||||
|
.color_space(color_space),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
focus: true,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| cx.new(|_| GradientViewer::new()),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+95
@@ -0,0 +1,95 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, Hsla, Window, WindowBounds, WindowOptions, container_query, div,
|
||||||
|
prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
// https://en.wikipedia.org/wiki/Holy_grail_(web_design)
|
||||||
|
//
|
||||||
|
// Resize the window: the layout is chosen by `container_query` based on the
|
||||||
|
// measured size of the container, collapsing to a single stacked column when
|
||||||
|
// it becomes too narrow for the three-column grid.
|
||||||
|
struct HolyGrailExample {}
|
||||||
|
|
||||||
|
impl Render for HolyGrailExample {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
container_query(|container_size, _window, _cx| {
|
||||||
|
let block = |color: Hsla| {
|
||||||
|
div()
|
||||||
|
.size_full()
|
||||||
|
.bg(color)
|
||||||
|
.border_1()
|
||||||
|
.border_dashed()
|
||||||
|
.rounded_md()
|
||||||
|
.border_color(gpui::white())
|
||||||
|
.items_center()
|
||||||
|
};
|
||||||
|
|
||||||
|
let header = block(gpui::white()).child(format!("Header — {}", container_size.width));
|
||||||
|
let table_of_contents = block(gpui::red()).child("Table of contents");
|
||||||
|
let content = block(gpui::green()).child("Content");
|
||||||
|
let ad = block(gpui::blue()).child("AD :(").text_color(gpui::white());
|
||||||
|
let footer = block(gpui::black())
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.child("Footer");
|
||||||
|
|
||||||
|
let container = div().gap_1().bg(rgb(0x505050)).shadow_lg().size_full();
|
||||||
|
|
||||||
|
if container_size.width < px(400.) {
|
||||||
|
container
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.child(header.h_12().flex_none())
|
||||||
|
.child(table_of_contents.h_20().flex_none())
|
||||||
|
.child(content.flex_1())
|
||||||
|
.child(ad.h_20().flex_none())
|
||||||
|
.child(footer.h_12().flex_none())
|
||||||
|
} else {
|
||||||
|
container
|
||||||
|
.grid()
|
||||||
|
.grid_cols(5)
|
||||||
|
.grid_rows(5)
|
||||||
|
.child(header.row_span(1).col_span_full())
|
||||||
|
.child(table_of_contents.col_span(1).h_56())
|
||||||
|
.child(content.col_span(3).row_span(3))
|
||||||
|
.child(ad.col_span(1).row_span(3))
|
||||||
|
.child(footer.row_span(1).col_span_full())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(500.), px(500.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| cx.new(|_| HolyGrailExample {}),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+127
@@ -0,0 +1,127 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, SharedString, Window, WindowBounds, WindowOptions, div, prelude::*, px,
|
||||||
|
rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct HelloWorld {
|
||||||
|
text: SharedString,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for HelloWorld {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_3()
|
||||||
|
.bg(rgb(0x505050))
|
||||||
|
.size(px(500.0))
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.shadow_lg()
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(0x0000ff))
|
||||||
|
.text_xl()
|
||||||
|
.text_color(rgb(0xffffff))
|
||||||
|
.child(format!("Hello, {}!", self.text))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.size_8()
|
||||||
|
.bg(gpui::red())
|
||||||
|
.border_1()
|
||||||
|
.border_dashed()
|
||||||
|
.rounded_md()
|
||||||
|
.border_color(gpui::white()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.size_8()
|
||||||
|
.bg(gpui::green())
|
||||||
|
.border_1()
|
||||||
|
.border_dashed()
|
||||||
|
.rounded_md()
|
||||||
|
.border_color(gpui::white()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.size_8()
|
||||||
|
.bg(gpui::blue())
|
||||||
|
.border_1()
|
||||||
|
.border_dashed()
|
||||||
|
.rounded_md()
|
||||||
|
.border_color(gpui::white()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.size_8()
|
||||||
|
.bg(gpui::yellow())
|
||||||
|
.border_1()
|
||||||
|
.border_dashed()
|
||||||
|
.rounded_md()
|
||||||
|
.border_color(gpui::white()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.size_8()
|
||||||
|
.bg(gpui::black())
|
||||||
|
.border_1()
|
||||||
|
.border_dashed()
|
||||||
|
.rounded_md()
|
||||||
|
.rounded_md()
|
||||||
|
.border_color(gpui::white()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.size_8()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.border_1()
|
||||||
|
.border_dashed()
|
||||||
|
.rounded_md()
|
||||||
|
.border_color(gpui::black()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(500.), px(500.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| {
|
||||||
|
cx.new(|_| HelloWorld {
|
||||||
|
text: "World".into(),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 164 KiB |
@@ -0,0 +1,6 @@
|
|||||||
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M3 8C3 6.67392 3.52678 5.40215 4.46446 4.46447C5.40214 3.52679 6.67391 3.00001 7.99999 3.00001C9.39779 3.00527 10.7394 3.55069 11.7444 4.52223L13 5.77778" stroke="black" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M13 3.00001V5.77778H10.2222" stroke="black" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M13 8C13 9.32608 12.4732 10.5978 11.5355 11.5355C10.5978 12.4732 9.32607 13 7.99999 13C6.60219 12.9947 5.26054 12.4493 4.25555 11.4778L3 10.2222" stroke="black" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M5.77777 10.2222H3V13" stroke="black" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 748 B |
Binary file not shown.
|
After Width: | Height: | Size: 4.3 MiB |
+13
@@ -0,0 +1,13 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="480" height="480" viewBox="0 0 480 480" fill="none"
|
||||||
|
stroke="currentColor" stroke-width="40" stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
class="lucide lucide-grip">
|
||||||
|
<circle cx="240" cy="240" r="50" stroke="#44403c" />
|
||||||
|
<circle cx="100" cy="100" r="20" stroke="#65a30d" />
|
||||||
|
<circle cx="240" cy="100" r="30" stroke="#dc2626" />
|
||||||
|
<circle cx="380" cy="100" r="20" stroke="#d97706" />
|
||||||
|
<circle cx="380" cy="240" r="30" stroke="#06b6d4" />
|
||||||
|
<circle cx="100" cy="240" r="30" stroke="#3b82f666" />
|
||||||
|
<circle cx="240" cy="380" r="30" stroke="#7c3aed" />
|
||||||
|
<circle cx="380" cy="380" r="20" stroke="#c026d3" />
|
||||||
|
<circle cx="100" cy="380" r="20" stroke="#e11d4866" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 746 B |
Binary file not shown.
|
After Width: | Height: | Size: 378 B |
+223
@@ -0,0 +1,223 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "../example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use gpui::{
|
||||||
|
App, AppContext, AssetSource, Bounds, Context, ImageSource, KeyBinding, Menu, MenuItem, Point,
|
||||||
|
SharedString, SharedUri, TitlebarOptions, Window, WindowBounds, WindowOptions, actions, div,
|
||||||
|
img, prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
use reqwest_client::ReqwestClient;
|
||||||
|
|
||||||
|
struct Assets {
|
||||||
|
base: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AssetSource for Assets {
|
||||||
|
fn load(&self, path: &str) -> Result<Option<std::borrow::Cow<'static, [u8]>>> {
|
||||||
|
fs::read(self.base.join(path))
|
||||||
|
.map(|data| Some(std::borrow::Cow::Owned(data)))
|
||||||
|
.map_err(|e| e.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
|
||||||
|
fs::read_dir(self.base.join(path))
|
||||||
|
.map(|entries| {
|
||||||
|
entries
|
||||||
|
.filter_map(|entry| {
|
||||||
|
entry
|
||||||
|
.ok()
|
||||||
|
.and_then(|entry| entry.file_name().into_string().ok())
|
||||||
|
.map(SharedString::from)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.map_err(|e| e.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(IntoElement)]
|
||||||
|
struct ImageContainer {
|
||||||
|
text: SharedString,
|
||||||
|
src: ImageSource,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImageContainer {
|
||||||
|
pub fn new(text: impl Into<SharedString>, src: impl Into<ImageSource>) -> Self {
|
||||||
|
Self {
|
||||||
|
text: text.into(),
|
||||||
|
src: src.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RenderOnce for ImageContainer {
|
||||||
|
fn render(self, _window: &mut Window, _: &mut App) -> impl IntoElement {
|
||||||
|
div().child(
|
||||||
|
div()
|
||||||
|
.flex_row()
|
||||||
|
.size_full()
|
||||||
|
.gap_4()
|
||||||
|
.child(self.text)
|
||||||
|
.child(img(self.src).size(px(256.0))),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ImageShowcase {
|
||||||
|
local_resource: Arc<std::path::Path>,
|
||||||
|
remote_resource: SharedUri,
|
||||||
|
asset_resource: SharedString,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for ImageShowcase {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.id("main")
|
||||||
|
.bg(gpui::white())
|
||||||
|
.overflow_y_scroll()
|
||||||
|
.p_5()
|
||||||
|
.size_full()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.gap_8()
|
||||||
|
.child(img(
|
||||||
|
"https://github.com/zed-industries/zed/actions/workflows/ci.yml/badge.svg",
|
||||||
|
))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.gap_8()
|
||||||
|
.child(ImageContainer::new(
|
||||||
|
"Image loaded from a local file with EXIF orientation",
|
||||||
|
self.local_resource.clone(),
|
||||||
|
))
|
||||||
|
.child(ImageContainer::new(
|
||||||
|
"Image loaded from a remote resource",
|
||||||
|
self.remote_resource.clone(),
|
||||||
|
))
|
||||||
|
.child(ImageContainer::new(
|
||||||
|
"Image loaded from an asset",
|
||||||
|
self.asset_resource.clone(),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.gap_8()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex_col()
|
||||||
|
.child("Auto Width")
|
||||||
|
.child(img("https://picsum.photos/800/400").h(px(180.))),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex_col()
|
||||||
|
.child("Auto Height")
|
||||||
|
.child(img("https://picsum.photos/800/400").w(px(180.))),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.w_full()
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(0xC0C0C0))
|
||||||
|
.child("image with max width 100%")
|
||||||
|
.child(img("https://picsum.photos/800/400").max_w_full()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actions!(image, [Quit]);
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
let app = gpui_platform::application();
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
let app = gpui_platform::application();
|
||||||
|
app.with_assets(Assets {
|
||||||
|
base: manifest_dir.join("examples"),
|
||||||
|
})
|
||||||
|
.run(move |cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
{
|
||||||
|
let http_client = ReqwestClient::user_agent("gpui example").unwrap();
|
||||||
|
cx.set_http_client(Arc::new(http_client));
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.activate(true);
|
||||||
|
cx.on_action(|_: &Quit, cx| cx.quit());
|
||||||
|
cx.bind_keys([KeyBinding::new("cmd-q", Quit, None)]);
|
||||||
|
cx.set_menus(vec![Menu {
|
||||||
|
name: "Image".into(),
|
||||||
|
items: vec![MenuItem::action("Quit", Quit)],
|
||||||
|
disabled: false,
|
||||||
|
}]);
|
||||||
|
|
||||||
|
let window_options = WindowOptions {
|
||||||
|
titlebar: Some(TitlebarOptions {
|
||||||
|
title: Some(SharedString::from("Image Example")),
|
||||||
|
appears_transparent: false,
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(Bounds {
|
||||||
|
size: size(px(1100.), px(600.)),
|
||||||
|
origin: Point::new(px(200.), px(200.)),
|
||||||
|
})),
|
||||||
|
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
cx.open_window(window_options, |_, cx| {
|
||||||
|
cx.new(|_| ImageShowcase {
|
||||||
|
// Relative path to your root project path
|
||||||
|
local_resource: manifest_dir
|
||||||
|
.join("examples/image/exif-orientation-rotate-180.jpg")
|
||||||
|
.into(),
|
||||||
|
remote_resource: "https://picsum.photos/800/400".into(),
|
||||||
|
asset_resource: "image/color.svg".into(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
env_logger::init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+299
@@ -0,0 +1,299 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, AppContext, Bounds, ClickEvent, Context, ElementId, Entity, ImageCache,
|
||||||
|
ImageCacheProvider, KeyBinding, Menu, MenuItem, RetainAllImageCache, SharedString,
|
||||||
|
TitlebarOptions, Window, WindowBounds, WindowOptions, actions, div, hash, image_cache, img,
|
||||||
|
prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
use reqwest_client::ReqwestClient;
|
||||||
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
|
const IMAGES_IN_GALLERY: usize = 30;
|
||||||
|
|
||||||
|
struct ImageGallery {
|
||||||
|
image_key: String,
|
||||||
|
items_count: usize,
|
||||||
|
total_count: usize,
|
||||||
|
image_cache: Entity<RetainAllImageCache>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImageGallery {
|
||||||
|
fn on_next_image(&mut self, _: &ClickEvent, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.image_cache
|
||||||
|
.update(cx, |image_cache, cx| image_cache.clear(window, cx));
|
||||||
|
|
||||||
|
let t = std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_millis();
|
||||||
|
|
||||||
|
self.image_key = format!("{}", t);
|
||||||
|
self.total_count += self.items_count;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for ImageGallery {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let image_url: SharedString =
|
||||||
|
format!("https://picsum.photos/400/200?t={}", self.image_key).into();
|
||||||
|
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.child("Manually managed image cache:")
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.image_cache(self.image_cache.clone())
|
||||||
|
.id("main")
|
||||||
|
.text_color(gpui::black())
|
||||||
|
.bg(rgb(0xE9E9E9))
|
||||||
|
.overflow_y_scroll()
|
||||||
|
.p_4()
|
||||||
|
.size_full()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.items_center()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.w_full()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.justify_between()
|
||||||
|
.child(format!(
|
||||||
|
"Example to show images and test memory usage (Rendered: {} images).",
|
||||||
|
self.total_count
|
||||||
|
))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("btn")
|
||||||
|
.py_1()
|
||||||
|
.px_4()
|
||||||
|
.bg(gpui::black())
|
||||||
|
.hover(|this| this.opacity(0.8))
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.text_center()
|
||||||
|
.w_40()
|
||||||
|
.child("Next Photos")
|
||||||
|
.on_click(cx.listener(Self::on_next_image)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("image-gallery")
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.flex_wrap()
|
||||||
|
.gap_x_4()
|
||||||
|
.gap_y_2()
|
||||||
|
.justify_around()
|
||||||
|
.children(
|
||||||
|
(0..self.items_count)
|
||||||
|
.map(|ix| img(format!("{}-{}", image_url, ix)).size_20()),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
"Automatically managed image cache:"
|
||||||
|
)
|
||||||
|
.child(image_cache(simple_lru_cache("lru-cache", IMAGES_IN_GALLERY)).child(
|
||||||
|
div()
|
||||||
|
.id("main")
|
||||||
|
.bg(rgb(0xE9E9E9))
|
||||||
|
.text_color(gpui::black())
|
||||||
|
.overflow_y_scroll()
|
||||||
|
.p_4()
|
||||||
|
.size_full()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.items_center()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("image-gallery")
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.flex_wrap()
|
||||||
|
.gap_x_4()
|
||||||
|
.gap_y_2()
|
||||||
|
.justify_around()
|
||||||
|
.children(
|
||||||
|
(0..self.items_count)
|
||||||
|
.map(|ix| img(format!("{}-{}", image_url, ix)).size_20()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn simple_lru_cache(id: impl Into<ElementId>, max_items: usize) -> SimpleLruCacheProvider {
|
||||||
|
SimpleLruCacheProvider {
|
||||||
|
id: id.into(),
|
||||||
|
max_items,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SimpleLruCacheProvider {
|
||||||
|
id: ElementId,
|
||||||
|
max_items: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImageCacheProvider for SimpleLruCacheProvider {
|
||||||
|
fn provide(&mut self, window: &mut Window, cx: &mut App) -> gpui::AnyImageCache {
|
||||||
|
window
|
||||||
|
.with_global_id(self.id.clone(), |global_id, window| {
|
||||||
|
window.with_element_state::<Entity<SimpleLruCache>, _>(
|
||||||
|
global_id,
|
||||||
|
|lru_cache, _window| {
|
||||||
|
let mut lru_cache = lru_cache.unwrap_or_else(|| {
|
||||||
|
cx.new(|cx| SimpleLruCache::new(self.max_items, cx))
|
||||||
|
});
|
||||||
|
if lru_cache.read(cx).max_items != self.max_items {
|
||||||
|
lru_cache = cx.new(|cx| SimpleLruCache::new(self.max_items, cx));
|
||||||
|
}
|
||||||
|
(lru_cache.clone(), lru_cache)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SimpleLruCache {
|
||||||
|
max_items: usize,
|
||||||
|
usages: Vec<u64>,
|
||||||
|
cache: HashMap<u64, gpui::ImageCacheItem>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SimpleLruCache {
|
||||||
|
fn new(max_items: usize, cx: &mut Context<Self>) -> Self {
|
||||||
|
cx.on_release(|simple_cache, cx| {
|
||||||
|
for (_, item) in std::mem::take(&mut simple_cache.cache) {
|
||||||
|
if let Some(Ok(image)) = item.get() {
|
||||||
|
cx.drop_image(image, None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
max_items,
|
||||||
|
usages: Vec::with_capacity(max_items),
|
||||||
|
cache: HashMap::with_capacity(max_items),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImageCache for SimpleLruCache {
|
||||||
|
fn load(
|
||||||
|
&mut self,
|
||||||
|
resource: &gpui::Resource,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut App,
|
||||||
|
) -> Option<Result<Arc<gpui::RenderImage>, gpui::ImageCacheError>> {
|
||||||
|
assert_eq!(self.usages.len(), self.cache.len());
|
||||||
|
assert!(self.cache.len() <= self.max_items);
|
||||||
|
|
||||||
|
let hash = hash(resource);
|
||||||
|
|
||||||
|
if let Some(item) = self.cache.get_mut(&hash) {
|
||||||
|
let current_ix = self
|
||||||
|
.usages
|
||||||
|
.iter()
|
||||||
|
.position(|item| *item == hash)
|
||||||
|
.expect("cache and usages must stay in sync");
|
||||||
|
self.usages.remove(current_ix);
|
||||||
|
self.usages.insert(0, hash);
|
||||||
|
|
||||||
|
return item.use_image(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.usages.len() == self.max_items {
|
||||||
|
let oldest = self.usages.pop().unwrap();
|
||||||
|
let image = self
|
||||||
|
.cache
|
||||||
|
.remove(&oldest)
|
||||||
|
.expect("cache and usages must be in sync");
|
||||||
|
if let Some(Ok(image)) = image.get() {
|
||||||
|
cx.drop_image(image, Some(window));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let item = gpui::ImageCacheItem::new(resource, cx);
|
||||||
|
let result = item.use_image(window);
|
||||||
|
self.cache.insert(hash, item);
|
||||||
|
self.usages.insert(0, hash);
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actions!(image, [Quit]);
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
let app = gpui_platform::application();
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
let app = gpui_platform::single_threaded_web();
|
||||||
|
|
||||||
|
app.run(move |cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
{
|
||||||
|
let http_client = ReqwestClient::user_agent("gpui example").unwrap();
|
||||||
|
cx.set_http_client(Arc::new(http_client));
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.activate(true);
|
||||||
|
cx.on_action(|_: &Quit, cx| cx.quit());
|
||||||
|
cx.bind_keys([KeyBinding::new("cmd-q", Quit, None)]);
|
||||||
|
cx.set_menus([Menu::new("Image Gallery").items([MenuItem::action("Quit", Quit)])]);
|
||||||
|
|
||||||
|
let window_options = WindowOptions {
|
||||||
|
titlebar: Some(TitlebarOptions {
|
||||||
|
title: Some(SharedString::from("Image Gallery")),
|
||||||
|
appears_transparent: false,
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
|
||||||
|
None,
|
||||||
|
size(px(1100.), px(860.)),
|
||||||
|
cx,
|
||||||
|
))),
|
||||||
|
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
cx.open_window(window_options, |_, cx| {
|
||||||
|
cx.new(|ctx| ImageGallery {
|
||||||
|
image_key: "".into(),
|
||||||
|
items_count: IMAGES_IN_GALLERY,
|
||||||
|
total_count: 0,
|
||||||
|
image_cache: RetainAllImageCache::new(ctx),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
env_logger::init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+232
@@ -0,0 +1,232 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use std::{path::Path, sync::Arc, time::Duration};
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
Animation, AnimationExt, App, Asset, AssetLogger, AssetSource, Bounds, Context, Hsla,
|
||||||
|
ImageAssetLoader, ImageCacheError, ImgResourceLoader, LOADING_DELAY, Length, RenderImage,
|
||||||
|
Resource, SharedString, Window, WindowBounds, WindowOptions, black, div, img, prelude::*,
|
||||||
|
pulsating_between, px, red, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct Assets {}
|
||||||
|
|
||||||
|
impl AssetSource for Assets {
|
||||||
|
fn load(&self, path: &str) -> anyhow::Result<Option<std::borrow::Cow<'static, [u8]>>> {
|
||||||
|
std::fs::read(path)
|
||||||
|
.map(Into::into)
|
||||||
|
.map_err(Into::into)
|
||||||
|
.map(Some)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn list(&self, path: &str) -> anyhow::Result<Vec<SharedString>> {
|
||||||
|
Ok(std::fs::read_dir(path)?
|
||||||
|
.filter_map(|entry| {
|
||||||
|
Some(SharedString::from(
|
||||||
|
entry.ok()?.path().to_string_lossy().into_owned(),
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const IMAGE: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/image/app-icon.png");
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Hash)]
|
||||||
|
struct LoadImageParameters {
|
||||||
|
timeout: Duration,
|
||||||
|
fail: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct LoadImageWithParameters {}
|
||||||
|
|
||||||
|
impl Asset for LoadImageWithParameters {
|
||||||
|
type Source = LoadImageParameters;
|
||||||
|
|
||||||
|
type Output = Result<Arc<RenderImage>, ImageCacheError>;
|
||||||
|
|
||||||
|
fn load(
|
||||||
|
parameters: Self::Source,
|
||||||
|
cx: &mut App,
|
||||||
|
) -> impl std::future::Future<Output = Self::Output> + Send + 'static {
|
||||||
|
let timer = cx.background_executor().timer(parameters.timeout);
|
||||||
|
let data = AssetLogger::<ImageAssetLoader>::load(
|
||||||
|
Resource::Path(Path::new(IMAGE).to_path_buf().into()),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
async move {
|
||||||
|
timer.await;
|
||||||
|
if parameters.fail {
|
||||||
|
log::error!("Intentionally failed to load image");
|
||||||
|
Err(anyhow::anyhow!("Failed to load image").into())
|
||||||
|
} else {
|
||||||
|
data.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ImageLoadingExample {}
|
||||||
|
|
||||||
|
impl ImageLoadingExample {
|
||||||
|
fn loading_element() -> impl IntoElement {
|
||||||
|
div().size_full().flex_none().p_0p5().rounded_xs().child(
|
||||||
|
div().size_full().with_animation(
|
||||||
|
"loading-bg",
|
||||||
|
Animation::new(Duration::from_secs(3))
|
||||||
|
.repeat()
|
||||||
|
.with_easing(pulsating_between(0.04, 0.24)),
|
||||||
|
move |this, delta| this.bg(black().opacity(delta)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fallback_element() -> impl IntoElement {
|
||||||
|
let fallback_color: Hsla = black().opacity(0.5);
|
||||||
|
|
||||||
|
div().size_full().flex_none().p_0p5().child(
|
||||||
|
div()
|
||||||
|
.size_full()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.rounded_xs()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(fallback_color)
|
||||||
|
.border_1()
|
||||||
|
.border_color(fallback_color)
|
||||||
|
.child("?"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for ImageLoadingExample {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div().flex().flex_col().size_full().justify_around().child(
|
||||||
|
div().flex().flex_row().w_full().justify_around().child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.size(Length::Definite(px(300.0).into()))
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.child({
|
||||||
|
let image_source = LoadImageParameters {
|
||||||
|
timeout: LOADING_DELAY.saturating_sub(Duration::from_millis(25)),
|
||||||
|
fail: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Load within the 'loading delay', should not show loading fallback
|
||||||
|
img(move |window: &mut Window, cx: &mut App| {
|
||||||
|
window.use_asset::<LoadImageWithParameters>(&image_source, cx)
|
||||||
|
})
|
||||||
|
.id("image-1")
|
||||||
|
.border_1()
|
||||||
|
.size_12()
|
||||||
|
.with_fallback(|| Self::fallback_element().into_any_element())
|
||||||
|
.border_color(red())
|
||||||
|
.with_loading(|| Self::loading_element().into_any_element())
|
||||||
|
.on_click(move |_, _, cx| {
|
||||||
|
cx.remove_asset::<LoadImageWithParameters>(&image_source);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.child({
|
||||||
|
// Load after a long delay
|
||||||
|
let image_source = LoadImageParameters {
|
||||||
|
timeout: Duration::from_secs(5),
|
||||||
|
fail: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
img(move |window: &mut Window, cx: &mut App| {
|
||||||
|
window.use_asset::<LoadImageWithParameters>(&image_source, cx)
|
||||||
|
})
|
||||||
|
.id("image-2")
|
||||||
|
.with_fallback(|| Self::fallback_element().into_any_element())
|
||||||
|
.with_loading(|| Self::loading_element().into_any_element())
|
||||||
|
.size_12()
|
||||||
|
.border_1()
|
||||||
|
.border_color(red())
|
||||||
|
.on_click(move |_, _, cx| {
|
||||||
|
cx.remove_asset::<LoadImageWithParameters>(&image_source);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.child({
|
||||||
|
// Fail to load image after a long delay
|
||||||
|
let image_source = LoadImageParameters {
|
||||||
|
timeout: Duration::from_secs(5),
|
||||||
|
fail: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fail to load after a long delay
|
||||||
|
img(move |window: &mut Window, cx: &mut App| {
|
||||||
|
window.use_asset::<LoadImageWithParameters>(&image_source, cx)
|
||||||
|
})
|
||||||
|
.id("image-3")
|
||||||
|
.with_fallback(|| Self::fallback_element().into_any_element())
|
||||||
|
.with_loading(|| Self::loading_element().into_any_element())
|
||||||
|
.size_12()
|
||||||
|
.border_1()
|
||||||
|
.border_color(red())
|
||||||
|
.on_click(move |_, _, cx| {
|
||||||
|
cx.remove_asset::<LoadImageWithParameters>(&image_source);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.child({
|
||||||
|
// Ensure that the normal image loader doesn't spam logs
|
||||||
|
let image_source = Path::new(
|
||||||
|
"this/file/really/shouldn't/exist/or/won't/be/an/image/I/hope",
|
||||||
|
)
|
||||||
|
.to_path_buf();
|
||||||
|
img(image_source.clone())
|
||||||
|
.id("image-4")
|
||||||
|
.border_1()
|
||||||
|
.size_12()
|
||||||
|
.with_fallback(|| Self::fallback_element().into_any_element())
|
||||||
|
.border_color(red())
|
||||||
|
.with_loading(|| Self::loading_element().into_any_element())
|
||||||
|
.on_click(move |_, _, cx| {
|
||||||
|
cx.remove_asset::<ImgResourceLoader>(&image_source.clone().into());
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().with_assets(Assets {}).run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let options = WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
|
||||||
|
None,
|
||||||
|
size(px(300.), px(300.)),
|
||||||
|
cx,
|
||||||
|
))),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
cx.open_window(options, |_, cx| {
|
||||||
|
cx.activate(false);
|
||||||
|
cx.new(|_| ImageLoadingExample {})
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
env_logger::init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
Vendored
+784
@@ -0,0 +1,784 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use std::ops::Range;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, ClipboardItem, Context, CursorStyle, ElementId, ElementInputHandler, Entity,
|
||||||
|
EntityInputHandler, FocusHandle, Focusable, GlobalElementId, KeyBinding, Keystroke, LayoutId,
|
||||||
|
MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PaintQuad, Pixels, Point,
|
||||||
|
ShapedLine, SharedString, Style, TextRun, UTF16Selection, UnderlineStyle, Window, WindowBounds,
|
||||||
|
WindowOptions, actions, black, div, fill, hsla, opaque_grey, point, prelude::*, px, relative,
|
||||||
|
rgb, rgba, size, white, yellow,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
use unicode_segmentation::*;
|
||||||
|
|
||||||
|
actions!(
|
||||||
|
text_input,
|
||||||
|
[
|
||||||
|
Backspace,
|
||||||
|
Delete,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
SelectLeft,
|
||||||
|
SelectRight,
|
||||||
|
SelectAll,
|
||||||
|
Home,
|
||||||
|
End,
|
||||||
|
ShowCharacterPalette,
|
||||||
|
Paste,
|
||||||
|
Cut,
|
||||||
|
Copy,
|
||||||
|
Quit,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
struct TextInput {
|
||||||
|
focus_handle: FocusHandle,
|
||||||
|
content: SharedString,
|
||||||
|
placeholder: SharedString,
|
||||||
|
selected_range: Range<usize>,
|
||||||
|
selection_reversed: bool,
|
||||||
|
marked_range: Option<Range<usize>>,
|
||||||
|
last_layout: Option<ShapedLine>,
|
||||||
|
last_bounds: Option<Bounds<Pixels>>,
|
||||||
|
is_selecting: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextInput {
|
||||||
|
fn left(&mut self, _: &Left, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if self.selected_range.is_empty() {
|
||||||
|
self.move_to(self.previous_boundary(self.cursor_offset()), cx);
|
||||||
|
} else {
|
||||||
|
self.move_to(self.selected_range.start, cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn right(&mut self, _: &Right, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if self.selected_range.is_empty() {
|
||||||
|
self.move_to(self.next_boundary(self.selected_range.end), cx);
|
||||||
|
} else {
|
||||||
|
self.move_to(self.selected_range.end, cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn select_left(&mut self, _: &SelectLeft, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.select_to(self.previous_boundary(self.cursor_offset()), cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn select_right(&mut self, _: &SelectRight, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.select_to(self.next_boundary(self.cursor_offset()), cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn select_all(&mut self, _: &SelectAll, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.move_to(0, cx);
|
||||||
|
self.select_to(self.content.len(), cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn home(&mut self, _: &Home, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.move_to(0, cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end(&mut self, _: &End, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.move_to(self.content.len(), cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn backspace(&mut self, _: &Backspace, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if self.selected_range.is_empty() {
|
||||||
|
let prev = self.previous_boundary(self.cursor_offset());
|
||||||
|
if self.cursor_offset() == prev {
|
||||||
|
window.play_system_bell();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.select_to(prev, cx)
|
||||||
|
}
|
||||||
|
self.replace_text_in_range(None, "", window, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete(&mut self, _: &Delete, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if self.selected_range.is_empty() {
|
||||||
|
let next = self.next_boundary(self.cursor_offset());
|
||||||
|
if self.cursor_offset() == next {
|
||||||
|
window.play_system_bell();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.select_to(next, cx)
|
||||||
|
}
|
||||||
|
self.replace_text_in_range(None, "", window, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_mouse_down(
|
||||||
|
&mut self,
|
||||||
|
event: &MouseDownEvent,
|
||||||
|
_window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
self.is_selecting = true;
|
||||||
|
|
||||||
|
if event.modifiers.shift {
|
||||||
|
self.select_to(self.index_for_mouse_position(event.position), cx);
|
||||||
|
} else {
|
||||||
|
self.move_to(self.index_for_mouse_position(event.position), cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_mouse_up(&mut self, _: &MouseUpEvent, _window: &mut Window, _: &mut Context<Self>) {
|
||||||
|
self.is_selecting = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_mouse_move(&mut self, event: &MouseMoveEvent, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if self.is_selecting {
|
||||||
|
self.select_to(self.index_for_mouse_position(event.position), cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn show_character_palette(
|
||||||
|
&mut self,
|
||||||
|
_: &ShowCharacterPalette,
|
||||||
|
window: &mut Window,
|
||||||
|
_: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
window.show_character_palette();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn paste(&mut self, _: &Paste, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if let Some(text) = cx.read_from_clipboard().and_then(|item| item.text()) {
|
||||||
|
self.replace_text_in_range(None, &text.replace("\n", " "), window, cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn copy(&mut self, _: &Copy, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if !self.selected_range.is_empty() {
|
||||||
|
cx.write_to_clipboard(ClipboardItem::new_string(
|
||||||
|
self.content[self.selected_range.clone()].to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn cut(&mut self, _: &Cut, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if !self.selected_range.is_empty() {
|
||||||
|
cx.write_to_clipboard(ClipboardItem::new_string(
|
||||||
|
self.content[self.selected_range.clone()].to_string(),
|
||||||
|
));
|
||||||
|
self.replace_text_in_range(None, "", window, cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_to(&mut self, offset: usize, cx: &mut Context<Self>) {
|
||||||
|
self.selected_range = offset..offset;
|
||||||
|
cx.notify()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cursor_offset(&self) -> usize {
|
||||||
|
if self.selection_reversed {
|
||||||
|
self.selected_range.start
|
||||||
|
} else {
|
||||||
|
self.selected_range.end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn index_for_mouse_position(&self, position: Point<Pixels>) -> usize {
|
||||||
|
if self.content.is_empty() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let (Some(bounds), Some(line)) = (self.last_bounds.as_ref(), self.last_layout.as_ref())
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
if position.y < bounds.top() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if position.y > bounds.bottom() {
|
||||||
|
return self.content.len();
|
||||||
|
}
|
||||||
|
line.closest_index_for_x(position.x - bounds.left())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn select_to(&mut self, offset: usize, cx: &mut Context<Self>) {
|
||||||
|
if self.selection_reversed {
|
||||||
|
self.selected_range.start = offset
|
||||||
|
} else {
|
||||||
|
self.selected_range.end = offset
|
||||||
|
};
|
||||||
|
if self.selected_range.end < self.selected_range.start {
|
||||||
|
self.selection_reversed = !self.selection_reversed;
|
||||||
|
self.selected_range = self.selected_range.end..self.selected_range.start;
|
||||||
|
}
|
||||||
|
cx.notify()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn offset_from_utf16(&self, offset: usize) -> usize {
|
||||||
|
let mut utf8_offset = 0;
|
||||||
|
let mut utf16_count = 0;
|
||||||
|
|
||||||
|
for ch in self.content.chars() {
|
||||||
|
if utf16_count >= offset {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
utf16_count += ch.len_utf16();
|
||||||
|
utf8_offset += ch.len_utf8();
|
||||||
|
}
|
||||||
|
|
||||||
|
utf8_offset
|
||||||
|
}
|
||||||
|
|
||||||
|
fn offset_to_utf16(&self, offset: usize) -> usize {
|
||||||
|
let mut utf16_offset = 0;
|
||||||
|
let mut utf8_count = 0;
|
||||||
|
|
||||||
|
for ch in self.content.chars() {
|
||||||
|
if utf8_count >= offset {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
utf8_count += ch.len_utf8();
|
||||||
|
utf16_offset += ch.len_utf16();
|
||||||
|
}
|
||||||
|
|
||||||
|
utf16_offset
|
||||||
|
}
|
||||||
|
|
||||||
|
fn range_to_utf16(&self, range: &Range<usize>) -> Range<usize> {
|
||||||
|
self.offset_to_utf16(range.start)..self.offset_to_utf16(range.end)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn range_from_utf16(&self, range_utf16: &Range<usize>) -> Range<usize> {
|
||||||
|
self.offset_from_utf16(range_utf16.start)..self.offset_from_utf16(range_utf16.end)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn previous_boundary(&self, offset: usize) -> usize {
|
||||||
|
self.content
|
||||||
|
.grapheme_indices(true)
|
||||||
|
.rev()
|
||||||
|
.find_map(|(idx, _)| (idx < offset).then_some(idx))
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_boundary(&self, offset: usize) -> usize {
|
||||||
|
self.content
|
||||||
|
.grapheme_indices(true)
|
||||||
|
.find_map(|(idx, _)| (idx > offset).then_some(idx))
|
||||||
|
.unwrap_or(self.content.len())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reset(&mut self) {
|
||||||
|
self.content = "".into();
|
||||||
|
self.selected_range = 0..0;
|
||||||
|
self.selection_reversed = false;
|
||||||
|
self.marked_range = None;
|
||||||
|
self.last_layout = None;
|
||||||
|
self.last_bounds = None;
|
||||||
|
self.is_selecting = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EntityInputHandler for TextInput {
|
||||||
|
fn text_for_range(
|
||||||
|
&mut self,
|
||||||
|
range_utf16: Range<usize>,
|
||||||
|
actual_range: &mut Option<Range<usize>>,
|
||||||
|
_window: &mut Window,
|
||||||
|
_cx: &mut Context<Self>,
|
||||||
|
) -> Option<String> {
|
||||||
|
let range = self.range_from_utf16(&range_utf16);
|
||||||
|
actual_range.replace(self.range_to_utf16(&range));
|
||||||
|
Some(self.content[range].to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn selected_text_range(
|
||||||
|
&mut self,
|
||||||
|
_ignore_disabled_input: bool,
|
||||||
|
_window: &mut Window,
|
||||||
|
_cx: &mut Context<Self>,
|
||||||
|
) -> Option<UTF16Selection> {
|
||||||
|
Some(UTF16Selection {
|
||||||
|
range: self.range_to_utf16(&self.selected_range),
|
||||||
|
reversed: self.selection_reversed,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn marked_text_range(
|
||||||
|
&self,
|
||||||
|
_window: &mut Window,
|
||||||
|
_cx: &mut Context<Self>,
|
||||||
|
) -> Option<Range<usize>> {
|
||||||
|
self.marked_range
|
||||||
|
.as_ref()
|
||||||
|
.map(|range| self.range_to_utf16(range))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unmark_text(&mut self, _window: &mut Window, _cx: &mut Context<Self>) {
|
||||||
|
self.marked_range = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn replace_text_in_range(
|
||||||
|
&mut self,
|
||||||
|
range_utf16: Option<Range<usize>>,
|
||||||
|
new_text: &str,
|
||||||
|
_: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
let range = range_utf16
|
||||||
|
.as_ref()
|
||||||
|
.map(|range_utf16| self.range_from_utf16(range_utf16))
|
||||||
|
.or(self.marked_range.clone())
|
||||||
|
.unwrap_or(self.selected_range.clone());
|
||||||
|
|
||||||
|
self.content =
|
||||||
|
(self.content[0..range.start].to_owned() + new_text + &self.content[range.end..])
|
||||||
|
.into();
|
||||||
|
self.selected_range = range.start + new_text.len()..range.start + new_text.len();
|
||||||
|
self.marked_range.take();
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn replace_and_mark_text_in_range(
|
||||||
|
&mut self,
|
||||||
|
range_utf16: Option<Range<usize>>,
|
||||||
|
new_text: &str,
|
||||||
|
new_selected_range_utf16: Option<Range<usize>>,
|
||||||
|
_window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
let range = range_utf16
|
||||||
|
.as_ref()
|
||||||
|
.map(|range_utf16| self.range_from_utf16(range_utf16))
|
||||||
|
.or(self.marked_range.clone())
|
||||||
|
.unwrap_or(self.selected_range.clone());
|
||||||
|
|
||||||
|
self.content =
|
||||||
|
(self.content[0..range.start].to_owned() + new_text + &self.content[range.end..])
|
||||||
|
.into();
|
||||||
|
if !new_text.is_empty() {
|
||||||
|
self.marked_range = Some(range.start..range.start + new_text.len());
|
||||||
|
} else {
|
||||||
|
self.marked_range = None;
|
||||||
|
}
|
||||||
|
self.selected_range = new_selected_range_utf16
|
||||||
|
.as_ref()
|
||||||
|
.map(|range_utf16| self.range_from_utf16(range_utf16))
|
||||||
|
.map(|new_range| new_range.start + range.start..new_range.end + range.end)
|
||||||
|
.unwrap_or_else(|| range.start + new_text.len()..range.start + new_text.len());
|
||||||
|
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bounds_for_range(
|
||||||
|
&mut self,
|
||||||
|
range_utf16: Range<usize>,
|
||||||
|
bounds: Bounds<Pixels>,
|
||||||
|
_window: &mut Window,
|
||||||
|
_cx: &mut Context<Self>,
|
||||||
|
) -> Option<Bounds<Pixels>> {
|
||||||
|
let last_layout = self.last_layout.as_ref()?;
|
||||||
|
let range = self.range_from_utf16(&range_utf16);
|
||||||
|
Some(Bounds::from_corners(
|
||||||
|
point(
|
||||||
|
bounds.left() + last_layout.x_for_index(range.start),
|
||||||
|
bounds.top(),
|
||||||
|
),
|
||||||
|
point(
|
||||||
|
bounds.left() + last_layout.x_for_index(range.end),
|
||||||
|
bounds.bottom(),
|
||||||
|
),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn character_index_for_point(
|
||||||
|
&mut self,
|
||||||
|
point: gpui::Point<Pixels>,
|
||||||
|
_window: &mut Window,
|
||||||
|
_cx: &mut Context<Self>,
|
||||||
|
) -> Option<usize> {
|
||||||
|
let line_point = self.last_bounds?.localize(&point)?;
|
||||||
|
let last_layout = self.last_layout.as_ref()?;
|
||||||
|
|
||||||
|
assert_eq!(last_layout.text, self.content);
|
||||||
|
let utf8_index = last_layout.index_for_x(point.x - line_point.x)?;
|
||||||
|
Some(self.offset_to_utf16(utf8_index))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TextElement {
|
||||||
|
input: Entity<TextInput>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PrepaintState {
|
||||||
|
line: Option<ShapedLine>,
|
||||||
|
cursor: Option<PaintQuad>,
|
||||||
|
selection: Option<PaintQuad>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoElement for TextElement {
|
||||||
|
type Element = Self;
|
||||||
|
|
||||||
|
fn into_element(self) -> Self::Element {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Element for TextElement {
|
||||||
|
type RequestLayoutState = ();
|
||||||
|
type PrepaintState = PrepaintState;
|
||||||
|
|
||||||
|
fn id(&self) -> Option<ElementId> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn source_location(&self) -> Option<&'static core::panic::Location<'static>> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn request_layout(
|
||||||
|
&mut self,
|
||||||
|
_id: Option<&GlobalElementId>,
|
||||||
|
_inspector_id: Option<&gpui::InspectorElementId>,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut App,
|
||||||
|
) -> (LayoutId, Self::RequestLayoutState) {
|
||||||
|
let mut style = Style::default();
|
||||||
|
style.size.width = relative(1.).into();
|
||||||
|
style.size.height = window.line_height().into();
|
||||||
|
(window.request_layout(style, [], cx), ())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prepaint(
|
||||||
|
&mut self,
|
||||||
|
_id: Option<&GlobalElementId>,
|
||||||
|
_inspector_id: Option<&gpui::InspectorElementId>,
|
||||||
|
bounds: Bounds<Pixels>,
|
||||||
|
_request_layout: &mut Self::RequestLayoutState,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut App,
|
||||||
|
) -> Self::PrepaintState {
|
||||||
|
let input = self.input.read(cx);
|
||||||
|
let content = input.content.clone();
|
||||||
|
let selected_range = input.selected_range.clone();
|
||||||
|
let cursor = input.cursor_offset();
|
||||||
|
let style = window.text_style();
|
||||||
|
|
||||||
|
let (display_text, text_color) = if content.is_empty() {
|
||||||
|
(input.placeholder.clone(), hsla(0., 0., 0., 0.2))
|
||||||
|
} else {
|
||||||
|
(content, style.color)
|
||||||
|
};
|
||||||
|
|
||||||
|
let run = TextRun {
|
||||||
|
len: display_text.len(),
|
||||||
|
font: style.font(),
|
||||||
|
color: text_color,
|
||||||
|
background_color: None,
|
||||||
|
underline: None,
|
||||||
|
strikethrough: None,
|
||||||
|
};
|
||||||
|
let runs = if let Some(marked_range) = input.marked_range.as_ref() {
|
||||||
|
vec![
|
||||||
|
TextRun {
|
||||||
|
len: marked_range.start,
|
||||||
|
..run.clone()
|
||||||
|
},
|
||||||
|
TextRun {
|
||||||
|
len: marked_range.end - marked_range.start,
|
||||||
|
underline: Some(UnderlineStyle {
|
||||||
|
color: Some(run.color),
|
||||||
|
thickness: px(1.0),
|
||||||
|
wavy: false,
|
||||||
|
}),
|
||||||
|
..run.clone()
|
||||||
|
},
|
||||||
|
TextRun {
|
||||||
|
len: display_text.len() - marked_range.end,
|
||||||
|
..run
|
||||||
|
},
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.filter(|run| run.len > 0)
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
vec![run]
|
||||||
|
};
|
||||||
|
|
||||||
|
let font_size = style.font_size.to_pixels(window.rem_size());
|
||||||
|
let line = window
|
||||||
|
.text_system()
|
||||||
|
.shape_line(display_text, font_size, &runs, None);
|
||||||
|
|
||||||
|
let cursor_pos = line.x_for_index(cursor);
|
||||||
|
let (selection, cursor) = if selected_range.is_empty() {
|
||||||
|
(
|
||||||
|
None,
|
||||||
|
Some(fill(
|
||||||
|
Bounds::new(
|
||||||
|
point(bounds.left() + cursor_pos, bounds.top()),
|
||||||
|
size(px(2.), bounds.bottom() - bounds.top()),
|
||||||
|
),
|
||||||
|
gpui::blue(),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
(
|
||||||
|
Some(fill(
|
||||||
|
Bounds::from_corners(
|
||||||
|
point(
|
||||||
|
bounds.left() + line.x_for_index(selected_range.start),
|
||||||
|
bounds.top(),
|
||||||
|
),
|
||||||
|
point(
|
||||||
|
bounds.left() + line.x_for_index(selected_range.end),
|
||||||
|
bounds.bottom(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
rgba(0x3311ff30),
|
||||||
|
)),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
PrepaintState {
|
||||||
|
line: Some(line),
|
||||||
|
cursor,
|
||||||
|
selection,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn paint(
|
||||||
|
&mut self,
|
||||||
|
_id: Option<&GlobalElementId>,
|
||||||
|
_inspector_id: Option<&gpui::InspectorElementId>,
|
||||||
|
bounds: Bounds<Pixels>,
|
||||||
|
_request_layout: &mut Self::RequestLayoutState,
|
||||||
|
prepaint: &mut Self::PrepaintState,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut App,
|
||||||
|
) {
|
||||||
|
let focus_handle = self.input.read(cx).focus_handle.clone();
|
||||||
|
window.handle_input(
|
||||||
|
&focus_handle,
|
||||||
|
ElementInputHandler::new(bounds, self.input.clone()),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
if let Some(selection) = prepaint.selection.take() {
|
||||||
|
window.paint_quad(selection)
|
||||||
|
}
|
||||||
|
let line = prepaint.line.take().unwrap();
|
||||||
|
line.paint(
|
||||||
|
bounds.origin,
|
||||||
|
window.line_height(),
|
||||||
|
gpui::TextAlign::Left,
|
||||||
|
None,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if focus_handle.is_focused(window)
|
||||||
|
&& let Some(cursor) = prepaint.cursor.take()
|
||||||
|
{
|
||||||
|
window.paint_quad(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.input.update(cx, |input, _cx| {
|
||||||
|
input.last_layout = Some(line);
|
||||||
|
input.last_bounds = Some(bounds);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for TextInput {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.key_context("TextInput")
|
||||||
|
.track_focus(&self.focus_handle(cx))
|
||||||
|
.cursor(CursorStyle::IBeam)
|
||||||
|
.on_action(cx.listener(Self::backspace))
|
||||||
|
.on_action(cx.listener(Self::delete))
|
||||||
|
.on_action(cx.listener(Self::left))
|
||||||
|
.on_action(cx.listener(Self::right))
|
||||||
|
.on_action(cx.listener(Self::select_left))
|
||||||
|
.on_action(cx.listener(Self::select_right))
|
||||||
|
.on_action(cx.listener(Self::select_all))
|
||||||
|
.on_action(cx.listener(Self::home))
|
||||||
|
.on_action(cx.listener(Self::end))
|
||||||
|
.on_action(cx.listener(Self::show_character_palette))
|
||||||
|
.on_action(cx.listener(Self::paste))
|
||||||
|
.on_action(cx.listener(Self::cut))
|
||||||
|
.on_action(cx.listener(Self::copy))
|
||||||
|
.on_mouse_down(MouseButton::Left, cx.listener(Self::on_mouse_down))
|
||||||
|
.on_mouse_up(MouseButton::Left, cx.listener(Self::on_mouse_up))
|
||||||
|
.on_mouse_up_out(MouseButton::Left, cx.listener(Self::on_mouse_up))
|
||||||
|
.on_mouse_move(cx.listener(Self::on_mouse_move))
|
||||||
|
.bg(rgb(0xeeeeee))
|
||||||
|
.line_height(px(30.))
|
||||||
|
.text_size(px(24.))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.h(px(30. + 4. * 2.))
|
||||||
|
.w_full()
|
||||||
|
.p(px(4.))
|
||||||
|
.bg(white())
|
||||||
|
.child(TextElement { input: cx.entity() }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Focusable for TextInput {
|
||||||
|
fn focus_handle(&self, _: &App) -> FocusHandle {
|
||||||
|
self.focus_handle.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct InputExample {
|
||||||
|
text_input: Entity<TextInput>,
|
||||||
|
recent_keystrokes: Vec<Keystroke>,
|
||||||
|
focus_handle: FocusHandle,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Focusable for InputExample {
|
||||||
|
fn focus_handle(&self, _: &App) -> FocusHandle {
|
||||||
|
self.focus_handle.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InputExample {
|
||||||
|
fn on_reset_click(&mut self, _: &MouseUpEvent, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.recent_keystrokes.clear();
|
||||||
|
self.text_input
|
||||||
|
.update(cx, |text_input, _cx| text_input.reset());
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for InputExample {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.bg(rgb(0xaaaaaa))
|
||||||
|
.track_focus(&self.focus_handle(cx))
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.size_full()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.bg(white())
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(black())
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.justify_between()
|
||||||
|
.child(format!("Keyboard {}", cx.keyboard_layout().name()))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.border_1()
|
||||||
|
.border_color(black())
|
||||||
|
.px_2()
|
||||||
|
.bg(yellow())
|
||||||
|
.child("Reset")
|
||||||
|
.hover(|style| {
|
||||||
|
style
|
||||||
|
.bg(yellow().blend(opaque_grey(0.5, 0.5)))
|
||||||
|
.cursor_pointer()
|
||||||
|
})
|
||||||
|
.on_mouse_up(MouseButton::Left, cx.listener(Self::on_reset_click)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(self.text_input.clone())
|
||||||
|
.children(self.recent_keystrokes.iter().rev().map(|ks| {
|
||||||
|
format!(
|
||||||
|
"{:} {}",
|
||||||
|
ks.unparse(),
|
||||||
|
if let Some(key_char) = ks.key_char.as_ref() {
|
||||||
|
format!("-> {:?}", key_char)
|
||||||
|
} else {
|
||||||
|
"".to_owned()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(300.0), px(300.0)), cx);
|
||||||
|
cx.bind_keys([
|
||||||
|
KeyBinding::new("backspace", Backspace, None),
|
||||||
|
KeyBinding::new("delete", Delete, None),
|
||||||
|
KeyBinding::new("left", Left, None),
|
||||||
|
KeyBinding::new("right", Right, None),
|
||||||
|
KeyBinding::new("shift-left", SelectLeft, None),
|
||||||
|
KeyBinding::new("shift-right", SelectRight, None),
|
||||||
|
KeyBinding::new("cmd-a", SelectAll, None),
|
||||||
|
KeyBinding::new("cmd-v", Paste, None),
|
||||||
|
KeyBinding::new("cmd-c", Copy, None),
|
||||||
|
KeyBinding::new("cmd-x", Cut, None),
|
||||||
|
KeyBinding::new("home", Home, None),
|
||||||
|
KeyBinding::new("end", End, None),
|
||||||
|
KeyBinding::new("ctrl-cmd-space", ShowCharacterPalette, None),
|
||||||
|
]);
|
||||||
|
|
||||||
|
let window = cx
|
||||||
|
.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| {
|
||||||
|
let text_input = cx.new(|cx| TextInput {
|
||||||
|
focus_handle: cx.focus_handle(),
|
||||||
|
content: "".into(),
|
||||||
|
placeholder: "Type here...".into(),
|
||||||
|
selected_range: 0..0,
|
||||||
|
selection_reversed: false,
|
||||||
|
marked_range: None,
|
||||||
|
last_layout: None,
|
||||||
|
last_bounds: None,
|
||||||
|
is_selecting: false,
|
||||||
|
});
|
||||||
|
cx.new(|cx| InputExample {
|
||||||
|
text_input,
|
||||||
|
recent_keystrokes: vec![],
|
||||||
|
focus_handle: cx.focus_handle(),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let view = window.update(cx, |_, _, cx| cx.entity()).unwrap();
|
||||||
|
cx.observe_keystrokes(move |ev, _, cx| {
|
||||||
|
view.update(cx, |view, cx| {
|
||||||
|
view.recent_keystrokes.push(ev.keystroke.clone());
|
||||||
|
cx.notify();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
cx.on_keyboard_layout_change({
|
||||||
|
move |cx| {
|
||||||
|
window.update(cx, |_, _, cx| cx.notify()).ok();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
window
|
||||||
|
.update(cx, |view, window, cx| {
|
||||||
|
window.focus(&view.text_input.focus_handle(cx), cx);
|
||||||
|
cx.activate(true);
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
cx.on_action(|_: &Quit, cx| cx.quit());
|
||||||
|
cx.bind_keys([KeyBinding::new("cmd-q", Quit, None)]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+101
@@ -0,0 +1,101 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
#[cfg(all(target_os = "linux", feature = "wayland"))]
|
||||||
|
example::main();
|
||||||
|
|
||||||
|
#[cfg(not(all(target_os = "linux", feature = "wayland")))]
|
||||||
|
panic!("This example requires the `wayland` feature and a linux system.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(target_os = "linux", feature = "wayland"))]
|
||||||
|
mod example {
|
||||||
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, FontWeight, Size, Window, WindowBackgroundAppearance, WindowBounds,
|
||||||
|
WindowKind, WindowOptions, div, layer_shell::*, point, prelude::*, px, rems, rgba, white,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct LayerShellExample;
|
||||||
|
|
||||||
|
impl LayerShellExample {
|
||||||
|
fn new(cx: &mut Context<Self>) -> Self {
|
||||||
|
cx.spawn(async move |this, cx| {
|
||||||
|
loop {
|
||||||
|
let _ = this.update(cx, |_, cx| cx.notify());
|
||||||
|
cx.background_executor()
|
||||||
|
.timer(Duration::from_millis(500))
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
LayerShellExample
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for LayerShellExample {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let now = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs();
|
||||||
|
|
||||||
|
let hours = (now / 3600) % 24;
|
||||||
|
let minutes = (now / 60) % 60;
|
||||||
|
let seconds = now % 60;
|
||||||
|
|
||||||
|
div()
|
||||||
|
.size_full()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.text_size(rems(4.5))
|
||||||
|
.font_weight(FontWeight::EXTRA_BOLD)
|
||||||
|
.text_color(white())
|
||||||
|
.bg(rgba(0x0000044))
|
||||||
|
.rounded_xl()
|
||||||
|
.child(format!("{:02}:{:02}:{:02}", hours, minutes, seconds))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
titlebar: None,
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(Bounds {
|
||||||
|
origin: point(px(0.), px(0.)),
|
||||||
|
size: Size::new(px(500.), px(200.)),
|
||||||
|
})),
|
||||||
|
app_id: Some("gpui-layer-shell-example".to_string()),
|
||||||
|
window_background: WindowBackgroundAppearance::Transparent,
|
||||||
|
kind: WindowKind::LayerShell(LayerShellOptions {
|
||||||
|
namespace: "gpui".to_string(),
|
||||||
|
anchor: Anchor::LEFT | Anchor::RIGHT | Anchor::BOTTOM,
|
||||||
|
margin: Some((px(0.), px(0.), px(40.), px(0.))),
|
||||||
|
keyboard_interactivity: KeyboardInteractivity::None,
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| cx.new(LayerShellExample::new),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+176
@@ -0,0 +1,176 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, ListAlignment, ListState, Render, Window, WindowBounds, WindowOptions,
|
||||||
|
div, list, prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
const ITEM_COUNT: usize = 40;
|
||||||
|
const SCROLLBAR_WIDTH: f32 = 12.;
|
||||||
|
|
||||||
|
struct BottomListDemo {
|
||||||
|
list_state: ListState,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BottomListDemo {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
list_state: ListState::new(ITEM_COUNT, ListAlignment::Bottom, px(500.)).measure_all(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for BottomListDemo {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let max_offset = self.list_state.max_offset_for_scrollbar().y;
|
||||||
|
let current_offset = -self.list_state.scroll_px_offset_for_scrollbar().y;
|
||||||
|
|
||||||
|
let viewport_height = self.list_state.viewport_bounds().size.height;
|
||||||
|
|
||||||
|
let raw_fraction = if max_offset > px(0.) {
|
||||||
|
current_offset / max_offset
|
||||||
|
} else {
|
||||||
|
0.
|
||||||
|
};
|
||||||
|
|
||||||
|
let total_height = viewport_height + max_offset;
|
||||||
|
let thumb_height = if total_height > px(0.) {
|
||||||
|
px(viewport_height.as_f32() * viewport_height.as_f32() / total_height.as_f32())
|
||||||
|
.max(px(30.))
|
||||||
|
} else {
|
||||||
|
px(30.)
|
||||||
|
};
|
||||||
|
|
||||||
|
let track_space = viewport_height - thumb_height;
|
||||||
|
let thumb_top = track_space * raw_fraction;
|
||||||
|
|
||||||
|
let bug_detected = raw_fraction > 1.0;
|
||||||
|
|
||||||
|
div()
|
||||||
|
.size_full()
|
||||||
|
.bg(rgb(0xFFFFFF))
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.p_4()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_1()
|
||||||
|
.child(format!(
|
||||||
|
"offset: {:.0} / max: {:.0} | fraction: {:.3}",
|
||||||
|
current_offset.as_f32(),
|
||||||
|
max_offset.as_f32(),
|
||||||
|
raw_fraction,
|
||||||
|
))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_color(if bug_detected {
|
||||||
|
rgb(0xCC0000)
|
||||||
|
} else {
|
||||||
|
rgb(0x008800)
|
||||||
|
})
|
||||||
|
.child(if bug_detected {
|
||||||
|
format!(
|
||||||
|
"BUG: fraction is {:.3} (> 1.0) — thumb is off-track!",
|
||||||
|
raw_fraction
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
"OK: fraction <= 1.0 — thumb is within track.".to_string()
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex_1()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.overflow_hidden()
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(0xCCCCCC))
|
||||||
|
.rounded_sm()
|
||||||
|
.child(
|
||||||
|
list(self.list_state.clone(), |index, _window, _cx| {
|
||||||
|
let height = px(30. + (index % 5) as f32 * 10.);
|
||||||
|
div()
|
||||||
|
.h(height)
|
||||||
|
.w_full()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.px_3()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(rgb(0xEEEEEE))
|
||||||
|
.bg(if index % 2 == 0 {
|
||||||
|
rgb(0xFAFAFA)
|
||||||
|
} else {
|
||||||
|
rgb(0xFFFFFF)
|
||||||
|
})
|
||||||
|
.text_sm()
|
||||||
|
.child(format!("Item {index}"))
|
||||||
|
.into_any()
|
||||||
|
})
|
||||||
|
.flex_1(),
|
||||||
|
)
|
||||||
|
// Scrollbar track
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.w(px(SCROLLBAR_WIDTH))
|
||||||
|
.h_full()
|
||||||
|
.flex_shrink_0()
|
||||||
|
.bg(rgb(0xE0E0E0))
|
||||||
|
.relative()
|
||||||
|
.child(
|
||||||
|
// Thumb — position is unclamped to expose the bug
|
||||||
|
div()
|
||||||
|
.absolute()
|
||||||
|
.top(thumb_top)
|
||||||
|
.w_full()
|
||||||
|
.h(thumb_height)
|
||||||
|
.bg(if bug_detected {
|
||||||
|
rgb(0xCC0000)
|
||||||
|
} else {
|
||||||
|
rgb(0x888888)
|
||||||
|
})
|
||||||
|
.rounded_sm(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(400.), px(500.)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
focus: true,
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| cx.new(|_| BottomListDemo::new()),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+87
@@ -0,0 +1,87 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, MousePressureEvent, PressureStage, Window, WindowBounds, WindowOptions,
|
||||||
|
div, prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct MousePressureExample {
|
||||||
|
pressure_stage: PressureStage,
|
||||||
|
pressure_amount: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for MousePressureExample {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_3()
|
||||||
|
.bg(rgb(0x505050))
|
||||||
|
.size(px(500.0))
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.shadow_lg()
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(0x0000ff))
|
||||||
|
.text_xl()
|
||||||
|
.text_color(rgb(0xffffff))
|
||||||
|
.child(format!("Pressure stage: {:?}", self.pressure_stage))
|
||||||
|
.child(format!("Pressure amount: {:.2}", self.pressure_amount))
|
||||||
|
.on_mouse_pressure(cx.listener(Self::on_mouse_pressure))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MousePressureExample {
|
||||||
|
fn on_mouse_pressure(
|
||||||
|
&mut self,
|
||||||
|
pressure_event: &MousePressureEvent,
|
||||||
|
_window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
self.pressure_amount = pressure_event.pressure;
|
||||||
|
self.pressure_stage = pressure_event.stage;
|
||||||
|
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(500.), px(500.0)), cx);
|
||||||
|
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| {
|
||||||
|
cx.new(|_| MousePressureExample {
|
||||||
|
pressure_stage: PressureStage::Zero,
|
||||||
|
pressure_amount: 0.0,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
//! An entity registers callbacks via the `_in` API family and then gets
|
||||||
|
//! re-hosted in a new window via a click. The point of the example is to
|
||||||
|
//! demonstrate that callbacks dispatched after the move correctly target the
|
||||||
|
//! entity's *current* window rather than the window it was in at
|
||||||
|
//! registration time.
|
||||||
|
//!
|
||||||
|
//! To run: cargo run -p gpui --example move_entity_between_windows
|
||||||
|
|
||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, AppContext as _, Bounds, Context, EventEmitter, MouseButton, Render, SharedString,
|
||||||
|
Subscription, Task, Window, WindowBounds, WindowOptions, div, prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct MoveToNewWindow;
|
||||||
|
|
||||||
|
struct HelloWorld {
|
||||||
|
text: SharedString,
|
||||||
|
tick_count: u32,
|
||||||
|
move_count: u32,
|
||||||
|
_tasks: Vec<Task<()>>,
|
||||||
|
_subscriptions: Vec<Subscription>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<MoveToNewWindow> for HelloWorld {}
|
||||||
|
|
||||||
|
impl HelloWorld {
|
||||||
|
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let self_entity = cx.entity();
|
||||||
|
|
||||||
|
let task = cx.spawn_in(window, async move |this, cx| {
|
||||||
|
loop {
|
||||||
|
cx.background_executor().timer(Duration::from_secs(1)).await;
|
||||||
|
let result = this.update_in(cx, |this, window, _cx| {
|
||||||
|
this.tick_count += 1;
|
||||||
|
println!(
|
||||||
|
"tick #{} fired in entity's current window {}",
|
||||||
|
this.tick_count,
|
||||||
|
window.window_handle().window_id().as_u64(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
if let Err(err) = result {
|
||||||
|
println!("tick task giving up: {err}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let subscription = cx.subscribe_in::<_, MoveToNewWindow>(
|
||||||
|
&self_entity,
|
||||||
|
window,
|
||||||
|
move |this, _emitter, _event, window, cx| {
|
||||||
|
let entered_window_id = window.window_handle().window_id().as_u64();
|
||||||
|
println!(
|
||||||
|
"MoveToNewWindow handler fired in entity's current window {entered_window_id}",
|
||||||
|
);
|
||||||
|
|
||||||
|
this.move_count += 1;
|
||||||
|
cx.notify();
|
||||||
|
|
||||||
|
let entity = cx.entity();
|
||||||
|
let old_window = window.window_handle();
|
||||||
|
cx.defer(move |cx| {
|
||||||
|
let bounds = Bounds::centered(None, size(px(500.0), px(500.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
move |_, _| entity,
|
||||||
|
)
|
||||||
|
.expect("failed to open new window");
|
||||||
|
old_window
|
||||||
|
.update(cx, |_, window, _| window.remove_window())
|
||||||
|
.ok();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
text: "World".into(),
|
||||||
|
tick_count: 0,
|
||||||
|
move_count: 0,
|
||||||
|
_tasks: vec![task],
|
||||||
|
_subscriptions: vec![subscription],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for HelloWorld {
|
||||||
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let window_id = window.window_handle().window_id().as_u64();
|
||||||
|
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_3()
|
||||||
|
.bg(rgb(0x505050))
|
||||||
|
.size(px(500.0))
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.text_xl()
|
||||||
|
.text_color(rgb(0xffffff))
|
||||||
|
.child(format!("Hello, {}!", self.text))
|
||||||
|
.child(format!("Rendering in window: {window_id}"))
|
||||||
|
.child(format!("Ticks observed by entity: {}", self.tick_count))
|
||||||
|
.child(format!("Moves observed by entity: {}", self.move_count))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.px_4()
|
||||||
|
.py_2()
|
||||||
|
.bg(rgb(0x4040ff))
|
||||||
|
.rounded_md()
|
||||||
|
.child("Move me to a new window")
|
||||||
|
.on_mouse_down(
|
||||||
|
MouseButton::Left,
|
||||||
|
cx.listener(|_this, _, _window, cx| {
|
||||||
|
cx.emit(MoveToNewWindow);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(500.0), px(500.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|window, cx| cx.new(|cx| HelloWorld::new(window, cx)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+103
@@ -0,0 +1,103 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, FocusHandle, KeyBinding, Window, WindowBounds, WindowOptions, actions,
|
||||||
|
div, prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
actions!(example, [CloseWindow]);
|
||||||
|
|
||||||
|
struct ExampleWindow {
|
||||||
|
focus_handle: FocusHandle,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for ExampleWindow {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.on_action(|_: &CloseWindow, window, _| {
|
||||||
|
window.remove_window();
|
||||||
|
})
|
||||||
|
.track_focus(&self.focus_handle)
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_3()
|
||||||
|
.bg(rgb(0x505050))
|
||||||
|
.size(px(500.0))
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.shadow_lg()
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(0x0000ff))
|
||||||
|
.text_xl()
|
||||||
|
.text_color(rgb(0xffffff))
|
||||||
|
.child(
|
||||||
|
"Closing this window with cmd-w or the traffic lights should quit the application!",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut bounds = Bounds::centered(None, size(px(500.), px(500.0)), cx);
|
||||||
|
|
||||||
|
cx.bind_keys([KeyBinding::new("cmd-w", CloseWindow, None)]);
|
||||||
|
cx.on_window_closed(|cx, _window_id| {
|
||||||
|
if cx.windows().is_empty() {
|
||||||
|
cx.quit();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|window, cx| {
|
||||||
|
cx.activate(false);
|
||||||
|
cx.new(|cx| {
|
||||||
|
let focus_handle = cx.focus_handle();
|
||||||
|
focus_handle.focus(window, cx);
|
||||||
|
ExampleWindow { focus_handle }
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
bounds.origin.x += bounds.size.width;
|
||||||
|
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|window, cx| {
|
||||||
|
cx.new(|cx| {
|
||||||
|
let focus_handle = cx.focus_handle();
|
||||||
|
focus_handle.focus(window, cx);
|
||||||
|
ExampleWindow { focus_handle }
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
Vendored
+195
@@ -0,0 +1,195 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use std::{fs, path::PathBuf};
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use gpui::{
|
||||||
|
App, AssetSource, Bounds, BoxShadow, ClickEvent, Context, SharedString, Task, Window,
|
||||||
|
WindowBounds, WindowOptions, div, hsla, img, prelude::*, px, rgb, size, svg,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct Assets {
|
||||||
|
base: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AssetSource for Assets {
|
||||||
|
fn load(&self, path: &str) -> Result<Option<std::borrow::Cow<'static, [u8]>>> {
|
||||||
|
fs::read(self.base.join(path))
|
||||||
|
.map(|data| Some(std::borrow::Cow::Owned(data)))
|
||||||
|
.map_err(|e| e.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
|
||||||
|
fs::read_dir(self.base.join(path))
|
||||||
|
.map(|entries| {
|
||||||
|
entries
|
||||||
|
.filter_map(|entry| {
|
||||||
|
entry
|
||||||
|
.ok()
|
||||||
|
.and_then(|entry| entry.file_name().into_string().ok())
|
||||||
|
.map(SharedString::from)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.map_err(|e| e.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct HelloWorld {
|
||||||
|
_task: Option<Task<()>>,
|
||||||
|
opacity: f32,
|
||||||
|
animating: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HelloWorld {
|
||||||
|
fn new(_window: &mut Window, _: &mut Context<Self>) -> Self {
|
||||||
|
Self {
|
||||||
|
_task: None,
|
||||||
|
opacity: 0.5,
|
||||||
|
animating: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_animation(&mut self, _: &ClickEvent, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.opacity = 0.0;
|
||||||
|
self.animating = true;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for HelloWorld {
|
||||||
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
if self.animating {
|
||||||
|
self.opacity += 0.005;
|
||||||
|
if self.opacity >= 1.0 {
|
||||||
|
self.animating = false;
|
||||||
|
self.opacity = 1.0;
|
||||||
|
} else {
|
||||||
|
window.request_animation_frame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.size_full()
|
||||||
|
.bg(rgb(0xe0e0e0))
|
||||||
|
.text_xl()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.size_full()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.border_1()
|
||||||
|
.text_color(gpui::blue())
|
||||||
|
.child(div().child("This is background text.")),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("panel")
|
||||||
|
.on_click(cx.listener(Self::start_animation))
|
||||||
|
.absolute()
|
||||||
|
.top_8()
|
||||||
|
.left_8()
|
||||||
|
.right_8()
|
||||||
|
.bottom_8()
|
||||||
|
.opacity(self.opacity)
|
||||||
|
.flex()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.border_3()
|
||||||
|
.border_color(gpui::red())
|
||||||
|
.text_color(gpui::yellow())
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_2()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.size(px(300.))
|
||||||
|
.bg(gpui::blue())
|
||||||
|
.border_3()
|
||||||
|
.border_color(gpui::black())
|
||||||
|
.shadow(vec![
|
||||||
|
BoxShadow::new(px(10.0), px(10.0), hsla(0.0, 0.0, 0.0, 0.5))
|
||||||
|
.blur_radius(px(1.0))
|
||||||
|
.spread_radius(px(5.0)),
|
||||||
|
])
|
||||||
|
.child(img("image/app-icon.png").size_8())
|
||||||
|
.child("Opacity Panel (Click to test)")
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("deep-level-text")
|
||||||
|
.flex()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.p_4()
|
||||||
|
.bg(gpui::black())
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.text_decoration_2()
|
||||||
|
.text_decoration_wavy()
|
||||||
|
.text_decoration_color(gpui::red())
|
||||||
|
.child(format!("opacity: {:.1}", self.opacity)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
svg()
|
||||||
|
.path("image/arrow_circle.svg")
|
||||||
|
.text_color(gpui::black())
|
||||||
|
.text_2xl()
|
||||||
|
.size_8(),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.children(["🎊", "✈️", "🎉", "🎈", "🎁", "🎂"].map(|emoji| {
|
||||||
|
div()
|
||||||
|
.child(emoji.to_string())
|
||||||
|
.hover(|style| style.opacity(0.5))
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.child(img("image/black-cat-typing.gif").size_12()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application()
|
||||||
|
.with_assets(Assets {
|
||||||
|
base: PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples"),
|
||||||
|
})
|
||||||
|
.run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(500.0), px(500.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|window, cx| cx.new(|cx| HelloWorld::new(window, cx)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{App, Context, Entity, EventEmitter, prelude::*};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct Counter {
|
||||||
|
count: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Change {
|
||||||
|
increment: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<Change> for Counter {}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let counter: Entity<Counter> = cx.new(|_cx| Counter { count: 0 });
|
||||||
|
let subscriber = cx.new(|cx: &mut Context<Counter>| {
|
||||||
|
cx.subscribe(&counter, |subscriber, _emitter, event, _cx| {
|
||||||
|
subscriber.count += event.increment * 2;
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
Counter {
|
||||||
|
count: counter.read(cx).count * 2,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
counter.update(cx, |counter, cx| {
|
||||||
|
counter.count += 2;
|
||||||
|
cx.notify();
|
||||||
|
cx.emit(Change { increment: 2 });
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(subscriber.read(cx).count, 4);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
Vendored
+478
@@ -0,0 +1,478 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
Background, Bounds, ColorSpace, Context, MouseDownEvent, Path, PathBuilder, PathStyle, Pixels,
|
||||||
|
Point, Render, StrokeOptions, Window, WindowOptions, canvas, div, linear_color_stop,
|
||||||
|
linear_gradient, point, prelude::*, px, quad, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct PaintingViewer {
|
||||||
|
default_lines: Vec<(Path<Pixels>, Background)>,
|
||||||
|
background_quads: Vec<(Bounds<Pixels>, Background)>,
|
||||||
|
lines: Vec<Vec<Point<Pixels>>>,
|
||||||
|
start: Point<Pixels>,
|
||||||
|
dashed: bool,
|
||||||
|
_painting: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PaintingViewer {
|
||||||
|
fn new(_window: &mut Window, _cx: &mut Context<Self>) -> Self {
|
||||||
|
let mut lines = vec![];
|
||||||
|
|
||||||
|
// Black squares beneath transparent paths.
|
||||||
|
let background_quads = vec![
|
||||||
|
(
|
||||||
|
Bounds {
|
||||||
|
origin: point(px(70.), px(70.)),
|
||||||
|
size: size(px(40.), px(40.)),
|
||||||
|
},
|
||||||
|
gpui::black().into(),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Bounds {
|
||||||
|
origin: point(px(170.), px(70.)),
|
||||||
|
size: size(px(40.), px(40.)),
|
||||||
|
},
|
||||||
|
gpui::black().into(),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Bounds {
|
||||||
|
origin: point(px(270.), px(70.)),
|
||||||
|
size: size(px(40.), px(40.)),
|
||||||
|
},
|
||||||
|
gpui::black().into(),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Bounds {
|
||||||
|
origin: point(px(370.), px(70.)),
|
||||||
|
size: size(px(40.), px(40.)),
|
||||||
|
},
|
||||||
|
gpui::black().into(),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Bounds {
|
||||||
|
origin: point(px(450.), px(50.)),
|
||||||
|
size: size(px(80.), px(80.)),
|
||||||
|
},
|
||||||
|
gpui::black().into(),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
// 50% opaque red path that extends across black quad.
|
||||||
|
let mut builder = PathBuilder::fill();
|
||||||
|
builder.move_to(point(px(50.), px(50.)));
|
||||||
|
builder.line_to(point(px(130.), px(50.)));
|
||||||
|
builder.line_to(point(px(130.), px(130.)));
|
||||||
|
builder.line_to(point(px(50.), px(130.)));
|
||||||
|
builder.close();
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
let red = rgb(0xFF0000).alpha(0.5);
|
||||||
|
lines.push((path, red.into()));
|
||||||
|
|
||||||
|
// 50% opaque blue path that extends across black quad.
|
||||||
|
let mut builder = PathBuilder::fill();
|
||||||
|
builder.move_to(point(px(150.), px(50.)));
|
||||||
|
builder.line_to(point(px(230.), px(50.)));
|
||||||
|
builder.line_to(point(px(230.), px(130.)));
|
||||||
|
builder.line_to(point(px(150.), px(130.)));
|
||||||
|
builder.close();
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
let blue = rgb(0x0000FF).alpha(0.5);
|
||||||
|
lines.push((path, blue.into()));
|
||||||
|
|
||||||
|
// 50% opaque green path that extends across black quad.
|
||||||
|
let mut builder = PathBuilder::fill();
|
||||||
|
builder.move_to(point(px(250.), px(50.)));
|
||||||
|
builder.line_to(point(px(330.), px(50.)));
|
||||||
|
builder.line_to(point(px(330.), px(130.)));
|
||||||
|
builder.line_to(point(px(250.), px(130.)));
|
||||||
|
builder.close();
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
let green = rgb(0x00FF00).alpha(0.5);
|
||||||
|
lines.push((path, green.into()));
|
||||||
|
|
||||||
|
// 50% opaque black path that extends across black quad.
|
||||||
|
let mut builder = PathBuilder::fill();
|
||||||
|
builder.move_to(point(px(350.), px(50.)));
|
||||||
|
builder.line_to(point(px(430.), px(50.)));
|
||||||
|
builder.line_to(point(px(430.), px(130.)));
|
||||||
|
builder.line_to(point(px(350.), px(130.)));
|
||||||
|
builder.close();
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
let black = rgb(0x000000).alpha(0.5);
|
||||||
|
lines.push((path, black.into()));
|
||||||
|
|
||||||
|
// Two 50% opaque red circles overlapping - center should be darker red
|
||||||
|
let mut builder = PathBuilder::fill();
|
||||||
|
let center = point(px(530.), px(85.));
|
||||||
|
let radius = px(30.);
|
||||||
|
builder.move_to(point(center.x + radius, center.y));
|
||||||
|
builder.arc_to(
|
||||||
|
point(radius, radius),
|
||||||
|
px(0.),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
point(center.x - radius, center.y),
|
||||||
|
);
|
||||||
|
builder.arc_to(
|
||||||
|
point(radius, radius),
|
||||||
|
px(0.),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
point(center.x + radius, center.y),
|
||||||
|
);
|
||||||
|
builder.close();
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
let red1 = rgb(0xFF0000).alpha(0.5);
|
||||||
|
lines.push((path, red1.into()));
|
||||||
|
|
||||||
|
let mut builder = PathBuilder::fill();
|
||||||
|
let center = point(px(570.), px(85.));
|
||||||
|
let radius = px(30.);
|
||||||
|
builder.move_to(point(center.x + radius, center.y));
|
||||||
|
builder.arc_to(
|
||||||
|
point(radius, radius),
|
||||||
|
px(0.),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
point(center.x - radius, center.y),
|
||||||
|
);
|
||||||
|
builder.arc_to(
|
||||||
|
point(radius, radius),
|
||||||
|
px(0.),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
point(center.x + radius, center.y),
|
||||||
|
);
|
||||||
|
builder.close();
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
let red2 = rgb(0xFF0000).alpha(0.5);
|
||||||
|
lines.push((path, red2.into()));
|
||||||
|
|
||||||
|
// draw a Rust logo
|
||||||
|
let mut builder = lyon::path::Path::svg_builder();
|
||||||
|
lyon::extra::rust_logo::build_logo_path(&mut builder);
|
||||||
|
// move down the Path
|
||||||
|
let mut builder: PathBuilder = builder.into();
|
||||||
|
builder.translate(point(px(10.), px(200.)));
|
||||||
|
builder.scale(0.9);
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
lines.push((path, gpui::black().into()));
|
||||||
|
|
||||||
|
// draw a lightening bolt ⚡
|
||||||
|
let mut builder = PathBuilder::fill();
|
||||||
|
builder.add_polygon(
|
||||||
|
&[
|
||||||
|
point(px(150.), px(300.)),
|
||||||
|
point(px(200.), px(225.)),
|
||||||
|
point(px(200.), px(275.)),
|
||||||
|
point(px(250.), px(200.)),
|
||||||
|
],
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
lines.push((path, rgb(0x1d4ed8).into()));
|
||||||
|
|
||||||
|
// draw a ⭐
|
||||||
|
let mut builder = PathBuilder::fill();
|
||||||
|
builder.move_to(point(px(350.), px(200.)));
|
||||||
|
builder.line_to(point(px(370.), px(260.)));
|
||||||
|
builder.line_to(point(px(430.), px(260.)));
|
||||||
|
builder.line_to(point(px(380.), px(300.)));
|
||||||
|
builder.line_to(point(px(400.), px(360.)));
|
||||||
|
builder.line_to(point(px(350.), px(320.)));
|
||||||
|
builder.line_to(point(px(300.), px(360.)));
|
||||||
|
builder.line_to(point(px(320.), px(300.)));
|
||||||
|
builder.line_to(point(px(270.), px(260.)));
|
||||||
|
builder.line_to(point(px(330.), px(260.)));
|
||||||
|
builder.line_to(point(px(350.), px(200.)));
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
lines.push((
|
||||||
|
path,
|
||||||
|
linear_gradient(
|
||||||
|
180.,
|
||||||
|
linear_color_stop(rgb(0xFACC15), 0.7),
|
||||||
|
linear_color_stop(rgb(0xD56D0C), 1.),
|
||||||
|
)
|
||||||
|
.color_space(ColorSpace::Oklab),
|
||||||
|
));
|
||||||
|
|
||||||
|
// draw linear gradient
|
||||||
|
let square_bounds = Bounds {
|
||||||
|
origin: point(px(450.), px(200.)),
|
||||||
|
size: size(px(200.), px(80.)),
|
||||||
|
};
|
||||||
|
let height = square_bounds.size.height;
|
||||||
|
let horizontal_offset = height;
|
||||||
|
let vertical_offset = px(30.);
|
||||||
|
let mut builder = PathBuilder::fill();
|
||||||
|
builder.move_to(square_bounds.bottom_left());
|
||||||
|
builder.curve_to(
|
||||||
|
square_bounds.origin + point(horizontal_offset, vertical_offset),
|
||||||
|
square_bounds.origin + point(px(0.0), vertical_offset),
|
||||||
|
);
|
||||||
|
builder.line_to(square_bounds.top_right() + point(-horizontal_offset, vertical_offset));
|
||||||
|
builder.curve_to(
|
||||||
|
square_bounds.bottom_right(),
|
||||||
|
square_bounds.top_right() + point(px(0.0), vertical_offset),
|
||||||
|
);
|
||||||
|
builder.line_to(square_bounds.bottom_left());
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
lines.push((
|
||||||
|
path,
|
||||||
|
linear_gradient(
|
||||||
|
180.,
|
||||||
|
linear_color_stop(gpui::blue(), 0.4),
|
||||||
|
linear_color_stop(gpui::red(), 1.),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
// draw a pie chart
|
||||||
|
let center = point(px(96.), px(96.));
|
||||||
|
let pie_center = point(px(775.), px(255.));
|
||||||
|
let segments = [
|
||||||
|
(
|
||||||
|
point(px(871.), px(255.)),
|
||||||
|
point(px(747.), px(163.)),
|
||||||
|
rgb(0x1374e9),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
point(px(747.), px(163.)),
|
||||||
|
point(px(679.), px(263.)),
|
||||||
|
rgb(0xe13527),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
point(px(679.), px(263.)),
|
||||||
|
point(px(754.), px(349.)),
|
||||||
|
rgb(0x0751ce),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
point(px(754.), px(349.)),
|
||||||
|
point(px(854.), px(310.)),
|
||||||
|
rgb(0x209742),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
point(px(854.), px(310.)),
|
||||||
|
point(px(871.), px(255.)),
|
||||||
|
rgb(0xfbc10a),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (start, end, color) in segments {
|
||||||
|
let mut builder = PathBuilder::fill();
|
||||||
|
builder.move_to(start);
|
||||||
|
builder.arc_to(center, px(0.), false, false, end);
|
||||||
|
builder.line_to(pie_center);
|
||||||
|
builder.close();
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
lines.push((path, color.into()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw a wave
|
||||||
|
let options = StrokeOptions::default()
|
||||||
|
.with_line_width(1.)
|
||||||
|
.with_line_join(lyon::path::LineJoin::Bevel);
|
||||||
|
let mut builder = PathBuilder::stroke(px(1.)).with_style(PathStyle::Stroke(options));
|
||||||
|
builder.move_to(point(px(40.), px(420.)));
|
||||||
|
for i in 1..50 {
|
||||||
|
builder.line_to(point(
|
||||||
|
px(40.0 + i as f32 * 10.0),
|
||||||
|
px(420.0 + (i as f32 * 10.0).sin() * 40.0),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
lines.push((path, gpui::green().into()));
|
||||||
|
|
||||||
|
Self {
|
||||||
|
default_lines: lines.clone(),
|
||||||
|
background_quads,
|
||||||
|
lines: vec![],
|
||||||
|
start: point(px(0.), px(0.)),
|
||||||
|
dashed: false,
|
||||||
|
_painting: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clear(&mut self, cx: &mut Context<Self>) {
|
||||||
|
self.lines.clear();
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn button(
|
||||||
|
text: &str,
|
||||||
|
cx: &mut Context<PaintingViewer>,
|
||||||
|
on_click: impl Fn(&mut PaintingViewer, &mut Context<PaintingViewer>) + 'static,
|
||||||
|
) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.id(text.to_string())
|
||||||
|
.child(text.to_string())
|
||||||
|
.bg(gpui::black())
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.active(|this| this.opacity(0.8))
|
||||||
|
.flex()
|
||||||
|
.px_3()
|
||||||
|
.py_1()
|
||||||
|
.on_click(cx.listener(move |this, _, _, cx| on_click(this, cx)))
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for PaintingViewer {
|
||||||
|
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let default_lines = self.default_lines.clone();
|
||||||
|
let background_quads = self.background_quads.clone();
|
||||||
|
let lines = self.lines.clone();
|
||||||
|
let dashed = self.dashed;
|
||||||
|
|
||||||
|
div()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.size_full()
|
||||||
|
.p_4()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.gap_2()
|
||||||
|
.justify_between()
|
||||||
|
.items_center()
|
||||||
|
.child("Mouse down any point and drag to draw lines (Hold on shift key to draw straight lines)")
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.gap_x_2()
|
||||||
|
.child(button(
|
||||||
|
if dashed { "Solid" } else { "Dashed" },
|
||||||
|
cx,
|
||||||
|
move |this, _| this.dashed = !dashed,
|
||||||
|
))
|
||||||
|
.child(button("Clear", cx, |this, cx| this.clear(cx))),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.size_full()
|
||||||
|
.child(
|
||||||
|
canvas(
|
||||||
|
move |_, _, _| {},
|
||||||
|
move |_, _, window, _| {
|
||||||
|
// First draw background quads
|
||||||
|
for (bounds, color) in background_quads.iter() {
|
||||||
|
window.paint_quad(quad(
|
||||||
|
*bounds,
|
||||||
|
px(0.),
|
||||||
|
*color,
|
||||||
|
px(0.),
|
||||||
|
gpui::transparent_black(),
|
||||||
|
Default::default(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then draw the default paths on top
|
||||||
|
for (path, color) in default_lines {
|
||||||
|
window.paint_path(path, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
for points in lines {
|
||||||
|
if points.len() < 2 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut builder = PathBuilder::stroke(px(1.));
|
||||||
|
if dashed {
|
||||||
|
builder = builder.dash_array(&[px(4.), px(2.)]);
|
||||||
|
}
|
||||||
|
for (i, p) in points.into_iter().enumerate() {
|
||||||
|
if i == 0 {
|
||||||
|
builder.move_to(p);
|
||||||
|
} else {
|
||||||
|
builder.line_to(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(path) = builder.build() {
|
||||||
|
window.paint_path(path, gpui::black());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.size_full(),
|
||||||
|
)
|
||||||
|
.on_mouse_down(
|
||||||
|
gpui::MouseButton::Left,
|
||||||
|
cx.listener(|this, ev: &MouseDownEvent, _, _| {
|
||||||
|
this._painting = true;
|
||||||
|
this.start = ev.position;
|
||||||
|
let path = vec![ev.position];
|
||||||
|
this.lines.push(path);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.on_mouse_move(cx.listener(|this, ev: &gpui::MouseMoveEvent, _, cx| {
|
||||||
|
if !this._painting {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let is_shifted = ev.modifiers.shift;
|
||||||
|
let mut pos = ev.position;
|
||||||
|
// When holding shift, draw a straight line
|
||||||
|
if is_shifted {
|
||||||
|
let dx = pos.x - this.start.x;
|
||||||
|
let dy = pos.y - this.start.y;
|
||||||
|
if dx.abs() > dy.abs() {
|
||||||
|
pos.y = this.start.y;
|
||||||
|
} else {
|
||||||
|
pos.x = this.start.x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(path) = this.lines.last_mut() {
|
||||||
|
path.push(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.on_mouse_up(
|
||||||
|
gpui::MouseButton::Left,
|
||||||
|
cx.listener(|this, _, _, _| {
|
||||||
|
this._painting = false;
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
focus: true,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|window, cx| cx.new(|cx| PaintingViewer::new(window, cx)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.on_window_closed(|cx, _window_id| {
|
||||||
|
cx.quit();
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
Background, Bounds, ColorSpace, Context, Path, PathBuilder, Pixels, Render, TitlebarOptions,
|
||||||
|
Window, WindowBounds, WindowOptions, canvas, div, linear_color_stop, linear_gradient, point,
|
||||||
|
prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
const DEFAULT_WINDOW_WIDTH: Pixels = px(1024.0);
|
||||||
|
const DEFAULT_WINDOW_HEIGHT: Pixels = px(768.0);
|
||||||
|
|
||||||
|
struct PaintingViewer {
|
||||||
|
default_lines: Vec<(Path<Pixels>, Background)>,
|
||||||
|
_painting: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PaintingViewer {
|
||||||
|
fn new(_window: &mut Window, _cx: &mut Context<Self>) -> Self {
|
||||||
|
let mut lines = vec![];
|
||||||
|
|
||||||
|
// draw a lightening bolt ⚡
|
||||||
|
for _ in 0..2000 {
|
||||||
|
// draw a ⭐
|
||||||
|
let mut builder = PathBuilder::fill();
|
||||||
|
builder.move_to(point(px(350.), px(100.)));
|
||||||
|
builder.line_to(point(px(370.), px(160.)));
|
||||||
|
builder.line_to(point(px(430.), px(160.)));
|
||||||
|
builder.line_to(point(px(380.), px(200.)));
|
||||||
|
builder.line_to(point(px(400.), px(260.)));
|
||||||
|
builder.line_to(point(px(350.), px(220.)));
|
||||||
|
builder.line_to(point(px(300.), px(260.)));
|
||||||
|
builder.line_to(point(px(320.), px(200.)));
|
||||||
|
builder.line_to(point(px(270.), px(160.)));
|
||||||
|
builder.line_to(point(px(330.), px(160.)));
|
||||||
|
builder.line_to(point(px(350.), px(100.)));
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
lines.push((
|
||||||
|
path,
|
||||||
|
linear_gradient(
|
||||||
|
180.,
|
||||||
|
linear_color_stop(rgb(0xFACC15), 0.7),
|
||||||
|
linear_color_stop(rgb(0xD56D0C), 1.),
|
||||||
|
)
|
||||||
|
.color_space(ColorSpace::Oklab),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Self {
|
||||||
|
default_lines: lines,
|
||||||
|
_painting: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for PaintingViewer {
|
||||||
|
fn render(&mut self, window: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
window.request_animation_frame();
|
||||||
|
let lines = self.default_lines.clone();
|
||||||
|
div().size_full().child(
|
||||||
|
canvas(
|
||||||
|
move |_, _, _| {},
|
||||||
|
move |_, _, window, _| {
|
||||||
|
for (path, color) in lines {
|
||||||
|
window.paint_path(path, color);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.size_full(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
titlebar: Some(TitlebarOptions {
|
||||||
|
title: Some("Vulkan".into()),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
focus: true,
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
|
||||||
|
None,
|
||||||
|
size(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT),
|
||||||
|
cx,
|
||||||
|
))),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|window, cx| cx.new(|cx| PaintingViewer::new(window, cx)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
Vendored
+136
@@ -0,0 +1,136 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, AppContext, Bounds, Context, Window, WindowBounds, WindowOptions, div, linear_color_stop,
|
||||||
|
linear_gradient, pattern_slash, prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct PatternExample;
|
||||||
|
|
||||||
|
impl Render for PatternExample {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_3()
|
||||||
|
.bg(rgb(0xffffff))
|
||||||
|
.size(px(600.0))
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.shadow_lg()
|
||||||
|
.text_xl()
|
||||||
|
.text_color(rgb(0x000000))
|
||||||
|
.child("Pattern Example")
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.border_1()
|
||||||
|
.border_color(gpui::blue())
|
||||||
|
.child(div().w(px(54.0)).h(px(18.0)).bg(pattern_slash(
|
||||||
|
gpui::red(),
|
||||||
|
18.0 / 4.0,
|
||||||
|
18.0 / 4.0,
|
||||||
|
)))
|
||||||
|
.child(div().w(px(54.0)).h(px(18.0)).bg(pattern_slash(
|
||||||
|
gpui::red(),
|
||||||
|
18.0 / 4.0,
|
||||||
|
18.0 / 4.0,
|
||||||
|
)))
|
||||||
|
.child(div().w(px(54.0)).h(px(18.0)).bg(pattern_slash(
|
||||||
|
gpui::red(),
|
||||||
|
18.0 / 4.0,
|
||||||
|
18.0 / 4.0,
|
||||||
|
)))
|
||||||
|
.child(div().w(px(54.0)).h(px(18.0)).bg(pattern_slash(
|
||||||
|
gpui::red(),
|
||||||
|
18.0 / 4.0,
|
||||||
|
18.0 / 2.0,
|
||||||
|
))),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.border_1()
|
||||||
|
.border_color(gpui::blue())
|
||||||
|
.bg(gpui::green().opacity(0.16))
|
||||||
|
.child("Elements the same height should align")
|
||||||
|
.child(div().w(px(256.0)).h(px(56.0)).bg(pattern_slash(
|
||||||
|
gpui::red(),
|
||||||
|
56.0 / 6.0,
|
||||||
|
56.0 / 6.0,
|
||||||
|
)))
|
||||||
|
.child(div().w(px(256.0)).h(px(56.0)).bg(pattern_slash(
|
||||||
|
gpui::green(),
|
||||||
|
56.0 / 6.0,
|
||||||
|
56.0 / 6.0,
|
||||||
|
)))
|
||||||
|
.child(div().w(px(256.0)).h(px(56.0)).bg(pattern_slash(
|
||||||
|
gpui::blue(),
|
||||||
|
56.0 / 6.0,
|
||||||
|
56.0 / 6.0,
|
||||||
|
)))
|
||||||
|
.child(div().w(px(256.0)).h(px(26.0)).bg(pattern_slash(
|
||||||
|
gpui::yellow(),
|
||||||
|
56.0 / 6.0,
|
||||||
|
56.0 / 6.0,
|
||||||
|
))),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.border_1()
|
||||||
|
.border_color(gpui::blue())
|
||||||
|
.w(px(240.0))
|
||||||
|
.h(px(40.0))
|
||||||
|
.bg(gpui::red()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.border_1()
|
||||||
|
.border_color(gpui::blue())
|
||||||
|
.w(px(240.0))
|
||||||
|
.h(px(40.0))
|
||||||
|
.bg(linear_gradient(
|
||||||
|
45.,
|
||||||
|
linear_color_stop(gpui::red(), 0.),
|
||||||
|
linear_color_stop(gpui::blue(), 1.),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(600.0), px(600.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_window, cx| cx.new(|_cx| PatternExample),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
Vendored
+197
@@ -0,0 +1,197 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
Anchor, App, Context, Div, Hsla, Stateful, Window, WindowOptions, anchored, deferred, div,
|
||||||
|
prelude::*, px,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
/// An example show use deferred to create a floating layers.
|
||||||
|
struct HelloWorld {
|
||||||
|
open: bool,
|
||||||
|
secondary_open: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn button(id: &'static str) -> Stateful<Div> {
|
||||||
|
div()
|
||||||
|
.id(id)
|
||||||
|
.bg(gpui::black())
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.px_3()
|
||||||
|
.py_1()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn popover() -> Div {
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.shadow_lg()
|
||||||
|
.p_3()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.text_color(gpui::black())
|
||||||
|
.border_1()
|
||||||
|
.text_sm()
|
||||||
|
.border_color(gpui::black().opacity(0.1))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn line(color: Hsla) -> Div {
|
||||||
|
div().w(px(480.)).h_2().bg(color.opacity(0.25))
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HelloWorld {
|
||||||
|
fn render_secondary_popover(
|
||||||
|
&mut self,
|
||||||
|
_window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> impl IntoElement {
|
||||||
|
button("secondary-btn")
|
||||||
|
.mt_2()
|
||||||
|
.child("Child Popover")
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.secondary_open = true;
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.when(self.secondary_open, |this| {
|
||||||
|
this.child(
|
||||||
|
// Now GPUI supports nested deferred!
|
||||||
|
deferred(
|
||||||
|
anchored()
|
||||||
|
.anchor(Anchor::TopLeft)
|
||||||
|
.snap_to_window_with_margin(px(8.))
|
||||||
|
.child(
|
||||||
|
popover()
|
||||||
|
.child("This is second level Popover with nested deferred!")
|
||||||
|
.bg(gpui::white())
|
||||||
|
.border_color(gpui::blue())
|
||||||
|
.on_mouse_down_out(cx.listener(|this, _, _, cx| {
|
||||||
|
this.secondary_open = false;
|
||||||
|
cx.notify();
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.priority(2),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for HelloWorld {
|
||||||
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_3()
|
||||||
|
.size_full()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.text_color(gpui::black())
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.gap_4()
|
||||||
|
.child(
|
||||||
|
button("popover0").child("Opened Popover").child(
|
||||||
|
deferred(
|
||||||
|
anchored()
|
||||||
|
.anchor(Anchor::TopLeft)
|
||||||
|
.snap_to_window_with_margin(px(8.))
|
||||||
|
.child(popover().w_96().gap_3().child(
|
||||||
|
"This is a default opened Popover, \
|
||||||
|
we can use deferred to render it \
|
||||||
|
in a floating layer.",
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
.priority(0),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
button("popover1")
|
||||||
|
.child("Open Popover")
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.open = true;
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.when(self.open, |this| {
|
||||||
|
this.child(
|
||||||
|
deferred(
|
||||||
|
anchored()
|
||||||
|
.anchor(Anchor::TopLeft)
|
||||||
|
.snap_to_window_with_margin(px(8.))
|
||||||
|
.child(
|
||||||
|
popover()
|
||||||
|
.w_96()
|
||||||
|
.gap_3()
|
||||||
|
.child(
|
||||||
|
"This is first level Popover, \
|
||||||
|
we can use deferred to render it \
|
||||||
|
in a floating layer.\n\
|
||||||
|
Click outside to close.",
|
||||||
|
)
|
||||||
|
.when(!self.secondary_open, |this| {
|
||||||
|
this.on_mouse_down_out(cx.listener(
|
||||||
|
|this, _, _, cx| {
|
||||||
|
this.open = false;
|
||||||
|
cx.notify();
|
||||||
|
},
|
||||||
|
))
|
||||||
|
})
|
||||||
|
// Here we need render popover after the content
|
||||||
|
// to ensure it will be on top layer.
|
||||||
|
.child(
|
||||||
|
self.render_secondary_popover(window, cx),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.priority(1),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
"Here is an example text rendered, \
|
||||||
|
to ensure the Popover will float above this contents.",
|
||||||
|
)
|
||||||
|
.children([
|
||||||
|
line(gpui::red()),
|
||||||
|
line(gpui::yellow()),
|
||||||
|
line(gpui::blue()),
|
||||||
|
line(gpui::green()),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.open_window(WindowOptions::default(), |_, cx| {
|
||||||
|
cx.new(|_| HelloWorld {
|
||||||
|
open: false,
|
||||||
|
secondary_open: false,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+78
@@ -0,0 +1,78 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{App, Bounds, Context, Window, WindowBounds, WindowOptions, div, prelude::*, px, size};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct Scrollable {}
|
||||||
|
|
||||||
|
impl Render for Scrollable {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.size_full()
|
||||||
|
.id("vertical")
|
||||||
|
.p_4()
|
||||||
|
.overflow_scroll()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.child("Example for test 2 way scroll in nested layout")
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.h(px(5000.))
|
||||||
|
.border_1()
|
||||||
|
.border_color(gpui::blue())
|
||||||
|
.bg(gpui::blue().opacity(0.05))
|
||||||
|
.p_4()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.mb_5()
|
||||||
|
.w_full()
|
||||||
|
.id("horizontal")
|
||||||
|
.overflow_scroll()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.w(px(2000.))
|
||||||
|
.h(px(150.))
|
||||||
|
.bg(gpui::green().opacity(0.1))
|
||||||
|
.hover(|this| this.bg(gpui::green().opacity(0.2)))
|
||||||
|
.border_1()
|
||||||
|
.border_color(gpui::green())
|
||||||
|
.p_4()
|
||||||
|
.child("Scroll Horizontal"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child("Scroll Vertical"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(500.), px(500.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| cx.new(|_| Scrollable {}),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+134
@@ -0,0 +1,134 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Context, Global, Menu, MenuItem, SharedString, SystemMenuType, Window, WindowOptions,
|
||||||
|
actions, div, prelude::*,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct SetMenus;
|
||||||
|
|
||||||
|
impl Render for SetMenus {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.size_full()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.text_xl()
|
||||||
|
.text_color(gpui::black())
|
||||||
|
.child("Set Menus Example")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.set_global(AppState::new());
|
||||||
|
|
||||||
|
// Bring the menu bar to the foreground (so you can see the menu bar)
|
||||||
|
cx.activate(true);
|
||||||
|
// Register the `quit` function so it can be referenced
|
||||||
|
// by the `MenuItem::action` in the menu bar
|
||||||
|
cx.on_action(quit);
|
||||||
|
cx.on_action(toggle_check);
|
||||||
|
// Add menu items
|
||||||
|
set_app_menus(cx);
|
||||||
|
cx.open_window(WindowOptions::default(), |_, cx| cx.new(|_| SetMenus {}))
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
enum ViewMode {
|
||||||
|
List,
|
||||||
|
Grid,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ViewMode {
|
||||||
|
fn toggle(&mut self) {
|
||||||
|
*self = match self {
|
||||||
|
ViewMode::List => ViewMode::Grid,
|
||||||
|
ViewMode::Grid => ViewMode::List,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<SharedString> for ViewMode {
|
||||||
|
fn into(self) -> SharedString {
|
||||||
|
match self {
|
||||||
|
ViewMode::List => "List",
|
||||||
|
ViewMode::Grid => "Grid",
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AppState {
|
||||||
|
view_mode: ViewMode,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppState {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
view_mode: ViewMode::List,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Global for AppState {}
|
||||||
|
|
||||||
|
fn set_app_menus(cx: &mut App) {
|
||||||
|
let app_state = cx.global::<AppState>();
|
||||||
|
cx.set_menus([Menu::new("set_menus").items([
|
||||||
|
MenuItem::os_submenu("Services", SystemMenuType::Services),
|
||||||
|
MenuItem::separator(),
|
||||||
|
MenuItem::action("Disabled Item", gpui::NoAction).disabled(true),
|
||||||
|
MenuItem::submenu(Menu::new("Disabled Submenu").disabled(true)),
|
||||||
|
MenuItem::separator(),
|
||||||
|
MenuItem::action("List Mode", ToggleCheck).checked(app_state.view_mode == ViewMode::List),
|
||||||
|
MenuItem::submenu(
|
||||||
|
Menu::new("Mode").items([
|
||||||
|
MenuItem::action(ViewMode::List, ToggleCheck)
|
||||||
|
.checked(app_state.view_mode == ViewMode::List),
|
||||||
|
MenuItem::action(ViewMode::Grid, ToggleCheck)
|
||||||
|
.checked(app_state.view_mode == ViewMode::Grid),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
MenuItem::separator(),
|
||||||
|
MenuItem::action("Quit", Quit),
|
||||||
|
])]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Associate actions using the `actions!` macro (or `Action` derive macro)
|
||||||
|
actions!(set_menus, [Quit, ToggleCheck]);
|
||||||
|
|
||||||
|
// Define the quit function that is registered with the App
|
||||||
|
fn quit(_: &Quit, cx: &mut App) {
|
||||||
|
println!("Gracefully quitting the application...");
|
||||||
|
cx.quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn toggle_check(_: &ToggleCheck, cx: &mut App) {
|
||||||
|
let app_state = cx.global_mut::<AppState>();
|
||||||
|
app_state.view_mode.toggle();
|
||||||
|
set_app_menus(cx);
|
||||||
|
}
|
||||||
Vendored
+622
@@ -0,0 +1,622 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, BoxShadow, Context, Div, SharedString, Window, WindowBounds, WindowOptions, div,
|
||||||
|
hsla, prelude::*, px, relative, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct Shadow {}
|
||||||
|
|
||||||
|
impl Shadow {
|
||||||
|
fn base() -> Div {
|
||||||
|
div()
|
||||||
|
.size_16()
|
||||||
|
.bg(rgb(0xffffff))
|
||||||
|
.rounded_full()
|
||||||
|
.border_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 0.1))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn square() -> Div {
|
||||||
|
div()
|
||||||
|
.size_16()
|
||||||
|
.bg(rgb(0xffffff))
|
||||||
|
.border_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 0.1))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rounded_small() -> Div {
|
||||||
|
div()
|
||||||
|
.size_16()
|
||||||
|
.bg(rgb(0xffffff))
|
||||||
|
.rounded(px(4.))
|
||||||
|
.border_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 0.1))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rounded_medium() -> Div {
|
||||||
|
div()
|
||||||
|
.size_16()
|
||||||
|
.bg(rgb(0xffffff))
|
||||||
|
.rounded(px(8.))
|
||||||
|
.border_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 0.1))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rounded_large() -> Div {
|
||||||
|
div()
|
||||||
|
.size_16()
|
||||||
|
.bg(rgb(0xffffff))
|
||||||
|
.rounded(px(12.))
|
||||||
|
.border_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 0.1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn example(label: impl Into<SharedString>, example: impl IntoElement) -> impl IntoElement {
|
||||||
|
let label = label.into();
|
||||||
|
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.w(relative(1. / 6.))
|
||||||
|
.border_r_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.flex_1()
|
||||||
|
.py_12()
|
||||||
|
.child(example),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.w_full()
|
||||||
|
.border_t_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.p_1()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.child(label),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for Shadow {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.id("shadow-example")
|
||||||
|
.overflow_y_scroll()
|
||||||
|
.bg(rgb(0xffffff))
|
||||||
|
.size_full()
|
||||||
|
.text_xs()
|
||||||
|
.child(div().flex().flex_col().w_full().children(vec![
|
||||||
|
div()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.children(vec![
|
||||||
|
example(
|
||||||
|
"Square",
|
||||||
|
Shadow::square().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Rounded 4",
|
||||||
|
Shadow::rounded_small().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Rounded 8",
|
||||||
|
Shadow::rounded_medium().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Rounded 16",
|
||||||
|
Shadow::rounded_large().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Circle",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
div()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.flex()
|
||||||
|
.w_full()
|
||||||
|
.children(vec![
|
||||||
|
example("None", Shadow::base()),
|
||||||
|
// 2Xsmall shadow
|
||||||
|
example("2X Small", Shadow::base().shadow_2xs()),
|
||||||
|
// Xsmall shadow
|
||||||
|
example("Extra Small", Shadow::base().shadow_xs()),
|
||||||
|
// Small shadow
|
||||||
|
example("Small", Shadow::base().shadow_sm()),
|
||||||
|
// Medium shadow
|
||||||
|
example("Medium", Shadow::base().shadow_md()),
|
||||||
|
// Large shadow
|
||||||
|
example("Large", Shadow::base().shadow_lg()),
|
||||||
|
example("Extra Large", Shadow::base().shadow_xl()),
|
||||||
|
example("2X Large", Shadow::base().shadow_2xl()),
|
||||||
|
]),
|
||||||
|
// Horizontal list of increasing blur radii
|
||||||
|
div()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.flex()
|
||||||
|
.children(vec![
|
||||||
|
example(
|
||||||
|
"Blur 0",
|
||||||
|
Shadow::base().shadow(vec![BoxShadow::new(
|
||||||
|
px(0.),
|
||||||
|
px(8.),
|
||||||
|
hsla(0.0, 0.0, 0.0, 0.3),
|
||||||
|
)]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Blur 2",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(2.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Blur 4",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(4.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Blur 8",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Blur 16",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(16.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
// Horizontal list of increasing spread radii
|
||||||
|
div()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.flex()
|
||||||
|
.children(vec![
|
||||||
|
example(
|
||||||
|
"Spread 0",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Spread 2",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Spread 4",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(4.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Spread 8",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Spread 16",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(16.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
// Square spread examples
|
||||||
|
div()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.flex()
|
||||||
|
.children(vec![
|
||||||
|
example(
|
||||||
|
"Square Spread 0",
|
||||||
|
Shadow::square().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Square Spread 8",
|
||||||
|
Shadow::square().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Square Spread 16",
|
||||||
|
Shadow::square().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(16.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
// Rounded large spread examples
|
||||||
|
div()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.flex()
|
||||||
|
.children(vec![
|
||||||
|
example(
|
||||||
|
"Rounded Large Spread 0",
|
||||||
|
Shadow::rounded_large().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Rounded Large Spread 8",
|
||||||
|
Shadow::rounded_large().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Rounded Large Spread 16",
|
||||||
|
Shadow::rounded_large().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.3))
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(16.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
// Directional shadows
|
||||||
|
div()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.flex()
|
||||||
|
.children(vec![
|
||||||
|
example(
|
||||||
|
"Left",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(-8.), px(0.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Right",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(8.), px(0.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Top",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(-8.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Bottom",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
// Square directional shadows
|
||||||
|
div()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.flex()
|
||||||
|
.children(vec![
|
||||||
|
example(
|
||||||
|
"Square Left",
|
||||||
|
Shadow::square().shadow(vec![
|
||||||
|
BoxShadow::new(px(-8.), px(0.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Square Right",
|
||||||
|
Shadow::square().shadow(vec![
|
||||||
|
BoxShadow::new(px(8.), px(0.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Square Top",
|
||||||
|
Shadow::square().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(-8.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Square Bottom",
|
||||||
|
Shadow::square().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
// Rounded large directional shadows
|
||||||
|
div()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.flex()
|
||||||
|
.children(vec![
|
||||||
|
example(
|
||||||
|
"Rounded Large Left",
|
||||||
|
Shadow::rounded_large().shadow(vec![
|
||||||
|
BoxShadow::new(px(-8.), px(0.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Rounded Large Right",
|
||||||
|
Shadow::rounded_large().shadow(vec![
|
||||||
|
BoxShadow::new(px(8.), px(0.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Rounded Large Top",
|
||||||
|
Shadow::rounded_large().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(-8.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Rounded Large Bottom",
|
||||||
|
Shadow::rounded_large().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.5, 0.5, 0.3))
|
||||||
|
.blur_radius(px(8.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
// Multiple shadows for different shapes
|
||||||
|
div()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.flex()
|
||||||
|
.children(vec![
|
||||||
|
example(
|
||||||
|
"Circle Multiple",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(
|
||||||
|
px(0.),
|
||||||
|
px(-12.),
|
||||||
|
hsla(0.0 / 360., 1.0, 0.5, 0.3),
|
||||||
|
)
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
BoxShadow::new(
|
||||||
|
px(12.),
|
||||||
|
px(0.),
|
||||||
|
hsla(60.0 / 360., 1.0, 0.5, 0.3),
|
||||||
|
)
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
BoxShadow::new(
|
||||||
|
px(0.),
|
||||||
|
px(12.),
|
||||||
|
hsla(120.0 / 360., 1.0, 0.5, 0.3),
|
||||||
|
)
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
BoxShadow::new(
|
||||||
|
px(-12.),
|
||||||
|
px(0.),
|
||||||
|
hsla(240.0 / 360., 1.0, 0.5, 0.3),
|
||||||
|
)
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Square Multiple",
|
||||||
|
Shadow::square().shadow(vec![
|
||||||
|
BoxShadow::new(
|
||||||
|
px(0.),
|
||||||
|
px(-12.),
|
||||||
|
hsla(0.0 / 360., 1.0, 0.5, 0.3),
|
||||||
|
)
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
BoxShadow::new(
|
||||||
|
px(12.),
|
||||||
|
px(0.),
|
||||||
|
hsla(60.0 / 360., 1.0, 0.5, 0.3),
|
||||||
|
)
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
BoxShadow::new(
|
||||||
|
px(0.),
|
||||||
|
px(12.),
|
||||||
|
hsla(120.0 / 360., 1.0, 0.5, 0.3),
|
||||||
|
)
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
BoxShadow::new(
|
||||||
|
px(-12.),
|
||||||
|
px(0.),
|
||||||
|
hsla(240.0 / 360., 1.0, 0.5, 0.3),
|
||||||
|
)
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Rounded Large Multiple",
|
||||||
|
Shadow::rounded_large().shadow(vec![
|
||||||
|
BoxShadow::new(
|
||||||
|
px(0.),
|
||||||
|
px(-12.),
|
||||||
|
hsla(0.0 / 360., 1.0, 0.5, 0.3),
|
||||||
|
)
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
BoxShadow::new(
|
||||||
|
px(12.),
|
||||||
|
px(0.),
|
||||||
|
hsla(60.0 / 360., 1.0, 0.5, 0.3),
|
||||||
|
)
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
BoxShadow::new(
|
||||||
|
px(0.),
|
||||||
|
px(12.),
|
||||||
|
hsla(120.0 / 360., 1.0, 0.5, 0.3),
|
||||||
|
)
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
BoxShadow::new(
|
||||||
|
px(-12.),
|
||||||
|
px(0.),
|
||||||
|
hsla(240.0 / 360., 1.0, 0.5, 0.3),
|
||||||
|
)
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.spread_radius(px(2.)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
// Inset shadows (CSS `box-shadow: inset ...`).
|
||||||
|
div()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.flex()
|
||||||
|
.w_full()
|
||||||
|
.children(vec![
|
||||||
|
example(
|
||||||
|
"Inset basic",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(0.), hsla(0.0, 0.0, 0.0, 0.5))
|
||||||
|
.blur_radius(px(12.))
|
||||||
|
.inset(),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Inset offset",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(6.), px(6.), hsla(0.0, 0.0, 0.0, 0.5))
|
||||||
|
.blur_radius(px(8.))
|
||||||
|
.inset(),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Inset spread",
|
||||||
|
Shadow::base().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(0.), hsla(0.0, 0.0, 0.0, 0.5))
|
||||||
|
.blur_radius(px(4.))
|
||||||
|
.spread_radius(px(8.))
|
||||||
|
.inset(),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Inset rounded",
|
||||||
|
Shadow::rounded_large().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(4.), hsla(0.0, 0.0, 0.0, 0.5))
|
||||||
|
.blur_radius(px(10.))
|
||||||
|
.spread_radius(px(2.))
|
||||||
|
.inset(),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
example(
|
||||||
|
"Inset sharp",
|
||||||
|
Shadow::square().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(0.), hsla(0.0, 0.0, 0.0, 0.6))
|
||||||
|
.spread_radius(px(6.))
|
||||||
|
.inset(),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
// Combined: drop + inset shadows on the same element.
|
||||||
|
div()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(hsla(0.0, 0.0, 0.0, 1.0))
|
||||||
|
.flex()
|
||||||
|
.w_full()
|
||||||
|
.children(vec![example(
|
||||||
|
"Drop + Inset",
|
||||||
|
Shadow::rounded_medium().shadow(vec![
|
||||||
|
BoxShadow::new(px(0.), px(8.), hsla(0.0, 0.0, 0.0, 0.25))
|
||||||
|
.blur_radius(px(12.)),
|
||||||
|
BoxShadow::new(px(0.), px(2.), hsla(0.0, 0.0, 0.0, 0.4))
|
||||||
|
.blur_radius(px(4.))
|
||||||
|
.inset(),
|
||||||
|
]),
|
||||||
|
)]),
|
||||||
|
]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(1000.0), px(800.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| cx.new(|_| Shadow {}),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+240
@@ -0,0 +1,240 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
<!-- Retrieved from https://commons.wikimedia.org/wiki/Category:SVG_files#/media/File:Dragon_clip_art.svg -->
|
||||||
|
<!-- License: CC BY-SA 3.0 -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="273.55759"
|
||||||
|
height="297.81952"
|
||||||
|
id="svg2"
|
||||||
|
version="1.1"
|
||||||
|
inkscape:version="0.48.2 r9819"
|
||||||
|
sodipodi:docname="New document 1">
|
||||||
|
<defs
|
||||||
|
id="defs4" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="0.78061715"
|
||||||
|
inkscape:cx="112.41895"
|
||||||
|
inkscape:cy="87.896202"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
inkscape:window-width="1024"
|
||||||
|
inkscape:window-height="712"
|
||||||
|
inkscape:window-x="-4"
|
||||||
|
inkscape:window-y="-4"
|
||||||
|
inkscape:window-maximized="1" />
|
||||||
|
<metadata
|
||||||
|
id="metadata7">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(12.737105,20.750754)">
|
||||||
|
<path
|
||||||
|
style="fill:#ff0000;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="M 73.44622,98.502944 95.574248,123.45583 103.10719,106.5067 73.44622,75.904107 c -3.686689,-4.753593 -11.648074,-6.667124 -21.18641,-7.532946 2.554639,2.715713 6.322156,2.39923 6.591328,10.82861 0.824915,3.302369 -2.23752,5.956846 -8.945373,8.003754 C 38.790859,84.969312 29.325417,85.209295 20.7156,86.732716 10.937191,88.437808 3.3459273,92.876831 -1.4124273,100.85699 L 14.595082,96.148898 c 7.184903,-0.279702 11.921181,1.889221 10.3578,10.357802 -1.994238,5.38177 -5.541365,9.21065 -11.299418,10.82861 -13.89013312,3.69644 -14.20560941,10.40948 -17.4199368,16.47832 2.98162616,-2.35421 5.619737,-5.05194 12.2410366,-3.76648 C 12.049969,137.75238 6.2740844,144.2887 0,150.76275 c -8.2557969,11.86874 -11.815365,18.89318 -11.299418,29.19017 -3.600096,18.58594 5.3801474,23.59338 8.4745634,34.36906 C -3.7567158,203.36083 -1.3904441,200.64501 0,195.48962 l 7.0621365,-10.3578 c -0.8666538,6.37974 -2.2779903,12.39636 0.4708091,21.18641 12.3493154,22.89597 28.0783714,46.43569 15.0658914,64.50084 l 15.065891,-22.59883 c 5.315347,9.96887 6.398134,20.64317 25.894501,28.24854 l 26.836118,-1.41242 c 0,0 -66.854892,-105.46124 -67.79651,-107.34448 -0.941618,-1.88323 53.201428,-70.621364 53.201428,-70.621364 z"
|
||||||
|
id="path3790"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="ccccccccccccccccccccccccscc" />
|
||||||
|
<path
|
||||||
|
style="fill:#b4daff;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="M 142.47916,274.20076 160.07509,273.64393 96.045057,235.03758 65.913274,202.08095 58.851138,160.64975 90.866157,124.86825 68.26732,97.561326 c -12.595581,1.14506 -19.978043,4.375364 -26.36531,8.003754 -10.473991,7.25982 -17.726182,17.74144 -24.482073,28.71936 -6.479109,23.36435 -7.280245,49.16212 3.766473,80.03754 11.380348,21.89016 28.33967,38.20135 48.493337,51.31819 l 18.835517,9.59325 z"
|
||||||
|
id="path3788"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="ccccccccccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#ffa100;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 156.77943,275.05636 17.41994,-9.41619 0.94162,-16.47831 -25.4237,-4.70809 -12.71184,21.1864 z"
|
||||||
|
id="path2998"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="fill:#ffa100;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 149.24649,255.75318 c 0,0 6.12051,-17.41993 4.23728,-17.41993 -1.88324,0 -22.59884,-3.76648 -22.59884,-3.76648 l -17.89075,17.41994 24.95289,13.65346 z"
|
||||||
|
id="path3000"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="fill:#ffa100;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 95.103438,237.39163 21.186412,16.47832 16.00751,-9.88699 0.47081,-18.36156 -23.54046,-5.64971 0.47081,10.82861 z"
|
||||||
|
id="path3002"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="fill:#ffa100;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 90.866157,216.67603 2.824854,-11.77023 17.419939,12.71185 -1.88324,15.06589 -16.007508,5.1789 -20.244791,-18.36156 z"
|
||||||
|
id="path3004"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="fill:#ffa100;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 62.61761,202.55176 18.832364,-8.47457 13.653464,8.47457 -2.824854,16.0075 -19.303173,0 z"
|
||||||
|
id="path3006"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="fill:#ffa100;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 57.909519,180.42373 18.832364,0.47081 9.416183,10.3578 -5.178901,9.88699 -21.186409,-0.47081 z"
|
||||||
|
id="path3008"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="fill:#ffa100;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 56.497092,159.70813 18.361555,2.82485 6.591327,13.18266 -8.474563,9.88699 -16.949128,-5.1789 z"
|
||||||
|
id="path3780"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="fill:#ffa100;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 89.924538,126.28068 c -9.664322,8.18228 -14.377332,17.78125 -10.357799,33.42745 l -13.182656,8.00375 -9.886991,-8.47457 c 3.769665,-18.09309 15.869815,-31.15434 33.427446,-32.95663 z"
|
||||||
|
id="path3786"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="ccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#80afb8;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="M 133.77127,121.15445 C 102.29445,108.16921 71.200271,103.60211 38.733769,68.843895 58.122127,89.497163 77.85045,109.22179 101.42657,118.35923 L 69.081877,100.38995 c 11.499182,15.61467 23.598373,27.80948 42.327623,31.94538 -11.24421,1.21671 -20.380767,-7.051 -29.549472,-15.17405 24.733762,29.06649 40.923142,28.22765 55.105772,20.36517 -8.16571,-3.14828 -15.52424,-7.10373 -21.56313,-12.37883 z"
|
||||||
|
id="path3798"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="ccccccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#ffaf29;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="M 138.56307,117.95991 128.58014,122.3524 87.051152,98.792686 C 67.454225,70.758132 70.300802,54.846161 60.696216,35.301249 68.447691,43.355436 74.77626,52.358226 85.453883,58.461647 79.819169,46.517664 80.927543,37.270916 80.262759,27.314905 c 3.166784,15.761986 9.719966,24.751173 15.972689,34.34128 -1.47816,-6.276965 -3.350278,-13.144867 -2.795221,-16.372006 5.304337,8.158007 10.295783,16.503749 20.764493,21.56313 3.59095,0.562069 10.55437,5.339728 18.36859,11.180882 7.24446,7.245148 12.72056,16.848114 16.77133,28.351519 z"
|
||||||
|
id="path3808"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cccccccccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#00d7d6;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 113.8054,124.34899 15.57338,-3.59386 12.37883,-4.7918 6.78839,-10.78157 -0.79863,-6.389074 17.17064,13.976104 14.37542,7.18771 9.58361,13.9761 14.77474,-1.99659 c 4.39249,1.57017 8.78497,2.92164 13.17746,7.58703 5.76188,6.36887 11.20761,14.0023 17.96928,16.37201 4.23518,-1.76668 8.10347,-4.0837 14.37542,-2.79522 5.61406,0.5029 9.02747,3.75662 10.38225,9.58361 2.60388,11.36945 -3.06132,11.71345 -6.38908,15.17405 0.037,9.48753 -3.51318,15.38783 -8.78497,19.56654 -1.67328,-6.90259 -4.18558,-12.12712 -7.98635,-14.77473 -13.4304,-10.55772 -26.90659,-1.42587 -40.33104,-8.38566 -17.65083,-10.24469 -27.78384,-26.45774 -37.93513,-31.14674 -9.67041,-1.16902 -16.20698,-3.38266 -22.76109,-5.59045 z"
|
||||||
|
id="path3810"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cccccccccccccccccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 154.53576,133.53328 c 7.83618,0.93458 14.84203,2.00755 16.37201,3.99317 12.61186,7.01602 21.03384,26.20016 31.54606,30.34811 -3.00497,-5.51683 -3.48439,-10.71796 1.99658,-15.17405 7.22535,-3.03546 10.55836,-0.45702 14.77474,2.3959 6.02262,6.9248 11.74338,16.2645 18.76791,15.17406"
|
||||||
|
id="path3814"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 209.24222,167.47525 c 0.33375,-1.59661 0.12171,-3.55709 1.59727,-4.39249 0.98845,-1.35075 2.83593,-0.98344 4.39249,-1.19796 4.8086,3.66257 4.22462,5.91709 5.98975,8.78498"
|
||||||
|
id="path3816"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cccc" />
|
||||||
|
<path
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 219.22515,144.31485 11.18088,11.18088 13.57679,8.78498"
|
||||||
|
id="path3818"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="fill:#80b7c4;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 146.94873,99.59132 c -8.40512,-14.108233 -7.32446,-24.976745 -9.98293,-38.334452 2.28959,7.959558 5.31902,15.17927 10.78157,19.96586 -5.86678,-10.515353 -3.24744,-21.030706 -1.99659,-31.546059 1.01072,9.17552 3.11766,18.229239 13.57679,26.354936 5.88809,4.549002 13.0362,8.257998 15.97269,14.774736 6.35347,8.175649 4.50901,17.892639 8.78497,23.160399 -1.99075,-8.86593 -0.24555,-12.75061 0.79864,-17.569958 0.68276,7.697158 4.15451,11.675658 7.98634,15.174058 l 0.39932,-15.174058 c 8.25592,15.027878 19.79844,10.971398 23.95903,28.750838 l -6.78839,8.38566 -9.58361,-1.19795 -6.38908,4.39249 -8.38566,-2.79522 -9.58361,-13.17747 z"
|
||||||
|
id="path3820"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="ccccccccccccccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 163.10163,110.79268 c -0.23573,2.97072 13.46423,4.4681 19.60954,10.89419 2.70861,3.95943 5.16753,8.73304 8.71536,13.07303 -5.87363,0.0346 -11.0482,1.74698 -18.05324,-0.93378 -7.43617,-4.47099 -6.44315,-11.29641 -9.33788,-18.98702 z"
|
||||||
|
id="path3822"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#ffcd71;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 169.40234,116.31052 c 0.19359,4.0262 -0.47444,12.71073 6.79118,16.41203 3.5528,1.27665 7.10559,1.14632 10.65839,0.94322 -2.15752,-3.14407 -3.90555,-6.28813 -5.565,-9.4322 -2.11396,-2.77299 -6.25107,-5.40146 -11.88457,-7.92305 z"
|
||||||
|
id="path3824"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="ccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#009d80;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 181.19259,123.29035 c -3.74814,1.60851 -4.45804,5.32041 -4.99907,9.14923 2.28898,-1.15726 4.81391,-2.06949 5.65932,-8.11169 z"
|
||||||
|
id="path3826"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#de4000;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 137.41517,138.64674 15.74549,16.46119 -4.77136,20.03971 c -5.06394,19.66324 4.09464,25.78123 11.9284,33.16095 10.22958,3.59957 20.40736,7.66534 31.25241,5.72563 -6.95999,-6.56919 -15.51616,-8.88191 -20.75542,-20.03971 -6.49636,-7.22625 -3.74543,-16.18636 -0.23857,-25.28821 4.60728,-11.28719 1.0716,-14.4314 -2.38568,-17.65403 -7.16108,-6.52548 -8.39426,-6.27621 -11.45126,-8.11131 -6.42685,-0.0251 -14.02518,-3.48676 -19.32401,-4.29422 z"
|
||||||
|
id="path3828"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cccccccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 153.87636,142.94096 c 3.90631,-1.87096 9.69299,16.23198 6.67991,19.80114 -5.63668,6.67696 -2.80544,19.95511 -0.23857,16.22262"
|
||||||
|
id="path3830"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="csc" />
|
||||||
|
<path
|
||||||
|
style="fill:#ececec;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 147.43503,184.21322 c 5.98074,4.73827 16.11122,1.17708 25.76534,-1.43141 -7.03019,7.0566 -13.84727,16.88359 -21.47112,16.22263 l -4.77136,-7.87275 z"
|
||||||
|
id="path3832"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="ccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#f2f2f2;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 173.67751,213.31852 8.11131,1.43141 c 6.06788,-12.85113 5.3157,-19.63998 5.9642,-27.67389 -3.126,10.99543 -11.45068,18.09185 -22.18683,23.37966 l 7.87275,4.5328 z"
|
||||||
|
id="path3834"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#ff6c00;fill-opacity:1;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 134.31379,139.12387 5.48706,0.47714 13.12124,8.58844 -1.90854,21.70969 -3.10139,26.71962 20.51685,15.02978 24.09537,2.14712 c -7.59703,15.51076 -21.44479,13.73677 -24.33394,26.24248 1.27084,-6.44195 0.86471,-13.55469 5.00993,-18.84688 -8.47582,5.06966 -15.09323,4.5641 -22.42539,6.20277 4.22385,-2.68547 8.10205,-6.06224 11.68983,-10.01985 -5.80515,-0.60962 -11.61031,-2.01583 -17.41546,-4.5328 -8.64382,-4.18289 -9.62981,-5.93913 -11.9284,-8.11131 7.01942,0.86252 9.473,-1.31884 12.88267,-2.86281 -26.93647,-7.55398 -26.92199,-14.26574 -35.0695,-21.23256 l 20.51685,7.39561 c 4.4984,0.68777 6.63439,-1.32438 6.6799,-5.72563 -16.33876,-9.8522 -21.88964,-21.17548 -24.33393,-32.92239 0.59372,8.94131 30.81833,14.94779 28.38959,14.79122 -3.07926,-0.19851 -18.61897,-12.87576 -17.1769,-16.22262 4.13518,3.60847 8.27036,6.74347 12.40554,5.9642 4.34471,1.92284 4.85595,-1.2656 5.48706,-4.29423 -6.58133,-6.79299 -11.82628,-7.57225 -17.17689,-8.82701 z"
|
||||||
|
id="path3836"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="ccccccccccccccccccsccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#f2f2f2;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 203.49851,177.05618 c -1.12284,5.42482 -3.73922,9.99619 -9.30416,12.88267 6.07286,-0.34494 18.50532,-3.68719 24.09537,-12.88267 z"
|
||||||
|
id="path3838"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#ececec;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 230.21812,178.96473 c 3.65804,1.99083 7.31609,3.07314 10.97413,9.30415 -6.98529,5.73834 -13.78235,11.6649 -26.95818,11.2127 8.7089,-1.5798 12.95652,-10.09936 15.98405,-20.51685 z"
|
||||||
|
id="path3840"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#999999;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 186.79875,168.22917 c -1.59045,3.42787 -3.18091,5.13539 -4.77136,7.3956 4.18355,-0.76297 7.96823,-1.79187 10.25842,-3.81708 z"
|
||||||
|
id="path3842"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#ca0000;fill-opacity:1;stroke:#130e13;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 155.78491,120.51557 c 0,0 -0.47714,-10.73556 -2.14712,-12.64411 -1.66997,-1.90854 -21.94825,-15.506918 -21.94825,-15.506918 -9.7295,-4.220532 -14.38334,-6.731213 -20.51685,-15.745488 2.90484,10.265925 7.92673,20.108438 17.1769,29.105296 -5.32802,-3.09071 -10.65604,-6.298919 -15.98406,-10.019856 2.26988,6.838946 5.33355,13.677896 15.74549,20.516846 10.6125,6.05766 18.85054,4.20042 27.67389,4.29423 z"
|
||||||
|
id="path3846"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cscccccc" />
|
||||||
|
<path
|
||||||
|
style="fill:#000000;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="M 139.45292,84.438938 125.20773,71.693241 C 119.15983,58.804456 109.97182,43.346495 95.217856,23.334566 86.780901,17.513373 80.270569,10.150883 68.226968,7.2150074 60.058839,6.6898637 52.035767,7.0350652 43.110447,1.9667792 34.99844,-5.3656363 30.6958,-11.065466 28.115509,-16.027146 34.01411,-10.45225 40.197961,-4.0216063 45.359687,-0.65733498 52.482283,2.4482615 59.604878,2.589719 66.727474,3.466273 c 14.767928,1.2266725 22.683537,9.305664 32.239116,15.744685 16.18998,15.07105 25.9637,31.746167 35.98785,48.358675 -1.05571,-9.882878 -3.6074,-20.064949 -8.62209,-30.739623 -6.0246,-9.94338 -14.00687,-17.755415 -20.7603,-26.241142 C 95.75565,5.1501111 90.473401,1.2722747 75.724437,-6.2804367 70.112554,-8.4271577 66.785373,-15.143282 62.603866,-20.150754 l 13.120571,10.121583 c 12.287926,4.1420139 32.155153,15.4397069 38.237093,21.367786 12.3045,10.369959 16.369,17.443923 20.99291,24.741648 l 8.99696,25.116521 0.37488,16.494432 c 0,0 -7.87234,-18.743673 -7.87234,-17.244179 0,1.499494 2.99898,23.991901 2.99898,23.991901 z"
|
||||||
|
id="path3848"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="cccccccccccccccccccsc" />
|
||||||
|
<path
|
||||||
|
style="fill:#1a1a1a;stroke:#000000;stroke-width:1.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:2"
|
||||||
|
d="m 99.012729,134.48743 11.893421,6.24404 c -25.631941,9.87193 -51.204911,20.45152 -77.604572,21.11082 -8.62273,0.0124 -17.24546,-2.90897 -25.86819,-6.83871 L -8.3253946,139.83947 9.5147367,151.13822 c 7.9289473,3.73642 15.8578943,4.42414 23.7868413,5.94671 16.056118,-2.54274 32.112237,-4.68742 48.168355,-13.3801 z"
|
||||||
|
id="path3850"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="ccccccccc" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 20 KiB |
Vendored
+108
@@ -0,0 +1,108 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "../example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use gpui::{
|
||||||
|
App, AssetSource, Bounds, Context, SharedString, Window, WindowBounds, WindowOptions, div,
|
||||||
|
prelude::*, px, rgb, size, svg,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct Assets {
|
||||||
|
base: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AssetSource for Assets {
|
||||||
|
fn load(&self, path: &str) -> Result<Option<std::borrow::Cow<'static, [u8]>>> {
|
||||||
|
fs::read(self.base.join(path))
|
||||||
|
.map(|data| Some(std::borrow::Cow::Owned(data)))
|
||||||
|
.map_err(|err| err.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
|
||||||
|
fs::read_dir(self.base.join(path))
|
||||||
|
.map(|entries| {
|
||||||
|
entries
|
||||||
|
.filter_map(|entry| {
|
||||||
|
entry
|
||||||
|
.ok()
|
||||||
|
.and_then(|entry| entry.file_name().into_string().ok())
|
||||||
|
.map(SharedString::from)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.map_err(|err| err.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SvgExample;
|
||||||
|
|
||||||
|
impl Render for SvgExample {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.size_full()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.gap_8()
|
||||||
|
.bg(rgb(0xffffff))
|
||||||
|
.child(
|
||||||
|
svg()
|
||||||
|
.path("svg/dragon.svg")
|
||||||
|
.size_8()
|
||||||
|
.text_color(rgb(0xff0000)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
svg()
|
||||||
|
.path("svg/dragon.svg")
|
||||||
|
.size_8()
|
||||||
|
.text_color(rgb(0x00ff00)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
svg()
|
||||||
|
.path("svg/dragon.svg")
|
||||||
|
.size_8()
|
||||||
|
.text_color(rgb(0x0000ff)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application()
|
||||||
|
.with_assets(Assets {
|
||||||
|
base: PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples"),
|
||||||
|
})
|
||||||
|
.run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(300.0), px(300.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| cx.new(|_| SvgExample),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+155
@@ -0,0 +1,155 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
//! Demonstrates posting, replacing, dismissing, and responding to system notifications.
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, Div, SharedString, Stateful, SystemNotification,
|
||||||
|
SystemNotificationAction, SystemNotificationResponse, Window, WindowBounds, WindowOptions, div,
|
||||||
|
prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
const NOTIFICATION_TAG: &str = "gpui-system-notification-example";
|
||||||
|
|
||||||
|
struct SystemNotificationExample {
|
||||||
|
revision: usize,
|
||||||
|
status: SharedString,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for SystemNotificationExample {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.size_full()
|
||||||
|
.gap_4()
|
||||||
|
.p_8()
|
||||||
|
.bg(rgb(0x18181b))
|
||||||
|
.text_color(rgb(0xf4f4f5))
|
||||||
|
.child(div().text_2xl().child("GPUI system notifications"))
|
||||||
|
.child(div().text_sm().text_color(rgb(0xa1a1aa)).child(
|
||||||
|
"Post repeatedly to replace the notification with the same tag. Click the \
|
||||||
|
notification body or an action button to send a response back to GPUI.",
|
||||||
|
))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.gap_3()
|
||||||
|
.child(button("show", "Show or replace").on_click(cx.listener(
|
||||||
|
|this, _, _, cx| {
|
||||||
|
this.revision += 1;
|
||||||
|
let revision = this.revision;
|
||||||
|
cx.show_system_notification(SystemNotification {
|
||||||
|
tag: NOTIFICATION_TAG.into(),
|
||||||
|
title: format!("Example notification {revision}").into(),
|
||||||
|
body: "This notification was posted by the GPUI example.".into(),
|
||||||
|
actions: vec![
|
||||||
|
SystemNotificationAction {
|
||||||
|
id: "open".into(),
|
||||||
|
label: "Open".into(),
|
||||||
|
},
|
||||||
|
SystemNotificationAction {
|
||||||
|
id: "snooze".into(),
|
||||||
|
label: "Snooze".into(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
this.status = format!("Posted notification revision {revision}").into();
|
||||||
|
cx.notify();
|
||||||
|
},
|
||||||
|
)))
|
||||||
|
.child(
|
||||||
|
button("dismiss", "Dismiss").on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
cx.dismiss_system_notification(NOTIFICATION_TAG);
|
||||||
|
this.status = "Dismissed the notification".into();
|
||||||
|
cx.notify();
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.mt_2()
|
||||||
|
.p_4()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgb(0x27272a))
|
||||||
|
.child(self.status.clone()),
|
||||||
|
)
|
||||||
|
.when(cfg!(target_os = "macos"), |this| {
|
||||||
|
this.child(div().mt_2().text_xs().text_color(rgb(0x71717a)).child(
|
||||||
|
"macOS only delivers notifications when this example runs from an app bundle.",
|
||||||
|
))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn button(id: &'static str, label: &'static str) -> Stateful<Div> {
|
||||||
|
div()
|
||||||
|
.id(id)
|
||||||
|
.px_4()
|
||||||
|
.py_2()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgb(0x3f3f46))
|
||||||
|
.hover(|style| style.bg(rgb(0x52525b)))
|
||||||
|
.active(|style| style.bg(rgb(0x71717a)))
|
||||||
|
.cursor_pointer()
|
||||||
|
.child(label)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.set_app_identity("dev.zed.gpui.system-notifications", "GPUI Notifications");
|
||||||
|
|
||||||
|
let view = cx.new(|_| SystemNotificationExample {
|
||||||
|
revision: 0,
|
||||||
|
status: "No notification posted yet".into(),
|
||||||
|
});
|
||||||
|
cx.on_system_notification_response({
|
||||||
|
let view = view.clone();
|
||||||
|
move |response, cx| {
|
||||||
|
let SystemNotificationResponse { tag, action_id } = response;
|
||||||
|
view.update(cx, |this, cx| {
|
||||||
|
this.status = match action_id {
|
||||||
|
Some(action_id) => {
|
||||||
|
format!("Received action '{action_id}' for tag '{tag}'").into()
|
||||||
|
}
|
||||||
|
None => format!("Notification body clicked for tag '{tag}'").into(),
|
||||||
|
};
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let bounds = Bounds::centered(None, size(px(560.), px(360.)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
titlebar: Some(gpui::TitlebarOptions {
|
||||||
|
title: Some("System Notifications Example".into()),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
move |_, _| view,
|
||||||
|
)
|
||||||
|
.expect("failed to open system notifications example window");
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
Vendored
+220
@@ -0,0 +1,220 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, Div, ElementId, FocusHandle, KeyBinding, SharedString, Stateful, Window,
|
||||||
|
WindowBounds, WindowOptions, actions, div, prelude::*, px, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
actions!(example, [Tab, TabPrev]);
|
||||||
|
|
||||||
|
struct Example {
|
||||||
|
focus_handle: FocusHandle,
|
||||||
|
items: Vec<FocusHandle>,
|
||||||
|
message: SharedString,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Example {
|
||||||
|
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let items = vec![
|
||||||
|
cx.focus_handle().tab_index(1).tab_stop(true),
|
||||||
|
cx.focus_handle().tab_index(2).tab_stop(true),
|
||||||
|
cx.focus_handle().tab_index(3).tab_stop(true),
|
||||||
|
cx.focus_handle(),
|
||||||
|
cx.focus_handle().tab_index(2).tab_stop(true),
|
||||||
|
];
|
||||||
|
|
||||||
|
let focus_handle = cx.focus_handle();
|
||||||
|
window.focus(&focus_handle, cx);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
focus_handle,
|
||||||
|
items,
|
||||||
|
message: SharedString::from("Press `Tab`, `Shift-Tab` to switch focus."),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_tab(&mut self, _: &Tab, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
window.focus_next(cx);
|
||||||
|
self.message = SharedString::from("You have pressed `Tab`.");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_tab_prev(&mut self, _: &TabPrev, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
window.focus_prev(cx);
|
||||||
|
self.message = SharedString::from("You have pressed `Shift-Tab`.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for Example {
|
||||||
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
fn tab_stop_style<T: Styled>(this: T) -> T {
|
||||||
|
this.border_3().border_color(gpui::blue())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn button(id: impl Into<ElementId>) -> Stateful<Div> {
|
||||||
|
div()
|
||||||
|
.id(id)
|
||||||
|
.h_10()
|
||||||
|
.flex_1()
|
||||||
|
.flex()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.border_1()
|
||||||
|
.border_color(gpui::black())
|
||||||
|
.bg(gpui::black())
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.focus(tab_stop_style)
|
||||||
|
.shadow_sm()
|
||||||
|
}
|
||||||
|
|
||||||
|
div()
|
||||||
|
.id("app")
|
||||||
|
.track_focus(&self.focus_handle)
|
||||||
|
.on_action(cx.listener(Self::on_tab))
|
||||||
|
.on_action(cx.listener(Self::on_tab_prev))
|
||||||
|
.size_full()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.p_4()
|
||||||
|
.gap_3()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.text_color(gpui::black())
|
||||||
|
.child(self.message.clone())
|
||||||
|
.children(
|
||||||
|
self.items
|
||||||
|
.clone()
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(ix, item_handle)| {
|
||||||
|
div()
|
||||||
|
.id(("item", ix))
|
||||||
|
.track_focus(&item_handle)
|
||||||
|
.h_10()
|
||||||
|
.w_full()
|
||||||
|
.flex()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.border_1()
|
||||||
|
.border_color(gpui::black())
|
||||||
|
.when(
|
||||||
|
item_handle.tab_stop && item_handle.is_focused(window),
|
||||||
|
tab_stop_style,
|
||||||
|
)
|
||||||
|
.map(|this| match item_handle.tab_stop {
|
||||||
|
true => this
|
||||||
|
.hover(|this| this.bg(gpui::black().opacity(0.1)))
|
||||||
|
.child(format!("tab_index: {}", item_handle.tab_index)),
|
||||||
|
false => this.opacity(0.4).child("tab_stop: false"),
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.gap_3()
|
||||||
|
.items_center()
|
||||||
|
.child(
|
||||||
|
button("el1")
|
||||||
|
.tab_index(4)
|
||||||
|
.child("Button 1")
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.message = "You have clicked Button 1.".into();
|
||||||
|
cx.notify();
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
button("el2")
|
||||||
|
.tab_index(5)
|
||||||
|
.child("Button 2")
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.message = "You have clicked Button 2.".into();
|
||||||
|
cx.notify();
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("group-1")
|
||||||
|
.tab_index(6)
|
||||||
|
.tab_group()
|
||||||
|
.tab_stop(false)
|
||||||
|
.child(
|
||||||
|
button("group-1-button-1")
|
||||||
|
.tab_index(1)
|
||||||
|
.child("Tab index [6, 1]"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
button("group-1-button-2")
|
||||||
|
.tab_index(2)
|
||||||
|
.child("Tab index [6, 2]"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
button("group-1-button-3")
|
||||||
|
.tab_index(3)
|
||||||
|
.child("Tab index [6, 3]"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("group-2")
|
||||||
|
.tab_index(7)
|
||||||
|
.tab_group()
|
||||||
|
.tab_stop(false)
|
||||||
|
.child(
|
||||||
|
button("group-2-button-1")
|
||||||
|
.tab_index(1)
|
||||||
|
.child("Tab index [7, 1]"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
button("group-2-button-2")
|
||||||
|
.tab_index(2)
|
||||||
|
.child("Tab index [7, 2]"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
button("group-2-button-3")
|
||||||
|
.tab_index(3)
|
||||||
|
.child("Tab index [7, 3]"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.bind_keys([
|
||||||
|
KeyBinding::new("tab", Tab, None),
|
||||||
|
KeyBinding::new("shift-tab", TabPrev, None),
|
||||||
|
]);
|
||||||
|
|
||||||
|
let bounds = Bounds::centered(None, size(px(800.), px(600.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|window, cx| cx.new(|cx| Example::new(window, cx)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
Vendored
+559
@@ -0,0 +1,559 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
//! Example demonstrating GPUI's testing infrastructure.
|
||||||
|
//!
|
||||||
|
//! When run normally, this displays an interactive counter window.
|
||||||
|
//! The tests below demonstrate various GPUI testing patterns.
|
||||||
|
//!
|
||||||
|
//! Run the app: cargo run -p gpui --example testing
|
||||||
|
//! Run tests: cargo test -p gpui --example testing --features test-support
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, FocusHandle, Focusable, Render, Task, Window, WindowBounds,
|
||||||
|
WindowOptions, actions, div, prelude::*, px, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
actions!(counter, [Increment, Decrement]);
|
||||||
|
|
||||||
|
struct Counter {
|
||||||
|
count: i32,
|
||||||
|
focus_handle: FocusHandle,
|
||||||
|
_subscription: gpui::Subscription,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Event emitted by Counter
|
||||||
|
struct CounterEvent;
|
||||||
|
|
||||||
|
impl gpui::EventEmitter<CounterEvent> for Counter {}
|
||||||
|
|
||||||
|
impl Counter {
|
||||||
|
fn new(cx: &mut Context<Self>) -> Self {
|
||||||
|
let subscription = cx.subscribe_self(|this: &mut Self, _event: &CounterEvent, _cx| {
|
||||||
|
this.count = 999;
|
||||||
|
});
|
||||||
|
|
||||||
|
Self {
|
||||||
|
count: 0,
|
||||||
|
focus_handle: cx.focus_handle(),
|
||||||
|
_subscription: subscription,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn increment(&mut self, _: &Increment, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.count += 1;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decrement(&mut self, _: &Decrement, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.count -= 1;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load(&self, cx: &mut Context<Self>) -> Task<()> {
|
||||||
|
cx.spawn(async move |this, cx| {
|
||||||
|
// Simulate loading data (e.g., from disk or network)
|
||||||
|
this.update(cx, |counter, _| {
|
||||||
|
counter.count = 100;
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reload(&self, cx: &mut Context<Self>) {
|
||||||
|
cx.spawn(async move |this, cx| {
|
||||||
|
// Simulate reloading data in the background
|
||||||
|
this.update(cx, |counter, _| {
|
||||||
|
counter.count += 50;
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Focusable for Counter {
|
||||||
|
fn focus_handle(&self, _cx: &App) -> FocusHandle {
|
||||||
|
self.focus_handle.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for Counter {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.id("counter")
|
||||||
|
.key_context("Counter")
|
||||||
|
.on_action(cx.listener(Self::increment))
|
||||||
|
.on_action(cx.listener(Self::decrement))
|
||||||
|
.track_focus(&self.focus_handle)
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_4()
|
||||||
|
.bg(rgb(0x1e1e2e))
|
||||||
|
.size_full()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_3xl()
|
||||||
|
.text_color(rgb(0xcdd6f4))
|
||||||
|
.child(format!("{}", self.count)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("decrement")
|
||||||
|
.px_4()
|
||||||
|
.py_2()
|
||||||
|
.bg(rgb(0x313244))
|
||||||
|
.hover(|s| s.bg(rgb(0x45475a)))
|
||||||
|
.rounded_md()
|
||||||
|
.cursor_pointer()
|
||||||
|
.text_color(rgb(0xcdd6f4))
|
||||||
|
.on_click(cx.listener(|this, _, window, cx| {
|
||||||
|
this.decrement(&Decrement, window, cx)
|
||||||
|
}))
|
||||||
|
.child("−"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("increment")
|
||||||
|
.px_4()
|
||||||
|
.py_2()
|
||||||
|
.bg(rgb(0x313244))
|
||||||
|
.hover(|s| s.bg(rgb(0x45475a)))
|
||||||
|
.rounded_md()
|
||||||
|
.cursor_pointer()
|
||||||
|
.text_color(rgb(0xcdd6f4))
|
||||||
|
.on_click(cx.listener(|this, _, window, cx| {
|
||||||
|
this.increment(&Increment, window, cx)
|
||||||
|
}))
|
||||||
|
.child("+"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("load")
|
||||||
|
.px_4()
|
||||||
|
.py_2()
|
||||||
|
.bg(rgb(0x313244))
|
||||||
|
.hover(|s| s.bg(rgb(0x45475a)))
|
||||||
|
.rounded_md()
|
||||||
|
.cursor_pointer()
|
||||||
|
.text_color(rgb(0xcdd6f4))
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.load(cx).detach();
|
||||||
|
}))
|
||||||
|
.child("Load"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("reload")
|
||||||
|
.px_4()
|
||||||
|
.py_2()
|
||||||
|
.bg(rgb(0x313244))
|
||||||
|
.hover(|s| s.bg(rgb(0x45475a)))
|
||||||
|
.rounded_md()
|
||||||
|
.cursor_pointer()
|
||||||
|
.text_color(rgb(0xcdd6f4))
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.reload(cx);
|
||||||
|
}))
|
||||||
|
.child("Reload"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(rgb(0x6c7086))
|
||||||
|
.child("Press ↑/↓ or click buttons"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.bind_keys([
|
||||||
|
gpui::KeyBinding::new("up", Increment, Some("Counter")),
|
||||||
|
gpui::KeyBinding::new("down", Decrement, Some("Counter")),
|
||||||
|
]);
|
||||||
|
|
||||||
|
let bounds = Bounds::centered(None, size(px(300.), px(200.)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|window, cx| {
|
||||||
|
let counter = cx.new(|cx| Counter::new(cx));
|
||||||
|
counter.focus_handle(cx).focus(window, cx);
|
||||||
|
counter
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use gpui::{TestAppContext, VisualTestContext};
|
||||||
|
use rand::prelude::*;
|
||||||
|
|
||||||
|
/// Here's a basic GPUI test. Just add the macro and take a TestAppContext as an argument!
|
||||||
|
///
|
||||||
|
/// Note that synchronous side effects run immediately after your "update*" calls complete.
|
||||||
|
#[gpui::test]
|
||||||
|
fn basic_testing(cx: &mut TestAppContext) {
|
||||||
|
let counter = cx.new(|cx| Counter::new(cx));
|
||||||
|
|
||||||
|
counter.update(cx, |counter, _| {
|
||||||
|
counter.count = 42;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Note that TestAppContext doesn't support `read(cx)`
|
||||||
|
let updated = counter.read_with(cx, |counter, _| counter.count);
|
||||||
|
assert_eq!(updated, 42);
|
||||||
|
|
||||||
|
// Emit an event - the subscriber will run immediately after the update finishes
|
||||||
|
counter.update(cx, |_, cx| {
|
||||||
|
cx.emit(CounterEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
let count_after_update = counter.read_with(cx, |counter, _| counter.count);
|
||||||
|
assert_eq!(
|
||||||
|
count_after_update, 999,
|
||||||
|
"Side effects should run after update completes"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Tests which involve the window require you to construct a VisualTestContext.
|
||||||
|
/// Just like synchronous side effects, the window will be drawn after every "update*"
|
||||||
|
/// call, so you can test render-dependent behavior.
|
||||||
|
#[gpui::test]
|
||||||
|
fn test_counter_in_window(cx: &mut TestAppContext) {
|
||||||
|
let window = cx.update(|cx| {
|
||||||
|
cx.open_window(Default::default(), |_, cx| cx.new(|cx| Counter::new(cx)))
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut cx = VisualTestContext::from_window(window.into(), cx);
|
||||||
|
let counter = window.root(&mut cx).unwrap();
|
||||||
|
|
||||||
|
// Action dispatch depends on the element tree to resolve which action handler
|
||||||
|
// to call, and this works exactly as you'd expect in a test.
|
||||||
|
let focus_handle = counter.read_with(&cx, |counter, _| counter.focus_handle.clone());
|
||||||
|
cx.update(|window, cx| {
|
||||||
|
focus_handle.dispatch_action(&Increment, window, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
let count_after = counter.read_with(&cx, |counter, _| counter.count);
|
||||||
|
assert_eq!(
|
||||||
|
count_after, 1,
|
||||||
|
"Action dispatched via focus handle should increment"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// GPUI tests can also be async, simply add the async keyword before the test.
|
||||||
|
/// Note that the test executor is single thread, so async side effects (including
|
||||||
|
/// background tasks) won't run until you explicitly yield control.
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_async_operations(cx: &mut TestAppContext) {
|
||||||
|
let counter = cx.new(|cx| Counter::new(cx));
|
||||||
|
|
||||||
|
// Tasks can be awaited directly
|
||||||
|
counter.update(cx, |counter, cx| counter.load(cx)).await;
|
||||||
|
|
||||||
|
let count = counter.read_with(cx, |counter, _| counter.count);
|
||||||
|
assert_eq!(count, 100, "Load task should have set count to 100");
|
||||||
|
|
||||||
|
// But side effects don't run until you yield control
|
||||||
|
counter.update(cx, |counter, cx| counter.reload(cx));
|
||||||
|
|
||||||
|
let count = counter.read_with(cx, |counter, _| counter.count);
|
||||||
|
assert_eq!(count, 100, "Detached reload task shouldn't have run yet");
|
||||||
|
|
||||||
|
// This runs all pending tasks
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
let count = counter.read_with(cx, |counter, _| counter.count);
|
||||||
|
assert_eq!(count, 150, "Reload task should have run after parking");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Note that the test executor panics if you await a future that waits on
|
||||||
|
/// something outside GPUI's control, like a reading a file or network IO.
|
||||||
|
/// You should mock external systems where possible, as this feature can be used
|
||||||
|
/// to detect potential deadlocks in your async code.
|
||||||
|
///
|
||||||
|
/// However, if you want to disable this check use `allow_parking()`
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_allow_parking(cx: &mut TestAppContext) {
|
||||||
|
// Allow the thread to park
|
||||||
|
cx.executor().allow_parking();
|
||||||
|
|
||||||
|
// Simulate an external system (like a file system) with an OS thread
|
||||||
|
let (tx, rx) = futures::channel::oneshot::channel();
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||||
|
tx.send(42).ok();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Without allow_parking(), this await would panic because GPUI's
|
||||||
|
// scheduler runs out of tasks while waiting for the external thread.
|
||||||
|
let result = rx.await.unwrap();
|
||||||
|
assert_eq!(result, 42);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// GPUI also provides support for property testing, via the iterations flag
|
||||||
|
#[gpui::test(iterations = 10)]
|
||||||
|
fn test_counter_random_operations(cx: &mut TestAppContext, mut rng: StdRng) {
|
||||||
|
let window = cx.update(|cx| {
|
||||||
|
cx.open_window(Default::default(), |_, cx| cx.new(|cx| Counter::new(cx)))
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
let mut cx = VisualTestContext::from_window(window.into(), cx);
|
||||||
|
|
||||||
|
let counter = cx.new(|cx| Counter::new(cx));
|
||||||
|
|
||||||
|
// Perform random increments/decrements
|
||||||
|
let mut expected = 0i32;
|
||||||
|
for _ in 0..100 {
|
||||||
|
if rng.random_bool(0.5) {
|
||||||
|
expected += 1;
|
||||||
|
counter.update_in(&mut cx, |counter, window, cx| {
|
||||||
|
counter.increment(&Increment, window, cx)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
expected -= 1;
|
||||||
|
counter.update_in(&mut cx, |counter, window, cx| {
|
||||||
|
counter.decrement(&Decrement, window, cx)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let actual = counter.read_with(&cx, |counter, _| counter.count);
|
||||||
|
assert_eq!(
|
||||||
|
actual, expected,
|
||||||
|
"Counter should match expected after random ops"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Now, all of those tests are good, but GPUI also provides strong support for testing distributed systems.
|
||||||
|
/// Let's setup a mock network and enhance the counter to send messages over it.
|
||||||
|
mod distributed_systems {
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
/// The state of the mock network.
|
||||||
|
struct MockNetworkState {
|
||||||
|
ordering: Vec<i32>,
|
||||||
|
a_to_b: Vec<i32>,
|
||||||
|
b_to_a: Vec<i32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A mock network that delivers messages between two peers.
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct MockNetwork {
|
||||||
|
state: Arc<Mutex<MockNetworkState>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MockNetwork {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
state: Arc::new(Mutex::new(MockNetworkState {
|
||||||
|
ordering: Vec::new(),
|
||||||
|
a_to_b: Vec::new(),
|
||||||
|
b_to_a: Vec::new(),
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn a_client(&self) -> NetworkClient {
|
||||||
|
NetworkClient {
|
||||||
|
network: self.clone(),
|
||||||
|
is_a: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn b_client(&self) -> NetworkClient {
|
||||||
|
NetworkClient {
|
||||||
|
network: self.clone(),
|
||||||
|
is_a: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A client handle for sending/receiving messages over the mock network.
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct NetworkClient {
|
||||||
|
network: MockNetwork,
|
||||||
|
is_a: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
// See, networking is easy!
|
||||||
|
impl NetworkClient {
|
||||||
|
fn send(&self, value: i32) {
|
||||||
|
let mut network = self.network.state.lock().unwrap();
|
||||||
|
network.ordering.push(value);
|
||||||
|
if self.is_a {
|
||||||
|
network.b_to_a.push(value);
|
||||||
|
} else {
|
||||||
|
network.a_to_b.push(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn receive_all(&self) -> Vec<i32> {
|
||||||
|
let mut network = self.network.state.lock().unwrap();
|
||||||
|
if self.is_a {
|
||||||
|
network.a_to_b.drain(..).collect()
|
||||||
|
} else {
|
||||||
|
network.b_to_a.drain(..).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
use gpui::Context;
|
||||||
|
|
||||||
|
/// A networked counter that can send/receive over a mock network.
|
||||||
|
struct NetworkedCounter {
|
||||||
|
count: i32,
|
||||||
|
client: NetworkClient,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NetworkedCounter {
|
||||||
|
fn new(client: NetworkClient) -> Self {
|
||||||
|
Self { count: 0, client }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Increment the counter and broadcast the change.
|
||||||
|
fn increment(&mut self, delta: i32, cx: &mut Context<Self>) {
|
||||||
|
self.count += delta;
|
||||||
|
|
||||||
|
cx.background_spawn({
|
||||||
|
let client = self.client.clone();
|
||||||
|
async move {
|
||||||
|
client.send(delta);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Process incoming increment requests.
|
||||||
|
fn sync(&mut self) {
|
||||||
|
for delta in self.client.receive_all() {
|
||||||
|
self.count += delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// You can simulate distributed systems with multiple app contexts, simply by adding
|
||||||
|
/// additional parameters.
|
||||||
|
#[gpui::test]
|
||||||
|
fn test_app_sync(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) {
|
||||||
|
let network = MockNetwork::new();
|
||||||
|
|
||||||
|
let a = cx_a.new(|_| NetworkedCounter::new(network.a_client()));
|
||||||
|
let b = cx_b.new(|_| NetworkedCounter::new(network.b_client()));
|
||||||
|
|
||||||
|
// B increments locally and broadcasts the delta
|
||||||
|
b.update(cx_b, |b, cx| b.increment(42, cx));
|
||||||
|
b.read_with(cx_b, |b, _| assert_eq!(b.count, 42)); // B's count is set immediately
|
||||||
|
a.read_with(cx_a, |a, _| assert_eq!(a.count, 0)); // A's count is in a side effect
|
||||||
|
|
||||||
|
cx_b.run_until_parked(); // Send the delta from B
|
||||||
|
a.update(cx_a, |a, _| a.sync()); // Receive the delta at A
|
||||||
|
|
||||||
|
b.read_with(cx_b, |b, _| assert_eq!(b.count, 42)); // Both counts now match
|
||||||
|
a.read_with(cx_a, |a, _| assert_eq!(a.count, 42));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Multiple apps can run concurrently, and to capture this each test app shares
|
||||||
|
/// a dispatcher. Whenever you call `run_until_parked`, the dispatcher will randomly
|
||||||
|
/// pick which app's tasks to run next. This allows you to test that your distributed code
|
||||||
|
/// is robust to different execution orderings.
|
||||||
|
#[gpui::test(iterations = 10)]
|
||||||
|
fn test_random_interleaving(
|
||||||
|
cx_a: &mut TestAppContext,
|
||||||
|
cx_b: &mut TestAppContext,
|
||||||
|
mut rng: StdRng,
|
||||||
|
) {
|
||||||
|
let network = MockNetwork::new();
|
||||||
|
|
||||||
|
// Track execution order
|
||||||
|
let mut original_order = Vec::new();
|
||||||
|
let a = cx_a.new(|_| NetworkedCounter::new(MockNetwork::a_client(&network)));
|
||||||
|
let b = cx_b.new(|_| NetworkedCounter::new(MockNetwork::b_client(&network)));
|
||||||
|
|
||||||
|
let num_operations: usize = rng.random_range(3..8);
|
||||||
|
|
||||||
|
for i in 0..num_operations {
|
||||||
|
let i = i as i32;
|
||||||
|
let which = rng.random_bool(0.5);
|
||||||
|
|
||||||
|
original_order.push(i);
|
||||||
|
if which {
|
||||||
|
b.update(cx_b, |b, cx| b.increment(i, cx));
|
||||||
|
} else {
|
||||||
|
a.update(cx_a, |a, cx| a.increment(i, cx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This will send all of the pending increment messages, from both a and b
|
||||||
|
cx_a.run_until_parked();
|
||||||
|
|
||||||
|
a.update(cx_a, |a, _| a.sync());
|
||||||
|
b.update(cx_b, |b, _| b.sync());
|
||||||
|
|
||||||
|
let a_count = a.read_with(cx_a, |a, _| a.count);
|
||||||
|
let b_count = b.read_with(cx_b, |b, _| b.count);
|
||||||
|
|
||||||
|
assert_eq!(a_count, b_count, "A and B should have the same count");
|
||||||
|
|
||||||
|
// Nicely format the execution order output.
|
||||||
|
// Run this test with `-- --nocapture` to see it!
|
||||||
|
let actual = network.state.lock().unwrap().ordering.clone();
|
||||||
|
let spawned: Vec<_> = original_order.iter().map(|n| format!("{}", n)).collect();
|
||||||
|
let ran: Vec<_> = actual.iter().map(|n| format!("{}", n)).collect();
|
||||||
|
let diff: Vec<_> = original_order
|
||||||
|
.iter()
|
||||||
|
.zip(actual.iter())
|
||||||
|
.map(|(o, a)| {
|
||||||
|
if o == a {
|
||||||
|
" ".to_string()
|
||||||
|
} else {
|
||||||
|
"^".to_string()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
println!("spawned: [{}]", spawned.join(", "));
|
||||||
|
println!("ran: [{}]", ran.join(", "));
|
||||||
|
println!(" [{}]", diff.join(", "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+432
@@ -0,0 +1,432 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
|
ops::{Deref, DerefMut},
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
AbsoluteLength, App, Context, DefiniteLength, ElementId, Global, Hsla, Menu, SharedString,
|
||||||
|
TextStyle, TitlebarOptions, Window, WindowBounds, WindowOptions, bounds, colors::DefaultColors,
|
||||||
|
div, point, prelude::*, px, relative, rgb, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
use std::iter;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct TextContext {
|
||||||
|
font_size: f32,
|
||||||
|
line_height: f32,
|
||||||
|
type_scale: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for TextContext {
|
||||||
|
fn default() -> Self {
|
||||||
|
TextContext {
|
||||||
|
font_size: 16.0,
|
||||||
|
line_height: 1.3,
|
||||||
|
type_scale: 1.33,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextContext {
|
||||||
|
pub fn get_global(cx: &App) -> &Arc<TextContext> {
|
||||||
|
&cx.global::<GlobalTextContext>().0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct GlobalTextContext(pub Arc<TextContext>);
|
||||||
|
|
||||||
|
impl Deref for GlobalTextContext {
|
||||||
|
type Target = Arc<TextContext>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DerefMut for GlobalTextContext {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Global for GlobalTextContext {}
|
||||||
|
|
||||||
|
pub trait ActiveTextContext {
|
||||||
|
fn text_context(&self) -> &Arc<TextContext>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveTextContext for App {
|
||||||
|
fn text_context(&self) -> &Arc<TextContext> {
|
||||||
|
&self.global::<GlobalTextContext>().0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
pub struct SpecimenTheme {
|
||||||
|
pub bg: Hsla,
|
||||||
|
pub fg: Hsla,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for SpecimenTheme {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
bg: gpui::white(),
|
||||||
|
fg: gpui::black(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SpecimenTheme {
|
||||||
|
pub fn invert(&self) -> Self {
|
||||||
|
Self {
|
||||||
|
bg: self.fg,
|
||||||
|
fg: self.bg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, IntoElement)]
|
||||||
|
struct Specimen {
|
||||||
|
id: ElementId,
|
||||||
|
scale: f32,
|
||||||
|
text_style: Option<TextStyle>,
|
||||||
|
string: SharedString,
|
||||||
|
invert: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Specimen {
|
||||||
|
pub fn new(id: usize) -> Self {
|
||||||
|
let string = SharedString::new_static("The quick brown fox jumps over the lazy dog");
|
||||||
|
let id_string = format!("specimen-{}", id);
|
||||||
|
let id = ElementId::Name(id_string.into());
|
||||||
|
Self {
|
||||||
|
id,
|
||||||
|
scale: 1.0,
|
||||||
|
text_style: None,
|
||||||
|
string,
|
||||||
|
invert: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn invert(mut self) -> Self {
|
||||||
|
self.invert = !self.invert;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn scale(mut self, scale: f32) -> Self {
|
||||||
|
self.scale = scale;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RenderOnce for Specimen {
|
||||||
|
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||||
|
let rem_size = window.rem_size();
|
||||||
|
let scale = self.scale;
|
||||||
|
let global_style = cx.text_context();
|
||||||
|
|
||||||
|
let style_override = self.text_style;
|
||||||
|
|
||||||
|
let mut font_size = global_style.font_size;
|
||||||
|
let mut line_height = global_style.line_height;
|
||||||
|
|
||||||
|
if let Some(style_override) = style_override {
|
||||||
|
font_size = style_override.font_size.to_pixels(rem_size).into();
|
||||||
|
line_height = match style_override.line_height {
|
||||||
|
DefiniteLength::Absolute(absolute_len) => match absolute_len {
|
||||||
|
AbsoluteLength::Rems(absolute_len) => absolute_len.to_pixels(rem_size).into(),
|
||||||
|
AbsoluteLength::Pixels(absolute_len) => absolute_len.into(),
|
||||||
|
},
|
||||||
|
DefiniteLength::Fraction(value) => value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut theme = SpecimenTheme::default();
|
||||||
|
|
||||||
|
if self.invert {
|
||||||
|
theme = theme.invert();
|
||||||
|
}
|
||||||
|
|
||||||
|
div()
|
||||||
|
.id(self.id)
|
||||||
|
.bg(theme.bg)
|
||||||
|
.text_color(theme.fg)
|
||||||
|
.text_size(px(font_size * scale))
|
||||||
|
.line_height(relative(line_height))
|
||||||
|
.p(px(10.0))
|
||||||
|
.child(self.string)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, IntoElement)]
|
||||||
|
struct CharacterGrid {
|
||||||
|
scale: f32,
|
||||||
|
invert: bool,
|
||||||
|
text_style: Option<TextStyle>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CharacterGrid {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
scale: 1.0,
|
||||||
|
invert: false,
|
||||||
|
text_style: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn scale(mut self, scale: f32) -> Self {
|
||||||
|
self.scale = scale;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RenderOnce for CharacterGrid {
|
||||||
|
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
|
||||||
|
let mut theme = SpecimenTheme::default();
|
||||||
|
|
||||||
|
if self.invert {
|
||||||
|
theme = theme.invert();
|
||||||
|
}
|
||||||
|
|
||||||
|
let characters = vec![
|
||||||
|
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "A", "B", "C", "D", "E", "F", "G",
|
||||||
|
"H", "I", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y",
|
||||||
|
"Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "p", "q",
|
||||||
|
"r", "s", "t", "u", "v", "w", "x", "y", "z", "ẞ", "ſ", "ß", "ð", "Þ", "þ", "α", "β",
|
||||||
|
"Γ", "γ", "Δ", "δ", "η", "θ", "ι", "κ", "Λ", "λ", "μ", "ν", "ξ", "π", "τ", "υ", "φ",
|
||||||
|
"χ", "ψ", "∂", "а", "в", "Ж", "ж", "З", "з", "К", "к", "л", "м", "Н", "н", "Р", "р",
|
||||||
|
"У", "у", "ф", "ч", "ь", "ы", "Э", "э", "Я", "я", "ij", "öẋ", ".,", "⣝⣑", "~", "*",
|
||||||
|
"_", "^", "`", "'", "(", "{", "«", "#", "&", "@", "$", "¢", "%", "|", "?", "¶", "µ",
|
||||||
|
"❮", "<=", "!=", "==", "--", "++", "=>", "->", "🏀", "🎊", "😍", "❤️", "👍", "👎",
|
||||||
|
];
|
||||||
|
|
||||||
|
let columns = 20;
|
||||||
|
let rows = characters.len().div_ceil(columns);
|
||||||
|
|
||||||
|
let grid_rows = (0..rows).map(|row_idx| {
|
||||||
|
let start_idx = row_idx * columns;
|
||||||
|
let end_idx = (start_idx + columns).min(characters.len());
|
||||||
|
|
||||||
|
div()
|
||||||
|
.w_full()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.children((start_idx..end_idx).map(|i| {
|
||||||
|
div()
|
||||||
|
.text_center()
|
||||||
|
.size(px(62.))
|
||||||
|
.bg(theme.bg)
|
||||||
|
.text_color(theme.fg)
|
||||||
|
.text_size(px(24.0))
|
||||||
|
.line_height(relative(1.0))
|
||||||
|
.child(characters[i])
|
||||||
|
}))
|
||||||
|
.when(end_idx - start_idx < columns, |d| {
|
||||||
|
d.children(
|
||||||
|
iter::repeat_with(|| div().flex_1()).take(columns - (end_idx - start_idx)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
div().p_4().gap_2().flex().flex_col().children(grid_rows)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TextExample {
|
||||||
|
next_id: usize,
|
||||||
|
font_family: SharedString,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextExample {
|
||||||
|
fn next_id(&mut self) -> usize {
|
||||||
|
self.next_id += 1;
|
||||||
|
self.next_id
|
||||||
|
}
|
||||||
|
|
||||||
|
fn button(
|
||||||
|
text: &str,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
on_click: impl Fn(&mut Self, &mut Context<Self>) + 'static,
|
||||||
|
) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.id(text.to_string())
|
||||||
|
.flex_none()
|
||||||
|
.child(text.to_string())
|
||||||
|
.bg(gpui::black())
|
||||||
|
.text_color(gpui::white())
|
||||||
|
.active(|this| this.opacity(0.8))
|
||||||
|
.px_3()
|
||||||
|
.py_1()
|
||||||
|
.on_click(cx.listener(move |this, _, _, cx| on_click(this, cx)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const FONT_FAMILIES: [&str; 5] = [
|
||||||
|
".ZedMono",
|
||||||
|
".SystemUIFont",
|
||||||
|
"Menlo",
|
||||||
|
"Monaco",
|
||||||
|
"Courier New",
|
||||||
|
];
|
||||||
|
|
||||||
|
impl Render for TextExample {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let tcx = cx.text_context();
|
||||||
|
let colors = cx.default_colors().clone();
|
||||||
|
|
||||||
|
let font_size = tcx.font_size;
|
||||||
|
let line_height = tcx.line_height;
|
||||||
|
let type_scale = tcx.type_scale;
|
||||||
|
|
||||||
|
let step_down_2 = 1.0 / (type_scale * type_scale);
|
||||||
|
let step_down_1 = 1.0 / type_scale;
|
||||||
|
let base = 1.0;
|
||||||
|
let step_up_1 = base * type_scale;
|
||||||
|
let step_up_2 = step_up_1 * type_scale;
|
||||||
|
let step_up_3 = step_up_2 * type_scale;
|
||||||
|
let step_up_4 = step_up_3 * type_scale;
|
||||||
|
let step_up_5 = step_up_4 * type_scale;
|
||||||
|
let step_up_6 = step_up_5 * type_scale;
|
||||||
|
|
||||||
|
div()
|
||||||
|
.font_family(self.font_family.clone())
|
||||||
|
.size_full()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(gpui::black())
|
||||||
|
.p_3()
|
||||||
|
.flex()
|
||||||
|
.child(Self::button(&self.font_family, cx, |this, cx| {
|
||||||
|
let new_family = FONT_FAMILIES
|
||||||
|
.iter()
|
||||||
|
.position(|f| *f == this.font_family.as_str())
|
||||||
|
.map(|idx| FONT_FAMILIES[(idx + 1) % FONT_FAMILIES.len()])
|
||||||
|
.unwrap_or(FONT_FAMILIES[0]);
|
||||||
|
|
||||||
|
this.font_family = SharedString::new(new_family);
|
||||||
|
cx.notify();
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("text-example")
|
||||||
|
.overflow_y_scroll()
|
||||||
|
.overflow_x_hidden()
|
||||||
|
.bg(rgb(0xffffff))
|
||||||
|
.size_full()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.p_3()
|
||||||
|
.text_size(px(font_size))
|
||||||
|
.line_height(relative(line_height))
|
||||||
|
.children([
|
||||||
|
div().child("CJK: 中文「日本語」한글"),
|
||||||
|
div().child(
|
||||||
|
"Kana: が / か\u{3099}; Hangul: 각 / \u{1100}\u{1161}\u{11a8}",
|
||||||
|
),
|
||||||
|
div().child("Emoji: 😀 ❤️ ❤\u{fe0e} 👍🏽 🇯🇵 1\u{fe0f}\u{20e3} 👩💻 👨👩👧👦"),
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
.child(div().child(CharacterGrid::new().scale(base)))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_down_2))
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_down_2).invert())
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_down_1))
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_down_1).invert())
|
||||||
|
.child(Specimen::new(self.next_id()).scale(base))
|
||||||
|
.child(Specimen::new(self.next_id()).scale(base).invert())
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_up_1))
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_up_1).invert())
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_up_2))
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_up_2).invert())
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_up_3))
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_up_3).invert())
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_up_4))
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_up_4).invert())
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_up_5))
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_up_5).invert())
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_up_6))
|
||||||
|
.child(Specimen::new(self.next_id()).scale(step_up_6).invert()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(div().w(px(240.)).h_full().bg(colors.container))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cx.set_menus(vec![Menu {
|
||||||
|
name: "GPUI Typography".into(),
|
||||||
|
disabled: false,
|
||||||
|
items: vec![],
|
||||||
|
}]);
|
||||||
|
|
||||||
|
let fonts = [include_bytes!(
|
||||||
|
"../../../assets/fonts/lilex/Lilex-Regular.ttf"
|
||||||
|
)]
|
||||||
|
.iter()
|
||||||
|
.map(|b| Cow::Borrowed(&b[..]))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
_ = cx.text_system().add_fonts(fonts);
|
||||||
|
|
||||||
|
cx.init_colors();
|
||||||
|
cx.set_global(GlobalTextContext(Arc::new(TextContext::default())));
|
||||||
|
|
||||||
|
let window = cx
|
||||||
|
.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
titlebar: Some(TitlebarOptions {
|
||||||
|
title: Some("GPUI Typography".into()),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds(
|
||||||
|
point(px(0.0), px(0.0)),
|
||||||
|
size(px(920.), px(720.)),
|
||||||
|
))),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_window, cx| {
|
||||||
|
cx.new(|_cx| TextExample {
|
||||||
|
next_id: 0,
|
||||||
|
font_family: ".ZedMono".into(),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
window
|
||||||
|
.update(cx, |_view, _window, cx| {
|
||||||
|
cx.activate(true);
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
+117
@@ -0,0 +1,117 @@
|
|||||||
|
#![cfg_attr(target_family = "wasm", no_main)]
|
||||||
|
|
||||||
|
#[path = "example_support/fonts.rs"]
|
||||||
|
mod example_support;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
App, Bounds, Context, FontStyle, FontWeight, StyledText, Window, WindowBounds, WindowOptions,
|
||||||
|
div, prelude::*, px, size,
|
||||||
|
};
|
||||||
|
use gpui_platform::application;
|
||||||
|
|
||||||
|
struct HelloWorld {}
|
||||||
|
|
||||||
|
impl Render for HelloWorld {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div()
|
||||||
|
.bg(gpui::white())
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_2()
|
||||||
|
.p_4()
|
||||||
|
.size_full()
|
||||||
|
.child(div().child("Text left"))
|
||||||
|
.child(div().text_center().child("Text center"))
|
||||||
|
.child(div().text_right().child("Text right"))
|
||||||
|
.child(div().text_decoration_1().child("Text left (underline)"))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_center()
|
||||||
|
.text_decoration_1()
|
||||||
|
.child("Text center (underline)"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_right()
|
||||||
|
.text_decoration_1()
|
||||||
|
.child("Text right (underline)"),
|
||||||
|
)
|
||||||
|
.child(div().line_through().child("Text left (line_through)"))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_center()
|
||||||
|
.line_through()
|
||||||
|
.child("Text center (line_through)"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_right()
|
||||||
|
.line_through()
|
||||||
|
.child("Text right (line_through)"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.gap_2()
|
||||||
|
.justify_between()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.w(px(400.))
|
||||||
|
.border_1()
|
||||||
|
.border_color(gpui::blue())
|
||||||
|
.p_1()
|
||||||
|
.whitespace_nowrap()
|
||||||
|
.overflow_hidden()
|
||||||
|
.text_center()
|
||||||
|
.child("A long non-wrapping text align center"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.w_32()
|
||||||
|
.border_1()
|
||||||
|
.border_color(gpui::blue())
|
||||||
|
.p_1()
|
||||||
|
.whitespace_nowrap()
|
||||||
|
.overflow_hidden()
|
||||||
|
.text_right()
|
||||||
|
.child("100%"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(div().flex().gap_2().justify_between().child(
|
||||||
|
StyledText::new("ABCD").with_highlights([
|
||||||
|
(0..1, FontWeight::EXTRA_BOLD.into()),
|
||||||
|
(2..3, FontStyle::Italic.into()),
|
||||||
|
]),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_example() {
|
||||||
|
application().run(|cx: &mut App| {
|
||||||
|
if !example_support::load_fonts(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bounds = Bounds::centered(None, size(px(800.0), px(600.0)), cx);
|
||||||
|
cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|_, cx| cx.new(|_| HelloWorld {}),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cx.activate(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
fn main() {
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
|
pub fn start() {
|
||||||
|
gpui_platform::web_init();
|
||||||
|
run_example();
|
||||||
|
}
|
||||||
Loaded 100 of 209 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user