Skip to content

Commit

Permalink
#71
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 12, 2020
1 parent 413fb45 commit cfd070b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
20 changes: 4 additions & 16 deletions src/eez/gui/widgets/display_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ struct DisplayDataState {
uint16_t activeBackgroundColor;
uint32_t dataRefreshLastTime;
int16_t cursorPosition;
uint32_t cursorBlinkStartTime;
uint8_t cursorVisible;
uint8_t xScroll;
};

Expand Down Expand Up @@ -87,7 +85,7 @@ DrawFunctionType DISPLAY_DATA_draw = [](const WidgetCursor &widgetCursor) {

uint32_t currentTime = millis();
widgetCursor.currentState->data = get(widgetCursor.cursor, widget->data);
bool refreshData;
bool refreshData = false;
if (widgetCursor.previousState) {
refreshData = widgetCursor.currentState->data != widgetCursor.previousState->data;
if (refreshData) {
Expand All @@ -109,7 +107,8 @@ DrawFunctionType DISPLAY_DATA_draw = [](const WidgetCursor &widgetCursor) {
currentState->activeColor = widgetCursor.currentState->flags.focused ? style->focus_background_color : getActiveColor(widgetCursor.cursor, widget->data, style);
currentState->activeBackgroundColor = widgetCursor.currentState->flags.focused ? style->focus_color : getActiveBackgroundColor(widgetCursor.cursor, widget->data, style);

currentState->cursorPosition = getTextCursorPosition(widgetCursor.cursor, widget->data);
bool cursorVisible = millis() % (2 * CONF_GUI_TEXT_CURSOR_BLINK_TIME_MS) < CONF_GUI_TEXT_CURSOR_BLINK_TIME_MS;
currentState->cursorPosition = cursorVisible ? getTextCursorPosition(widgetCursor.cursor, widget->data) : -1;

currentState->xScroll = getXScroll(widgetCursor);

Expand All @@ -126,17 +125,6 @@ DrawFunctionType DISPLAY_DATA_draw = [](const WidgetCursor &widgetCursor) {
currentState->cursorPosition != previousState->cursorPosition ||
currentState->xScroll != previousState->xScroll;

if (currentState->cursorPosition != -1) {
if (refresh) {
currentState->cursorBlinkStartTime = millis();
currentState->cursorVisible = 1;
} else {
currentState->cursorBlinkStartTime = previousState->cursorBlinkStartTime;
currentState->cursorVisible = (millis() - currentState->cursorBlinkStartTime) % (2 * CONF_GUI_TEXT_CURSOR_BLINK_TIME_MS) < CONF_GUI_TEXT_CURSOR_BLINK_TIME_MS;
refresh = currentState->cursorVisible != previousState->cursorVisible;
}
}

if (refresh) {
char text[64];
widgetCursor.currentState->data.toText(text, sizeof(text));
Expand Down Expand Up @@ -182,7 +170,7 @@ DrawFunctionType DISPLAY_DATA_draw = [](const WidgetCursor &widgetCursor) {
widgetCursor.currentState->flags.blinking, false,
&currentState->color, &currentState->backgroundColor, &currentState->activeColor, &currentState->activeBackgroundColor,
widgetCursor.currentState->data.getType() == VALUE_TYPE_FLOAT,
currentState->cursorVisible ? currentState->cursorPosition : -1, currentState->xScroll);
currentState->cursorPosition, currentState->xScroll);
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/eez/modules/mcu/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include <eez/libs/image/image.h>

static const int CURSOR_WIDTH = 2;

namespace eez {
namespace mcu {
namespace display {
Expand Down
6 changes: 3 additions & 3 deletions src/eez/modules/mcu/simulator/display.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* EEZ Modular Firmware
* Copyright (C) 2015-present, Envox d.o.o.
*
Expand Down Expand Up @@ -658,8 +658,8 @@ void drawStr(const char *text, int textLength, int x, int y, int clip_x1, int cl
}

if (cursorPosition != -1) {
drawVLine(xCursor, clip_y1 + 1, clip_y2 - clip_y1 - 2);
drawVLine(xCursor + 1, clip_y1 + 1, clip_y2 - clip_y1 - 2);
auto d = MAX(((clip_y2 - clip_y1) - font.getHeight()) / 2, 0);
fillRect(xCursor - CURSOR_WIDTH / 2, clip_y1 + d, xCursor + CURSOR_WIDTH / 2 - 1, clip_y2 - d);
}

markDirty(clip_x1, clip_y1, clip_x2, clip_y2);
Expand Down
4 changes: 2 additions & 2 deletions src/eez/modules/mcu/stm32/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,8 @@ void drawStr(const char *text, int textLength, int x, int y, int clip_x1, int cl
}

if (cursorPosition != -1) {
drawVLine(xCursor, clip_y1 + 1, clip_y2 - clip_y1 - 2);
drawVLine(xCursor + 1, clip_y1 + 1, clip_y2 - clip_y1 - 2);
auto d = MAX(((clip_y2 - clip_y1) - font.getHeight()) / 2, 0);
fillRect(xCursor - CURSOR_WIDTH / 2, clip_y1 + d, xCursor + CURSOR_WIDTH / 2 - 1, clip_y2 - d);
}

markDirty(clip_x1, clip_y1, clip_x2, clip_y2);
Expand Down
15 changes: 11 additions & 4 deletions src/eez/modules/psu/gui/keypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void onKeypadTextTouch(const WidgetCursor &widgetCursor, Event &touchEvent) {
}

Keypad *keypad = getActiveKeypad();
if (keypad) {
if (keypad && keypad != getActiveNumericKeypad()) {
keypad->setCursorPosition(DISPLAY_DATA_getCharIndexAtPosition(touchEvent.x, widgetCursor));
}
}
Expand Down Expand Up @@ -305,9 +305,7 @@ int Keypad::getXScroll(const WidgetCursor &widgetCursor) {

x -= widgetCursor.x;

static const int CURSOR_WIDTH = 2;

if (x < m_xScroll) {
if (x < m_xScroll + widgetCursor.widget->w / 4) {
m_xScroll = MAX(x - widgetCursor.widget->w / 2, 0);
} else if (m_xScroll + widgetCursor.widget->w < x + CURSOR_WIDTH) {
m_xScroll = x + CURSOR_WIDTH - widgetCursor.widget->w;
Expand Down Expand Up @@ -468,6 +466,7 @@ char NumericKeypad::getDotSign() {
}

void NumericKeypad::appendEditUnit(char *text) {
strcat(text, " ");
strcat(text, getUnitName(m_options.editValueUnit));
}

Expand Down Expand Up @@ -704,6 +703,14 @@ void NumericKeypad::toggleEditUnit() {
m_options.editValueUnit = getSwitchToUnit();
}

int NumericKeypad::getCursorPostion() {
if (m_state == START) {
return -1;
}

return Keypad::getCursorPostion();
}

////////////////////////////////////////////////////////////////////////////////

double NumericKeypad::getValue() {
Expand Down
4 changes: 3 additions & 1 deletion src/eez/modules/psu/gui/keypad.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Keypad : public Page {

KeypadMode m_keypadMode;

int getCursorPostion();
virtual int getCursorPostion();
void setCursorPosition(int cursorPosition);

int getXScroll(const WidgetCursor &widgetCursor);
Expand Down Expand Up @@ -228,6 +228,8 @@ class NumericKeypad : public Keypad {

Unit getSwitchToUnit();

virtual int getCursorPostion() override;

NumericKeypadOptions m_options;

private:
Expand Down

0 comments on commit cfd070b

Please sign in to comment.