team-ljyzipelo

공개
625줄23 KB
1use eframe::egui::{self, Color32, FontId, Stroke, TextStyle};
2
3pub const BACKGROUND: Color32 = Color32::from_rgb(247, 248, 250);
4pub const PANEL: Color32 = Color32::WHITE;
5pub const STRIPE: Color32 = Color32::from_rgb(243, 245, 248);
6pub const BORDER: Color32 = Color32::from_rgb(217, 222, 229);
7pub const TEXT: Color32 = Color32::from_rgb(31, 41, 51);
8pub const MUTED: Color32 = Color32::from_rgb(91, 102, 115);
9pub const BLUE: Color32 = Color32::from_rgb(37, 99, 235);
10pub const BLUE_HOVER: Color32 = Color32::from_rgb(29, 78, 216);
11pub const BLUE_ACTIVE: Color32 = Color32::from_rgb(30, 64, 175);
12pub const SELECTED: Color32 = Color32::from_rgb(232, 240, 254);
13pub const DROP: Color32 = Color32::from_rgb(238, 244, 255);
14pub const DASH: Color32 = Color32::from_rgb(170, 180, 192);
15pub const SUCCESS: Color32 = Color32::from_rgb(21, 128, 61);
16pub const SUCCESS_BG: Color32 = Color32::from_rgb(232, 245, 236);
17pub const WARNING: Color32 = Color32::from_rgb(180, 83, 9);
18pub const WARNING_BG: Color32 = Color32::from_rgb(255, 247, 232);
19pub const ERROR: Color32 = Color32::from_rgb(185, 28, 28);
20pub const ERROR_BG: Color32 = Color32::from_rgb(253, 237, 237);
21pub const FOLDER: Color32 = Color32::from_rgb(240, 160, 0);
22pub const FILE: Color32 = Color32::from_rgb(123, 135, 148);
23pub const SPACE: f32 = 8.0;
24pub const PAD: i8 = 16;
25pub const DROP_PAD: i8 = 24;
26pub const DROP_HEIGHT: f32 = 280.0;
27pub const DROP_RADIUS: u8 = 12;
28pub const ROW: f32 = 32.0;
29pub const BUTTON: f32 = 40.0;
30/// 글자 크기 단계. 앱의 모든 글자는 이 세 값 중 하나를 씀.
31/// 기본 16px을 기준으로 보조 글자는 작게, 제목과 강조 글자는 크게 씀.
32pub const FONT_SMALL: f32 = 14.0;
33pub const FONT_BODY: f32 = 16.0;
34pub const FONT_LARGE: f32 = 20.0;
35/// 경로와 검색 입력란의 높이. 위쪽 경로 줄은 이 높이만큼만 차지함.
36pub const FIELD: f32 = 36.0;
37/// 테두리 없는 버튼에 마우스를 올리거나 누를 때의 배경.
38pub const HOVER: Color32 = Color32::from_rgb(229, 233, 239);
39pub const PRESS: Color32 = Color32::from_rgb(214, 220, 229);
40
41/// 앱에 포함한 기본 글꼴 (SIL OFL 1.1, assets/fonts/OFL.txt).
42pub const PRETENDARD: &[u8] = include_bytes!("assets/fonts/Pretendard-Regular.ttf");
43
44/// Pretendard를 기본 글꼴로 쓰고, 없는 글자는 운영체제 한글 글꼴로 대신 그림.
45pub fn fonts(fallback: Option<(Vec<u8>, u32)>) -> egui::FontDefinitions {
46 let mut fonts = egui::FontDefinitions::empty();
47 fonts.font_data.insert(
48 "pretendard".into(),
49 egui::FontData::from_static(PRETENDARD).into(),
50 );
51 let mut family = vec!["pretendard".to_owned()];
52 if let Some((bytes, index)) = fallback {
53 let mut data = egui::FontData::from_owned(bytes);
54 data.index = index;
55 fonts.font_data.insert("system-kr".into(), data.into());
56 family.push("system-kr".into());
57 }
58 fonts
59 .families
60 .insert(egui::FontFamily::Proportional, family.clone());
61 fonts.families.insert(egui::FontFamily::Monospace, family);
62 fonts
63}
64
65pub fn apply(ctx: &egui::Context) {
66 ctx.set_theme(egui::Theme::Light);
67 ctx.set_visuals(egui::Visuals::light());
68 ctx.style_mut_of(egui::Theme::Light, |style| {
69 style
70 .text_styles
71 .insert(TextStyle::Body, FontId::proportional(FONT_BODY));
72 style
73 .text_styles
74 .insert(TextStyle::Button, FontId::proportional(FONT_BODY));
75 style
76 .text_styles
77 .insert(TextStyle::Small, FontId::proportional(FONT_SMALL));
78 style
79 .text_styles
80 .insert(TextStyle::Heading, FontId::proportional(FONT_LARGE));
81 style.visuals.override_text_color = Some(TEXT);
82 style.visuals.panel_fill = BACKGROUND;
83 style.visuals.window_fill = PANEL;
84 style.visuals.extreme_bg_color = PANEL;
85 style.visuals.faint_bg_color = STRIPE;
86 style.visuals.selection.bg_fill = SELECTED;
87 style.visuals.selection.stroke = Stroke::new(2.0, BLUE);
88 style.visuals.widgets.inactive.bg_fill = PANEL;
89 style.visuals.widgets.inactive.weak_bg_fill = PANEL;
90 style.visuals.widgets.inactive.bg_stroke = Stroke::new(1.0, BORDER);
91 style.visuals.widgets.hovered.bg_fill = DROP;
92 style.visuals.widgets.hovered.weak_bg_fill = DROP;
93 style.visuals.widgets.hovered.bg_stroke = Stroke::new(1.0, BLUE);
94 style.visuals.widgets.active.bg_stroke = Stroke::new(2.0, BLUE);
95 for widget in [
96 &mut style.visuals.widgets.inactive,
97 &mut style.visuals.widgets.hovered,
98 &mut style.visuals.widgets.active,
99 &mut style.visuals.widgets.noninteractive,
100 ] {
101 widget.corner_radius = egui::CornerRadius::same(6);
102 widget.fg_stroke = Stroke::new(1.5, TEXT);
103 }
104 style.visuals.window_corner_radius = egui::CornerRadius::same(8);
105 style.spacing.item_spacing = egui::vec2(SPACE, SPACE);
106 style.spacing.button_padding = egui::vec2(16.0, SPACE);
107 style.spacing.interact_size.y = ROW;
108 style.spacing.window_margin = egui::Margin::same(PAD);
109 style.visuals.disabled_alpha = 0.4;
110 // 클릭과 표시가 즉시 바뀌도록 서서히 나타남, 부드러운 스크롤, 커서 깜빡임을 모두 끔.
111 style.animation_time = 0.0;
112 style.scroll_animation = egui::style::ScrollAnimation::none();
113 style.visuals.text_cursor.blink = false;
114 });
115}
116
117pub fn focus(response: &egui::Response) {
118 if response.has_focus() {
119 response.ctx.layer_painter(response.layer_id).rect_stroke(
120 response.rect.expand(2.0),
121 6,
122 Stroke::new(2.0, BLUE),
123 egui::StrokeKind::Outside,
124 );
125 }
126}
127
128pub fn action(ui: &mut egui::Ui, text: &str, primary: bool, enabled: bool) -> egui::Response {
129 let response = ui
130 .scope(|ui| {
131 if primary {
132 let style = ui.style_mut();
133 style.visuals.widgets.inactive.bg_fill = BLUE;
134 style.visuals.widgets.inactive.weak_bg_fill = BLUE;
135 style.visuals.widgets.hovered.bg_fill = BLUE_HOVER;
136 style.visuals.widgets.hovered.weak_bg_fill = BLUE_HOVER;
137 style.visuals.widgets.active.bg_fill = BLUE_ACTIVE;
138 style.visuals.widgets.active.weak_bg_fill = BLUE_ACTIVE;
139 }
140 ui.add_enabled(
141 enabled,
142 egui::Button::new(egui::RichText::new(text).strong().color(if primary {
143 PANEL
144 } else if text == "취소" {
145 ERROR
146 } else {
147 TEXT
148 }))
149 .min_size(egui::vec2(
150 if primary { 112.0 } else { 0.0 },
151 if primary { BUTTON } else { 36.0 },
152 ))
153 .stroke(Stroke::new(1.0, if primary { BLUE } else { BORDER })),
154 )
155 })
156 .inner;
157 focus(&response);
158 response
159}
160
161pub const STATUS_HEIGHT: f32 = 34.0;
162
163/// 경로 줄 높이를 꽉 채우는 입력란을 그림. 모서리는 각지게 하고,
164/// 위 테두리는 상단 메뉴의 구분선이, 아래 테두리는 경로 줄의 아래 선이 대신해
165/// 선이 겹쳐 보이지 않게 함. 초점이 있으면 파란 테두리.
166pub fn field_frame(ui: &egui::Ui, rect: egui::Rect, focused: bool) {
167 let painter = ui.painter();
168 painter.rect_filled(rect, 0, PANEL);
169 if focused {
170 painter.rect_stroke(rect, 0, Stroke::new(1.0, BLUE), egui::StrokeKind::Inside);
171 return;
172 }
173 let stroke = Stroke::new(1.0, BORDER);
174 painter.vline(rect.left() + 0.5, rect.y_range(), stroke);
175 painter.vline(rect.right() - 0.5, rect.y_range(), stroke);
176}
177
178/// 네 변 테두리가 모두 있는 입력란 모양 (주변에 구분선이 없는 곳에서 씀).
179pub fn boxed_field(ui: &egui::Ui, rect: egui::Rect) {
180 ui.painter().rect(
181 rect,
182 0,
183 PANEL,
184 Stroke::new(1.0, BORDER),
185 egui::StrokeKind::Inside,
186 );
187}
188
189/// 입력란 안에 경로처럼 한 줄 글자를 그림. 넘치면 줄이고 전체 글자는 툴팁으로 보여 줌.
190/// 부모 배치에 영향을 주지 않는 하위 영역을 써서 옆 칸의 위치가 흔들리지 않게 함.
191pub fn field_text(ui: &mut egui::Ui, rect: egui::Rect, text: &str) {
192 let mut child = ui.new_child(
193 egui::UiBuilder::new()
194 .max_rect(rect.shrink2(egui::vec2(10.0, 0.0)))
195 .layout(egui::Layout::left_to_right(egui::Align::Center)),
196 );
197 bounded_text(&mut child, text, (rect.width() - 20.0).max(0.0));
198}
199
200/// 상태 줄 글자를 칸의 세로 가운데에 그림. 넘치면 줄이고 전체 글자는 툴팁으로 보여 줌.
201pub fn status_text(
202 ui: &mut egui::Ui,
203 rect: egui::Rect,
204 text: &str,
205 width: f32,
206 align: egui::Align,
207) {
208 let mut job = egui::text::LayoutJob::simple_singleline(
209 text.into(),
210 FontId::proportional(FONT_BODY),
211 TEXT,
212 );
213 job.wrap = egui::text::TextWrapping {
214 max_width: width.max(0.0),
215 max_rows: 1,
216 ..Default::default()
217 };
218 let galley = ui.fonts_mut(|fonts| fonts.layout_job(job));
219 let size = galley.size();
220 let x = if align == egui::Align::Max {
221 rect.right() - size.x
222 } else {
223 rect.left()
224 };
225 let text_rect = egui::Rect::from_min_size(egui::pos2(x, rect.center().y - size.y / 2.0), size);
226 ui.painter().galley(text_rect.min, galley, TEXT);
227 let response = ui.interact(
228 text_rect,
229 ui.scope_id()
230 .with(("status-text", align == egui::Align::Max)),
231 egui::Sense::hover(),
232 );
233 response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Label, true, text));
234 response.on_hover_text(text);
235}
236
237pub fn panel(fill: Color32) -> egui::Frame {
238 egui::Frame::new()
239 .fill(fill)
240 .inner_margin(egui::Margin::same(PAD))
241 .corner_radius(8)
242}
243
244#[derive(Clone, Copy)]
245pub enum Icon {
246 File,
247 Folder,
248 Archive,
249 Lock,
250 Success,
251 Warning,
252 Error,
253}
254
255pub fn icon(ui: &mut egui::Ui, kind: Icon, size: f32) {
256 let (rect, _) = ui.allocate_exact_size(egui::vec2(size, size), egui::Sense::hover());
257 let p = ui.painter();
258 let color = match kind {
259 Icon::Folder => FOLDER,
260 Icon::Archive => BLUE,
261 Icon::Lock | Icon::Warning => WARNING,
262 Icon::Success => SUCCESS,
263 Icon::Error => ERROR,
264 Icon::File => FILE,
265 };
266 let s = Stroke::new(if size > 32.0 { 2.5 } else { 1.5 }, color);
267 let point = |x, y| rect.min + egui::vec2(x * size, y * size);
268 let box_at = |x, y, w, h| egui::Rect::from_min_max(point(x, y), point(x + w, y + h));
269 match kind {
270 Icon::Folder => {
271 p.rect_filled(box_at(0.08, 0.22, 0.42, 0.22), 2, color);
272 p.rect_filled(box_at(0.08, 0.34, 0.84, 0.50), 2, color);
273 }
274 Icon::File | Icon::Archive => {
275 p.rect_stroke(
276 box_at(0.19, 0.08, 0.62, 0.84),
277 2,
278 s,
279 egui::StrokeKind::Inside,
280 );
281 p.line_segment([point(0.60, 0.08), point(0.60, 0.30)], s);
282 p.line_segment([point(0.60, 0.30), point(0.81, 0.30)], s);
283 if matches!(kind, Icon::Archive) {
284 for y in [0.42, 0.57, 0.72] {
285 p.line_segment([point(0.39, y), point(0.59, y)], s);
286 }
287 }
288 }
289 Icon::Lock => {
290 p.circle_stroke(point(0.50, 0.35), size * 0.23, s);
291 p.rect_filled(box_at(0.18, 0.39, 0.64, 0.47), 2, color);
292 }
293 Icon::Success | Icon::Error => {
294 p.circle_stroke(rect.center(), size * 0.40, s);
295 if matches!(kind, Icon::Success) {
296 p.line_segment([point(0.28, 0.50), point(0.44, 0.66)], s);
297 p.line_segment([point(0.44, 0.66), point(0.74, 0.33)], s);
298 } else {
299 p.line_segment([point(0.34, 0.34), point(0.66, 0.66)], s);
300 p.line_segment([point(0.66, 0.34), point(0.34, 0.66)], s);
301 }
302 }
303 Icon::Warning => {
304 p.add(egui::Shape::closed_line(
305 vec![point(0.50, 0.08), point(0.94, 0.86), point(0.06, 0.86)],
306 s,
307 ));
308 p.line_segment([point(0.50, 0.32), point(0.50, 0.57)], s);
309 p.circle_filled(point(0.50, 0.73), size * 0.035, color);
310 }
311 }
312}
313
314pub fn bounded_text(ui: &mut egui::Ui, text: &str, width: f32) -> egui::Response {
315 bounded_text_hover(ui, text, text, width)
316}
317
318/// 폭에 맞춰 줄인 글자를 그리고, 마우스를 올리면 hover 글자를 보여 줌.
319pub fn bounded_text_hover(
320 ui: &mut egui::Ui,
321 text: &str,
322 hover: &str,
323 width: f32,
324) -> egui::Response {
325 let width = width.max(0.0);
326 ui.allocate_ui_with_layout(
327 egui::vec2(width, ui.text_style_height(&TextStyle::Body)),
328 ui.layout().clone(),
329 |ui| {
330 ui.set_min_width(width);
331 ui.set_max_width(width);
332 ui.add(egui::Label::new(text).truncate())
333 },
334 )
335 .inner
336 .on_hover_text(hover)
337}
338
339pub fn window_title(ui: &egui::Ui, text: &str, width: f32) -> String {
340 let mut job = egui::text::LayoutJob::simple_singleline(
341 text.into(),
342 FontId::proportional(FONT_BODY),
343 TEXT,
344 );
345 job.wrap = egui::text::TextWrapping {
346 max_width: width.max(0.0),
347 max_rows: 1,
348 break_anywhere: true,
349 ..Default::default()
350 };
351 ui.fonts_mut(|fonts| fonts.layout_job(job))
352 .rows
353 .iter()
354 .flat_map(|row| row.glyphs.iter().map(|glyph| glyph.chr))
355 .collect()
356}
357
358pub fn column_label(
359 ui: &mut egui::Ui,
360 text: impl Into<egui::WidgetText>,
361 width: f32,
362 align: egui::Align,
363) -> egui::Response {
364 let layout = if align == egui::Align::Max {
365 egui::Layout::right_to_left(egui::Align::Center)
366 } else {
367 egui::Layout::left_to_right(egui::Align::Center)
368 };
369 ui.allocate_ui_with_layout(egui::vec2(width, ROW), layout, |ui| {
370 ui.set_min_width(width);
371 ui.set_max_width(width);
372 ui.add(egui::Label::new(text).truncate())
373 })
374 .inner
375}
376
377pub fn action_pair(
378 ui: &mut egui::Ui,
379 secondary: &str,
380 primary: Option<(&str, bool)>,
381) -> (bool, bool) {
382 let text_width = |text: &str| {
383 ui.painter()
384 .layout_no_wrap(text.into(), FontId::proportional(FONT_BODY), TEXT)
385 .size()
386 .x
387 };
388 let width = text_width(secondary)
389 + 32.0
390 + primary.map_or(0.0, |(label, _)| {
391 SPACE + (text_width(label) + 32.0).max(112.0)
392 });
393 ui.horizontal(|ui| {
394 ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
395 ui.add_space((ui.available_width() - width).max(0.0));
396 let secondary = action(ui, secondary, false, true).clicked();
397 let primary = primary.is_some_and(|(label, enabled)| {
398 action(ui, label, true, enabled)
399 .on_disabled_hover_text(match label {
400 "만들기" => "묶을 파일이나 폴더를 추가하세요",
401 "다른 폴더에 풀기" => "기존 풀 위치 폴더를 먼저 확인하세요",
402 _ => "입력한 내용을 확인하세요",
403 })
404 .clicked()
405 });
406 (secondary, primary)
407 })
408 .inner
409 })
410 .inner
411}
412
413pub fn indeterminate(ui: &mut egui::Ui) {
414 let (rect, response) = ui.allocate_exact_size(
415 egui::vec2(ui.available_width(), SPACE * 2.0),
416 egui::Sense::hover(),
417 );
418 // 움직이는 표시 없이 전체 막대를 옅은 파란색으로 채워 진행 중임을 나타냄.
419 ui.painter()
420 .rect_filled(rect, 8, Color32::from_rgb(191, 211, 248));
421 response.widget_info(|| {
422 egui::WidgetInfo::labeled(
423 egui::Role::ProgressIndicator,
424 ui.is_enabled(),
425 "전체 크기를 알 수 없는 작업 진행 중",
426 )
427 });
428}
429
430pub const OPEN: &str = include_str!("assets/icons/open-archive.svg");
431pub const CREATE: &str = include_str!("assets/icons/create-zip.svg");
432pub const EXTRACT: &str = include_str!("assets/icons/extract-archive.svg");
433pub const UP: &str = include_str!("assets/icons/navigate-up.svg");
434pub const CLOSE: &str = include_str!("assets/icons/close-dialog.svg");
435
436pub fn svg_icon(painter: &egui::Painter, rect: egui::Rect, asset: &str, color: Color32) {
437 for element in asset.split("points=\"").skip(1) {
438 let points = element
439 .split('"')
440 .next()
441 .unwrap_or_default()
442 .split_whitespace()
443 .filter_map(|pair| {
444 let (x, y) = pair.split_once(',')?;
445 Some(
446 rect.min
447 + egui::vec2(x.parse::<f32>().ok()?, y.parse::<f32>().ok()?)
448 * (rect.width() / 24.0),
449 )
450 })
451 .collect::<Vec<_>>();
452 let width = rect.width() / 18.0;
453 // 꼭짓점과 끝점에 원을 더해 둥근 이음과 둥근 끝을 만듦.
454 for point in &points {
455 painter.circle_filled(*point, width / 2.0, color);
456 }
457 painter.add(egui::Shape::line(points, Stroke::new(width, color)));
458 }
459}
460
461/// 가장 긴 이름(압축해제, FONT_SMALL에서 약 48px) 양옆에 12px씩 남는 폭.
462pub const TOOL_SIZE: egui::Vec2 = egui::vec2(72.0, 60.0);
463const TOOL_ICON: f32 = 30.0;
464const TOOL_LABEL: f32 = FONT_SMALL;
465/// 아이콘 그림 아래와 이름 글자 위 사이의 보이는 간격.
466const TOOL_GAP: f32 = 6.0;
467
468/// SVG 폴리라인 점들의 세로 범위(24 단위 좌표).
469fn svg_y_range(asset: &str) -> Option<(f32, f32)> {
470 asset
471 .split("points=\"")
472 .skip(1)
473 .flat_map(|element| {
474 element
475 .split('"')
476 .next()
477 .unwrap_or_default()
478 .split_whitespace()
479 .filter_map(|pair| pair.split_once(',')?.1.parse::<f32>().ok())
480 .collect::<Vec<_>>()
481 })
482 .fold(None, |range: Option<(f32, f32)>, y| {
483 Some(range.map_or((y, y), |(lo, hi)| (lo.min(y), hi.max(y))))
484 })
485}
486
487/// 상단 메뉴 아이콘 세 개를 합친 그림 범위. 모든 버튼이 같은 기준을 써서 이름 높이가 맞음.
488fn tool_icon_ink() -> (f32, f32) {
489 let scale = TOOL_ICON / 24.0;
490 let half_stroke = TOOL_ICON / 18.0 / 2.0;
491 let (lo, hi) = [OPEN, CREATE, EXTRACT]
492 .iter()
493 .filter_map(|asset| svg_y_range(asset))
494 .fold((24.0f32, 0.0f32), |(lo, hi), (a, b)| (lo.min(a), hi.max(b)));
495 (lo * scale - half_stroke, hi * scale + half_stroke)
496}
497
498/// 글자 줄 상자가 아니라 실제로 그려지는 글자 모양의 위아래 범위.
499fn galley_ink(galley: &egui::Galley) -> (f32, f32) {
500 galley
501 .rows
502 .iter()
503 .flat_map(|row| {
504 row.glyphs
505 .iter()
506 .filter(|g| g.uv_rect.size.y > 0.0)
507 .map(move |g| {
508 let top = row.pos.y + g.pos.y + g.uv_rect.offset.y;
509 (top, top + g.uv_rect.size.y)
510 })
511 })
512 .fold(None, |range: Option<(f32, f32)>, (top, bottom)| {
513 Some(range.map_or((top, bottom), |(a, b)| (a.min(top), b.max(bottom))))
514 })
515 .unwrap_or((0.0, galley.size().y))
516}
517
518pub fn tool(
519 ui: &mut egui::Ui,
520 label: &str,
521 asset: &str,
522 enabled: bool,
523 blue: bool,
524) -> egui::Response {
525 let (rect, response) = ui.allocate_exact_size(
526 TOOL_SIZE,
527 if enabled {
528 egui::Sense::click()
529 } else {
530 egui::Sense::hover()
531 },
532 );
533 response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, enabled, label));
534 let color = if enabled {
535 if blue { BLUE } else { TEXT }
536 } else {
537 MUTED
538 };
539 if enabled && (response.hovered() || response.has_focus()) {
540 let fill = if response.is_pointer_button_down_on() {
541 PRESS
542 } else {
543 HOVER
544 };
545 ui.painter().rect_filled(rect, 8, fill);
546 }
547 // 아이콘 그림 위쪽부터 글자 모양 아래쪽까지를 하나로 보고 버튼 가운데에 둠.
548 // 그래서 마우스를 올려 배경이 보일 때 위아래 여백이 같음.
549 let galley =
550 ui.painter()
551 .layout_no_wrap(label.to_owned(), FontId::proportional(TOOL_LABEL), color);
552 let (icon_top, icon_bottom) = tool_icon_ink();
553 let (text_top, text_bottom) = galley_ink(&galley);
554 let block = (icon_bottom - icon_top) + TOOL_GAP + (text_bottom - text_top);
555 let start = rect.top() + (rect.height() - block) / 2.0;
556 let icon_rect = egui::Rect::from_min_size(
557 egui::pos2(rect.center().x - TOOL_ICON / 2.0, start - icon_top),
558 egui::vec2(TOOL_ICON, TOOL_ICON),
559 );
560 svg_icon(ui.painter(), icon_rect, asset, color);
561 let text_y = start + (icon_bottom - icon_top) + TOOL_GAP - text_top;
562 ui.painter().galley(
563 egui::pos2(rect.center().x - galley.size().x / 2.0, text_y).round(),
564 galley,
565 color,
566 );
567 focus(&response);
568 response
569}
570
571/// 테두리와 배경 없이 아이콘만 그리는 버튼. 사용할 수 있을 때만 마우스를 올리면 배경이 어두워짐.
572pub fn flat_icon_button(
573 ui: &mut egui::Ui,
574 name: &str,
575 asset: &str,
576 enabled: bool,
577 size: egui::Vec2,
578) -> egui::Response {
579 let (rect, response) = ui.allocate_exact_size(
580 size,
581 if enabled {
582 egui::Sense::click()
583 } else {
584 egui::Sense::hover()
585 },
586 );
587 let response = response.on_hover_text(name);
588 response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, enabled, name));
589 if enabled && response.hovered() {
590 let fill = if response.is_pointer_button_down_on() {
591 PRESS
592 } else {
593 HOVER
594 };
595 ui.painter().rect_filled(rect, 6, fill);
596 }
597 svg_icon(
598 ui.painter(),
599 egui::Rect::from_center_size(rect.center(), egui::vec2(20.0, 20.0)),
600 asset,
601 if enabled { TEXT } else { MUTED },
602 );
603 focus(&response);
604 response
605}
606
607pub const SEARCH: &str = include_str!("assets/icons/search-files.svg");
608
609pub fn icon_button(ui: &mut egui::Ui, name: &str, asset: &str, enabled: bool) -> egui::Response {
610 let response = ui
611 .add_enabled(
612 enabled,
613 egui::Button::new("").min_size(egui::vec2(38.0, 36.0)),
614 )
615 .on_hover_text(name);
616 response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, enabled, name));
617 svg_icon(
618 ui.painter(),
619 egui::Rect::from_center_size(response.rect.center(), egui::vec2(22.0, 22.0)),
620 asset,
621 if enabled { TEXT } else { MUTED },
622 );
623 focus(&response);
624 response
625}