1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

GUI: Use the client's fonts for 'Open URL?' dialogues

This popup is related to user safety, thus it should not
use server-provided font media files.
This commit is contained in:
SmallJoker 2025-03-15 15:30:35 +01:00 committed by SmallJoker
parent 5b2b2c7796
commit f1364b1e0b
4 changed files with 72 additions and 32 deletions

View file

@ -87,6 +87,12 @@ void GUIOpenURLMenu::regenerateGui(v2u32 screensize)
ok = false;
}
std::array<StyleSpec, StyleSpec::NUM_STATES> styles {};
for (auto &style : styles)
style.set(StyleSpec::Property::FONT, "_no_server_media");
auto font_standard = styles[0].getFont();
/*
Add stuff
*/
@ -99,8 +105,9 @@ void GUIOpenURLMenu::regenerateGui(v2u32 screensize)
std::wstring title = ok
? wstrgettext("Open URL?")
: wstrgettext("Unable to open URL");
gui::StaticText::add(Environment, title, rect,
auto *e = gui::StaticText::add(Environment, title, rect,
false, true, this, -1);
e->setOverrideFont(font_standard);
}
ypos += 50 * s;
@ -108,8 +115,11 @@ void GUIOpenURLMenu::regenerateGui(v2u32 screensize)
{
core::rect<s32> rect(0, 0, 440 * s, 60 * s);
auto font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED,
ok ? FM_Mono : FM_Standard);
FontSpec fontspec(FONT_SIZE_UNSPECIFIED, FM_Mono, false, false);
fontspec.allow_server_media = false;
auto font = ok ? g_fontengine->getFont(fontspec) : font_standard;
int scrollbar_width = Environment->getSkin()->getSize(gui::EGDS_SCROLLBAR_SIZE);
int max_cols = (rect.getWidth() - scrollbar_width - 10) / font->getDimension(L"x").Width;
@ -131,14 +141,16 @@ void GUIOpenURLMenu::regenerateGui(v2u32 screensize)
if (ok) {
core::rect<s32> rect(0, 0, 100 * s, 40 * s);
rect = rect + v2s32(size.X / 2 - 150 * s, ypos);
GUIButton::addButton(Environment, rect, m_tsrc, this, ID_open,
auto *e = GUIButton::addButton(Environment, rect, m_tsrc, this, ID_open,
wstrgettext("Open").c_str());
e->setStyles(styles);
}
{
core::rect<s32> rect(0, 0, 100 * s, 40 * s);
rect = rect + v2s32(size.X / 2 + 50 * s, ypos);
GUIButton::addButton(Environment, rect, m_tsrc, this, ID_cancel,
auto *e = GUIButton::addButton(Environment, rect, m_tsrc, this, ID_cancel,
wstrgettext("Cancel").c_str());
e->setStyles(styles);
}
}