40 lines
825 B
C++
40 lines
825 B
C++
#include <iostream>
|
|
#include "Button.hpp"
|
|
#include "Box.hpp"
|
|
#include "Window.hpp"
|
|
#include "Painter.hpp"
|
|
#include "Styles.hpp"
|
|
#include "pango/pango-layout.h"
|
|
#include <pango/pangocairo.h>
|
|
|
|
namespace Raven {
|
|
|
|
void Button::set_text(std::string text) {
|
|
m_text = text;
|
|
|
|
if (window()) {
|
|
fit_text(text);
|
|
}
|
|
}
|
|
|
|
void Button::on_init() {
|
|
set_style(&default_button_style);
|
|
fit_text(m_text);
|
|
set_did_init(true);
|
|
}
|
|
|
|
void Button::on_paint() {
|
|
auto painter = window()->painter();
|
|
|
|
painter.source_rgb(style()->foreground());
|
|
painter.text(rect(), m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_END, style()->font_description());
|
|
painter.fill();
|
|
}
|
|
|
|
void Button::on_activation_update(ActivationUpdateEvent &event) {
|
|
if (event.activation_status() == false) {
|
|
on_click();
|
|
}
|
|
}
|
|
|
|
}
|