C++ apps: templated scene controller (#517)
* C++ apps: templated scene controller * templated app: fix type names * templated app: text store component * Applications: add "Templated Scene" application * templated app: refractoring * Gui module byte input: fix docs * templated app: new byte input scene * templated app: dialog ex view module * templated app: popup view module * templated app: dialog-ex view module, fix docs * templated app: text input view module * Gui module text input: fix docs * Furi: duplicated include * templated app: record holder (controller) class * templated app: view modules can now be accessed via cast * templated app: remove unused includes * templated app: fix return code
This commit is contained in:
32
lib/app-scened-template/view-modules/byte-input-vm.cpp
Normal file
32
lib/app-scened-template/view-modules/byte-input-vm.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "byte-input-vm.h"
|
||||
|
||||
ByteInputVM::ByteInputVM() {
|
||||
byte_input = byte_input_alloc();
|
||||
}
|
||||
|
||||
ByteInputVM::~ByteInputVM() {
|
||||
byte_input_free(byte_input);
|
||||
}
|
||||
|
||||
View* ByteInputVM::get_view() {
|
||||
return byte_input_get_view(byte_input);
|
||||
}
|
||||
|
||||
void ByteInputVM::clean() {
|
||||
byte_input_set_header_text(byte_input, "");
|
||||
byte_input_set_result_callback(byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
void ByteInputVM::set_result_callback(
|
||||
ByteInputCallback input_callback,
|
||||
ByteChangedCallback changed_callback,
|
||||
void* callback_context,
|
||||
uint8_t* bytes,
|
||||
uint8_t bytes_count) {
|
||||
byte_input_set_result_callback(
|
||||
byte_input, input_callback, changed_callback, callback_context, bytes, bytes_count);
|
||||
}
|
||||
|
||||
void ByteInputVM::set_header_text(const char* text) {
|
||||
byte_input_set_header_text(byte_input, text);
|
||||
}
|
37
lib/app-scened-template/view-modules/byte-input-vm.h
Normal file
37
lib/app-scened-template/view-modules/byte-input-vm.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include "generic-view-module.h"
|
||||
#include <gui/modules/byte_input.h>
|
||||
|
||||
class ByteInputVM : public GenericViewModule {
|
||||
public:
|
||||
ByteInputVM();
|
||||
~ByteInputVM() final;
|
||||
View* get_view() final;
|
||||
void clean() final;
|
||||
|
||||
/**
|
||||
* @brief Set byte input result callback
|
||||
*
|
||||
* @param input_callback input callback fn
|
||||
* @param changed_callback changed callback fn
|
||||
* @param callback_context callback context
|
||||
* @param bytes buffer to use
|
||||
* @param bytes_count buffer length
|
||||
*/
|
||||
void set_result_callback(
|
||||
ByteInputCallback input_callback,
|
||||
ByteChangedCallback changed_callback,
|
||||
void* callback_context,
|
||||
uint8_t* bytes,
|
||||
uint8_t bytes_count);
|
||||
|
||||
/**
|
||||
* @brief Set byte input header text
|
||||
*
|
||||
* @param text text to be shown
|
||||
*/
|
||||
void set_header_text(const char* text);
|
||||
|
||||
private:
|
||||
ByteInput* byte_input;
|
||||
};
|
61
lib/app-scened-template/view-modules/dialog-ex-vm.cpp
Normal file
61
lib/app-scened-template/view-modules/dialog-ex-vm.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "dialog-ex-vm.h"
|
||||
|
||||
DialogExVM::DialogExVM() {
|
||||
dialog_ex = dialog_ex_alloc();
|
||||
}
|
||||
|
||||
DialogExVM::~DialogExVM() {
|
||||
dialog_ex_free(dialog_ex);
|
||||
}
|
||||
|
||||
View* DialogExVM::get_view() {
|
||||
return dialog_ex_get_view(dialog_ex);
|
||||
}
|
||||
|
||||
void DialogExVM::clean() {
|
||||
set_result_callback(NULL);
|
||||
set_context(NULL);
|
||||
set_header(NULL, 0, 0, AlignLeft, AlignBottom);
|
||||
set_text(NULL, 0, 0, AlignLeft, AlignBottom);
|
||||
set_icon(-1, -1, I_ButtonCenter_7x7);
|
||||
set_left_button_text(NULL);
|
||||
set_center_button_text(NULL);
|
||||
set_right_button_text(NULL);
|
||||
}
|
||||
|
||||
void DialogExVM::set_result_callback(DialogExResultCallback callback) {
|
||||
dialog_ex_set_result_callback(dialog_ex, callback);
|
||||
}
|
||||
|
||||
void DialogExVM::set_context(void* context) {
|
||||
dialog_ex_set_context(dialog_ex, context);
|
||||
}
|
||||
|
||||
void DialogExVM::set_header(
|
||||
const char* text,
|
||||
uint8_t x,
|
||||
uint8_t y,
|
||||
Align horizontal,
|
||||
Align vertical) {
|
||||
dialog_ex_set_header(dialog_ex, text, x, y, horizontal, vertical);
|
||||
}
|
||||
|
||||
void DialogExVM::set_text(const char* text, uint8_t x, uint8_t y, Align horizontal, Align vertical) {
|
||||
dialog_ex_set_text(dialog_ex, text, x, y, horizontal, vertical);
|
||||
}
|
||||
|
||||
void DialogExVM::set_icon(int8_t x, int8_t y, IconName name) {
|
||||
dialog_ex_set_icon(dialog_ex, x, y, name);
|
||||
}
|
||||
|
||||
void DialogExVM::set_left_button_text(const char* text) {
|
||||
dialog_ex_set_left_button_text(dialog_ex, text);
|
||||
}
|
||||
|
||||
void DialogExVM::set_center_button_text(const char* text) {
|
||||
dialog_ex_set_center_button_text(dialog_ex, text);
|
||||
}
|
||||
|
||||
void DialogExVM::set_right_button_text(const char* text) {
|
||||
dialog_ex_set_right_button_text(dialog_ex, text);
|
||||
}
|
73
lib/app-scened-template/view-modules/dialog-ex-vm.h
Normal file
73
lib/app-scened-template/view-modules/dialog-ex-vm.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
#include "generic-view-module.h"
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
class DialogExVM : public GenericViewModule {
|
||||
public:
|
||||
DialogExVM();
|
||||
~DialogExVM() final;
|
||||
View* get_view() final;
|
||||
void clean() final;
|
||||
|
||||
/**
|
||||
* Set dialog result callback
|
||||
* @param callback - result callback function
|
||||
*/
|
||||
void set_result_callback(DialogExResultCallback callback);
|
||||
|
||||
/**
|
||||
* Set dialog context
|
||||
* @param context - context pointer, will be passed to result callback
|
||||
*/
|
||||
void set_context(void* context);
|
||||
|
||||
/**
|
||||
* Set dialog header text
|
||||
* If text is null, dialog header will not be rendered
|
||||
* @param text - text to be shown, can be multiline
|
||||
* @param x, y - text position
|
||||
* @param horizontal, vertical - text aligment
|
||||
*/
|
||||
void set_header(const char* text, uint8_t x, uint8_t y, Align horizontal, Align vertical);
|
||||
|
||||
/**
|
||||
* Set dialog text
|
||||
* If text is null, dialog text will not be rendered
|
||||
* @param text - text to be shown, can be multiline
|
||||
* @param x, y - text position
|
||||
* @param horizontal, vertical - text aligment
|
||||
*/
|
||||
void set_text(const char* text, uint8_t x, uint8_t y, Align horizontal, Align vertical);
|
||||
|
||||
/**
|
||||
* Set dialog icon
|
||||
* If x or y is negative, dialog icon will not be rendered
|
||||
* @param x, y - icon position
|
||||
* @param name - icon to be shown
|
||||
*/
|
||||
void set_icon(int8_t x, int8_t y, IconName name);
|
||||
|
||||
/**
|
||||
* Set left button text
|
||||
* If text is null, left button will not be rendered and processed
|
||||
* @param text - text to be shown
|
||||
*/
|
||||
void set_left_button_text(const char* text);
|
||||
|
||||
/**
|
||||
* Set center button text
|
||||
* If text is null, center button will not be rendered and processed
|
||||
* @param text - text to be shown
|
||||
*/
|
||||
void set_center_button_text(const char* text);
|
||||
|
||||
/**
|
||||
* Set right button text
|
||||
* If text is null, right button will not be rendered and processed
|
||||
* @param text - text to be shown
|
||||
*/
|
||||
void set_right_button_text(const char* text);
|
||||
|
||||
private:
|
||||
DialogEx* dialog_ex;
|
||||
};
|
10
lib/app-scened-template/view-modules/generic-view-module.h
Normal file
10
lib/app-scened-template/view-modules/generic-view-module.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <gui/view.h>
|
||||
|
||||
class GenericViewModule {
|
||||
public:
|
||||
GenericViewModule(){};
|
||||
virtual ~GenericViewModule(){};
|
||||
virtual View* get_view() = 0;
|
||||
virtual void clean() = 0;
|
||||
};
|
54
lib/app-scened-template/view-modules/popup-vm.cpp
Normal file
54
lib/app-scened-template/view-modules/popup-vm.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "popup-vm.h"
|
||||
PopupVM::PopupVM() {
|
||||
popup = popup_alloc();
|
||||
}
|
||||
|
||||
PopupVM::~PopupVM() {
|
||||
popup_free(popup);
|
||||
}
|
||||
|
||||
View* PopupVM::get_view() {
|
||||
return popup_get_view(popup);
|
||||
}
|
||||
|
||||
void PopupVM::clean() {
|
||||
set_callback(NULL);
|
||||
set_context(NULL);
|
||||
set_header(NULL, 0, 0, AlignLeft, AlignBottom);
|
||||
set_text(NULL, 0, 0, AlignLeft, AlignBottom);
|
||||
set_icon(-1, -1, I_ButtonCenter_7x7);
|
||||
disable_timeout();
|
||||
set_timeout(1000);
|
||||
}
|
||||
|
||||
void PopupVM::set_callback(PopupCallback callback) {
|
||||
popup_set_callback(popup, callback);
|
||||
}
|
||||
|
||||
void PopupVM::set_context(void* context) {
|
||||
popup_set_context(popup, context);
|
||||
}
|
||||
|
||||
void PopupVM::set_header(const char* text, uint8_t x, uint8_t y, Align horizontal, Align vertical) {
|
||||
popup_set_header(popup, text, x, y, horizontal, vertical);
|
||||
}
|
||||
|
||||
void PopupVM::set_text(const char* text, uint8_t x, uint8_t y, Align horizontal, Align vertical) {
|
||||
popup_set_text(popup, text, x, y, horizontal, vertical);
|
||||
}
|
||||
|
||||
void PopupVM::set_icon(int8_t x, int8_t y, IconName name) {
|
||||
popup_set_icon(popup, x, y, name);
|
||||
}
|
||||
|
||||
void PopupVM::set_timeout(uint32_t timeout_in_ms) {
|
||||
popup_set_timeout(popup, timeout_in_ms);
|
||||
}
|
||||
|
||||
void PopupVM::enable_timeout() {
|
||||
popup_enable_timeout(popup);
|
||||
}
|
||||
|
||||
void PopupVM::disable_timeout() {
|
||||
popup_enable_timeout(popup);
|
||||
}
|
68
lib/app-scened-template/view-modules/popup-vm.h
Normal file
68
lib/app-scened-template/view-modules/popup-vm.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
#include "generic-view-module.h"
|
||||
#include <gui/modules/popup.h>
|
||||
|
||||
class PopupVM : public GenericViewModule {
|
||||
public:
|
||||
PopupVM();
|
||||
~PopupVM() final;
|
||||
View* get_view() final;
|
||||
void clean() final;
|
||||
|
||||
/**
|
||||
* Set popup header text
|
||||
* @param text - text to be shown
|
||||
*/
|
||||
void set_callback(PopupCallback callback);
|
||||
|
||||
/**
|
||||
* Set popup context
|
||||
* @param context - context pointer, will be passed to result callback
|
||||
*/
|
||||
void set_context(void* context);
|
||||
|
||||
/**
|
||||
* Set popup header text
|
||||
* If text is null, popup header will not be rendered
|
||||
* @param text - text to be shown, can be multiline
|
||||
* @param x, y - text position
|
||||
* @param horizontal, vertical - text aligment
|
||||
*/
|
||||
void set_header(const char* text, uint8_t x, uint8_t y, Align horizontal, Align vertical);
|
||||
|
||||
/**
|
||||
* Set popup text
|
||||
* If text is null, popup text will not be rendered
|
||||
* @param text - text to be shown, can be multiline
|
||||
* @param x, y - text position
|
||||
* @param horizontal, vertical - text aligment
|
||||
*/
|
||||
void set_text(const char* text, uint8_t x, uint8_t y, Align horizontal, Align vertical);
|
||||
|
||||
/**
|
||||
* Set popup icon
|
||||
* If icon position is negative, popup icon will not be rendered
|
||||
* @param x, y - icon position
|
||||
* @param name - icon to be shown
|
||||
*/
|
||||
void set_icon(int8_t x, int8_t y, IconName name);
|
||||
|
||||
/**
|
||||
* Set popup timeout
|
||||
* @param timeout_in_ms - popup timeout value in milliseconds
|
||||
*/
|
||||
void set_timeout(uint32_t timeout_in_ms);
|
||||
|
||||
/**
|
||||
* Enable popup timeout
|
||||
*/
|
||||
void enable_timeout();
|
||||
|
||||
/**
|
||||
* Disable popup timeout
|
||||
*/
|
||||
void disable_timeout();
|
||||
|
||||
private:
|
||||
Popup* popup;
|
||||
};
|
33
lib/app-scened-template/view-modules/submenu-vm.cpp
Normal file
33
lib/app-scened-template/view-modules/submenu-vm.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "submenu-vm.h"
|
||||
|
||||
SubmenuVM::SubmenuVM() {
|
||||
submenu = submenu_alloc();
|
||||
}
|
||||
|
||||
SubmenuVM::~SubmenuVM() {
|
||||
submenu_free(submenu);
|
||||
}
|
||||
|
||||
View* SubmenuVM::get_view() {
|
||||
return submenu_get_view(submenu);
|
||||
}
|
||||
|
||||
void SubmenuVM::clean() {
|
||||
submenu_clean(submenu);
|
||||
}
|
||||
|
||||
SubmenuItem* SubmenuVM::add_item(
|
||||
const char* label,
|
||||
uint32_t index,
|
||||
SubmenuItemCallback callback,
|
||||
void* callback_context) {
|
||||
return submenu_add_item(submenu, label, index, callback, callback_context);
|
||||
}
|
||||
|
||||
void SubmenuVM::set_selected_item(uint32_t index) {
|
||||
submenu_set_selected_item(submenu, index);
|
||||
}
|
||||
|
||||
void SubmenuVM::set_header(const char* header) {
|
||||
submenu_set_header(submenu, header);
|
||||
}
|
43
lib/app-scened-template/view-modules/submenu-vm.h
Normal file
43
lib/app-scened-template/view-modules/submenu-vm.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
#include "generic-view-module.h"
|
||||
#include <gui/modules/submenu.h>
|
||||
|
||||
class SubmenuVM : public GenericViewModule {
|
||||
public:
|
||||
SubmenuVM();
|
||||
~SubmenuVM() final;
|
||||
View* get_view() final;
|
||||
void clean() final;
|
||||
|
||||
/**
|
||||
* @brief Add item to submenu
|
||||
*
|
||||
* @param label - menu item label
|
||||
* @param index - menu item index, used for callback, may be the same with other items
|
||||
* @param callback - menu item callback
|
||||
* @param callback_context - menu item callback context
|
||||
* @return SubmenuItem instance that can be used to modify or delete that item
|
||||
*/
|
||||
SubmenuItem* add_item(
|
||||
const char* label,
|
||||
uint32_t index,
|
||||
SubmenuItemCallback callback,
|
||||
void* callback_context);
|
||||
|
||||
/**
|
||||
* @brief Set submenu item selector
|
||||
*
|
||||
* @param index index of the item to be selected
|
||||
*/
|
||||
void set_selected_item(uint32_t index);
|
||||
|
||||
/**
|
||||
* @brief Set optional header for submenu
|
||||
*
|
||||
* @param header header to set
|
||||
*/
|
||||
void set_header(const char* header);
|
||||
|
||||
private:
|
||||
Submenu* submenu;
|
||||
};
|
30
lib/app-scened-template/view-modules/text-input-vm.cpp
Normal file
30
lib/app-scened-template/view-modules/text-input-vm.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "text-input-vm.h"
|
||||
|
||||
TextInputVM::TextInputVM() {
|
||||
text_input = text_input_alloc();
|
||||
}
|
||||
|
||||
TextInputVM::~TextInputVM() {
|
||||
text_input_free(text_input);
|
||||
}
|
||||
|
||||
View* TextInputVM::get_view() {
|
||||
return text_input_get_view(text_input);
|
||||
}
|
||||
|
||||
void TextInputVM::clean() {
|
||||
set_result_callback(NULL, NULL, NULL, 0);
|
||||
set_header_text("");
|
||||
}
|
||||
|
||||
void TextInputVM::set_result_callback(
|
||||
TextInputCallback callback,
|
||||
void* callback_context,
|
||||
char* text,
|
||||
uint8_t max_text_length) {
|
||||
text_input_set_result_callback(text_input, callback, callback_context, text, max_text_length);
|
||||
}
|
||||
|
||||
void TextInputVM::set_header_text(const char* text) {
|
||||
text_input_set_header_text(text_input, text);
|
||||
}
|
35
lib/app-scened-template/view-modules/text-input-vm.h
Normal file
35
lib/app-scened-template/view-modules/text-input-vm.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "generic-view-module.h"
|
||||
#include <gui/modules/text_input.h>
|
||||
|
||||
class TextInputVM : public GenericViewModule {
|
||||
public:
|
||||
TextInputVM();
|
||||
~TextInputVM() final;
|
||||
View* get_view() final;
|
||||
void clean() final;
|
||||
|
||||
/**
|
||||
* @brief Set text input result callback
|
||||
*
|
||||
* @param callback - callback fn
|
||||
* @param callback_context - callback context
|
||||
* @param text - text buffer to use
|
||||
* @param max_text_length - text buffer length
|
||||
*/
|
||||
void set_result_callback(
|
||||
TextInputCallback callback,
|
||||
void* callback_context,
|
||||
char* text,
|
||||
uint8_t max_text_length);
|
||||
|
||||
/**
|
||||
* @brief Set text input header text
|
||||
*
|
||||
* @param text - text to be shown
|
||||
*/
|
||||
void set_header_text(const char* text);
|
||||
|
||||
private:
|
||||
TextInput* text_input;
|
||||
};
|
Reference in New Issue
Block a user