team-ljyzipelo

공개

상단 메뉴 버튼 안 내용을 보이는 모양 기준으로 가운데에 둠

마우스를 올려 배경이 보이면 아이콘 위 여백과 글자 아래 여백이 달랐음.
글자 줄 상자와 아이콘 상자의 빈 공간까지 계산에 들어갔기 때문임.
아이콘 그림의 실제 범위와 글자 모양(glyph)의 실제 위아래 범위로 내용을
가운데에 두고, 바깥 여백은 위아래 4px로 같게 함. 압축해제 아이콘의
뚜껑이 다른 아이콘보다 높이 솟아 있어 같은 높이 안에 들어오게 다시 그림.
측정: 배경 안 위 9px, 아래 10px, 배경 바깥 위아래 4px.

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

변경된 파일 3개

+71-19
수정experiments/rust-ui-memory-app/src/archive_screen.rs+3-4
@@ -617,10 +617,9 @@ impl ArchiveApp {
617617 .inner_margin(egui::Margin {
618618 left: 12,
619619 right: 12,
620삭제: top: 6,
621삭제: // 이름 글자 줄 높이 아래에 남는 빈 공간만큼 줄여 아이콘 위와
622삭제: // 글자 아래의 보이는 여백을 같게 맞춤 (FONT_SMALL에서 13px씩).
623삭제: bottom: 3,
620추가: // 버튼 안 내용은 보이는 모양 기준으로 가운데에 두므로 위아래를 같게 둠.
621추가: top: 4,
622추가: bottom: 4,
624623 }),
625624 )
626625 .show(root, |ui| {
수정experiments/rust-ui-memory-app/src/archive_theme.rs+67-14
@@ -437,9 +437,61 @@ pub fn svg_icon(painter: &egui::Painter, rect: egui::Rect, asset: &str, color: C
437437}
438438
439439/// 가장 긴 이름(압축해제, FONT_SMALL에서 약 48px) 양옆에 12px씩 남는 폭.
440삭제: pub const TOOL_SIZE: egui::Vec2 = egui::vec2(72.0, 68.0);
440추가: pub const TOOL_SIZE: egui::Vec2 = egui::vec2(72.0, 60.0);
441441const TOOL_ICON: f32 = 30.0;
442442const TOOL_LABEL: f32 = FONT_SMALL;
443추가: /// 아이콘 그림 아래와 이름 글자 위 사이의 보이는 간격.
444추가: const TOOL_GAP: f32 = 6.0;
445추가:
446추가: /// SVG 폴리라인 점들의 세로 범위(24 단위 좌표).
447추가: fn svg_y_range(asset: &str) -> Option<(f32, f32)> {
448추가: asset
449추가: .split("points=\"")
450추가: .skip(1)
451추가: .flat_map(|element| {
452추가: element
453추가: .split('"')
454추가: .next()
455추가: .unwrap_or_default()
456추가: .split_whitespace()
457추가: .filter_map(|pair| pair.split_once(',')?.1.parse::<f32>().ok())
458추가: .collect::<Vec<_>>()
459추가: })
460추가: .fold(None, |range: Option<(f32, f32)>, y| {
461추가: Some(range.map_or((y, y), |(lo, hi)| (lo.min(y), hi.max(y))))
462추가: })
463추가: }
464추가:
465추가: /// 상단 메뉴 아이콘 세 개를 합친 그림 범위. 모든 버튼이 같은 기준을 써서 이름 높이가 맞음.
466추가: fn tool_icon_ink() -> (f32, f32) {
467추가: let scale = TOOL_ICON / 24.0;
468추가: let half_stroke = TOOL_ICON / 18.0 / 2.0;
469추가: let (lo, hi) = [OPEN, CREATE, EXTRACT]
470추가: .iter()
471추가: .filter_map(|asset| svg_y_range(asset))
472추가: .fold((24.0f32, 0.0f32), |(lo, hi), (a, b)| (lo.min(a), hi.max(b)));
473추가: (lo * scale - half_stroke, hi * scale + half_stroke)
474추가: }
475추가:
476추가: /// 글자 줄 상자가 아니라 실제로 그려지는 글자 모양의 위아래 범위.
477추가: fn galley_ink(galley: &egui::Galley) -> (f32, f32) {
478추가: galley
479추가: .rows
480추가: .iter()
481추가: .flat_map(|row| {
482추가: row.glyphs
483추가: .iter()
484추가: .filter(|g| g.uv_rect.size.y > 0.0)
485추가: .map(move |g| {
486추가: let top = row.pos.y + g.pos.y + g.uv_rect.offset.y;
487추가: (top, top + g.uv_rect.size.y)
488추가: })
489추가: })
490추가: .fold(None, |range: Option<(f32, f32)>, (top, bottom)| {
491추가: Some(range.map_or((top, bottom), |(a, b)| (a.min(top), b.max(bottom))))
492추가: })
493추가: .unwrap_or((0.0, galley.size().y))
494추가: }
443495
444496pub fn tool(
445497 ui: &mut egui::Ui,
@@ -470,23 +522,24 @@ pub fn tool(
470522 };
471523 ui.painter().rect_filled(rect, 8, fill);
472524 }
473삭제: // 아이콘과 글자를 붙여 가운데에 두고, 아래쪽은 여백으로 남김.
474삭제: let label_height = TOOL_LABEL * 1.3;
475삭제: let gap = 4.0;
476삭제: let top = rect.top() + (rect.height() - TOOL_ICON - gap - label_height) / 2.0;
525추가: // 아이콘 그림 위쪽부터 글자 모양 아래쪽까지를 하나로 보고 버튼 가운데에 둠.
526추가: // 그래서 마우스를 올려 배경이 보일 때 위아래 여백이 같음.
527추가: let galley =
528추가: ui.painter()
529추가: .layout_no_wrap(label.to_owned(), FontId::proportional(TOOL_LABEL), color);
530추가: let (icon_top, icon_bottom) = tool_icon_ink();
531추가: let (text_top, text_bottom) = galley_ink(&galley);
532추가: let block = (icon_bottom - icon_top) + TOOL_GAP + (text_bottom - text_top);
533추가: let start = rect.top() + (rect.height() - block) / 2.0;
477534 let icon_rect = egui::Rect::from_min_size(
478삭제: egui::pos2(rect.center().x - TOOL_ICON / 2.0, top),
535추가: egui::pos2(rect.center().x - TOOL_ICON / 2.0, start - icon_top),
479536 egui::vec2(TOOL_ICON, TOOL_ICON),
480537 );
481538 svg_icon(ui.painter(), icon_rect, asset, color);
482삭제: ui.painter().text(
483삭제: egui::pos2(
484삭제: rect.center().x,
485삭제: icon_rect.bottom() + gap + label_height / 2.0,
486삭제: ),
487삭제: egui::Align2::CENTER_CENTER,
488삭제: label,
489삭제: FontId::proportional(TOOL_LABEL),
539추가: let text_y = start + (icon_bottom - icon_top) + TOOL_GAP - text_top;
540추가: ui.painter().galley(
541추가: egui::pos2(rect.center().x - galley.size().x / 2.0, text_y).round(),
542추가: galley,
490543 color,
491544 );
492545 focus(&response);
수정experiments/rust-ui-memory-app/src/assets/icons/extract-archive.svg+1-1
@@ -1 +1 @@
1삭제: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><polyline points="1.94,7.82 1.78,7.36 1.74,6.94 1.82,6.57 2.01,6.24 2.32,5.95 2.75,5.71 14.81,0.34 15.28,0.19 15.70,0.14 16.07,0.22 16.40,0.41 16.69,0.73 16.92,1.15 17.33,2.07 17.49,2.53 17.53,2.95 17.45,3.33 17.26,3.66 16.95,3.94 16.52,4.18 4.46,9.55 4.00,9.71 3.58,9.75 3.20,9.67 2.87,9.48 2.59,9.17 2.35,8.74 1.94,7.82"/> <polyline points="4.30,11.80 4.30,18.10 4.37,18.83 4.57,19.43 4.90,19.90 5.37,20.23 5.97,20.43 6.70,20.50 17.30,20.50 18.03,20.43 18.63,20.23 19.10,19.90 19.43,19.43 19.63,18.83 19.70,18.10 19.70,11.80"/> <polyline points="2.80,11.80 21.20,11.80"/> <polyline points="9.60,15.60 14.40,15.60"/></svg>
1추가: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><polyline points="2.33,9.40 2.23,8.95 2.24,8.55 2.36,8.22 2.58,7.93 2.90,7.70 3.32,7.53 14.42,4.14 14.87,4.04 15.26,4.05 15.60,4.17 15.89,4.38 16.12,4.71 16.29,5.13 16.52,5.90 16.62,6.35 16.61,6.74 16.49,7.08 16.28,7.37 15.95,7.60 15.53,7.77 4.43,11.16 3.98,11.26 3.59,11.25 3.25,11.13 2.96,10.91 2.74,10.59 2.56,10.17 2.33,9.40"/> <polyline points="4.30,12.60 4.30,17.60 4.37,18.33 4.57,18.93 4.90,19.40 5.37,19.73 5.97,19.93 6.70,20.00 17.30,20.00 18.03,19.93 18.63,19.73 19.10,19.40 19.43,18.93 19.63,18.33 19.70,17.60 19.70,12.60"/> <polyline points="2.80,12.60 21.20,12.60"/> <polyline points="9.60,16.00 14.40,16.00"/></svg>