add todo setup

This commit is contained in:
2025-12-21 00:36:00 +01:00
parent 36f8b6d8b2
commit 22a1b7e369
13 changed files with 277 additions and 31 deletions

View File

@@ -1,9 +0,0 @@
#include <gtkmm/label.h>
#include "widgets/todo.hpp"
Todo::Todo(std::string icon, std::string title) : Popover(icon, title) {
auto label = Gtk::make_managed<Gtk::Label>(title);
label->add_css_class("todo-label");
this->set_popover_child(*label);
}

View File

@@ -0,0 +1,78 @@
#include "widgets/todoPopover.hpp"
#include <gtkmm/box.h>
#include <gtkmm/entry.h>
#include <string>
TodoPopover::TodoPopover(std::string icon, std::string title) : Popover(icon, title) {
this->name = title;
this->popover->set_size_request(300, -1);
container.set_orientation(Gtk::Orientation::VERTICAL);
container.set_spacing(10);
container.add_css_class("todo-popover-container");
auto entry = Gtk::make_managed<Gtk::Entry>();
entry->set_placeholder_text("Enter your to-do item...");
entry->add_css_class("todo-input");
entry->set_hexpand(true);
entry->set_halign(Gtk::Align::FILL);
entry->set_valign(Gtk::Align::START);
inputArea.append(*entry);
inputArea.add_css_class("todo-input-area");
inputArea.set_hexpand(true);
inputArea.set_halign(Gtk::Align::FILL);
entry->signal_activate().connect([this, entry]() {
std::string text = entry->get_text();
if (!text.empty()) {
this->todoService->addTodo(text);
}
});
container.append(inputArea);
this->todoList = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL);
container.append(*todoList);
todoList->add_css_class("todo-list");
auto signal = sigc::signal<void()>();
this->todoService = new TodoService(signal);
signal.connect(sigc::mem_fun(*this, &TodoPopover::update));
this->set_popover_child(this->container);
this->update();
}
void TodoPopover::update() {
auto todos = this->todoService->getTodos();
Gtk::Widget* child = todoList->get_first_child();
while (child) {
Gtk::Widget* next = child->get_next_sibling();
bool found = false;
for (auto& [id, todo] : todos) {
if (child == todo) {
found = true;
break;
}
}
if (!found) {
todoList->remove(*child);
}
child = next;
}
for (auto &[id, todo] : todos) {
if (todo->get_parent() == nullptr) {
todoList->append(*todo);
}
}
}

View File

@@ -1,5 +1,4 @@
#include "widgets/webWidget.hpp"
#include <gtkmm/box.h>
#include <gtkmm/label.h>
#include <webkit/webkit.h>