File tree Expand file tree Collapse file tree 8 files changed +47
-4
lines changed
Expand file tree Collapse file tree 8 files changed +47
-4
lines changed Original file line number Diff line number Diff line change 11[build ]
2+ # Cloudflare Workers Static Assets 单个文件大小限制为 25MiB,需要压缩一下
23minify = " on_release"
Original file line number Diff line number Diff line change 1+ //! egui 应用主入口
2+
13use lucide_icons:: Icon ;
24
35use 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| {
Original file line number Diff line number Diff line change 1+ /// 为指定的 egui 上下文配置字体
12pub 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+ /// ```
6980pub fn ic ( icon : lucide_icons:: Icon ) -> String {
7081 char:: from ( icon) . to_string ( )
7182}
Original file line number Diff line number Diff line change 1+ //! # Project Graph
2+ //!
3+ //! 无限画布上的思维操作系统。融合笔记、思维导图与系统分析,用图论拓扑重构你的知识网络。
4+
15pub mod app;
26pub mod fonts;
37pub mod settings;
@@ -7,6 +11,8 @@ pub mod stage;
711pub mod structs;
812pub mod themes;
913
14+ /// Android 平台入口点
15+ /// 将会编译为 libproject_graph.so,作为一个 Native Activity
1016#[ cfg( android) ]
1117#[ unsafe( no_mangle) ]
1218fn android_main ( app : android_activity:: AndroidApp ) {
Original file line number Diff line number Diff line change 1+ /// 桌面平台入口点
12#[ cfg( desktop) ]
23fn main ( ) {
34 env_logger:: init ( ) ;
@@ -16,6 +17,7 @@ fn main() {
1617 . expect ( "Failed to start eframe" ) ;
1718}
1819
20+ /// WebAssembly 平台入口点
1921#[ cfg( wasm) ]
2022fn main ( ) {
2123 use eframe:: wasm_bindgen:: JsCast ;
Original file line number Diff line number Diff line change 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+ /// ```
217pub 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
Original file line number Diff line number Diff line change @@ -2,13 +2,13 @@ mod camera;
22
33use camera:: Camera ;
44use eframe:: egui:: { self } ;
5- use egui:: { Pos2 , Vec2 } ;
5+ use egui:: Pos2 ;
66use nanoid:: nanoid;
77use rand:: Rng ;
88
99use crate :: structs:: { StageObject , TextNode } ;
1010
11- /// egui和画布之间的桥梁
11+ /// egui 和画布之间的桥梁
1212/// 负责坐标系转换、事件处理等
1313pub struct Stage {
1414 camera : Camera ,
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ use egui::{
33 style:: { WidgetVisuals , Widgets } ,
44} ;
55
6+ /// 将主题应用到指定的 egui 上下文上
67pub fn apply_custom_theme ( ctx : & Context ) {
78 let mut style = ( * ctx. style ( ) ) . clone ( ) ;
89
You can’t perform that action at this time.
0 commit comments