1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

eframe: selectively expose parts of the API based on compile target (#1867)

A lot of the `eframe` API is native-only or web-only. With this PR, only the parts that are implemented for each platform is exposed.

This means you'll need to add `#[cfg(target_arch = "wasm32")]` around code that uses the web-parts of the eframe API, and add `#[cfg(not(target_arch = "wasm32"))]` around the parts that are for native/desktop.
This commit is contained in:
Emil Ernerfeldt
2022-07-29 14:37:23 +02:00
committed by GitHub
parent 51052c08e9
commit 8c09804abd
7 changed files with 76 additions and 69 deletions

View File

@@ -136,7 +136,8 @@ impl BackendPanel {
ui.ctx().options().screen_reader = screen_reader;
}
if !frame.is_web() {
#[cfg(not(target_arch = "wasm32"))]
{
ui.separator();
if ui.button("Quit").clicked() {
frame.quit();
@@ -159,11 +160,10 @@ impl BackendPanel {
ui.label(".");
});
if let Some(web_info) = &frame.info().web_info {
ui.collapsing("Web info (location)", |ui| {
ui.monospace(format!("{:#?}", web_info.location));
});
}
#[cfg(target_arch = "wasm32")]
ui.collapsing("Web info (location)", |ui| {
ui.monospace(format!("{:#?}", frame.info().web_info.location));
});
// For instance: `eframe` web sets `pixels_per_point` every frame to force
// egui to use the same scale as the web zoom factor.
@@ -174,10 +174,11 @@ impl BackendPanel {
}
}
if !frame.is_web() {
#[cfg(not(target_arch = "wasm32"))]
{
ui.horizontal(|ui| {
if let Some(window_info) = &frame.info().window_info {
let mut fullscreen = window_info.fullscreen;
{
let mut fullscreen = frame.info().window_info.fullscreen;
ui.checkbox(&mut fullscreen, "🗖 Fullscreen")
.on_hover_text("Fullscreen the window");
frame.set_fullscreen(fullscreen);

View File

@@ -168,10 +168,9 @@ impl eframe::App for WrapApp {
}
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
if let Some(web_info) = frame.info().web_info.as_ref() {
if let Some(anchor) = web_info.location.hash.strip_prefix('#') {
self.state.selected_anchor = anchor.to_owned();
}
#[cfg(target_arch = "wasm32")]
if let Some(anchor) = frame.info().web_info.location.hash.strip_prefix('#') {
self.state.selected_anchor = anchor.to_owned();
}
if self.state.selected_anchor.is_empty() {