Merge pull request #95 from Team-LJY/fix/linux-dialog-progress-window
Linux 파일 선택 멈춤, 큰 파일 진행률, 작업 진행 창과 Wayland 제목 표시줄 수정
- 작성자
- LeeJunyoung
- 작성 시각
- 커밋
185b606521c27dad622e3076aeaef66dee89e252
변경된 파일 10개
+1,281-26| @@ -198,8 +198,16 @@ impl<W: Write> Job<W> { | ||
| 198 | 198 | let extract = matches!(start.action, Action::Extract { .. }); |
| 199 | 199 | let path = source.to_path()?; |
| 200 | 200 | self.progress(Stage::Read, 0, None, 0)?; |
| 201 | 삭제: let mut snapshot = | |
| 202 | 삭제: crate::spool::Snapshot::open(&path, start.limits.input, &mut || self.check())?; | |
| 201 | 추가: let mut snapshot = crate::spool::Snapshot::open_reporting( | |
| 202 | 추가: &path, | |
| 203 | 추가: start.limits.input, | |
| 204 | 추가: &mut |step| match step { | |
| 205 | 추가: crate::spool::Step::Check => self.check(), | |
| 206 | 추가: crate::spool::Step::Read { bytes, total } => { | |
| 207 | 추가: self.progress(Stage::Read, bytes, Some(total), 0) | |
| 208 | 추가: } | |
| 209 | 추가: }, | |
| 210 | 추가: )?; | |
| 203 | 211 | if let Action::Extract { |
| 204 | 212 | list_id: Some(expected), |
| 205 | 213 | .. |
| @@ -70,6 +70,12 @@ pub(crate) fn temporary() -> Result<File> { | ||
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 추가: #[derive(Clone, Copy, Debug)] | |
| 74 | 추가: pub(crate) enum Step { | |
| 75 | 추가: Check, | |
| 76 | 추가: Read { bytes: u64, total: u64 }, | |
| 77 | 추가: } | |
| 78 | 추가: | |
| 73 | 79 | pub(crate) struct Snapshot { |
| 74 | 80 | pub file: File, |
| 75 | 81 | pub len: u64, |
| @@ -77,7 +83,12 @@ pub(crate) struct Snapshot { | ||
| 77 | 83 | pub hash: [u8; 32], |
| 78 | 84 | } |
| 79 | 85 | impl Snapshot { |
| 80 | 삭제: pub fn open(path: &Path, limit: u64, check: &mut impl FnMut() -> Result<()>) -> Result<Self> { | |
| 86 | 추가: /// 원본을 임시 파일로 복사하는 동안 읽은 바이트와 전체 크기를 함께 알림. | |
| 87 | 추가: pub fn open_reporting( | |
| 88 | 추가: path: &Path, | |
| 89 | 추가: limit: u64, | |
| 90 | 추가: step: &mut impl FnMut(Step) -> Result<()>, | |
| 91 | 추가: ) -> Result<Self> { | |
| 81 | 92 | let mut options = OpenOptions::new(); |
| 82 | 93 | options.read(true); |
| 83 | 94 | #[cfg(unix)] |
| @@ -91,7 +102,7 @@ impl Snapshot { | ||
| 91 | 102 | options.share_mode(1); |
| 92 | 103 | } |
| 93 | 104 | let mut source = options.open(path).map_err(|_| ErrorCode::Io)?; |
| 94 | 삭제: let snapshot = Self::capture(&mut source, limit, check)?; | |
| 105 | 추가: let snapshot = Self::capture_reporting(&mut source, limit, step)?; | |
| 95 | 106 | let named = options.open(path).map_err(|_| ErrorCode::SourceChanged)?; |
| 96 | 107 | if filesystem::object(&named)? != snapshot.object |
| 97 | 108 | || !named.metadata().map_err(|_| ErrorCode::Io)?.is_file() |
| @@ -104,6 +115,16 @@ impl Snapshot { | ||
| 104 | 115 | source: &mut File, |
| 105 | 116 | limit: u64, |
| 106 | 117 | check: &mut impl FnMut() -> Result<()>, |
| 118 | 추가: ) -> Result<Self> { | |
| 119 | 추가: Self::capture_reporting(source, limit, &mut |step| match step { | |
| 120 | 추가: Step::Check => check(), | |
| 121 | 추가: Step::Read { .. } => Ok(()), | |
| 122 | 추가: }) | |
| 123 | 추가: } | |
| 124 | 추가: fn capture_reporting( | |
| 125 | 추가: source: &mut File, | |
| 126 | 추가: limit: u64, | |
| 127 | 추가: step: &mut impl FnMut(Step) -> Result<()>, | |
| 107 | 128 | ) -> Result<Self> { |
| 108 | 129 | let before = source.metadata().map_err(|_| ErrorCode::Io)?; |
| 109 | 130 | if !before.is_file() { |
| @@ -119,8 +140,10 @@ impl Snapshot { | ||
| 119 | 140 | let mut buffer = zeroize::Zeroizing::new([0; 65536]); |
| 120 | 141 | let mut hash = Sha256::new(); |
| 121 | 142 | let mut len = 0u64; |
| 143 | 추가: let total = before.len(); | |
| 144 | 추가: let mut reported = std::time::Instant::now(); | |
| 122 | 145 | loop { |
| 123 | 삭제: check()?; | |
| 146 | 추가: step(Step::Check)?; | |
| 124 | 147 | let n = source.read(&mut buffer[..]).map_err(|_| ErrorCode::Io)?; |
| 125 | 148 | if n == 0 { |
| 126 | 149 | break; |
| @@ -132,7 +155,13 @@ impl Snapshot { | ||
| 132 | 155 | file.write_all(&buffer[..n]) |
| 133 | 156 | .map_err(crate::space::io_error)?; |
| 134 | 157 | hash.update(&buffer[..n]); |
| 158 | 추가: // 큰 파일에서도 진행이 보이도록 일정 간격으로만 알림. | |
| 159 | 추가: if reported.elapsed() >= std::time::Duration::from_millis(200) { | |
| 160 | 추가: step(Step::Read { bytes: len, total })?; | |
| 161 | 추가: reported = std::time::Instant::now(); | |
| 162 | 추가: } | |
| 135 | 163 | } |
| 164 | 추가: step(Step::Read { bytes: len, total })?; | |
| 136 | 165 | let after = source.metadata().map_err(|_| ErrorCode::Io)?; |
| 137 | 166 | if filesystem::object(&source)? != object |
| 138 | 167 | || before.len() != len |
| @@ -19,8 +19,20 @@ pub struct DialogRequest { | ||
| 19 | 19 | pub file_name: String, |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 추가: pub type DialogAnswer = Result<Option<Vec<PathBuf>>, String>; | |
| 23 | 추가: | |
| 24 | 추가: pub enum PendingDialog { | |
| 25 | 추가: Ready(DialogAnswer), | |
| 26 | 추가: Waiting(std::sync::mpsc::Receiver<DialogAnswer>), | |
| 27 | 추가: } | |
| 28 | 추가: | |
| 22 | 29 | pub trait Dialogs { |
| 23 | 삭제: fn choose(&mut self, request: DialogRequest) -> Result<Option<Vec<PathBuf>>, String>; | |
| 30 | 추가: fn choose(&mut self, request: DialogRequest) -> DialogAnswer; | |
| 31 | 추가: | |
| 32 | 추가: /// 선택 창을 연다. 기본 구현은 응답을 바로 돌려준다. | |
| 33 | 추가: fn start(&mut self, request: DialogRequest) -> PendingDialog { | |
| 34 | 추가: PendingDialog::Ready(self.choose(request)) | |
| 35 | 추가: } | |
| 24 | 36 | } |
| 25 | 37 | |
| 26 | 38 | pub fn archive_filters() -> Vec<(&'static str, Vec<String>)> { |
| @@ -62,6 +74,20 @@ impl Dialogs for NativeDialogs { | ||
| 62 | 74 | })) |
| 63 | 75 | .unwrap_or_else(|_| Err(DIALOG_UNAVAILABLE.into())) |
| 64 | 76 | } |
| 77 | 추가: | |
| 78 | 추가: // 포털 응답을 화면 스레드에서 기다리면 창이 이벤트를 처리하지 못해 "응답 없음"으로 표시됨. | |
| 79 | 추가: #[cfg(target_os = "linux")] | |
| 80 | 추가: fn start(&mut self, request: DialogRequest) -> PendingDialog { | |
| 81 | 추가: let (sender, receiver) = std::sync::mpsc::channel(); | |
| 82 | 추가: match std::thread::Builder::new() | |
| 83 | 추가: .name("zipelo-file-dialog".into()) | |
| 84 | 추가: .spawn(move || { | |
| 85 | 추가: let _ = sender.send(NativeDialogs.choose(request)); | |
| 86 | 추가: }) { | |
| 87 | 추가: Ok(_) => PendingDialog::Waiting(receiver), | |
| 88 | 추가: Err(_) => PendingDialog::Ready(Err(DIALOG_UNAVAILABLE.into())), | |
| 89 | 추가: } | |
| 90 | 추가: } | |
| 65 | 91 | } |
| 66 | 92 | |
| 67 | 93 | #[cfg(target_os = "linux")] |
| @@ -1,9 +1,13 @@ | ||
| 1 | 1 | use crate::{ |
| 2 | 2 | archive_browser as browser, |
| 3 | 삭제: archive_dialog::{DialogRequest, Dialogs, NativeDialogs, Purpose}, | |
| 3 | 추가: archive_dialog::{ | |
| 4 | 추가: DIALOG_UNAVAILABLE, DialogAnswer, DialogRequest, Dialogs, NativeDialogs, PendingDialog, | |
| 5 | 추가: Purpose, | |
| 6 | 추가: }, | |
| 4 | 7 | archive_present as present, |
| 5 | 8 | archive_theme::{self as theme, Icon}, |
| 6 | 9 | archive_ui::*, |
| 10 | 추가: window_frame, | |
| 7 | 11 | }; |
| 8 | 12 | use eframe::egui::{self, Align, Layout, RichText}; |
| 9 | 13 | use std::{ |
| @@ -11,6 +15,37 @@ use std::{ | ||
| 11 | 15 | path::{Path, PathBuf}, |
| 12 | 16 | }; |
| 13 | 17 | |
| 18 | 추가: const WORK_WIDTH: f32 = 480.0; | |
| 19 | 추가: const WORK_MIN_HEIGHT: f32 = 96.0; | |
| 20 | 추가: const WORK_MAX_HEIGHT: f32 = 520.0; | |
| 21 | 추가: const WORK_RESULT_MAX_HEIGHT: f32 = 220.0; | |
| 22 | 추가: | |
| 23 | 추가: /// 작업 진행·결과를 보여주는 자식 창의 위치 상태. | |
| 24 | 추가: /// 부모 창 기준 상대 위치를 기억해 두고, 부모 창이 움직이면 같은 상대 위치로 따라감. | |
| 25 | 추가: struct WorkWindow { | |
| 26 | 추가: open: bool, | |
| 27 | 추가: initial: Option<egui::Pos2>, | |
| 28 | 추가: offset: Option<egui::Vec2>, | |
| 29 | 추가: parent: Option<egui::Pos2>, | |
| 30 | 추가: expected: Option<egui::Pos2>, | |
| 31 | 추가: settle_until: f64, | |
| 32 | 추가: height: f32, | |
| 33 | 추가: } | |
| 34 | 추가: | |
| 35 | 추가: impl Default for WorkWindow { | |
| 36 | 추가: fn default() -> Self { | |
| 37 | 추가: Self { | |
| 38 | 추가: open: false, | |
| 39 | 추가: initial: None, | |
| 40 | 추가: offset: None, | |
| 41 | 추가: parent: None, | |
| 42 | 추가: expected: None, | |
| 43 | 추가: settle_until: 0.0, | |
| 44 | 추가: height: 168.0, | |
| 45 | 추가: } | |
| 46 | 추가: } | |
| 47 | 추가: } | |
| 48 | 추가: | |
| 14 | 49 | struct Marquee { |
| 15 | 50 | // 스크롤 중에도 시작점을 목록 좌표로 유지함. |
| 16 | 51 | origin: egui::Pos2, |
| @@ -39,6 +74,10 @@ pub struct ArchiveApp { | ||
| 39 | 74 | selected_only: bool, |
| 40 | 75 | method: Method, |
| 41 | 76 | dialogs: Box<dyn Dialogs>, |
| 77 | 추가: picker: Option<(Purpose, std::sync::mpsc::Receiver<DialogAnswer>)>, | |
| 78 | 추가: work: WorkWindow, | |
| 79 | 추가: custom_frame: bool, | |
| 80 | 추가: release_after_move: bool, | |
| 42 | 81 | folder: String, |
| 43 | 82 | search: String, |
| 44 | 83 | list_anchor: Option<usize>, |
| @@ -77,6 +116,10 @@ impl ArchiveApp { | ||
| 77 | 116 | selected_only: false, |
| 78 | 117 | method: Method::Deflate, |
| 79 | 118 | dialogs: Box::new(NativeDialogs), |
| 119 | 추가: picker: None, | |
| 120 | 추가: work: WorkWindow::default(), | |
| 121 | 추가: custom_frame: false, | |
| 122 | 추가: release_after_move: false, | |
| 80 | 123 | folder: String::new(), |
| 81 | 124 | search: String::new(), |
| 82 | 125 | list_anchor: None, |
| @@ -103,6 +146,11 @@ impl ArchiveApp { | ||
| 103 | 146 | self.dialogs = dialogs; |
| 104 | 147 | } |
| 105 | 148 | |
| 149 | 추가: /// 운영체제가 창 테두리를 그려 주지 않을 때(GNOME Wayland) 제목 표시줄을 직접 그림. | |
| 150 | 추가: pub fn set_custom_frame(&mut self, custom: bool) { | |
| 151 | 추가: self.custom_frame = custom; | |
| 152 | 추가: } | |
| 153 | 추가: | |
| 106 | 154 | pub fn browse_folder(&mut self, folder: &str) { |
| 107 | 155 | self.folder = folder.trim_matches('/').to_owned(); |
| 108 | 156 | self.search.clear(); |
| @@ -143,6 +191,10 @@ impl ArchiveApp { | ||
| 143 | 191 | } |
| 144 | 192 | |
| 145 | 193 | fn start(&mut self, request: Start) -> bool { |
| 194 | 추가: // 파일 선택 창이 응답을 기다리는 동안에는 어느 창에서도 새 작업을 시작하지 않음. | |
| 195 | 추가: if self.picker.is_some() { | |
| 196 | 추가: return false; | |
| 197 | 추가: } | |
| 146 | 198 | self.last_request = Some(request.clone()); |
| 147 | 199 | self.dismissed = false; |
| 148 | 200 | self.details = false; |
| @@ -306,7 +358,7 @@ impl ArchiveApp { | ||
| 306 | 358 | } |
| 307 | 359 | |
| 308 | 360 | fn open_picker(&mut self, purpose: Purpose) { |
| 309 | 삭제: if self.model.busy() { | |
| 361 | 추가: if self.model.busy() || self.picker.is_some() { | |
| 310 | 362 | return; |
| 311 | 363 | } |
| 312 | 364 | let gzip = self |
| @@ -345,10 +397,28 @@ impl ArchiveApp { | ||
| 345 | 397 | self.zip_name.clone() |
| 346 | 398 | }, |
| 347 | 399 | }; |
| 348 | 삭제: let answer = self.dialogs.choose(request); | |
| 349 | 삭제: if answer.is_ok() | |
| 350 | 삭제: && self.ui_error.as_deref() == Some(crate::archive_dialog::DIALOG_UNAVAILABLE) | |
| 351 | 삭제: { | |
| 400 | 추가: match self.dialogs.start(request) { | |
| 401 | 추가: PendingDialog::Ready(answer) => self.apply_picker(purpose, answer), | |
| 402 | 추가: PendingDialog::Waiting(receiver) => self.picker = Some((purpose, receiver)), | |
| 403 | 추가: } | |
| 404 | 추가: } | |
| 405 | 추가: | |
| 406 | 추가: fn poll_picker(&mut self) { | |
| 407 | 추가: let Some((purpose, receiver)) = &self.picker else { | |
| 408 | 추가: return; | |
| 409 | 추가: }; | |
| 410 | 추가: let purpose = *purpose; | |
| 411 | 추가: let answer = match receiver.try_recv() { | |
| 412 | 추가: Ok(answer) => answer, | |
| 413 | 추가: Err(std::sync::mpsc::TryRecvError::Empty) => return, | |
| 414 | 추가: Err(std::sync::mpsc::TryRecvError::Disconnected) => Err(DIALOG_UNAVAILABLE.into()), | |
| 415 | 추가: }; | |
| 416 | 추가: self.picker = None; | |
| 417 | 추가: self.apply_picker(purpose, answer); | |
| 418 | 추가: } | |
| 419 | 추가: | |
| 420 | 추가: fn apply_picker(&mut self, purpose: Purpose, answer: DialogAnswer) { | |
| 421 | 추가: if answer.is_ok() && self.ui_error.as_deref() == Some(DIALOG_UNAVAILABLE) { | |
| 352 | 422 | self.ui_error = None; |
| 353 | 423 | } |
| 354 | 424 | match answer { |
| @@ -479,19 +549,23 @@ impl ArchiveApp { | ||
| 479 | 549 | self.initialized = true; |
| 480 | 550 | } |
| 481 | 551 | self.poll(); |
| 552 | 추가: self.poll_picker(); | |
| 482 | 553 | let challenge = self.model.challenge.map(|(id, _, _)| id); |
| 483 | 554 | let new_challenge = challenge != self.password_challenge; |
| 484 | 555 | if new_challenge || challenge.is_none() { |
| 485 | 556 | self.clear_password(); |
| 486 | 557 | } |
| 487 | 558 | self.password_challenge = challenge; |
| 488 | 삭제: self.on_drop(ctx.input(|i| { | |
| 559 | 추가: let dropped = ctx.input(|i| { | |
| 489 | 560 | i.raw |
| 490 | 561 | .dropped_files |
| 491 | 562 | .iter() |
| 492 | 563 | .map(|file| file.path().to_path_buf()) |
| 493 | 564 | .collect() |
| 494 | 삭제: })); | |
| 565 | 추가: }); | |
| 566 | 추가: if self.picker.is_none() { | |
| 567 | 추가: self.on_drop(dropped); | |
| 568 | 추가: } | |
| 495 | 569 | if ctx.input(|i| i.viewport().close_requested()) { |
| 496 | 570 | self.model.request_close(); |
| 497 | 571 | if self.model.close != Close::Allowed { |
| @@ -523,6 +597,19 @@ impl ArchiveApp { | ||
| 523 | 597 | title.clone() |
| 524 | 598 | }; |
| 525 | 599 | ctx.send_viewport_cmd(egui::ViewportCommand::Title(short_title)); |
| 600 | 추가: if self.custom_frame | |
| 601 | 추가: && window_frame::title_bar( | |
| 602 | 추가: root, | |
| 603 | 추가: "main", | |
| 604 | 추가: &title, | |
| 605 | 추가: window_frame::Buttons { | |
| 606 | 추가: minimize: true, | |
| 607 | 추가: maximize: true, | |
| 608 | 추가: }, | |
| 609 | 추가: ) | |
| 610 | 추가: { | |
| 611 | 추가: self.release_after_move = true; | |
| 612 | 추가: } | |
| 526 | 613 | egui::Panel::top("archive-actions") |
| 527 | 614 | .frame( |
| 528 | 615 | theme::panel(theme::PANEL) |
| @@ -531,7 +618,9 @@ impl ArchiveApp { | ||
| 531 | 618 | ) |
| 532 | 619 | .show(root, |ui| { |
| 533 | 620 | ui.horizontal(|ui| { |
| 534 | 삭제: let idle = !self.model.busy() && self.model.close == Close::Open; | |
| 621 | 추가: let idle = !self.model.busy() | |
| 622 | 추가: && self.model.close == Close::Open | |
| 623 | 추가: && self.picker.is_none(); | |
| 535 | 624 | if theme::tool(ui, "열기", theme::OPEN, idle, false) |
| 536 | 625 | .on_hover_text(&title) |
| 537 | 626 | .clicked() |
| @@ -587,7 +676,8 @@ impl ArchiveApp { | ||
| 587 | 676 | }); |
| 588 | 677 | }); |
| 589 | 678 | }); |
| 590 | 삭제: if self.model.busy() || self.result_visible() || (self.ui_error.is_some() && !self.create) { | |
| 679 | 추가: if ctx.embed_viewports() && self.work_visible() { | |
| 680 | 추가: // 별도 창을 만들 수 없을 때만 쓰는 대체 배치. 목록을 가리지 않도록 하단에 둠. | |
| 591 | 681 | egui::Panel::bottom("archive-work") |
| 592 | 682 | .frame(theme::panel(theme::PANEL).corner_radius(0)) |
| 593 | 683 | .show(root, |ui| self.work_area(ui)); |
| @@ -605,6 +695,7 @@ impl ArchiveApp { | ||
| 605 | 695 | self.empty(ui); |
| 606 | 696 | } |
| 607 | 697 | }); |
| 698 | 추가: self.work_window(&ctx); | |
| 608 | 699 | if self.create && !self.model.busy() { |
| 609 | 700 | self.create_dialog(&ctx); |
| 610 | 701 | } |
| @@ -612,11 +703,27 @@ impl ArchiveApp { | ||
| 612 | 703 | self.password_dialog(&ctx, new_challenge); |
| 613 | 704 | } |
| 614 | 705 | self.close_dialog(&ctx); |
| 706 | 추가: self.picker_notice(&ctx); | |
| 707 | 추가: if self.custom_frame { | |
| 708 | 추가: window_frame::edges(&ctx, true); | |
| 709 | 추가: } | |
| 615 | 710 | if self.model.busy() { |
| 616 | 711 | ctx.request_repaint_after(std::time::Duration::from_millis(30)); |
| 617 | 712 | } |
| 618 | 713 | } |
| 619 | 714 | |
| 715 | 추가: // 선택 창이 열려 있는 동안 다른 조작을 막고, 응답을 받도록 화면을 계속 갱신함. | |
| 716 | 추가: fn picker_notice(&mut self, ctx: &egui::Context) { | |
| 717 | 추가: if self.picker.is_none() { | |
| 718 | 추가: return; | |
| 719 | 추가: } | |
| 720 | 추가: egui::Modal::new(egui::Id::unique("archive-picker")).show(ctx, |ui| { | |
| 721 | 추가: ui.set_width(360.0); | |
| 722 | 추가: ui.label("파일 선택 창에서 선택을 마쳐 주세요"); | |
| 723 | 추가: }); | |
| 724 | 추가: ctx.request_repaint_after(std::time::Duration::from_millis(100)); | |
| 725 | 추가: } | |
| 726 | 추가: | |
| 620 | 727 | fn empty(&mut self, ui: &mut egui::Ui) { |
| 621 | 728 | let hovered = ui.ctx().input(|i| !i.raw.hovered_files.is_empty()); |
| 622 | 729 | let width = (ui.available_width() * 0.60) |
| @@ -1122,7 +1229,169 @@ impl ArchiveApp { | ||
| 1122 | 1229 | response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Alert, true, error)); |
| 1123 | 1230 | } |
| 1124 | 1231 | |
| 1232 | 추가: fn work_visible(&self) -> bool { | |
| 1233 | 추가: self.model.busy() || self.result_visible() || (self.ui_error.is_some() && !self.create) | |
| 1234 | 추가: } | |
| 1235 | 추가: | |
| 1236 | 추가: /// 메인 창 가운데에 모달(ZIP 만들기, 암호 입력, 종료 확인, 파일 선택 안내)이 떠 있는지. | |
| 1237 | 추가: /// 모달이 늘어도 진행·결과 창 숨김 규칙은 이 한 곳만 보면 되도록 모음. | |
| 1238 | 추가: fn main_modal_open(&self) -> bool { | |
| 1239 | 추가: (self.create && !self.model.busy()) | |
| 1240 | 추가: || self.picker.is_some() | |
| 1241 | 추가: || self.model.challenge.is_some() | |
| 1242 | 추가: || self.model.close != Close::Open | |
| 1243 | 추가: } | |
| 1244 | 추가: | |
| 1245 | 추가: fn work_window(&mut self, ctx: &egui::Context) { | |
| 1246 | 추가: if !self.work_visible() { | |
| 1247 | 추가: self.work = WorkWindow::default(); | |
| 1248 | 추가: return; | |
| 1249 | 추가: } | |
| 1250 | 추가: if ctx.embed_viewports() { | |
| 1251 | 추가: // 별도 창을 만들 수 없는 환경(시험 등)은 show()에서 하단에 그림. | |
| 1252 | 추가: return; | |
| 1253 | 추가: } | |
| 1254 | 추가: if self.main_modal_open() { | |
| 1255 | 추가: // 메인 창 가운데에 뜨는 모달을 항상 위에 뜨는 진행·결과 창이 가리지 않게 | |
| 1256 | 추가: // 그동안 창을 닫음. 부모 기준 위치는 기억해 두고 다시 엶. | |
| 1257 | 추가: self.work.open = false; | |
| 1258 | 추가: return; | |
| 1259 | 추가: } | |
| 1260 | 추가: let id = egui::ViewportId::from_hash_of("archive-work"); | |
| 1261 | 추가: let (parent, parent_focused, now) = ctx.input(|i| { | |
| 1262 | 추가: ( | |
| 1263 | 추가: i.viewport().outer_rect, | |
| 1264 | 추가: i.viewport().focused.unwrap_or(false), | |
| 1265 | 추가: i.time, | |
| 1266 | 추가: ) | |
| 1267 | 추가: }); | |
| 1268 | 추가: let (child, child_focused) = ctx.input(|i| { | |
| 1269 | 추가: i.raw.viewports.get(&id).map_or((None, false), |v| { | |
| 1270 | 추가: (v.outer_rect, v.focused.unwrap_or(false)) | |
| 1271 | 추가: }) | |
| 1272 | 추가: }); | |
| 1273 | 추가: let size = egui::vec2(WORK_WIDTH, self.work.height); | |
| 1274 | 추가: if !self.work.open { | |
| 1275 | 추가: // 처음 열 때 부모 창 가운데에 둠. 암호 입력 뒤 다시 열 때는 기억한 위치에 둠. | |
| 1276 | 추가: // Wayland처럼 위치를 알 수 없으면 창 관리자에 맡김. | |
| 1277 | 추가: self.work.open = true; | |
| 1278 | 추가: self.work.initial = parent.map(|p| match self.work.offset { | |
| 1279 | 추가: Some(offset) => (p.min + offset).round(), | |
| 1280 | 추가: None => (p.center() - size / 2.0).round(), | |
| 1281 | 추가: }); | |
| 1282 | 추가: self.work.offset = self.work.initial.zip(parent).map(|(c, p)| c - p.min); | |
| 1283 | 추가: self.work.parent = parent.map(|p| p.min); | |
| 1284 | 추가: self.work.expected = self.work.initial; | |
| 1285 | 추가: self.work.settle_until = now + 0.5; | |
| 1286 | 추가: } | |
| 1287 | 추가: if let (Some(parent), Some(child)) = (parent, child) { | |
| 1288 | 추가: let parent_moved = self | |
| 1289 | 추가: .work | |
| 1290 | 추가: .parent | |
| 1291 | 추가: .is_some_and(|p| (p - parent.min).length() > 0.5); | |
| 1292 | 추가: let settled = self | |
| 1293 | 추가: .work | |
| 1294 | 추가: .expected | |
| 1295 | 추가: .is_some_and(|e| (child.min - e).length() <= 2.0); | |
| 1296 | 추가: if settled || now >= self.work.settle_until { | |
| 1297 | 추가: self.work.settle_until = 0.0; | |
| 1298 | 추가: } | |
| 1299 | 추가: if parent_moved { | |
| 1300 | 추가: if let Some(offset) = self.work.offset { | |
| 1301 | 추가: let target = (parent.min + offset).round(); | |
| 1302 | 추가: ctx.send_viewport_cmd_to(id, egui::ViewportCommand::OuterPosition(target)); | |
| 1303 | 추가: self.work.expected = Some(target); | |
| 1304 | 추가: self.work.settle_until = now + 0.5; | |
| 1305 | 추가: } | |
| 1306 | 추가: } else if self.work.settle_until == 0.0 && !settled { | |
| 1307 | 추가: // 사용자가 자식 창을 옮긴 위치를 부모 기준으로 기억함. | |
| 1308 | 추가: self.work.offset = Some(child.min - parent.min); | |
| 1309 | 추가: self.work.expected = Some(child.min); | |
| 1310 | 추가: } | |
| 1311 | 추가: self.work.parent = Some(parent.min); | |
| 1312 | 추가: } | |
| 1313 | 추가: let title = if self.model.busy() { | |
| 1314 | 추가: present::activity_text( | |
| 1315 | 추가: &self.model, | |
| 1316 | 추가: matches!(self.last_request, Some(Start::CreateZip { .. })), | |
| 1317 | 추가: ) | |
| 1318 | 추가: .to_owned() | |
| 1319 | 추가: } else { | |
| 1320 | 추가: "작업 결과".to_owned() | |
| 1321 | 추가: }; | |
| 1322 | 추가: let window_title = format!("{title} — Zipelo"); | |
| 1323 | 추가: let custom_frame = self.custom_frame; | |
| 1324 | 추가: let mut builder = egui::ViewportBuilder::default() | |
| 1325 | 추가: .with_title(window_title.clone()) | |
| 1326 | 추가: .with_decorations(!custom_frame) | |
| 1327 | 추가: .with_inner_size(size) | |
| 1328 | 추가: .with_resizable(false) | |
| 1329 | 추가: .with_minimize_button(false) | |
| 1330 | 추가: .with_maximize_button(false) | |
| 1331 | 추가: .with_taskbar(false) | |
| 1332 | 추가: // 앱을 쓰는 동안에만 부모 창 위에 유지함. | |
| 1333 | 추가: .with_window_level(if parent_focused || child_focused { | |
| 1334 | 추가: egui::WindowLevel::AlwaysOnTop | |
| 1335 | 추가: } else { | |
| 1336 | 추가: egui::WindowLevel::Normal | |
| 1337 | 추가: }); | |
| 1338 | 추가: if let Some(position) = self.work.initial { | |
| 1339 | 추가: builder = builder.with_position(position); | |
| 1340 | 추가: } | |
| 1341 | 추가: let height = ctx.show_viewport_immediate(id, builder, |ui, class| { | |
| 1342 | 추가: if ui.ctx().input(|i| i.viewport().close_requested()) { | |
| 1343 | 추가: if self.model.busy() { | |
| 1344 | 추가: ui.ctx() | |
| 1345 | 추가: .send_viewport_cmd(egui::ViewportCommand::CancelClose); | |
| 1346 | 추가: } else { | |
| 1347 | 추가: self.dismissed = true; | |
| 1348 | 추가: self.ui_error = None; | |
| 1349 | 추가: self.model.input_error = None; | |
| 1350 | 추가: } | |
| 1351 | 추가: } | |
| 1352 | 추가: if class == egui::ViewportClass::EmbeddedWindow { | |
| 1353 | 추가: ui.set_width(WORK_WIDTH); | |
| 1354 | 추가: self.work_area(ui); | |
| 1355 | 추가: return None; | |
| 1356 | 추가: } | |
| 1357 | 추가: let mut chrome = 0.0; | |
| 1358 | 추가: if custom_frame { | |
| 1359 | 추가: window_frame::title_bar( | |
| 1360 | 추가: ui, | |
| 1361 | 추가: "work", | |
| 1362 | 추가: &window_title, | |
| 1363 | 추가: window_frame::Buttons { | |
| 1364 | 추가: minimize: false, | |
| 1365 | 추가: maximize: false, | |
| 1366 | 추가: }, | |
| 1367 | 추가: ); | |
| 1368 | 추가: window_frame::edges(ui.ctx(), false); | |
| 1369 | 추가: chrome = window_frame::TITLE_HEIGHT; | |
| 1370 | 추가: } | |
| 1371 | 추가: let margin = theme::PAD as f32; | |
| 1372 | 추가: egui::CentralPanel::default() | |
| 1373 | 추가: .frame(theme::panel(theme::PANEL).corner_radius(0)) | |
| 1374 | 추가: .show(ui, |ui| { | |
| 1375 | 추가: let content = ui.vertical(|ui| self.work_area(ui)).response.rect; | |
| 1376 | 추가: Some(content.height() + 2.0 * margin + chrome) | |
| 1377 | 추가: }) | |
| 1378 | 추가: .inner | |
| 1379 | 추가: }); | |
| 1380 | 추가: if let Some(height) = height { | |
| 1381 | 추가: let height = height.clamp(WORK_MIN_HEIGHT, WORK_MAX_HEIGHT).ceil(); | |
| 1382 | 추가: if (height - self.work.height).abs() > 1.0 { | |
| 1383 | 추가: self.work.height = height; | |
| 1384 | 추가: } | |
| 1385 | 추가: } | |
| 1386 | 추가: } | |
| 1387 | 추가: | |
| 1125 | 1388 | fn work_area(&mut self, ui: &mut egui::Ui) { |
| 1389 | 추가: // 선택 창 안내 모달은 메인 창만 막으므로, 별도 진행 창의 버튼은 여기서 막음. | |
| 1390 | 추가: let enabled = self.picker.is_none(); | |
| 1391 | 추가: ui.add_enabled_ui(enabled, |ui| self.work_contents(ui)); | |
| 1392 | 추가: } | |
| 1393 | 추가: | |
| 1394 | 추가: fn work_contents(&mut self, ui: &mut egui::Ui) { | |
| 1126 | 1395 | if self.model.busy() { |
| 1127 | 1396 | self.progress(ui); |
| 1128 | 1397 | } else if self.result_visible() { |
| @@ -1159,7 +1428,13 @@ impl ArchiveApp { | ||
| 1159 | 1428 | let cancelling = self.model.cancellation_requested() || self.model.cancel.is_some(); |
| 1160 | 1429 | let title = present::activity_text(&self.model, creating); |
| 1161 | 1430 | ui.strong(title); |
| 1162 | 삭제: if let Some((_, done, total, count)) = self.model.progress { | |
| 1431 | 추가: if let Some((stage, done, total, count)) = self.model.progress { | |
| 1432 | 추가: // 원본을 읽는 단계에서는 아직 처리한 항목이 없으므로 개수를 표시하지 않음. | |
| 1433 | 추가: let processed = if stage == Stage::Read { | |
| 1434 | 추가: String::new() | |
| 1435 | 추가: } else { | |
| 1436 | 추가: format!("{count}개 처리함, ") | |
| 1437 | 추가: }; | |
| 1163 | 1438 | if let Some(total) = total.filter(|n| *n > 0) { |
| 1164 | 1439 | ui.scope(|ui| { |
| 1165 | 1440 | ui.visuals_mut().extreme_bg_color = theme::BORDER; |
| @@ -1171,7 +1446,7 @@ impl ArchiveApp { | ||
| 1171 | 1446 | }); |
| 1172 | 1447 | ui.horizontal(|ui| { |
| 1173 | 1448 | ui.label(format!( |
| 1174 | 삭제: "{:.0}% / {count}개 처리함, {} / {}", | |
| 1449 | 추가: "{:.0}% / {processed}{} / {}", | |
| 1175 | 1450 | (done as f64 / total as f64).clamp(0.0, 1.0) * 100.0, |
| 1176 | 1451 | present::bytes_text(done), |
| 1177 | 1452 | present::bytes_text(total) |
| @@ -1181,7 +1456,7 @@ impl ArchiveApp { | ||
| 1181 | 1456 | } else { |
| 1182 | 1457 | theme::indeterminate(ui); |
| 1183 | 1458 | ui.horizontal(|ui| { |
| 1184 | 삭제: ui.label(format!("{count}개 처리함, {}", present::bytes_text(done))); | |
| 1459 | 추가: ui.label(format!("{processed}{}", present::bytes_text(done))); | |
| 1185 | 1460 | self.cancel_action(ui, cancelling); |
| 1186 | 1461 | }); |
| 1187 | 1462 | } |
| @@ -1272,7 +1547,7 @@ impl ArchiveApp { | ||
| 1272 | 1547 | ); |
| 1273 | 1548 | ui.strong(title); |
| 1274 | 1549 | }); |
| 1275 | 삭제: let max_height = (ui.ctx().content_rect().height() * 0.24).max(80.0); | |
| 1550 | 추가: let max_height = WORK_RESULT_MAX_HEIGHT; | |
| 1276 | 1551 | egui::ScrollArea::vertical() |
| 1277 | 1552 | .id_salt("result-message") |
| 1278 | 1553 | .max_height(max_height) |
| @@ -1760,6 +2035,22 @@ impl eframe::App for ArchiveApp { | ||
| 1760 | 2035 | fn ui(&mut self, root: &mut egui::Ui, _: &mut eframe::Frame) { |
| 1761 | 2036 | self.show(root); |
| 1762 | 2037 | } |
| 2038 | 추가: | |
| 2039 | 추가: fn raw_input_hook(&mut self, ctx: &egui::Context, raw_input: &mut egui::RawInput) { | |
| 2040 | 추가: // 운영체제가 창 이동을 맡으면 버튼 놓기가 오지 않으므로 대신 넣어 눌림 상태를 풀어 줌. | |
| 2041 | 추가: if std::mem::take(&mut self.release_after_move) { | |
| 2042 | 추가: let pos = ctx.input(|i| i.pointer.latest_pos()).unwrap_or_default(); | |
| 2043 | 추가: raw_input.events.insert( | |
| 2044 | 추가: 0, | |
| 2045 | 추가: egui::Event::PointerButton { | |
| 2046 | 추가: pos, | |
| 2047 | 추가: button: egui::PointerButton::Primary, | |
| 2048 | 추가: pressed: false, | |
| 2049 | 추가: modifiers: ctx.input(|i| i.modifiers), | |
| 2050 | 추가: }, | |
| 2051 | 추가: ); | |
| 2052 | 추가: } | |
| 2053 | 추가: } | |
| 1763 | 2054 | } |
| 1764 | 2055 | impl Drop for ArchiveApp { |
| 1765 | 2056 | fn drop(&mut self) { |
| @@ -42,13 +42,15 @@ fn show_startup_error(message: &str) { | ||
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | fn run() -> eframe::Result { |
| 45 | 추가: let custom_frame = zipelo_ui_memory_app::window_frame::custom_frame_needed(); | |
| 45 | 46 | let font = system_font::load().map_err(|e| eframe::Error::AppCreation(Box::new(e)))?; |
| 46 | 47 | renderer::run_native( |
| 47 | 48 | "Zipelo", |
| 48 | 49 | eframe::NativeOptions { |
| 49 | 50 | viewport: egui::ViewportBuilder::default() |
| 50 | 51 | .with_inner_size([1060.0, 720.0]) |
| 51 | 삭제: .with_min_inner_size([760.0, 540.0]), | |
| 52 | 추가: .with_min_inner_size([760.0, 540.0]) | |
| 53 | 추가: .with_decorations(!custom_frame), | |
| 52 | 54 | ..Default::default() |
| 53 | 55 | }, |
| 54 | 56 | || { |
| @@ -86,11 +88,11 @@ fn run() -> eframe::Result { | ||
| 86 | 88 | .map_err(std::io::Error::other)?, |
| 87 | 89 | ) |
| 88 | 90 | }; |
| 89 | 삭제: Ok(Box::new( | |
| 90 | 삭제: zipelo_ui_memory_app::archive_screen::ArchiveApp::new( | |
| 91 | 삭제: factory, startup, fixture, | |
| 92 | 삭제: ), | |
| 93 | 삭제: )) | |
| 91 | 추가: let mut app = zipelo_ui_memory_app::archive_screen::ArchiveApp::new( | |
| 92 | 추가: factory, startup, fixture, | |
| 93 | 추가: ); | |
| 94 | 추가: app.set_custom_frame(custom_frame); | |
| 95 | 추가: Ok(Box::new(app)) | |
| 94 | 96 | }) |
| 95 | 97 | }, |
| 96 | 98 | ) |
| @@ -19,5 +19,7 @@ pub mod archive_browser; | ||
| 19 | 19 | pub mod archive_dialog; |
| 20 | 20 | #[cfg(feature = "ui")] |
| 21 | 21 | pub mod archive_theme; |
| 22 | 추가: #[cfg(feature = "ui")] | |
| 23 | 추가: pub mod window_frame; | |
| 22 | 24 | |
| 23 | 25 | pub mod archive_path; |
| @@ -0,0 +1,282 @@ | ||
| 1 | 추가: //! GNOME Wayland는 창 테두리를 그려 주지 않으므로 제목 표시줄과 테두리를 직접 그림. | |
| 2 | 추가: //! 앱 글꼴로 그려서 한글 제목도 그대로 표시됨. | |
| 3 | 추가: | |
| 4 | 추가: use crate::archive_theme as theme; | |
| 5 | 추가: use eframe::egui::{ | |
| 6 | 추가: self, Align2, Color32, CursorIcon, FontId, Rect, ResizeDirection, Sense, Stroke, Vec2, | |
| 7 | 추가: ViewportCommand, | |
| 8 | 추가: }; | |
| 9 | 추가: | |
| 10 | 추가: pub const TITLE_HEIGHT: f32 = 38.0; | |
| 11 | 추가: const BUTTON_SIZE: Vec2 = egui::vec2(34.0, 26.0); | |
| 12 | 추가: const RESIZE_EDGE: f32 = 6.0; | |
| 13 | 추가: const DRAG_THRESHOLD: f32 = 4.0; | |
| 14 | 추가: const TITLE_BG: Color32 = Color32::from_rgb(235, 238, 242); | |
| 15 | 추가: | |
| 16 | 추가: /// 창 테두리를 직접 그려야 하는지 판단함. | |
| 17 | 추가: /// winit은 Linux에서 Wayland 연결 정보가 있으면 Wayland로 창을 만듦. | |
| 18 | 추가: pub fn custom_frame_needed() -> bool { | |
| 19 | 추가: cfg!(target_os = "linux") | |
| 20 | 추가: && ["WAYLAND_DISPLAY", "WAYLAND_SOCKET"] | |
| 21 | 추가: .iter() | |
| 22 | 추가: .any(|key| std::env::var_os(key).is_some_and(|value| !value.is_empty())) | |
| 23 | 추가: } | |
| 24 | 추가: | |
| 25 | 추가: #[derive(Clone, Copy)] | |
| 26 | 추가: pub struct Buttons { | |
| 27 | 추가: pub minimize: bool, | |
| 28 | 추가: pub maximize: bool, | |
| 29 | 추가: } | |
| 30 | 추가: | |
| 31 | 추가: #[derive(Clone, Copy, PartialEq)] | |
| 32 | 추가: enum Glyph { | |
| 33 | 추가: Minimize, | |
| 34 | 추가: Maximize, | |
| 35 | 추가: Restore, | |
| 36 | 추가: Close, | |
| 37 | 추가: } | |
| 38 | 추가: | |
| 39 | 추가: /// 위쪽 패널로 제목 표시줄을 그림. 버튼과 끌기 동작은 현재 창에 명령으로 보냄. | |
| 40 | 추가: /// 창 이동을 운영체제에 넘긴 프레임이면 true를 돌려줌. | |
| 41 | 추가: pub fn title_bar(root: &mut egui::Ui, id: &str, title: &str, buttons: Buttons) -> bool { | |
| 42 | 추가: let mut moved = false; | |
| 43 | 추가: egui::Panel::top(egui::Id::unique(("window-title", id))) | |
| 44 | 추가: .exact_size(TITLE_HEIGHT) | |
| 45 | 추가: .resizable(false) | |
| 46 | 추가: .show_separator_line(false) | |
| 47 | 추가: .frame(egui::Frame::new().fill(TITLE_BG)) | |
| 48 | 추가: .show(root, |ui| { | |
| 49 | 추가: let rect = ui.max_rect(); | |
| 50 | 추가: let ctx = ui.ctx().clone(); | |
| 51 | 추가: let bar = ui.interact( | |
| 52 | 추가: rect, | |
| 53 | 추가: egui::Id::unique(("window-title-drag", id)), | |
| 54 | 추가: Sense::click_and_drag(), | |
| 55 | 추가: ); | |
| 56 | 추가: let maximized = ctx.input(|i| i.viewport().maximized.unwrap_or(false)); | |
| 57 | 추가: if buttons.maximize && bar.double_clicked() { | |
| 58 | 추가: ctx.send_viewport_cmd(ViewportCommand::Maximized(!maximized)); | |
| 59 | 추가: } | |
| 60 | 추가: | |
| 61 | 추가: let mut glyphs = vec![Glyph::Close]; | |
| 62 | 추가: if buttons.maximize { | |
| 63 | 추가: glyphs.push(if maximized { | |
| 64 | 추가: Glyph::Restore | |
| 65 | 추가: } else { | |
| 66 | 추가: Glyph::Maximize | |
| 67 | 추가: }); | |
| 68 | 추가: } | |
| 69 | 추가: if buttons.minimize { | |
| 70 | 추가: glyphs.push(Glyph::Minimize); | |
| 71 | 추가: } | |
| 72 | 추가: let button_count = glyphs.len() as f32; | |
| 73 | 추가: let buttons_left = rect.right() - 6.0 - button_count * (BUTTON_SIZE.x + 4.0); | |
| 74 | 추가: if start_move(&ctx, id, rect, buttons_left) { | |
| 75 | 추가: ctx.send_viewport_cmd(ViewportCommand::StartDrag); | |
| 76 | 추가: moved = true; | |
| 77 | 추가: } | |
| 78 | 추가: let mut right = rect.right() - 6.0; | |
| 79 | 추가: for glyph in glyphs { | |
| 80 | 추가: let button = Rect::from_center_size( | |
| 81 | 추가: egui::pos2(right - BUTTON_SIZE.x / 2.0, rect.center().y), | |
| 82 | 추가: BUTTON_SIZE, | |
| 83 | 추가: ); | |
| 84 | 추가: right -= BUTTON_SIZE.x + 4.0; | |
| 85 | 추가: if window_button(ui, id, button, glyph).clicked() { | |
| 86 | 추가: ctx.send_viewport_cmd(match glyph { | |
| 87 | 추가: Glyph::Minimize => ViewportCommand::Minimized(true), | |
| 88 | 추가: Glyph::Maximize => ViewportCommand::Maximized(true), | |
| 89 | 추가: Glyph::Restore => ViewportCommand::Maximized(false), | |
| 90 | 추가: Glyph::Close => ViewportCommand::Close, | |
| 91 | 추가: }); | |
| 92 | 추가: } | |
| 93 | 추가: } | |
| 94 | 추가: | |
| 95 | 추가: // 버튼 영역을 피해 가운데에 제목을 그림. | |
| 96 | 추가: let reserved = rect.right() - right; | |
| 97 | 추가: let width = (rect.width() - 2.0 * reserved).max(0.0); | |
| 98 | 추가: let font = FontId::proportional(theme::BODY - 2.0); | |
| 99 | 추가: let text = fit(ui, title, &font, width); | |
| 100 | 추가: ui.painter().text( | |
| 101 | 추가: rect.center(), | |
| 102 | 추가: Align2::CENTER_CENTER, | |
| 103 | 추가: text, | |
| 104 | 추가: font, | |
| 105 | 추가: theme::TEXT, | |
| 106 | 추가: ); | |
| 107 | 추가: ui.painter().hline( | |
| 108 | 추가: rect.x_range(), | |
| 109 | 추가: rect.bottom() - 0.5, | |
| 110 | 추가: Stroke::new(1.0, theme::BORDER), | |
| 111 | 추가: ); | |
| 112 | 추가: }); | |
| 113 | 추가: moved | |
| 114 | 추가: } | |
| 115 | 추가: | |
| 116 | 추가: /// 제목 표시줄을 누른 채 움직였는지를 원시 입력으로 판단함. | |
| 117 | 추가: /// 창 이동 중에는 운영체제가 마우스를 가져가서 버튼 놓기가 앱에 오지 않으므로, | |
| 118 | 추가: /// egui의 끌기 상태에 기대면 다음 끌기가 시작되지 않음. | |
| 119 | 추가: fn start_move(ctx: &egui::Context, id: &str, bar: Rect, buttons_left: f32) -> bool { | |
| 120 | 추가: let key = egui::Id::unique(("window-title-press", id)); | |
| 121 | 추가: let mut origin: Option<egui::Pos2> = ctx.data(|d| d.get_temp(key)).flatten(); | |
| 122 | 추가: let latest = ctx.input(|i| { | |
| 123 | 추가: for event in &i.raw.events { | |
| 124 | 추가: if let egui::Event::PointerButton { | |
| 125 | 추가: pos, | |
| 126 | 추가: button: egui::PointerButton::Primary, | |
| 127 | 추가: pressed, | |
| 128 | 추가: .. | |
| 129 | 추가: } = event | |
| 130 | 추가: { | |
| 131 | 추가: origin = (*pressed && bar.contains(*pos) && pos.x < buttons_left).then_some(*pos); | |
| 132 | 추가: } | |
| 133 | 추가: } | |
| 134 | 추가: i.pointer.latest_pos() | |
| 135 | 추가: }); | |
| 136 | 추가: let start = origin | |
| 137 | 추가: .zip(latest) | |
| 138 | 추가: .is_some_and(|(origin, latest)| (latest - origin).length() >= DRAG_THRESHOLD); | |
| 139 | 추가: if start { | |
| 140 | 추가: origin = None; | |
| 141 | 추가: // 운영체제가 이동을 맡으므로 egui 쪽 끌기는 끝낸 것으로 처리함. | |
| 142 | 추가: ctx.stop_dragging(); | |
| 143 | 추가: } | |
| 144 | 추가: ctx.data_mut(|d| d.insert_temp(key, origin)); | |
| 145 | 추가: start | |
| 146 | 추가: } | |
| 147 | 추가: | |
| 148 | 추가: fn window_button(ui: &mut egui::Ui, id: &str, rect: Rect, glyph: Glyph) -> egui::Response { | |
| 149 | 추가: let label = match glyph { | |
| 150 | 추가: Glyph::Minimize => "최소화", | |
| 151 | 추가: Glyph::Maximize => "최대화", | |
| 152 | 추가: Glyph::Restore => "이전 크기로", | |
| 153 | 추가: Glyph::Close => "닫기", | |
| 154 | 추가: }; | |
| 155 | 추가: let response = ui | |
| 156 | 추가: .interact( | |
| 157 | 추가: rect, | |
| 158 | 추가: egui::Id::unique(("window-button", id, label)), | |
| 159 | 추가: Sense::click(), | |
| 160 | 추가: ) | |
| 161 | 추가: .on_hover_text(label); | |
| 162 | 추가: response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, label)); | |
| 163 | 추가: let painter = ui.painter(); | |
| 164 | 추가: if response.hovered() || response.is_pointer_button_down_on() { | |
| 165 | 추가: let fill = if glyph == Glyph::Close { | |
| 166 | 추가: Color32::from_rgb(232, 17, 35) | |
| 167 | 추가: } else { | |
| 168 | 추가: theme::BORDER | |
| 169 | 추가: }; | |
| 170 | 추가: painter.rect_filled(rect, 6.0, fill); | |
| 171 | 추가: } | |
| 172 | 추가: let color = if glyph == Glyph::Close && response.hovered() { | |
| 173 | 추가: Color32::WHITE | |
| 174 | 추가: } else { | |
| 175 | 추가: theme::TEXT | |
| 176 | 추가: }; | |
| 177 | 추가: let stroke = Stroke::new(1.4, color); | |
| 178 | 추가: let c = rect.center(); | |
| 179 | 추가: let r = 5.0; | |
| 180 | 추가: match glyph { | |
| 181 | 추가: Glyph::Minimize => { | |
| 182 | 추가: painter.hline(c.x - r..=c.x + r, c.y + r * 0.6, stroke); | |
| 183 | 추가: } | |
| 184 | 추가: Glyph::Maximize => { | |
| 185 | 추가: painter.rect_stroke( | |
| 186 | 추가: Rect::from_center_size(c, egui::vec2(2.0 * r, 2.0 * r)), | |
| 187 | 추가: 1.0, | |
| 188 | 추가: stroke, | |
| 189 | 추가: egui::StrokeKind::Middle, | |
| 190 | 추가: ); | |
| 191 | 추가: } | |
| 192 | 추가: Glyph::Restore => { | |
| 193 | 추가: let back = Rect::from_center_size(c + egui::vec2(1.5, -1.5), egui::vec2(8.0, 8.0)); | |
| 194 | 추가: let front = Rect::from_center_size(c + egui::vec2(-1.5, 1.5), egui::vec2(8.0, 8.0)); | |
| 195 | 추가: painter.rect_stroke(back, 1.0, stroke, egui::StrokeKind::Middle); | |
| 196 | 추가: painter.rect_filled(front, 1.0, TITLE_BG); | |
| 197 | 추가: painter.rect_stroke(front, 1.0, stroke, egui::StrokeKind::Middle); | |
| 198 | 추가: } | |
| 199 | 추가: Glyph::Close => { | |
| 200 | 추가: painter.line_segment([c + egui::vec2(-r, -r), c + egui::vec2(r, r)], stroke); | |
| 201 | 추가: painter.line_segment([c + egui::vec2(-r, r), c + egui::vec2(r, -r)], stroke); | |
| 202 | 추가: } | |
| 203 | 추가: } | |
| 204 | 추가: response | |
| 205 | 추가: } | |
| 206 | 추가: | |
| 207 | 추가: /// 폭을 넘는 제목은 앞부분을 줄이고 끝(파일 이름과 앱 이름)을 남김. | |
| 208 | 추가: fn fit(ui: &egui::Ui, title: &str, font: &FontId, width: f32) -> String { | |
| 209 | 추가: let measure = |text: &str| { | |
| 210 | 추가: ui.fonts_mut(|fonts| { | |
| 211 | 추가: fonts | |
| 212 | 추가: .layout_no_wrap(text.to_owned(), font.clone(), theme::TEXT) | |
| 213 | 추가: .size() | |
| 214 | 추가: .x | |
| 215 | 추가: }) | |
| 216 | 추가: }; | |
| 217 | 추가: if measure(title) <= width { | |
| 218 | 추가: return title.to_owned(); | |
| 219 | 추가: } | |
| 220 | 추가: let chars: Vec<char> = title.chars().collect(); | |
| 221 | 추가: for start in 1..chars.len() { | |
| 222 | 추가: let candidate = format!("…{}", chars[start..].iter().collect::<String>()); | |
| 223 | 추가: if measure(&candidate) <= width { | |
| 224 | 추가: return candidate; | |
| 225 | 추가: } | |
| 226 | 추가: } | |
| 227 | 추가: String::new() | |
| 228 | 추가: } | |
| 229 | 추가: | |
| 230 | 추가: /// 창 가장자리에서 크기 조절을 시작하고 얇은 테두리를 그림. | |
| 231 | 추가: pub fn edges(ctx: &egui::Context, resizable: bool) { | |
| 232 | 추가: let rect = ctx.content_rect(); | |
| 233 | 추가: let maximized = ctx.input(|i| { | |
| 234 | 추가: i.viewport().maximized.unwrap_or(false) || i.viewport().fullscreen.unwrap_or(false) | |
| 235 | 추가: }); | |
| 236 | 추가: if !maximized { | |
| 237 | 추가: ctx.layer_painter(egui::LayerId::new( | |
| 238 | 추가: egui::Order::Foreground, | |
| 239 | 추가: egui::Id::unique("window-border"), | |
| 240 | 추가: )) | |
| 241 | 추가: .rect_stroke( | |
| 242 | 추가: rect.shrink(0.5), | |
| 243 | 추가: 0.0, | |
| 244 | 추가: Stroke::new(1.0, theme::BORDER), | |
| 245 | 추가: egui::StrokeKind::Middle, | |
| 246 | 추가: ); | |
| 247 | 추가: } | |
| 248 | 추가: if !resizable || maximized { | |
| 249 | 추가: return; | |
| 250 | 추가: } | |
| 251 | 추가: let Some(pointer) = ctx.input(|i| i.pointer.hover_pos()) else { | |
| 252 | 추가: return; | |
| 253 | 추가: }; | |
| 254 | 추가: let left = pointer.x - rect.left() <= RESIZE_EDGE; | |
| 255 | 추가: let right = rect.right() - pointer.x <= RESIZE_EDGE; | |
| 256 | 추가: let top = pointer.y - rect.top() <= RESIZE_EDGE; | |
| 257 | 추가: let bottom = rect.bottom() - pointer.y <= RESIZE_EDGE; | |
| 258 | 추가: let direction = match (left, right, top, bottom) { | |
| 259 | 추가: (true, _, true, _) => ResizeDirection::NorthWest, | |
| 260 | 추가: (_, true, true, _) => ResizeDirection::NorthEast, | |
| 261 | 추가: (true, _, _, true) => ResizeDirection::SouthWest, | |
| 262 | 추가: (_, true, _, true) => ResizeDirection::SouthEast, | |
| 263 | 추가: (true, ..) => ResizeDirection::West, | |
| 264 | 추가: (_, true, ..) => ResizeDirection::East, | |
| 265 | 추가: (_, _, true, _) => ResizeDirection::North, | |
| 266 | 추가: (_, _, _, true) => ResizeDirection::South, | |
| 267 | 추가: _ => return, | |
| 268 | 추가: }; | |
| 269 | 추가: ctx.set_cursor_icon(match direction { | |
| 270 | 추가: ResizeDirection::North => CursorIcon::ResizeNorth, | |
| 271 | 추가: ResizeDirection::South => CursorIcon::ResizeSouth, | |
| 272 | 추가: ResizeDirection::East => CursorIcon::ResizeEast, | |
| 273 | 추가: ResizeDirection::West => CursorIcon::ResizeWest, | |
| 274 | 추가: ResizeDirection::NorthEast => CursorIcon::ResizeNorthEast, | |
| 275 | 추가: ResizeDirection::NorthWest => CursorIcon::ResizeNorthWest, | |
| 276 | 추가: ResizeDirection::SouthEast => CursorIcon::ResizeSouthEast, | |
| 277 | 추가: ResizeDirection::SouthWest => CursorIcon::ResizeSouthWest, | |
| 278 | 추가: }); | |
| 279 | 추가: if ctx.input(|i| i.pointer.primary_pressed()) { | |
| 280 | 추가: ctx.send_viewport_cmd(ViewportCommand::BeginResize(direction)); | |
| 281 | 추가: } | |
| 282 | 추가: } |
| @@ -909,6 +909,8 @@ mod widgets { | ||
| 909 | 909 | include!("toolbar.rs"); |
| 910 | 910 | include!("long_layout.rs"); |
| 911 | 911 | include!("explorer_selection.rs"); |
| 912 | 추가: include!("window_frame.rs"); | |
| 913 | 추가: include!("work_window.rs"); | |
| 912 | 914 | } |
| 913 | 915 | |
| 914 | 916 | #[cfg(feature = "ui")] |
| @@ -0,0 +1,201 @@ | ||
| 1 | 추가: // GNOME Wayland처럼 운영체제가 창 테두리를 그리지 않을 때 쓰는 자체 제목 표시줄 회귀 시험. | |
| 2 | 추가: | |
| 3 | 추가: fn frame_output( | |
| 4 | 추가: ctx: &egui::Context, | |
| 5 | 추가: app: &mut ArchiveApp, | |
| 6 | 추가: events: Vec<egui::Event>, | |
| 7 | 추가: ) -> egui::FullOutput { | |
| 8 | 추가: let mut output = ctx.run_ui( | |
| 9 | 추가: egui::RawInput { | |
| 10 | 추가: screen_rect: Some(egui::Rect::from_min_size( | |
| 11 | 추가: egui::Pos2::ZERO, | |
| 12 | 추가: egui::vec2(1060.0, 720.0), | |
| 13 | 추가: )), | |
| 14 | 추가: events, | |
| 15 | 추가: ..Default::default() | |
| 16 | 추가: }, | |
| 17 | 추가: |ui| app.show(ui), | |
| 18 | 추가: ); | |
| 19 | 추가: output.textures_delta.clear(); | |
| 20 | 추가: output | |
| 21 | 추가: } | |
| 22 | 추가: | |
| 23 | 추가: fn root_commands(output: &egui::FullOutput) -> Vec<egui::ViewportCommand> { | |
| 24 | 추가: output | |
| 25 | 추가: .viewport_output | |
| 26 | 추가: .get(&egui::ViewportId::ROOT) | |
| 27 | 추가: .map(|viewport| viewport.commands.clone()) | |
| 28 | 추가: .unwrap_or_default() | |
| 29 | 추가: } | |
| 30 | 추가: | |
| 31 | 추가: fn press_release( | |
| 32 | 추가: ctx: &egui::Context, | |
| 33 | 추가: app: &mut ArchiveApp, | |
| 34 | 추가: point: egui::Pos2, | |
| 35 | 추가: ) -> Vec<egui::ViewportCommand> { | |
| 36 | 추가: frame_output(ctx, app, vec![egui::Event::PointerMoved(point)]); | |
| 37 | 추가: let mut commands = Vec::new(); | |
| 38 | 추가: for pressed in [true, false] { | |
| 39 | 추가: let output = frame_output( | |
| 40 | 추가: ctx, | |
| 41 | 추가: app, | |
| 42 | 추가: vec![egui::Event::PointerButton { | |
| 43 | 추가: pos: point, | |
| 44 | 추가: button: egui::PointerButton::Primary, | |
| 45 | 추가: pressed, | |
| 46 | 추가: modifiers: egui::Modifiers::NONE, | |
| 47 | 추가: }], | |
| 48 | 추가: ); | |
| 49 | 추가: commands.extend(root_commands(&output)); | |
| 50 | 추가: } | |
| 51 | 추가: commands | |
| 52 | 추가: } | |
| 53 | 추가: | |
| 54 | 추가: fn window_commands(commands: &[egui::ViewportCommand]) -> Vec<egui::ViewportCommand> { | |
| 55 | 추가: // 제목 갱신은 매 프레임 나가므로 창 조작 명령만 비교함. | |
| 56 | 추가: commands | |
| 57 | 추가: .iter() | |
| 58 | 추가: .filter(|command| !matches!(command, egui::ViewportCommand::Title(_))) | |
| 59 | 추가: .cloned() | |
| 60 | 추가: .collect() | |
| 61 | 추가: } | |
| 62 | 추가: | |
| 63 | 추가: #[test] | |
| 64 | 추가: fn custom_window_frame_shows_title_and_sends_window_commands() { | |
| 65 | 추가: use zipelo_ui_memory_app::window_frame::TITLE_HEIGHT; | |
| 66 | 추가: // 제목 표시줄 버튼 중심: 오른쪽 여백 6, 버튼 폭 34, 간격 4. | |
| 67 | 추가: let close = egui::pos2(1060.0 - 6.0 - 17.0, TITLE_HEIGHT / 2.0); | |
| 68 | 추가: let maximize = close - egui::vec2(38.0, 0.0); | |
| 69 | 추가: let minimize = maximize - egui::vec2(38.0, 0.0); | |
| 70 | 추가: for (point, expected) in [ | |
| 71 | 추가: (close, egui::ViewportCommand::Close), | |
| 72 | 추가: (maximize, egui::ViewportCommand::Maximized(true)), | |
| 73 | 추가: (minimize, egui::ViewportCommand::Minimized(true)), | |
| 74 | 추가: ] { | |
| 75 | 추가: let scratch = Folder::new(); | |
| 76 | 추가: let factory = FakeFactory::default(); | |
| 77 | 추가: let mut app = loaded(&scratch, &factory); | |
| 78 | 추가: app.set_custom_frame(true); | |
| 79 | 추가: let ctx = egui::Context::default(); | |
| 80 | 추가: let shown = labels(&frame_output(&ctx, &mut app, vec![]).shapes); | |
| 81 | 추가: assert!( | |
| 82 | 추가: shown | |
| 83 | 추가: .iter() | |
| 84 | 추가: .any(|(text, pos)| text.ends_with("sample.zip — Zipelo") && pos.y < TITLE_HEIGHT), | |
| 85 | 추가: "제목 표시줄에 창 제목이 없음: {shown:?}" | |
| 86 | 추가: ); | |
| 87 | 추가: assert_eq!( | |
| 88 | 추가: window_commands(&press_release(&ctx, &mut app, point)), | |
| 89 | 추가: [expected] | |
| 90 | 추가: ); | |
| 91 | 추가: } | |
| 92 | 추가: | |
| 93 | 추가: // 제목 표시줄을 끌면 운영체제 창 이동을 시작함. | |
| 94 | 추가: let scratch = Folder::new(); | |
| 95 | 추가: let factory = FakeFactory::default(); | |
| 96 | 추가: let mut app = loaded(&scratch, &factory); | |
| 97 | 추가: app.set_custom_frame(true); | |
| 98 | 추가: let ctx = egui::Context::default(); | |
| 99 | 추가: let start = egui::pos2(300.0, TITLE_HEIGHT / 2.0); | |
| 100 | 추가: frame_output(&ctx, &mut app, vec![egui::Event::PointerMoved(start)]); | |
| 101 | 추가: let mut commands = root_commands(&frame_output( | |
| 102 | 추가: &ctx, | |
| 103 | 추가: &mut app, | |
| 104 | 추가: vec![egui::Event::PointerButton { | |
| 105 | 추가: pos: start, | |
| 106 | 추가: button: egui::PointerButton::Primary, | |
| 107 | 추가: pressed: true, | |
| 108 | 추가: modifiers: egui::Modifiers::NONE, | |
| 109 | 추가: }], | |
| 110 | 추가: )); | |
| 111 | 추가: for step in 1..=4 { | |
| 112 | 추가: commands.extend(root_commands(&frame_output( | |
| 113 | 추가: &ctx, | |
| 114 | 추가: &mut app, | |
| 115 | 추가: vec![egui::Event::PointerMoved( | |
| 116 | 추가: start + egui::vec2(6.0 * step as f32, 0.0), | |
| 117 | 추가: )], | |
| 118 | 추가: ))); | |
| 119 | 추가: } | |
| 120 | 추가: assert_eq!( | |
| 121 | 추가: window_commands(&commands), | |
| 122 | 추가: [egui::ViewportCommand::StartDrag] | |
| 123 | 추가: ); | |
| 124 | 추가: } | |
| 125 | 추가: | |
| 126 | 추가: #[test] | |
| 127 | 추가: fn default_window_frame_draws_no_title_bar_or_window_commands() { | |
| 128 | 추가: let scratch = Folder::new(); | |
| 129 | 추가: let factory = FakeFactory::default(); | |
| 130 | 추가: let mut app = loaded(&scratch, &factory); | |
| 131 | 추가: let ctx = egui::Context::default(); | |
| 132 | 추가: let shown = labels(&frame_output(&ctx, &mut app, vec![]).shapes); | |
| 133 | 추가: assert!( | |
| 134 | 추가: !shown | |
| 135 | 추가: .iter() | |
| 136 | 추가: .any(|(text, _)| text.ends_with(" — Zipelo")), | |
| 137 | 추가: "운영체제가 테두리를 그릴 때는 제목 표시줄을 그리지 않아야 함" | |
| 138 | 추가: ); | |
| 139 | 추가: let close = egui::pos2(1060.0 - 6.0 - 17.0, 19.0); | |
| 140 | 추가: assert!(window_commands(&press_release(&ctx, &mut app, close)).is_empty()); | |
| 141 | 추가: } | |
| 142 | 추가: | |
| 143 | 추가: fn drag_without_release( | |
| 144 | 추가: ctx: &egui::Context, | |
| 145 | 추가: app: &mut ArchiveApp, | |
| 146 | 추가: start: egui::Pos2, | |
| 147 | 추가: ) -> Vec<egui::ViewportCommand> { | |
| 148 | 추가: frame_output(ctx, app, vec![egui::Event::PointerMoved(start)]); | |
| 149 | 추가: let mut commands = root_commands(&frame_output( | |
| 150 | 추가: ctx, | |
| 151 | 추가: app, | |
| 152 | 추가: vec![egui::Event::PointerButton { | |
| 153 | 추가: pos: start, | |
| 154 | 추가: button: egui::PointerButton::Primary, | |
| 155 | 추가: pressed: true, | |
| 156 | 추가: modifiers: egui::Modifiers::NONE, | |
| 157 | 추가: }], | |
| 158 | 추가: )); | |
| 159 | 추가: for step in 1..=4 { | |
| 160 | 추가: commands.extend(root_commands(&frame_output( | |
| 161 | 추가: ctx, | |
| 162 | 추가: app, | |
| 163 | 추가: vec![egui::Event::PointerMoved( | |
| 164 | 추가: start + egui::vec2(6.0 * step as f32, 0.0), | |
| 165 | 추가: )], | |
| 166 | 추가: ))); | |
| 167 | 추가: } | |
| 168 | 추가: window_commands(&commands) | |
| 169 | 추가: } | |
| 170 | 추가: | |
| 171 | 추가: #[test] | |
| 172 | 추가: fn title_bar_drag_starts_again_when_the_system_swallowed_the_release() { | |
| 173 | 추가: use zipelo_ui_memory_app::window_frame::TITLE_HEIGHT; | |
| 174 | 추가: let scratch = Folder::new(); | |
| 175 | 추가: let factory = FakeFactory::default(); | |
| 176 | 추가: let mut app = loaded(&scratch, &factory); | |
| 177 | 추가: app.set_custom_frame(true); | |
| 178 | 추가: let ctx = egui::Context::default(); | |
| 179 | 추가: // GNOME Wayland는 창 이동이 끝나도 버튼 놓기를 앱에 보내지 않음. | |
| 180 | 추가: let first = drag_without_release(&ctx, &mut app, egui::pos2(300.0, TITLE_HEIGHT / 2.0)); | |
| 181 | 추가: assert_eq!(first, [egui::ViewportCommand::StartDrag]); | |
| 182 | 추가: let second = drag_without_release(&ctx, &mut app, egui::pos2(500.0, TITLE_HEIGHT / 2.0)); | |
| 183 | 추가: assert_eq!(second, [egui::ViewportCommand::StartDrag]); | |
| 184 | 추가: | |
| 185 | 추가: // 이동을 넘긴 뒤 다음 프레임 입력에 버튼 놓기를 넣어 눌림 상태를 풀어야 함. | |
| 186 | 추가: let mut raw = egui::RawInput::default(); | |
| 187 | 추가: eframe::App::raw_input_hook(&mut app, &ctx, &mut raw); | |
| 188 | 추가: assert!(raw.events.iter().any(|event| matches!( | |
| 189 | 추가: event, | |
| 190 | 추가: egui::Event::PointerButton { | |
| 191 | 추가: button: egui::PointerButton::Primary, | |
| 192 | 추가: pressed: false, | |
| 193 | 추가: .. | |
| 194 | 추가: } | |
| 195 | 추가: ))); | |
| 196 | 추가: frame_output(&ctx, &mut app, raw.events); | |
| 197 | 추가: assert!(!ctx.input(|i| i.pointer.any_down())); | |
| 198 | 추가: let mut again = egui::RawInput::default(); | |
| 199 | 추가: eframe::App::raw_input_hook(&mut app, &ctx, &mut again); | |
| 200 | 추가: assert!(again.events.is_empty(), "놓기는 이동 한 번에 한 번만 넣어야 함"); | |
| 201 | 추가: } |
| @@ -0,0 +1,412 @@ | ||
| 1 | 추가: // 별도 진행 창(실제 즉시 viewport 콜백)에서 파일 선택 대기 중에 작업이 시작되지 않는지 확인함. | |
| 2 | 추가: | |
| 3 | 추가: #[derive(Default)] | |
| 4 | 추가: struct WorkChild { | |
| 5 | 추가: events: Vec<egui::Event>, | |
| 6 | 추가: labels: Vec<(String, egui::Pos2)>, | |
| 7 | 추가: rendered: usize, | |
| 8 | 추가: } | |
| 9 | 추가: | |
| 10 | 추가: std::thread_local! { | |
| 11 | 추가: static WORK_CHILD: std::cell::RefCell<WorkChild> = Default::default(); | |
| 12 | 추가: } | |
| 13 | 추가: | |
| 14 | 추가: /// eframe처럼 별도 viewport 콜백을 같은 Context에서 실행하고, 그 viewport에만 입력을 넣음. | |
| 15 | 추가: fn install_work_child_renderer() { | |
| 16 | 추가: // 같은 스레드에서 이어 도는 시험끼리 기록이 섞이지 않게 비움. | |
| 17 | 추가: WORK_CHILD.with(|child| *child.borrow_mut() = WorkChild::default()); | |
| 18 | 추가: egui::Context::set_immediate_viewport_renderer(|ctx, mut viewport| { | |
| 19 | 추가: let events = WORK_CHILD.with(|child| std::mem::take(&mut child.borrow_mut().events)); | |
| 20 | 추가: let mut raw = egui::RawInput { | |
| 21 | 추가: viewport_id: viewport.ids.this, | |
| 22 | 추가: screen_rect: Some(egui::Rect::from_min_size( | |
| 23 | 추가: egui::Pos2::ZERO, | |
| 24 | 추가: egui::vec2(480.0, 240.0), | |
| 25 | 추가: )), | |
| 26 | 추가: events, | |
| 27 | 추가: ..Default::default() | |
| 28 | 추가: }; | |
| 29 | 추가: raw.viewports.insert( | |
| 30 | 추가: viewport.ids.this, | |
| 31 | 추가: egui::ViewportInfo { | |
| 32 | 추가: parent: Some(viewport.ids.parent), | |
| 33 | 추가: focused: Some(true), | |
| 34 | 추가: ..Default::default() | |
| 35 | 추가: }, | |
| 36 | 추가: ); | |
| 37 | 추가: let mut output = ctx.run_ui(raw, |ui| (viewport.viewport_ui_cb)(ui)); | |
| 38 | 추가: output.textures_delta.clear(); | |
| 39 | 추가: WORK_CHILD.with(|child| { | |
| 40 | 추가: let mut child = child.borrow_mut(); | |
| 41 | 추가: child.labels = labels(&output.shapes); | |
| 42 | 추가: // 진행·결과 창이 그려진 횟수만 셈(다른 별도 창은 세지 않음). | |
| 43 | 추가: if viewport.ids.this == egui::ViewportId::from_hash_of("archive-work") { | |
| 44 | 추가: child.rendered += 1; | |
| 45 | 추가: } | |
| 46 | 추가: }); | |
| 47 | 추가: }); | |
| 48 | 추가: } | |
| 49 | 추가: | |
| 50 | 추가: fn work_child_label(label: &str) -> Option<egui::Pos2> { | |
| 51 | 추가: WORK_CHILD.with(|child| { | |
| 52 | 추가: child | |
| 53 | 추가: .borrow() | |
| 54 | 추가: .labels | |
| 55 | 추가: .iter() | |
| 56 | 추가: .rev() | |
| 57 | 추가: .find(|(text, _)| text == label) | |
| 58 | 추가: .map(|(_, pos)| *pos) | |
| 59 | 추가: }) | |
| 60 | 추가: } | |
| 61 | 추가: | |
| 62 | 추가: fn work_child_click(ctx: &egui::Context, app: &mut ArchiveApp, point: egui::Pos2) { | |
| 63 | 추가: for pressed in [true, false] { | |
| 64 | 추가: WORK_CHILD.with(|child| { | |
| 65 | 추가: child.borrow_mut().events = vec![ | |
| 66 | 추가: egui::Event::PointerMoved(point), | |
| 67 | 추가: egui::Event::PointerButton { | |
| 68 | 추가: pos: point, | |
| 69 | 추가: button: egui::PointerButton::Primary, | |
| 70 | 추가: pressed, | |
| 71 | 추가: modifiers: egui::Modifiers::NONE, | |
| 72 | 추가: }, | |
| 73 | 추가: ]; | |
| 74 | 추가: }); | |
| 75 | 추가: policy_render(ctx, app, vec![]); | |
| 76 | 추가: } | |
| 77 | 추가: } | |
| 78 | 추가: | |
| 79 | 추가: /// 열기 선택 창의 응답을 시험이 보낼 때까지 보류함. | |
| 80 | 추가: #[derive(Clone, Default)] | |
| 81 | 추가: struct HeldDialogs( | |
| 82 | 추가: std::rc::Rc< | |
| 83 | 추가: std::cell::RefCell< | |
| 84 | 추가: Vec<std::sync::mpsc::Sender<zipelo_ui_memory_app::archive_dialog::DialogAnswer>>, | |
| 85 | 추가: >, | |
| 86 | 추가: >, | |
| 87 | 추가: ); | |
| 88 | 추가: | |
| 89 | 추가: impl zipelo_ui_memory_app::archive_dialog::Dialogs for HeldDialogs { | |
| 90 | 추가: fn choose( | |
| 91 | 추가: &mut self, | |
| 92 | 추가: _: zipelo_ui_memory_app::archive_dialog::DialogRequest, | |
| 93 | 추가: ) -> zipelo_ui_memory_app::archive_dialog::DialogAnswer { | |
| 94 | 추가: Ok(None) | |
| 95 | 추가: } | |
| 96 | 추가: | |
| 97 | 추가: fn start( | |
| 98 | 추가: &mut self, | |
| 99 | 추가: _: zipelo_ui_memory_app::archive_dialog::DialogRequest, | |
| 100 | 추가: ) -> zipelo_ui_memory_app::archive_dialog::PendingDialog { | |
| 101 | 추가: let (sender, receiver) = std::sync::mpsc::channel(); | |
| 102 | 추가: self.0.borrow_mut().push(sender); | |
| 103 | 추가: zipelo_ui_memory_app::archive_dialog::PendingDialog::Waiting(receiver) | |
| 104 | 추가: } | |
| 105 | 추가: } | |
| 106 | 추가: | |
| 107 | 추가: #[test] | |
| 108 | 추가: fn picker_wait_blocks_retry_in_separate_work_window() { | |
| 109 | 추가: let scratch = Folder::new(); | |
| 110 | 추가: let factory = FakeFactory::default(); | |
| 111 | 추가: let mut app = loaded(&scratch, &factory); | |
| 112 | 추가: factory.state.borrow_mut().manual = true; | |
| 113 | 추가: assert!(app.begin_extract()); | |
| 114 | 추가: { | |
| 115 | 추가: let mut worker = factory.state.borrow_mut(); | |
| 116 | 추가: worker.frame(Event::Accepted { encryption: false }); | |
| 117 | 추가: worker.finish(Outcome::Failed, Publication::None); | |
| 118 | 추가: for event in &mut worker.queue { | |
| 119 | 추가: if let HostEvent::Frame { | |
| 120 | 추가: event: Event::Terminal(t), | |
| 121 | 추가: .. | |
| 122 | 추가: } = event | |
| 123 | 추가: { | |
| 124 | 추가: t.error = Some(ErrorCode::Io); | |
| 125 | 추가: } | |
| 126 | 추가: } | |
| 127 | 추가: } | |
| 128 | 추가: let ctx = egui::Context::default(); | |
| 129 | 추가: ctx.set_embed_viewports(false); | |
| 130 | 추가: install_work_child_renderer(); | |
| 131 | 추가: for _ in 0..10 { | |
| 132 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 133 | 추가: } | |
| 134 | 추가: assert!( | |
| 135 | 추가: WORK_CHILD.with(|child| child.borrow().rendered) > 0, | |
| 136 | 추가: "결과가 별도 viewport에 그려져야 함" | |
| 137 | 추가: ); | |
| 138 | 추가: let retry = work_child_label("다시 시도").expect("별도 결과 창에 다시 시도 버튼이 있어야 함"); | |
| 139 | 추가: | |
| 140 | 추가: let dialogs = HeldDialogs::default(); | |
| 141 | 추가: app.set_dialogs(Box::new(dialogs.clone())); | |
| 142 | 추가: policy_click(&ctx, &mut app, "열기"); | |
| 143 | 추가: assert_eq!( | |
| 144 | 추가: dialogs.0.borrow().len(), | |
| 145 | 추가: 1, | |
| 146 | 추가: "열기 선택 창이 응답을 기다려야 함" | |
| 147 | 추가: ); | |
| 148 | 추가: let before = factory.state.borrow().starts.len(); | |
| 149 | 추가: work_child_click(&ctx, &mut app, retry); | |
| 150 | 추가: assert_eq!( | |
| 151 | 추가: factory.state.borrow().starts.len(), | |
| 152 | 추가: before, | |
| 153 | 추가: "파일 선택 창이 열린 동안 별도 결과 창에서 작업이 시작됨" | |
| 154 | 추가: ); | |
| 155 | 추가: | |
| 156 | 추가: // 대조: 선택 창을 닫으면 같은 클릭으로 다시 시도가 시작됨. | |
| 157 | 추가: dialogs.0.borrow()[0].send(Ok(None)).unwrap(); | |
| 158 | 추가: for _ in 0..3 { | |
| 159 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 160 | 추가: } | |
| 161 | 추가: let retry = work_child_label("다시 시도").expect("선택 창을 닫은 뒤에도 결과가 남아야 함"); | |
| 162 | 추가: work_child_click(&ctx, &mut app, retry); | |
| 163 | 추가: assert_eq!(factory.state.borrow().starts.len(), before + 1); | |
| 164 | 추가: } | |
| 165 | 추가: | |
| 166 | 추가: #[test] | |
| 167 | 추가: fn password_prompt_is_not_covered_by_separate_work_window() { | |
| 168 | 추가: let scratch = Folder::new(); | |
| 169 | 추가: let factory = FakeFactory::manual(); | |
| 170 | 추가: let mut app = ArchiveApp::new(Box::new(factory.clone()), None, false); | |
| 171 | 추가: assert!(app.model.begin( | |
| 172 | 추가: Start::CreateZip { | |
| 173 | 추가: sources: vec![(scratch.0.join("source"), "source".into())], | |
| 174 | 추가: output_file: scratch.0.join("output.zip"), | |
| 175 | 추가: method: Method::Deflate, | |
| 176 | 추가: aes256: true | |
| 177 | 추가: }, | |
| 178 | 추가: &mut factory.clone() | |
| 179 | 추가: )); | |
| 180 | 추가: { | |
| 181 | 추가: let mut worker = factory.state.borrow_mut(); | |
| 182 | 추가: worker.frame(Event::Accepted { encryption: true }); | |
| 183 | 추가: worker.frame(Event::PasswordRequired { | |
| 184 | 추가: challenge_id: 17, | |
| 185 | 추가: attempt: 1, | |
| 186 | 추가: encrypt: true, | |
| 187 | 추가: }); | |
| 188 | 추가: } | |
| 189 | 추가: let ctx = egui::Context::default(); | |
| 190 | 추가: ctx.set_embed_viewports(false); | |
| 191 | 추가: install_work_child_renderer(); | |
| 192 | 추가: for _ in 0..12 { | |
| 193 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 194 | 추가: } | |
| 195 | 추가: assert!(app.model.challenge.is_some(), "암호 입력을 기다려야 함"); | |
| 196 | 추가: // 작업자 사건을 처리하기 전 몇 프레임은 진행 창이 정상으로 그려짐. | |
| 197 | 추가: // 암호 입력 창이 뜬 뒤부터 진행 창이 그려지는지만 셈. | |
| 198 | 추가: WORK_CHILD.with(|child| child.borrow_mut().rendered = 0); | |
| 199 | 추가: for _ in 0..5 { | |
| 200 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 201 | 추가: } | |
| 202 | 추가: assert!( | |
| 203 | 추가: ctx.read_response(egui::Id::unique("archive-password-input")) | |
| 204 | 추가: .is_some(), | |
| 205 | 추가: "메인 창에 암호 입력란이 있어야 함" | |
| 206 | 추가: ); | |
| 207 | 추가: // 항상 위에 뜨는 진행 창이 메인 창 가운데의 암호 입력란을 가리지 않도록 | |
| 208 | 추가: // 암호를 기다리는 동안에는 진행 창을 그리지 않음. | |
| 209 | 추가: assert_eq!( | |
| 210 | 추가: WORK_CHILD.with(|child| child.borrow().rendered), | |
| 211 | 추가: 0, | |
| 212 | 추가: "암호 입력 중에 별도 진행 창이 떠 있음" | |
| 213 | 추가: ); | |
| 214 | 추가: | |
| 215 | 추가: // 암호 입력이 끝나 작업이 이어지면 진행 창이 다시 나타남. | |
| 216 | 추가: app.model.challenge = None; | |
| 217 | 추가: for _ in 0..3 { | |
| 218 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 219 | 추가: } | |
| 220 | 추가: assert!(app.model.busy()); | |
| 221 | 추가: assert!( | |
| 222 | 추가: WORK_CHILD.with(|child| child.borrow().rendered) > 0, | |
| 223 | 추가: "암호 입력 뒤 진행 창이 다시 나타나야 함" | |
| 224 | 추가: ); | |
| 225 | 추가: } | |
| 226 | 추가: | |
| 227 | 추가: #[test] | |
| 228 | 추가: fn close_confirmation_is_not_covered_by_separate_work_window() { | |
| 229 | 추가: let scratch = Folder::new(); | |
| 230 | 추가: let factory = FakeFactory::default(); | |
| 231 | 추가: let mut app = loaded(&scratch, &factory); | |
| 232 | 추가: factory.state.borrow_mut().manual = true; | |
| 233 | 추가: assert!(app.begin_extract()); | |
| 234 | 추가: factory | |
| 235 | 추가: .state | |
| 236 | 추가: .borrow_mut() | |
| 237 | 추가: .frame(Event::Accepted { encryption: false }); | |
| 238 | 추가: let ctx = egui::Context::default(); | |
| 239 | 추가: ctx.set_embed_viewports(false); | |
| 240 | 추가: install_work_child_renderer(); | |
| 241 | 추가: for _ in 0..6 { | |
| 242 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 243 | 추가: } | |
| 244 | 추가: assert!(app.model.busy()); | |
| 245 | 추가: assert!( | |
| 246 | 추가: WORK_CHILD.with(|child| child.borrow().rendered) > 0, | |
| 247 | 추가: "작업 중에는 진행 창이 떠 있어야 함" | |
| 248 | 추가: ); | |
| 249 | 추가: | |
| 250 | 추가: // 작업 중 메인 창을 닫으면 메인 창 가운데에 종료 확인 창이 뜸. | |
| 251 | 추가: app.model.request_close(); | |
| 252 | 추가: assert_eq!(app.model.close, Close::Confirm); | |
| 253 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 254 | 추가: WORK_CHILD.with(|child| child.borrow_mut().rendered = 0); | |
| 255 | 추가: let mut shown = Vec::new(); | |
| 256 | 추가: for _ in 0..5 { | |
| 257 | 추가: shown = policy_render(&ctx, &mut app, vec![]); | |
| 258 | 추가: } | |
| 259 | 추가: for label in ["작업 중 닫기", "계속 작업", "취소하고 닫기"] { | |
| 260 | 추가: assert!(shown.iter().any(|(text, _)| text == label), "{label}"); | |
| 261 | 추가: } | |
| 262 | 추가: // 항상 위에 뜨는 진행 창이 확인 창을 가리지 않도록 그동안 진행 창을 그리지 않음. | |
| 263 | 추가: assert_eq!( | |
| 264 | 추가: WORK_CHILD.with(|child| child.borrow().rendered), | |
| 265 | 추가: 0, | |
| 266 | 추가: "종료 확인 중에 별도 진행 창이 떠 있음" | |
| 267 | 추가: ); | |
| 268 | 추가: | |
| 269 | 추가: // 계속 작업을 고르면 진행 창이 다시 나타남. | |
| 270 | 추가: app.model.keep_open(); | |
| 271 | 추가: for _ in 0..3 { | |
| 272 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 273 | 추가: } | |
| 274 | 추가: assert!(app.model.busy()); | |
| 275 | 추가: assert!( | |
| 276 | 추가: WORK_CHILD.with(|child| child.borrow().rendered) > 0, | |
| 277 | 추가: "계속 작업을 고르면 진행 창이 다시 나타나야 함" | |
| 278 | 추가: ); | |
| 279 | 추가: | |
| 280 | 추가: // 취소하고 닫기 뒤 정리를 기다리는 동안("종료 확인 중")도 가리지 않음. | |
| 281 | 추가: app.model.request_close(); | |
| 282 | 추가: app.model.confirm_close(); | |
| 283 | 추가: assert_eq!(app.model.close, Close::Waiting); | |
| 284 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 285 | 추가: WORK_CHILD.with(|child| child.borrow_mut().rendered = 0); | |
| 286 | 추가: for _ in 0..5 { | |
| 287 | 추가: shown = policy_render(&ctx, &mut app, vec![]); | |
| 288 | 추가: } | |
| 289 | 추가: assert!(shown.iter().any(|(text, _)| text == "종료 확인 중")); | |
| 290 | 추가: assert_eq!( | |
| 291 | 추가: WORK_CHILD.with(|child| child.borrow().rendered), | |
| 292 | 추가: 0, | |
| 293 | 추가: "종료 확인 중에 별도 진행 창이 떠 있음" | |
| 294 | 추가: ); | |
| 295 | 추가: | |
| 296 | 추가: // 정리가 끝나 결과 확인 후 닫기가 뜰 때도 결과 창이 가리지 않음. | |
| 297 | 추가: factory | |
| 298 | 추가: .state | |
| 299 | 추가: .borrow_mut() | |
| 300 | 추가: .finish(Outcome::Cancelled, Publication::None); | |
| 301 | 추가: for _ in 0..12 { | |
| 302 | 추가: shown = policy_render(&ctx, &mut app, vec![]); | |
| 303 | 추가: } | |
| 304 | 추가: assert_eq!(app.model.close, Close::Review); | |
| 305 | 추가: assert!(shown.iter().any(|(text, _)| text == "결과 확인 후 닫기")); | |
| 306 | 추가: assert_eq!( | |
| 307 | 추가: WORK_CHILD.with(|child| child.borrow().rendered), | |
| 308 | 추가: 0, | |
| 309 | 추가: "결과 확인 후 닫기에 별도 결과 창이 떠 있음" | |
| 310 | 추가: ); | |
| 311 | 추가: } | |
| 312 | 추가: | |
| 313 | 추가: /// 추출이 실패해 별도 결과 창이 남아 있는 상태를 만듦. | |
| 314 | 추가: fn failed_result(scratch: &Folder, factory: &FakeFactory) -> ArchiveApp { | |
| 315 | 추가: let mut app = loaded(scratch, factory); | |
| 316 | 추가: factory.state.borrow_mut().manual = true; | |
| 317 | 추가: assert!(app.begin_extract()); | |
| 318 | 추가: let mut worker = factory.state.borrow_mut(); | |
| 319 | 추가: worker.frame(Event::Accepted { encryption: false }); | |
| 320 | 추가: worker.finish(Outcome::Failed, Publication::None); | |
| 321 | 추가: for event in &mut worker.queue { | |
| 322 | 추가: if let HostEvent::Frame { | |
| 323 | 추가: event: Event::Terminal(t), | |
| 324 | 추가: .. | |
| 325 | 추가: } = event | |
| 326 | 추가: { | |
| 327 | 추가: t.error = Some(ErrorCode::Io); | |
| 328 | 추가: } | |
| 329 | 추가: } | |
| 330 | 추가: drop(worker); | |
| 331 | 추가: app | |
| 332 | 추가: } | |
| 333 | 추가: | |
| 334 | 추가: fn work_rendered() -> usize { | |
| 335 | 추가: WORK_CHILD.with(|child| child.borrow().rendered) | |
| 336 | 추가: } | |
| 337 | 추가: | |
| 338 | 추가: #[test] | |
| 339 | 추가: fn main_modals_are_not_covered_by_separate_result_window() { | |
| 340 | 추가: // 암호 입력과 종료 확인은 작업 중에만 뜨므로 위 시험들이 진행 창과의 조합을 봄. | |
| 341 | 추가: // 작업이 끝난 뒤 결과 창과 함께 뜰 수 있는 모달(ZIP 만들기, 파일 선택 안내)을 여기서 봄. | |
| 342 | 추가: let scratch = Folder::new(); | |
| 343 | 추가: let factory = FakeFactory::default(); | |
| 344 | 추가: let mut app = failed_result(&scratch, &factory); | |
| 345 | 추가: let ctx = egui::Context::default(); | |
| 346 | 추가: ctx.set_embed_viewports(false); | |
| 347 | 추가: install_work_child_renderer(); | |
| 348 | 추가: for _ in 0..10 { | |
| 349 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 350 | 추가: } | |
| 351 | 추가: assert!(!app.model.busy()); | |
| 352 | 추가: assert!(work_rendered() > 0, "결과가 별도 viewport에 그려져야 함"); | |
| 353 | 추가: | |
| 354 | 추가: // 결과 창을 둔 채 ZIP 만들기를 열면 그동안 결과 창을 그리지 않음. | |
| 355 | 추가: app.show_create(false); | |
| 356 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 357 | 추가: WORK_CHILD.with(|child| child.borrow_mut().rendered = 0); | |
| 358 | 추가: let mut shown = Vec::new(); | |
| 359 | 추가: for _ in 0..5 { | |
| 360 | 추가: shown = policy_render(&ctx, &mut app, vec![]); | |
| 361 | 추가: } | |
| 362 | 추가: assert!(shown.iter().any(|(text, _)| text == "ZIP 만들기")); | |
| 363 | 추가: assert_eq!( | |
| 364 | 추가: work_rendered(), | |
| 365 | 추가: 0, | |
| 366 | 추가: "ZIP 만들기 창 위에 별도 결과 창이 떠 있음" | |
| 367 | 추가: ); | |
| 368 | 추가: | |
| 369 | 추가: // ZIP 만들기를 닫으면 결과 창이 다시 나타남. | |
| 370 | 추가: policy_click(&ctx, &mut app, "취소"); | |
| 371 | 추가: for _ in 0..3 { | |
| 372 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 373 | 추가: } | |
| 374 | 추가: assert!( | |
| 375 | 추가: work_rendered() > 0, | |
| 376 | 추가: "ZIP 만들기를 닫으면 결과 창이 다시 나타나야 함" | |
| 377 | 추가: ); | |
| 378 | 추가: | |
| 379 | 추가: // 파일 선택 창을 기다리는 안내가 뜬 동안에도 결과 창을 그리지 않음. | |
| 380 | 추가: let dialogs = HeldDialogs::default(); | |
| 381 | 추가: app.set_dialogs(Box::new(dialogs.clone())); | |
| 382 | 추가: policy_click(&ctx, &mut app, "열기"); | |
| 383 | 추가: assert_eq!( | |
| 384 | 추가: dialogs.0.borrow().len(), | |
| 385 | 추가: 1, | |
| 386 | 추가: "열기 선택 창이 응답을 기다려야 함" | |
| 387 | 추가: ); | |
| 388 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 389 | 추가: WORK_CHILD.with(|child| child.borrow_mut().rendered = 0); | |
| 390 | 추가: for _ in 0..5 { | |
| 391 | 추가: shown = policy_render(&ctx, &mut app, vec![]); | |
| 392 | 추가: } | |
| 393 | 추가: assert!( | |
| 394 | 추가: shown | |
| 395 | 추가: .iter() | |
| 396 | 추가: .any(|(text, _)| text == "파일 선택 창에서 선택을 마쳐 주세요") | |
| 397 | 추가: ); | |
| 398 | 추가: assert_eq!( | |
| 399 | 추가: work_rendered(), | |
| 400 | 추가: 0, | |
| 401 | 추가: "파일 선택 안내 위에 별도 결과 창이 떠 있음" | |
| 402 | 추가: ); | |
| 403 | 추가: | |
| 404 | 추가: dialogs.0.borrow()[0].send(Ok(None)).unwrap(); | |
| 405 | 추가: for _ in 0..3 { | |
| 406 | 추가: policy_render(&ctx, &mut app, vec![]); | |
| 407 | 추가: } | |
| 408 | 추가: assert!( | |
| 409 | 추가: work_rendered() > 0, | |
| 410 | 추가: "선택 창을 닫으면 결과 창이 다시 나타나야 함" | |
| 411 | 추가: ); | |
| 412 | 추가: } |