"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

@@ -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 {