srctree

Robin Linden parent 0a3c6210 49deedb8
deps: Update to SFML 3

.bazelrc added: 207, removed: 215, total 0
@@ -47,6 +47,8 @@ build:macos --cxxopt='-std=c++2b'
build:macos --host_cxxopt='-std=c++2b'
build:macos --cxxopt='-fno-rtti'
build:macos --host_cxxopt='-fno-rtti'
build:macos --objccopt='-ObjC++'
build:macos --objccopt='-std=c++2b'
 
build:windows --enable_runfiles
build:windows --action_env=LOCALAPPDATA # Quirk for running vswhere, remove when icu no-longer needed
 
.github/workflows/ci.yaml added: 207, removed: 215, total 0
@@ -81,7 +81,7 @@ jobs:
- name: Install
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends ${{ matrix.compiler }}-${{ matrix.version }} ${{ matrix.apt }} libx11-dev
sudo apt-get install --no-install-recommends ${{ matrix.compiler }}-${{ matrix.version }} ${{ matrix.apt }} libx11-dev libxi-dev
- uses: actions/cache@v4
with:
path: ~/.cache/bazel
@@ -136,7 +136,7 @@ jobs:
sudo apt-get install --no-install-recommends lcov clang-${{ matrix.version }} libclang-rt-${{ matrix.version }}-dev llvm-${{ matrix.version }}
echo "CC=clang-18" >> $GITHUB_ENV
echo "CXX=clang++-18" >> $GITHUB_ENV
- run: sudo apt-get install libx11-dev
- run: sudo apt-get install libx11-dev libxi-dev
- name: Coverage
run: bazel coverage ... ${{ matrix.bazel }}
- name: Summary
 
