Add font size selection to ecode font picker:

Allow UIFontPickerDialog sections to be hidden and make ecode's UI, editor, and terminal font dialogs select both the font and its size.
Keep external fonts selectable across asynchronous font enumeration, including when they share a family name with a system font, and label them as external. Also normalize UILinearLayout weights across visible children so hidden picker columns release their space correctly.
Update font picker previews, size units, menu labels, translations, and lifetime handling.

Addresses SpartanJ/ecode#944.
This commit is contained in:
Martín Lucas Golini
2026-08-11 12:38:34 -03:00
parent 10a5d7effc
commit 6df0c0738f
17 changed files with 397 additions and 115 deletions
+2 -2
View File
@@ -442,9 +442,9 @@ void App::openFolderDialog() {
}
void App::openFontDialog( std::string& fontPath, bool loadingMonoFont, bool terminalFont,
std::function<void()> onFinish ) {
std::function<void()> onFinish, bool pickFontSize ) {
mFontPickerController->openFontDialog( fontPath, loadingMonoFont, terminalFont,
std::move( onFinish ) );
std::move( onFinish ), pickFontSize );
}
void App::updateInputFonts() {
+11 -8
View File
@@ -80,7 +80,7 @@ class App : public UICodeEditorSplitter::Client, public PluginContextProvider {
void openFolderDialog();
void openFontDialog( std::string& fontPath, bool loadingMonoFont, bool terminalFont = false,
std::function<void()> onFinish = {} );
std::function<void()> onFinish = {}, bool pickFontSize = true );
void updateInputFonts();
@@ -356,13 +356,16 @@ class App : public UICodeEditorSplitter::Client, public PluginContextProvider {
t.setCommand( "terminal-font",
[this] { openFontDialog( mConfig.ui.terminalFont, true, true ); } );
t.setCommand( "fallback-font", [this] {
openFontDialog( mConfig.ui.fallbackFont, false, false, [this] {
UIMessageBox::New( UIMessageBox::OK,
i18n( "new_fallback_font_requires_restart",
"New fallback font has been set. Application must be "
"restarted in order to see the changes." ) )
->showWhenReady();
} );
openFontDialog(
mConfig.ui.fallbackFont, false, false,
[this] {
UIMessageBox::New( UIMessageBox::OK,
i18n( "new_fallback_font_requires_restart",
"New fallback font has been set. Application must be "
"restarted in order to see the changes." ) )
->showWhenReady();
},
false );
} );
t.setCommand( "tree-view-configure-ignore-files",
[this] { treeViewConfigureIgnoreFiles(); } );
+29 -7
View File
@@ -1,5 +1,6 @@
#include "fontpickercontroller.hpp"
#include "ecode.hpp"
#include "settingsactions.hpp"
#include <eepp/graphics/fontfamily.hpp>
#include <eepp/scene/scenemanager.hpp>
#include <eepp/ui/tools/uifontpickerdialog.hpp>
@@ -18,7 +19,8 @@ struct MonospaceFontPreview {
};
void FontPickerController::openFontDialog( std::string& fontPath, bool loadingMonoFont,
bool terminalFont, std::function<void()> onFinish ) {
bool terminalFont, std::function<void()> onFinish,
bool pickFontSize ) {
std::string absoluteFontPath( fontPath );
if ( FileSystem::isRelativePath( absoluteFontPath ) )
absoluteFontPath = mApp->resPath() + fontPath;
@@ -103,19 +105,20 @@ void FontPickerController::openFontDialog( std::string& fontPath, bool loadingMo
defaultResourceScope().publishLocalFont( std::move( fontName ), font );
};
const Uint32 flags = UIFontPickerDialog::DefaultFlags |
const Uint32 flags = ( pickFontSize ? UIFontPickerDialog::ShowSize : 0 ) |
( loadingMonoFont ? UIFontPickerDialog::MonospaceOnly : 0 );
UIFontPickerDialog* dialog = UIFontPickerDialog::New( flags );
dialog->setTitle( mApp->i18n( "select_font", "Select Font" ) );
dialog->setCloseShortcut( KEY_ESCAPE );
dialog->on( Event::OnWindowClose, [this, preview, applyMonospaceFont]( const Event* ) {
if ( !App::instance() || SceneManager::isShuttingDown() )
return;
if ( preview && !preview->confirmed )
applyMonospaceFont( preview->originalFont, false );
if ( App::instance() && mApp->getSplitter() && mApp->getSplitter()->getCurWidget() &&
!SceneManager::instance()->isShuttingDown() ) {
if ( mApp->getSplitter() && mApp->getSplitter()->getCurWidget() )
mApp->getSplitter()->getCurWidget()->setFocus();
}
} );
if ( loadingMonoFont ) {
dialog->setOnFontSelectionChanged(
@@ -138,9 +141,18 @@ void FontPickerController::openFontDialog( std::string& fontPath, bool loadingMo
}
} );
}
dialog->setOnFontPicked( [&fontPath, loadingMonoFont, onFinish, preview, normalizedFontPath,
loadPreviewFont, publishPreviewFont,
dialog->setOnFontPicked( [this, &fontPath, loadingMonoFont, terminalFont, onFinish, preview,
normalizedFontPath, pickFontSize, loadPreviewFont, publishPreviewFont,
applyMonospaceFont]( const UIFontSelection& selection ) {
if ( pickFontSize ) {
const StyleSheetLength size( selection.size, StyleSheetLength::Dp );
if ( terminalFont )
mApp->getSettingsActions()->setTerminalFontSize( size );
else if ( loadingMonoFont )
mApp->getSettingsActions()->setEditorFontSize( size );
else
mApp->getSettingsActions()->setUIFontSize( size );
}
auto newPath = normalizedFontPath( selection.font.path );
if ( newPath.empty() )
return;
@@ -168,6 +180,16 @@ void FontPickerController::openFontDialog( std::string& fontPath, bool loadingMo
applyMonospaceFont( preview->originalFont, false );
}
} );
if ( pickFontSize ) {
UIFontSelection selection = dialog->getSelection();
const Float currentSize =
terminalFont ? mApp->getConfig().term.fontSize.asDp( 0, Sizef(), mApp->getDisplayDPI() )
: loadingMonoFont
? mApp->getConfig().editor.fontSize.asDp( 0, Sizef(), mApp->getDisplayDPI() )
: mApp->getConfig().ui.fontSize.asDp( 0, Sizef(), mApp->getDisplayDPI() );
selection.size = static_cast<Uint32>( currentSize );
dialog->setSelection( selection );
}
dialog->setSelectedFont( absoluteFontPath );
dialog->center();
dialog->show();
+1 -1
View File
@@ -13,7 +13,7 @@ class FontPickerController {
explicit FontPickerController( App* app ) : mApp( app ) {}
void openFontDialog( std::string& fontPath, bool loadingMonoFont, bool terminalFont = false,
std::function<void()> onFinish = {} );
std::function<void()> onFinish = {}, bool pickFontSize = true );
private:
App* mApp{ nullptr };
+37 -27
View File
@@ -316,15 +316,18 @@ void SettingsActions::setEditorFontSize() {
msgBox->setCloseShortcut( { KEY_ESCAPE, 0 } );
msgBox->showWhenReady();
msgBox->on( Event::OnConfirm, [this, msgBox]( const Event* ) {
mApp->getConfig().editor.fontSize = StyleSheetLength( msgBox->getTextInput()->getText() );
mApp->getSplitter()->forEachEditor( [this]( UICodeEditor* editor ) {
editor->setFontSize(
mApp->getConfig().editor.fontSize.asPixels( 0, Sizef(), mApp->getDisplayDPI() ) );
} );
setEditorFontSize( StyleSheetLength( msgBox->getTextInput()->getText() ) );
} );
mApp->setFocusEditorOnClose( msgBox );
}
void SettingsActions::setEditorFontSize( const StyleSheetLength& size ) {
mApp->getConfig().editor.fontSize = size;
const Float fontSize = size.asPixels( 0, Sizef(), mApp->getDisplayDPI() );
mApp->getSplitter()->forEachEditor(
[fontSize]( UICodeEditor* editor ) { editor->setFontSize( fontSize ); } );
}
void SettingsActions::setTerminalFontSize() {
UIMessageBox* msgBox = UIMessageBox::New(
UIMessageBox::INPUT, i18n( "set_terminal_font_size", "Set the terminal font size:" ) );
@@ -333,16 +336,20 @@ void SettingsActions::setTerminalFontSize() {
msgBox->setCloseShortcut( { KEY_ESCAPE, 0 } );
msgBox->showWhenReady();
msgBox->on( Event::OnConfirm, [this, msgBox]( const Event* ) {
mApp->getConfig().term.fontSize = StyleSheetLength( msgBox->getTextInput()->getText() );
mApp->getSplitter()->forEachWidget( [this]( UIWidget* widget ) {
if ( widget && widget->isType( UI_TYPE_TERMINAL ) )
widget->asType<UITerminal>()->setFontSize(
mApp->getConfig().term.fontSize.asPixels( 0, Sizef(), mApp->getDisplayDPI() ) );
} );
setTerminalFontSize( StyleSheetLength( msgBox->getTextInput()->getText() ) );
} );
mApp->setFocusEditorOnClose( msgBox );
}
void SettingsActions::setTerminalFontSize( const StyleSheetLength& size ) {
mApp->getConfig().term.fontSize = size;
const Float fontSize = size.asPixels( 0, Sizef(), mApp->getDisplayDPI() );
mApp->getSplitter()->forEachWidget( [fontSize]( UIWidget* widget ) {
if ( widget && widget->isType( UI_TYPE_TERMINAL ) )
widget->asType<UITerminal>()->setFontSize( fontSize );
} );
}
void SettingsActions::setUIFontSize() {
UIMessageBox* msgBox = UIMessageBox::New( UIMessageBox::INPUT,
i18n( "set_ui_font_size", "Set the UI font size:" ) );
@@ -351,27 +358,30 @@ void SettingsActions::setUIFontSize() {
msgBox->setCloseShortcut( { KEY_ESCAPE, 0 } );
msgBox->showWhenReady();
msgBox->on( Event::OnConfirm, [this, msgBox]( const Event* ) {
mApp->getConfig().ui.fontSize = StyleSheetLength( msgBox->getTextInput()->getText() );
Float fontSize =
mApp->getConfig().ui.fontSize.asPixels( 0, Sizef(), mApp->getDisplayDPI() );
UIThemeManager* manager = mApp->getUISceneNode()->getUIThemeManager();
manager->setDefaultFontSize( fontSize );
manager->getDefaultTheme()->setDefaultFontSize( fontSize );
mApp->getUISceneNode()->forEachNode( [this]( Node* node ) {
if ( node->isType( UI_TYPE_TEXTVIEW ) ) {
UITextView* textView = node->asType<UITextView>();
if ( !textView->getUIStyle()->hasProperty( PropertyId::FontSize ) ) {
textView->setFontSize( mApp->getConfig().ui.fontSize.asPixels(
node->getParent()->getPixelsSize().getWidth(), Sizef(),
mApp->getUISceneNode()->getDPI() ) );
}
}
} );
setUIFontSize( StyleSheetLength( msgBox->getTextInput()->getText() ) );
msgBox->closeWindow();
} );
mApp->setFocusEditorOnClose( msgBox );
}
void SettingsActions::setUIFontSize( const StyleSheetLength& size ) {
mApp->getConfig().ui.fontSize = size;
const Float fontSize = size.asPixels( 0, Sizef(), mApp->getDisplayDPI() );
UIThemeManager* manager = mApp->getUISceneNode()->getUIThemeManager();
manager->setDefaultFontSize( fontSize );
manager->getDefaultTheme()->setDefaultFontSize( fontSize );
mApp->getUISceneNode()->forEachNode( [this]( Node* node ) {
if ( node->isType( UI_TYPE_TEXTVIEW ) ) {
UITextView* textView = node->asType<UITextView>();
if ( !textView->getUIStyle()->hasProperty( PropertyId::FontSize ) ) {
textView->setFontSize( mApp->getConfig().ui.fontSize.asPixels(
node->getParent()->getPixelsSize().getWidth(), Sizef(),
mApp->getUISceneNode()->getDPI() ) );
}
}
} );
}
void SettingsActions::setUIPanelFontSize() {
UIMessageBox* msgBox = UIMessageBox::New(
UIMessageBox::INPUT, i18n( "set_side_panel_font_size", "Set side panel font size:" ) );
+3 -1
View File
@@ -30,10 +30,13 @@ class SettingsActions {
void setUIScaleFactor();
void setUIFontSize();
void setUIFontSize( const StyleSheetLength& size );
void setEditorFontSize();
void setEditorFontSize( const StyleSheetLength& size );
void setTerminalFontSize();
void setTerminalFontSize( const StyleSheetLength& size );
void setUIPanelFontSize();
@@ -43,7 +46,6 @@ class SettingsActions {
String i18n( const std::string& key, const String& def );
void checkForUpdatesResponse( Http::Response&& response, bool fromStartup );
};
} // namespace ecode
+6 -9
View File
@@ -3300,21 +3300,18 @@ UIMenu* SettingsMenu::createFontsMenu() {
createFontHintMenu() );
mFontsMenu->addSubMenu( i18n( "ui_font_antialiasing", "Font Anti-Aliasing" ),
findIcon( "font-size" ), createFontAntiAliasingMenu() );
mFontsMenu->add( i18n( "ui_font_size", "UI Font Size" ), findIcon( "font-size" ) )
->setId( "ui-font-size" );
mFontsMenu->add( i18n( "ui_panel_font_size", "UI Panel Font Size" ), findIcon( "font-size" ) )
->setId( "ui-panel-font-size" );
mFontsMenu->add( i18n( "editor_font_size", "Editor Font Size" ), findIcon( "font-size" ) )
->setId( "editor-font-size" );
mFontsMenu->add( i18n( "terminal_font_size", "Terminal Font Size" ), findIcon( "font-size" ) )
->setId( "terminal-font-size" );
mFontsMenu
->add( i18n( "sans-serif_font_ellipsis", "Sans-Serif Font..." ), findIcon( "font-size" ) )
->add( i18n( "ui_font_and_size_ellipsis", "UI Font & Size..." ), findIcon( "font-size" ) )
->setId( "sans-serif-font" );
mFontsMenu
->add( i18n( "monospace_font_ellipsis", "Monospace Font..." ), findIcon( "font-size" ) )
->add( i18n( "editor_font_and_size_ellipsis", "Editor Font & Size..." ),
findIcon( "font-size" ) )
->setId( "monospace-font" );
mFontsMenu->add( i18n( "terminal_font_ellipsis", "Terminal Font..." ), findIcon( "font-size" ) )
mFontsMenu
->add( i18n( "terminal_font_and_size_ellipsis", "Terminal Font & Size..." ),
findIcon( "font-size" ) )
->setId( "terminal-font" );
mFontsMenu->add( i18n( "fallback_font_ellipsis", "Fallback Font..." ), findIcon( "font-size" ) )
->setId( "fallback-font" );