-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1e8b54
commit dde75d1
Showing
10 changed files
with
1,814 additions
and
16 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "geph5-client-gui" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
anyhow = "1.0.81" | ||
csv = "1.3.0" | ||
dirs = "5.0.1" | ||
eframe = {version="0.27.2", default-features=false, features=["wgpu", "x11"]} | ||
egui = "0.27.2" | ||
moka = {version="0.12.5", features=["sync"]} | ||
|
||
once_cell = "1.19.0" | ||
smol_str = {version="0.2.1", features=["serde"]} | ||
tap = "1.0.1" |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
! | ||
" | ||
& | ||
' | ||
( | ||
) | ||
, | ||
- | ||
. | ||
/ | ||
: | ||
; | ||
< | ||
= | ||
> | ||
? | ||
[ | ||
] | ||
_ | ||
{ | ||
| | ||
} | ||
0 | ||
1 | ||
2 | ||
3 | ||
5 | ||
6 | ||
8 | ||
a | ||
A | ||
b | ||
B | ||
c | ||
C | ||
d | ||
D | ||
e | ||
E | ||
f | ||
F | ||
g | ||
G | ||
h | ||
H | ||
i | ||
I | ||
j | ||
J | ||
k | ||
K | ||
l | ||
L | ||
m | ||
M | ||
n | ||
N | ||
o | ||
O | ||
p | ||
P | ||
q | ||
r | ||
R | ||
s | ||
S | ||
t | ||
T | ||
u | ||
v | ||
V | ||
w | ||
x | ||
y | ||
z | ||
你 | ||
好 | ||
迷 | ||
通 | ||
雾 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
find ../ -type f -name '*.rs' -o -name '*.csv' | xargs cat | grep -o . | sort -u > chars.txt | ||
pyftsubset SarasaUiSC-Regular.ttf --text-file=chars.txt --output-file=subset.ttf |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
label,en,zh | ||
geph,Geph,迷雾通 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use once_cell::sync::Lazy; | ||
use smol_str::SmolStr; | ||
|
||
use crate::prefs::pref_read; | ||
|
||
static L10N_TABLE: Lazy<BTreeMap<SmolStr, BTreeMap<SmolStr, SmolStr>>> = Lazy::new(|| { | ||
let csv = include_bytes!("l10n.csv"); | ||
let mut rdr = csv::Reader::from_reader(&csv[..]); | ||
let mut toret = BTreeMap::new(); | ||
for result in rdr.deserialize() { | ||
let mut record: BTreeMap<SmolStr, SmolStr> = result.unwrap(); | ||
let label = record.remove("label").unwrap(); | ||
toret.insert(label, record); | ||
} | ||
toret | ||
}); | ||
|
||
pub fn l10n(label: &str) -> &str { | ||
&L10N_TABLE[label][&pref_read("lang").unwrap()] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
mod l10n; | ||
mod prefs; | ||
use std::time::Duration; | ||
|
||
use egui::{Color32, FontData, FontDefinitions, FontFamily, Visuals}; | ||
use l10n::l10n; | ||
use prefs::pref_write; | ||
use tap::Tap as _; | ||
|
||
fn main() { | ||
// default prefs | ||
for (key, value) in [("lang", "en")] { | ||
pref_write(key, value).unwrap(); | ||
} | ||
|
||
let native_options = eframe::NativeOptions { | ||
viewport: egui::ViewportBuilder::default() | ||
.with_inner_size([800.0, 600.0]) | ||
.with_min_inner_size([300.0, 220.0]), | ||
..Default::default() | ||
}; | ||
eframe::run_native( | ||
l10n("geph"), | ||
native_options, | ||
Box::new(|cc| Box::new(App::new(cc))), | ||
) | ||
.unwrap(); | ||
} | ||
|
||
pub struct App {} | ||
|
||
impl App { | ||
/// Constructs the app. | ||
pub fn new(cc: &eframe::CreationContext<'_>) -> Self { | ||
// light mode | ||
cc.egui_ctx.set_visuals( | ||
Visuals::light() | ||
.tap_mut(|vis| vis.widgets.noninteractive.fg_stroke.color = Color32::BLACK), | ||
); | ||
|
||
// set up fonts. currently this uses SC for CJK, but this can be autodetected instead. | ||
let mut fonts = FontDefinitions::default(); | ||
fonts.font_data.insert( | ||
"sarasa_sc".into(), | ||
FontData::from_static(include_bytes!("assets/subset.ttf")), | ||
); | ||
fonts | ||
.families | ||
.get_mut(&FontFamily::Proportional) | ||
.unwrap() | ||
.insert(0, "sarasa_sc".into()); | ||
cc.egui_ctx.set_fonts(fonts); | ||
Self {} | ||
} | ||
} | ||
|
||
impl eframe::App for App { | ||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { | ||
ctx.request_repaint_after(Duration::from_secs(1)); | ||
|
||
egui::TopBottomPanel::top("top").show(ctx, |ui| {}); | ||
egui::TopBottomPanel::bottom("bottom").show(ctx, |ui| {}); | ||
egui::CentralPanel::default().show(ctx, |ui| ui.label("hello world 你好你好")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::Context as _; | ||
use moka::sync::Cache; | ||
use once_cell::sync::Lazy; | ||
use smol_str::SmolStr; | ||
|
||
static PREF_DIR: Lazy<PathBuf> = Lazy::new(|| { | ||
let dir = dirs::config_dir() | ||
.context("no config dir") | ||
.unwrap() | ||
.join("geph5-prefs"); | ||
std::fs::create_dir_all(&dir).unwrap(); | ||
dir | ||
}); | ||
|
||
static PREF_CACHE: Lazy<Cache<SmolStr, SmolStr>> = Lazy::new(|| Cache::new(10000)); | ||
|
||
pub fn pref_write(key: &str, val: &str) -> anyhow::Result<()> { | ||
PREF_CACHE.remove(key); | ||
let key_path = PREF_DIR.join(key); | ||
std::fs::write(key_path, val.as_bytes())?; | ||
Ok(()) | ||
} | ||
|
||
pub fn pref_read(key: &str) -> anyhow::Result<SmolStr> { | ||
PREF_CACHE | ||
.try_get_with(key.into(), || { | ||
let key_path = PREF_DIR.join(key); | ||
let contents = std::fs::read_to_string(key_path)?; | ||
anyhow::Ok(SmolStr::from(contents)) | ||
}) | ||
.map_err(|e| anyhow::anyhow!("{e}")) | ||
} |