Skip to content

Commit 385de9b

Browse files
committed
Update dependencies and enhance UI: Refactor color settings, improve text box styles, and adjust button backgrounds
1 parent 5aa9923 commit 385de9b

File tree

2 files changed

+50
-34
lines changed

2 files changed

+50
-34
lines changed

File-Explorer/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ edition = "2021"
55

66
[dependencies]
77
druid = "0.8.3"
8-
regex = "1.7"
9-
walkdir = "2.3"
10-
im = "15.0"
11-
rfd = "0.11.0"
8+
regex = "1.5.5"
9+
walkdir = "2.3.2"
10+
rfd = "0.15.2"

File-Explorer/src/main.rs

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use druid::widget::{Button, Flex, Label, List, Scroll, TextBox};
22
use druid::{
33
AppDelegate, AppLauncher, Command, Data, DelegateCtx, Env, Lens, Selector, Target,
4-
Widget, WidgetExt, WindowDesc, commands, FileDialogOptions, theme, Color, // add import for Color
4+
Widget, WidgetExt, WindowDesc, commands, FileDialogOptions, theme, Color,
55
};
66
use regex::Regex;
7-
use std::path::{Path, PathBuf}; // added Path
7+
use std::path::{Path, PathBuf};
88
use std::sync::Arc;
99
use std::thread;
1010
use walkdir::WalkDir;
@@ -40,32 +40,17 @@ struct AppState {
4040
}
4141

4242
fn build_ui() -> impl Widget<AppState> {
43-
// Button to let the user choose a directory (using rfd for a native dialog)
43+
// Use string literals for the buttons instead of Label::new(...)
4444
let choose_dir_btn = Button::new("Choose Directory")
4545
.padding(8.0)
46-
.background(theme::BUTTON_DARK)
46+
.background(Color::rgb8(0x44, 0x44, 0x44))
4747
.on_click(|ctx, _data, _env| {
4848
ctx.submit_command(Command::new(commands::SHOW_OPEN_PANEL, FileDialogOptions::default(), Target::Auto));
4949
});
5050

51-
// Replace the static label with an editable text box for directory input.
52-
let directory_box = TextBox::new()
53-
.with_placeholder("Enter directory path")
54-
.with_text_size(14.0)
55-
.padding(8.0)
56-
.lens(AppState::root_path);
57-
58-
// Text box for entering the search term.
59-
let search_box = TextBox::new()
60-
.with_placeholder("Enter search term")
61-
.with_text_size(14.0)
62-
.padding(8.0)
63-
.lens(AppState::search_term);
64-
65-
// Button to kick off the search.
6651
let search_btn = Button::new("Search")
6752
.padding(8.0)
68-
.background(theme::BUTTON_DARK)
53+
.background(Color::rgb8(0x44, 0x44, 0x44))
6954
.on_click(|ctx, data: &mut AppState, _env| {
7055
let root = data.root_path.clone();
7156
let term = data.search_term.clone();
@@ -83,28 +68,52 @@ fn build_ui() -> impl Widget<AppState> {
8368
});
8469
});
8570

86-
// Create a list widget to display search results.
71+
// TextBox: dark background and white text; uses lens for state binding
72+
let directory_box = TextBox::new()
73+
.with_placeholder("Enter directory path")
74+
.with_text_size(14.0)
75+
.with_text_color(Color::WHITE)
76+
.padding(8.0)
77+
.background(Color::rgb8(0x33, 0x33, 0x33))
78+
.lens(AppState::root_path);
79+
80+
let search_box = TextBox::new()
81+
.with_placeholder("Enter search term")
82+
.with_text_size(14.0)
83+
.with_text_color(Color::WHITE)
84+
.padding(8.0)
85+
.background(Color::rgb8(0x33, 0x33, 0x33))
86+
.lens(AppState::search_term);
87+
88+
// List: style each item with white text, padding, dark background, border, and rounded corners.
8789
let results_list = List::new(|| {
8890
Label::new(|item: &String, _env: &_| format!("{}", item))
8991
.with_text_size(14.0)
90-
.padding(6.0)
92+
.with_text_color(Color::WHITE)
93+
.padding(8.0)
94+
.background(Color::rgb8(0x33, 0x33, 0x33))
95+
.border(Color::rgb8(0x55, 0x55, 0x55), 1.0)
96+
.rounded(4.0)
9197
.on_click(|_ctx, item: &mut String, _env| {
9298
open_path(item);
9399
})
94100
})
95101
.with_spacing(4.0)
96-
// Lens into the search_results field (which is now an Arc<Vec<String>>)
97102
.lens(AppState::search_results);
98103

99-
// Layout the UI elements vertically.
104+
let scroll = Scroll::new(results_list)
105+
.background(Color::BLACK)
106+
.expand();
107+
108+
// Main layout with black background
100109
Flex::column()
101-
.with_child(choose_dir_btn.padding(8.0))
102-
.with_child(directory_box.padding(8.0)) // new text box for directory input
103-
.with_child(search_box.padding(8.0))
104-
.with_child(search_btn.padding(8.0))
105-
.with_flex_child(Scroll::new(results_list).expand(), 1.0)
110+
.with_child(choose_dir_btn)
111+
.with_child(directory_box)
112+
.with_child(search_box)
113+
.with_child(search_btn)
114+
.with_flex_child(scroll, 1.0)
106115
.padding(12.0)
107-
.background(Color::BLACK) // changed background to black
116+
.background(Color::BLACK)
108117
}
109118

110119
/// Searches files and directories under the given directory whose names match the search term (case-insensitive)
@@ -179,6 +188,14 @@ fn main() {
179188

180189
// Launch the application with the delegate to handle background commands.
181190
AppLauncher::with_window(main_window)
191+
.configure_env(|env: &mut Env, _| {
192+
env.set(druid::theme::BACKGROUND_LIGHT, Color::BLACK);
193+
env.set(druid::theme::TEXT_COLOR, Color::WHITE);
194+
env.set(druid::theme::PLACEHOLDER_COLOR, Color::grey(0.6));
195+
// Replace WIDGET_BACKGROUND_COLOR with WINDOW_BACKGROUND_COLOR
196+
env.set(druid::theme::WINDOW_BACKGROUND_COLOR, Color::rgb8(0x33, 0x33, 0x33));
197+
env.set(druid::theme::BUTTON_DARK, Color::rgb8(0x44, 0x44, 0x44));
198+
})
182199
.delegate(Delegate)
183200
.launch(initial_state)
184201
.expect("Failed to launch application");

0 commit comments

Comments
 (0)