The layout is now configured in a .json file so you can change it.

master
Zed A. Shaw 2 days ago
parent 8abdc5f6c5
commit ba911f8703
  1. 22
      assets/layouts.json
  2. 5
      meson.build
  3. 3
      sample/about-bezos.md
  4. 41
      src/slides_ui.cpp
  5. 4
      src/slides_ui.hpp
  6. 9
      wraps/utf8cpp.wrap

@ -0,0 +1,22 @@
{
"default_ui": [
"[t_left|t_center|t_right]",
"[*%(300,500)slide|_|_|*%(200,500)alternate|_]",
"[_|_|_|_|_]",
"[_|_|_|_|_]",
"[_|_|_|_|_]",
"[_|_|_|_|_]",
"[_]",
"[title|*%(200,100)description|_|_|_]"
],
"default_slide": [
"[=*%(300,200)title|_|_]",
"[_|_|_]",
"[*%(300,600)content|_|_]",
"[_|_|_]",
"[_|_|_]",
"[_|_|_]",
"[_|_|_]",
"[_|_|_]"
]
}

@ -1,7 +1,7 @@
# clang might need _LIBCPP_ENABLE_CXX26_REMOVED_CODECVT
project('bezos-loves-slides', 'cpp',
version: '0.1.0',
version: '0.2.0',
default_options: [
'cpp_std=c++20',
'cpp_args=-D_GLIBCXX_DEBUG=1 -D_GLIBCXX_DEBUG_PEDANTIC=1',
@ -76,13 +76,14 @@ sfml_system = subproject('sfml').get_variable('sfml_system_dep')
sfml_window = subproject('sfml').get_variable('sfml_window_dep')
lel_guecs = subproject('lel-guecs').get_variable('lel_guecs_dep')
lel_guecs_sfml = subproject('lel-guecs').get_variable('lel_guecs_sfml_dep')
utf8cpp = subproject('utf8cpp').get_variable('utf8cpp_dep')
dependencies += [
fmt, json, freetype2,
flac, ogg, vorbis, vorbisfile, vorbisenc,
sfml_audio, sfml_graphics,
sfml_network, sfml_system,
sfml_window, lel_guecs, lel_guecs_sfml
sfml_window, lel_guecs, lel_guecs_sfml, utf8cpp
]

@ -1,7 +1,8 @@
{
"title": "How to use Bezos",
"description": "A short presentation on Bezos.",
"font_file": "assets/bold.otf"
"font_file": "assets/bold.otf",
"layouts": "assets/layouts.json"
}
===
# Bezos Slide Format

@ -3,6 +3,7 @@
#include <fmt/xchar.h>
#include <deque>
#include <iostream>
#include <fstream>
#include <nlohmann/json.hpp>
#include "dbc.hpp"
#include <memory>
@ -25,20 +26,12 @@ Slide::Slide(const string& title, const string& content, json& config, json& dec
config_text($content_font, $config);
}
void Slide::init(lel::Cell& cell) {
void Slide::init(lel::Cell& cell, const std::string& layout) {
if(!$initialized) {
$initialized = true;
$gui.position(cell.x, cell.y, cell.w, cell.h);
$gui.layout(
"[=*%(300,200)title|_|_]"
"[_|_|_]"
"[*%(300,600)content|_|_]"
"[_|_|_]"
"[_|_|_]"
"[_|_|_]"
"[_|_|_]"
"[_|_|_]");
$gui.layout(layout);
auto title = $gui.entity("title");
$gui.set<guecs::Text>(title, $title_font);
@ -82,6 +75,7 @@ SlidesUI::SlidesUI(shared_ptr<SlideDeck> deck) {
dbc::check(deck->slides.size() > 0, "slide deck is empy");
$deck = deck;
$current = 0;
configure_layouts();
}
void SlidesUI::set_text(const std::string& name) {
@ -98,16 +92,7 @@ void SlidesUI::set_text(const std::string& name) {
void SlidesUI::init() {
$gui.position(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
$gui.layout(
"[t_left|t_center|t_right]"
"[*%(300,500)slide|_|_|_|_]"
"[_|_|_|_|_]"
"[_|_|_|_|_]"
"[_|_|_|_|_]"
"[_|_|_|_|_]"
"[_]"
"[title|*%(200,100)description|_|_|_]"
);
$gui.layout($layouts["default_ui"]);
set_text("title");
set_text("description");
@ -172,7 +157,8 @@ void SlidesUI::show_slide() {
bg.init();
auto& cell = $gui.cell_for("slide");
slide.init(cell);
auto& layout = $layouts["default_slide"];
slide.init(cell, layout);
}
void SlidesUI::render(sf::RenderWindow& window) {
@ -204,3 +190,16 @@ void SlidesUI::handle_events(sf::RenderWindow& presenter, const sf::Event& event
}
}
}
void SlidesUI::configure_layouts() {
std::ifstream in_file{$deck->config["layouts"]};
json layout_config = json::parse(in_file);
for(auto& [name, layout_list] : layout_config.items()) {
std::string layout;
for(auto& line : layout_list) {
layout += line;
}
$layouts.try_emplace(name, layout);
}
}

@ -21,7 +21,7 @@ struct Slide {
Slide() {}
void init(lel::Cell& cell);
void init(lel::Cell& cell, const std::string& layout);
void render(sf::RenderWindow& window);
void config_text(guecs::Text &result, nlohmann::json& config);
};
@ -36,6 +36,7 @@ struct SlideDeck {
struct SlidesUI {
guecs::UI $gui;
std::shared_ptr<SlideDeck> $deck = nullptr;
std::unordered_map<std::string, std::string> $layouts;
size_t $current = 0;
SlidesUI(std::shared_ptr<SlideDeck> deck);
@ -50,4 +51,5 @@ struct SlidesUI {
void mouse(float x, float y, guecs::Modifiers mods);
void set_text(const std::string& name);
void handle_events(sf::RenderWindow& presenter, const sf::Event& event);
void configure_layouts();
};

@ -0,0 +1,9 @@
[wrap-git]
directory=utf8cpp-4.0.9
url=https://github.com/nemtrif/utfcpp.git
revision=v4.0.9
depth=1
method=cmake
[provide]
utf8cpp = utf8cpp_dep
Loading…
Cancel
Save