diff --git a/apps/graph/list/storage_list_controller.cpp b/apps/graph/list/storage_list_controller.cpp index 982990742..87c7771f8 100644 --- a/apps/graph/list/storage_list_controller.cpp +++ b/apps/graph/list/storage_list_controller.cpp @@ -31,7 +31,7 @@ int StorageListController::maxNumberOfRows() { return k_maxNumberOfRows; } -HighlightCell * StorageListController::titleCells(int index) { +FunctionTitleCell * StorageListController::titleCells(int index) { assert(index >= 0 && index < k_maxNumberOfRows); return &m_functionTitleCells[index]; } diff --git a/apps/graph/list/storage_list_controller.h b/apps/graph/list/storage_list_controller.h index 299fee084..bf0efd981 100644 --- a/apps/graph/list/storage_list_controller.h +++ b/apps/graph/list/storage_list_controller.h @@ -17,7 +17,7 @@ public: private: Shared::StorageListParameterController * parameterController() override; int maxNumberOfRows() override; - HighlightCell * titleCells(int index) override; + Shared::FunctionTitleCell * titleCells(int index) override; HighlightCell * expressionCells(int index) override; void willDisplayTitleCellAtIndex(HighlightCell * cell, int j) override; void willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) override; diff --git a/apps/sequence/list/list_controller.h b/apps/sequence/list/list_controller.h index 6fc4c675e..3857a0723 100644 --- a/apps/sequence/list/list_controller.h +++ b/apps/sequence/list/list_controller.h @@ -32,7 +32,7 @@ private: Shared::ExpressionFieldDelegateApp * expressionFieldDelegateApp() override; ListParameterController * parameterController() override; int maxNumberOfRows() override; - HighlightCell * titleCells(int index) override; + Shared::FunctionTitleCell * titleCells(int index) override; HighlightCell * expressionCells(int index) override; void willDisplayTitleCellAtIndex(HighlightCell * cell, int j) override; void willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) override; diff --git a/apps/shared/buffer_function_title_cell.h b/apps/shared/buffer_function_title_cell.h index c2f8a8b15..fe4718781 100644 --- a/apps/shared/buffer_function_title_cell.h +++ b/apps/shared/buffer_function_title_cell.h @@ -13,6 +13,7 @@ public: void setColor(KDColor color) override; void setText(const char * textContent); void setFont(const KDFont * font) { m_bufferTextView.setFont(font); } + KDFont * font() const override { return m_bufferTextView.font(); } const char * text() const override { return m_bufferTextView.text(); } diff --git a/apps/shared/function_title_cell.h b/apps/shared/function_title_cell.h index e9723a050..4af9fd8f9 100644 --- a/apps/shared/function_title_cell.h +++ b/apps/shared/function_title_cell.h @@ -15,6 +15,7 @@ public: void setOrientation(Orientation orientation); virtual void setColor(KDColor color); void drawRect(KDContext * ctx, KDRect rect) const override; + virtual KDText::FontSize fontSize() const = 0; protected: constexpr static KDCoordinate k_separatorThickness = 1; constexpr static KDCoordinate k_colorIndicatorThickness = 2; diff --git a/apps/shared/storage_function_list_controller.h b/apps/shared/storage_function_list_controller.h index 256c67b72..59c076c1f 100644 --- a/apps/shared/storage_function_list_controller.h +++ b/apps/shared/storage_function_list_controller.h @@ -2,6 +2,7 @@ #define SHARED_STORAGE_FUNCTION_LIST_CONTROLLER_H #include +#include "function_title_cell.h" #include "storage_function_store.h" #include "function_app.h" #include "storage_list_parameter_controller.h" @@ -43,12 +44,27 @@ public: KDCoordinate rowHeight(int j) override { return this->expressionRowHeight(j); } + + KDCoordinate maxDiplayedFunctionNameWidth() { + KDCoordinate columnWidth = k_minNameColumnWidth; + int firstDisplayedIndex = m_selectableTableView.firstDisplayedRowIndex(); + int lastDisplayedIndex = firstDisplayedIndex+m_selectableTableView.numberOfDisplayableRows(); + for (int i = firstDisplayedIndex; i < lastDisplayedIndex; i++) { + const char * currentName = titleCells(i)->text(); + KDText::FontSize fontSize = titleCells(i)->fontSize(); + KDCoordinate currentNameWidth = KDText::stringSize(currentName, fontSize).width(); + columnWidth = columnWidth < currentNameWidth ? currentNameWidth : columnWidth; + } + // TODO What if very big name? + return columnWidth + k_functionNameSumOfMargins; + } + KDCoordinate columnWidth(int i) override { switch (i) { case 0: - return k_functionNameWidth; + return maxDiplayedFunctionNameWidth(); case 1: - return selectableTableView()->bounds().width()-k_functionNameWidth; + return selectableTableView()->bounds().width()-maxDiplayedFunctionNameWidth(); default: assert(false); return 0; @@ -59,7 +75,7 @@ public: case 0: return 0; case 1: - return k_functionNameWidth; + return maxDiplayedFunctionNameWidth(); case 2: return selectableTableView()->bounds().width(); default: @@ -68,7 +84,7 @@ public: } } int indexFromCumulatedWidth(KDCoordinate offsetX) override { - if (offsetX <= k_functionNameWidth) { + if (offsetX <= maxDiplayedFunctionNameWidth()) { return 0; } else { if (offsetX <= selectableTableView()->bounds().width()) @@ -224,7 +240,8 @@ protected: } StorageFunctionStore * m_functionStore; private: - static constexpr KDCoordinate k_functionNameWidth = 65; + static constexpr KDCoordinate k_minNameColumnWidth = 35; + static constexpr KDCoordinate k_functionNameSumOfMargins = 2*Metric::HistoryHorizontalMargin; TabViewController * tabController() const { return (TabViewController *)(this->parentResponder()->parentResponder()->parentResponder()->parentResponder()); } @@ -235,7 +252,7 @@ private: } virtual StorageListParameterController * parameterController() = 0; virtual int maxNumberOfRows() = 0; - virtual HighlightCell * titleCells(int index) = 0; + virtual FunctionTitleCell * titleCells(int index) = 0; virtual HighlightCell * expressionCells(int index) = 0; virtual void willDisplayTitleCellAtIndex(HighlightCell * cell, int j) = 0; SelectableTableView m_selectableTableView; diff --git a/escher/include/escher/even_odd_buffer_text_cell.h b/escher/include/escher/even_odd_buffer_text_cell.h index c4410494c..3fb1636b7 100644 --- a/escher/include/escher/even_odd_buffer_text_cell.h +++ b/escher/include/escher/even_odd_buffer_text_cell.h @@ -11,6 +11,9 @@ public: void setFont(const KDFont * font) { m_bufferTextView.setFont(font); } + KDText::FontSize fontSize() const { + return m_bufferTextView.fontSize(); + } void setAlignment(float horizontalAlignment, float verticalAlignment) { m_bufferTextView.setAlignment(horizontalAlignment, verticalAlignment); } @@ -21,7 +24,8 @@ public: protected: int numberOfSubviews() const override; View * subviewAtIndex(int index) override; - void layoutSubviews() override; BufferTextView m_bufferTextView; + void layoutSubviews() override; + BufferTextView m_bufferTextView; }; #endif diff --git a/escher/include/escher/table_view.h b/escher/include/escher/table_view.h index 31f8ae195..b67868cae 100644 --- a/escher/include/escher/table_view.h +++ b/escher/include/escher/table_view.h @@ -12,6 +12,10 @@ public: void setHorizontalCellOverlap(KDCoordinate o) { m_contentView.setHorizontalCellOverlap(o); } void setVerticalCellOverlap(KDCoordinate o) { m_contentView.setVerticalCellOverlap(o); } + int firstDisplayedRowIndex() const { return m_contentView.rowsScrollingOffset(); } + int firstDisplayedColumnIndex() const { return m_contentView.columnsScrollingOffset(); } + int numberOfDisplayableRows() const { return m_contentView.numberOfDisplayableRows(); } + int numberOfDisplayableColumns() const { return m_contentView.numberOfDisplayableColumns(); } virtual void scrollToCell(int i, int j); HighlightCell * cellAtLocation(int i, int j); @@ -36,6 +40,10 @@ protected: HighlightCell * cellAtLocation(int i, int j); void resizeToFitContent(); TableViewDataSource * dataSource(); + int rowsScrollingOffset() const; + int columnsScrollingOffset() const; + int numberOfDisplayableRows() const; + int numberOfDisplayableColumns() const; protected: #if ESCHER_VIEW_LOGGING const char * className() const override; @@ -57,10 +65,6 @@ protected: int absoluteRowNumberFromSubviewIndex(int index) const; int numberOfFullyDisplayableRows() const; int numberOfFullyDisplayableColumns() const; - int numberOfDisplayableRows() const; - int numberOfDisplayableColumns() const; - int rowsScrollingOffset() const; - int columnsScrollingOffset() const; int typeOfSubviewAtIndex(int index) const; /* This method transform a index (of subview for instance) into an index * refering to the set of cells of type "type". */ diff --git a/escher/include/escher/text_view.h b/escher/include/escher/text_view.h index e252a9360..c57b5ca65 100644 --- a/escher/include/escher/text_view.h +++ b/escher/include/escher/text_view.h @@ -18,6 +18,7 @@ public: KDSize minimalSizeForOptimalDisplay() const override; virtual const char * text() const = 0; virtual void setText(const char * text) = 0; + KDFont * font() const { return m_font; } void setFont(const KDFont * font); protected: #if ESCHER_VIEW_LOGGING