forked from 1b-agent/opencadstudio-upstream
Merge pull request #1831 from manuvarkey/system-ui-font-face
This commit is contained in:
commit
012ccc7b65
10 files changed
+1134
-7
No files matched your search
@@ -2476,6 +2476,10 @@ pub enum Message {
|
||||
ApplyWebFont(crate::scene::text::web_font::Script),
|
||||
/// Completion of the UI renderer's runtime font registration.
|
||||
WebUiFontLoaded(crate::scene::text::web_font::Script, Result<(), String>),
|
||||
/// The desktop reported (or a poll may have found) a UI-font change.
|
||||
UiFontSettingsChanged,
|
||||
/// A re-read of the desktop UI font finished.
|
||||
UiFontDetected(Option<crate::sys::ui_font::SystemUiFont>),
|
||||
/// Ctrl+V. Routed by `update` into an open text editor, the drawing-object
|
||||
/// clipboard, or the system text clipboard.
|
||||
PasteShortcut,
|
||||
@@ -5577,6 +5581,9 @@ use std::path::PathBuf;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn run() -> iced::Result {
|
||||
// UI text follows the desktop's interface font: generic sans-serif, iced's
|
||||
// default font, is remapped to it before the first window opens.
|
||||
crate::sys::ui_font::apply(crate::sys::ui_font::detect().as_ref());
|
||||
iced::daemon(
|
||||
OpenCADStudio::boot,
|
||||
OpenCADStudio::update,
|
||||
|
||||
@@ -1052,6 +1052,27 @@ impl OpenCADStudio {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
Message::UiFontSettingsChanged => Task::perform(
|
||||
async { crate::sys::ui_font::detect() },
|
||||
Message::UiFontDetected,
|
||||
),
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
Message::UiFontSettingsChanged => Task::none(),
|
||||
|
||||
// Re-setting the defaults recreates the renderers and lays out
|
||||
// every window again with the remapped sans-serif family.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
Message::UiFontDetected(system) => {
|
||||
if crate::sys::ui_font::apply(system.as_ref()) {
|
||||
iced::font::set_defaults(iced::Font::DEFAULT, 16.0)
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
Message::UiFontDetected(_) => Task::none(),
|
||||
|
||||
Message::Tick(t) => self.on_tick(t),
|
||||
|
||||
Message::OpenFile => self.on_open_file(),
|
||||
|
||||
@@ -146,6 +146,22 @@ pub(in crate::app) const VIEWPORT_CAPTURE_BOUNDS_ID: &str = "viewport-capture-bo
|
||||
|
||||
const VIEWCUBE_HIT_SIZE: f32 = VIEWCUBE_REGION_PX;
|
||||
|
||||
/// Desktop UI-font changes while running. Linux listens for the Settings
|
||||
/// portal's `SettingChanged` (no portal: restart to apply). Windows exposes no
|
||||
/// change notification through iced, but the metrics read is a cheap system
|
||||
/// call, so it is polled. macOS has no user-adjustable UI font, and the web
|
||||
/// build follows the font it loads for the UI language.
|
||||
fn ui_font_changes() -> Subscription<Message> {
|
||||
#[cfg(target_os = "linux")]
|
||||
return Subscription::run(crate::sys::ui_font::change_signals)
|
||||
.map(|()| Message::UiFontSettingsChanged);
|
||||
#[cfg(target_os = "windows")]
|
||||
return iced::time::every(std::time::Duration::from_secs(2))
|
||||
.map(|_| Message::UiFontSettingsChanged);
|
||||
#[allow(unreachable_code)]
|
||||
Subscription::none()
|
||||
}
|
||||
|
||||
/// Background used by drafting overlays in model or paper space.
|
||||
fn crosshair_background(tab: &DocumentTab, is_paper: bool) -> [f32; 4] {
|
||||
if !is_paper {
|
||||
@@ -3053,6 +3069,7 @@ impl OpenCADStudio {
|
||||
single_instance,
|
||||
hatch_pattern_keys,
|
||||
keyboard_events,
|
||||
ui_font_changes(),
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user