use svg pre-rendered surfaces

This commit is contained in:
hippoz 2022-07-31 23:14:54 +03:00
parent 5bf39962ca
commit eceef00e48
Signed by: hippoz
GPG key ID: 7C52899193467641
5 changed files with 16 additions and 7 deletions

View file

@ -4,6 +4,8 @@ project(
default_options : ['cpp_std=c++17']
)
add_project_arguments('-O3', language : 'cpp')
raven_dep = dependency('raven')
executable(

View file

@ -16,7 +16,7 @@ void DirectoryView::set_current_path(std::filesystem::path path) {
target()->clear_children();
for (const auto &entry : std::filesystem::directory_iterator(m_current_path)) {
std::string filename = entry.path().filename();
auto button = m_target->add<FileButton>(
auto button = target()->add<FileButton>(
entry.path().filename(),
entry.is_directory() ? FileButton::ButtonType::Directory : FileButton::ButtonType::File
);
@ -44,8 +44,8 @@ void DirectoryView::on_init() {
set_current_path(go);
};
m_target = make_target();
m_target->set_layout<Raven::DocumentLayout>(16.0);
make_target();
target()->set_layout<Raven::DocumentLayout>(16.0);
set_did_init(true);
}

View file

@ -31,6 +31,5 @@ protected:
void on_init();
private:
std::filesystem::path m_current_path { "/" };
std::shared_ptr<Raven::Widget> m_target;
CheckpointStack<std::filesystem::path> m_checkpoint_stack {};
};

View file

@ -1,7 +1,8 @@
#include "FileButton.hpp"
#include "DirectoryView.hpp"
#include "SvgUtil.hpp"
Raven::GenericStyle FileButton::style = Raven::GenericStyle {
Raven::GenericStyle FileButton::style = {
pango_font_description_from_string("sans-serif"),
Raven::black6,
Raven::white3,
@ -12,6 +13,9 @@ Raven::GenericStyle FileButton::style = Raven::GenericStyle {
true
};
Cairo::RefPtr<Cairo::ImageSurface> FileButton::folder_icon = Raven::render_svg("/usr/share/icons/Papirus/64x64/places/folder-adwaita.svg", 0, 0, 64, 64);
Cairo::RefPtr<Cairo::ImageSurface> FileButton::file_icon = Raven::render_svg("/usr/share/icons/Papirus/64x64/mimetypes/text-x-generic.svg", 0, 0, 64, 64);
void FileButton::on_init() {
rect().set_width(64);
rect().set_height(88);
@ -23,9 +27,9 @@ void FileButton::on_init() {
layout->slot_pixel(24); // name (text)
if (m_button_type == ButtonType::Directory) {
add<Raven::SvgWidget>("/usr/share/icons/Papirus/64x64/places/folder-adwaita.svg");
add<Raven::SvgWidget>(folder_icon);
} else if (m_button_type == ButtonType::File) {
add<Raven::SvgWidget>("/usr/share/icons/Papirus/64x64/mimetypes/text-x-generic.svg");
add<Raven::SvgWidget>(file_icon);
}
auto label = add<Raven::Label>(m_name, Raven::PaintTextAlign::Center);
label->rect().set_max_width(rect().width());

View file

@ -2,6 +2,8 @@
#include <memory>
#include <string>
#include "cairomm/refptr.h"
#include "cairomm/surface.h"
#include "raven/Widget.hpp"
#include "raven/BoxLayout.hpp"
#include "raven/Label.hpp"
@ -12,6 +14,8 @@
class FileButton : public Raven::Widget {
public:
static Raven::GenericStyle style;
static Cairo::RefPtr<Cairo::ImageSurface> folder_icon;
static Cairo::RefPtr<Cairo::ImageSurface> file_icon;
enum class ButtonType {
Directory,