← luna

Commit a487ee9

2
files
+100
added
-0
deleted
@@ -0,0 +1,100 @@
1 +//! Galeria pakietu ikon libLuny — „packshot” całego zestawu `IconName::ALL`.
2 +//!
3 +//! Uruchom: `cargo run -p luna-demo --bin icons`
4 +//! Efekt: `docs/images/icons.png` (górna sekcja: motyw jasny, dolna: ciemny).
5 +
6 +use std::error::Error;
7 +
8 +use libluna_core::style::weight;
9 +use libluna_core::{Rect, Size, Theme};
10 +use libluna_render::{Scene, SoftwareRenderer, TextEngine};
11 +use libluna_widgets::{paint_icon, IconName, PaintCtx};
12 +
13 +const COLS: usize = 7;
14 +const CELL_W: f64 = 118.0;
15 +const CELL_H: f64 = 112.0;
16 +const MARGIN: f64 = 24.0;
17 +const TITLE_H: f64 = 40.0;
18 +
19 +/// Szerokość obrazu dobrana do liczby kolumn.
20 +fn width() -> u32 {
21 + (MARGIN * 2.0 + CELL_W * COLS as f64) as u32
22 +}
23 +
24 +/// Wysokość jednej sekcji motywu.
25 +fn section_h() -> f64 {
26 + let rows = IconName::ALL.len().div_ceil(COLS) as f64;
27 + TITLE_H + rows * CELL_H + MARGIN
28 +}
29 +
30 +fn main() -> Result<(), Box<dyn Error>> {
31 + let text = TextEngine::system();
32 + let w = width();
33 + let h = (section_h() * 2.0) as u32;
34 + let size = Size::new(w as f64, h as f64);
35 +
36 + let mut scene = Scene::new();
37 + scene.fill_rect(Rect::from_size(size), Theme::light().colors.window_bg);
38 +
39 + let mut y = 0.0;
40 + for (label, theme) in [
41 + ("Motyw jasny", Theme::light()),
42 + ("Motyw ciemny", Theme::dark()),
43 + ] {
44 + let mut paint = PaintCtx::new(&mut scene, &theme, &text);
45 + // Tło sekcji.
46 + let section = Rect::from_xywh(0.0, y, size.width, section_h());
47 + paint.scene.fill_rect(section, theme.colors.window_bg);
48 + paint.label_left(
49 + MARGIN,
50 + y + TITLE_H / 2.0,
51 + label,
52 + theme.typography.heading.size,
53 + weight::BOLD,
54 + theme.colors.text,
55 + );
56 + paint_icon_grid(&mut paint, &theme, y + TITLE_H);
57 + y += section_h();
58 + }
59 +
60 + let mut renderer = SoftwareRenderer::new(w, h);
61 + renderer.draw(&scene, 1.0, Theme::light().colors.window_bg);
62 + let png = renderer.encode_png().ok_or("nie udało się zakodować PNG")?;
63 + std::fs::write("docs/images/icons.png", png)?;
64 + println!("saved docs/images/icons.png ({w}x{h})");
65 + Ok(())
66 +}
67 +
68 +/// Rysuje siatkę wszystkich ikon z podpisami, zaczynając w `top`.
69 +fn paint_icon_grid(paint: &mut PaintCtx, theme: &Theme, top: f64) {
70 + for (i, icon) in IconName::ALL.iter().enumerate() {
71 + let col = (i % COLS) as f64;
72 + let row = (i / COLS) as f64;
73 + let cell = Rect::from_xywh(
74 + MARGIN + col * CELL_W,
75 + top + row * CELL_H,
76 + CELL_W - 8.0,
77 + CELL_H - 8.0,
78 + );
79 +
80 + // Karta z ikoną.
81 + paint
82 + .scene
83 + .fill_rounded_rect(cell, theme.radius.medium, theme.colors.card_bg);
84 + paint
85 + .scene
86 + .stroke_rounded_rect(cell, theme.radius.medium, 1.0, theme.colors.border);
87 +
88 + let icon_rect = Rect::from_xywh(cell.center().x - 24.0, cell.y() + 22.0, 48.0, 48.0);
89 + paint_icon(paint, *icon, icon_rect, theme.colors.accent);
90 +
91 + paint.label_center(
92 + cell.center().x,
93 + icon_rect.bottom() + 16.0,
94 + icon.name(),
95 + theme.typography.caption.size,
96 + weight::NORMAL,
97 + theme.colors.text,
98 + );
99 + }
100 +}
0 101 new file mode 100644
1 102 Binary files /dev/null and b/docs/images/icons.png differ