[Table] Focus / selection fixes

This commit is contained in:
Bertrand Songis
2020-09-11 13:53:21 +02:00
parent a54da93207
commit 8b6ce1e13c
2 changed files with 8 additions and 6 deletions
+4 -2
View File
@@ -38,10 +38,11 @@ void Table::Body::paint(BitmapBuffer * dc)
coord_t x;
int index = 0;
for (auto & line: lines) {
dc->drawSolidFilledRect(0, y, width(), TABLE_LINE_HEIGHT - 2, index == selection ? MENU_HIGHLIGHT_BGCOLOR : TABLE_BGCOLOR);
bool highlight = hasFocus() && index == selection;
dc->drawSolidFilledRect(0, y, width(), TABLE_LINE_HEIGHT - 2, highlight ? MENU_HIGHLIGHT_BGCOLOR : TABLE_BGCOLOR);
x = 10;
for (unsigned i = 0; i < line.values.size(); i++) {
dc->drawText(x, y + (TABLE_LINE_HEIGHT - getFontHeight(TABLE_BODY_FONT)) / 2 + 3, line.values[i].c_str(), line.flags | (index == selection ? MENU_HIGHLIGHT_COLOR : DEFAULT_COLOR));
dc->drawText(x, y + (TABLE_LINE_HEIGHT - getFontHeight(TABLE_BODY_FONT)) / 2 + 3, line.values[i].c_str(), line.flags | (highlight ? MENU_HIGHLIGHT_COLOR : DEFAULT_COLOR));
x += columnsWidth[i];
}
y += TABLE_LINE_HEIGHT;
@@ -54,6 +55,7 @@ bool Table::Body::onTouchEnd(coord_t x, coord_t y)
{
unsigned index = y / TABLE_LINE_HEIGHT;
if (index < lines.size()) {
setFocus(SET_FOCUS_DEFAULT);
auto onPress = lines[index].onPress;
if (onPress)
onPress();
+4 -4
View File
@@ -20,12 +20,12 @@
#ifndef _TABLE_H_
#define _TABLE_H_
#include "window.h"
#include "form.h"
#include <utility>
#include <vector>
#include "libopenui_config.h"
class Table: public Window {
class Table: public FormField {
class Line {
public:
explicit Line(uint8_t columnsCount):
@@ -135,7 +135,7 @@ class Table: public Window {
public:
Table(Window * parent, const rect_t & rect, uint8_t columnsCount, WindowFlags windowFlags = OPAQUE):
Window(parent, rect),
FormField(parent, rect),
columnsCount(columnsCount),
columnsWidth(columnsCount, width() / columnsCount),
header(this, {0, 0, width(), 0}, columnsCount),
@@ -218,7 +218,7 @@ class Table: public Window {
clearSelection();
}
uint8_t size()
uint8_t size() const
{
return body.lines.size();
}