forked from 1b-agent/opencadstudio-upstream
The missing-fonts list is as wide as its longest name, so its scrollbar
was drawn over the end of every name ("ROMANT.sh").
Fixes #1715
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
3.4 KiB
Rust
102 lines
3.4 KiB
Rust
// Missing-fonts prompt — shown after a drawing opens with `.shx` fonts this
|
|
// machine doesn't have. Offers to fetch them from the community repository
|
|
// (see `fonts/README.md` in the repo root) instead of rendering with a
|
|
// mismatched substitute.
|
|
|
|
use crate::app::Message;
|
|
use crate::ui::style::form::dialog_button_styled_opt;
|
|
use iced::widget::{button, column, container, row, scrollable, text, text_input, Space};
|
|
use iced::{Element, Fill, Length, Shrink, Theme};
|
|
|
|
fn muted_style(theme: &Theme) -> text::Style {
|
|
text::Style {
|
|
color: Some(theme.palette().background.weak.text),
|
|
}
|
|
}
|
|
|
|
/// The prompt: the missing-font list, a download action, and a skip.
|
|
pub fn view_window<'a>(
|
|
fonts: &'a [String],
|
|
font_source: &'a str,
|
|
downloading: bool,
|
|
sizing: crate::ui::modal::ModalSizing,
|
|
) -> Element<'a, Message> {
|
|
let content_width = if matches!(sizing.width, Length::Fill) {
|
|
Fill
|
|
} else {
|
|
Shrink
|
|
};
|
|
let content_height = if matches!(sizing.height, Length::Fill) {
|
|
Fill
|
|
} else {
|
|
Shrink
|
|
};
|
|
let listed: Vec<Element<'a, Message>> = fonts
|
|
.iter()
|
|
.map(|name| text(format!(" {name}")).size(12).into())
|
|
.collect();
|
|
let download = dialog_button_styled_opt(
|
|
if downloading {
|
|
crate::t!("Downloading...")
|
|
} else {
|
|
crate::t!("Download available")
|
|
},
|
|
(!downloading).then_some(Message::MissingFontsDownload),
|
|
button::primary,
|
|
);
|
|
let actions = row![
|
|
Space::new().width(content_width),
|
|
dialog_button_styled_opt(
|
|
crate::t!("Skip"),
|
|
(!downloading).then_some(Message::MissingFontsDismiss),
|
|
button::secondary,
|
|
),
|
|
download,
|
|
]
|
|
.spacing(8);
|
|
|
|
container(
|
|
column![
|
|
text(crate::t!("Missing fonts")).size(20),
|
|
text(crate::t!(
|
|
"This drawing uses fonts that are not installed on this machine. OpenCADStudio can download any redistributable fonts that exist in the selected repository; unavailable fonts will keep using a substitute."
|
|
))
|
|
.size(11)
|
|
.style(muted_style),
|
|
// The right padding keeps the names clear of the scrollbar, which
|
|
// a list as wide as its longest name would otherwise draw over.
|
|
container(
|
|
scrollable(column(listed).spacing(2).padding(iced::Padding {
|
|
right: 14.0,
|
|
..iced::Padding::ZERO
|
|
}))
|
|
.height(content_height),
|
|
)
|
|
.padding([10, 12])
|
|
.width(content_width)
|
|
.height(content_height)
|
|
.style(container::bordered_box),
|
|
column![
|
|
text(crate::t!("Font source — leave empty for the community repository, or point at any folder (e.g. your company's font server):"))
|
|
.size(10)
|
|
.style(muted_style),
|
|
text_input(
|
|
crate::t!("https://server/fonts or a GitHub raw folder").as_ref(),
|
|
font_source,
|
|
)
|
|
.on_input(Message::MissingFontsSourceChanged)
|
|
.size(11)
|
|
.padding([4, 8])
|
|
.width(content_width),
|
|
]
|
|
.spacing(3),
|
|
actions,
|
|
]
|
|
.spacing(10)
|
|
.width(sizing.width)
|
|
.height(sizing.height),
|
|
)
|
|
.padding([12, 16])
|
|
.into()
|
|
}
|