From ba911f8703142e3dd295bcdaade8da5ad3b2ad8c Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 26 Apr 2026 23:31:56 -0400 Subject: [PATCH] The layout is now configured in a .json file so you can change it. --- assets/layouts.json | 22 ++++++++++++++++++++++ meson.build | 5 +++-- sample/about-bezos.md | 3 ++- src/slides_ui.cpp | 41 ++++++++++++++++++++--------------------- src/slides_ui.hpp | 4 +++- wraps/utf8cpp.wrap | 9 +++++++++ 6 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 assets/layouts.json create mode 100644 wraps/utf8cpp.wrap diff --git a/assets/layouts.json b/assets/layouts.json new file mode 100644 index 0000000..3bf4897 --- /dev/null +++ b/assets/layouts.json @@ -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|_|_]", + "[_|_|_]", + "[_|_|_]", + "[_|_|_]", + "[_|_|_]", + "[_|_|_]" + ] +} diff --git a/meson.build b/meson.build index e297b7f..645a83f 100644 --- a/meson.build +++ b/meson.build @@ -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 ] diff --git a/sample/about-bezos.md b/sample/about-bezos.md index c2eae67..861f38e 100644 --- a/sample/about-bezos.md +++ b/sample/about-bezos.md @@ -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 diff --git a/src/slides_ui.cpp b/src/slides_ui.cpp index 2dd436e..0c5a321 100644 --- a/src/slides_ui.cpp +++ b/src/slides_ui.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "dbc.hpp" #include @@ -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(title, $title_font); @@ -82,6 +75,7 @@ SlidesUI::SlidesUI(shared_ptr 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); + } +} diff --git a/src/slides_ui.hpp b/src/slides_ui.hpp index 4033b23..2ec2fd4 100644 --- a/src/slides_ui.hpp +++ b/src/slides_ui.hpp @@ -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 $deck = nullptr; + std::unordered_map $layouts; size_t $current = 0; SlidesUI(std::shared_ptr 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(); }; diff --git a/wraps/utf8cpp.wrap b/wraps/utf8cpp.wrap new file mode 100644 index 0000000..c1ae900 --- /dev/null +++ b/wraps/utf8cpp.wrap @@ -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