egui_nerdfonts
1.0.0
حزم الرموز الطالب الذي يذاكر كثيرا من أجل egui.
أضف الصندوق باعتباره تبعية في Cargo.toml:
egui_nerdfonts = " 0.1.3 " أو اكتب cargo add egui_nerdfonts ، في مشروعك.
أولاً ، قم بتحديث الخطوط في سياق egui الخاص بك:
let mut fonts = egui :: FontDefinitions :: default ( ) ;
egui_nerdfonts :: add_to_fonts ( & mut fonts , egui_nerdfonts :: Variant :: Regular ) ;
let egui_ctx = Context :: default ( ) ;
egui_ctx . set_fonts ( fonts ) ;اختر أيقونات Nerdfonts التي تريد استخدامها بين هذه.
ثم استخدم أيقونات Nerdfonts على النحو التالي:
ui . label ( format ! ( "{}" , egui_nerdfonts :: regular :: NF_DEV_RUST ) ) ; cargo run --example rust_logo

حصلت على إلهام من eGui_phosphor ، يستخدم الكود نفس الهيكل.
.TTF المستخدم هو هذا واحد ، وتم إنشاء src/variants/regular.rs nerdfonts_regular.ttf
from itertools import chain
from fontTools . ttLib import TTFont
from fontTools . unicode import Unicode
import sys
with TTFont (
sys . argv [ 1 ], 0 , allowVID = 0 , ignoreDecompileErrors = True , fontNumber = - 1
) as ttf :
chars = chain . from_iterable (
[ y + ( Unicode [ y [ 0 ]],) for y in x . cmap . items ()] for x in ttf [ "cmap" ]. tables
)
for char in chars :
symbol_name = char [ 1 ]. upper (). replace ( '-' , '_' ). replace ( ' ' , '_' ). replace ( '#' , '_' ). replace ( '!' , '' )
code = r"u" + "{" + f" { char [ 0 ]:X } " + "}"
print ( f"pub const { symbol_name } : &str = " { code } " ;" )