initial commit
This commit is contained in:
commit
90c3a0402a
3 changed files with 184 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
.cache/
|
||||
builddir/
|
||||
build/
|
||||
compile_commands.json
|
14
meson.build
Normal file
14
meson.build
Normal file
|
@ -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]
|
||||
)
|
166
src/main.cpp
Normal file
166
src/main.cpp
Normal file
|
@ -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 <bits/types/FILE.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
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<void()> 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::BoxLayout>(Raven::Direction::Vertical);
|
||||
layout->slot_percent(100); // icon
|
||||
layout->slot_pixel(24); // name (text)
|
||||
|
||||
add<SvgWidget>("folder-adwaita.svg");
|
||||
auto label = add<Raven::Label>(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<FileButton>(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<Raven::DocumentLayout>(12.0);
|
||||
update();
|
||||
set_did_init(true);
|
||||
}
|
||||
private:
|
||||
std::filesystem::path m_current_path { "/" };
|
||||
std::shared_ptr<Raven::Widget> m_target;
|
||||
};
|
||||
|
||||
int main() {
|
||||
Raven::Window window {};
|
||||
window.spawn_window();
|
||||
|
||||
auto main_widget = window.set_main_widget<DirectoryView>();
|
||||
|
||||
window.run(true);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue