Set up monospaced font in text editor, use it for art
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
f80cf75e30
commit
2e4fb8975e
4 changed files with 61 additions and 18 deletions
|
|
@ -38,7 +38,10 @@ struct ImGuiTextEditor::PrivateData {
|
||||||
|
|
||||||
ImGuiTextEditor::ImGuiTextEditor()
|
ImGuiTextEditor::ImGuiTextEditor()
|
||||||
: ImGuiWidget(),
|
: ImGuiWidget(),
|
||||||
pData(new PrivateData) {}
|
pData(new PrivateData())
|
||||||
|
{
|
||||||
|
setUseMonospaceFont();
|
||||||
|
}
|
||||||
|
|
||||||
ImGuiTextEditor::~ImGuiTextEditor()
|
ImGuiTextEditor::~ImGuiTextEditor()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ struct ImGuiWidget::PrivateData {
|
||||||
ImGuiContext* context = nullptr;
|
ImGuiContext* context = nullptr;
|
||||||
bool created = false;
|
bool created = false;
|
||||||
bool fontGenerated = false;
|
bool fontGenerated = false;
|
||||||
|
bool useMonospacedFont = false;
|
||||||
float originalScaleFactor = 0.0f;
|
float originalScaleFactor = 0.0f;
|
||||||
float scaleFactor = 0.0f;
|
float scaleFactor = 0.0f;
|
||||||
|
|
||||||
|
|
@ -86,8 +87,21 @@ struct ImGuiWidget::PrivateData {
|
||||||
|
|
||||||
fontGenerated = true;
|
fontGenerated = true;
|
||||||
|
|
||||||
#ifndef DGL_NO_SHARED_RESOURCES
|
|
||||||
ImGuiIO& io(ImGui::GetIO());
|
ImGuiIO& io(ImGui::GetIO());
|
||||||
|
|
||||||
|
if (useMonospacedFont)
|
||||||
|
{
|
||||||
|
const std::string fontPath = asset::system("fonts/ShareTechMono-Regular.ttf");
|
||||||
|
ImFontConfig fc;
|
||||||
|
fc.OversampleH = 1;
|
||||||
|
fc.OversampleV = 1;
|
||||||
|
fc.PixelSnapH = true;
|
||||||
|
io.Fonts->AddFontFromFileTTF(fontPath.c_str(), 13.0f * scaleFactor, &fc);
|
||||||
|
io.Fonts->Build();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifndef DGL_NO_SHARED_RESOURCES
|
||||||
using namespace dpf_resources;
|
using namespace dpf_resources;
|
||||||
ImFontConfig fc;
|
ImFontConfig fc;
|
||||||
fc.FontDataOwnedByAtlas = false;
|
fc.FontDataOwnedByAtlas = false;
|
||||||
|
|
@ -98,6 +112,7 @@ struct ImGuiWidget::PrivateData {
|
||||||
io.Fonts->Build();
|
io.Fonts->Build();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void resetStyle()
|
void resetStyle()
|
||||||
{
|
{
|
||||||
|
|
@ -170,6 +185,13 @@ void ImGuiWidget::setAsCurrentContext()
|
||||||
ImGui::SetCurrentContext(imData->context);
|
ImGui::SetCurrentContext(imData->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImGuiWidget::setUseMonospaceFont(const bool useMonoFont)
|
||||||
|
{
|
||||||
|
DISTRHO_SAFE_ASSERT_RETURN(!imData->fontGenerated,);
|
||||||
|
|
||||||
|
imData->useMonospacedFont = useMonoFont;
|
||||||
|
}
|
||||||
|
|
||||||
void ImGuiWidget::onHover(const HoverEvent& e)
|
void ImGuiWidget::onHover(const HoverEvent& e)
|
||||||
{
|
{
|
||||||
ImGui::SetCurrentContext(imData->context);
|
ImGui::SetCurrentContext(imData->context);
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ protected:
|
||||||
void onSelectKey(const SelectKeyEvent& e) override;
|
void onSelectKey(const SelectKeyEvent& e) override;
|
||||||
void onSelectText(const SelectTextEvent& e) override;
|
void onSelectText(const SelectTextEvent& e) override;
|
||||||
void setAsCurrentContext();
|
void setAsCurrentContext();
|
||||||
|
void setUseMonospaceFont(bool useMonoFont = true);
|
||||||
|
|
||||||
virtual void drawImGui()
|
virtual void drawImGui()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,31 @@
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// defaults
|
// defaults (artwork based on content from https://www.asciiart.eu/animals/cats)
|
||||||
#define DEFAULT_LANG "C++"
|
#define DEFAULT_LANG "None"
|
||||||
#define DEFAULT_TEXT "" \
|
#define DEFAULT_TEXT "" \
|
||||||
"// Welcome to a real text editor inside Cardinal\n\n" \
|
" \n" \
|
||||||
"#define I_AM_A_MACRO\n\n" \
|
" ^ ^ ,_, \n" \
|
||||||
"int and_i_am_a_variable;\n\n" \
|
" (O,O) (.,.) \n" \
|
||||||
"/* look ma, a comment! */\n" \
|
" ( ) ( ) \n" \
|
||||||
"int such_highlight_much_wow() { return 1337; }\n"
|
"--------\"-\"---dwb--\"-\"---dwb- \n" \
|
||||||
|
" \n" \
|
||||||
|
" \n" \
|
||||||
|
" \n" \
|
||||||
|
" \n" \
|
||||||
|
" \n" \
|
||||||
|
" \n" \
|
||||||
|
" \n" \
|
||||||
|
" /^--^\\ /^--^\\ /^--^\\ \n" \
|
||||||
|
" \\____/ \\____/ \\____/ \n" \
|
||||||
|
" / \\ / \\ / \\ \n" \
|
||||||
|
" | | | | | | \n" \
|
||||||
|
" \\__ __/ \\__ __/ \\__ __/ \n" \
|
||||||
|
"|^|^|^|^\\ \\^|^|^|^/ /^|^|^|^|^\\ \\^|^|^|^|^|^|^|^|^|\n" \
|
||||||
|
"| | | | |\\ \\| | |/ /| | | | | |\\ \\| | | | | | | | |\n" \
|
||||||
|
"#########/ /#####\\ \\###########/ /#################\n" \
|
||||||
|
"| | | | |\\/ | | | \\/| | | | | |\\/ | | | | | | | | |\n" \
|
||||||
|
"|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n"
|
||||||
#define DEFAULT_WIDTH 30
|
#define DEFAULT_WIDTH 30
|
||||||
|
|
||||||
struct TextEditorModule : Module {
|
struct TextEditorModule : Module {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue