Skip to content

Commit 3ffa5ce

Browse files
committed
docs: 添加注释
1 parent 3ff0b81 commit 3ffa5ce

File tree

8 files changed

+47
-4
lines changed

8 files changed

+47
-4
lines changed

crates/project_graph/Trunk.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[build]
2+
# Cloudflare Workers Static Assets 单个文件大小限制为 25MiB,需要压缩一下
23
minify = "on_release"

crates/project_graph/src/app.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! egui 应用主入口
2+
13
use lucide_icons::Icon;
24

35
use crate::{
@@ -36,6 +38,7 @@ impl eframe::App for MyApp {
3638
}
3739

3840
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
41+
// 因为是手动处理绘图逻辑的,所以需要持续请求重绘
3942
ctx.request_repaint();
4043

4144
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {

crates/project_graph/src/fonts.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
/// 为指定的 egui 上下文配置字体
12
pub fn setup_custom_fonts(ctx: &egui::Context) {
23
let mut fonts = egui::FontDefinitions::default();
34

4-
// 默认字体
5+
// 在桌面平台上尝试加载系统字体
56
#[cfg(desktop)]
67
{
78
use font_kit::family_name::FamilyName;
@@ -33,6 +34,7 @@ pub fn setup_custom_fonts(ctx: &egui::Context) {
3334
}
3435
}
3536
}
37+
// 在不支持使用 font-kit 的平台上,使用内置的 MiSans 字体作为替代
3638
#[cfg(any(wasm, android))]
3739
{
3840
// Web 平台使用内置字体
@@ -66,6 +68,15 @@ pub fn setup_custom_fonts(ctx: &egui::Context) {
6668
}
6769

6870
/// 获取 Lucide 图标的 Unicode 字符串
71+
///
72+
/// # Examples
73+
///
74+
/// ```
75+
/// # use lucide_icons::Icon;
76+
/// # use project_graph::fonts::ic;
77+
/// let settings_icon = ic(Icon::Settings);
78+
/// assert_eq!(settings_icon, "\u{e154}");
79+
/// ```
6980
pub fn ic(icon: lucide_icons::Icon) -> String {
7081
char::from(icon).to_string()
7182
}

crates/project_graph/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! # Project Graph
2+
//!
3+
//! 无限画布上的思维操作系统。融合笔记、思维导图与系统分析,用图论拓扑重构你的知识网络。
4+
15
pub mod app;
26
pub mod fonts;
37
pub mod settings;
@@ -7,6 +11,8 @@ pub mod stage;
711
pub mod structs;
812
pub mod themes;
913

14+
/// Android 平台入口点
15+
/// 将会编译为 libproject_graph.so,作为一个 Native Activity
1016
#[cfg(android)]
1117
#[unsafe(no_mangle)]
1218
fn android_main(app: android_activity::AndroidApp) {

crates/project_graph/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// 桌面平台入口点
12
#[cfg(desktop)]
23
fn main() {
34
env_logger::init();
@@ -16,6 +17,7 @@ fn main() {
1617
.expect("Failed to start eframe");
1718
}
1819

20+
/// WebAssembly 平台入口点
1921
#[cfg(wasm)]
2022
fn main() {
2123
use eframe::wasm_bindgen::JsCast;

crates/project_graph/src/smooth_value.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
/// 数据结构,用于实现缓动效果
1+
/// 一个支持缓动过渡的值容器,适用于需要平滑动画效果的场景。
2+
///
3+
/// # Examples
4+
///
5+
/// ```
6+
/// # use project_graph::smooth_value::SmoothValue;
7+
/// let mut smooth = SmoothValue::new(0.0).with_speed(5.0);
8+
/// smooth.set(10.0);
9+
/// // 模拟每帧更新,假设每帧间隔为 0.032 秒(约 30 FPS)
10+
/// for _ in 0..100 {
11+
/// smooth.tick(0.032);
12+
/// println!("Current value: {}", smooth.get());
13+
/// }
14+
/// // 最终值应该接近目标值
15+
/// assert!((smooth.get() - 10.0).abs() < 0.01);
16+
/// ```
217
pub struct SmoothValue<T> {
318
current: T,
419
target: T,
@@ -20,11 +35,15 @@ where
2035
speed: 10.0,
2136
}
2237
}
38+
/// 指数衰减速率系数
39+
/// 物体完成约 63.2% 的过渡所需的时间为 1/speed 秒
40+
/// 较高的值会更快地接近目标值,但可能会产生更明显的动画跳跃
2341
pub fn with_speed(mut self, speed: f32) -> Self {
2442
self.speed = speed;
2543
self
2644
}
2745

46+
/// 更新当前值,应该在每帧调用,dt 是与上一帧的时间间隔(秒)
2847
pub fn tick(&mut self, dt: f32) {
2948
let lerp_factor = (1.0 - (-self.speed * dt).exp()).clamp(0.0, 1.0);
3049

crates/project_graph/src/stage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ mod camera;
22

33
use camera::Camera;
44
use eframe::egui::{self};
5-
use egui::{Pos2, Vec2};
5+
use egui::Pos2;
66
use nanoid::nanoid;
77
use rand::Rng;
88

99
use crate::structs::{StageObject, TextNode};
1010

11-
/// egui和画布之间的桥梁
11+
/// egui 和画布之间的桥梁
1212
/// 负责坐标系转换、事件处理等
1313
pub struct Stage {
1414
camera: Camera,

crates/project_graph/src/themes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use egui::{
33
style::{WidgetVisuals, Widgets},
44
};
55

6+
/// 将主题应用到指定的 egui 上下文上
67
pub fn apply_custom_theme(ctx: &Context) {
78
let mut style = (*ctx.style()).clone();
89

0 commit comments

Comments
 (0)