Code refactor and make update

This commit is contained in:
Corentin 2026-07-23 15:43:54 +09:00
commit 2a2044c632
Signed by: corentin
GPG key ID: 48C87E27C6C917F4
10 changed files with 35 additions and 44 deletions

View file

@ -12,6 +12,7 @@ class ContainerInterface
{
public:
virtual std::tuple<int, int> get_child_position(const std::size_t child_index [[maybe_unused]]) const = 0;
protected:
virtual std::size_t push_child(std::shared_ptr<Component> child) = 0;
virtual std::shared_ptr<Component> get_child(std::size_t index) const = 0;

View file

@ -20,4 +20,3 @@ protected:
};
} // namespace uui

View file

@ -1,4 +1,3 @@
#pragma once
#include <memory>
@ -19,8 +18,7 @@ protected:
std::size_t parent_index, const position_t x, const position_t y, const Direction direction);
GlButton(
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y,
const Direction direction):
GlButton(window, window_index, window, window_index, x, y, direction)
const Direction direction): GlButton(window, window_index, window, window_index, x, y, direction)
{}
virtual std::tuple<int, int> get_child_position(const std::size_t child_index) const;

View file

@ -1,8 +1,9 @@
#pragma once
// clang-format off
#define GLAD_GL_IMPLEMENTATION
#include "glad/glad.h"
#define GLFW_INCLUDE_VULKAN
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#define GLM_FORCE_RADIANS

44
make.py
View file

@ -1,50 +1,38 @@
#! python3
import os
from pathlib import Path
import shutil
from umake import get_hash, make
class Config:
CC = 'g++'
APPS = ['test/example_gl', 'test/benchmark_text', 'test/sample']
IGNORE_APPS = []
JOB_COUNT = int(os.cpu_count() * 0.8)
BIN_DIR = Path('bin')
INCLUDE_DIR = Path('include')
OBJECT_DIR = Path('obj')
SOURCE_DIR = Path('src')
COMMON_FLAGS = '-std=c++20 -fno-semantic-interposition'
COMMON_DEBUG_FLAGS = '-g -Og -DDEBUG'
COMMON_RELEASE_FLAGS = '-O2 -flto=auto'
COMPILE_FLAGS = f'-Wall -Wextra -Wpedantic -Wconversion -I{INCLUDE_DIR} `pkg-config --cflags glfw3 vulkan gl x11 freetype2`'
LINK_FLAGS = '-lpthread -ldl `pkg-config --libs glfw3 vulkan gl x11 freetype2`'
PRE_COMPILE_FUNCTION = None
CPP_SOURCES = [filepath for filepath in SOURCE_DIR.rglob('*.cpp') if not filepath.name.startswith('.')]
from umake.umake import get_hash, make, Config
def main():
config = Config()
def pre_compile():
# Copying OpenGL shaders
src_opengl_shader_path = Config.SOURCE_DIR / 'uui' / 'opengl' / 'shaders'
src_opengl_shader_path = config.source_dir / 'uui' / 'opengl' / 'shaders'
for shader_path in (
list(src_opengl_shader_path.rglob('*.vert'))
+ list(src_opengl_shader_path.rglob('*.frag'))):
out_path = Config.BIN_DIR / shader_path.relative_to(Config.SOURCE_DIR)
out_path = config.bin_dir / shader_path.relative_to(config.source_dir)
if out_path.exists() and get_hash(shader_path) == get_hash(out_path):
continue
if not out_path.parent.exists():
out_path.parent.mkdir(parents=True)
shutil.copy(shader_path, out_path)
Config.PRE_COMPILE_FUNCTION = pre_compile
make(Config)
config.apps = [str(p.relative_to(Path('src')))[:-4] for p in (config.source_dir / 'test').rglob('*.cpp')]
config.watch = True
config.common_flags = '-std=c++20 -fno-semantic-interposition'
config.common_debug_flags = '-g -Og -DDEBUG'
config.common_release_flags = '-O2 -flto=auto'
config.compile_flags = f'-Wall -Wextra -Wpedantic -Wconversion -I{config.include_dir} `pkg-config --cflags glfw3 gl x11 freetype2`'
config.link_flags = '-lpthread -ldl `pkg-config --libs glfw3 gl freetype2`'
config.pre_compile_function = pre_compile
make(config)
if __name__ == '__main__':

