Skip to content

Commit 57cdab7

Browse files
committed
Implemented UIFontPickerDialog.
Fixed alignment in UILinearLayout when padding is used.
1 parent 3a1c75f commit 57cdab7

15 files changed

Lines changed: 1298 additions & 17 deletions

File tree

.ecode/project_build.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,12 @@
381381
"command": "${project_root}/bin/eepp-ui-html-debug",
382382
"name": "eepp-ui-html-debug",
383383
"working_dir": "${project_root}/bin"
384+
},
385+
{
386+
"args": "",
387+
"command": "${project_root}/bin/eepp-ui-font-picker-debug",
388+
"name": "eepp-ui-font-picker-debug",
389+
"working_dir": "${project_root}/bin"
384390
}
385391
],
386392
"var": {

include/eepp/graphics/fonttruetype.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class EE_API FontTrueType : public Font {
3535

3636
const Font::Info& getInfo() const;
3737

38+
const Uint32& getFaceIndex() const { return mFaceIndex; }
39+
3840
Glyph getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, bool italic,
3941
Float outlineThickness = 0 ) const;
4042

include/eepp/scene/event.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class EE_API Event {
131131
OnFocusWithin,
132132
OnFocusWithinLoss,
133133
OnItemsCountChange,
134+
OnApply,
134135
NoEvent = eeINDEX_NOT_FOUND
135136
};
136137

include/eepp/ui.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include <eepp/ui/tools/uicolorpicker.hpp>
7575
#include <eepp/ui/tools/uidiffview.hpp>
7676
#include <eepp/ui/tools/uidocfindreplace.hpp>
77+
#include <eepp/ui/tools/uifontpickerdialog.hpp>
7778
#include <eepp/ui/tools/uiimageviewer.hpp>
7879
#include <eepp/ui/tools/uiwidgetinspector.hpp>
7980
#include <eepp/ui/uiapplication.hpp>
@@ -141,7 +142,6 @@
141142
#include <eepp/ui/uiscrollablewidget.hpp>
142143
#include <eepp/ui/uiscrollbar.hpp>
143144
#include <eepp/ui/uiscrollview.hpp>
144-
#include <eepp/ui/uiwebview.hpp>
145145
#include <eepp/ui/uiselectbutton.hpp>
146146
#include <eepp/ui/uiskin.hpp>
147147
#include <eepp/ui/uiskinstate.hpp>
@@ -172,6 +172,7 @@
172172
#include <eepp/ui/uitouchdraggablewidget.hpp>
173173
#include <eepp/ui/uitreeview.hpp>
174174
#include <eepp/ui/uiviewpager.hpp>
175+
#include <eepp/ui/uiwebview.hpp>
175176
#include <eepp/ui/uiwidget.hpp>
176177
#include <eepp/ui/uiwidgetcreator.hpp>
177178
#include <eepp/ui/uiwidgettable.hpp>
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#ifndef EE_UI_TOOLS_UIFONTPICKERDIALOG_HPP
2+
#define EE_UI_TOOLS_UIFONTPICKERDIALOG_HPP
3+
4+
#include <atomic>
5+
#include <eepp/graphics/systemfontresolver.hpp>
6+
#include <eepp/system/color.hpp>
7+
#include <eepp/ui/keyboardshortcut.hpp>
8+
#include <eepp/ui/models/model.hpp>
9+
#include <eepp/ui/uiwindow.hpp>
10+
#include <functional>
11+
#include <memory>
12+
#include <string>
13+
#include <vector>
14+
15+
namespace EE { namespace UI {
16+
class UICheckBox;
17+
class UIFileDialog;
18+
class UILoader;
19+
class UIListView;
20+
class UIPushButton;
21+
class UITextInput;
22+
class UITextView;
23+
}} // namespace EE::UI
24+
25+
namespace EE { namespace UI { namespace Tools {
26+
27+
class UIColorPicker;
28+
29+
struct UIFontSelection {
30+
FontDesc font;
31+
Uint32 size{ 12 };
32+
bool underline{ false };
33+
bool strikeThrough{ false };
34+
bool antialiasing{ true };
35+
Color color{ Color::White };
36+
};
37+
38+
class EE_API UIFontPickerDialog : public UIWindow {
39+
public:
40+
using FontPickedCb = std::function<void( const UIFontSelection& )>;
41+
42+
enum Flags {
43+
MonospaceOnly = 1 << 0,
44+
ShowSize = 1 << 1,
45+
ShowEffects = 1 << 2,
46+
ShowColor = 1 << 3,
47+
ShowApplyButton = 1 << 4,
48+
DefaultFlags = ShowSize | ShowEffects | ShowColor,
49+
};
50+
51+
struct FontStyleEntry {
52+
std::string label;
53+
FontDesc desc;
54+
};
55+
56+
static UIFontPickerDialog* New( Uint32 flags = DefaultFlags );
57+
58+
virtual ~UIFontPickerDialog();
59+
60+
virtual Uint32 getType() const;
61+
62+
virtual bool isType( const Uint32& type ) const;
63+
64+
virtual void setTheme( UITheme* theme );
65+
66+
void setSelectedFont( const FontDesc& desc );
67+
68+
void setSelectedFont( const std::string& path, Uint32 faceIndex = 0 );
69+
70+
const UIFontSelection& getSelection() const;
71+
72+
void setSelection( const UIFontSelection& selection );
73+
74+
void setOnFontPicked( FontPickedCb cb );
75+
76+
UIPushButton* getButtonOK() const;
77+
78+
UIPushButton* getButtonCancel() const;
79+
80+
UIPushButton* getButtonApply() const;
81+
82+
UIPushButton* getButtonBrowse() const;
83+
84+
UITextInput* getSearchInput() const;
85+
86+
UIListView* getFamilyList() const;
87+
88+
UIListView* getStyleList() const;
89+
90+
UIListView* getSizeList() const;
91+
92+
const KeyBindings::Shortcut& getCloseShortcut() const;
93+
94+
void setCloseShortcut( const KeyBindings::Shortcut& closeShortcut );
95+
96+
virtual bool show();
97+
98+
protected:
99+
Uint32 mFlags{ DefaultFlags };
100+
KeyBindings::Shortcut mCloseShortcut{ KEY_UNKNOWN };
101+
UIFontSelection mSelection;
102+
FontPickedCb mFontPickedCb;
103+
std::vector<FontDesc> mFonts;
104+
std::vector<std::string> mFamilies;
105+
std::vector<FontStyleEntry> mStyles;
106+
std::vector<Uint32> mSizes;
107+
std::shared_ptr<Models::Model> mFamilyModel;
108+
std::shared_ptr<Models::Model> mStyleModel;
109+
std::shared_ptr<Models::Model> mSizeModel;
110+
UIWidget* mFontContent{ nullptr };
111+
UILoader* mFontLoader{ nullptr };
112+
UITextInput* mSearchInput{ nullptr };
113+
UIListView* mFamilyList{ nullptr };
114+
UIListView* mStyleList{ nullptr };
115+
UIListView* mSizeList{ nullptr };
116+
UITextView* mPreviewText{ nullptr };
117+
UITextInput* mPreviewInput{ nullptr };
118+
UITextView* mDetailsText{ nullptr };
119+
UIColorPicker* mColorPicker{ nullptr };
120+
UIFileDialog* mBrowseDialog{ nullptr };
121+
Uint32 mColorPickerCloseCb{ 0 };
122+
Uint32 mBrowseDialogCloseCb{ 0 };
123+
Uint32 mBrowseDialogOpenCb{ 0 };
124+
UICheckBox* mMonospaceOnly{ nullptr };
125+
UICheckBox* mAntialiasing{ nullptr };
126+
UICheckBox* mUnderline{ nullptr };
127+
UICheckBox* mStrikeThrough{ nullptr };
128+
UIPushButton* mColorButton{ nullptr };
129+
UIPushButton* mButtonOK{ nullptr };
130+
UIPushButton* mButtonCancel{ nullptr };
131+
UIPushButton* mButtonApply{ nullptr };
132+
UIPushButton* mButtonBrowse{ nullptr };
133+
bool mUpdating{ false };
134+
bool mLoadingFonts{ false };
135+
Uint64 mLoadFontsTaskId{ 0 };
136+
137+
struct LoadFontsRequest {
138+
std::atomic<bool> alive{ true };
139+
std::atomic<UIFontPickerDialog*> dialog{ nullptr };
140+
};
141+
std::shared_ptr<LoadFontsRequest> mLoadFontsRequest;
142+
143+
UIFontPickerDialog( Uint32 flags = DefaultFlags );
144+
145+
virtual void onWindowReady();
146+
147+
virtual Uint32 onKeyUp( const KeyEvent& event );
148+
149+
virtual Uint32 onMessage( const NodeMessage* msg );
150+
151+
void loadWidgets();
152+
153+
void loadFonts();
154+
155+
void setFonts( std::vector<FontDesc> fonts );
156+
157+
void sortFonts();
158+
159+
void setFontsLoading( bool loading );
160+
161+
void updateFamilies();
162+
163+
void updateStyles();
164+
165+
void updateSelectionFromLists();
166+
167+
void updatePreview();
168+
169+
void selectInitialRows();
170+
171+
void selectFamily( const std::string& family );
172+
173+
void selectStyle( const FontDesc& desc );
174+
175+
void selectSize( Uint32 size );
176+
177+
void emitPicked();
178+
179+
void pickColor();
180+
181+
void browseFont();
182+
183+
bool addExternalFont( const std::string& path, Uint32 faceIndex = 0 );
184+
185+
void clearBrowseDialog();
186+
187+
bool wantsMonospaceOnly() const;
188+
};
189+
190+
}}} // namespace EE::UI::Tools
191+
192+
#endif

include/eepp/ui/uihelper.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ enum UINodeType {
138138
UI_TYPE_WEBVIEW,
139139
UI_TYPE_SVG,
140140
UI_TYPE_TEXTNODE,
141+
UI_TYPE_FONTPICKERDIALOG,
141142
UI_TYPE_MODULES = 10000,
142143
UI_TYPE_TERMINAL = 10001,
143144
UI_TYPE_USER = 200000,

premake4.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,12 @@ solution "eepp"
16691669
files { "src/examples/ui_application_hello_world/*.cpp" }
16701670
build_link_configuration( "eepp-ui-application-hello-world", true )
16711671

1672+
project "eepp-ui-font-picker"
1673+
set_kind()
1674+
language "C++"
1675+
files { "src/examples/ui_font_picker/*.cpp" }
1676+
build_link_configuration( "eepp-ui-font-picker", true )
1677+
16721678
project "eepp-ui-dropdownmodellist"
16731679
set_kind()
16741680
language "C++"

premake5.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,12 @@ workspace "eepp"
16621662
files { "src/examples/ui_application_hello_world/*.cpp" }
16631663
build_link_configuration( "eepp-ui-application-hello-world", true )
16641664

1665+
project "eepp-ui-font-picker"
1666+
set_kind()
1667+
language "C++"
1668+
files { "src/examples/ui_font_picker/*.cpp" }
1669+
build_link_configuration( "eepp-ui-font-picker", true )
1670+
16651671
project "eepp-ui-dropdownmodellist"
16661672
set_kind()
16671673
language "C++"

src/eepp/graphics/fontmanager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ FontTrueType* FontManager::getOrLoadSystemFallbackFont( const FontDesc& desc ) {
111111
for ( auto* font : mSystemFallbackFonts ) {
112112
if ( font->getType() == FontType::TTF ) {
113113
auto* ttf = static_cast<FontTrueType*>( font );
114-
if ( ttf->getInfo().fontpath + ttf->getInfo().filename == desc.path )
114+
if ( ttf->getInfo().fontpath + ttf->getInfo().filename == desc.path &&
115+
ttf->getFaceIndex() == desc.faceIndex )
115116
return ttf;
116117
}
117118
}

0 commit comments

Comments
 (0)