Compare commits

..

9 commits

Author SHA1 Message Date
hippoz
112a3b83d3
add test to window 2022-07-26 01:06:51 +03:00
hippoz
cbbe90f57d
add clear_children function for widget 2022-07-26 01:06:40 +03:00
hippoz
32524f01e2
add scrollcontainer hack for width 2022-07-26 01:06:19 +03:00
hippoz
533b6ebe91
remove png function as it was not very useful 2022-07-26 01:06:07 +03:00
hippoz
801482efbf
add hack for label 2022-07-26 01:05:51 +03:00
hippoz
6dd0a1338f
fix documentlayout automatic sizing 2022-07-26 01:05:37 +03:00
hippoz
59e8806c9e
clean up some of the imports 2022-07-26 01:05:21 +03:00
hippoz
3139582373
hopefully fix library dependencies 2022-07-26 01:04:16 +03:00
hippoz
c63d94a651
new install script 2022-07-26 01:03:51 +03:00
15 changed files with 42 additions and 22 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
build/
builddir/ builddir/
buildclang/ buildclang/
releaseclang/ releaseclang/

View file

@ -74,7 +74,7 @@ pkg_mod.generate(
filebase : meson.project_name(), filebase : meson.project_name(),
description : project_description, description : project_description,
subdirs : meson.project_name(), subdirs : meson.project_name(),
libraries : raven_lib libraries : [raven_dependencies, raven_lib]
) )
executable( executable(

13
pkg/install.sh Executable file
View file

@ -0,0 +1,13 @@
#!/bin/sh
if ! command -v arch-meson &> /dev/null
then
echo "arch-meson not found, using meson"
meson build
else
echo "found arch-meson"
arch-meson . build
fi
meson compile -C build
meson install -C build --destdir "$DEST"

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "src/Layout.hpp" #include "Layout.hpp"
#include "src/Widget.hpp" #include "Widget.hpp"
#include "src/Box.hpp" #include "Box.hpp"
#include <memory> #include <memory>
#include <vector> #include <vector>

View file

@ -30,6 +30,7 @@ void Button::on_paint() {
auto painter = window()->painter(); auto painter = window()->painter();
painter.source_rgb(style()->foreground()); painter.source_rgb(style()->foreground());
// todo: do we use the max geometry like in Label?
painter.text(rect(), m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_END, style()->font_description()); painter.text(rect(), m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_END, style()->font_description());
painter.fill(); painter.fill();
} }

View file

@ -9,7 +9,7 @@ void DocumentLayout::run() {
if (!m_target) if (!m_target)
return; return;
Point bound { m_margin, m_margin }; Point bound { m_margin + m_target->rect().max_geometry().width(), m_margin };
Point current_position { m_margin, m_margin }; Point current_position { m_margin, m_margin };
double largest_height_so_far = -1.0; double largest_height_so_far = -1.0;
@ -36,10 +36,12 @@ void DocumentLayout::run() {
if (!new_row_because_of_control_widget) { if (!new_row_because_of_control_widget) {
current_position.add(child->rect().width() + m_margin, 0); current_position.add(child->rect().width() + m_margin, 0);
bound.add(child->rect().width() + m_margin, 0);
} }
} }
/* account for the first row */
bound.add(0, largest_height_so_far);
m_target->rect().set_width(bound.x()); m_target->rect().set_width(bound.x());
m_target->rect().set_height(bound.y()); m_target->rect().set_height(bound.y());
} }

View file

@ -25,9 +25,10 @@ void Label::on_init() {
void Label::on_paint() { void Label::on_paint() {
auto painter = window()->painter(); auto painter = window()->painter();
auto geometry = rect().max_geometry();
painter.source_rgb(style()->foreground()); painter.source_rgb(style()->foreground());
painter.text(rect(), m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_NONE, style()->font_description()); painter.text(geometry, m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_END, style()->font_description());
painter.fill(); painter.fill();
} }

View file

@ -102,11 +102,4 @@ void Painter::flush_paint_group() {
m_cairo->get_target()->flush(); m_cairo->get_target()->flush();
} }
Point Painter::png(std::string path) {
auto image = Cairo::ImageSurface::create_from_png(path.c_str());
m_cairo->set_source(image, 0, 0);
return Point(image->get_width(), image->get_height());
}
} }

