1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 08:17:35 +00:00

LibGUI: Add a GFontDatabase class that lets you enumerate fonts and more.

"More" in this case being also giving you the ability to load a font by name.
Use this as backend for Terminal's font menu. :^)
This commit is contained in:
Andreas Kling 2019-02-12 14:35:33 +01:00
parent 7df7e5e2a6
commit d6326d6c2e
4 changed files with 79 additions and 8 deletions

View file

@ -15,6 +15,7 @@
#include <LibGUI/GWindow.h>
#include <LibGUI/GMenuBar.h>
#include <LibGUI/GAction.h>
#include <LibGUI/GFontDatabase.h>
static void make_shell(int ptm_fd)
{
@ -104,14 +105,12 @@ int main(int argc, char** argv)
menubar->add_menu(move(app_menu));
auto font_menu = make<GMenu>("Font");
auto handle_font_selection = [&terminal] (const GAction& action) {
terminal.set_font(Font::load_from_file(action.custom_data()));
terminal.force_repaint();
};
font_menu->add_action(make<GAction>("Liza Thin", "/res/fonts/LizaThin8x10.font", move(handle_font_selection)));
font_menu->add_action(make<GAction>("Liza Regular", "/res/fonts/LizaRegular8x10.font", move(handle_font_selection)));
font_menu->add_action(make<GAction>("Liza Bold", "/res/fonts/LizaBold8x10.font", move(handle_font_selection)));
GFontDatabase::the().for_each_font([&] (const String& font_name) {
font_menu->add_action(make<GAction>(font_name, [&terminal] (const GAction& action) {
terminal.set_font(GFontDatabase::the().get_by_name(action.text()));
terminal.force_repaint();
}));
});
menubar->add_menu(move(font_menu));
auto help_menu = make<GMenu>("Help");