"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 ?
//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: Sort by category in edit screen
//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;
add_children({
&text_setfreq,
&labels,
&button_setfreq,
&text_bps,
&options_bps,
&text_mark,
&field_mark,
&text_space,
&field_space,
&text_bw,
&field_bw,
&text_repeat,
&field_repeat,
&text_format,
&options_format,
&button_save
});

View File

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

View File

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

View File

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

View File

@ -42,11 +42,14 @@ int Painter::draw_char(const Point p, const Style& style, const char c) {
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;
for(const auto c : text) {
const auto glyph = style.font.glyph(c);
display.draw_glyph(p, glyph, style.foreground, style.background);
const auto glyph = font.glyph(c);
display.draw_glyph(p, glyph, foreground, background);
const auto advance = glyph.advance();
p += advance;
width += advance.x();
@ -54,6 +57,10 @@ int Painter::draw_string(Point p, const Style& style, const std::string text) {
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) {
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_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);
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(
std::vector<Label> * labels
std::initializer_list<Label> labels
) : labels_ { labels }
{
}
void Labels::set_labels(std::vector<Label> * const labels) {
void Labels::set_labels(std::initializer_list<Label> labels) {
labels_ = labels;
set_dirty();
}
void Labels::paint(Painter& painter) {
/*const auto rect = screen_rect();
const auto s = style();
painter.fill_rectangle(rect, s.background);
painter.draw_string(
rect.location(),
s,
text
);*/
for (auto &label : labels_) {
painter.draw_string(
label.pos + screen_pos(),
style().font,
label.color,
style().background,
label.text
);
}
}
/* BigFrequency **********************************************************/

View File

@ -27,6 +27,7 @@
#include "ui_text.hpp"
#include "ui_painter.hpp"
#include "ui_focus.hpp"
#include "ui_font_fixed_8x16.hpp"
#include "radio.hpp"
#include "portapack.hpp"
@ -224,14 +225,14 @@ public:
Labels& operator=(const 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;
private:
std::vector<Label> * labels_;
std::vector<Label> labels_;
};
class BigFrequency : public Widget {

Binary file not shown.

Binary file not shown.