From 2015bcce89ce09d8c72763dc748cc8beb0ccbc85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 24 Nov 2017 15:49:25 +0100 Subject: [PATCH] [code] Created DoubleBufferTextView for functions/variables toolbox. Change-Id: I8fb8d12463de44f244230eca36d4b0404343f57d --- apps/code/Makefile | 1 + apps/code/double_buffer_text_cell.cpp | 53 +++++++++++++++++++++++++++ apps/code/double_buffer_text_cell.h | 33 +++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 apps/code/double_buffer_text_cell.cpp create mode 100644 apps/code/double_buffer_text_cell.h diff --git a/apps/code/Makefile b/apps/code/Makefile index 1618dd63d..a01d3f7c6 100644 --- a/apps/code/Makefile +++ b/apps/code/Makefile @@ -8,6 +8,7 @@ app_objs += $(addprefix apps/code/,\ console_edit_cell.o\ console_line_cell.o\ console_store.o\ + double_buffer_text_cell.o\ editor_controller.o\ helpers.o\ menu_controller.o\ diff --git a/apps/code/double_buffer_text_cell.cpp b/apps/code/double_buffer_text_cell.cpp new file mode 100644 index 000000000..c3037cb88 --- /dev/null +++ b/apps/code/double_buffer_text_cell.cpp @@ -0,0 +1,53 @@ +#include "double_buffer_text_cell.h" +#include +#include + +DoubleBufferTextCell::DoubleBufferTextCell(KDText::FontSize size, float horizontalAlignment, float verticalAlignment) : + TableCell(TableCell::Layout::Vertical), + m_firstBufferTextView(size, horizontalAlignment, verticalAlignment), + m_secondBufferTextView(size, horizontalAlignment, verticalAlignment) +{ +} + +const char * DoubleBufferTextCell::firstText() { + return m_firstBufferTextView.text(); +} + +const char * DoubleBufferTextCell::secondText() { + return m_secondBufferTextView.text(); +} + +void DoubleBufferTextCell::setFirstText(const char * textContent) { + m_firstBufferTextView.setText(textContent); +} + +void DoubleBufferTextCell::setSecondText(const char * textContent) { + m_secondBufferTextView.setText(textContent); +} + +void DoubleBufferTextCell::setFirstTextColor(KDColor textColor) { + m_firstBufferTextView.setTextColor(textColor); +} + +void DoubleBufferTextCell::setSecondTextColor(KDColor textColor) { + m_secondBufferTextView.setTextColor(textColor); +} + +void DoubleBufferTextCell::setHighlighted(bool highlight) { + HighlightCell::setHighlighted(highlight); + KDColor background = isHighlighted() ? Palette::Select : KDColorWhite; + m_firstBufferTextView.setBackgroundColor(background); + m_secondBufferTextView.setBackgroundColor(background); +} + +View * DoubleBufferTextCell::subviewAtIndex(int index) { + assert(index >= 0 && index <= 1); + if (index == 0) { + return &m_firstBufferTextView; + } + return &m_secondBufferTextView; +} + +void DoubleBufferTextCell::layoutSubviews() { + TableCell::layoutSubviews(); +} diff --git a/apps/code/double_buffer_text_cell.h b/apps/code/double_buffer_text_cell.h new file mode 100644 index 000000000..280a455da --- /dev/null +++ b/apps/code/double_buffer_text_cell.h @@ -0,0 +1,33 @@ +#ifndef CODE_DOUBLE_BUFFER_TEXT_CELL_H +#define CODE_DOUBLE_BUFFER_TEXT_CELL_H + +#include +#include + +class DoubleBufferTextCell : public TableCell { +public: + DoubleBufferTextCell(KDText::FontSize size = KDText::FontSize::Small, float horizontalAlignment = 0.0f, float verticalAlignment = 0.5f); + const char * firstText(); + const char * secondText(); + void setFirstText(const char * textContent); + void setSecondText(const char * textContent); + void setFirstTextColor(KDColor textColor); + void setSecondTextColor(KDColor textColor); + + /* TableCell */ + View * labelView() const override { return const_cast(static_cast(&m_firstBufferTextView)); } + View * accessoryView() const override { return const_cast(static_cast(&m_secondBufferTextView)); } + + /* HighlightCell */ + void setHighlighted(bool highlight) override; + + /* View */ + int numberOfSubviews() const override { return 2; } + View * subviewAtIndex(int index) override; + void layoutSubviews() override; +protected: + BufferTextView m_firstBufferTextView; + BufferTextView m_secondBufferTextView; +}; + +#endif