mirror of https://github.com/Leinnan/rpack.git
Better fonts
This commit is contained in:
parent
35ae42d2bb
commit
7016780c6d
|
|
@ -10,20 +10,20 @@ env:
|
|||
RUSTDOCFLAGS: -D warnings
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
override: true
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --all-features --lib
|
||||
# check:
|
||||
# name: Check
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - uses: actions/checkout@v4
|
||||
# - uses: actions-rs/toolchain@v1
|
||||
# with:
|
||||
# profile: minimal
|
||||
# toolchain: stable
|
||||
# override: true
|
||||
# - uses: actions-rs/cargo@v1
|
||||
# with:
|
||||
# command: check
|
||||
# args: --all-features --lib
|
||||
|
||||
check_wasm:
|
||||
name: Check wasm32
|
||||
|
|
|
|||
|
|
@ -4404,6 +4404,7 @@ checksum = "3cd14fd5e3b777a7422cca79358c57a8f6e3a703d9ac187448d0daf220c2407f"
|
|||
name = "rpack"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"eframe",
|
||||
"egui",
|
||||
"egui_extras",
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
mod bevy;
|
||||
|
||||
pub mod prelude {
|
||||
pub use super::{AtlasAsset,SerializableRect, AtlasFrame};
|
||||
#[cfg(feature = "bevy")]
|
||||
pub use super::bevy::{RpackAssetPlugin, RpackAtlasAsset, RpackAtlasAssetError, RpackAtlasAssetLoader};
|
||||
pub use super::bevy::{
|
||||
RpackAssetPlugin, RpackAtlasAsset, RpackAtlasAssetError, RpackAtlasAssetLoader,
|
||||
};
|
||||
pub use super::{AtlasAsset, AtlasFrame, SerializableRect};
|
||||
}
|
||||
|
||||
/// Defines a rectangle in pixels with the origin at the top-left of the texture atlas.
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ image = { version = "0.25", features = ["jpeg", "png"] }
|
|||
egui_extras = { version = "*", features = ["all_loaders"] }
|
||||
rfd = { version = "0.15", features = [] }
|
||||
wasm-bindgen-futures = "0.4"
|
||||
anyhow = "1"
|
||||
|
||||
# native:
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ impl TemplateApp {
|
|||
}
|
||||
/// Called once before the first frame.
|
||||
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||
setup_custom_fonts(&cc.egui_ctx);
|
||||
crate::fonts::setup_custom_fonts(&cc.egui_ctx);
|
||||
// This is also where you can customize the look and feel of egui using
|
||||
// `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`.
|
||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||
|
|
@ -232,44 +232,6 @@ impl TemplateApp {
|
|||
}
|
||||
}
|
||||
|
||||
fn setup_custom_fonts(ctx: &egui::Context) {
|
||||
// Start with the default fonts (we will be adding to them rather than replacing them).
|
||||
let mut fonts = egui::FontDefinitions::default();
|
||||
|
||||
// Install my own font (maybe supporting non-latin characters).
|
||||
// .ttf and .otf files supported.
|
||||
fonts.font_data.insert(
|
||||
"regular".to_owned(),
|
||||
egui::FontData::from_static(include_bytes!("../static/JetBrainsMonoNL-Regular.ttf")).into(),
|
||||
);
|
||||
fonts.font_data.insert(
|
||||
"semibold".to_owned(),
|
||||
egui::FontData::from_static(include_bytes!("../static/JetBrainsMono-SemiBold.ttf")).into(),
|
||||
);
|
||||
|
||||
// Put my font first (highest priority) for proportional text:
|
||||
fonts
|
||||
.families
|
||||
.entry(egui::FontFamily::Proportional)
|
||||
.or_default()
|
||||
.insert(0, "regular".to_owned());
|
||||
fonts
|
||||
.families
|
||||
.entry(egui::FontFamily::Name("semibold".into()))
|
||||
.or_default()
|
||||
.insert(0, "semibold".to_owned());
|
||||
|
||||
// Put my font as last fallback for monospace:
|
||||
fonts
|
||||
.families
|
||||
.entry(egui::FontFamily::Monospace)
|
||||
.or_default()
|
||||
.push("regular".to_owned());
|
||||
|
||||
// Tell egui to use these fonts:
|
||||
ctx.set_fonts(fonts);
|
||||
}
|
||||
|
||||
impl eframe::App for TemplateApp {
|
||||
/// Called by the frame work to save state before shutdown.
|
||||
fn save(&mut self, storage: &mut dyn eframe::Storage) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
pub fn setup_custom_fonts(ctx: &egui::Context) {
|
||||
// Start with the default fonts (we will be adding to them rather than replacing them).
|
||||
let mut fonts = egui::FontDefinitions::default();
|
||||
let Ok((regular, semibold)) = get_fonts() else {
|
||||
return;
|
||||
};
|
||||
fonts.font_data.insert(
|
||||
"regular".to_owned(),
|
||||
egui::FontData::from_owned(regular).into(),
|
||||
);
|
||||
fonts.font_data.insert(
|
||||
"semibold".to_owned(),
|
||||
egui::FontData::from_owned(semibold).into(),
|
||||
);
|
||||
|
||||
// Put my font first (highest priority) for proportional text:
|
||||
fonts
|
||||
.families
|
||||
.entry(egui::FontFamily::Proportional)
|
||||
.or_default()
|
||||
.insert(0, "regular".to_owned());
|
||||
fonts
|
||||
.families
|
||||
.entry(egui::FontFamily::Name("semibold".into()))
|
||||
.or_default()
|
||||
.insert(0, "semibold".to_owned());
|
||||
|
||||
// Put my font as last fallback for monospace:
|
||||
fonts
|
||||
.families
|
||||
.entry(egui::FontFamily::Monospace)
|
||||
.or_default()
|
||||
.push("regular".to_owned());
|
||||
|
||||
// Tell egui to use these fonts:
|
||||
ctx.set_fonts(fonts);
|
||||
|
||||
ctx.style_mut(|style| {
|
||||
for font_id in style.text_styles.values_mut() {
|
||||
font_id.size *= 1.4;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(all(not(target_os = "macos"), not(windows)))]
|
||||
fn get_fonts() -> anyhow::Result<(Vec<u8>, Vec<u8>)> {
|
||||
let regular = include_bytes!("../static/JetBrainsMonoNL-Regular.ttf").to_vec();
|
||||
let semibold = include_bytes!("../static/JetBrainsMono-SemiBold.ttf").to_vec();
|
||||
|
||||
Ok((regular, semibold))
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn get_fonts() -> anyhow::Result<(Vec<u8>, Vec<u8>)> {
|
||||
let font_path = std::path::Path::new("/System/Library/Fonts");
|
||||
|
||||
let regular = fs::read(font_path.join("SFNSRounded.ttf"))?;
|
||||
let semibold = fs::read(font_path.join("SFCompact.ttf"))?;
|
||||
|
||||
Ok((regular, semibold))
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn get_fonts() -> anyhow::Result<(Vec<u8>, Vec<u8>)> {
|
||||
use std::fs;
|
||||
|
||||
let app_data = std::env::var("APPDATA")?;
|
||||
let font_path = std::path::Path::new(&app_data);
|
||||
|
||||
let regular = fs::read(font_path.join("../Local/Microsoft/Windows/Fonts/aptos.ttf"))?;
|
||||
let semibold = fs::read(font_path.join("../Local/Microsoft/Windows/Fonts/aptos-semibold.ttf"))?;
|
||||
|
||||
Ok((regular, semibold))
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#![warn(clippy::all, rust_2018_idioms)]
|
||||
|
||||
mod app;
|
||||
mod fonts;
|
||||
pub use app::TemplateApp;
|
||||
|
|
|
|||
Loading…
Reference in New Issue