Rename modelBmp using new 'displayName', add more options (#544)
* Make img buf only size of img not whole widget * Don't draw buffer if there's no image * If there's no image, draw model name * Add some options, draw model name if img not set Add options for text colour, size, fill enable and colour * Use valid values for defaults * Get right colours * Add concept of a 'friendly name to widgets' Allows for separation of internal and user visible names * Use new theme constants * Use right version of libopenui * `displayName` instead of `friendlyName` * Allow using theme colour or custom for name
This commit is contained in:
@@ -121,11 +121,11 @@ SetupWidgetsPageSlot::SetupWidgetsPageSlot(FormGroup * parent, const rect_t & re
|
|||||||
menu->addLine(TR_SELECT_WIDGET, [=]() {
|
menu->addLine(TR_SELECT_WIDGET, [=]() {
|
||||||
Menu * menu = new Menu(parent);
|
Menu * menu = new Menu(parent);
|
||||||
for (auto factory: getRegisteredWidgets()) {
|
for (auto factory: getRegisteredWidgets()) {
|
||||||
menu->addLine(factory->getName(), [=]() {
|
menu->addLine(factory->getDisplayName(), [=]() {
|
||||||
container->createWidget(slotIndex, factory);
|
container->createWidget(slotIndex, factory);
|
||||||
auto widget = container->getWidget(slotIndex);
|
auto widget = container->getWidget(slotIndex);
|
||||||
if(widget->getOptions() && widget->getOptions()->name)
|
if(widget->getOptions() && widget->getOptions()->name)
|
||||||
new WidgetSettings(parent, widget);
|
new WidgetSettings(parent, widget);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -120,8 +120,9 @@ void unregisterWidget(const WidgetFactory * factory);
|
|||||||
class WidgetFactory
|
class WidgetFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit WidgetFactory(const char * name, const ZoneOption * options = nullptr):
|
explicit WidgetFactory(const char * name, const ZoneOption * options = nullptr, const char * displayName = nullptr):
|
||||||
name(name),
|
name(name),
|
||||||
|
displayName(displayName),
|
||||||
options(options)
|
options(options)
|
||||||
{
|
{
|
||||||
registerWidget(this);
|
registerWidget(this);
|
||||||
@@ -139,6 +140,14 @@ class WidgetFactory
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const char * getDisplayName() const
|
||||||
|
{
|
||||||
|
if (displayName)
|
||||||
|
return displayName;
|
||||||
|
else
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
void initPersistentData(Widget::PersistentData * persistentData) const
|
void initPersistentData(Widget::PersistentData * persistentData) const
|
||||||
{
|
{
|
||||||
memset(persistentData, 0, sizeof(Widget::PersistentData));
|
memset(persistentData, 0, sizeof(Widget::PersistentData));
|
||||||
@@ -157,6 +166,7 @@ class WidgetFactory
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
const char * name;
|
const char * name;
|
||||||
|
const char * displayName;
|
||||||
const ZoneOption * options;
|
const ZoneOption * options;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,24 @@ class ModelBitmapWidget: public Widget
|
|||||||
|
|
||||||
void refresh(BitmapBuffer * dc) override
|
void refresh(BitmapBuffer * dc) override
|
||||||
{
|
{
|
||||||
|
std::string filename = std::string(g_model.header.bitmap);
|
||||||
|
|
||||||
|
// set font colour from options[0], if use theme color option off
|
||||||
|
LcdFlags fontColor;
|
||||||
|
if (persistentData->options[4].value.boolValue)
|
||||||
|
fontColor = COLOR_THEME_SECONDARY1;
|
||||||
|
else
|
||||||
|
fontColor = COLOR2FLAGS(persistentData->options[0].value.unsignedValue);
|
||||||
|
|
||||||
|
// get font size from options[1]
|
||||||
|
LcdFlags fontSize = persistentData->options[1].value.unsignedValue << 8u;
|
||||||
|
|
||||||
|
// fill bg from options[3] if options[2] set
|
||||||
|
if (persistentData->options[2].value.boolValue) {
|
||||||
|
LcdFlags fillColour = COLOR2FLAGS(persistentData->options[3].value.unsignedValue);
|
||||||
|
dc->drawSolidFilledRect(0, 0, width(), height(), fillColour);
|
||||||
|
}
|
||||||
|
|
||||||
if (buffer &&
|
if (buffer &&
|
||||||
((buffer->width() != width()) || (buffer->height() != height()) ||
|
((buffer->width() != width()) || (buffer->height() != height()) ||
|
||||||
(deps_hash != getHash()))) {
|
(deps_hash != getHash()))) {
|
||||||
@@ -46,22 +64,20 @@ class ModelBitmapWidget: public Widget
|
|||||||
// big space to draw
|
// big space to draw
|
||||||
if (rect.h >= 96 && rect.w >= 120) {
|
if (rect.h >= 96 && rect.w >= 120) {
|
||||||
|
|
||||||
if (buffer) {
|
if (!filename.empty() && buffer) {
|
||||||
dc->drawBitmap(0, 0, buffer.get());
|
dc->drawBitmap(0, 38, buffer.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto iconMask = theme->getIconMask(ICON_MODEL);
|
dc->drawSizedText(5, 5, g_model.header.name, LEN_MODEL_NAME, fontSize | fontColor);
|
||||||
if (iconMask) {
|
|
||||||
dc->drawMask(6, 4, iconMask, COLOR_THEME_SECONDARY1);
|
|
||||||
}
|
|
||||||
|
|
||||||
dc->drawSizedText(45, 10, g_model.header.name, LEN_MODEL_NAME,
|
|
||||||
FONT(XS) | COLOR_THEME_SECONDARY1);
|
|
||||||
dc->drawSolidFilledRect(39, 27, rect.w - 48, 2, COLOR_THEME_SECONDARY1);
|
|
||||||
}
|
}
|
||||||
// smaller space to draw
|
// smaller space to draw
|
||||||
else if (buffer) {
|
else {
|
||||||
dc->drawBitmap(0, 0, buffer.get());
|
if (!filename.empty() && buffer) {
|
||||||
|
dc->drawBitmap(0, 0, buffer.get());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dc->drawSizedText(0, 0, g_model.header.name, LEN_MODEL_NAME, fontSize | fontColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +89,8 @@ class ModelBitmapWidget: public Widget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const ZoneOption options[];
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<BitmapBuffer> buffer;
|
std::unique_ptr<BitmapBuffer> buffer;
|
||||||
uint32_t deps_hash = 0;
|
uint32_t deps_hash = 0;
|
||||||
@@ -100,7 +118,7 @@ class ModelBitmapWidget: public Widget
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rect.h >= 96 && rect.w >= 120) {
|
if (rect.h >= 96 && rect.w >= 120) {
|
||||||
buffer->drawScaledBitmap(bitmap.get(), 0, 38, width(), height() - 38);
|
buffer->drawScaledBitmap(bitmap.get(), 0, 0, width(), height() - 38);
|
||||||
} else {
|
} else {
|
||||||
buffer->drawScaledBitmap(bitmap.get(), 0, 0, width(), height());
|
buffer->drawScaledBitmap(bitmap.get(), 0, 0, width(), height());
|
||||||
}
|
}
|
||||||
@@ -108,5 +126,12 @@ class ModelBitmapWidget: public Widget
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BaseWidgetFactory<ModelBitmapWidget> modelBitmapWidget("ModelBmp", nullptr);
|
const ZoneOption ModelBitmapWidget::options[] = {
|
||||||
const WidgetFactory * defaultWidget = &modelBitmapWidget;
|
{STR_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(COLOR_THEME_SECONDARY1>>16)},
|
||||||
|
{STR_SIZE, ZoneOption::TextSize, OPTION_VALUE_UNSIGNED(FONT_STD_INDEX)},
|
||||||
|
{STR_FILL_BACKGROUND, ZoneOption::Bool, OPTION_VALUE_BOOL(false)},
|
||||||
|
{STR_BG_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(COLOR_THEME_SECONDARY3>>16)},
|
||||||
|
{STR_USE_THEME_COLOR, ZoneOption::Bool, OPTION_VALUE_BOOL(true)},
|
||||||
|
{nullptr, ZoneOption::Bool}};
|
||||||
|
|
||||||
|
BaseWidgetFactory<ModelBitmapWidget> modelBitmapWidget("ModelBmp", ModelBitmapWidget::options, "Models");
|
||||||
|
|||||||
@@ -160,8 +160,8 @@ template<class T>
|
|||||||
class BaseWidgetFactory: public WidgetFactory
|
class BaseWidgetFactory: public WidgetFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BaseWidgetFactory(const char * name, const ZoneOption * options):
|
BaseWidgetFactory(const char * name, const ZoneOption * options, const char * displayName = nullptr):
|
||||||
WidgetFactory(name, options)
|
WidgetFactory(name, options, displayName)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
Submodule radio/src/thirdparty/libopenui updated: 89fe9cda18...ebf86ef1c4
@@ -940,3 +940,5 @@ const char STR_RACING_MODE[] = TR_RACING_MODE;
|
|||||||
#if defined(PCBNV14)
|
#if defined(PCBNV14)
|
||||||
const char STR_RFPOWER_AFHDS2[] = TR_RFPOWER_AFHDS2;
|
const char STR_RFPOWER_AFHDS2[] = TR_RFPOWER_AFHDS2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const char STR_USE_THEME_COLOR[] = TR_USE_THEME_COLOR;
|
||||||
|
|||||||
@@ -1120,6 +1120,8 @@ extern const char STR_AUTH_FAILURE[];
|
|||||||
extern const char STR_PROTOCOL[];
|
extern const char STR_PROTOCOL[];
|
||||||
extern const char STR_RACING_MODE[];
|
extern const char STR_RACING_MODE[];
|
||||||
|
|
||||||
|
extern const char STR_USE_THEME_COLOR[];
|
||||||
|
|
||||||
#define CHR_HOUR TR_CHR_HOUR
|
#define CHR_HOUR TR_CHR_HOUR
|
||||||
#define CHR_INPUT TR_CHR_INPUT
|
#define CHR_INPUT TR_CHR_INPUT
|
||||||
|
|
||||||
|
|||||||
@@ -331,3 +331,5 @@
|
|||||||
#define CHAR_CHANNEL STR_CHAR_CHANNEL[0]
|
#define CHAR_CHANNEL STR_CHAR_CHANNEL[0]
|
||||||
#define CHAR_TELEMETRY STR_CHAR_TELEMETRY[0]
|
#define CHAR_TELEMETRY STR_CHAR_TELEMETRY[0]
|
||||||
#define CHAR_LUA STR_CHAR_LUA[0]
|
#define CHAR_LUA STR_CHAR_LUA[0]
|
||||||
|
|
||||||
|
#define TR_USE_THEME_COLOR "Use theme color"
|
||||||
|
|||||||
Reference in New Issue
Block a user