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