initial commit

This commit is contained in:
hippoz 2022-10-29 14:09:25 +03:00
commit 0ee7786a2b
No known key found for this signature in database
GPG key ID: 7C52899193467641
5 changed files with 114 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.cache/
builddir/
compile_commands.json

14
meson.build Normal file
View file

@ -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]
)

62
src/AppWidget.cpp Normal file
View file

@ -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::BoxLayout>(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<Raven::Widget>();
m_top_bar->rect().set_min_height(42.0);
m_top_bar->set_layout<Raven::DocumentLayout>(8.0);
m_top_bar->set_style(&Raven::raised_widget_style);
m_top_bar->set_grows(false);
}
/* message list */
{
m_message_list = add<Raven::ScrollContainer>();
m_message_list->set_grows(true);
auto target = m_message_list->make_target();
auto target_layout = target->set_layout<Raven::ListLayout>(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<Raven::TextInput>();
m_message_input->rect().set_min_height(38.0);
}
/* dummy data */
{
for (int i = 0; i < 20; i++) {
auto button = m_top_bar->add<Raven::Button>("channel " + std::to_string(i));
button->set_style(&Raven::raised_button_style);
}
for (int i = 0; i < 200; i++) {
m_message_list->target()->add<Raven::Label>("<test> message " + std::to_string(i));
}
}
reflow();
set_did_init(true);
}

18
src/AppWidget.hpp Normal file
View file

@ -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<Raven::Widget> m_top_bar;
std::shared_ptr<Raven::ScrollContainer> m_message_list;
std::shared_ptr<Raven::TextInput> m_message_input;
};

17
src/main.cpp Normal file
View file

@ -0,0 +1,17 @@
#include <iostream>
#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<Raven::Window>();
window->spawn_window();
window->set_main_widget<AppWidget>();
return application.run();
}