Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ eframe = { version = "0.36", default-features = false }
egui_kittest = "0.36"
rfd = "0.17"
arboard = { version = "3.6", default-features = false }
# The desktop's preferred language, for the first-run interface language (native only).
sys-locale = "0.3"

[workspace.lints.rust]
unsafe_code = "forbid"
Expand Down
13 changes: 11 additions & 2 deletions apps/gridcraft-web/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,17 @@ pub fn start() {
} else if q.contains("sample") {
let _ = session.execute("file.new", serde_json::json!({"sample": "sales"}));
}
let app = SheetApp::new(session, services(inbox.clone(), cc.egui_ctx.clone()));
SheetApp::setup_context(&cc.egui_ctx, false);
let mut app = SheetApp::new(session, services(inbox.clone(), cc.egui_ctx.clone()));
// Follow the browser's language, except a CJK one: the web build has no system
// CJK fonts (none are bundled), so that interface would render as tofu.
let browser = gridcraft_ui_egui::i18n::Language::system();
if !matches!(
browser,
gridcraft_ui_egui::i18n::Language::Zh | gridcraft_ui_egui::i18n::Language::Ja | gridcraft_ui_egui::i18n::Language::Ko
) {
app.ui.language = browser;
}
SheetApp::setup_context_for_language(&cc.egui_ctx, false, app.ui.language);
Ok(Box::new(WebShell { app, inbox }))
}),
)
Expand Down
9 changes: 7 additions & 2 deletions apps/gridcraft/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@ fn load_prefs(app: &mut SheetApp) {
if !prefs_enabled() {
return;
}
// First run (or a ui.json without a usable language): follow the desktop's language.
app.ui.language = gridcraft_ui_egui::i18n::Language::system();
let Some(dir) = config_dir() else { return };
if let Ok(b) = std::fs::read(dir.join("ui.json"))
&& let Ok(ui) = serde_json::from_slice(&b)
&& let Ok(ui) = serde_json::from_slice::<gridcraft_ui_egui::UiState>(&b)
{
let saved = serde_json::from_slice(&b).ok().and_then(|v| gridcraft_ui_egui::i18n::saved_language(&v));
let language = saved.unwrap_or(app.ui.language);
app.ui = ui;
app.ui.language = language;
}
if let Ok(b) = std::fs::read(dir.join("prefs.json"))
&& let Ok(p) = serde_json::from_slice(&b)
Expand Down Expand Up @@ -257,7 +262,7 @@ fn main() -> eframe::Result<()> {
"GridCraft",
options,
Box::new(move |cc| {
SheetApp::setup_context(&cc.egui_ctx, app.ui.dark);
SheetApp::setup_context_for_language(&cc.egui_ctx, app.ui.dark, app.ui.language);
if let Some(port) = control_port {
match control_server::start(port, cc.egui_ctx.clone()) {
Ok(rx) => app.control_rx = Some(rx),
Expand Down
3 changes: 3 additions & 0 deletions contributors/people.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ sync_github_name = false
[people.nihilist-narwhal]
display_name = "nihilist-narwhal"
sync_github_name = false

[people.edurbs]
sync_github_name = true
2 changes: 1 addition & 1 deletion crates/core/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn serial_from_ymd(sys: DateSystem, year: i64, month: i64, day: i64) -> Opti

/// Date/time from a serial. `None` for negative or too-large serials.
pub fn datetime_from_serial(sys: DateSystem, serial: f64) -> Option<DateTime> {
if !serial.is_finite() || serial < 0.0 || serial >= 2_958_466.0 {
if !serial.is_finite() || !(0.0..2_958_466.0).contains(&serial) {
return None;
}
let mut day = serial.floor() as i64;
Expand Down
2 changes: 1 addition & 1 deletion crates/functions/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ fn integer_args(a: &[Arg]) -> R<Vec<u64>> {
v.iter()
.map(|x| {
let t = x.trunc();
if t < 0.0 || t >= 9.007_199_254_740_992e15 { Err(CellError::Num) } else { Ok(t as u64) }
if !(0.0..9.007_199_254_740_992e15).contains(&t) { Err(CellError::Num) } else { Ok(t as u64) }
})
.collect()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/functions/src/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ fn binom_dist_range(a: &[Arg], _: C) -> R<Value> {
let p = num(a, 1)?;
let s1 = num(a, 2)?.trunc();
let s2 = if has(a, 3) { num(a, 3)?.trunc() } else { s1 };
if n < 0.0 || n > 1e15 || !(0.0..=1.0).contains(&p) || s1 < 0.0 || s1 > n || s2 < s1 || s2 > n {
if !(0.0..=1e15).contains(&n) || !(0.0..=1.0).contains(&p) || s1 < 0.0 || s1 > n || s2 < s1 || s2 > n {
return Err(CellError::Num);
}
if s2 - s1 > 10_000.0 {
Expand Down
2 changes: 1 addition & 1 deletion crates/functions/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) fn arg(args: &[Arg], i: usize) -> R<&Arg> {

/// Whether argument `i` was supplied (present and not an empty literal like `F(1,)`).
pub(crate) fn has(args: &[Arg], i: usize) -> bool {
matches!(args.get(i), Some(a) if !(matches!(a.value, Value::Empty) && !a.from_ref))
matches!(args.get(i), Some(a) if !matches!(a.value, Value::Empty) || a.from_ref)
}

/// Number coercion for a scalar parameter: empty = 0, TRUE = 1, numeric text parses.
Expand Down
2 changes: 1 addition & 1 deletion crates/numfmt/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) fn render_general(sec: &Section, v: f64, width: usize) -> Out {

/// Renders a date/time. `None` when the serial is outside the supported range.
pub(crate) fn render_date(sec: &Section, v: f64, sys: DateSystem) -> Option<Out> {
if !v.is_finite() || v < 0.0 || v >= 2_958_466.0 {
if !v.is_finite() || !(0.0..2_958_466.0).contains(&v) {
return None;
}
let sub_digits = sec.toks.iter().filter_map(|t| if let Tok::Date(DatePart::SubSec(n)) = t { Some(*n) } else { None }).max().unwrap_or(0).min(3);
Expand Down
8 changes: 8 additions & 0 deletions crates/ui-egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ image = { workspace = true }
[dev-dependencies]
egui_kittest = { workspace = true, features = ["wgpu", "snapshot"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# The desktop's preferred language for the first-run interface language.
sys-locale = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
# Read the browser's preferred language for the first-run web interface language.
web-sys = { version = "0.3", features = ["Window", "Navigator"] }

[build-dependencies]
serde_json = { workspace = true }
toml = "1"
12 changes: 11 additions & 1 deletion crates/ui-egui/examples/snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Renders the whole GridCraft window offscreen (wgpu, no window) to a PNG.
//!
//! `cargo run --release -p gridcraft-ui-egui --example snapshot -- [--sample sales] [--in file.xlsx]
//! [--size 1440x900] [--scale 2] [--cmd 'id={json}']... [--tab Insert] [--dark]
//! [--size 1440x900] [--scale 2] [--cmd 'id={json}']... [--tab Insert] [--dark] [--language en|zh|ja|ko|ru|pt]
//! [--dialog 'name={json}'] out.png`

use gridcraft_engine::Session;
Expand All @@ -20,6 +20,7 @@ fn main() {
let mut pane: Option<String> = None;
let mut chart: Option<u32> = None;
let mut dialog: Option<String> = None;
let mut language: Option<String> = None;
let mut out = "snapshot.png".to_string();
let mut i = 0;
while i < args.len() {
Expand Down Expand Up @@ -65,6 +66,10 @@ fn main() {
i += 1;
dialog = args.get(i).cloned();
}
"--language" => {
i += 1;
language = args.get(i).cloned();
}
other => out = other.to_string(),
}
i += 1;
Expand Down Expand Up @@ -93,6 +98,11 @@ fn main() {
{
let mut app = SheetApp::new(session, Default::default());
app.ui.dark = dark;
if let Some(code) = &language
&& let Some(l) = gridcraft_ui_egui::i18n::Language::parse(code)
{
app.ui.language = l;
}
if let Some(t) = tab {
app.ui.ribbon_tab = t;
}
Expand Down
21 changes: 12 additions & 9 deletions crates/ui-egui/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,19 @@ pub fn handle(app: &mut SheetApp, ctx: &egui::Context, method: &str, p: &Json) -
}
"engine.commands" => {
let mut v: Vec<Json> = app.session.commands().into_iter().map(|c| serde_json::to_value(c).unwrap_or_default()).collect();
for (id, label) in [
("ui.ribbonTab", "Ribbon Tab"),
("view.formulaBar", "Formula Bar"),
("view.collapseRibbon", "Collapse Ribbon"),
("view.darkMode", "Dark Mode"),
("view.theme", "Display Theme"),
("view.zoom100", "100%"),
("ui.dialog", "Open Dialog"),
for (id, label, params) in [
("ui.ribbonTab", "Ribbon Tab", ""),
("view.formulaBar", "Formula Bar", ""),
("view.collapseRibbon", "Collapse Ribbon", ""),
("view.darkMode", "Dark Mode", ""),
("view.theme", "Display Theme", ""),
("view.zoom100", "100%", ""),
("ui.dialog", "Open Dialog", ""),
("app.language.set", "Interface Language", "{language: \"en\"|\"zh\"|\"ja\"|\"ko\"|\"ru\"|\"pt\"} (alias: code)"),
("app.language.english", "Interface Language: English", ""),
("app.language.japanese", "Interface Language: Japanese", ""),
] {
v.push(json!({"id": id, "label": label, "enabled": true, "ui": true}));
v.push(json!({"id": id, "label": label, "params": params, "enabled": true, "ui": true}));
}
ok(Json::Array(v))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ui-egui/src/formula_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn editor_widget(app: &mut SheetApp, ui: &mut egui::Ui, id: egui::Id, font:
ed.caret_to_end = false;
ed.sync_caret = true;
}
if !ed.autocomplete.is_empty() && (tab || (enter && false)) {
if !ed.autocomplete.is_empty() && tab {
ed.accept_autocomplete();
} else if enter {
action = Some((if shift { -1 } else { 1 }, 0, false, false));
Expand Down
Loading