View file

@ -1,7 +1,7 @@
MAKE_PATH="."
UMAKE_PATH="umake"
.PHONY: all clean
.PHONY: all watch debug debug_watch clean lint
all:
@PYTHONPATH=$(UMAKE_PATH) python $(MAKE_PATH)/make.py

View file

@ -30,6 +30,8 @@ void uui::GlApplication::init()
std::cout << "Initialize the GlApplication" << std::endl;
// Init GLFW
// Avoiding libdecor would be better
// glfwInitHint(GLFW_WAYLAND_LIBDECOR, GLFW_WAYLAND_DISABLE_LIBDECOR);
glfwInit();
// Set all the required options for GLFW
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
@ -69,7 +71,7 @@ void uui::GlApplication::run()
if constexpr(debug_mode)
{
end_time = std::chrono::high_resolution_clock::now();
render_duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count();
render_duration = std::chrono::duration<float, std::milli>(end_time - start_time).count();
// std::cout << "Frame " << frame_count << ", duration: " << render_duration << std::endl;
if(frame_count > 0.0f && render_duration > 500.0f)
{

View file

@ -8,8 +8,8 @@
uui::GlLabel::GlLabel(
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent,
std::size_t parent_index, const LabelParams& params):
GlComponent(window, window_index, parent, parent_index, {params.x, params.y, 0.0f, 0.0f}),
text(params.text), text_color(params.text_color)
GlComponent(window, window_index, parent, parent_index, {params.x, params.y, 0.0f, 0.0f}), text(params.text),
text_color(params.text_color)
{
if constexpr(uui::Application::debug_mode)
std::cout << "Creating GlLabel " << parent_index << std::endl;
@ -27,9 +27,9 @@ uui::GlLabel::GlLabel(
void uui::GlLabel::render()
{
float text_x = _position_x.index() == 1 ? std::get<1>(_position_x) * static_cast<float>(_window->width())
: static_cast<float>(std::get<0>(_position_x));
: static_cast<float>(std::get<0>(_position_x));
float text_y = _position_y.index() == 1 ? std::get<1>(_position_y) * static_cast<float>(_window->height())
: static_cast<float>(std::get<0>(_position_y));
: static_cast<float>(std::get<0>(_position_y));
text_y += static_cast<float>(text_height) - 1;
glBindVertexArray(gl_vao);

View file

@ -58,10 +58,12 @@ void uui::GlStack::create_label(const StackLabelParams& params, uui::InitFunctio
std::tuple<int, int> uui::GlStack::get_child_position(const std::size_t child_index) const
{
int x = _position_x.index() == 0 ? std::get<0>(_position_x)
: static_cast<int>(std::get<1>(_position_x) * static_cast<float>(_window->width()));
int y = _position_y.index() == 0 ? std::get<0>(_position_y)
: static_cast<int>(std::get<1>(_position_y) * static_cast<float>(_window->height()));
int x = _position_x.index() == 0
? std::get<0>(_position_x)
: static_cast<int>(std::get<1>(_position_x) * static_cast<float>(_window->width()));
int y = _position_y.index() == 0
? std::get<0>(_position_y)
: static_cast<int>(std::get<1>(_position_y) * static_cast<float>(_window->height()));
if(child_index == 0)
return {x, y};

2
umake

@ -1 +1 @@
Subproject commit 797d6accd2fd4fd1faa742a6ec8039b6aad8d861
Subproject commit 933dea2b9e9da0b03489ea9dca3cd597fdd2d09e