chore: apply clippy fixes and cargo fmt

- Fix 5 clippy warnings: collapsible ifs, useless format
- Format all source files with cargo fmt
This commit is contained in:
loki5512344 2026-06-19 17:03:20 +02:00
parent f983f12bec
commit 42c147a13e
12 changed files with 509 additions and 298 deletions

View file

@ -1,8 +1,8 @@
//! Переиспользуемая таблица файлов с нормальными колонками
use egui::{Color32, Id, RichText, Ui};
use crate::domain::file_entry::{EntryKind, FileEntry};
use crate::ui::drag::DragPayload;
use crate::ui::theme::*;
use egui::{Color32, Id, RichText, Ui};
pub fn format_size(bytes: Option<u64>) -> String {
match bytes {
@ -22,10 +22,18 @@ pub fn format_time(ts: Option<i64>) -> String {
}
#[derive(Clone, Copy, PartialEq)]
pub enum SortCol { Name, Size, Kind, Modified }
pub enum SortCol {
Name,
Size,
Kind,
Modified,
}
#[derive(Clone, Copy, PartialEq)]
pub enum SortDir { Asc, Desc }
pub enum SortDir {
Asc,
Desc,
}
pub struct FileTableResponse {
pub double_clicked: Option<String>,
@ -44,9 +52,9 @@ where
{
// Сортировка — читаем из egui memory
let sort_id = Id::new((id, "sort"));
let (sort_col, sort_dir) = ui.ctx().data_mut(|d| {
*d.get_temp_mut_or(sort_id, (SortCol::Name, SortDir::Asc))
});
let (sort_col, sort_dir) = ui
.ctx()
.data_mut(|d| *d.get_temp_mut_or(sort_id, (SortCol::Name, SortDir::Asc)));
let mut sorted = entries.to_vec();
let dotdot_entry = sorted.iter().position(|e| e.name == "..");
@ -60,15 +68,21 @@ where
(_, EntryKind::Dir) => std::cmp::Ordering::Less,
_ => std::cmp::Ordering::Equal,
};
if dir_cmp != std::cmp::Ordering::Equal { return dir_cmp; }
if dir_cmp != std::cmp::Ordering::Equal {
return dir_cmp;
}
let ord = match sort_col {
SortCol::Name => a.name.to_lowercase().cmp(&b.name.to_lowercase()),
SortCol::Size => a.size.unwrap_or(0).cmp(&b.size.unwrap_or(0)),
SortCol::Kind => format!("{:?}", a.kind).cmp(&format!("{:?}", b.kind)),
SortCol::Name => a.name.to_lowercase().cmp(&b.name.to_lowercase()),
SortCol::Size => a.size.unwrap_or(0).cmp(&b.size.unwrap_or(0)),
SortCol::Kind => format!("{:?}", a.kind).cmp(&format!("{:?}", b.kind)),
SortCol::Modified => a.modified.unwrap_or(0).cmp(&b.modified.unwrap_or(0)),
};
if sort_dir == SortDir::Desc { ord.reverse() } else { ord }
if sort_dir == SortDir::Desc {
ord.reverse()
} else {
ord
}
});
if let Some(dd) = dotdot {
@ -82,7 +96,12 @@ where
// Заголовки колонок
let header_frame = egui::Frame::none()
.fill(BG_HEADER)
.inner_margin(egui::Margin { left: 6.0, right: 6.0, top: 0.0, bottom: 0.0 });
.inner_margin(egui::Margin {
left: 6.0,
right: 6.0,
top: 0.0,
bottom: 0.0,
});
header_frame.show(ui, |ui| {
ui.set_min_height(22.0);
@ -93,20 +112,34 @@ where
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let mod_r = sort_header(ui, "Modified", 140.0, sort_col == SortCol::Modified, sort_dir);
if mod_r { new_sort = Some(toggle_sort(SortCol::Modified, sort_col, sort_dir)); }
let mod_r = sort_header(
ui,
"Modified",
140.0,
sort_col == SortCol::Modified,
sort_dir,
);
if mod_r {
new_sort = Some(toggle_sort(SortCol::Modified, sort_col, sort_dir));
}
let type_r = sort_header(ui, "Type", 40.0, sort_col == SortCol::Kind, sort_dir);
if type_r { new_sort = Some(toggle_sort(SortCol::Kind, sort_col, sort_dir)); }
if type_r {
new_sort = Some(toggle_sort(SortCol::Kind, sort_col, sort_dir));
}
let size_r = sort_header(ui, "Size", 70.0, sort_col == SortCol::Size, sort_dir);
if size_r { new_sort = Some(toggle_sort(SortCol::Size, sort_col, sort_dir)); }
if size_r {
new_sort = Some(toggle_sort(SortCol::Size, sort_col, sort_dir));
}
});
});
});
if let Some(s) = new_sort {
ui.ctx().data_mut(|d| { d.insert_temp(sort_id, s); });
ui.ctx().data_mut(|d| {
d.insert_temp(sort_id, s);
});
}
// разделитель
@ -137,18 +170,23 @@ where
let response = egui::Frame::none()
.fill(bg)
.inner_margin(egui::Margin { left: 6.0, right: 6.0, top: 0.0, bottom: 0.0 })
.inner_margin(egui::Margin {
left: 6.0,
right: 6.0,
top: 0.0,
bottom: 0.0,
})
.show(ui, |ui| {
ui.set_min_height(ROW_H);
ui.horizontal_centered(|ui| {
// иконка + имя
let name_text = if entry.name == ".." {
format!("⬆ ..")
"⬆ ..".to_string()
} else {
match entry.kind {
EntryKind::Dir => format!("📁 {}", entry.name),
EntryKind::Dir => format!("📁 {}", entry.name),
EntryKind::Symlink => format!("🔗 {}", entry.name),
EntryKind::File => {
EntryKind::File => {
let icon = file_icon(&entry.name);
format!("{} {}", icon, entry.name)
}
@ -165,9 +203,7 @@ where
if let Some(payload) = make_drag_payload(entry) {
ui.dnd_drag_source(row_id, payload, |ui| {
ui.label(
RichText::new(&name_text).color(name_col).size(12.0)
);
ui.label(RichText::new(&name_text).color(name_col).size(12.0));
});
} else {
ui.label(RichText::new(&name_text).color(name_col).size(12.0));
@ -185,12 +221,12 @@ where
ui.add_space(6.0);
let (type_str, type_col) = match entry.kind {
EntryKind::Dir => ("Dir", TEXT_DIM),
EntryKind::File => ("File", TEXT_HINT),
EntryKind::Dir => ("Dir", TEXT_DIM),
EntryKind::File => ("File", TEXT_HINT),
EntryKind::Symlink => ("Link", YELLOW),
};
let type_label = egui::Label::new(
RichText::new(type_str).color(type_col).size(11.0)
RichText::new(type_str).color(type_col).size(11.0),
)
.truncate();
ui.add_sized([38.0, ROW_H], type_label);
@ -217,7 +253,10 @@ where
}
});
FileTableResponse { double_clicked, clicked }
FileTableResponse {
double_clicked,
clicked,
}
}
fn sort_header(ui: &mut Ui, label: &str, min_w: f32, active: bool, dir: SortDir) -> bool {
@ -236,7 +275,11 @@ fn sort_header(ui: &mut Ui, label: &str, min_w: f32, active: bool, dir: SortDir)
fn toggle_sort(col: SortCol, cur_col: SortCol, cur_dir: SortDir) -> (SortCol, SortDir) {
if col == cur_col {
let new_dir = if cur_dir == SortDir::Asc { SortDir::Desc } else { SortDir::Asc };
let new_dir = if cur_dir == SortDir::Asc {
SortDir::Desc
} else {
SortDir::Asc
};
(col, new_dir)
} else {
(col, SortDir::Asc)
@ -246,18 +289,18 @@ fn toggle_sort(col: SortCol, cur_col: SortCol, cur_dir: SortDir) -> (SortCol, So
fn file_icon(name: &str) -> &'static str {
let ext = name.rsplit('.').next().unwrap_or("").to_lowercase();
match ext.as_str() {
"rs" => "🦀",
"rs" => "🦀",
"toml" | "yaml" | "yml" | "json" => "⚙",
"md" | "txt" | "log" => "📝",
"md" | "txt" | "log" => "📝",
"png" | "jpg" | "jpeg" | "gif" | "webp" | "svg" => "🖼",
"mp4" | "mkv" | "avi" | "mov" => "🎬",
"mp3" | "ogg" | "flac" | "wav" => "🎵",
"mp4" | "mkv" | "avi" | "mov" => "🎬",
"mp3" | "ogg" | "flac" | "wav" => "🎵",
"zip" | "tar" | "gz" | "bz2" | "xz" | "7z" => "📦",
"pdf" => "📕",
"sh" | "bash" | "fish" | "zsh" => "⚡",
"html" | "css" | "js" | "ts" => "🌐",
"py" => "🐍",
"java" | "class" | "jar" => "☕",
_ => "📄",
"pdf" => "📕",
"sh" | "bash" | "fish" | "zsh" => "⚡",
"html" | "css" | "js" | "ts" => "🌐",
"py" => "🐍",
"java" | "class" | "jar" => "☕",
_ => "📄",
}
}

View file

@ -1,14 +1,14 @@
use egui::{RichText, Ui};
use crate::domain::connection::ConnectionStatus;
use crate::domain::file_entry::{EntryKind, FileEntry};
use crate::domain::transfer::{TransferKind, TransferTask};
use crate::fs::local;
use crate::fs::remote::RemoteRegistry;
use crate::transfer::queue::TransferQueue;
use crate::ui::drag::{make_local_payload, DragPayload};
use crate::ui::panels::file_pane::{file_table, FileTableResponse, format_size};
use crate::ui::drag::{DragPayload, make_local_payload};
use crate::ui::panels::file_pane::{FileTableResponse, file_table, format_size};
use crate::ui::state::AppState;
use crate::ui::theme::*;
use egui::{RichText, Ui};
use std::sync::Arc;
fn parent_path(path: &str) -> String {
@ -88,29 +88,24 @@ fn render_inner(ui: &mut Ui, state: &mut AppState) {
.map(|t| t.status == ConnectionStatus::Connected)
.unwrap_or(false);
let FileTableResponse { double_clicked, .. } = file_table(
ui,
"local_table",
&entries,
&mut selected,
|entry| {
let FileTableResponse { double_clicked, .. } =
file_table(ui, "local_table", &entries, &mut selected, |entry| {
if has_connection {
make_local_payload(entry)
} else {
None
}
},
);
});
state.local_selected = selected;
if let Some(name) = double_clicked {
if name == ".." {
state.local_path = parent_path(&state.local_path);
} else if let Some(entry) = state.local_entries.iter().find(|e| e.name == name) {
if entry.kind == EntryKind::Dir {
state.local_path = entry.path.clone();
}
} else if let Some(entry) = state.local_entries.iter().find(|e| e.name == name)
&& entry.kind == EntryKind::Dir
{
state.local_path = entry.path.clone();
}
refresh_local(state);
}
@ -122,7 +117,12 @@ fn render_inner(ui: &mut Ui, state: &mut AppState) {
fn render_path_bar(ui: &mut Ui, state: &mut AppState) {
let frame = egui::Frame::none()
.fill(BG_PANEL)
.inner_margin(egui::Margin { left: 8.0, right: 8.0, top: 4.0, bottom: 4.0 });
.inner_margin(egui::Margin {
left: 8.0,
right: 8.0,
top: 4.0,
bottom: 4.0,
});
frame.show(ui, |ui| {
ui.horizontal(|ui| {
@ -132,12 +132,14 @@ fn render_path_bar(ui: &mut Ui, state: &mut AppState) {
.to_string_lossy()
.to_string();
let is_home = state.local_path == home;
let home_btn = egui::Button::new(
RichText::new("🏠").size(13.0)
)
.fill(if is_home { BG_ROW_SEL } else { egui::Color32::TRANSPARENT })
.rounding(4.0)
.min_size(egui::vec2(22.0, 22.0));
let home_btn = egui::Button::new(RichText::new("🏠").size(13.0))
.fill(if is_home {
BG_ROW_SEL
} else {
egui::Color32::TRANSPARENT
})
.rounding(4.0)
.min_size(egui::vec2(22.0, 22.0));
if ui.add(home_btn).clicked() {
state.local_path = home;
refresh_local(state);
@ -159,9 +161,8 @@ fn render_path_bar(ui: &mut Ui, state: &mut AppState) {
ui.label(RichText::new(*part).color(TEXT_PRIMARY).size(12.0).strong());
} else {
let path_snap = acc.clone();
let link = egui::Label::new(
RichText::new(*part).color(TEXT_DIM).size(12.0)
).sense(egui::Sense::click());
let link = egui::Label::new(RichText::new(*part).color(TEXT_DIM).size(12.0))
.sense(egui::Sense::click());
if ui.add(link).clicked() {
state.local_path = path_snap;
refresh_local(state);
@ -183,20 +184,24 @@ fn render_footer(ui: &mut Ui, state: &mut AppState) {
frame.show(ui, |ui| {
ui.horizontal(|ui| {
let count = state.local_entries.iter().filter(|e| e.name != "..").count();
let count = state
.local_entries
.iter()
.filter(|e| e.name != "..")
.count();
let total_size: u64 = state.local_entries.iter().filter_map(|e| e.size).sum();
ui.label(
RichText::new(format!("{} items", count))
.color(TEXT_DIM)
.size(11.0)
.size(11.0),
);
if total_size > 0 {
ui.label(
RichText::new(format!("({})", format_size(Some(total_size))))
.color(TEXT_HINT)
.size(11.0)
.size(11.0),
);
}

View file

@ -1,9 +1,9 @@
use egui::{Color32, RichText, Ui};
use crate::domain::transfer::{TaskState, TransferKind};
use crate::domain::transfer::TransferTask;
use crate::domain::transfer::{TaskState, TransferKind};
use crate::ui::panels::file_pane::format_size;
use crate::ui::state::AppState;
use crate::ui::theme::*;
use egui::{Color32, RichText, Ui};
pub fn render(ui: &mut Ui, state: &mut AppState, tasks: &[TransferTask]) {
// Заголовок очереди (всегда виден)
@ -15,7 +15,10 @@ pub fn render(ui: &mut Ui, state: &mut AppState, tasks: &[TransferTask]) {
ui.set_min_height(QUEUE_COLLAPSED_H);
ui.horizontal_centered(|ui| {
let arrow = if state.show_queue { "▼" } else { "▲" };
let n_active = tasks.iter().filter(|t| matches!(t.state, TaskState::Running | TaskState::Queued)).count();
let n_active = tasks
.iter()
.filter(|t| matches!(t.state, TaskState::Running | TaskState::Queued))
.count();
let title = if n_active > 0 {
format!("{} Transfer Queue ({})", arrow, n_active)
@ -24,7 +27,10 @@ pub fn render(ui: &mut Ui, state: &mut AppState, tasks: &[TransferTask]) {
};
let btn = egui::Button::new(
RichText::new(&title).color(TEXT_PRIMARY).size(12.0).strong()
RichText::new(&title)
.color(TEXT_PRIMARY)
.size(12.0)
.strong(),
)
.fill(Color32::TRANSPARENT)
.min_size(egui::vec2(0.0, QUEUE_COLLAPSED_H));
@ -35,7 +41,8 @@ pub fn render(ui: &mut Ui, state: &mut AppState, tasks: &[TransferTask]) {
// Аггрегированная скорость справа
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let agg_speed: u64 = tasks.iter()
let agg_speed: u64 = tasks
.iter()
.filter(|t| t.state == TaskState::Running)
.filter_map(|t| t.speed)
.sum();
@ -44,19 +51,29 @@ pub fn render(ui: &mut Ui, state: &mut AppState, tasks: &[TransferTask]) {
ui.label(
RichText::new(format!("{}/s", format_size(Some(agg_speed))))
.color(GREEN)
.size(11.0)
.size(11.0),
);
} else if !tasks.is_empty() {
let done = tasks.iter().filter(|t| t.state == TaskState::Completed).count();
let failed = tasks.iter().filter(|t| matches!(t.state, TaskState::Failed(_))).count();
let done = tasks
.iter()
.filter(|t| t.state == TaskState::Completed)
.count();
let failed = tasks
.iter()
.filter(|t| matches!(t.state, TaskState::Failed(_)))
.count();
ui.label(
RichText::new(format!("{}/{} done", done, tasks.len()))
.color(TEXT_DIM)
.size(11.0)
.size(11.0),
);
if failed > 0 {
ui.add_space(8.0);
ui.label(RichText::new(format!("{} failed", failed)).color(RED).size(11.0));
ui.label(
RichText::new(format!("{} failed", failed))
.color(RED)
.size(11.0),
);
}
}
});
@ -82,21 +99,26 @@ pub fn render(ui: &mut Ui, state: &mut AppState, tasks: &[TransferTask]) {
fn render_task(ui: &mut Ui, task: &TransferTask) {
let bg = match &task.state {
TaskState::Completed => Color32::from_rgb(22, 38, 24),
TaskState::Failed(_) => Color32::from_rgb(38, 22, 22),
TaskState::Running => Color32::from_rgb(22, 28, 42),
TaskState::Queued => BG_QUEUE,
_ => BG_QUEUE,
TaskState::Completed => Color32::from_rgb(22, 38, 24),
TaskState::Failed(_) => Color32::from_rgb(38, 22, 22),
TaskState::Running => Color32::from_rgb(22, 28, 42),
TaskState::Queued => BG_QUEUE,
_ => BG_QUEUE,
};
egui::Frame::none()
.fill(bg)
.inner_margin(egui::Margin { left: 10.0, right: 10.0, top: 4.0, bottom: 4.0 })
.inner_margin(egui::Margin {
left: 10.0,
right: 10.0,
top: 4.0,
bottom: 4.0,
})
.show(ui, |ui| {
ui.horizontal(|ui| {
// стрелка вида
let (arrow, arrow_col) = match task.kind {
TransferKind::Upload => ("↑", ACCENT),
TransferKind::Upload => ("↑", ACCENT),
TransferKind::Download => ("↓", GREEN),
};
ui.label(RichText::new(arrow).color(arrow_col).size(13.0).strong());
@ -104,19 +126,21 @@ fn render_task(ui: &mut Ui, task: &TransferTask) {
// имя файла
ui.label(
RichText::new(&task.file_name).color(TEXT_PRIMARY).size(12.0)
RichText::new(&task.file_name)
.color(TEXT_PRIMARY)
.size(12.0),
);
// статус справа
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let (state_str, state_col) = match &task.state {
TaskState::Queued => ("Queued", TEXT_HINT),
TaskState::Running => ("Uploading", ACCENT),
TaskState::Completed => ("✓ Done", GREEN),
TaskState::Failed(_) => ("× Failed", RED),
TaskState::Paused => ("Paused", YELLOW),
TaskState::Cancelled => ("Cancelled", TEXT_HINT),
TaskState::Retrying(_) => ("Retrying", YELLOW),
TaskState::Queued => ("Queued", TEXT_HINT),
TaskState::Running => ("Uploading", ACCENT),
TaskState::Completed => ("✓ Done", GREEN),
TaskState::Failed(_) => ("× Failed", RED),
TaskState::Paused => ("Paused", YELLOW),
TaskState::Cancelled => ("Cancelled", TEXT_HINT),
TaskState::Retrying(_) => ("Retrying", YELLOW),
};
ui.label(RichText::new(state_str).color(state_col).size(11.0));
});
@ -128,7 +152,7 @@ fn render_task(ui: &mut Ui, task: &TransferTask) {
let bar_col = match &task.state {
TaskState::Completed => GREEN,
TaskState::Failed(_) => RED,
_ => ACCENT,
_ => ACCENT,
};
let bar = egui::ProgressBar::new(pct)
@ -144,26 +168,26 @@ fn render_task(ui: &mut Ui, task: &TransferTask) {
format_size(Some(task.total_bytes))
))
.color(TEXT_DIM)
.size(11.0)
.size(11.0),
);
if let Some(speed) = task.speed {
if speed > 0 {
ui.label(
RichText::new(format!(" {}/s", format_size(Some(speed))))
.color(GREEN)
.size(11.0)
);
}
if let Some(speed) = task.speed
&& speed > 0
{
ui.label(
RichText::new(format!(" {}/s", format_size(Some(speed))))
.color(GREEN)
.size(11.0),
);
}
if let Some(eta) = task.eta_secs {
if eta > 0 {
ui.label(
RichText::new(format!(" ETA {}s", eta))
.color(TEXT_HINT)
.size(10.0)
);
}
if let Some(eta) = task.eta_secs
&& eta > 0
{
ui.label(
RichText::new(format!(" ETA {}s", eta))
.color(TEXT_HINT)
.size(10.0),
);
}
});

View file

@ -6,17 +6,23 @@ use crate::domain::file_entry::{EntryKind, FileEntry};
use crate::domain::transfer::{TransferKind, TransferTask};
use crate::fs::remote::RemoteRegistry;
use crate::transfer::queue::TransferQueue;
use crate::ui::drag::{make_remote_payload, DragPayload};
use crate::ui::panels::file_pane::{file_table, FileTableResponse, format_size};
use crate::ui::drag::{DragPayload, make_remote_payload};
use crate::ui::panels::file_pane::{FileTableResponse, file_table, format_size};
use crate::ui::state::{AppState, PendingRemoteList};
use crate::ui::theme::*;
pub fn remote_parent(path: &str) -> String {
let trimmed = path.trim_end_matches('/');
if trimmed.is_empty() || trimmed == "/" { return "/".into(); }
if trimmed.is_empty() || trimmed == "/" {
return "/".into();
}
if let Some(idx) = trimmed.rfind('/') {
let p = &trimmed[..idx];
if p.is_empty() { "/".into() } else { p.to_string() }
if p.is_empty() {
"/".into()
} else {
p.to_string()
}
} else {
"/".into()
}
@ -150,16 +156,21 @@ fn render_path_bar(
) {
let frame = egui::Frame::none()
.fill(BG_PANEL)
.inner_margin(egui::Margin { left: 8.0, right: 8.0, top: 4.0, bottom: 4.0 });
.inner_margin(egui::Margin {
left: 8.0,
right: 8.0,
top: 4.0,
bottom: 4.0,
});
frame.show(ui, |ui| {
ui.horizontal(|ui| {
// статус точка
let (dot, dot_col) = match state.tabs[tab_idx].status {
ConnectionStatus::Connected => ("●", GREEN),
ConnectionStatus::Connected => ("●", GREEN),
ConnectionStatus::Disconnected => ("○", TEXT_HINT),
ConnectionStatus::Connecting => ("◐", YELLOW),
ConnectionStatus::Error(_) => ("×", RED),
ConnectionStatus::Connecting => ("◐", YELLOW),
ConnectionStatus::Error(_) => ("×", RED),
};
ui.label(RichText::new(dot).color(dot_col).size(10.0));
ui.add_space(4.0);
@ -189,9 +200,8 @@ fn render_path_bar(
if is_last {
ui.label(RichText::new(*part).color(TEXT_PRIMARY).size(12.0).strong());
} else {
let link = egui::Label::new(
RichText::new(*part).color(TEXT_DIM).size(12.0)
).sense(egui::Sense::click());
let link = egui::Label::new(RichText::new(*part).color(TEXT_DIM).size(12.0))
.sense(egui::Sense::click());
if ui.add(link).clicked() {
state.tabs[tab_idx].remote_path = path_snap;
if !state.tabs[tab_idx].loading {
@ -237,7 +247,7 @@ fn render_footer(
ui.label(
RichText::new(format!("({})", format_size(Some(total_size))))
.color(TEXT_HINT)
.size(11.0)
.size(11.0),
);
}
@ -246,10 +256,10 @@ fn render_footer(
let refresh = egui::Button::new(RichText::new("⟳").color(ACCENT).size(14.0))
.fill(egui::Color32::TRANSPARENT)
.min_size(egui::vec2(20.0, 20.0));
if ui.add(refresh).on_hover_text("Refresh").clicked() {
if !state.tabs[tab_idx].loading {
trigger_list(state, tab_idx, registry, rt_handle);
}
if ui.add(refresh).on_hover_text("Refresh").clicked()
&& !state.tabs[tab_idx].loading
{
trigger_list(state, tab_idx, registry, rt_handle);
}
});
});
@ -289,5 +299,7 @@ pub fn trigger_list(
*result_clone.lock().unwrap() = Some(r);
});
state.pending_remote_list.push(PendingRemoteList { tab_idx, result });
state
.pending_remote_list
.push(PendingRemoteList { tab_idx, result });
}

View file

@ -1,8 +1,8 @@
//! Левая боковая панель — bookmarks + места
use egui::{RichText, Ui};
use crate::ui::panels::local_pane::refresh_local;
use crate::ui::state::AppState;
use crate::ui::theme::*;
use crate::ui::panels::local_pane::refresh_local;
use egui::{RichText, Ui};
pub fn render(ui: &mut Ui, state: &mut AppState) {
let frame = egui::Frame::none()
@ -69,12 +69,12 @@ pub fn render(ui: &mut Ui, state: &mut AppState) {
ui.label(
RichText::new(" No bookmarks yet")
.color(TEXT_HINT)
.size(11.0)
.size(11.0),
);
ui.label(
RichText::new(" Use ★ in file list")
.color(TEXT_HINT)
.size(10.0)
.size(10.0),
);
} else {
for bm in &custom {
@ -104,23 +104,32 @@ fn section_divider(ui: &mut Ui) {
}
fn sidebar_item(ui: &mut Ui, icon: &str, label: &str, active: bool, mut on_click: impl FnMut()) {
let bg = if active { BG_ROW_SEL } else { egui::Color32::TRANSPARENT };
let text_col = if active { egui::Color32::WHITE } else { TEXT_PRIMARY };
let bg = if active {
BG_ROW_SEL
} else {
egui::Color32::TRANSPARENT
};
let text_col = if active {
egui::Color32::WHITE
} else {
TEXT_PRIMARY
};
let resp = egui::Frame::none()
.fill(bg)
.rounding(4.0)
.inner_margin(egui::Margin { left: 10.0, right: 6.0, top: 2.0, bottom: 2.0 })
.inner_margin(egui::Margin {
left: 10.0,
right: 6.0,
top: 2.0,
bottom: 2.0,
})
.show(ui, |ui| {
ui.set_min_width(SIDEBAR_W - 8.0);
ui.horizontal(|ui| {
ui.label(RichText::new(icon).size(12.0));
ui.add_space(6.0);
ui.label(
RichText::new(label)
.color(text_col)
.size(12.0)
);
ui.label(RichText::new(label).color(text_col).size(12.0));
});
});
@ -131,14 +140,14 @@ fn sidebar_item(ui: &mut Ui, icon: &str, label: &str, active: bool, mut on_click
fn bookmark_icon(name: &str) -> &'static str {
match name {
"Home" => "🏠",
"Desktop" => "🖥",
"Home" => "🏠",
"Desktop" => "🖥",
"Documents" => "📄",
"Downloads" => "⬇",
"Pictures" => "🖼",
"Music" => "🎵",
"Videos" => "🎬",
_ => "📁",
"Pictures" => "🖼",
"Music" => "🎵",
"Videos" => "🎬",
_ => "📁",
}
}

View file

@ -1,8 +1,8 @@
use egui::RichText;
use crate::domain::connection::ConnectionStatus;
use crate::ui::panels::file_pane::format_size;
use crate::ui::state::AppState;
use crate::ui::theme::*;
use egui::RichText;
pub fn render(ui: &mut egui::Ui, state: &AppState) {
let frame = egui::Frame::none()
@ -16,12 +16,14 @@ pub fn render(ui: &mut egui::Ui, state: &AppState) {
ui.label(
RichText::new(&state.status_message)
.color(TEXT_DIM)
.size(11.0)
.size(11.0),
);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
// аггрегированная скорость
let agg: u64 = state.queue_tasks.iter()
let agg: u64 = state
.queue_tasks
.iter()
.filter(|t| t.state == crate::domain::transfer::TaskState::Running)
.filter_map(|t| t.speed)
.sum();
@ -30,13 +32,15 @@ pub fn render(ui: &mut egui::Ui, state: &AppState) {
ui.label(
RichText::new(format!("⬆⬇ {}/s", format_size(Some(agg))))
.color(GREEN)
.size(11.0)
.size(11.0),
);
ui.add_space(10.0);
}
// соединения
let connected = state.tabs.iter()
let connected = state
.tabs
.iter()
.filter(|t| t.status == ConnectionStatus::Connected)
.count();
let total = state.tabs.len();
@ -46,13 +50,13 @@ pub fn render(ui: &mut egui::Ui, state: &AppState) {
ui.label(
RichText::new(format!("● {}/{}", connected, total))
.color(dot_col)
.size(11.0)
.size(11.0),
);
} else {
ui.label(
RichText::new("○ Not connected")
.color(TEXT_HINT)
.size(11.0)
.size(11.0),
);
}
});

View file

@ -1,12 +1,17 @@
use egui::{Color32, RichText, Ui};
use crate::domain::connection::ConnectionStatus;
use crate::ui::state::AppState;
use crate::ui::theme::*;
use egui::{Color32, RichText, Ui};
pub fn render(ui: &mut Ui, state: &mut AppState) {
let frame = egui::Frame::none()
.fill(BG_BASE)
.inner_margin(egui::Margin { left: 6.0, right: 6.0, top: 0.0, bottom: 0.0 });
.inner_margin(egui::Margin {
left: 6.0,
right: 6.0,
top: 0.0,
bottom: 0.0,
});
frame.show(ui, |ui| {
ui.set_min_height(TABBAR_H);
@ -21,19 +26,33 @@ pub fn render(ui: &mut Ui, state: &mut AppState) {
let is_active = i == state.active_tab;
let (dot_col, dot) = match &tab.status {
ConnectionStatus::Connected => (GREEN, "●"),
ConnectionStatus::Connected => (GREEN, "●"),
ConnectionStatus::Disconnected => (TEXT_HINT, "○"),
ConnectionStatus::Connecting => (YELLOW, "◐"),
ConnectionStatus::Error(_) => (RED, "×"),
ConnectionStatus::Connecting => (YELLOW, "◐"),
ConnectionStatus::Error(_) => (RED, "×"),
};
let bg = if is_active { BG_TAB_ACTIVE } else { BG_TAB_IDLE };
let bg = if is_active {
BG_TAB_ACTIVE
} else {
BG_TAB_IDLE
};
let tcol = if is_active { TEXT_PRIMARY } else { TEXT_DIM };
let tab_response = egui::Frame::none()
.fill(bg)
.rounding(egui::Rounding { nw: 4.0, ne: 4.0, sw: 0.0, se: 0.0 })
.inner_margin(egui::Margin { left: 10.0, right: 4.0, top: 0.0, bottom: 0.0 })
.rounding(egui::Rounding {
nw: 4.0,
ne: 4.0,
sw: 0.0,
se: 0.0,
})
.inner_margin(egui::Margin {
left: 10.0,
right: 4.0,
top: 0.0,
bottom: 0.0,
})
.show(ui, |ui| {
ui.set_min_height(TABBAR_H);
ui.horizontal_centered(|ui| {
@ -41,19 +60,17 @@ pub fn render(ui: &mut Ui, state: &mut AppState) {
ui.label(RichText::new(dot).color(dot_col).size(9.0));
ui.add_space(4.0);
// название вкладки
let lbl = egui::Label::new(
RichText::new(&tab.label).color(tcol).size(12.0)
)
.sense(egui::Sense::click());
let lbl =
egui::Label::new(RichText::new(&tab.label).color(tcol).size(12.0))
.sense(egui::Sense::click());
if ui.add(lbl).clicked() {
// обрабатывается ниже
}
ui.add_space(6.0);
// кнопка закрытия
let close = egui::Label::new(
RichText::new("×").color(TEXT_HINT).size(14.0)
)
.sense(egui::Sense::click());
let close =
egui::Label::new(RichText::new("×").color(TEXT_HINT).size(14.0))
.sense(egui::Sense::click());
if ui.add(close).clicked() {
to_close = Some(i);
}

View file

@ -1,6 +1,6 @@
use egui::{Align, Layout, RichText, Ui};
use crate::ui::state::AppState;
use crate::ui::theme::*;
use egui::{Align, Layout, RichText, Ui};
pub fn render(ui: &mut Ui, state: &mut AppState) {
let frame = egui::Frame::none()
@ -112,34 +112,44 @@ fn render_history_popup(ui: &mut Ui, state: &mut AppState) {
.inner_margin(egui::Margin::same(8.0))
.show(ui, |ui| {
ui.set_width(260.0);
ui.label(RichText::new("Recent Connections").color(TEXT_DIM).size(11.0));
ui.label(
RichText::new("Recent Connections")
.color(TEXT_DIM)
.size(11.0),
);
ui.add_space(4.0);
if state.history.is_empty() {
ui.label(RichText::new("No history yet").color(TEXT_HINT));
} else {
egui::ScrollArea::vertical().max_height(160.0).show(ui, |ui| {
for entry in &state.history.clone() {
let label = format!("{}@{}:{}", entry.user, entry.host, entry.port);
let time = RichText::new(&entry.time).color(TEXT_HINT).size(10.0);
if ui
.add(
egui::Button::new(
RichText::new(&label).color(TEXT_PRIMARY).size(12.0),
egui::ScrollArea::vertical()
.max_height(160.0)
.show(ui, |ui| {
for entry in &state.history.clone() {
let label =
format!("{}@{}:{}", entry.user, entry.host, entry.port);
let time =
RichText::new(&entry.time).color(TEXT_HINT).size(10.0);
if ui
.add(
egui::Button::new(
RichText::new(&label)
.color(TEXT_PRIMARY)
.size(12.0),
)
.fill(egui::Color32::TRANSPARENT)
.min_size(egui::vec2(240.0, 24.0)),
)
.fill(egui::Color32::TRANSPARENT)
.min_size(egui::vec2(240.0, 24.0)),
)
.clicked()
{
state.connect_host = entry.host.clone();
state.connect_user = entry.user.clone();
state.connect_port = entry.port.to_string();
state.show_connect_dialog = true;
state.show_history = false;
.clicked()
{
state.connect_host = entry.host.clone();
state.connect_user = entry.user.clone();
state.connect_port = entry.port.to_string();
state.show_connect_dialog = true;
state.show_history = false;
}
ui.label(time);
}
ui.label(time);
}
});
});
}
ui.add_space(4.0);
if ui
@ -156,7 +166,11 @@ fn render_history_popup(ui: &mut Ui, state: &mut AppState) {
}
fn toolbar_btn(ui: &mut Ui, label: &str, active: bool, mut on_click: impl FnMut()) {
let fill = if active { BG_TAB_ACTIVE } else { egui::Color32::TRANSPARENT };
let fill = if active {
BG_TAB_ACTIVE
} else {
egui::Color32::TRANSPARENT
};
let text_col = if active { ACCENT } else { TEXT_PRIMARY };
let btn = egui::Button::new(RichText::new(label).color(text_col).size(12.0))
.fill(fill)