From 90c3a0402af3daba14d78073ca204023201e512a Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Tue, 26 Jul 2022 01:09:13 +0300 Subject: [PATCH] initial commit --- .gitignore | 4 ++ meson.build | 14 +++++ src/main.cpp | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100644 .gitignore create mode 100644 meson.build create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5f9d7dc --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.cache/ +builddir/ +build/ +compile_commands.json diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..ea7c632 --- /dev/null +++ b/meson.build @@ -0,0 +1,14 @@ +project( + 'raven', + 'cpp', + default_options : ['cpp_std=c++17'] +) + +raven_dep = dependency('raven') +librsvg_dep = dependency('librsvg-2.0') + +executable( + 'filemanager', + './src/main.cpp', + dependencies : [raven_dep, librsvg_dep] +) diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..8fcb3a3 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,166 @@ +#include "GenericStyle.hpp" +#include "librsvg/rsvg.h" +#include "raven/Label.hpp" +#include "cairomm/refptr.h" +#include "cairomm/surface.h" +#include "raven/Window.hpp" +#include "raven/Widget.hpp" +#include "raven/Button.hpp" +#include "raven/Box.hpp" +#include "raven/Label.hpp" +#include "raven/Layout.hpp" +#include "raven/RGB.hpp" +#include "raven/DocumentLayout.hpp" +#include "raven/Events.hpp" +#include "raven/BoxLayout.hpp" +#include "raven/Box.hpp" +#include "raven/ScrollContainer.hpp" +#include "raven/Styles.hpp" +#include +#include +#include +#include +#include + +class SvgWidget : public Raven::Widget { +public: + SvgWidget(std::string path) + : Raven::Widget() + , m_path(path) {} + + ~SvgWidget() { + g_object_unref(m_file); + g_object_unref(m_handle); + } + + std::string &path() { return m_path; } + void set_path(std::string path) { m_path = path; repaint(); } +protected: + void on_init() { + m_file = g_file_new_for_path(m_path.c_str()); + m_handle = rsvg_handle_new_from_gfile_sync(m_file, RSVG_HANDLE_FLAGS_NONE, NULL, NULL); + + set_style(&Raven::clear_widget_style); + + if (!m_handle) + { + std::cerr << "could not load svg file: " << m_path << std::endl; + exit(EXIT_FAILURE); + } + + set_did_init(true); + } + + void on_paint() { + RsvgRectangle viewport = { + .x = 0.0, + .y = 0.0, + .width = rect().width(), + .height = rect().height(), + }; + + rsvg_handle_render_document(m_handle, painter()->cairo()->cobj(), &viewport, NULL); + } +private: + std::string m_path; + RsvgHandle *m_handle; + GFile *m_file; +}; + +class FileButton : public Raven::Widget { +public: + static Raven::GenericStyle style; +public: + FileButton(std::string name) + : Raven::Widget() + , m_name(name) {} + + std::function on_open { [](){} }; + + std::string &name() { return m_name; } +protected: + void on_init() { + rect().set_width(96); + rect().set_height(118); + + set_style(&style); + + auto layout = set_layout(Raven::Direction::Vertical); + layout->slot_percent(100); // icon + layout->slot_pixel(24); // name (text) + + add("folder-adwaita.svg"); + auto label = add(m_name); + label->rect().set_max_width(rect().width()); + label->rect().set_max_height(24); + set_did_init(true); + } + + void on_activation_update(Raven::ActivationUpdateEvent &event) { + if (event.activation_status() == false) { + on_open(); + } + } +private: + std::string m_name; +}; + +Raven::GenericStyle FileButton::style = Raven::GenericStyle { + pango_font_description_from_string("sans-serif"), + Raven::black6, + Raven::white3, + Raven::white2, + Raven::white1, + 0.0, + true, + true +}; + +class DirectoryView : public Raven::ScrollContainer { +public: + DirectoryView() + : Raven::ScrollContainer() {} + + void update() { + std::cout << "update(): path: " << m_current_path << std::endl; + window()->start_batch(); + m_target->clear_children(); + for (const auto &entry : std::filesystem::directory_iterator(m_current_path)) { + auto button = m_target->add(entry.path().filename()); + button->on_open = [this, button]() { + navigate_relative(button->name()); + }; + } + window()->end_batch(); + } + + void navigate(std::string path) { + m_current_path = path; + update(); + } + + void navigate_relative(std::string path) { + m_current_path /= path; + update(); + } +protected: + void on_init() { + m_target = make_target(); + m_target->set_layout(12.0); + update(); + set_did_init(true); + } +private: + std::filesystem::path m_current_path { "/" }; + std::shared_ptr m_target; +}; + +int main() { + Raven::Window window {}; + window.spawn_window(); + + auto main_widget = window.set_main_widget(); + + window.run(true); + return 0; +}