"Labels" widget

This commit is contained in:
furrtek 2017-02-12 07:23:31 +00:00
parent 0102a34286
commit d12cd0d8af
11 changed files with 52 additions and 74 deletions

View File

@ -28,9 +28,9 @@
//BUG: RDS doesn't stop baseband when stopping tx ? //BUG: RDS doesn't stop baseband when stopping tx ?
//TEST: Imperial in whipcalc //TEST: Imperial in whipcalc
//TEST: Numbers
//TODO: Use TransmitterView in ADSB, Morse, TEDI/LCR, Numbers, whistle, jammer... //TODO: Use Labels widget wherever possible
//TODO: Use TransmitterView in Morse, TEDI/LCR, Numbers, whistle, jammer...
//TODO: FreqMan: Add and rename categories //TODO: FreqMan: Add and rename categories
//TODO: FreqMan: Sort by category in edit screen //TODO: FreqMan: Sort by category in edit screen
//TODO: FreqMan: Cap entry count per category (only done for total entries right now) //TODO: FreqMan: Cap entry count per category (only done for total entries right now)

View File

@ -69,19 +69,13 @@ AFSKSetupView::AFSKSetupView(
size_t i; size_t i;
add_children({ add_children({
&text_setfreq, &labels,
&button_setfreq, &button_setfreq,
&text_bps,
&options_bps, &options_bps,
&text_mark,
&field_mark, &field_mark,
&text_space,
&field_space, &field_space,
&text_bw,
&field_bw, &field_bw,
&text_repeat,
&field_repeat, &field_repeat,
&text_format,
&options_format, &options_format,
&button_save &button_save
}); });

View File

@ -39,19 +39,21 @@ public:
private: private:
void update_freq(rf::Frequency f); void update_freq(rf::Frequency f);
Text text_setfreq { Labels labels {
{ 8, 32, 104, 16 }, { { 1 * 8, 4 * 8 }, "Frequency:", Color::light_grey() },
"Frequency:" { { 16 * 8, 5 * 8 }, "Speed:", Color::light_grey() },
{ { 2 * 8, 13 * 8 }, "Mark: Hz", Color::light_grey() },
{ { 2 * 8, 15 * 8 }, "Space: Hz", Color::light_grey() },
{ { 140, 13 * 8 }, "BW: kHz", Color::light_grey() },
{ { 140, 15 * 8 }, "Repeat:", Color::light_grey() },
{ { 2 * 8, 19 * 8 }, "Format:", Color::light_grey() }
}; };
Button button_setfreq { Button button_setfreq {
{ 8, 48, 104, 32 }, { 8, 48, 104, 32 },
"----.----" "----.----"
}; };
Text text_bps {
{ 128, 40, 104, 16 },
"Speed:"
};
OptionsField options_bps { OptionsField options_bps {
{ 128, 60 }, { 128, 60 },
7, 7,
@ -63,11 +65,7 @@ private:
{ "9600bps", 9600 } { "9600bps", 9600 }
} }
}; };
Text text_mark {
{ 16, 104, 48, 16 },
"Mark: Hz"
};
NumberField field_mark { NumberField field_mark {
{ 64, 104 }, { 64, 104 },
5, 5,
@ -76,10 +74,6 @@ private:
' ' ' '
}; };
Text text_space {
{ 16, 120, 48, 16 },
"Space: Hz"
};
NumberField field_space { NumberField field_space {
{ 64, 120 }, { 64, 120 },
5, 5,
@ -88,10 +82,6 @@ private:
' ' ' '
}; };
Text text_bw {
{ 140, 104, 80, 16 },
"BW: kHz"
};
NumberField field_bw { NumberField field_bw {
{ 172, 104 }, { 172, 104 },
2, 2,
@ -100,10 +90,6 @@ private:
' ' ' '
}; };
Text text_repeat {
{ 140, 120, 64, 16 },
"Repeat: "
};
NumberField field_repeat { NumberField field_repeat {
{ 204, 120 }, { 204, 120 },
2, 2,
@ -112,10 +98,6 @@ private:
' ' ' '
}; };
Text text_format {
{ 16, 152, 7 * 8, 16 },
"Format:"
};
OptionsField options_format { OptionsField options_format {
{ 80, 152 }, { 80, 152 },
10, 10,

View File

@ -119,7 +119,7 @@ bool POCSAGTXView::start_tx() {
void POCSAGTXView::paint(Painter&) { void POCSAGTXView::paint(Painter&) {
message = buffer; message = buffer;
text_message.set("Message:" + message); text_message.set(message);
} }
void POCSAGTXView::on_set_text(NavigationView& nav) { void POCSAGTXView::on_set_text(NavigationView& nav) {
@ -134,11 +134,9 @@ POCSAGTXView::POCSAGTXView(
baseband::run_image(portapack::spi_flash::image_tag_fsktx); baseband::run_image(portapack::spi_flash::image_tag_fsktx);
add_children({ add_children({
&text_bitrate, &labels,
&options_bitrate, &options_bitrate,
&text_address,
&field_address, &field_address,
&text_type,
&options_type, &options_type,
&text_message, &text_message,
&button_message, &button_message,

View File

@ -26,7 +26,6 @@
#include "ui.hpp" #include "ui.hpp"
#include "ui_widget.hpp" #include "ui_widget.hpp"
#include "ui_navigation.hpp" #include "ui_navigation.hpp"
#include "ui_font_fixed_8x16.hpp"
#include "ui_receiver.hpp" #include "ui_receiver.hpp"
#include "ui_transmitter.hpp" #include "ui_transmitter.hpp"
#include "ui_textentry.hpp" #include "ui_textentry.hpp"
@ -68,10 +67,13 @@ private:
void on_tx_progress(const int progress, const bool done); void on_tx_progress(const int progress, const bool done);
bool start_tx(); bool start_tx();
Text text_bitrate { Labels labels {
{ 3 * 8, 4 * 8, 8 * 8, 16 }, { { 3 * 8, 4 * 8 }, "Bitrate:", Color::light_grey() },
"Bitrate:" { { 3 * 8, 6 * 8 }, "Address:", Color::light_grey() },
{ { 6 * 8, 8 * 8 }, "Type:", Color::light_grey() },
{ { 3 * 8, 12 * 8 }, "Message:", Color::light_grey() }
}; };
OptionsField options_bitrate { OptionsField options_bitrate {
{ 11 * 8, 4 * 8 }, { 11 * 8, 4 * 8 },
8, 8,
@ -81,21 +83,13 @@ private:
{ "2400 bps", 2 } { "2400 bps", 2 }
} }
}; };
Text text_address {
{ 3 * 8, 6 * 8, 8 * 8, 16 },
"Address:"
};
SymField field_address { SymField field_address {
{ 11 * 8, 6 * 8 }, { 11 * 8, 6 * 8 },
7, 7,
SymField::SYMFIELD_DEC SymField::SYMFIELD_DEC
}; };
Text text_type {
{ 6 * 8, 8 * 8, 5 * 8, 16 },
"Type:"
};
OptionsField options_type { OptionsField options_type {
{ 11 * 8, 8 * 8 }, { 11 * 8, 8 * 8 },
12, 12,
@ -107,9 +101,10 @@ private:
}; };
Text text_message { Text text_message {
{ 3 * 8, 12 * 8, 16 * 8, 16 }, { 11 * 8, 12 * 8, 16 * 8, 16 },
"" ""
}; };
Button button_message { Button button_message {
{ 3 * 8, 14 * 8, 8 * 8, 28 }, { 3 * 8, 14 * 8, 8 * 8, 28 },
"Set" "Set"

View File

@ -42,11 +42,14 @@ int Painter::draw_char(const Point p, const Style& style, const char c) {
return glyph.advance().x(); return glyph.advance().x();
} }
int Painter::draw_string(Point p, const Style& style, const std::string text) { int Painter::draw_string(Point p, const Font& font, const Color foreground,
const Color background, const std::string text) {
size_t width = 0; size_t width = 0;
for(const auto c : text) { for(const auto c : text) {
const auto glyph = style.font.glyph(c); const auto glyph = font.glyph(c);
display.draw_glyph(p, glyph, style.foreground, style.background); display.draw_glyph(p, glyph, foreground, background);
const auto advance = glyph.advance(); const auto advance = glyph.advance();
p += advance; p += advance;
width += advance.x(); width += advance.x();
@ -54,6 +57,10 @@ int Painter::draw_string(Point p, const Style& style, const std::string text) {
return width; return width;
} }
int Painter::draw_string(Point p, const Style& style, const std::string text) {
return draw_string(p, style.font, style.foreground, style.background, text);
}
void Painter::draw_bitmap(const Point p, const Bitmap& bitmap, const Color foreground, const Color background) { void Painter::draw_bitmap(const Point p, const Bitmap& bitmap, const Color foreground, const Color background) {
display.draw_bitmap(p, bitmap.size, bitmap.data, foreground, background); display.draw_bitmap(p, bitmap.size, bitmap.data, foreground, background);
} }

View File

@ -48,6 +48,8 @@ public:
int draw_char(const Point p, const Style& style, const char c); int draw_char(const Point p, const Style& style, const char c);
int draw_string(Point p, const Font& font, const Color foreground,
const Color background, const std::string text);
int draw_string(Point p, const Style& style, const std::string text); int draw_string(Point p, const Style& style, const std::string text);
void draw_bitmap(const Point p, const Bitmap& bitmap, const Color background, const Color foreground); void draw_bitmap(const Point p, const Bitmap& bitmap, const Color background, const Color foreground);

View File

@ -352,27 +352,26 @@ void Text::paint(Painter& painter) {
/* Labels ****************************************************************/ /* Labels ****************************************************************/
Labels::Labels( Labels::Labels(
std::vector<Label> * labels std::initializer_list<Label> labels
) : labels_ { labels } ) : labels_ { labels }
{ {
} }
void Labels::set_labels(std::vector<Label> * const labels) { void Labels::set_labels(std::initializer_list<Label> labels) {
labels_ = labels; labels_ = labels;
set_dirty(); set_dirty();
} }
void Labels::paint(Painter& painter) { void Labels::paint(Painter& painter) {
/*const auto rect = screen_rect(); for (auto &label : labels_) {
const auto s = style(); painter.draw_string(
label.pos + screen_pos(),
painter.fill_rectangle(rect, s.background); style().font,
label.color,
painter.draw_string( style().background,
rect.location(), label.text
s, );
text }
);*/
} }
/* BigFrequency **********************************************************/ /* BigFrequency **********************************************************/

View File

@ -27,6 +27,7 @@
#include "ui_text.hpp" #include "ui_text.hpp"
#include "ui_painter.hpp" #include "ui_painter.hpp"
#include "ui_focus.hpp" #include "ui_focus.hpp"
#include "ui_font_fixed_8x16.hpp"
#include "radio.hpp" #include "radio.hpp"
#include "portapack.hpp" #include "portapack.hpp"
@ -224,14 +225,14 @@ public:
Labels& operator=(const Labels&) = delete; Labels& operator=(const Labels&) = delete;
Labels& operator=(Labels&&) = delete; Labels& operator=(Labels&&) = delete;
Labels(std::vector<Label> * labels); Labels(std::initializer_list<Label> labels);
void set_labels(std::vector<Label> * const labels); void set_labels(std::initializer_list<Label> labels);
void paint(Painter& painter) override; void paint(Painter& painter) override;
private: private:
std::vector<Label> * labels_; std::vector<Label> labels_;
}; };
class BigFrequency : public Widget { class BigFrequency : public Widget {

Binary file not shown.

Binary file not shown.