add breadcrumb bar in the topbar
This commit is contained in:
parent
ba2f22b221
commit
51a75e9cc1
5 changed files with 54 additions and 13 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include "BoxLayout.hpp"
|
#include "BoxLayout.hpp"
|
||||||
#include "DirectoryView.hpp"
|
#include "DirectoryView.hpp"
|
||||||
#include "TopBar.hpp"
|
#include "TopBar.hpp"
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
void AppWidget::on_init() {
|
void AppWidget::on_init() {
|
||||||
auto layout = set_layout<Raven::BoxLayout>(Raven::Direction::Vertical);
|
auto layout = set_layout<Raven::BoxLayout>(Raven::Direction::Vertical);
|
||||||
|
@ -12,6 +13,14 @@ void AppWidget::on_init() {
|
||||||
auto top_bar = add<TopBar>();
|
auto top_bar = add<TopBar>();
|
||||||
auto directory_view = add<DirectoryView>();
|
auto directory_view = add<DirectoryView>();
|
||||||
|
|
||||||
|
directory_view->on_path_update = [top_bar](std::filesystem::path where) {
|
||||||
|
top_bar->breadcrumb_set(where);
|
||||||
|
};
|
||||||
|
|
||||||
|
top_bar->on_navigate = [directory_view](std::filesystem::path where) {
|
||||||
|
directory_view->navigate(where);
|
||||||
|
};
|
||||||
|
|
||||||
top_bar->on_action = [directory_view](TopBar::Action action) {
|
top_bar->on_action = [directory_view](TopBar::Action action) {
|
||||||
if (action == TopBar::Action::Back) {
|
if (action == TopBar::Action::Back) {
|
||||||
directory_view->go_back();
|
directory_view->go_back();
|
||||||
|
@ -24,5 +33,7 @@ void AppWidget::on_init() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
directory_view->navigate_home();
|
||||||
|
|
||||||
set_did_init(true);
|
set_did_init(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ DirectoryView::~DirectoryView() {}
|
||||||
|
|
||||||
void DirectoryView::set_current_path(std::filesystem::path path) {
|
void DirectoryView::set_current_path(std::filesystem::path path) {
|
||||||
m_current_path = path;
|
m_current_path = path;
|
||||||
|
on_path_update(m_current_path);
|
||||||
|
|
||||||
// microtasks defer execution of the callback until all external events are processed.
|
// microtasks defer execution of the callback until all external events are processed.
|
||||||
// if they're not used here and set_current_path() is called in a click or hover handler,
|
// if they're not used here and set_current_path() is called in a click or hover handler,
|
||||||
|
@ -34,7 +35,6 @@ void DirectoryView::on_init() {
|
||||||
|
|
||||||
m_target = make_target();
|
m_target = make_target();
|
||||||
m_target->set_layout<Raven::DocumentLayout>(16.0);
|
m_target->set_layout<Raven::DocumentLayout>(16.0);
|
||||||
navigate_home();
|
|
||||||
set_did_init(true);
|
set_did_init(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
@ -22,6 +23,8 @@ public:
|
||||||
void go_forward();
|
void go_forward();
|
||||||
void navigate_home();
|
void navigate_home();
|
||||||
void navigate_parent_directory();
|
void navigate_parent_directory();
|
||||||
|
|
||||||
|
std::function<void(std::filesystem::path)> on_path_update { [](std::filesystem::path _){} };
|
||||||
protected:
|
protected:
|
||||||
void set_current_path(std::filesystem::path path);
|
void set_current_path(std::filesystem::path path);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#include "TopBar.hpp"
|
#include "TopBar.hpp"
|
||||||
#include "raven/Styles.hpp"
|
#include "Styles.hpp"
|
||||||
#include "raven/Box.hpp"
|
#include "Box.hpp"
|
||||||
#include "raven/BoxLayout.hpp"
|
#include "BoxLayout.hpp"
|
||||||
#include "raven/SvgWidget.hpp"
|
#include "SvgWidget.hpp"
|
||||||
#include "raven/RowLayout.hpp"
|
#include "RowLayout.hpp"
|
||||||
|
#include "Button.hpp"
|
||||||
|
|
||||||
void TopBar::on_init() {
|
void TopBar::on_init() {
|
||||||
set_style(&Raven::accent_widget_style);
|
set_style(&Raven::accent_widget_style);
|
||||||
|
@ -22,8 +23,12 @@ void TopBar::on_init() {
|
||||||
auto home_button = add<Raven::SvgWidget>("/usr/share/icons/Papirus/24x24/actions/go-home.svg");
|
auto home_button = add<Raven::SvgWidget>("/usr/share/icons/Papirus/24x24/actions/go-home.svg");
|
||||||
home_button->set_style(&Raven::default_button_style);
|
home_button->set_style(&Raven::default_button_style);
|
||||||
|
|
||||||
|
m_breadcrumbs = add<Raven::Widget>();
|
||||||
|
m_breadcrumbs->set_style(&Raven::accent_widget_style);
|
||||||
|
auto breadcrumbs_layout = m_breadcrumbs->set_layout<Raven::BoxLayout>(Raven::Direction::Horizontal);
|
||||||
|
breadcrumbs_layout->set_spacing(8);
|
||||||
|
|
||||||
back_button->on_click = [this, back_button]() {
|
back_button->on_click = [this, back_button]() {
|
||||||
std::cout << back_button->rect().width() << ", " << back_button->rect().height() << std::endl;
|
|
||||||
on_action(Action::Back);
|
on_action(Action::Back);
|
||||||
};
|
};
|
||||||
forward_button->on_click = [this]() {
|
forward_button->on_click = [this]() {
|
||||||
|
@ -38,3 +43,18 @@ void TopBar::on_init() {
|
||||||
|
|
||||||
set_did_init(true);
|
set_did_init(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TopBar::breadcrumb_set(std::filesystem::path path) {
|
||||||
|
window()->queue_microtask([this, path]() {
|
||||||
|
m_breadcrumbs->clear_children();
|
||||||
|
|
||||||
|
std::filesystem::path current_path;
|
||||||
|
for (std::filesystem::path::iterator i = path.begin(); i != path.end(); i++) {
|
||||||
|
auto button = m_breadcrumbs->add<Raven::Button>(*i == "/" ? "/" : i->filename());
|
||||||
|
current_path /= *i;
|
||||||
|
button->on_click = [this, current_path]() {
|
||||||
|
on_navigate(current_path);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -1,22 +1,29 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Widget.hpp"
|
#include "Widget.hpp"
|
||||||
|
#include <filesystem>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class TopBar : public Raven::Widget {
|
class TopBar : public Raven::Widget {
|
||||||
public:
|
public:
|
||||||
enum class Action {
|
enum class Action {
|
||||||
Back = 0,
|
Back = 0,
|
||||||
Forward,
|
Forward,
|
||||||
Home,
|
Home,
|
||||||
ParentDirectory
|
ParentDirectory
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
TopBar()
|
TopBar()
|
||||||
: Raven::Widget() {}
|
: Raven::Widget() {}
|
||||||
|
|
||||||
|
void breadcrumb_set(std::filesystem::path path);
|
||||||
|
|
||||||
std::function<void(Action)> on_action { [](Action _){} };
|
std::function<void(Action)> on_action { [](Action _){} };
|
||||||
|
std::function<void(std::filesystem::path)> on_navigate { [](std::filesystem::path _){} };
|
||||||
protected:
|
protected:
|
||||||
void on_init();
|
void on_init();
|
||||||
private:
|
private:
|
||||||
|
std::shared_ptr<Raven::Widget> m_breadcrumbs;
|
||||||
|
std::filesystem::path m_breadcrumb_path { "/" };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue