Add Remote App & UI updates. (#1451)

* Alpha order sub-menus
* WIP Getting Remote types outlined
* WIP building UI
* WIP adding RemoteButton control
* WIP Fix build
* WIP Basic editing support
* Border on the active button
* Make TxView2 sane
* Add easier RGB color creation from uint32
* Center some button icons
* WIP Remote - main UI
* WIP main UI mostly working, can send
* Add 'join' utility
* WIP save/load
* Pre-alloc buttons to prevent focus dangling
* Alpha order settings/debug pages
* Add UI for picking capture and set frequency
* WIP Getting really close now
* Fix path for init name
* Some fit & finish
This commit is contained in:
Kyle Reed
2023-09-18 14:22:46 -07:00
committed by GitHub
parent 537cf2e79b
commit fca373d936
27 changed files with 1205 additions and 312 deletions

View File

@@ -97,6 +97,14 @@ struct Color {
return (v ^ 0xffff);
}
/* Converts a 32-bit color into a 16-bit color.
* High byte is ignored. */
static constexpr Color RGB(uint32_t rgb) {
return {static_cast<uint8_t>((rgb >> 16) & 0xff),
static_cast<uint8_t>((rgb >> 8) & 0xff),
static_cast<uint8_t>(rgb & 0xff)};
}
static constexpr Color black() {
return {0, 0, 0};
}

View File

@@ -1139,9 +1139,9 @@ NewButton::NewButton(
Color color,
bool vertical_center)
: Widget{parent_rect},
color_{color},
text_{text},
bitmap_{bitmap},
color_{color},
vertical_center_{vertical_center} {
set_focusable(true);
}
@@ -1182,18 +1182,8 @@ void NewButton::paint(Painter& painter) {
if (!bitmap_ && text_.empty())
return;
Color bg, fg;
const auto r = screen_rect();
if (has_focus() || highlighted()) {
bg = style().foreground;
fg = Color::black();
} else {
bg = Color::grey();
fg = style().foreground;
}
const Style paint_style = {style().font, bg, fg};
const Style style = paint_style();
painter.draw_rectangle({r.location(), {r.width(), 1}}, Color::light_grey());
painter.draw_rectangle({r.left(), r.top() + r.height() - 1, r.width(), 1}, Color::dark_grey());
@@ -1201,7 +1191,7 @@ void NewButton::paint(Painter& painter) {
painter.fill_rectangle(
{r.left(), r.top() + 1, r.width() - 1, r.height() - 2},
paint_style.background);
style.background);
int y = r.top();
if (bitmap_) {
@@ -1213,18 +1203,32 @@ void NewButton::paint(Painter& painter) {
bmp_pos,
*bitmap_,
color_,
bg);
style.background);
}
if (!text_.empty()) {
const auto label_r = paint_style.font.size_of(text_);
const auto label_r = style.font.size_of(text_);
painter.draw_string(
{r.left() + (r.width() - label_r.width()) / 2, y + (r.height() - label_r.height()) / 2},
paint_style,
style,
text_);
}
}
Style NewButton::paint_style() {
MutableStyle s{style()};
if (has_focus() || highlighted()) {
s.background = style().foreground;
s.foreground = Color::black();
} else {
s.background = Color::grey();
s.foreground = style().foreground;
}
return s;
}
void NewButton::on_focus() {
if (on_highlight)
on_highlight(*this);

View File

@@ -479,10 +479,13 @@ class NewButton : public Widget {
void paint(Painter& painter) override;
protected:
virtual Style paint_style();
Color color_;
private:
std::string text_;
const Bitmap* bitmap_;
Color color_;
bool vertical_center_{false};
};

View File

@@ -213,3 +213,25 @@ static constexpr uint32_t gcd_top(const uint32_t u, const uint32_t v) {
uint32_t gcd(const uint32_t u, const uint32_t v) {
return gcd_top(u, v);
}
std::string join(char c, std::initializer_list<std::string_view> strings) {
std::string result;
size_t total_size = strings.size();
for (auto s : strings)
total_size += s.size();
result.reserve(total_size);
bool first = true;
for (auto s : strings) {
if (!first)
result += c;
else
first = false;
result += s;
}
return result;
}

View File

@@ -27,7 +27,9 @@
#include <complex>
#include <cstdint>
#include <cstddef>
#include <initializer_list>
#include <memory>
#include <string_view>
#include <type_traits>
#define LOCATE_IN_RAM __attribute__((section(".ramtext")))
@@ -213,4 +215,6 @@ struct range_t {
}
};
std::string join(char c, std::initializer_list<std::string_view> strings);
#endif /*__UTILITY_H__*/