Skip to content

Commit

Permalink
- add history to search box
Browse files Browse the repository at this point in the history
- select search box text on focus for easier typing of new terms
  • Loading branch information
markusdd committed Mar 16, 2024
1 parent 7594dc9 commit 5cefd97
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
11 changes: 10 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "easyeda_to_kicad_lib_ui"
version = "1.1.2"
version = "1.2.0"
authors = ["Markus Krause <[email protected]>"]
edition = "2021"
rust-version = "1.72"
Expand All @@ -14,6 +14,8 @@ eframe = { version = "0.26.2", default-features = false, features = [
"glow", # Use the glow rendering backend. Alternative: "wgpu".
"persistence", # Enable restoring app state when restarting the app.
] }
# remove until PR merged egui-dropdown = "0.7.0"
egui-dropdown = { git = "https://github.com/markusdd/egui-dropdown.git", branch = "master" }
image = { version = "0.24.9", features = ["jpeg", "png"] }
egui_extras = { version = "0.26.2", features = ["all_loaders"] }
log = "0.4"
Expand All @@ -28,6 +30,7 @@ tempdir = "0.3.7"
glob = "0.3.1"
arboard = "3.3.2"


# You only need serde if you want app persistence:
serde = { version = "1", features = ["derive"] }

Expand Down
22 changes: 21 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::{
collections::VecDeque,
fs::{create_dir_all, read_to_string},
path::Path,
};

use arboard::Clipboard;
use downloader::{Download, Downloader};
use egui::{TextEdit, Vec2, Window};
use egui_dropdown::DropDownBox;
use egui_extras::{Column, TableBuilder};
use glob::glob;
use indexmap::{indexmap, IndexMap};
Expand All @@ -32,6 +34,7 @@ pub struct MyApp {
skip_existing: bool,
no_footprint: bool,
no_symbol: bool,
history: VecDeque<String>,
#[serde(skip)]
tempdir: Option<TempDir>,
#[serde(skip)]
Expand Down Expand Up @@ -60,6 +63,7 @@ impl Default for MyApp {
skip_existing: false,
no_footprint: false,
no_symbol: false,
history: VecDeque::with_capacity(11),
tempdir: TempDir::new("easyedatokicadlib").ok(),
settings_open: false,
is_init: false,
Expand Down Expand Up @@ -273,12 +277,28 @@ impl eframe::App for MyApp {
ui.vertical(|ui| {
ui.horizontal(|ui| {
ui.label("LCSC number or part URL: ");
ui.add(TextEdit::singleline(&mut self.part).desired_width(800.0));
// ui.add(TextEdit::singleline(&mut self.part).desired_width(800.0));

ui.add(
DropDownBox::from_iter(
&self.history,
"searchbox",
&mut self.part,
|ui, text| ui.selectable_label(false, text),
)
.desired_width(800.0)
.select_on_focus(true)
.filter_by_input(false),
);

if ui.button("Search").clicked() {
self.part = self.part.trim().to_owned();
if let Some(tabledata) = Self::get_part(self.part.as_str()) {
self.current_part = tabledata;
self.search_good = true;
// handle history
self.history.push_front(self.part.clone());
self.history.truncate(10);
} else {
self.search_good = false;
}
Expand Down

0 comments on commit 5cefd97

Please sign in to comment.