Compare commits
2 Commits
99be46acf7
...
90800b9a21
| Author | SHA1 | Date | |
|---|---|---|---|
| 90800b9a21 | |||
| 32b58d121a |
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.5-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -105,6 +105,9 @@ struct SendState {
|
|||||||
session_token: String,
|
session_token: String,
|
||||||
status: String,
|
status: String,
|
||||||
connected_device: String,
|
connected_device: String,
|
||||||
|
qr_focus: bool,
|
||||||
|
qr_controls_height: f32,
|
||||||
|
qr_zoom: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
@@ -222,6 +225,9 @@ impl QftApp {
|
|||||||
session_token: String::new(),
|
session_token: String::new(),
|
||||||
status: "选择文件后生成二维码;手机扫码会自动配网并开始下载。".into(),
|
status: "选择文件后生成二维码;手机扫码会自动配网并开始下载。".into(),
|
||||||
connected_device: "等待 Android 扫码".into(),
|
connected_device: "等待 Android 扫码".into(),
|
||||||
|
qr_focus: false,
|
||||||
|
qr_controls_height: 220.0,
|
||||||
|
qr_zoom: 1.0,
|
||||||
},
|
},
|
||||||
pc: PcPeerState {
|
pc: PcPeerState {
|
||||||
mode: PcMode::Receive,
|
mode: PcMode::Receive,
|
||||||
@@ -633,9 +639,24 @@ impl QftApp {
|
|||||||
ui.heading("电脑 → Android · 扫码自动直传");
|
ui.heading("电脑 → Android · 扫码自动直传");
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.label("QFTSEND2 · 自动连接本地 Wi-Fi · 扫码后立即下载");
|
ui.label("QFTSEND2 · 自动连接本地 Wi-Fi · 扫码后立即下载");
|
||||||
|
if ui.add_enabled(
|
||||||
|
running,
|
||||||
|
egui::Button::new(if self.send.qr_focus { "退出专注二维码" } else { "专注二维码" }),
|
||||||
|
).clicked() {
|
||||||
|
self.send.qr_focus = !self.send.qr_focus;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
ui.add_space(10.0);
|
ui.add_space(10.0);
|
||||||
|
|
||||||
|
if running {
|
||||||
|
if self.send.qr_focus {
|
||||||
|
self.pc_to_phone_qr_focus_ui(ui, ctx);
|
||||||
|
} else {
|
||||||
|
self.pc_to_phone_resizable_qr_ui(ui, ctx);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
ui.heading("1 · 选择发送文件");
|
ui.heading("1 · 选择发送文件");
|
||||||
ui.horizontal_wrapped(|ui| {
|
ui.horizontal_wrapped(|ui| {
|
||||||
@@ -708,6 +729,148 @@ impl QftApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pc_to_phone_resizable_qr_ui(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) {
|
||||||
|
const DIVIDER_HEIGHT: f32 = 10.0;
|
||||||
|
let available_height = ui.available_height();
|
||||||
|
let min_controls_height = 150.0;
|
||||||
|
let min_qr_height = 260.0_f32.min((available_height * 0.55).max(180.0));
|
||||||
|
let max_controls_height = (available_height - min_qr_height - DIVIDER_HEIGHT)
|
||||||
|
.max(min_controls_height);
|
||||||
|
self.send.qr_controls_height = self
|
||||||
|
.send
|
||||||
|
.qr_controls_height
|
||||||
|
.clamp(min_controls_height, max_controls_height);
|
||||||
|
|
||||||
|
ui.allocate_ui_with_layout(
|
||||||
|
egui::vec2(ui.available_width(), self.send.qr_controls_height),
|
||||||
|
egui::Layout::top_down(egui::Align::Min),
|
||||||
|
|ui| {
|
||||||
|
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||||
|
self.pc_to_phone_running_controls(ui);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
let (divider_rect, divider_response) = ui.allocate_exact_size(
|
||||||
|
egui::vec2(ui.available_width(), DIVIDER_HEIGHT),
|
||||||
|
egui::Sense::drag(),
|
||||||
|
);
|
||||||
|
let divider_response = divider_response.on_hover_cursor(egui::CursorIcon::ResizeVertical);
|
||||||
|
let divider_color = if divider_response.dragged() || divider_response.hovered() {
|
||||||
|
ui.visuals().widgets.active.bg_fill
|
||||||
|
} else {
|
||||||
|
ui.visuals().widgets.inactive.bg_fill
|
||||||
|
};
|
||||||
|
ui.painter().rect_filled(
|
||||||
|
divider_rect.shrink2(egui::vec2(0.0, 3.0)),
|
||||||
|
3.0,
|
||||||
|
divider_color,
|
||||||
|
);
|
||||||
|
if divider_response.dragged() {
|
||||||
|
let delta_y = ui.input(|input| input.pointer.delta().y);
|
||||||
|
self.send.qr_controls_height = (self.send.qr_controls_height + delta_y)
|
||||||
|
.clamp(min_controls_height, max_controls_height);
|
||||||
|
ctx.request_repaint();
|
||||||
|
}
|
||||||
|
divider_response.on_hover_text("上下拖动,调整控制区和二维码区域的高度");
|
||||||
|
|
||||||
|
self.pc_to_phone_qr_panel(ui, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pc_to_phone_running_controls(&mut self, ui: &mut egui::Ui) {
|
||||||
|
ui.group(|ui| {
|
||||||
|
ui.heading("直传控制");
|
||||||
|
ui.horizontal_wrapped(|ui| {
|
||||||
|
if ui.button("停止直传").clicked() {
|
||||||
|
self.stop_sender();
|
||||||
|
}
|
||||||
|
ui.add(egui::Slider::new(&mut self.send.qr_zoom, 0.65..=1.0)
|
||||||
|
.text("二维码占比"));
|
||||||
|
});
|
||||||
|
if let Some(file) = &self.send.file {
|
||||||
|
ui.label(format!("文件:{} · {}", file.display(), human_bytes(self.send.file_size)));
|
||||||
|
}
|
||||||
|
ui.label(&self.send.status);
|
||||||
|
ui.small("拖动下方分隔条可为二维码腾出更多高度;也可切换到“专注二维码”。");
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.add_space(6.0);
|
||||||
|
ui.group(|ui| {
|
||||||
|
ui.label(format!("电脑:{}", self.local_device));
|
||||||
|
ui.label(format!("手机:{}", self.send.connected_device));
|
||||||
|
if let Some(ap) = &self.send.direct_ap {
|
||||||
|
ui.label(format!("临时网络:{}", ap.ssid));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pc_to_phone_qr_focus_ui(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) {
|
||||||
|
if ctx.input(|input| input.key_pressed(egui::Key::Escape)) {
|
||||||
|
self.send.qr_focus = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.horizontal_wrapped(|ui| {
|
||||||
|
if ui.button("退出专注二维码").clicked() {
|
||||||
|
self.send.qr_focus = false;
|
||||||
|
}
|
||||||
|
if ui.button("停止直传").clicked() {
|
||||||
|
self.stop_sender();
|
||||||
|
}
|
||||||
|
ui.add(egui::Slider::new(&mut self.send.qr_zoom, 0.65..=1.0)
|
||||||
|
.text("二维码占比"));
|
||||||
|
ui.small("按 Esc 也可退出专注模式");
|
||||||
|
});
|
||||||
|
ui.add_space(6.0);
|
||||||
|
self.pc_to_phone_qr_panel(ui, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pc_to_phone_qr_panel(&mut self, ui: &mut egui::Ui, focus: bool) {
|
||||||
|
let panel_height = ui.available_height();
|
||||||
|
if focus {
|
||||||
|
ui.group(|ui| {
|
||||||
|
ui.heading("手机扫码 · QFTSEND2");
|
||||||
|
ui.small("专注模式:二维码会始终按当前可用区域完整显示。");
|
||||||
|
if let Some(texture) = &self.send.pair_texture {
|
||||||
|
let available = ui.available_size();
|
||||||
|
let max_side = available.x.min((available.y - 32.0).max(1.0));
|
||||||
|
let side = (max_side * self.send.qr_zoom).max(1.0).min(max_side);
|
||||||
|
let side = snap_to_physical(side, ui.ctx().pixels_per_point());
|
||||||
|
ui.vertical_centered(|ui| {
|
||||||
|
ui.add_space(((available.y - side).max(0.0)) * 0.5);
|
||||||
|
ui.image((texture.id(), egui::vec2(side, side)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ui.set_min_height(panel_height);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.columns(2, |cols| {
|
||||||
|
cols[0].group(|ui| {
|
||||||
|
ui.heading("手机扫码 · QFTSEND2");
|
||||||
|
if let Some(texture) = &self.send.pair_texture {
|
||||||
|
let available = ui.available_size();
|
||||||
|
let max_side = available.x.min((available.y - 42.0).max(1.0));
|
||||||
|
let side = (max_side * self.send.qr_zoom).max(1.0).min(max_side);
|
||||||
|
let side = snap_to_physical(side, ui.ctx().pixels_per_point());
|
||||||
|
ui.vertical_centered(|ui| {
|
||||||
|
ui.image((texture.id(), egui::vec2(side, side)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ui.set_min_height(panel_height);
|
||||||
|
});
|
||||||
|
cols[1].group(|ui| {
|
||||||
|
ui.heading("发送状态");
|
||||||
|
ui.label(format!("电脑:{}", self.local_device));
|
||||||
|
ui.label(format!("手机:{}", self.send.connected_device));
|
||||||
|
ui.label(self.send.file.as_ref().map(|file| format!("文件:{}", file.display())).unwrap_or_default());
|
||||||
|
ui.small("二维码只在本次直传会话有效;停止直传后立即失效。");
|
||||||
|
ui.set_min_height(panel_height);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn optical_pick_file(&mut self, ctx: &egui::Context) {
|
fn optical_pick_file(&mut self, ctx: &egui::Context) {
|
||||||
let Some(path) = pick_file_safely() else { return };
|
let Some(path) = pick_file_safely() else { return };
|
||||||
match TransferSource::open(&path, DEFAULT_CHUNK_SIZE) {
|
match TransferSource::open(&path, DEFAULT_CHUNK_SIZE) {
|
||||||
@@ -958,6 +1121,7 @@ impl QftApp {
|
|||||||
self.send.direct_ap = None;
|
self.send.direct_ap = None;
|
||||||
self.send.pair_texture = None;
|
self.send.pair_texture = None;
|
||||||
self.send.session_token.clear();
|
self.send.session_token.clear();
|
||||||
|
self.send.qr_focus = false;
|
||||||
self.send.connected_device = "等待 Android 扫码".into();
|
self.send.connected_device = "等待 Android 扫码".into();
|
||||||
self.send.status = "直传已停止。".into();
|
self.send.status = "直传已停止。".into();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user