Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Theme: interface type closer to Premiere's

Peet Guerciof9ca62f67e05
diff --git a/crates/text/build.rs b/crates/text/build.rs
index 715a8b7df..be3fb7866 100644
--- a/crates/text/build.rs
+++ b/crates/text/build.rs
@@ -7,8 +7,9 @@
//! empty and nothing else changes. A `CRAFT_FONTS_DIR` that is not a checkout is a warning, or an
//! error with `CRAFT_FONTS_REQUIRED=1` (release builds).
//!
-//! Native builds embed every font. The web (wasm32) build embeds only the UI font (BIZ UDPGothic
-//! Regular, ~4.5 MB) to stay under the web size budget (Cloudflare serves files up to 25 MiB).
+//! Native builds embed every font. The web (wasm32) build embeds only the UI fonts (BIZ UDPGothic
+//! Regular, ~4.5 MB, and Source Sans 3, ~1.3 MB) to stay under the web size budget (Cloudflare serves
+//! files up to 25 MiB).
//! Only the local directory is read: no network.
use std::fmt::Write as _;
@@ -47,7 +48,7 @@ fn craft_fonts(dir: &std::path::Path) -> Result<String, String> {
let [family, style, file, scripts, ..] = f.as_slice() else {
return Err(format!("malformed manifest line: {line}"));
};
- if wasm && !(*family == "BIZ UDPGothic" && *style == "Regular") {
+ if wasm && !(*family == "BIZ UDPGothic" && *style == "Regular") && *family != "Source Sans 3" {
continue;
}
let path = dir.join(file).canonicalize().map_err(|e| format!("{file}: {e}"))?;
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index 14966f38e..d25cfe856 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -543,7 +543,7 @@ pub fn menu_bar(app: &mut FilmcraftApp, ui: &mut egui::Ui) {
let items = menu_items(app);
let ctx = ui.ctx().clone();
let mut clicked: Option<String> = None;
- egui::MenuBar::new().ui(ui, |ui| {
+ egui::MenuBar::new().config(egui::containers::menu::MenuConfig::new().style(crate::theme::menu_style)).ui(ui, |ui| {
for top in MENUS {
let mine: Vec<&MenuItem> = items.iter().filter(|i| i.path.first().map(String::as_str) == Some(top)).collect();
ui.menu_button(app.ui.language.tr(top), |ui| {
diff --git a/crates/ui-egui/src/panels/monitor.rs b/crates/ui-egui/src/panels/monitor.rs
index 6213eb3c5..d98b9b4db 100644
--- a/crates/ui-egui/src/panels/monitor.rs
+++ b/crates/ui-egui/src/panels/monitor.rs
@@ -258,7 +258,7 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect, which: Which)
// ---- controls row: timecode | zoom | res | wrench | duration
let row1 = Rect::from_min_size(pos2(rect.min.x + 14.0, rect.max.y - controls_h + 2.0), vec2(rect.width() - 28.0, 26.0));
let tc = format_time(time, rate, drop_frame, TimeDisplay::Timecode, 48000);
- ui.painter().text(pos2(row1.min.x, row1.center().y), Align2::LEFT_CENTER, &tc, Tokens::semibold(15.0), t.hot_text);
+ ui.painter().text(pos2(row1.min.x, row1.center().y), Align2::LEFT_CENTER, &tc, Tokens::timecode(), t.timecode);
app.auto.add(&format!("{prefix}.timecode"), Rect::from_min_size(row1.min, vec2(110.0, row1.height())), &tc);
let dur_tc = format_time(
mark_out.map(|o| o + rate.frame_duration()).unwrap_or(duration) - mark_in.unwrap_or(Tick::ZERO),
@@ -267,7 +267,7 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect, which: Which)
TimeDisplay::Timecode,
48000,
);
- ui.painter().text(pos2(row1.max.x, row1.center().y), Align2::RIGHT_CENTER, &dur_tc, Tokens::semibold(15.0), t.text_dim);
+ ui.painter().text(pos2(row1.max.x, row1.center().y), Align2::RIGHT_CENTER, &dur_tc, Tokens::timecode(), t.text_dim);
// zoom + resolution dropdowns centred-ish
let zr = Rect::from_min_size(pos2(row1.min.x + 116.0, row1.min.y), vec2(70.0, 24.0));
let zoom_label = match mv.zoom {
diff --git a/crates/ui-egui/src/panels/reference.rs b/crates/ui-egui/src/panels/reference.rs
index 7b7b3890a..be1bd4251 100644
--- a/crates/ui-egui/src/panels/reference.rs
+++ b/crates/ui-egui/src/panels/reference.rs
@@ -92,7 +92,7 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
// ---- control bar: timecode · ◀ ▶ · Match Playhead · Gang · [Composite Video ▾]
let bar = Rect::from_min_max(pos2(rect.min.x, area.max.y + 4.0), rect.max);
let tc = format_time(rate.tick_of(frame), rate, q.settings.drop_frame, TimeDisplay::Timecode, 48000);
- let tr = ui.painter().text(pos2(bar.min.x + 10.0, bar.center().y), Align2::LEFT_CENTER, &tc, Tokens::semibold(15.0), t.timecode);
+ let tr = ui.painter().text(pos2(bar.min.x + 10.0, bar.center().y), Align2::LEFT_CENTER, &tc, Tokens::timecode(), t.timecode);
elems.push(("reference.timecode".into(), tr, tc.clone()));
let mut step = 0i64;
let mut x = tr.max.x + 16.0;
diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs
index 5ca911b61..0a64b72ea 100644
--- a/crates/ui-egui/src/panels/timeline.rs
+++ b/crates/ui-egui/src/panels/timeline.rs
@@ -937,10 +937,10 @@ fn draw_top(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect, seq: &Sequenc
let ruler = layout.ruler;
// background of the whole top block
p.rect_filled(Rect::from_min_max(rect.min, pos2(rect.max.x, ruler.max.y)), 0.0, t.panel_bg);
- // current timecode: 14 pt semibold accent
+ // current timecode: Premiere's big blue timecode
let tc = format_time(app.session.playhead(), rate, seq.settings.drop_frame, TimeDisplay::Timecode, seq.settings.sample_rate as i64);
let tc_rect = Rect::from_min_size(pos2(rect.min.x + 14.0, rect.min.y + 4.0), vec2(hw - 20.0, 20.0));
- p.text(pos2(tc_rect.min.x, tc_rect.center().y), Align2::LEFT_CENTER, &tc, Tokens::semibold(15.0), t.hot_text);
+ p.text(pos2(tc_rect.min.x, tc_rect.center().y), Align2::LEFT_CENTER, &tc, Tokens::timecode(), t.timecode);
app.auto.add("timeline.timecode", tc_rect, &tc);
// toolbar: 30 × 30 buttons, "on" = #4b4b4b fill
let mut x = rect.min.x + 12.0;
diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs
index 51ff869d6..2f4f3b75c 100644
--- a/crates/ui-egui/src/theme.rs
+++ b/crates/ui-egui/src/theme.rs
@@ -1,7 +1,9 @@
//! Design tokens. Every widget reads colours/sizes from [`Tokens`] so themes apply everywhere.
//!
//! The default theme follows the look of Premiere Pro's current dark UI (values measured from
-//! black-box screenshots, see `plan/premiere/02-ui-ux.md`); fonts are Inter + JetBrains Mono (OFL).
+//! black-box screenshots, see `plan/premiere/02-ui-ux.md`); fonts are Inter + JetBrains Mono (OFL), and
+//! Source Sans 3 (OFL, the closest open face to Premiere's) for the interface when the app is built
+//! with craft-fonts.
use std::sync::Arc;
@@ -124,7 +126,7 @@ impl Tokens {
separator: Color32::from_rgb(0x30, 0x30, 0x30),
row_alt: Color32::from_rgb(0x21, 0x21, 0x21),
row_selected: Color32::from_rgb(0x33, 0x33, 0x33),
- hot_text: Color32::from_rgb(0x57, 0x94, 0xec),
+ hot_text: Color32::from_rgb(0x40, 0x96, 0xf3),
tl_bg: Color32::from_rgb(0x1d, 0x1d, 0x1d),
tl_track_bg: Color32::from_rgb(0x1d, 0x1d, 0x1d),
tl_track_bg_alt: Color32::from_rgb(0x1d, 0x1d, 0x1d),
@@ -139,7 +141,7 @@ impl Tokens {
render_yellow: Color32::from_rgb(0xf0, 0xf0, 0x4f),
render_green: Color32::from_rgb(0x2d, 0x9d, 0x78),
monitor_bg: Color32::from_rgb(0x1d, 0x1d, 0x1d),
- timecode: Color32::from_rgb(0x57, 0x94, 0xec),
+ timecode: Color32::from_rgb(0x40, 0x96, 0xf3),
danger: Color32::from_rgb(0xdc, 0x51, 0x3d),
radius: 0.0,
radius_sm: 4.0,
@@ -228,6 +230,35 @@ impl Tokens {
pub fn semibold(size: f32) -> FontId {
FontId::new(size, FontFamily::Name("semibold".into()))
}
+ /// The big blue timecode over the timeline and under the monitors: regular weight, as in
+ /// Premiere (Premiere's reads 10 px tall and 76 px wide for 00:00:16:05 at 1x).
+ pub fn timecode() -> FontId {
+ FontId::new(16.0, FontFamily::Proportional)
+ }
+}
+
+/// Menu text: Premiere's menus are the system's, larger and brighter than panel text.
+pub const MENU_TEXT_SIZE: f32 = 13.0;
+pub const MENU_TEXT: Color32 = Color32::from_rgb(0xde, 0xde, 0xde);
+
+/// Style of the menu bar's menus and their submenus (on top of egui's own menu style).
+pub fn menu_style(s: &mut egui::Style) {
+ egui::containers::menu::menu_style(s);
+ s.text_styles.insert(TextStyle::Button, FontId::new(MENU_TEXT_SIZE, FontFamily::Proportional));
+ s.text_styles.insert(TextStyle::Body, FontId::new(MENU_TEXT_SIZE, FontFamily::Proportional));
+ if s.visuals.dark_mode {
+ s.visuals.override_text_color = Some(MENU_TEXT);
+ }
+}
+
+/// The interface face in craft-fonts: Source Sans 3 (Adobe's open-source sans, SIL OFL; the closest open
+/// face to Premiere's interface type, which is not licensable).
+pub const UI_FAMILY: &str = "Source Sans 3";
+
+/// The craft-fonts entry of the interface face in `style`; `None` when the app was built without
+/// craft-fonts (the interface then stays in Inter).
+fn craft_ui_face(style: &str) -> Option<&'static filmcraft_text::fonts::CraftFont> {
+ filmcraft_text::fonts::CRAFT_FONTS.iter().find(|f| f.family == UI_FAMILY && f.style == style)
}
/// Every font family the theme defines (fallback fonts such as the Japanese fonts are added to each
@@ -236,8 +267,9 @@ pub fn font_families() -> Vec<FontFamily> {
vec![FontFamily::Proportional, FontFamily::Monospace, FontFamily::Name("semibold".into()), FontFamily::Name("medium".into())]
}
-/// Install fonts (Inter, Inter SemiBold, JetBrains Mono, then the Japanese craft-fonts when built with
-/// `CRAFT_FONTS_DIR`) and egui visuals.
+/// Install fonts (Source Sans 3 from craft-fonts when built with `CRAFT_FONTS_DIR`, then Inter, Inter
+/// SemiBold, JetBrains Mono, then the Japanese craft-fonts) and egui visuals. Inter stays behind
+/// Source Sans 3 for the symbols it lacks.
pub fn install(ctx: &egui::Context, t: &Tokens) {
let mut fonts = FontDefinitions::default();
fonts.font_data.insert("inter".into(), Arc::new(FontData::from_static(filmcraft_text::fonts::INTER_REGULAR)));
@@ -248,6 +280,14 @@ pub fn install(ctx: &egui::Context, t: &Tokens) {
fonts.families.entry(FontFamily::Monospace).or_default().insert(0, "jbmono".into());
fonts.families.insert(FontFamily::Name("semibold".into()), vec!["inter-semibold".into(), "inter".into()]);
fonts.families.insert(FontFamily::Name("medium".into()), vec!["inter-medium".into(), "inter".into()]);
+ for (family, style) in [("", "Regular"), ("medium", "Medium"), ("semibold", "Semibold")] {
+ if let Some(f) = craft_ui_face(style) {
+ let name = format!("ui:{} {}", f.family, f.style);
+ fonts.font_data.insert(name.clone(), Arc::new(FontData::from_static(f.bytes)));
+ let family = if family.is_empty() { FontFamily::Proportional } else { FontFamily::Name(family.into()) };
+ fonts.families.entry(family).or_default().insert(0, name);
+ }
+ }
add_craft_fonts(&mut fonts);
ctx.set_fonts(fonts);
apply_visuals(ctx, t);
@@ -377,7 +417,8 @@ mod tests {
ctx.fonts_mut(|fonts| {
let defs = fonts.definitions().clone();
assert_eq!(defs.font_data.keys().filter(|k| k.starts_with("craft:")).count(), n);
- assert_eq!(defs.families[&FontFamily::Proportional].first().map(String::as_str), Some("inter"));
+ let ui = if craft_ui_face("Regular").is_some() { "ui:Source Sans 3 Regular" } else { "inter" };
+ assert_eq!(defs.families[&FontFamily::Proportional].first().map(String::as_str), Some(ui));
assert_eq!(defs.families[&FontFamily::Monospace].first().map(String::as_str), Some("jbmono"));
assert!(fonts.has_glyph(&FontId::new(13.0, FontFamily::Proportional), 'A'));
if n == 0 {
@@ -385,4 +426,27 @@ mod tests {
}
});
}
+
+ /// Built with craft-fonts that carry Source Sans 3: the interface text is set in it, every weight,
+ /// with Inter right behind it for symbols it lacks.
+ #[test]
+ fn interface_face_from_craft_fonts() {
+ if craft_ui_face("Regular").is_none() {
+ eprintln!("SKIPPED: built without Source Sans 3 in craft-fonts (set CRAFT_FONTS_DIR to run)");
+ return;
+ }
+ let ctx = installed();
+ ctx.fonts_mut(|fonts| {
+ let defs = fonts.definitions().clone();
+ for (family, first, next) in [
+ (FontFamily::Proportional, "ui:Source Sans 3 Regular", "inter"),
+ (FontFamily::Name("medium".into()), "ui:Source Sans 3 Medium", "inter-medium"),
+ (FontFamily::Name("semibold".into()), "ui:Source Sans 3 Semibold", "inter-semibold"),
+ ] {
+ let stack = &defs.families[&family];
+ assert_eq!(&stack[..2], &[first.to_string(), next.to_string()], "{family:?}: {stack:?}");
+ }
+ assert!(fonts.has_glyph(&Tokens::timecode(), '0'));
+ });
+ }
}