Add the possibility to the screen to handle a touch gesture.

A default action is taken if the current screen doesn't handle it.
This commit is contained in:
JF
2020-03-15 21:01:24 +01:00
parent 2c55ab20b4
commit 8ed6ffaaf8
7 changed files with 61 additions and 25 deletions

View File

@@ -70,3 +70,23 @@ uint8_t Brightness::LevelToInt(Pinetime::Controllers::BrightnessController::Leve
default : return 0;
}
}
bool Brightness::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
switch(event) {
case TouchEvents::SwipeLeft:
brightness.Lower();
SetValue();
return true;
case TouchEvents::SwipeRight:
brightness.Higher();
SetValue();
return true;
default:
return false;
}
}
void Brightness::SetValue() {
lv_slider_set_value(slider, LevelToInt(brightness.Level()), LV_ANIM_OFF);
lv_label_set_text(slider_label, LevelToString(brightness.Level()));
}

View File

@@ -13,6 +13,7 @@ namespace Pinetime {
~Brightness() override;
bool Refresh() override;
bool OnButtonPushed() override;
bool OnTouchEvent(TouchEvents event) override;
void OnValueChanged();
private:
@@ -25,6 +26,7 @@ namespace Pinetime {
const char* LevelToString(Controllers::BrightnessController::Levels level);
uint8_t LevelToInt(Controllers::BrightnessController::Levels level);
void SetValue(uint8_t value);
void SetValue();
};
}
}

View File

@@ -1,4 +1,5 @@
#pragma once
#include "../TouchEvents.h"
namespace Pinetime {
namespace Applications {
@@ -15,6 +16,9 @@ namespace Pinetime {
// Return false if the button hasn't been handled by the app, true if it has been handled
virtual bool OnButtonPushed() { return false; }
// Return false if the event hasn't been handled by the app, true if it has been handled
virtual bool OnTouchEvent(TouchEvents event) { return false; }
protected:
DisplayApp* app;
};