2015-07-08 15:39:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
2016-08-06 06:49:45 +00:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2015-07-08 15:39:24 +00:00
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __UI_WIDGET_H__
|
|
|
|
#define __UI_WIDGET_H__
|
|
|
|
|
|
|
|
#include "ui.hpp"
|
|
|
|
#include "ui_text.hpp"
|
|
|
|
#include "ui_painter.hpp"
|
|
|
|
#include "ui_focus.hpp"
|
2017-02-12 07:23:31 +00:00
|
|
|
#include "ui_font_fixed_8x16.hpp"
|
2017-09-20 06:50:59 +00:00
|
|
|
#include "rtc_time.hpp"
|
2016-05-11 21:57:22 +00:00
|
|
|
#include "radio.hpp"
|
2015-07-08 15:39:24 +00:00
|
|
|
|
2016-12-09 17:21:47 +00:00
|
|
|
#include "portapack.hpp"
|
2015-07-08 15:39:24 +00:00
|
|
|
#include "utility.hpp"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2015-08-15 04:17:23 +00:00
|
|
|
void dirty_set();
|
|
|
|
void dirty_clear();
|
|
|
|
bool is_dirty();
|
2015-07-08 15:39:24 +00:00
|
|
|
|
2015-11-09 19:56:40 +00:00
|
|
|
class Context {
|
|
|
|
public:
|
|
|
|
FocusManager& focus_manager() {
|
|
|
|
return focus_manager_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-11-27 00:50:44 +00:00
|
|
|
FocusManager focus_manager_ { };
|
2015-07-08 15:39:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Widget {
|
|
|
|
public:
|
2016-05-09 19:05:11 +00:00
|
|
|
Widget(
|
2016-12-06 17:28:48 +00:00
|
|
|
) : _parent_rect { }
|
2015-07-08 15:39:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-09 19:05:11 +00:00
|
|
|
Widget(
|
2015-07-08 15:39:24 +00:00
|
|
|
Rect parent_rect
|
2016-12-06 17:28:48 +00:00
|
|
|
) : _parent_rect { parent_rect }
|
2015-07-08 15:39:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget(const Widget&) = delete;
|
|
|
|
Widget(Widget&&) = delete;
|
2016-11-27 00:52:57 +00:00
|
|
|
Widget& operator=(const Widget&) = delete;
|
|
|
|
Widget& operator=(Widget&&) = delete;
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
virtual ~Widget() = default;
|
|
|
|
|
|
|
|
Point screen_pos();
|
|
|
|
Size size() const;
|
2016-05-09 19:05:11 +00:00
|
|
|
Rect screen_rect() const;
|
2016-12-06 17:28:48 +00:00
|
|
|
Rect parent_rect() const;
|
2015-07-08 15:39:24 +00:00
|
|
|
virtual void set_parent_rect(const Rect new_parent_rect);
|
|
|
|
|
|
|
|
Widget* parent() const;
|
|
|
|
void set_parent(Widget* const widget);
|
|
|
|
|
|
|
|
bool hidden() const { return flags.hidden; }
|
|
|
|
void hidden(bool hide);
|
|
|
|
|
|
|
|
virtual void focus();
|
|
|
|
virtual void on_focus();
|
|
|
|
virtual void blur();
|
|
|
|
virtual void on_blur();
|
|
|
|
bool focusable() const;
|
2016-02-07 18:32:38 +00:00
|
|
|
void set_focusable(const bool value);
|
2015-07-08 15:39:24 +00:00
|
|
|
bool has_focus();
|
|
|
|
|
|
|
|
virtual void paint(Painter& painter) = 0;
|
|
|
|
|
|
|
|
virtual void on_show() { };
|
|
|
|
virtual void on_hide() { };
|
|
|
|
|
|
|
|
virtual bool on_key(const KeyEvent event);
|
|
|
|
virtual bool on_encoder(const EncoderEvent event);
|
|
|
|
virtual bool on_touch(const TouchEvent event);
|
2016-02-07 19:24:25 +00:00
|
|
|
virtual const std::vector<Widget*>& children() const;
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
virtual Context& context() const;
|
|
|
|
|
|
|
|
void set_style(const Style* new_style);
|
|
|
|
|
|
|
|
const Style& style() const;
|
2017-04-20 23:31:21 +00:00
|
|
|
int16_t id = 0;
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
// State management methods.
|
|
|
|
void set_dirty();
|
|
|
|
bool dirty() const;
|
|
|
|
void set_clean();
|
|
|
|
|
|
|
|
void visible(bool v);
|
2016-08-03 02:53:51 +00:00
|
|
|
bool visible() { return flags.visible; };
|
2015-07-08 15:39:24 +00:00
|
|
|
|
2016-02-07 18:32:38 +00:00
|
|
|
bool highlighted() const;
|
|
|
|
void set_highlighted(const bool value);
|
|
|
|
|
2015-07-08 15:39:24 +00:00
|
|
|
protected:
|
2016-02-07 18:40:06 +00:00
|
|
|
void dirty_overlapping_children_in_rect(const Rect& child_rect);
|
|
|
|
|
|
|
|
private:
|
2015-07-08 15:39:24 +00:00
|
|
|
/* Widget rectangle relative to parent pos(). */
|
2016-12-06 17:28:48 +00:00
|
|
|
Rect _parent_rect;
|
2015-07-08 15:39:24 +00:00
|
|
|
const Style* style_ { nullptr };
|
|
|
|
Widget* parent_ { nullptr };
|
|
|
|
|
|
|
|
struct flags_t {
|
|
|
|
bool dirty : 1; // Widget content has changed.
|
|
|
|
bool hidden : 1; // Hide widget and children.
|
|
|
|
bool focusable : 1; // Widget can receive focus.
|
|
|
|
bool highlighted : 1; // Show in a highlighted style.
|
|
|
|
bool visible : 1; // Object was visible during last paint.
|
|
|
|
};
|
|
|
|
|
|
|
|
flags_t flags {
|
|
|
|
.dirty = true,
|
|
|
|
.hidden = false,
|
|
|
|
.focusable = false,
|
|
|
|
.highlighted = false,
|
|
|
|
.visible = false,
|
|
|
|
};
|
2016-01-31 08:34:24 +00:00
|
|
|
|
2016-02-07 19:24:25 +00:00
|
|
|
static const std::vector<Widget*> no_children;
|
2015-07-08 15:39:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class View : public Widget {
|
|
|
|
public:
|
|
|
|
View() {
|
|
|
|
}
|
|
|
|
|
|
|
|
View(Rect parent_rect) {
|
|
|
|
set_parent_rect(parent_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: ~View() should on_hide() all children?
|
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
void add_child(Widget* const widget);
|
2016-09-05 21:53:04 +00:00
|
|
|
void add_children(const std::initializer_list<Widget*> children);
|
2015-07-08 15:39:24 +00:00
|
|
|
void remove_child(Widget* const widget);
|
2016-12-09 17:21:47 +00:00
|
|
|
void remove_children(const std::vector<Widget*>& children);
|
2016-02-07 19:24:25 +00:00
|
|
|
const std::vector<Widget*>& children() const override;
|
2015-07-08 15:39:24 +00:00
|
|
|
|
2016-01-31 08:34:24 +00:00
|
|
|
virtual std::string title() const;
|
|
|
|
|
2015-07-08 15:39:24 +00:00
|
|
|
protected:
|
2016-11-27 00:50:44 +00:00
|
|
|
std::vector<Widget*> children_ { };
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
void invalidate_child(Widget* const widget);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Rectangle : public Widget {
|
|
|
|
public:
|
2016-05-25 18:32:06 +00:00
|
|
|
Rectangle(Color c);
|
2016-01-31 08:34:24 +00:00
|
|
|
Rectangle(Rect parent_rect, Color c);
|
2017-01-16 03:45:44 +00:00
|
|
|
Rectangle(
|
|
|
|
) : Rectangle { { }, { } }
|
|
|
|
{
|
|
|
|
}
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
void set_color(const Color c);
|
2016-07-29 02:52:51 +00:00
|
|
|
void set_outline(const bool outline);
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Color color;
|
2016-07-29 02:52:51 +00:00
|
|
|
bool _outline = false;
|
2015-07-08 15:39:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Text : public Widget {
|
|
|
|
public:
|
|
|
|
Text(
|
|
|
|
) : text { "" } {
|
|
|
|
}
|
|
|
|
|
2016-01-31 08:34:24 +00:00
|
|
|
Text(Rect parent_rect, std::string text);
|
|
|
|
Text(Rect parent_rect);
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
void set(const std::string value);
|
2016-02-04 09:27:53 +00:00
|
|
|
|
2015-07-08 15:39:24 +00:00
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string text;
|
|
|
|
};
|
|
|
|
|
2017-02-12 04:05:21 +00:00
|
|
|
class Labels : public Widget {
|
|
|
|
public:
|
|
|
|
struct Label {
|
|
|
|
Point pos;
|
|
|
|
std::string text;
|
|
|
|
ui::Color color;
|
|
|
|
};
|
|
|
|
|
|
|
|
Labels(const Labels&) = delete;
|
|
|
|
Labels(Labels&&) = delete;
|
|
|
|
Labels& operator=(const Labels&) = delete;
|
|
|
|
Labels& operator=(Labels&&) = delete;
|
|
|
|
|
2017-02-12 07:23:31 +00:00
|
|
|
Labels(std::initializer_list<Label> labels);
|
2017-02-12 04:05:21 +00:00
|
|
|
|
2017-02-12 07:23:31 +00:00
|
|
|
void set_labels(std::initializer_list<Label> labels);
|
2017-02-12 04:05:21 +00:00
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
private:
|
2017-02-12 07:23:31 +00:00
|
|
|
std::vector<Label> labels_;
|
2017-02-12 04:05:21 +00:00
|
|
|
};
|
|
|
|
|
2017-09-20 06:50:59 +00:00
|
|
|
class LiveDateTime : public Widget {
|
|
|
|
public:
|
|
|
|
LiveDateTime(Rect parent_rect);
|
|
|
|
~LiveDateTime();
|
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
std::string& string() {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void on_tick_second();
|
|
|
|
|
|
|
|
rtc::RTC datetime { };
|
|
|
|
SignalToken signal_token_tick_second { };
|
|
|
|
std::string text { };
|
|
|
|
};
|
|
|
|
|
2016-05-11 21:57:22 +00:00
|
|
|
class BigFrequency : public Widget {
|
|
|
|
public:
|
|
|
|
BigFrequency(Rect parent_rect, rf::Frequency frequency);
|
|
|
|
|
|
|
|
void set(const rf::Frequency frequency);
|
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
rf::Frequency _frequency;
|
2017-03-13 04:09:21 +00:00
|
|
|
|
2017-09-20 06:50:59 +00:00
|
|
|
static constexpr Dim digit_width = 32;
|
|
|
|
|
2017-03-13 04:09:21 +00:00
|
|
|
const uint8_t segment_font[11] = {
|
|
|
|
0b00111111, // 0: ABCDEF
|
|
|
|
0b00000110, // 1: AB
|
|
|
|
0b01011011, // 2: ABDEG
|
|
|
|
0b01001111, // 3: ABCDG
|
|
|
|
0b01100110, // 4: BCFG
|
|
|
|
0b01101101, // 5: ACDFG
|
|
|
|
0b01111101, // 6: ACDEFG
|
|
|
|
0b00000111, // 7: ABC
|
|
|
|
0b01111111, // 8: ABCDEFG
|
|
|
|
0b01101111, // 9: ABCDFG
|
|
|
|
0b01000000 // -: G
|
|
|
|
};
|
2017-09-20 06:50:59 +00:00
|
|
|
|
|
|
|
const Rect segments[7] = {
|
|
|
|
{{4, 0}, {20, 4}},
|
|
|
|
{{24, 4}, {4, 20}},
|
|
|
|
{{24, 28}, {4, 20}},
|
|
|
|
{{4, 48}, {20, 4}},
|
|
|
|
{{0, 28}, {4, 20}},
|
|
|
|
{{0, 4}, {4, 20}},
|
|
|
|
{{4, 24}, {20, 4}}
|
|
|
|
};
|
2016-05-11 21:57:22 +00:00
|
|
|
};
|
|
|
|
|
2016-05-09 18:42:20 +00:00
|
|
|
class ProgressBar : public Widget {
|
|
|
|
public:
|
|
|
|
ProgressBar(Rect parent_rect);
|
|
|
|
|
2016-08-26 06:11:24 +00:00
|
|
|
void set_max(const uint32_t max);
|
|
|
|
void set_value(const uint32_t value);
|
2016-05-09 18:42:20 +00:00
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
private:
|
2016-08-26 06:11:24 +00:00
|
|
|
uint32_t _value = 0;
|
|
|
|
uint32_t _max = 100;
|
2016-05-09 18:42:20 +00:00
|
|
|
};
|
|
|
|
|
2016-07-29 02:52:51 +00:00
|
|
|
class Console : public Widget {
|
|
|
|
public:
|
|
|
|
Console(Rect parent_rect);
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
void write(std::string message);
|
|
|
|
void writeln(std::string message);
|
|
|
|
|
2017-01-16 13:36:28 +00:00
|
|
|
void paint(Painter&) override;
|
2016-07-29 02:52:51 +00:00
|
|
|
|
|
|
|
void on_show() override;
|
|
|
|
void on_hide() override;
|
|
|
|
|
|
|
|
private:
|
2017-09-02 07:28:29 +00:00
|
|
|
//bool visible = false;
|
2016-07-29 02:52:51 +00:00
|
|
|
Point pos { 0, 0 };
|
2017-01-16 03:45:44 +00:00
|
|
|
std::string buffer { };
|
2016-07-29 02:52:51 +00:00
|
|
|
|
|
|
|
void crlf();
|
|
|
|
};
|
|
|
|
|
2016-02-05 16:40:14 +00:00
|
|
|
class Checkbox : public Widget {
|
|
|
|
public:
|
2017-01-17 14:27:37 +00:00
|
|
|
std::function<void(Checkbox&, bool)> on_select { };
|
2016-02-05 16:40:14 +00:00
|
|
|
|
2017-01-16 13:36:28 +00:00
|
|
|
Checkbox(Point parent_pos, size_t length, std::string text, bool small);
|
|
|
|
Checkbox(
|
|
|
|
Point parent_pos,
|
|
|
|
size_t length,
|
|
|
|
std::string text
|
|
|
|
) : Checkbox { parent_pos, length, text, false }
|
|
|
|
{
|
|
|
|
}
|
2016-02-05 16:40:14 +00:00
|
|
|
|
2016-07-27 22:08:05 +00:00
|
|
|
Checkbox(
|
|
|
|
) : Checkbox { { }, { }, { } }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-16 03:45:44 +00:00
|
|
|
Checkbox(const Checkbox&) = delete;
|
|
|
|
Checkbox(Checkbox&&) = delete;
|
|
|
|
Checkbox& operator=(const Checkbox&) = delete;
|
|
|
|
Checkbox& operator=(Checkbox&&) = delete;
|
|
|
|
|
2016-02-05 16:40:14 +00:00
|
|
|
void set_text(const std::string value);
|
2016-12-09 17:21:47 +00:00
|
|
|
bool set_value(const bool value);
|
2016-02-05 16:40:14 +00:00
|
|
|
bool value() const;
|
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
bool on_key(const KeyEvent key) override;
|
|
|
|
bool on_touch(const TouchEvent event) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string text_;
|
2017-01-16 13:36:28 +00:00
|
|
|
bool small_ { false };
|
|
|
|
bool value_ { false };
|
2017-02-12 04:05:21 +00:00
|
|
|
const Style * style_ { nullptr };
|
2016-02-05 16:40:14 +00:00
|
|
|
};
|
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
class Button : public Widget {
|
2015-09-05 18:17:43 +00:00
|
|
|
public:
|
2016-11-27 00:50:44 +00:00
|
|
|
std::function<void(Button&)> on_select { };
|
2017-01-16 03:45:44 +00:00
|
|
|
std::function<bool(Button&, KeyEvent)> on_dir { };
|
|
|
|
std::function<void(Button&)> on_highlight { };
|
2015-09-05 18:17:43 +00:00
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
Button(Rect parent_rect, std::string text);
|
2015-09-05 18:17:43 +00:00
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
Button(
|
|
|
|
) : Button { { }, { } }
|
2015-09-05 18:17:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_text(const std::string value);
|
|
|
|
std::string text() const;
|
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
2016-02-04 09:27:53 +00:00
|
|
|
|
2016-08-26 06:11:24 +00:00
|
|
|
void on_focus() override;
|
2015-09-05 18:17:43 +00:00
|
|
|
bool on_key(const KeyEvent key) override;
|
|
|
|
bool on_touch(const TouchEvent event) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string text_;
|
|
|
|
};
|
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
class Image : public Widget {
|
2015-07-08 15:39:24 +00:00
|
|
|
public:
|
2016-02-04 09:27:53 +00:00
|
|
|
Image();
|
|
|
|
Image(
|
|
|
|
const Rect parent_rect,
|
|
|
|
const Bitmap* bitmap,
|
|
|
|
const Color foreground,
|
|
|
|
const Color background
|
|
|
|
);
|
|
|
|
|
2016-11-27 00:52:57 +00:00
|
|
|
Image(const Image&) = delete;
|
|
|
|
Image(Image&&) = delete;
|
|
|
|
Image& operator=(const Image&) = delete;
|
|
|
|
Image& operator=(Image&&) = delete;
|
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
void set_bitmap(const Bitmap* bitmap);
|
|
|
|
void set_foreground(const Color color);
|
|
|
|
void set_background(const Color color);
|
2016-07-28 03:25:33 +00:00
|
|
|
void invert_colors();
|
2015-07-08 15:39:24 +00:00
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
void paint(Painter& painter) override;
|
2015-07-08 15:39:24 +00:00
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
private:
|
|
|
|
const Bitmap* bitmap_;
|
|
|
|
Color foreground_;
|
|
|
|
Color background_;
|
|
|
|
};
|
2015-07-08 15:39:24 +00:00
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
class ImageButton : public Image {
|
|
|
|
public:
|
2016-11-27 00:50:44 +00:00
|
|
|
std::function<void(ImageButton&)> on_select { };
|
2015-07-08 15:39:24 +00:00
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
ImageButton(
|
|
|
|
const Rect parent_rect,
|
|
|
|
const Bitmap* bitmap,
|
|
|
|
const Color foreground,
|
|
|
|
const Color background
|
|
|
|
);
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
bool on_key(const KeyEvent key) override;
|
|
|
|
bool on_touch(const TouchEvent event) override;
|
|
|
|
};
|
|
|
|
|
2016-05-27 04:48:04 +00:00
|
|
|
class ImageOptionsField : public Widget {
|
|
|
|
public:
|
|
|
|
using value_t = int32_t;
|
2017-07-18 18:31:05 +00:00
|
|
|
using option_t = std::pair<const Bitmap*, value_t>;
|
2016-05-27 04:48:04 +00:00
|
|
|
using options_t = std::vector<option_t>;
|
|
|
|
|
2017-01-16 03:45:44 +00:00
|
|
|
std::function<void(size_t, value_t)> on_change { };
|
|
|
|
std::function<void(void)> on_show_options { };
|
2016-05-27 04:48:04 +00:00
|
|
|
|
2017-07-18 18:31:05 +00:00
|
|
|
ImageOptionsField(
|
|
|
|
const Rect parent_rect,
|
|
|
|
const Color foreground,
|
|
|
|
const Color background,
|
|
|
|
const options_t options
|
|
|
|
);
|
2016-05-27 04:48:04 +00:00
|
|
|
|
2016-12-09 17:21:47 +00:00
|
|
|
ImageOptionsField(
|
2017-07-18 18:31:05 +00:00
|
|
|
) : ImageOptionsField { { }, Color::white(), Color::black(), { } }
|
2016-12-09 17:21:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-27 04:48:04 +00:00
|
|
|
void set_options(options_t new_options);
|
|
|
|
|
|
|
|
size_t selected_index() const;
|
|
|
|
size_t selected_index_value() const;
|
|
|
|
void set_selected_index(const size_t new_index);
|
|
|
|
|
|
|
|
void set_by_value(value_t v);
|
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
void on_focus() override;
|
|
|
|
bool on_encoder(const EncoderEvent delta) override;
|
|
|
|
bool on_touch(const TouchEvent event) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
options_t options;
|
|
|
|
size_t selected_index_ { 0 };
|
2017-07-18 18:31:05 +00:00
|
|
|
Color foreground_;
|
|
|
|
Color background_;
|
2016-05-27 04:48:04 +00:00
|
|
|
};
|
|
|
|
|
2015-07-08 15:39:24 +00:00
|
|
|
class OptionsField : public Widget {
|
|
|
|
public:
|
|
|
|
using name_t = std::string;
|
|
|
|
using value_t = int32_t;
|
|
|
|
using option_t = std::pair<name_t, value_t>;
|
|
|
|
using options_t = std::vector<option_t>;
|
|
|
|
|
2016-11-27 00:50:44 +00:00
|
|
|
std::function<void(size_t, value_t)> on_change { };
|
|
|
|
std::function<void(void)> on_show_options { };
|
2015-07-08 15:39:24 +00:00
|
|
|
|
2016-11-29 18:13:56 +00:00
|
|
|
OptionsField(Point parent_pos, int length, options_t options);
|
2016-02-05 16:40:14 +00:00
|
|
|
|
|
|
|
void set_options(options_t new_options);
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
size_t selected_index() const;
|
2016-05-13 07:34:15 +00:00
|
|
|
size_t selected_index_value() const;
|
2015-07-08 15:39:24 +00:00
|
|
|
void set_selected_index(const size_t new_index);
|
|
|
|
|
|
|
|
void set_by_value(value_t v);
|
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
void on_focus() override;
|
2015-07-08 15:39:24 +00:00
|
|
|
bool on_encoder(const EncoderEvent delta) override;
|
|
|
|
bool on_touch(const TouchEvent event) override;
|
|
|
|
|
|
|
|
private:
|
2016-11-29 18:13:56 +00:00
|
|
|
const int length_;
|
2015-07-08 15:39:24 +00:00
|
|
|
options_t options;
|
|
|
|
size_t selected_index_ { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
class NumberField : public Widget {
|
|
|
|
public:
|
2017-01-16 03:45:44 +00:00
|
|
|
std::function<void(NumberField&)> on_select { };
|
2016-11-27 00:50:44 +00:00
|
|
|
std::function<void(int32_t)> on_change { };
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
using range_t = std::pair<int32_t, int32_t>;
|
|
|
|
|
2017-07-30 08:39:01 +00:00
|
|
|
NumberField(Point parent_pos, int length, range_t range, int32_t step, char fill_char, bool can_loop);
|
|
|
|
|
|
|
|
NumberField(Point parent_pos, int length, range_t range, int32_t step, char fill_char
|
|
|
|
) : NumberField { parent_pos, length, range, step, fill_char, false }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-03 02:53:51 +00:00
|
|
|
NumberField(
|
2017-07-30 08:39:01 +00:00
|
|
|
) : NumberField { { 0, 0 }, 1, { 0, 1 }, 1, ' ', false }
|
2016-08-03 02:53:51 +00:00
|
|
|
{
|
|
|
|
}
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
NumberField(const NumberField&) = delete;
|
|
|
|
NumberField(NumberField&&) = delete;
|
|
|
|
|
|
|
|
int32_t value() const;
|
2016-08-06 06:49:45 +00:00
|
|
|
void set_value(int32_t new_value, bool trigger_change = true);
|
2016-08-03 02:53:51 +00:00
|
|
|
void set_range(const int32_t min, const int32_t max);
|
2017-10-15 14:53:40 +00:00
|
|
|
void set_step(const int32_t new_step);
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
2016-07-25 14:21:27 +00:00
|
|
|
bool on_key(const KeyEvent key) override;
|
2015-07-08 15:39:24 +00:00
|
|
|
bool on_encoder(const EncoderEvent delta) override;
|
|
|
|
bool on_touch(const TouchEvent event) override;
|
|
|
|
|
|
|
|
private:
|
2016-08-03 02:53:51 +00:00
|
|
|
range_t range;
|
2017-10-15 14:53:40 +00:00
|
|
|
int32_t step;
|
2016-11-29 18:13:56 +00:00
|
|
|
const int length_;
|
2015-07-08 15:39:24 +00:00
|
|
|
const char fill_char;
|
2016-11-27 00:50:44 +00:00
|
|
|
int32_t value_ { 0 };
|
2017-07-30 08:39:01 +00:00
|
|
|
bool can_loop { };
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
int32_t clip_value(int32_t value);
|
|
|
|
};
|
|
|
|
|
2016-08-06 06:49:45 +00:00
|
|
|
class SymField : public Widget {
|
|
|
|
public:
|
2017-01-16 03:45:44 +00:00
|
|
|
std::function<void(SymField&)> on_select { };
|
|
|
|
std::function<void()> on_change { };
|
2016-08-06 06:49:45 +00:00
|
|
|
|
2017-02-01 00:21:13 +00:00
|
|
|
enum symfield_type {
|
|
|
|
SYMFIELD_OCT,
|
|
|
|
SYMFIELD_DEC,
|
|
|
|
SYMFIELD_HEX,
|
2018-02-23 20:21:24 +00:00
|
|
|
SYMFIELD_ALPHANUM,
|
2017-02-01 00:21:13 +00:00
|
|
|
SYMFIELD_DEF // User DEFined
|
|
|
|
};
|
|
|
|
|
|
|
|
SymField(Point parent_pos, size_t length, symfield_type type);
|
2016-08-06 06:49:45 +00:00
|
|
|
|
|
|
|
SymField(const SymField&) = delete;
|
|
|
|
SymField(SymField&&) = delete;
|
|
|
|
|
2017-03-13 04:09:21 +00:00
|
|
|
uint32_t get_sym(const uint32_t index);
|
|
|
|
void set_sym(const uint32_t index, const uint32_t new_value);
|
2016-08-06 06:49:45 +00:00
|
|
|
void set_length(const uint32_t new_length);
|
2016-09-27 01:06:14 +00:00
|
|
|
void set_symbol_list(const uint32_t index, const std::string symbol_list);
|
2017-02-07 17:48:17 +00:00
|
|
|
uint32_t value_dec_u32();
|
2016-12-05 11:56:41 +00:00
|
|
|
uint64_t value_hex_u64();
|
2018-02-23 20:21:24 +00:00
|
|
|
std::string value_string();
|
2016-08-06 06:49:45 +00:00
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
bool on_key(const KeyEvent key) override;
|
|
|
|
bool on_encoder(const EncoderEvent delta) override;
|
|
|
|
bool on_touch(const TouchEvent event) override;
|
|
|
|
|
|
|
|
private:
|
2016-09-27 01:06:14 +00:00
|
|
|
std::string symbol_list_[32] = { "01" }; // Failsafe init
|
|
|
|
uint32_t values_[32] = { 0 };
|
2016-08-06 06:49:45 +00:00
|
|
|
uint32_t selected_ = 0;
|
2017-01-16 03:45:44 +00:00
|
|
|
size_t length_, prev_length_ = 0;
|
2016-08-06 06:49:45 +00:00
|
|
|
bool erase_prev_ = false;
|
2017-02-01 00:21:13 +00:00
|
|
|
symfield_type type_ { };
|
2016-08-06 06:49:45 +00:00
|
|
|
|
2016-09-27 01:06:14 +00:00
|
|
|
int32_t clip_value(const uint32_t index, const uint32_t value);
|
2016-08-06 06:49:45 +00:00
|
|
|
};
|
|
|
|
|
2017-01-09 02:45:29 +00:00
|
|
|
class Waveform : public Widget {
|
|
|
|
public:
|
|
|
|
|
2017-11-02 17:11:26 +00:00
|
|
|
Waveform(Rect parent_rect, int16_t * data, uint32_t length, uint32_t offset, bool digital, Color color);
|
2017-01-09 02:45:29 +00:00
|
|
|
|
|
|
|
Waveform(const Waveform&) = delete;
|
|
|
|
Waveform(Waveform&&) = delete;
|
2017-01-16 03:45:44 +00:00
|
|
|
Waveform& operator=(const Waveform&) = delete;
|
|
|
|
Waveform& operator=(Waveform&&) = delete;
|
2017-01-09 02:45:29 +00:00
|
|
|
|
|
|
|
void set_offset(const uint32_t new_offset);
|
|
|
|
void set_length(const uint32_t new_length);
|
2017-11-02 17:11:26 +00:00
|
|
|
void set_cursor(const uint32_t i, const int16_t position);
|
2017-01-09 02:45:29 +00:00
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
private:
|
2017-11-02 17:11:26 +00:00
|
|
|
const Color cursor_colors[2] = { Color::cyan(), Color::magenta() };
|
|
|
|
|
|
|
|
int16_t * data_;
|
2017-01-09 02:45:29 +00:00
|
|
|
uint32_t length_;
|
|
|
|
uint32_t offset_;
|
2017-01-17 07:00:42 +00:00
|
|
|
bool digital_ { false };
|
2017-01-09 02:45:29 +00:00
|
|
|
Color color_;
|
2017-11-02 17:11:26 +00:00
|
|
|
int16_t cursors[2] { };
|
|
|
|
bool show_cursors { false };
|
2017-01-09 02:45:29 +00:00
|
|
|
};
|
|
|
|
|
2017-03-13 04:09:21 +00:00
|
|
|
class VuMeter : public Widget {
|
|
|
|
public:
|
|
|
|
|
2017-05-18 10:06:11 +00:00
|
|
|
VuMeter(Rect parent_rect, uint32_t LEDs, bool show_max);
|
2017-03-13 04:09:21 +00:00
|
|
|
|
2017-05-18 10:06:11 +00:00
|
|
|
void set_value(const uint32_t new_value);
|
|
|
|
void set_mark(const uint32_t new_mark);
|
2017-03-13 04:09:21 +00:00
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t LEDs_, LED_height { 0 };
|
2017-05-18 10:06:11 +00:00
|
|
|
uint32_t value_ { 0 }, prev_value { 255 }; // Forces painting on first display
|
2017-03-13 04:09:21 +00:00
|
|
|
uint32_t split { 0 };
|
|
|
|
uint16_t max { 0 }, prev_max { 0 }, hold_timer { 0 }, mark { 0 }, prev_mark { 0 };
|
2017-05-18 10:06:11 +00:00
|
|
|
bool show_max_;
|
2017-03-13 04:09:21 +00:00
|
|
|
};
|
|
|
|
|
2017-08-16 09:02:57 +00:00
|
|
|
class OptionTabView : public View {
|
|
|
|
public:
|
|
|
|
OptionTabView(Rect parent_rect);
|
|
|
|
|
|
|
|
void focus() override;
|
|
|
|
|
|
|
|
bool is_enabled();
|
|
|
|
void set_type(std::string type);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool enabled { false };
|
|
|
|
|
|
|
|
void set_enabled(bool value);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Checkbox check_enable {
|
|
|
|
{ 2 * 8, 0 * 16 },
|
|
|
|
20,
|
|
|
|
"",
|
|
|
|
false
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-07-08 15:39:24 +00:00
|
|
|
} /* namespace ui */
|
|
|
|
|
|
|
|
#endif/*__UI_WIDGET_H__*/
|