Linux 파일 선택 멈춤을 고치고 작업 진행을 별도 창으로 옮김
- Linux 포털 파일 선택 창을 화면 스레드에서 기다려 GNOME이 "응답 없음"을 표시하던 문제를 고침. 선택 창은 별도 스레드에서 열고 결과를 프레임마다 받음. - 파일 목록 아래 작업 패널을 없애고 진행과 결과를 작은 별도 창으로 옮김. 부모 창 가운데에 열고, 옮긴 상대 위치를 유지한 채 부모 창을 따라감. Wayland에서는 창 위치를 정할 수 없어 창 관리자가 위치를 정함. - 원본을 읽는 단계에서는 처리한 항목 수를 표시하지 않음. - GNOME Wayland는 창 테두리를 그려 주지 않아 한글 제목이 깨지므로 앱 글꼴로 제목 표시줄을 직접 그림. 창 이동 뒤 버튼 놓기가 오지 않아 다음 끌기가 시작되지 않던 문제를 원시 입력 판단과 놓기 보충으로 고침. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 작성자
- LeeJunyoung
- 작성 시각
- 커밋
f3f54eb126b900ce12b6b8f25e051b53c0fc072a- 부모
- e4faa4c
변경된 파일 7개
+797-21| @@ -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(); |
| @@ -306,7 +354,7 @@ impl ArchiveApp { | ||
| 306 | 354 | } |
| 307 | 355 | |
| 308 | 356 | fn open_picker(&mut self, purpose: Purpose) { |
| 309 | 삭제: if self.model.busy() { | |
| 357 | 추가: if self.model.busy() || self.picker.is_some() { | |
| 310 | 358 | return; |
| 311 | 359 | } |
| 312 | 360 | let gzip = self |
| @@ -345,10 +393,28 @@ impl ArchiveApp { | ||
| 345 | 393 | self.zip_name.clone() |
| 346 | 394 | }, |
| 347 | 395 | }; |
| 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 | 삭제: { | |
| 396 | 추가: match self.dialogs.start(request) { | |
| 397 | 추가: PendingDialog::Ready(answer) => self.apply_picker(purpose, answer), | |
| 398 | 추가: PendingDialog::Waiting(receiver) => self.picker = Some((purpose, receiver)), | |
| 399 | 추가: } | |
| 400 | 추가: } | |
| 401 | 추가: | |
| 402 | 추가: fn poll_picker(&mut self) { | |
| 403 | 추가: let Some((purpose, receiver)) = &self.picker else { | |
| 404 | 추가: return; | |
| 405 | 추가: }; | |
| 406 | 추가: let purpose = *purpose; | |
| 407 | 추가: let answer = match receiver.try_recv() { | |
| 408 | 추가: Ok(answer) => answer, | |
| 409 | 추가: Err(std::sync::mpsc::TryRecvError::Empty) => return, | |
| 410 | 추가: Err(std::sync::mpsc::TryRecvError::Disconnected) => Err(DIALOG_UNAVAILABLE.into()), | |
| 411 | 추가: }; | |
| 412 | 추가: self.picker = None; | |
| 413 | 추가: self.apply_picker(purpose, answer); | |
| 414 | 추가: } | |
| 415 | 추가: | |
| 416 | 추가: fn apply_picker(&mut self, purpose: Purpose, answer: DialogAnswer) { | |
| 417 | 추가: if answer.is_ok() && self.ui_error.as_deref() == Some(DIALOG_UNAVAILABLE) { | |
| 352 | 418 | self.ui_error = None; |
| 353 | 419 | } |
| 354 | 420 | match answer { |
| @@ -479,19 +545,23 @@ impl ArchiveApp { | ||
| 479 | 545 | self.initialized = true; |
| 480 | 546 | } |
| 481 | 547 | self.poll(); |
| 548 | 추가: self.poll_picker(); | |
| 482 | 549 | let challenge = self.model.challenge.map(|(id, _, _)| id); |
| 483 | 550 | let new_challenge = challenge != self.password_challenge; |
| 484 | 551 | if new_challenge || challenge.is_none() { |
| 485 | 552 | self.clear_password(); |
| 486 | 553 | } |
| 487 | 554 | self.password_challenge = challenge; |
| 488 | 삭제: self.on_drop(ctx.input(|i| { | |
| 555 | 추가: let dropped = ctx.input(|i| { | |
| 489 | 556 | i.raw |
| 490 | 557 | .dropped_files |
| 491 | 558 | .iter() |
| 492 | 559 | .map(|file| file.path().to_path_buf()) |
| 493 | 560 | .collect() |
| 494 | 삭제: })); | |
| 561 | 추가: }); | |
| 562 | 추가: if self.picker.is_none() { | |
| 563 | 추가: self.on_drop(dropped); | |
| 564 | 추가: } | |
| 495 | 565 | if ctx.input(|i| i.viewport().close_requested()) { |
| 496 | 566 | self.model.request_close(); |
| 497 | 567 | if self.model.close != Close::Allowed { |
| @@ -523,6 +593,19 @@ impl ArchiveApp { | ||
| 523 | 593 | title.clone() |
| 524 | 594 | }; |
| 525 | 595 | ctx.send_viewport_cmd(egui::ViewportCommand::Title(short_title)); |
| 596 | 추가: if self.custom_frame | |
| 597 | 추가: && window_frame::title_bar( | |
| 598 | 추가: root, | |
| 599 | 추가: "main", | |
| 600 | 추가: &title, | |
| 601 | 추가: window_frame::Buttons { | |
| 602 | 추가: minimize: true, | |
| 603 | 추가: maximize: true, | |
| 604 | 추가: }, | |
| 605 | 추가: ) | |
| 606 | 추가: { | |
| 607 | 추가: self.release_after_move = true; | |
| 608 | 추가: } | |
| 526 | 609 | egui::Panel::top("archive-actions") |
| 527 | 610 | .frame( |
| 528 | 611 | theme::panel(theme::PANEL) |
| @@ -531,7 +614,9 @@ impl ArchiveApp { | ||
| 531 | 614 | ) |
| 532 | 615 | .show(root, |ui| { |
| 533 | 616 | ui.horizontal(|ui| { |
| 534 | 삭제: let idle = !self.model.busy() && self.model.close == Close::Open; | |
| 617 | 추가: let idle = !self.model.busy() | |
| 618 | 추가: && self.model.close == Close::Open | |
| 619 | 추가: && self.picker.is_none(); | |
| 535 | 620 | if theme::tool(ui, "열기", theme::OPEN, idle, false) |
| 536 | 621 | .on_hover_text(&title) |
| 537 | 622 | .clicked() |
| @@ -587,7 +672,8 @@ impl ArchiveApp { | ||
| 587 | 672 | }); |
| 588 | 673 | }); |
| 589 | 674 | }); |
| 590 | 삭제: if self.model.busy() || self.result_visible() || (self.ui_error.is_some() && !self.create) { | |
| 675 | 추가: if ctx.embed_viewports() && self.work_visible() { | |
| 676 | 추가: // 별도 창을 만들 수 없을 때만 쓰는 대체 배치. 목록을 가리지 않도록 하단에 둠. | |
| 591 | 677 | egui::Panel::bottom("archive-work") |
| 592 | 678 | .frame(theme::panel(theme::PANEL).corner_radius(0)) |
| 593 | 679 | .show(root, |ui| self.work_area(ui)); |
| @@ -605,6 +691,7 @@ impl ArchiveApp { | ||
| 605 | 691 | self.empty(ui); |
| 606 | 692 | } |
| 607 | 693 | }); |
| 694 | 추가: self.work_window(&ctx); | |
| 608 | 695 | if self.create && !self.model.busy() { |
| 609 | 696 | self.create_dialog(&ctx); |
| 610 | 697 | } |
| @@ -612,11 +699,27 @@ impl ArchiveApp { | ||
| 612 | 699 | self.password_dialog(&ctx, new_challenge); |
| 613 | 700 | } |
| 614 | 701 | self.close_dialog(&ctx); |
| 702 | 추가: self.picker_notice(&ctx); | |
| 703 | 추가: if self.custom_frame { | |
| 704 | 추가: window_frame::edges(&ctx, true); | |
| 705 | 추가: } | |
| 615 | 706 | if self.model.busy() { |
| 616 | 707 | ctx.request_repaint_after(std::time::Duration::from_millis(30)); |
| 617 | 708 | } |
| 618 | 709 | } |
| 619 | 710 | |
| 711 | 추가: // 선택 창이 열려 있는 동안 다른 조작을 막고, 응답을 받도록 화면을 계속 갱신함. | |
| 712 | 추가: fn picker_notice(&mut self, ctx: &egui::Context) { | |
| 713 | 추가: if self.picker.is_none() { | |
| 714 | 추가: return; | |
| 715 | 추가: } | |
| 716 | 추가: egui::Modal::new(egui::Id::unique("archive-picker")).show(ctx, |ui| { | |
| 717 | 추가: ui.set_width(360.0); | |
| 718 | 추가: ui.label("파일 선택 창에서 선택을 마쳐 주세요"); | |
| 719 | 추가: }); | |
| 720 | 추가: ctx.request_repaint_after(std::time::Duration::from_millis(100)); | |
| 721 | 추가: } | |
| 722 | 추가: | |
| 620 | 723 | fn empty(&mut self, ui: &mut egui::Ui) { |
| 621 | 724 | let hovered = ui.ctx().input(|i| !i.raw.hovered_files.is_empty()); |
| 622 | 725 | let width = (ui.available_width() * 0.60) |
| @@ -1122,6 +1225,143 @@ impl ArchiveApp { | ||
| 1122 | 1225 | response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Alert, true, error)); |
| 1123 | 1226 | } |
| 1124 | 1227 | |
| 1228 | 추가: fn work_visible(&self) -> bool { | |
| 1229 | 추가: self.model.busy() || self.result_visible() || (self.ui_error.is_some() && !self.create) | |
| 1230 | 추가: } | |
| 1231 | 추가: | |
| 1232 | 추가: fn work_window(&mut self, ctx: &egui::Context) { | |
| 1233 | 추가: if !self.work_visible() { | |
| 1234 | 추가: self.work = WorkWindow::default(); | |
| 1235 | 추가: return; | |
| 1236 | 추가: } | |
| 1237 | 추가: if ctx.embed_viewports() { | |
| 1238 | 추가: // 별도 창을 만들 수 없는 환경(시험 등)은 show()에서 하단에 그림. | |
| 1239 | 추가: return; | |
| 1240 | 추가: } | |
| 1241 | 추가: let id = egui::ViewportId::from_hash_of("archive-work"); | |
| 1242 | 추가: let (parent, parent_focused, now) = ctx.input(|i| { | |
| 1243 | 추가: ( | |
| 1244 | 추가: i.viewport().outer_rect, | |
| 1245 | 추가: i.viewport().focused.unwrap_or(false), | |
| 1246 | 추가: i.time, | |
| 1247 | 추가: ) | |
| 1248 | 추가: }); | |
| 1249 | 추가: let (child, child_focused) = ctx.input(|i| { | |
| 1250 | 추가: i.raw.viewports.get(&id).map_or((None, false), |v| { | |
| 1251 | 추가: (v.outer_rect, v.focused.unwrap_or(false)) | |
| 1252 | 추가: }) | |
| 1253 | 추가: }); | |
| 1254 | 추가: let size = egui::vec2(WORK_WIDTH, self.work.height); | |
| 1255 | 추가: if !self.work.open { | |
| 1256 | 추가: // 처음 열 때 부모 창 가운데에 둠. Wayland처럼 위치를 알 수 없으면 창 관리자에 맡김. | |
| 1257 | 추가: self.work.open = true; | |
| 1258 | 추가: self.work.initial = parent.map(|p| (p.center() - size / 2.0).round()); | |
| 1259 | 추가: self.work.offset = self.work.initial.zip(parent).map(|(c, p)| c - p.min); | |
| 1260 | 추가: self.work.parent = parent.map(|p| p.min); | |
| 1261 | 추가: self.work.expected = self.work.initial; | |
| 1262 | 추가: self.work.settle_until = now + 0.5; | |
| 1263 | 추가: } | |
| 1264 | 추가: if let (Some(parent), Some(child)) = (parent, child) { | |
| 1265 | 추가: let parent_moved = self | |
| 1266 | 추가: .work | |
| 1267 | 추가: .parent | |
| 1268 | 추가: .is_some_and(|p| (p - parent.min).length() > 0.5); | |
| 1269 | 추가: let settled = self | |
| 1270 | 추가: .work | |
| 1271 | 추가: .expected | |
| 1272 | 추가: .is_some_and(|e| (child.min - e).length() <= 2.0); | |
| 1273 | 추가: if settled || now >= self.work.settle_until { | |
| 1274 | 추가: self.work.settle_until = 0.0; | |
| 1275 | 추가: } | |
| 1276 | 추가: if parent_moved { | |
| 1277 | 추가: if let Some(offset) = self.work.offset { | |
| 1278 | 추가: let target = (parent.min + offset).round(); | |
| 1279 | 추가: ctx.send_viewport_cmd_to(id, egui::ViewportCommand::OuterPosition(target)); | |
| 1280 | 추가: self.work.expected = Some(target); | |
| 1281 | 추가: self.work.settle_until = now + 0.5; | |
| 1282 | 추가: } | |
| 1283 | 추가: } else if self.work.settle_until == 0.0 && !settled { | |
| 1284 | 추가: // 사용자가 자식 창을 옮긴 위치를 부모 기준으로 기억함. | |
| 1285 | 추가: self.work.offset = Some(child.min - parent.min); | |
| 1286 | 추가: self.work.expected = Some(child.min); | |
| 1287 | 추가: } | |
| 1288 | 추가: self.work.parent = Some(parent.min); | |
| 1289 | 추가: } | |
| 1290 | 추가: let title = if self.model.busy() { | |
| 1291 | 추가: present::activity_text( | |
| 1292 | 추가: &self.model, | |
| 1293 | 추가: matches!(self.last_request, Some(Start::CreateZip { .. })), | |
| 1294 | 추가: ) | |
| 1295 | 추가: .to_owned() | |
| 1296 | 추가: } else { | |
| 1297 | 추가: "작업 결과".to_owned() | |
| 1298 | 추가: }; | |
| 1299 | 추가: let window_title = format!("{title} — Zipelo"); | |
| 1300 | 추가: let custom_frame = self.custom_frame; | |
| 1301 | 추가: let mut builder = egui::ViewportBuilder::default() | |
| 1302 | 추가: .with_title(window_title.clone()) | |
| 1303 | 추가: .with_decorations(!custom_frame) | |
| 1304 | 추가: .with_inner_size(size) | |
| 1305 | 추가: .with_resizable(false) | |
| 1306 | 추가: .with_minimize_button(false) | |
| 1307 | 추가: .with_maximize_button(false) | |
| 1308 | 추가: .with_taskbar(false) | |
| 1309 | 추가: // 앱을 쓰는 동안에만 부모 창 위에 유지함. | |
| 1310 | 추가: .with_window_level(if parent_focused || child_focused { | |
| 1311 | 추가: egui::WindowLevel::AlwaysOnTop | |
| 1312 | 추가: } else { | |
| 1313 | 추가: egui::WindowLevel::Normal | |
| 1314 | 추가: }); | |
| 1315 | 추가: if let Some(position) = self.work.initial { | |
| 1316 | 추가: builder = builder.with_position(position); | |
| 1317 | 추가: } | |
| 1318 | 추가: let height = ctx.show_viewport_immediate(id, builder, |ui, class| { | |
| 1319 | 추가: if ui.ctx().input(|i| i.viewport().close_requested()) { | |
| 1320 | 추가: if self.model.busy() { | |
| 1321 | 추가: ui.ctx() | |
| 1322 | 추가: .send_viewport_cmd(egui::ViewportCommand::CancelClose); | |
| 1323 | 추가: } else { | |
| 1324 | 추가: self.dismissed = true; | |
| 1325 | 추가: self.ui_error = None; | |
| 1326 | 추가: self.model.input_error = None; | |
| 1327 | 추가: } | |
| 1328 | 추가: } | |
| 1329 | 추가: if class == egui::ViewportClass::EmbeddedWindow { | |
| 1330 | 추가: ui.set_width(WORK_WIDTH); | |
| 1331 | 추가: self.work_area(ui); | |
| 1332 | 추가: return None; | |
| 1333 | 추가: } | |
| 1334 | 추가: let mut chrome = 0.0; | |
| 1335 | 추가: if custom_frame { | |
| 1336 | 추가: window_frame::title_bar( | |
| 1337 | 추가: ui, | |
| 1338 | 추가: "work", | |
| 1339 | 추가: &window_title, | |
| 1340 | 추가: window_frame::Buttons { | |
| 1341 | 추가: minimize: false, | |
| 1342 | 추가: maximize: false, | |
| 1343 | 추가: }, | |
| 1344 | 추가: ); | |
| 1345 | 추가: window_frame::edges(ui.ctx(), false); | |
| 1346 | 추가: chrome = window_frame::TITLE_HEIGHT; | |
| 1347 | 추가: } | |
| 1348 | 추가: let margin = theme::PAD as f32; | |
| 1349 | 추가: egui::CentralPanel::default() | |
| 1350 | 추가: .frame(theme::panel(theme::PANEL).corner_radius(0)) | |
| 1351 | 추가: .show(ui, |ui| { | |
| 1352 | 추가: let content = ui.vertical(|ui| self.work_area(ui)).response.rect; | |
| 1353 | 추가: Some(content.height() + 2.0 * margin + chrome) | |
| 1354 | 추가: }) | |
| 1355 | 추가: .inner | |
| 1356 | 추가: }); | |
| 1357 | 추가: if let Some(height) = height { | |
| 1358 | 추가: let height = height.clamp(WORK_MIN_HEIGHT, WORK_MAX_HEIGHT).ceil(); | |
| 1359 | 추가: if (height - self.work.height).abs() > 1.0 { | |
| 1360 | 추가: self.work.height = height; | |
| 1361 | 추가: } | |
| 1362 | 추가: } | |
| 1363 | 추가: } | |
| 1364 | 추가: | |
| 1125 | 1365 | fn work_area(&mut self, ui: &mut egui::Ui) { |
| 1126 | 1366 | if self.model.busy() { |
| 1127 | 1367 | self.progress(ui); |
| @@ -1159,7 +1399,13 @@ impl ArchiveApp { | ||
| 1159 | 1399 | let cancelling = self.model.cancellation_requested() || self.model.cancel.is_some(); |
| 1160 | 1400 | let title = present::activity_text(&self.model, creating); |
| 1161 | 1401 | ui.strong(title); |
| 1162 | 삭제: if let Some((_, done, total, count)) = self.model.progress { | |
| 1402 | 추가: if let Some((stage, done, total, count)) = self.model.progress { | |
| 1403 | 추가: // 원본을 읽는 단계에서는 아직 처리한 항목이 없으므로 개수를 표시하지 않음. | |
| 1404 | 추가: let processed = if stage == Stage::Read { | |
| 1405 | 추가: String::new() | |
| 1406 | 추가: } else { | |
| 1407 | 추가: format!("{count}개 처리함, ") | |
| 1408 | 추가: }; | |
| 1163 | 1409 | if let Some(total) = total.filter(|n| *n > 0) { |
| 1164 | 1410 | ui.scope(|ui| { |
| 1165 | 1411 | ui.visuals_mut().extreme_bg_color = theme::BORDER; |
| @@ -1171,7 +1417,7 @@ impl ArchiveApp { | ||
| 1171 | 1417 | }); |
| 1172 | 1418 | ui.horizontal(|ui| { |
| 1173 | 1419 | ui.label(format!( |
| 1174 | 삭제: "{:.0}% / {count}개 처리함, {} / {}", | |
| 1420 | 추가: "{:.0}% / {processed}{} / {}", | |
| 1175 | 1421 | (done as f64 / total as f64).clamp(0.0, 1.0) * 100.0, |
| 1176 | 1422 | present::bytes_text(done), |
| 1177 | 1423 | present::bytes_text(total) |
| @@ -1181,7 +1427,7 @@ impl ArchiveApp { | ||
| 1181 | 1427 | } else { |
| 1182 | 1428 | theme::indeterminate(ui); |
| 1183 | 1429 | ui.horizontal(|ui| { |
| 1184 | 삭제: ui.label(format!("{count}개 처리함, {}", present::bytes_text(done))); | |
| 1430 | 추가: ui.label(format!("{processed}{}", present::bytes_text(done))); | |
| 1185 | 1431 | self.cancel_action(ui, cancelling); |
| 1186 | 1432 | }); |
| 1187 | 1433 | } |
| @@ -1272,7 +1518,7 @@ impl ArchiveApp { | ||
| 1272 | 1518 | ); |
| 1273 | 1519 | ui.strong(title); |
| 1274 | 1520 | }); |
| 1275 | 삭제: let max_height = (ui.ctx().content_rect().height() * 0.24).max(80.0); | |
| 1521 | 추가: let max_height = WORK_RESULT_MAX_HEIGHT; | |
| 1276 | 1522 | egui::ScrollArea::vertical() |
| 1277 | 1523 | .id_salt("result-message") |
| 1278 | 1524 | .max_height(max_height) |
| @@ -1760,6 +2006,22 @@ impl eframe::App for ArchiveApp { | ||
| 1760 | 2006 | fn ui(&mut self, root: &mut egui::Ui, _: &mut eframe::Frame) { |
| 1761 | 2007 | self.show(root); |
| 1762 | 2008 | } |
| 2009 | 추가: | |
| 2010 | 추가: fn raw_input_hook(&mut self, ctx: &egui::Context, raw_input: &mut egui::RawInput) { | |
| 2011 | 추가: // 운영체제가 창 이동을 맡으면 버튼 놓기가 오지 않으므로 대신 넣어 눌림 상태를 풀어 줌. | |
| 2012 | 추가: if std::mem::take(&mut self.release_after_move) { | |
| 2013 | 추가: let pos = ctx.input(|i| i.pointer.latest_pos()).unwrap_or_default(); | |
| 2014 | 추가: raw_input.events.insert( | |
| 2015 | 추가: 0, | |
| 2016 | 추가: egui::Event::PointerButton { | |
| 2017 | 추가: pos, | |
| 2018 | 추가: button: egui::PointerButton::Primary, | |
| 2019 | 추가: pressed: false, | |
| 2020 | 추가: modifiers: ctx.input(|i| i.modifiers), | |
| 2021 | 추가: }, | |
| 2022 | 추가: ); | |
| 2023 | 추가: } | |
| 2024 | 추가: } | |
| 1763 | 2025 | } |
| 1764 | 2026 | impl Drop for ArchiveApp { |
| 1765 | 2027 | 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,7 @@ mod widgets { | ||
| 909 | 909 | include!("toolbar.rs"); |
| 910 | 910 | include!("long_layout.rs"); |
| 911 | 911 | include!("explorer_selection.rs"); |
| 912 | 추가: include!("window_frame.rs"); | |
| 912 | 913 | } |
| 913 | 914 | |
| 914 | 915 | #[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 | 추가: } |