WORKSPACE added: 207, removed: 215, total 0
@@ -198,15 +198,15 @@ http_archive(
http_archive(
name = "imgui-sfml", # MIT
build_file = "//third_party:imgui-sfml.BUILD",
integrity = "sha256-BJfOzt904nj4IFAJF1VJvEZyOmODSBpOujTBzD+ORhY=",
patch_cmds = [
# Use glad for OpenGL instead of the system OpenGL headers.
"sed -i'' -e /OpenGL.hpp/d imgui-SFML.cpp",
"sed -i'' -e '4i\\\n#include <glad/gl.h>' imgui-SFML.cpp",
"sed -i'' -e '277i\\\n\\\tif (gladLoaderLoadGL() == 0) return false;' imgui-SFML.cpp",
"sed -i'' -e '4i\\\n#include <glad/gl.h>\\\n' imgui-SFML.cpp",
"sed -i'' -e '226i\\\n\\\tif (gladLoaderLoadGL() == 0) std::abort();\\\n' imgui-SFML.cpp",
],
sha256 = "b1195ca1210dd46c8049cfc8cae7f31cd34f1591da7de1c56297b277ac9c5cc0",
strip_prefix = "imgui-sfml-2.6",
url = "https://github.com/SFML/imgui-sfml/archive/v2.6.tar.gz",
strip_prefix = "imgui-sfml-2a4dc2d33a4891148bb1ab150cfcfd0cb33c2b8c",
url = "https://github.com/SFML/imgui-sfml/archive/2a4dc2d33a4891148bb1ab150cfcfd0cb33c2b8c.tar.gz",
)
 
# https://github.com/simdjson/simdjson
@@ -231,29 +231,15 @@ http_archive(
http_archive(
name = "sfml", # Zlib
build_file = "//third_party:sfml.BUILD",
integrity = "sha256-glNdueVxBdTzqK7avROGMd767cWTyrWJySS316Ef+50=",
integrity = "sha256-aA2n9DmKV2Z4fqnKad0cmkhxzzxINN362SJCXG95Lcg=",
patch_cmds = [
# Work around SFML check for enough bytes for a given UTF-8 character
# crashing in MSVC debug builds with "cannot seek string_view iterator
# after end".
# See: https://github.com/SFML/SFML/issues/2113
"sed -i'' -e 's/if (begin + trailingBytes < end)/if (trailingBytes < std::distance(begin, end))/' include/SFML/System/Utf.inl",
# SFML uses a non-standard include path to vulkan.h
# libvulkan-dev: /usr/include/vulkan/vulkan.h
"sed -i'' -e 's|vulkan.h|vulkan/vulkan.h|' src/SFML/Window/Win32/VulkanImplWin32.cpp",
"sed -i'' -e 's|vulkan.h|vulkan/vulkan.h|' src/SFML/Window/Unix/VulkanImplX11.cpp",
# SFML does non-standard things with std::basic_string<Uint32>.
# This will not compile with libc++19.
"sed -i'' -e '36i\\\n#ifdef _LIBCPP_VERSION\\\n' include/SFML/System/String.hpp",
"sed -i'' -e '37i\\\n#pragma clang diagnostic push\\\n' include/SFML/System/String.hpp",
"sed -i'' -e '38i\\\n#pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\\\n' include/SFML/System/String.hpp",
"sed -i'' -e '39i\\\n#endif\\\n' include/SFML/System/String.hpp",
"sed -i'' -e '619i\\\n#ifdef _LIBCPP_VERSION\\\n' include/SFML/System/String.hpp",
"sed -i'' -e '620i\\\n#pragma clang diagnostic pop\\\n' include/SFML/System/String.hpp",
"sed -i'' -e '621i\\\n#endif\\\n' include/SFML/System/String.hpp",
],
strip_prefix = "SFML-2.6.1",
url = "https://github.com/SFML/SFML/archive/2.6.1.tar.gz",
strip_prefix = "SFML-3.0.0-rc.1",
url = "https://github.com/SFML/SFML/archive/3.0.0-rc.1.tar.gz",
)
 
# https://github.com/gabime/spdlog
 
browser/gui/app.cpp added: 207, removed: 215, total 0
@@ -225,11 +225,10 @@ App::App(std::string browser_title, std::string start_page_hint, bool load_start
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0")),
create_font_system()},
browser_title_{std::move(browser_title)},
window_{sf::VideoMode(kDefaultResolutionX, kDefaultResolutionY), browser_title_},
window_{sf::VideoMode({kDefaultResolutionX, kDefaultResolutionY}), browser_title_},
url_buf_{std::move(start_page_hint)},
canvas_{std::make_unique<gfx::SfmlCanvas>(window_, static_cast<type::SfmlType &>(engine_.font_system()))} {
window_.setMouseCursor(cursor_);
window_.setIcon(16, 16, kBrowserIcon.data());
window_.setIcon({16, 16}, kBrowserIcon.data());
if (!ImGui::SFML::Init(window_)) {
spdlog::critical("imgui-sfml initialization failed");
std::abort();
@@ -269,148 +268,138 @@ void App::set_scale(unsigned scale) {
}
 
void App::step() {
sf::Event event{};
while (window_.pollEvent(event)) {
while (auto event = window_.pollEvent()) {
// ImGui needs a few iterations to do what it wants to do. This was
// pretty much picked at random after I still occasionally got
// unexpected results when giving it 2 iterations.
process_iterations_ = 5;
ImGui::SFML::ProcessEvent(event);
ImGui::SFML::ProcessEvent(window_, *event);
 
switch (event.type) {
case sf::Event::Closed: {
window_.close();
if (event->is<sf::Event::Closed>()) {
window_.close();
} else if (auto const *resized = event->getIf<sf::Event::Resized>()) {
canvas_->set_viewport_size(resized->size.x, resized->size.y);
if (maybe_page_) {
engine_.relayout(**maybe_page_, make_options());
on_layout_updated();
}
} else if (auto const *key_pressed = event->getIf<sf::Event::KeyPressed>()) {
if (ImGui::GetIO().WantCaptureKeyboard) {
break;
}
case sf::Event::Resized: {
canvas_->set_viewport_size(event.size.width, event.size.height);
if (maybe_page_) {
engine_.relayout(**maybe_page_, make_options());
on_layout_updated();
}
break;
}
case sf::Event::KeyPressed: {
if (ImGui::GetIO().WantCaptureKeyboard) {
 
switch (key_pressed->code) {
case sf::Keyboard::Key::J: {
scroll(key_pressed->shift ? -20 : -5);
break;
}
 
switch (event.key.code) {
case sf::Keyboard::Key::J: {
scroll(event.key.shift ? -20 : -5);
break;
}
case sf::Keyboard::Key::K: {
scroll(event.key.shift ? 20 : 5);
break;
}
case sf::Keyboard::Key::L: {
if (!event.key.control) {
break;
}
focus_url_input();
break;
}
case sf::Keyboard::Key::F1: {
render_debug_ = !render_debug_;
spdlog::info("Render debug: {}", render_debug_);
break;
}
case sf::Keyboard::Key::F2: {
switch_canvas();
spdlog::info("Switched canvas to {}", selected_canvas_ == Canvas::OpenGL ? "OpenGL" : "SFML");
break;
}
case sf::Keyboard::Key::F4: {
display_debug_gui_ = !display_debug_gui_;
spdlog::info("Display debug gui: {}", display_debug_gui_);
break;
}
case sf::Keyboard::Key::Left: {
if (!event.key.alt) {
break;
}
navigate_back();
break;
}
case sf::Keyboard::Key::Right: {
if (!event.key.alt) {
break;
}
navigate_forward();
break;
}
case sf::Keyboard::Key::Backspace: {
navigate_back();
break;
}
case sf::Keyboard::Key::R: {
if (!event.key.control) {
break;
}
reload();
break;
}
default:
break;
}
break;
}
case sf::Event::MouseMoved: {
if (!maybe_page_) {
case sf::Keyboard::Key::K: {
scroll(key_pressed->shift ? 20 : 5);
break;
}
 
auto window_position = geom::Position{event.mouseMove.x, event.mouseMove.y};
auto document_position = to_document_position(std::move(window_position));
auto const *hovered = get_hovered_node(document_position);
nav_widget_extra_info_ =
fmt::format("{},{}: {}", document_position.x, document_position.y, element_text(hovered));
 
// If imgui is dealing with the mouse, we do nothing and let imgui change the cursor.
if (ImGui::GetIO().WantCaptureMouse) {
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NoMouseCursorChange;
case sf::Keyboard::Key::L: {
if (!key_pressed->control) {
break;
}
focus_url_input();
break;
}
 
// Otherwise we tell imgui not to mess with the cursor, and change it according to what we're
// currently hovering over.
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
if (try_get_uri(hovered).has_value()) {
cursor_.loadFromSystem(sf::Cursor::Hand);
} else {
cursor_.loadFromSystem(sf::Cursor::Arrow);
}
window_.setMouseCursor(cursor_);
 
break;
}
case sf::Event::MouseButtonReleased: {
if (ImGui::GetIO().WantCaptureMouse || event.mouseButton.button != sf::Mouse::Left) {
case sf::Keyboard::Key::F1: {
render_debug_ = !render_debug_;
spdlog::info("Render debug: {}", render_debug_);
break;
}
 
auto window_position = geom::Position{event.mouseButton.x, event.mouseButton.y};
auto document_position = to_document_position(std::move(window_position));
auto const *hovered = get_hovered_node(std::move(document_position));
if (auto uri = try_get_uri(hovered); uri.has_value()) {
url_buf_ = std::string{*uri};
navigate();
}
 
break;
}
case sf::Event::MouseWheelScrolled: {
if (ImGui::GetIO().WantCaptureMouse
|| event.mouseWheelScroll.wheel != sf::Mouse::Wheel::VerticalWheel) {
case sf::Keyboard::Key::F2: {
switch_canvas();
spdlog::info("Switched canvas to {}", selected_canvas_ == Canvas::OpenGL ? "OpenGL" : "SFML");
break;
}
 
scroll(std::lround(event.mouseWheelScroll.delta) * kMouseWheelScrollFactor);
case sf::Keyboard::Key::F4: {
display_debug_gui_ = !display_debug_gui_;
spdlog::info("Display debug gui: {}", display_debug_gui_);
break;
}
case sf::Keyboard::Key::Left: {
if (!key_pressed->alt) {
break;
}
navigate_back();
break;
}
case sf::Keyboard::Key::Right: {
if (!key_pressed->alt) {
break;
}
navigate_forward();
break;
}
case sf::Keyboard::Key::Backspace: {
navigate_back();
break;
}
case sf::Keyboard::Key::R: {
if (!key_pressed->control) {
break;
}
reload();
break;
}
default:
break;
}
} else if (auto const *mouse_moved = event->getIf<sf::Event::MouseMoved>()) {
if (!maybe_page_) {
break;
}
default:
 
auto window_position = geom::Position{mouse_moved->position.x, mouse_moved->position.y};
auto document_position = to_document_position(std::move(window_position));
auto const *hovered = get_hovered_node(document_position);
nav_widget_extra_info_ =
fmt::format("{},{}: {}", document_position.x, document_position.y, element_text(hovered));
 
// If imgui is dealing with the mouse, we do nothing and let imgui change the cursor.
if (ImGui::GetIO().WantCaptureMouse) {
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NoMouseCursorChange;
break;
}
 
// Otherwise we tell imgui not to mess with the cursor, and change it according to what we're
// currently hovering over.
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
bool is_uri = try_get_uri(hovered).has_value();
if (is_uri) {
cursor_ = sf::Cursor::createFromSystem(sf::Cursor::Type::Hand);
} else {
cursor_ = sf::Cursor::createFromSystem(sf::Cursor::Type::Arrow);
}
 
if (cursor_) {
window_.setMouseCursor(*cursor_);
} else {
spdlog::warn("Unable to create cursor '{}'", is_uri ? "hand" : "arrow");
}
} else if (auto const *mouse_button_released = event->getIf<sf::Event::MouseButtonReleased>()) {
if (ImGui::GetIO().WantCaptureMouse || mouse_button_released->button != sf::Mouse::Button::Left) {
break;
}
 
auto window_position = geom::Position{mouse_button_released->position.x, mouse_button_released->position.y};
auto document_position = to_document_position(std::move(window_position));
auto const *hovered = get_hovered_node(std::move(document_position));
if (auto uri = try_get_uri(hovered); uri.has_value()) {
url_buf_ = std::string{*uri};
navigate();
}
 
break;
} else if (auto const *mouse_scroll = event->getIf<sf::Event::MouseWheelScrolled>()) {
if (ImGui::GetIO().WantCaptureMouse || mouse_scroll->wheel != sf::Mouse::Wheel::Vertical) {
break;
}
 
scroll(std::lround(mouse_scroll->delta) * kMouseWheelScrollFactor);
break;
}
}
 
@@ -446,7 +435,7 @@ int App::run() {
}
 
void App::navigate() {
window_.setIcon(16, 16, kBrowserIcon.data());
window_.setIcon({16, 16}, kBrowserIcon.data());
auto uri = [this] {
if (maybe_page_) {
spdlog::info("Completing '{}' with '{}'", url_buf_, (**maybe_page_).uri.uri);
@@ -570,7 +559,7 @@ void App::on_page_loaded() {
continue;
}
 
window_.setIcon(favicon.getSize().x, favicon.getSize().y, favicon.getPixelsPtr());
window_.setIcon({favicon.getSize().x, favicon.getSize().y}, favicon.getPixelsPtr());
break;
}
 
 
browser/gui/app.h added: 207, removed: 215, total 0
@@ -20,6 +20,7 @@
 
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
 
namespace browser::gui {
@@ -39,7 +40,7 @@ private:
tl::unexpected<engine::NavigationError>{{}}};
 
std::string browser_title_{};
sf::Cursor cursor_{};
std::optional<sf::Cursor> cursor_{};
sf::RenderWindow window_{};
sf::Clock clock_{};
std::string url_buf_{};
 
gfx/gfx_example.cpp added: 207, removed: 215, total 0
@@ -14,6 +14,7 @@
 
#include <array>
#include <cstdint>
#include <iostream>
#include <memory>
#include <string_view>
 
@@ -22,9 +23,12 @@ using namespace std::literals;
constexpr auto kHotPink = gfx::Color::from_rgb(0xff'69'b4);
 
int main(int argc, char **argv) {
sf::RenderWindow window{sf::VideoMode{800, 600}, "gfx"};
sf::RenderWindow window{sf::VideoMode{{800, 600}}, "gfx"};
window.setVerticalSyncEnabled(true);
window.setActive(true);
if (!window.setActive(true)) {
std::cerr << "Failed to set window active\n";
return 1;
}
 
type::SfmlType type;
 
@@ -39,17 +43,11 @@ int main(int argc, char **argv) {
 
bool running = true;
while (running) {
sf::Event event{};
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
running = false;
break;
case sf::Event::Resized:
canvas->set_viewport_size(event.size.width, event.size.height);
break;
default:
break;
while (auto event = window.pollEvent()) {
if (event->is<sf::Event::Closed>()) {
running = false;
} else if (auto const *resized = event->getIf<sf::Event::Resized>()) {
canvas->set_viewport_size(resized->size.x, resized->size.y);
}
}
 
 
gfx/sfml_canvas.cpp added: 207, removed: 215, total 0
@@ -35,6 +35,7 @@
#include <string>
#include <string_view>
#include <system_error>
#include <tuple>
 
using namespace std::literals;
 
@@ -59,7 +60,7 @@ sf::Font load_fallback_font() {
for (auto const &entry : get_font_dir_iterator(path)) {
if (std::filesystem::is_regular_file(entry) && entry.path().filename().string().ends_with(".ttf")) {
spdlog::info("Trying fallback {}", entry.path().string());
if (font.loadFromFile(entry.path().string())) {
if (font.openFromFile(entry.path().string())) {
spdlog::info("Using fallback {}", entry.path().string());
return font;
}
@@ -130,13 +131,14 @@ sf::Text::Style to_sfml(FontStyle style) {
} // namespace
 
SfmlCanvas::SfmlCanvas(sf::RenderTarget &target, type::SfmlType &type) : target_{target}, type_{type} {
border_shader_.loadFromMemory(
// TODO(robinlinden): Error-handling.
std::ignore = border_shader_.loadFromMemory(
std::string{reinterpret_cast<char const *>(gfx_basic_shader_vert), gfx_basic_shader_vert_len},
std::string{reinterpret_cast<char const *>(gfx_rect_shader_frag), gfx_rect_shader_frag_len});
}
 
void SfmlCanvas::set_viewport_size(int width, int height) {
sf::View viewport{sf::FloatRect{0, 0, static_cast<float>(width), static_cast<float>(height)}};
sf::View viewport{sf::FloatRect{{0, 0}, {static_cast<float>(width), static_cast<float>(height)}}};
target_.setView(viewport);
}
 
@@ -150,7 +152,7 @@ void SfmlCanvas::fill_rect(geom::Rect const &rect, Color color) {
auto scaled{translated.scaled(scale_)};
 
sf::RectangleShape drawable{{static_cast<float>(scaled.width), static_cast<float>(scaled.height)}};
drawable.setPosition(static_cast<float>(scaled.x), static_cast<float>(scaled.y));
drawable.setPosition({static_cast<float>(scaled.x), static_cast<float>(scaled.y)});
drawable.setFillColor(sf::Color{color.r, color.g, color.b, color.a});
target_.draw(drawable);
}
@@ -162,7 +164,7 @@ void SfmlCanvas::draw_rect(geom::Rect const &rect, Color const &color, Borders c
inner_rect.expanded({borders.left.size, borders.right.size, borders.top.size, borders.bottom.size})};
 
sf::RectangleShape drawable{{static_cast<float>(outer_rect.width), static_cast<float>(outer_rect.height)}};
drawable.setPosition(static_cast<float>(outer_rect.x), static_cast<float>(outer_rect.y));
drawable.setPosition({static_cast<float>(outer_rect.x), static_cast<float>(outer_rect.y)});
 
border_shader_.setUniform("resolution", target_.getView().getSize());
 
@@ -202,13 +204,12 @@ void SfmlCanvas::draw_text(geom::Position p,
auto font = find_font(type_, font_options);
assert(font != nullptr);
 
sf::Text drawable;
drawable.setFont(font->sf_font());
sf::Text drawable{font->sf_font()};
drawable.setString(sf::String::fromUtf8(cbegin(text), cend(text)));
drawable.setFillColor(sf::Color(color.as_rgba_u32()));
drawable.setCharacterSize(size.px * scale_);
drawable.setStyle(to_sfml(style));
drawable.setPosition(static_cast<float>(p.x), static_cast<float>(p.y));
drawable.setPosition({static_cast<float>(p.x), static_cast<float>(p.y)});
target_.draw(drawable);
}
 
@@ -223,10 +224,14 @@ void SfmlCanvas::draw_pixels(geom::Rect const &rect, std::span<std::uint8_t cons
// Textures need to be kept around while they're displayed. This will be
// cleared when the canvas is cleared.
sf::Texture &texture = textures_.emplace_back();
texture.create(static_cast<unsigned>(rect.width), static_cast<unsigned>(rect.height));
if (!texture.resize({static_cast<unsigned>(rect.width), static_cast<unsigned>(rect.height)})) {
spdlog::critical("Failed to resize texture");
std::terminate();
}
 
texture.update(rgba_data.data());
sf::Sprite sprite{texture};
sprite.setPosition(static_cast<float>(rect.x), static_cast<float>(rect.y));
sprite.setPosition({static_cast<float>(rect.x), static_cast<float>(rect.y)});
target_.draw(sprite);
sf::RectangleShape shape{{static_cast<float>(rect.width), static_cast<float>(rect.height)}};
shape.setTexture(&texture);
 
img/img_example.cpp added: 207, removed: 215, total 0
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2023-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -115,28 +115,25 @@ int main(int argc, char **argv) {
}
 
auto const &desktop = sf::VideoMode::getDesktopMode();
std::uint32_t window_width = std::clamp(width, 100u, desktop.width);
std::uint32_t window_height = std::clamp(height, 100u, desktop.height);
sf::RenderWindow window{sf::VideoMode{window_width, window_height}, "img"};
std::uint32_t window_width = std::clamp(width, 100u, desktop.size.x);
std::uint32_t window_height = std::clamp(height, 100u, desktop.size.y);
sf::RenderWindow window{sf::VideoMode{{window_width, window_height}}, "img"};
window.setVerticalSyncEnabled(true);
window.setActive(true);
if (!window.setActive(true)) {
std::cerr << "Failed to set window active\n";
return 1;
}
 
type::SfmlType type;
gfx::SfmlCanvas canvas{window, type};
 
bool running = true;
while (running) {
sf::Event event{};
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
running = false;
break;
case sf::Event::Resized:
canvas.set_viewport_size(event.size.width, event.size.height);
break;
default:
break;
while (auto event = window.pollEvent()) {
if (event->is<sf::Event::Closed>()) {
running = false;
} else if (auto const *resized = event->getIf<sf::Event::Resized>()) {
canvas.set_viewport_size(resized->size.x, resized->size.y);
}
}
 
 
third_party/sfml.BUILD added: 207, removed: 215, total 0
@@ -20,9 +20,18 @@ SFML_DEFINES = [
"_UNICODE",
]
 
cc_library(
name = "system_private_hdrs",
hdrs = glob(["src/SFML/System/*.hpp"]),
strip_include_prefix = "src/",
)
 
cc_library(
name = "system",
srcs = glob(["src/SFML/System/*.cpp"]) + select({
srcs = glob([
"src/SFML/System/*.cpp",
"src/SFML/System/*.hpp",
]) + select({
"@platforms//os:linux": glob([
"src/SFML/System/Unix/**/*.cpp",
"src/SFML/System/Unix/**/*.hpp",
@@ -95,7 +104,10 @@ cc_library(
defines = SFML_DEFINES,
implementation_deps = [":sf_glad"],
linkopts = select({
"@platforms//os:linux": ["-lX11"],
"@platforms//os:linux": [
"-lX11",
"-lXi",
],
"@platforms//os:windows": [
"-DEFAULTLIB:advapi32",
"-DEFAULTLIB:gdi32",
@@ -111,6 +123,7 @@ cc_library(
}),
deps = [
":system",
":system_private_hdrs",
"@vulkan",
] + select({
"@platforms//os:linux": [
@@ -128,9 +141,9 @@ objc_library(
include = [
"src/SFML/Window/*.cpp",
"src/SFML/Window/*.hpp",
"src/SFML/Window/OSX/*.cpp",
"src/SFML/Window/OSX/*.h",
"src/SFML/Window/OSX/*.hpp",
"src/SFML/Window/macOS/*.cpp",
"src/SFML/Window/macOS/*.h",
"src/SFML/Window/macOS/*.hpp",
],
exclude = [
"src/SFML/Window/EGLCheck.cpp",
@@ -149,8 +162,8 @@ objc_library(
includes = ["include/"],
linkopts = ["-ObjC"],
non_arc_srcs = glob([
"src/SFML/Window/OSX/*.m",
"src/SFML/Window/OSX/*.mm",
"src/SFML/Window/macOS/*.m",
"src/SFML/Window/macOS/*.mm",
]),
sdk_frameworks = [
"AppKit",
@@ -189,6 +202,7 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":system",
":system_private_hdrs",
":window",
"@freetype2",
"@stb//:image",
 
type/sfml.cpp added: 207, removed: 215, total 0
@@ -57,7 +57,7 @@ std::optional<std::string> find_path_to_font(std::string_view font_filename) {
 
Size SfmlFont::measure(std::string_view text, Px font_size, Weight weight) const {
sf::Text sf_text{
sf::String::fromUtf8(text.data(), text.data() + text.size()), font_, static_cast<unsigned>(font_size.v)};
font_, sf::String::fromUtf8(text.data(), text.data() + text.size()), static_cast<unsigned>(font_size.v)};
 
switch (weight) {
case Weight::Normal:
@@ -72,17 +72,17 @@ Size SfmlFont::measure(std::string_view text, Px font_size, Weight weight) const
int nbsp_extra_width = 0;
auto const nbsp_count = static_cast<int>(std::ranges::count(sf_text.getString(), std::uint32_t{0xA0}));
if (nbsp_count > 0) {
sf::Text sf_space{sf::String{" "}, font_, static_cast<unsigned>(font_size.v)};
sf::Text sf_space{font_, sf::String{" "}, static_cast<unsigned>(font_size.v)};
if (weight == Weight::Bold) {
sf_space.setStyle(sf::Text::Bold);
}
 
nbsp_extra_width = static_cast<int>(sf_space.getLocalBounds().width);
nbsp_extra_width = static_cast<int>(sf_space.getLocalBounds().size.x);
nbsp_extra_width *= nbsp_count;
}
 
auto bounds = sf_text.getLocalBounds();
return Size{static_cast<int>(bounds.width) + nbsp_extra_width, static_cast<int>(bounds.height)};
return Size{static_cast<int>(bounds.size.x) + nbsp_extra_width, static_cast<int>(bounds.size.y)};
}
 
std::optional<std::shared_ptr<IFont const>> SfmlType::font(std::string_view name) const {
@@ -91,7 +91,7 @@ std::optional<std::shared_ptr<IFont const>> SfmlType::font(std::string_view name
}
 
sf::Font font;
if (auto path = find_path_to_font(name); !path || !font.loadFromFile(*path)) {
if (auto path = find_path_to_font(name); !path || !font.openFromFile(*path)) {
font_cache_.insert(std::pair{std::string{name}, std::nullopt});
return std::nullopt;
}
 
type/sfml.h added: 207, removed: 215, total 0
@@ -21,7 +21,7 @@ namespace type {
 
class SfmlFont : public IFont {
public:
explicit SfmlFont(sf::Font const &font) : font_{font} {}
explicit SfmlFont(sf::Font font) : font_{std::move(font)} {}
 
Size measure(std::string_view text, Px font_size, Weight) const override;