switch to using callbacks for filebutton

This commit is contained in:
hippoz 2022-07-30 17:03:10 +03:00
parent 997be0290b
commit 5bf39962ca
No known key found for this signature in database
GPG key ID: 7C52899193467641
3 changed files with 6 additions and 12 deletions

View file

@ -15,11 +15,14 @@ void DirectoryView::set_current_path(std::filesystem::path path) {
window()->queue_microtask([this]() { window()->queue_microtask([this]() {
target()->clear_children(); target()->clear_children();
for (const auto &entry : std::filesystem::directory_iterator(m_current_path)) { 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 = m_target->add<FileButton>(
entry.path().filename(), entry.path().filename(),
entry.is_directory() ? FileButton::ButtonType::Directory : FileButton::ButtonType::File, entry.is_directory() ? FileButton::ButtonType::Directory : FileButton::ButtonType::File
this
); );
button->on_click = [this, filename]() {
navigate_relative(filename);
};
} }
}); });
} }

View file

@ -32,9 +32,3 @@ void FileButton::on_init() {
label->rect().set_max_height(24); label->rect().set_max_height(24);
set_did_init(true); set_did_init(true);
} }
void FileButton::on_activation_update(Raven::ActivationUpdateEvent &event) {
if (event.activation_status() == false && m_directory_view) {
m_directory_view->navigate_relative(m_name);
}
}

View file

@ -18,18 +18,15 @@ public:
File File
}; };
public: public:
FileButton(std::string name, ButtonType button_type, DirectoryView* directory_view) FileButton(std::string name, ButtonType button_type)
: Raven::Widget() : Raven::Widget()
, m_directory_view(directory_view)
, m_button_type(button_type) , m_button_type(button_type)
, m_name(name) {} , m_name(name) {}
std::string &name() { return m_name; } std::string &name() { return m_name; }
protected: protected:
void on_init(); void on_init();
void on_activation_update(Raven::ActivationUpdateEvent &event);
private: private:
DirectoryView* m_directory_view;
ButtonType m_button_type; ButtonType m_button_type;
std::string m_name; std::string m_name;
}; };