team-ljyzipelo

공개

파일 목록 행에 선택과 마우스 올림 배경을 반투명 파란색으로 그림

선택한 행은 반투명 파란색(BLUE 12%), 마우스를 올린 행은 그보다 옅은
파란색(BLUE 6%)으로 그림. 선택한 행은 마우스를 올려도 선택 색을 유지함.
메인 목록과 ZIP 만들기 목록이 같은 row_background를 씀. ZIP 만들기 목록은
한 번 누르면 그 항목을 선택하고, 보고 있는 폴더가 바뀌면 선택을 지움.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
작성자
LeeJunyoung
작성 시각
커밋
331925472b7a561d1338d99329fcddfbc29a7319
부모
9cb7e02
이 시점의 파일 보기

변경된 파일 3개

+118-3
수정experiments/rust-ui-memory-app/src/archive_screen.rs+16-3
@@ -207,6 +207,8 @@ pub struct ArchiveApp {
207207 create_listing: Option<(PathBuf, Option<std::rc::Rc<Vec<SourceRow>>>)>,
208208 /// 마지막으로 누른 폴더 행 (이름, 프레임 번호, 시각). 두 번 누름을 직접 판단할 때 씀.
209209 create_last_click: Option<(String, u64, f64)>,
210추가: /// ZIP 만들기 목록에서 한 번 눌러 선택한 항목 이름. 보고 있는 폴더가 바뀌면 지움.
211추가: create_selected: Option<String>,
210212 zip_password: String,
211213 zip_password_confirm: String,
212214 zip_password_visible: bool,
@@ -258,6 +260,7 @@ impl ArchiveApp {
258260 create_folder: String::new(),
259261 create_listing: None,
260262 create_last_click: None,
263추가: create_selected: None,
261264 zip_password: String::new(),
262265 zip_password_confirm: String::new(),
263266 zip_password_visible: false,
@@ -466,6 +469,7 @@ impl ArchiveApp {
466469 }
467470 self.create_folder.clear();
468471 self.create_listing = None;
472추가: self.create_selected = None;
469473 self.create = true;
470474 }
471475
@@ -1269,9 +1273,7 @@ impl ArchiveApp {
12691273 )
12701274 });
12711275 }
1272삭제: if selected {
1273삭제: ui.painter().rect_filled(rect, 0, theme::SELECTED);
1274삭제: }
1276추가: theme::row_background(ui, rect, selected, response.hovered());
12751277 if response.clicked() {
12761278 background.request_focus();
12771279 let modifiers = ui.input(|i| i.modifiers);
@@ -2077,6 +2079,7 @@ impl ArchiveApp {
20772079 .rsplit_once('/')
20782080 .map_or("", |(parent, _)| parent)
20792081 .to_owned();
2082추가: self.create_selected = None;
20802083 }
20812084 ui.add_space(6.0);
20822085 let path = match &root {
@@ -2135,6 +2138,15 @@ impl ArchiveApp {
21352138 &row.name,
21362139 )
21372140 });
2141추가: if response.clicked() {
2142추가: self.create_selected = Some(row.name.clone());
2143추가: }
2144추가: theme::row_background(
2145추가: ui,
2146추가: rect,
2147추가: self.create_selected.as_deref() == Some(row.name.as_str()),
2148추가: response.hovered(),
2149추가: );
21382150 if row.directory && root.is_some() && response.clicked() {
21392151 // egui가 한 프레임을 다시 그리면 두 번 누름 정보가 사라질 수 있어
21402152 // 같은 폴더를 다른 프레임에서 0.4초 안에 다시 누르면 두 번 누름으로 봄.
@@ -2175,6 +2187,7 @@ impl ArchiveApp {
21752187 } else {
21762188 format!("{}/{name}", self.create_folder)
21772189 };
2190추가: self.create_selected = None;
21782191 }
21792192 ui.add_space(theme::SPACE);
21802193
수정experiments/rust-ui-memory-app/src/archive_theme.rs+17-0
@@ -10,6 +10,10 @@ pub const BLUE: Color32 = Color32::from_rgb(37, 99, 235);
1010pub const BLUE_HOVER: Color32 = Color32::from_rgb(29, 78, 216);
1111pub const BLUE_ACTIVE: Color32 = Color32::from_rgb(30, 64, 175);
1212pub const SELECTED: Color32 = Color32::from_rgb(232, 240, 254);
13추가: /// 파일 목록에서 선택한 행의 반투명 파란 배경 (BLUE 12%).
14추가: pub const ROW_SELECTED: Color32 = Color32::from_rgba_unmultiplied_const(37, 99, 235, 31);
15추가: /// 파일 목록에서 마우스를 올린 행의 배경. 선택한 행보다 조금 더 투명함 (BLUE 6%).
16추가: pub const ROW_HOVER: Color32 = Color32::from_rgba_unmultiplied_const(37, 99, 235, 15);
1317pub const DROP: Color32 = Color32::from_rgb(238, 244, 255);
1418pub const DASH: Color32 = Color32::from_rgb(170, 180, 192);
1519pub const SUCCESS: Color32 = Color32::from_rgb(21, 128, 61);
@@ -172,6 +176,19 @@ pub fn action_sized(
172176
173177pub const STATUS_HEIGHT: f32 = 34.0;
174178
179추가: /// 파일 목록 행 배경. 선택한 행은 마우스를 올려도 선택 색을 유지하고,
180추가: /// 선택하지 않은 행에 마우스를 올리면 더 옅은 파란색을 칠함.
181추가: pub fn row_background(ui: &egui::Ui, rect: egui::Rect, selected: bool, hovered: bool) {
182추가: let fill = if selected {
183추가: ROW_SELECTED
184추가: } else if hovered {
185추가: ROW_HOVER
186추가: } else {
187추가: return;
188추가: };
189추가: ui.painter().rect_filled(rect, 0, fill);
190추가: }
191추가:
175192/// 경로 줄 높이를 꽉 채우는 입력란을 그림. 모서리는 각지게 하고,
176193/// 위 테두리는 상단 메뉴의 구분선이, 아래 테두리는 경로 줄의 아래 선이 대신해
177194/// 선이 겹쳐 보이지 않게 함. 초점이 있으면 파란 테두리.
수정tests/rust-app-ui/create_window.rs+85-0
@@ -190,3 +190,88 @@ fn retry_of_encrypted_creation_reopens_create_window_for_password() {
190190 assert!(!shown.iter().any(|(text, _)| text == "ZIP 암호 설정"));
191191 assert_eq!(factory.state.borrow().starts.len(), starts);
192192}
193추가:
194추가: /// 주어진 세로 위치를 덮는 목록 행 배경색(선택/마우스 올림 색 중)을 찾음.
195추가: fn row_fill_at(output: &egui::FullOutput, y: f32) -> Option<egui::Color32> {
196추가: use zipelo_ui_memory_app::archive_theme::{ROW_HOVER, ROW_SELECTED};
197추가: fn walk(shape: &egui::epaint::Shape, y: f32, found: &mut Option<egui::Color32>) {
198추가: match shape {
199추가: egui::epaint::Shape::Rect(rect)
200추가: if (rect.fill == ROW_SELECTED || rect.fill == ROW_HOVER)
201추가: && rect.rect.top() <= y
202추가: && y <= rect.rect.bottom() =>
203추가: {
204추가: *found = Some(rect.fill);
205추가: }
206추가: egui::epaint::Shape::Vec(shapes) => {
207추가: for shape in shapes {
208추가: walk(shape, y, found);
209추가: }
210추가: }
211추가: _ => {}
212추가: }
213추가: }
214추가: let mut found = None;
215추가: for shape in &output.shapes {
216추가: walk(&shape.shape, y, &mut found);
217추가: }
218추가: found
219추가: }
220추가:
221추가: fn label_y(ctx: &egui::Context, app: &mut ArchiveApp, label: &str) -> f32 {
222추가: policy_render(ctx, app, vec![])
223추가: .iter()
224추가: .rev()
225추가: .find(|(text, _)| text == label)
226추가: .unwrap_or_else(|| panic!("항목 없음: {label}"))
227추가: .1
228추가: .y
229추가: }
230추가:
231추가: fn hover(ctx: &egui::Context, app: &mut ArchiveApp, label: &str) -> egui::FullOutput {
232추가: let point = policy_render(ctx, app, vec![])
233추가: .iter()
234추가: .rev()
235추가: .find(|(text, _)| text == label)
236추가: .unwrap()
237추가: .1;
238추가: frame_output(ctx, app, vec![egui::Event::PointerMoved(point)]);
239추가: frame_output(ctx, app, vec![egui::Event::PointerMoved(point)])
240추가: }
241추가:
242추가: #[test]
243추가: fn create_list_click_selects_and_hover_uses_lighter_blue() {
244추가: use zipelo_ui_memory_app::archive_theme::{ROW_HOVER, ROW_SELECTED};
245추가: let scratch = Folder::new();
246추가: let factory = FakeFactory::default();
247추가: let (mut app, ctx) = create_from_folder(&scratch, &factory);
248추가: let a = label_y(&ctx, &mut app, "a.txt");
249추가: let trip = label_y(&ctx, &mut app, "trip");
250추가: // 한 번 누르면 반투명 파란 배경으로 선택함.
251추가: policy_click(&ctx, &mut app, "a.txt");
252추가: // 다른 행에 마우스를 올리면 선택 색보다 옅은 파란색.
253추가: let output = hover(&ctx, &mut app, "trip");
254추가: assert_eq!(row_fill_at(&output, a), Some(ROW_SELECTED));
255추가: assert_eq!(row_fill_at(&output, trip), Some(ROW_HOVER));
256추가: // 선택한 행에 마우스를 올려도 더 옅어지지 않음.
257추가: let output = hover(&ctx, &mut app, "a.txt");
258추가: assert_eq!(row_fill_at(&output, a), Some(ROW_SELECTED));
259추가: assert_eq!(row_fill_at(&output, trip), None);
260추가: assert!(ROW_HOVER.a() < ROW_SELECTED.a());
261추가: }
262추가:
263추가: #[test]
264추가: fn main_list_hover_uses_lighter_blue_and_selected_row_keeps_its_color() {
265추가: use zipelo_ui_memory_app::archive_theme::{ROW_HOVER, ROW_SELECTED};
266추가: let scratch = Folder::new();
267추가: let factory = FakeFactory::default();
268추가: let mut app = loaded(&scratch, &factory);
269추가: let ctx = egui::Context::default();
270추가: let name = "읽어주세요.txt";
271추가: let y = label_y(&ctx, &mut app, name);
272추가: let output = hover(&ctx, &mut app, name);
273추가: assert_eq!(row_fill_at(&output, y), Some(ROW_HOVER));
274추가: policy_click(&ctx, &mut app, name);
275추가: let output = hover(&ctx, &mut app, name);
276추가: assert_eq!(row_fill_at(&output, y), Some(ROW_SELECTED));
277추가: }