From 0ee7786a2b1c77c87df598864c7425782aeee006 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Sat, 29 Oct 2022 14:09:25 +0300 Subject: [PATCH] initial commit --- .gitignore | 3 +++ meson.build | 14 +++++++++++ src/AppWidget.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++ src/AppWidget.hpp | 18 ++++++++++++++ src/main.cpp | 17 +++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 .gitignore create mode 100644 meson.build create mode 100644 src/AppWidget.cpp create mode 100644 src/AppWidget.hpp create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d28b126 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.cache/ +builddir/ +compile_commands.json \ No newline at end of file diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..0abd109 --- /dev/null +++ b/meson.build @@ -0,0 +1,14 @@ +project( + 'waffle', + 'cpp', + default_options : ['cpp_std=c++17'] +) + +raven_dep = dependency('raven') + +executable( + 'waffle', + './src/AppWidget.cpp', + './src/main.cpp', + dependencies : [raven_dep] +) \ No newline at end of file diff --git a/src/AppWidget.cpp b/src/AppWidget.cpp new file mode 100644 index 0000000..9a4e8d3 --- /dev/null +++ b/src/AppWidget.cpp @@ -0,0 +1,62 @@ +#include "AppWidget.hpp" +#include "raven/Styles.hpp" +#include "raven/Box.hpp" +#include "raven/TextInput.hpp" +#include "raven/Button.hpp" +#include "raven/ScrollContainer.hpp" +#include "raven/Widget.hpp" +#include "raven/ListLayout.hpp" +#include "raven/BoxLayout.hpp" +#include "raven/Label.hpp" +#include "raven/DocumentLayout.hpp" + +void AppWidget::on_init() { + /* init */ + { + auto layout = set_layout(Raven::Direction::Vertical); + layout->set_spacing(8); + layout->set_margin(12); + } + + // TODO: this won't work because the document layout depends on the parent layout for its width, and the parent layout depends on the document layout outcome, thus creating a circular dependency in layouting, which makes things not work properly on the first relayout + /* top bar */ + { + m_top_bar = add(); + m_top_bar->rect().set_min_height(42.0); + m_top_bar->set_layout(8.0); + m_top_bar->set_style(&Raven::raised_widget_style); + m_top_bar->set_grows(false); + } + + /* message list */ + { + m_message_list = add(); + m_message_list->set_grows(true); + auto target = m_message_list->make_target(); + auto target_layout = target->set_layout(Raven::Direction::Vertical); + target_layout->set_inherit_secondary_dimension(true); + target_layout->set_margin(8); + target_layout->set_spacing(6); + } + + /* message input */ + { + m_message_input = add(); + m_message_input->rect().set_min_height(38.0); + } + + /* dummy data */ + { + for (int i = 0; i < 20; i++) { + auto button = m_top_bar->add("channel " + std::to_string(i)); + button->set_style(&Raven::raised_button_style); + } + + for (int i = 0; i < 200; i++) { + m_message_list->target()->add(" message " + std::to_string(i)); + } + } + + reflow(); + set_did_init(true); +} \ No newline at end of file diff --git a/src/AppWidget.hpp b/src/AppWidget.hpp new file mode 100644 index 0000000..508abc2 --- /dev/null +++ b/src/AppWidget.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "raven/ScrollContainer.hpp" +#include "raven/Widget.hpp" +#include "raven/TextInput.hpp" + +class AppWidget : public Raven::Widget { +public: + AppWidget() + : Raven::Widget() {} + +protected: + void on_init() override; +private: + std::shared_ptr m_top_bar; + std::shared_ptr m_message_list; + std::shared_ptr m_message_input; +}; diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..7d4c36b --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,17 @@ +#include +#include "raven/Window.hpp" +#include "raven/Application.hpp" +#include "raven/Widget.hpp" +#include "raven/Button.hpp" +#include "AppWidget.hpp" + +int main() +{ + Raven::Application application {}; + auto window = application.add_window(); + window->spawn_window(); + + window->set_main_widget(); + + return application.run(); +}