handle text bounds using pango
This commit is contained in:
parent
5744ee7add
commit
992ef1e3d6
5 changed files with 12 additions and 5 deletions
|
@ -3,6 +3,7 @@
|
|||
#include "Box.hpp"
|
||||
#include "Window.hpp"
|
||||
#include "Painter.hpp"
|
||||
#include "pango/pango-layout.h"
|
||||
#include <pango/pangocairo.h>
|
||||
|
||||
namespace Raven {
|
||||
|
@ -30,7 +31,7 @@ void Button::on_paint() {
|
|||
auto text_color = get_styles()->get_button_text_color();
|
||||
painter.source_rgb(text_color);
|
||||
painter.set_pango_font_description(get_styles()->get_controls_font_description());
|
||||
painter.text(get_current_geometry(), m_text, PaintTextAlign::Center);
|
||||
painter.text(get_current_geometry(), m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_END);
|
||||
painter.fill();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "Label.hpp"
|
||||
#include "Window.hpp"
|
||||
#include "pango/pango-layout.h"
|
||||
|
||||
namespace Raven {
|
||||
|
||||
|
@ -18,7 +19,7 @@ void Label::on_paint() {
|
|||
|
||||
painter.source_rgb(text_color);
|
||||
painter.set_pango_font_description(get_styles()->get_controls_font_description());
|
||||
painter.text(get_current_geometry(), m_text, PaintTextAlign::Center);
|
||||
painter.text(get_current_geometry(), m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_NONE);
|
||||
painter.fill();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "Painter.hpp"
|
||||
#include "RGB.hpp"
|
||||
#include "pango/pango-layout.h"
|
||||
#include "pango/pango-types.h"
|
||||
|
||||
namespace Raven {
|
||||
|
||||
|
@ -37,7 +39,7 @@ bool Painter::text(Point &where, std::string &text) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Painter::text(Box &geometry, std::string &text, PaintTextAlign align) {
|
||||
bool Painter::text(Box &geometry, std::string &text, PaintTextAlign align, PangoEllipsizeMode ellipsize) {
|
||||
if (m_pango_font_description == nullptr)
|
||||
return false;
|
||||
|
||||
|
@ -47,6 +49,9 @@ bool Painter::text(Box &geometry, std::string &text, PaintTextAlign align) {
|
|||
int font_height;
|
||||
|
||||
pango_layout_set_font_description(layout, m_pango_font_description);
|
||||
pango_layout_set_width(layout, pango_units_from_double(geometry.get_width()));
|
||||
pango_layout_set_height(layout, pango_units_from_double(geometry.get_height()));
|
||||
pango_layout_set_ellipsize(layout, ellipsize);
|
||||
pango_layout_set_text(layout, text.c_str(), -1);
|
||||
|
||||
pango_layout_get_pixel_size(layout, &font_width, &font_height);
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
|
||||
void rounded_rectangle(Box &geometry, double border_radius);
|
||||
bool text(Point &where, std::string &text);
|
||||
bool text(Box &geometry, std::string &text, PaintTextAlign align);
|
||||
bool text(Box &geometry, std::string &text, PaintTextAlign align, PangoEllipsizeMode ellipsize);
|
||||
|
||||
void source_rgb(RGB &source_rgb);
|
||||
void fill();
|
||||
|
|
|
@ -10,7 +10,7 @@ int main() {
|
|||
|
||||
Raven::Window window {};
|
||||
Raven::Widget main_widget {};
|
||||
Raven::Button button {"click me"};
|
||||
Raven::Button button {"click meeeeeeeeeeee"};
|
||||
Raven::Label label {"click it!"};
|
||||
|
||||
window.spawn_window();
|
||||
|
|
Loading…
Reference in a new issue