[Table] Focus / selection fixes
This commit is contained in:
+4
-2
@@ -38,10 +38,11 @@ void Table::Body::paint(BitmapBuffer * dc)
|
|||||||
coord_t x;
|
coord_t x;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (auto & line: lines) {
|
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;
|
x = 10;
|
||||||
for (unsigned i = 0; i < line.values.size(); i++) {
|
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];
|
x += columnsWidth[i];
|
||||||
}
|
}
|
||||||
y += TABLE_LINE_HEIGHT;
|
y += TABLE_LINE_HEIGHT;
|
||||||
@@ -54,6 +55,7 @@ bool Table::Body::onTouchEnd(coord_t x, coord_t y)
|
|||||||
{
|
{
|
||||||
unsigned index = y / TABLE_LINE_HEIGHT;
|
unsigned index = y / TABLE_LINE_HEIGHT;
|
||||||
if (index < lines.size()) {
|
if (index < lines.size()) {
|
||||||
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
auto onPress = lines[index].onPress;
|
auto onPress = lines[index].onPress;
|
||||||
if (onPress)
|
if (onPress)
|
||||||
onPress();
|
onPress();
|
||||||
|
|||||||
+4
-4
@@ -20,12 +20,12 @@
|
|||||||
#ifndef _TABLE_H_
|
#ifndef _TABLE_H_
|
||||||
#define _TABLE_H_
|
#define _TABLE_H_
|
||||||
|
|
||||||
#include "window.h"
|
#include "form.h"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "libopenui_config.h"
|
#include "libopenui_config.h"
|
||||||
|
|
||||||
class Table: public Window {
|
class Table: public FormField {
|
||||||
class Line {
|
class Line {
|
||||||
public:
|
public:
|
||||||
explicit Line(uint8_t columnsCount):
|
explicit Line(uint8_t columnsCount):
|
||||||
@@ -135,7 +135,7 @@ class Table: public Window {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Table(Window * parent, const rect_t & rect, uint8_t columnsCount, WindowFlags windowFlags = OPAQUE):
|
Table(Window * parent, const rect_t & rect, uint8_t columnsCount, WindowFlags windowFlags = OPAQUE):
|
||||||
Window(parent, rect),
|
FormField(parent, rect),
|
||||||
columnsCount(columnsCount),
|
columnsCount(columnsCount),
|
||||||
columnsWidth(columnsCount, width() / columnsCount),
|
columnsWidth(columnsCount, width() / columnsCount),
|
||||||
header(this, {0, 0, width(), 0}, columnsCount),
|
header(this, {0, 0, width(), 0}, columnsCount),
|
||||||
@@ -218,7 +218,7 @@ class Table: public Window {
|
|||||||
clearSelection();
|
clearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t size()
|
uint8_t size() const
|
||||||
{
|
{
|
||||||
return body.lines.size();
|
return body.lines.size();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user