Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
markusdd committed Mar 10, 2024
1 parent c82f156 commit 42eb128
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 63 deletions.
86 changes: 24 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,38 @@
# eframe template
# EasyEDA to KiCAD Library UI

[![dependency status](https://deps.rs/repo/github/emilk/eframe_template/status.svg)](https://deps.rs/repo/github/emilk/eframe_template)
[![Build Status](https://github.com/emilk/eframe_template/workflows/CI/badge.svg)](https://github.com/emilk/eframe_template/actions?workflow=CI)
If you like this, a small donation is appreciated:

This is a template repo for [eframe](https://github.com/emilk/egui/tree/master/crates/eframe), a framework for writing apps using [egui](https://github.com/emilk/egui/).
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/R6R8DQO8C)

The goal is for this to be the simplest way to get started writing a GUI app in Rust.
![screenshot](assets/screenshot.png)

You can compile your app natively or for the web, and share it using Github Pages.
This is a GUI application written in Rust powered by the awesome egui framework to turn
EasyEDA PCB library components into KiCAD library elements (compatible with KiCAD 6 and upwards).

## Getting started
In the background it builds on the amazing work of the JLC2KICad_lib project to generate
the actual library files.

Start by clicking "Use this template" at https://github.com/emilk/eframe_template/ or follow [these instructions](https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template).
What it adds on top is a convenient UI to save your settings. Also, you can provide the Cxxxxx
number from JLCPCB/LCSC directly, or you can drop in either URL from their parts detail pages and the
tool will extract the part number for you.

Change the name of the crate: Chose a good name for your project, and change the name to it in:
* `Cargo.toml`
* Change the `package.name` from `eframe_template` to `your_crate`.
* Change the `package.authors`
* `main.rs`
* Change `eframe_template::TemplateApp` to `your_crate::TemplateApp`
* `index.html`
* Change the `<title>eframe template</title>` to `<title>your_crate</title>`. optional.
* `assets/sw.js`
* Change the `'./eframe_template.js'` to `./your_crate.js` (in `filesToCache` array)
* Change the `'./eframe_template_bg.wasm'` to `./your_crate_bg.wasm` (in `filesToCache` array)
It also gives you a pretty parts overview to make sure it is what you wanted, and it provides thumbnails
of the pictures LCSC provides of the parts. If you hover over them, you get the full size view.

### Learning about egui
And it gives you the option to directly open the parts pages, access the datasheet URL (if there is one) and
also save the datasheet in addition to the library conversion.

`src/app.rs` contains a simple example app. This is just to give some inspiration - most of it can be removed if you like.
## How to get going

The official egui docs are at <https://docs.rs/egui>. If you prefer watching a video introduction, check out <https://www.youtube.com/watch?v=NtUkr_z7l84>. For inspiration, check out the [the egui web demo](https://emilk.github.io/egui/index.html) and follow the links in it to its source code.
You can clone this repository and just run `cargo build --release`, provided you have rust installed (use `rustup`, it's easy).
(release builds will be provided in the future)

### Testing locally
Also, you need https://github.com/TousstNicolas/JLC2KiCad_lib
installed on your machine. Install instructions are provided at the linked repo, easiest option is probably via `pip` if Python is already installed.

Make sure you are using the latest version of stable rust by running `rustup update`.
After you have the prerequisites, launch the application and adjust the settings to your liking, most importantly, provide a valid path to the JLC2KiCad_lib application, either by using an absolute path or making sure it is in your systems $PATH variable.

`cargo run --release`
![settings](assets/settings.png)

On Linux you need to first run:

`sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev`

On Fedora Rawhide you need to run:

`dnf install clang clang-devel clang-tools-extra libxkbcommon-devel pkg-config openssl-devel libxcb-devel gtk3-devel atk fontconfig-devel`

### Web Locally

You can compile your app to [WASM](https://en.wikipedia.org/wiki/WebAssembly) and publish it as a web page.

We use [Trunk](https://trunkrs.dev/) to build for web target.
1. Install the required target with `rustup target add wasm32-unknown-unknown`.
2. Install Trunk with `cargo install --locked trunk`.
3. Run `trunk serve` to build and serve on `http://127.0.0.1:8080`. Trunk will rebuild automatically if you edit the project.
4. Open `http://127.0.0.1:8080/index.html#dev` in a browser. See the warning below.

> `assets/sw.js` script will try to cache our app, and loads the cached version when it cannot connect to server allowing your app to work offline (like PWA).
> appending `#dev` to `index.html` will skip this caching, allowing us to load the latest builds during development.
### Web Deploy
1. Just run `trunk build --release`.
2. It will generate a `dist` directory as a "static html" website
3. Upload the `dist` directory to any of the numerous free hosting websites including [GitHub Pages](https://docs.github.com/en/free-pro-team@latest/github/working-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site).
4. we already provide a workflow that auto-deploys our app to GitHub pages if you enable it.
> To enable Github Pages, you need to go to Repository -> Settings -> Pages -> Source -> set to `gh-pages` branch and `/` (root).
>
> If `gh-pages` is not available in `Source`, just create and push a branch called `gh-pages` and it should be available.
You can test the template app at <https://emilk.github.io/eframe_template/>.

## Updating egui

As of 2023, egui is in active development with frequent releases with breaking changes. [eframe_template](https://github.com/emilk/eframe_template/) will be updated in lock-step to always use the latest version of egui.

When updating `egui` and `eframe` it is recommended you do so one version at the time, and read about the changes in [the egui changelog](https://github.com/emilk/egui/blob/master/CHANGELOG.md) and [eframe changelog](https://github.com/emilk/egui/blob/master/crates/eframe/CHANGELOG.md).
After entering everything close the program once to save everything.
The application leverages the save state mechanism of egui to persist your settings.
Binary file added assets/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct MyApp {
symbol_lib_dir: String,
footprint_lib: String,
model_dir: String,
datasheet_dir: String,
download_datasheet: bool,
skip_existing: bool,
no_footprint: bool,
Expand All @@ -39,6 +40,7 @@ impl Default for MyApp {
symbol_lib_dir: "symbol".to_owned(),
footprint_lib: "footprint".to_owned(),
model_dir: "packages3d".to_owned(),
datasheet_dir: "~/kicad_libs/datasheets".to_owned(),
download_datasheet: true,
skip_existing: false,
no_footprint: false,
Expand Down Expand Up @@ -405,7 +407,7 @@ impl eframe::App for MyApp {
ui.checkbox(&mut self.no_symbol, "Skip symbol generation");
ui.label("Path of JLC2KiCadLib executable:");
ui.add(TextEdit::singleline(&mut self.exe_path).desired_width(800.0));
ui.label("Output directory for the generated library:");
ui.label("Output directory for the generated library (absolute path):");
ui.add(
TextEdit::singleline(&mut self.output_path).desired_width(800.0),
);
Expand All @@ -427,6 +429,10 @@ impl eframe::App for MyApp {
"Name of the 3D model directory (relative to footprint directory):",
);
ui.add(TextEdit::singleline(&mut self.model_dir).desired_width(800.0));
ui.label("Output directory for downloaded datasheets (absolute path):");
ui.add(
TextEdit::singleline(&mut self.datasheet_dir).desired_width(800.0),
);
if ui.button("Close").clicked() {
self.settings_open = false;
}
Expand Down

0 comments on commit 42eb128

Please sign in to comment.