-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add wasm backend + fix std::time dep A basic wasm backend is added as a continuation of #30. Since std::time isn't available on wasm, an additional dependency is added to abstract std::time::Instant to work with wasm. * Disable simple logger on wasm This commit ensures that all examples run with minimal changes. More specifically we don't need to remove the .use_simple_logger() call on all Apps. * Fix resizing in wasm backends The resize callback should be registered to the window, since resizing the window doesn't call the resize callback for canvases even if those do get resized. * Added scrolling support + fixed hidpi handling The scroll example now works as expected on hi and low dpi screens. * Use explicit lifetime in StrOrChar This makes passing it easier to pass owned strings when creating a new KeyEvent, which is necessary when interfacing with WASM. * Prevent the browser from going back on backspace This should be the default behavior to make text widgets usable. At a later iteration it may be better to only disable the browser from going back when a widget is selected that is expecting keyboard input where backspace is intended for something else. I expect this functionality would require some way of accessing the web_sys event from within a druid callback. * Fix key text + require console_log + adjust style This commit addresses comments in the code review: Key text: - web_sys returns the name of each pressed key from which we can generate a viable printable string. This mechanism is revised to include all non-printable keys as listed in MDN. - notably, the tab character and numpad characters have gained printable text in this commit. console_log: - console_log is not required in wasm builds. - integrated console_log with the use_simple_logger api. `console_log` is initialized with log level `trace` as is done in simple logger by default. Style: - non std use statements are now before third party use statements. - key_to_text function signature refactor - specify the log module when calling log::{warn, error} explicitly. * Fix up console_log dependency Moved console_log dependency from druid-shell to druid, since this is where it is initialized. This fixes the wasm build. * Fix the build script for wasm examples This addresses the CI failures caused by the weird build of the wasm examples. To elaborate: In order to include each of the examples in the wasm example, a symlink to the examples directory is created in build.rs along with the corresponding examples.rs module which declares examples known to work with wasm. To satisfy CI, the examples.rs committed to the repo must be empty since rustfmt does not call "build.rs". * Add .gitignore to wasm examples + fix clippy bugs The included .gitignore ignores the generated examples module. The examples.rs should remain committed, but it need not be ever changed. * Fix x11 keycodes StrOrChar conversion The newly introduced lifetime parameter must be specified exmplicitly. * Add --no-run to `cargo test` for wasm targets wasm targets cannot be run in the normal way. * Do not build the unit test module for wasm32 The tests cannot be run in the normal way anyways. Leaving this for a future PR to flush out. * Install necessary deps in wasm CI for macos/ubuntu * Add warnings for unimplemented file ops in web backend This commit exposes the error of the missing implementation for file dialogs in the web backend using log::warn. This is a temporary solution until the `open_file_sync` and `save_as_sync` functions propagate the error downstream using Result instead of Option. * Rework the generated examples in the wasm example This commit attempts a different approach at including the automatically generated examples from the parent directory. This method satisfies both rustfmt and cargo test as before, but it also doesn't modify any files in the source tree, keeping the diff clean after a build. * Rename switch example js entry point for wasm build This commit fixes the generated html file for the switch example to load "switch_demo" instead of "switch" for the switch example. The word switch conflicts with JavaScript's switch statement, which is the reason for this awkwardness. Co-authored-by: Leopold Luley <[email protected]>
- Loading branch information
Showing
55 changed files
with
1,922 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ members = [ | |
"druid-shell", | ||
"druid-derive", | ||
"docs/book_examples", | ||
"druid/examples/wasm", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2020 The xi-editor Authors. | ||
// | ||
// 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. | ||
|
||
//! Web implementation of features at the application scope. | ||
use super::clipboard::Clipboard; | ||
use crate::application::AppHandler; | ||
|
||
pub struct Application; | ||
|
||
impl Application { | ||
pub fn new(_handler: Option<Box<dyn AppHandler>>) -> Application { | ||
Application | ||
} | ||
|
||
pub fn run(&mut self) {} | ||
|
||
pub fn quit() {} | ||
|
||
pub fn clipboard() -> Clipboard { | ||
Clipboard | ||
} | ||
|
||
pub fn get_locale() -> String { | ||
//TODO ahem | ||
"en-US".into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2020 The xi-editor Authors. | ||
// | ||
// 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. | ||
|
||
//! Interactions with the browser pasteboard. | ||
use crate::clipboard::{ClipboardFormat, FormatId}; | ||
|
||
/// The browser clipboard. | ||
#[derive(Debug, Clone, Default)] | ||
pub struct Clipboard; | ||
|
||
impl Clipboard { | ||
/// Put a string onto the system clipboard. | ||
pub fn put_string(&mut self, _s: impl AsRef<str>) { | ||
log::warn!("unimplemented"); | ||
} | ||
|
||
/// Put multi-format data on the system clipboard. | ||
pub fn put_formats(&mut self, _formats: &[ClipboardFormat]) { | ||
log::warn!("unimplemented"); | ||
} | ||
|
||
/// Get a string from the system clipboard, if one is available. | ||
pub fn get_string(&self) -> Option<String> { | ||
log::warn!("unimplemented"); | ||
None | ||
} | ||
|
||
/// Given a list of supported clipboard types, returns the supported type which has | ||
/// highest priority on the system clipboard, or `None` if no types are supported. | ||
pub fn preferred_format(&self, _formats: &[FormatId]) -> Option<FormatId> { | ||
log::warn!("unimplemented"); | ||
None | ||
} | ||
|
||
/// Return data in a given format, if available. | ||
/// | ||
/// It is recommended that the `fmt` argument be a format returned by | ||
/// [`Clipboard::preferred_format`] | ||
pub fn get_format(&self, _format: FormatId) -> Option<Vec<u8>> { | ||
log::warn!("unimplemented"); | ||
None | ||
} | ||
|
||
pub fn available_type_names(&self) -> Vec<String> { | ||
log::warn!("unimplemented"); | ||
Vec::new() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2020 The xi-editor Authors. | ||
// | ||
// 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. | ||
|
||
//! Web platform errors. | ||
use wasm_bindgen::JsValue; | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Error { | ||
NoWindow, | ||
NoDocument, | ||
Js(JsValue), | ||
JsCast, | ||
NoElementById(String), | ||
NoContext, | ||
Unimplemented, | ||
} | ||
|
||
impl std::fmt::Display for Error { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
match self { | ||
Error::NoWindow => write!(f, "No global window found"), | ||
Error::NoDocument => write!(f, "No global document found"), | ||
Error::Js(err) => write!(f, "JavaScript error: {:?}", err.as_string()), | ||
Error::JsCast => write!(f, "JavaScript cast error"), | ||
Error::NoElementById(err) => write!(f, "get_element_by_id error: {}", err), | ||
Error::NoContext => write!(f, "Failed to get a draw context"), | ||
Error::Unimplemented => write!(f, "Requested an unimplemented feature"), | ||
} | ||
} | ||
} | ||
|
||
impl From<JsValue> for Error { | ||
fn from(js: JsValue) -> Error { | ||
Error::Js(js) | ||
} | ||
} | ||
|
||
impl std::error::Error for Error {} |
Oops, something went wrong.