From cdfb1f724b49aeff416fb9f108d6a643e6d98559 Mon Sep 17 00:00:00 2001 From: AD Simmons <30960626+MixedMatched@users.noreply.github.com> Date: Sun, 29 Dec 2019 16:24:23 -0500 Subject: [PATCH] [apps/code] Add PythonFont preferences as the python font size in code --- apps/code/console_controller.cpp | 3 ++- apps/code/console_controller.h | 2 +- apps/code/console_edit_cell.cpp | 4 ++-- apps/code/console_edit_cell.h | 1 + apps/code/console_line_cell.cpp | 9 +++++---- apps/code/editor_view.cpp | 14 ++++++-------- apps/code/editor_view.h | 1 - 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apps/code/console_controller.cpp b/apps/code/console_controller.cpp index c3e0a0cb1..9cd6b1f86 100644 --- a/apps/code/console_controller.cpp +++ b/apps/code/console_controller.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "../apps_container.h" extern "C" { @@ -27,7 +28,7 @@ ConsoleController::ConsoleController(Responder * parentResponder, App * pythonDe TextFieldDelegate(), MicroPython::ExecutionEnvironment(), m_pythonDelegate(pythonDelegate), - m_rowHeight(k_font->glyphSize().height()), + m_rowHeight(Poincare::Preferences::sharedPreferences()->KDPythonFont()->glyphSize().height()), m_importScriptsWhenViewAppears(false), m_selectableTableView(this, this, this, this), m_editCell(this, pythonDelegate, this), diff --git a/apps/code/console_controller.h b/apps/code/console_controller.h index 1c32f4f04..5775744c3 100644 --- a/apps/code/console_controller.h +++ b/apps/code/console_controller.h @@ -3,6 +3,7 @@ #include #include +#include #include "console_edit_cell.h" #include "console_line_cell.h" @@ -16,7 +17,6 @@ class App; class ConsoleController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource, public SelectableTableViewDelegate, public TextFieldDelegate, public MicroPython::ExecutionEnvironment { public: - static constexpr const KDFont * k_font = KDFont::LargeFont; ConsoleController(Responder * parentResponder, App * pythonDelegate, ScriptStore * scriptStore #if EPSILON_GETOPT diff --git a/apps/code/console_edit_cell.cpp b/apps/code/console_edit_cell.cpp index e2472d8fe..9eb431206 100644 --- a/apps/code/console_edit_cell.cpp +++ b/apps/code/console_edit_cell.cpp @@ -9,8 +9,8 @@ namespace Code { ConsoleEditCell::ConsoleEditCell(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, TextFieldDelegate * delegate) : HighlightCell(), Responder(parentResponder), - m_promptView(ConsoleController::k_font, nullptr, 0, 0.5), - m_textField(this, nullptr, TextField::maxBufferSize(), TextField::maxBufferSize(), inputEventHandlerDelegate, delegate, ConsoleController::k_font) + m_promptView(Poincare::Preferences::sharedPreferences()->KDPythonFont(), nullptr, 0, 0.5), + m_textField(this, nullptr, TextField::maxBufferSize(), TextField::maxBufferSize(), inputEventHandlerDelegate, delegate, Poincare::Preferences::sharedPreferences()->KDPythonFont()) { } diff --git a/apps/code/console_edit_cell.h b/apps/code/console_edit_cell.h index e98cfba46..378beb8c4 100644 --- a/apps/code/console_edit_cell.h +++ b/apps/code/console_edit_cell.h @@ -6,6 +6,7 @@ #include #include #include +#include namespace Code { diff --git a/apps/code/console_line_cell.cpp b/apps/code/console_line_cell.cpp index 2d9ada321..e24a550c9 100644 --- a/apps/code/console_line_cell.cpp +++ b/apps/code/console_line_cell.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace Code { @@ -18,11 +19,11 @@ void ConsoleLineCell::ScrollableConsoleLineView::ConsoleLineView::setLine(Consol void ConsoleLineCell::ScrollableConsoleLineView::ConsoleLineView::drawRect(KDContext * ctx, KDRect rect) const { ctx->fillRect(bounds(), Palette::CodeBackground); - ctx->drawString(m_line->text(), KDPointZero, ConsoleController::k_font, textColor(m_line), isHighlighted()? Palette::CodeBackgroundSelected : Palette::CodeBackground); + ctx->drawString(m_line->text(), KDPointZero, Poincare::Preferences::sharedPreferences()->KDPythonFont(), textColor(m_line), isHighlighted()? Palette::CodeBackgroundSelected : Palette::CodeBackground); } KDSize ConsoleLineCell::ScrollableConsoleLineView::ConsoleLineView::minimalSizeForOptimalDisplay() const { - return ConsoleController::k_font->stringSize(m_line->text()); + return Poincare::Preferences::sharedPreferences()->KDPythonFont()->stringSize(m_line->text()); } ConsoleLineCell::ScrollableConsoleLineView::ScrollableConsoleLineView(Responder * parentResponder) : @@ -34,7 +35,7 @@ ConsoleLineCell::ScrollableConsoleLineView::ScrollableConsoleLineView(Responder ConsoleLineCell::ConsoleLineCell(Responder * parentResponder) : HighlightCell(), Responder(parentResponder), - m_promptView(ConsoleController::k_font, I18n::Message::ConsolePrompt, 0, 0.5), + m_promptView(Poincare::Preferences::sharedPreferences()->KDPythonFont(), I18n::Message::ConsolePrompt, 0, 0.5), m_scrollableView(this), m_line() { @@ -79,7 +80,7 @@ View * ConsoleLineCell::subviewAtIndex(int index) { void ConsoleLineCell::layoutSubviews() { if (m_line.isCommand()) { - KDSize promptSize = ConsoleController::k_font->stringSize(I18n::translate(I18n::Message::ConsolePrompt)); + KDSize promptSize = Poincare::Preferences::sharedPreferences()->KDPythonFont()->stringSize(I18n::translate(I18n::Message::ConsolePrompt)); m_promptView.setFrame(KDRect(KDPointZero, promptSize.width(), bounds().height())); m_scrollableView.setFrame(KDRect(KDPoint(promptSize.width(), 0), bounds().width() - promptSize.width(), bounds().height())); return; diff --git a/apps/code/editor_view.cpp b/apps/code/editor_view.cpp index 4138b5221..199a66845 100644 --- a/apps/code/editor_view.cpp +++ b/apps/code/editor_view.cpp @@ -1,18 +1,17 @@ #include "editor_view.h" #include #include +#include namespace Code { /* EditorView */ -static constexpr const KDFont * editorFont = KDFont::LargeFont; - EditorView::EditorView(Responder * parentResponder, App * pythonDelegate) : Responder(parentResponder), View(), - m_textArea(parentResponder, pythonDelegate, editorFont), - m_gutterView(editorFont) + m_textArea(parentResponder, pythonDelegate, Poincare::Preferences::sharedPreferences()->KDPythonFont()), + m_gutterView(Poincare::Preferences::sharedPreferences()->KDPythonFont()) { m_textArea.setScrollViewDelegate(this); } @@ -51,7 +50,6 @@ void EditorView::layoutSubviews() { EditorView::GutterView::GutterView(const KDFont * font) : View(), - m_font(font), m_offset(0) { } @@ -62,7 +60,7 @@ void EditorView::GutterView::drawRect(KDContext * ctx, KDRect rect) const { ctx->fillRect(rect, backgroundColor); - KDSize glyphSize = m_font->glyphSize(); + KDSize glyphSize = Poincare::Preferences::sharedPreferences()->KDPythonFont()->glyphSize(); KDCoordinate firstLine = m_offset / glyphSize.height(); KDCoordinate firstLinePixelOffset = m_offset - firstLine * glyphSize.height(); @@ -76,7 +74,7 @@ void EditorView::GutterView::drawRect(KDContext * ctx, KDRect rect) const { ctx->drawString( lineNumber, KDPoint(k_margin + leftPadding, i*glyphSize.height() - firstLinePixelOffset), - m_font, + Poincare::Preferences::sharedPreferences()->KDPythonFont(), textColor, backgroundColor ); @@ -94,7 +92,7 @@ void EditorView::GutterView::setOffset(KDCoordinate offset) { KDSize EditorView::GutterView::minimalSizeForOptimalDisplay() const { int numberOfChars = 2; // TODO: Could be computed - return KDSize(2 * k_margin + numberOfChars * m_font->glyphSize().width(), 0); + return KDSize(2 * k_margin + numberOfChars * Poincare::Preferences::sharedPreferences()->KDPythonFont()->glyphSize().width(), 0); } } diff --git a/apps/code/editor_view.h b/apps/code/editor_view.h index 7e4d85ece..9fb759fca 100644 --- a/apps/code/editor_view.h +++ b/apps/code/editor_view.h @@ -36,7 +36,6 @@ private: KDSize minimalSizeForOptimalDisplay() const override; private: static constexpr KDCoordinate k_margin = 2; - const KDFont * m_font; KDCoordinate m_offset; };