-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP support compiling example/hello_world for Android
- Loading branch information
Showing
4 changed files
with
82 additions
and
39 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
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 |
---|---|---|
@@ -1,3 +1,29 @@ | ||
## Linux, MacOS, Windows | ||
|
||
```sh | ||
cargo run -p hello_world | ||
``` | ||
|
||
## Android | ||
|
||
WIP, based on https://github.com/rust-windowing/android-ndk-rs#quick-start-hello-world-crate-on-android | ||
|
||
Install the Android NDK and SDK as per https://github.com/rust-windowing/android-ndk-rs#1-install-the-android-ndk-and-sdk | ||
|
||
Install Android target | ||
|
||
```sh | ||
rustup target add aarch64-linux-android | ||
``` | ||
|
||
Install cargo-apk | ||
|
||
```sh | ||
cargo install cargo-apk | ||
``` | ||
|
||
Run the Android app | ||
|
||
```sh | ||
cargo apk run --lib | ||
``` |
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,47 @@ | ||
use eframe::egui; | ||
|
||
// Android entry point | ||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
run() | ||
} | ||
|
||
pub fn run() { | ||
let options = eframe::NativeOptions::default(); | ||
eframe::run_native( | ||
"My egui App", | ||
options, | ||
Box::new(|_cc| Box::new(MyApp::default())), | ||
); | ||
} | ||
|
||
struct MyApp { | ||
name: String, | ||
age: u32, | ||
} | ||
|
||
impl Default for MyApp { | ||
fn default() -> Self { | ||
Self { | ||
name: "Arthur".to_owned(), | ||
age: 42, | ||
} | ||
} | ||
} | ||
|
||
impl eframe::App for MyApp { | ||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { | ||
egui::CentralPanel::default().show(ctx, |ui| { | ||
ui.heading("My egui Application"); | ||
ui.horizontal(|ui| { | ||
ui.label("Your name: "); | ||
ui.text_edit_singleline(&mut self.name); | ||
}); | ||
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age")); | ||
if ui.button("Click each year").clicked() { | ||
self.age += 1; | ||
} | ||
ui.label(format!("Hello '{}', age {}", self.name, self.age)); | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,43 +1,6 @@ | ||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release | ||
|
||
use eframe::egui; | ||
|
||
// Linux, MacOS, Windows entry point | ||
fn main() { | ||
let options = eframe::NativeOptions::default(); | ||
eframe::run_native( | ||
"My egui App", | ||
options, | ||
Box::new(|_cc| Box::new(MyApp::default())), | ||
); | ||
} | ||
|
||
struct MyApp { | ||
name: String, | ||
age: u32, | ||
} | ||
|
||
impl Default for MyApp { | ||
fn default() -> Self { | ||
Self { | ||
name: "Arthur".to_owned(), | ||
age: 42, | ||
} | ||
} | ||
} | ||
|
||
impl eframe::App for MyApp { | ||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { | ||
egui::CentralPanel::default().show(ctx, |ui| { | ||
ui.heading("My egui Application"); | ||
ui.horizontal(|ui| { | ||
ui.label("Your name: "); | ||
ui.text_edit_singleline(&mut self.name); | ||
}); | ||
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age")); | ||
if ui.button("Click each year").clicked() { | ||
self.age += 1; | ||
} | ||
ui.label(format!("Hello '{}', age {}", self.name, self.age)); | ||
}); | ||
} | ||
hello_world::run() | ||
} |