renderer: Use interface to render offset

This commit is contained in:
patrick96 2021-01-06 15:46:57 +01:00 committed by Patrick Ziegler
parent c676d7e6f5
commit 5d518e171e
9 changed files with 39 additions and 19 deletions

View File

@ -7,6 +7,7 @@
#include "cairo/fwd.hpp"
#include "common.hpp"
#include "components/renderer_interface.hpp"
#include "components/types.hpp"
#include "events/signal_fwd.hpp"
#include "events/signal_receiver.hpp"
@ -32,12 +33,12 @@ struct alignment_block {
};
class renderer
: public signal_receiver<SIGN_PRIORITY_RENDERER, signals::ui::request_snapshot, signals::parser::change_background,
: public renderer_interface,
public signal_receiver<SIGN_PRIORITY_RENDERER, signals::ui::request_snapshot, signals::parser::change_background,
signals::parser::change_foreground, signals::parser::change_underline, signals::parser::change_overline,
signals::parser::change_font, signals::parser::change_alignment, signals::parser::reverse_colors,
signals::parser::offset_pixel, signals::parser::attribute_set, signals::parser::attribute_unset,
signals::parser::attribute_toggle, signals::parser::action_begin, signals::parser::action_end,
signals::parser::text, signals::parser::control> {
signals::parser::attribute_set, signals::parser::attribute_unset, signals::parser::attribute_toggle,
signals::parser::action_begin, signals::parser::action_end, signals::parser::text, signals::parser::control> {
public:
using make_type = unique_ptr<renderer>;
static make_type make(const bar_settings& bar);
@ -62,6 +63,8 @@ class renderer
void fill_borders();
void draw_text(const string& contents);
void render_offset(const tags::context& ctxt, int pixels) override;
protected:
double block_x(alignment a) const;
double block_y(alignment a) const;
@ -79,7 +82,6 @@ class renderer
bool on(const signals::parser::change_font& evt) override;
bool on(const signals::parser::change_alignment& evt) override;
bool on(const signals::parser::reverse_colors&) override;
bool on(const signals::parser::offset_pixel& evt) override;
bool on(const signals::parser::attribute_set& evt) override;
bool on(const signals::parser::attribute_unset& evt) override;
bool on(const signals::parser::attribute_toggle& evt) override;

View File

@ -0,0 +1,11 @@
#pragma once
#include "common.hpp"
#include "tags/context.hpp"
POLYBAR_NS
class renderer_interface {
public:
virtual void render_offset(const tags::context& ctxt, int pixels) = 0;
};
POLYBAR_NS_END

View File

@ -153,9 +153,6 @@ namespace signals {
struct reverse_colors : public detail::base_signal<reverse_colors> {
using base_type::base_type;
};
struct offset_pixel : public detail::value_signal<offset_pixel, int> {
using base_type::base_type;
};
struct attribute_set : public detail::value_signal<attribute_set, tags::attribute> {
using base_type::base_type;
};

View File

@ -52,7 +52,6 @@ namespace signals {
struct change_font;
struct change_alignment;
struct reverse_colors;
struct offset_pixel;
struct attribute_set;
struct attribute_unset;
struct attribute_toggle;

11
include/tags/context.hpp Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include "common.hpp"
POLYBAR_NS
namespace tags {
class context {};
} // namespace tags
POLYBAR_NS_END

View File

@ -1,6 +1,7 @@
#pragma once
#include "common.hpp"
#include "components/renderer_interface.hpp"
#include "errors.hpp"
POLYBAR_NS
@ -25,7 +26,7 @@ namespace tags {
static make_type make();
explicit dispatch(signal_emitter& emitter, const logger& logger);
void parse(const bar_settings& bar, string data);
void parse(const bar_settings& bar, renderer_interface&, string data);
protected:
void text(string&& data);

View File

@ -361,7 +361,7 @@ void bar::parse(string&& data, bool force) {
m_renderer->begin(rect);
try {
m_dispatch->parse(settings(), data);
m_dispatch->parse(settings(), *m_renderer, data);
} catch (const exception& err) {
m_log.err("Failed to parse contents (reason: %s)", err.what());
}

View File

@ -711,6 +711,11 @@ void renderer::draw_text(const string& contents) {
}
}
void renderer::render_offset(const tags::context&, int pixels) {
m_log.trace_x("renderer: offset_pixel(%f)", pixels);
m_blocks[m_align].x += pixels;
}
/**
* Colorize the bounding box of created action blocks
*/
@ -813,12 +818,6 @@ bool renderer::on(const signals::parser::reverse_colors&) {
return true;
}
bool renderer::on(const signals::parser::offset_pixel& evt) {
m_log.trace_x("renderer: offset_pixel(%f)", evt.cast());
m_blocks[m_align].x += evt.cast();
return true;
}
bool renderer::on(const signals::parser::attribute_set& evt) {
m_log.trace_x("renderer: attribute_set(%i)", static_cast<int>(evt.cast()));
m_attr.set(static_cast<int>(evt.cast()), true);

View File

@ -37,7 +37,7 @@ namespace tags {
/**
* Process input string
*/
void dispatch::parse(const bar_settings& bar, string data) {
void dispatch::parse(const bar_settings& bar, renderer_interface& renderer, string data) {
tags::parser p;
p.set(std::move(data));
@ -67,7 +67,7 @@ namespace tags {
m_sig.emit(change_font{el.tag_data.font});
break;
case tags::syntaxtag::O:
m_sig.emit(offset_pixel{el.tag_data.offset});
renderer.render_offset(tags::context{}, el.tag_data.offset);
break;
case tags::syntaxtag::R:
m_sig.emit(reverse_colors{});