View file

@ -30,7 +30,6 @@ public:
bool can_paint() { if (m_cairo) return true; else return false; } bool can_paint() { if (m_cairo) return true; else return false; }
void source_rgb(RGB source_rgb); void source_rgb(RGB source_rgb);
Point png(std::string path);
void fill(); void fill();
void begin_paint_group(); void begin_paint_group();

View file

@ -1,5 +1,5 @@
#include "ScrollContainer.hpp" #include "ScrollContainer.hpp"
#include "src/Styles.hpp" #include "Styles.hpp"
#include <iostream> #include <iostream>
#include <memory> #include <memory>
@ -11,6 +11,9 @@ void ScrollContainer::on_layout() {
m_target->rect().set_x(-m_scroll.x()); m_target->rect().set_x(-m_scroll.x());
m_target->rect().set_y(-m_scroll.y()); m_target->rect().set_y(-m_scroll.y());
// todo: doesn't work with horizontal scrolling
m_target->rect().set_min_width(rect().width());
m_target->rect().set_max_width(rect().width());
} }
std::shared_ptr<Widget> ScrollContainer::make_target() { std::shared_ptr<Widget> ScrollContainer::make_target() {

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "Widget.hpp" #include "Widget.hpp"
#include "src/Point.hpp" #include "Point.hpp"
#include <memory> #include <memory>
namespace Raven { namespace Raven {

View file

@ -106,6 +106,11 @@ void Widget::remove_child(std::shared_ptr<Widget> child) {
reflow(); reflow();
} }
void Widget::clear_children() {
m_children.clear();
reflow();
}
void Widget::repaint() { void Widget::repaint() {
if (m_window) if (m_window)
m_window->repaint(this); m_window->repaint(this);

View file

@ -55,6 +55,7 @@ public:
std::vector<std::shared_ptr<Widget>> &children() { return m_children; } std::vector<std::shared_ptr<Widget>> &children() { return m_children; }
bool add_child(std::shared_ptr<Widget> child); bool add_child(std::shared_ptr<Widget> child);
void remove_child(std::shared_ptr<Widget> child); void remove_child(std::shared_ptr<Widget> child);
void clear_children();
Box &rect() { return m_rect; } Box &rect() { return m_rect; }
void set_rect(Box rect) { m_rect = rect; reflow(); } void set_rect(Box rect) { m_rect = rect; reflow(); }

View file

@ -21,6 +21,7 @@ void Window::set_main_widget(std::shared_ptr<Widget> main_widget) {
bool Window::spawn_window() { bool Window::spawn_window() {
Display *dsp = XOpenDisplay(NULL); Display *dsp = XOpenDisplay(NULL);
XSynchronize(dsp, False);
if (dsp == NULL) { if (dsp == NULL) {
std::cerr << "error: XOpenDisplay(NULL)" << "\n"; std::cerr << "error: XOpenDisplay(NULL)" << "\n";
return false; return false;

View file

@ -8,10 +8,10 @@
#include "RGB.hpp" #include "RGB.hpp"
#include "DocumentLayout.hpp" #include "DocumentLayout.hpp"
#include "Events.hpp" #include "Events.hpp"
#include "src/BoxLayout.hpp" #include "BoxLayout.hpp"
#include "src/Box.hpp" #include "Box.hpp"
#include "src/ScrollContainer.hpp" #include "ScrollContainer.hpp"
#include "src/Styles.hpp" #include "Styles.hpp"
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <string> #include <string>
@ -24,7 +24,7 @@ protected:
void on_paint() { void on_paint() {
if (!painter()) return; if (!painter()) return;
painter()->png("tuna.png"); //painter()->png("tuna.png");
painter()->cairo()->paint(); painter()->cairo()->paint();
} }
}; };