Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/properties.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(EKG_VERSION 2.2.0)
set(EKG_VERSION 2.3.0)
set(EKG_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include")

if(CMAKE_TOOLCHAIN_FILE)
Expand Down
46 changes: 38 additions & 8 deletions include/ekg/core/pools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include "ekg/ui/label/label.hpp"
#include "ekg/ui/label/widget.hpp"

#include "ekg/ui/scrollbar/scrollbar.hpp"
#include "ekg/ui/scrollbar/widget.hpp"

namespace ekg::core {
void registry(ekg::property_t &property);
}
Expand All @@ -62,6 +65,7 @@ namespace ekg::core {
ekg_core_declare_widget_case_todo(ekg::frame_t, widget_descriptor_at, ekg_core_widget_todo); \
ekg_core_declare_widget_case_todo(ekg::button_t, widget_descriptor_at, ekg_core_widget_todo); \
ekg_core_declare_widget_case_todo(ekg::label_t, widget_descriptor_at, ekg_core_widget_todo); \
ekg_core_declare_widget_case_todo(ekg::scrollbar_t, widget_descriptor_at, ekg_core_widget_todo); \
}

#define ekg_registry_widget(widget_descriptor_t, register_widget_pool, register_property_pool, is_container, register_settings) \
Expand Down Expand Up @@ -123,6 +127,9 @@ namespace ekg {

ekg::pool<ekg::property_t> label_property {};
ekg::pool<ekg::label_t> label {};

ekg::pool<ekg::property_t> scrollbar_property {};
ekg::pool<ekg::scrollbar_t> scrollbar {};
} pools;

template<typename t>
Expand Down Expand Up @@ -156,6 +163,10 @@ namespace ekg {
return ekg::io::any_static_cast<t>(
&ekg::pools.label_property.query(at)
);
case ekg::type::scrollbar:
return ekg::io::any_static_cast<t>(
&ekg::pools.scrollbar_property.query(at)
);
}
case ekg::type::button:
return ekg::io::any_static_cast<t>(
Expand All @@ -169,6 +180,10 @@ namespace ekg {
return ekg::io::any_static_cast<t>(
&ekg::pools.label.query(at)
);
case ekg::type::scrollbar:
return ekg::io::any_static_cast<t>(
&ekg::pools.scrollbar.query(at)
);
}

return t::not_found;
Expand All @@ -186,8 +201,8 @@ namespace ekg {
ekg::pools.frame_property,
true,
{
property.widget.is_childnizate = true;
property.widget.is_children_docknizable = true;
property.is_childnizate = true;
property.is_children_docknizable = true;
widget.color_scheme = global_theme.frame_color_scheme;
}
);
Expand All @@ -200,8 +215,8 @@ namespace ekg {
ekg::pools.button_property,
false,
{
property.widget.is_childnizate = false;
property.widget.is_children_docknizable = false;
property.is_childnizate = false;
property.is_children_docknizable = false;
widget.color_scheme = global_theme.button_color_scheme;
}
);
Expand All @@ -212,14 +227,29 @@ namespace ekg {
ekg::label_t,
ekg::pools.label,
ekg::pools.label_property,
true,
false,
{
property.widget.is_childnizate = false;
property.widget.is_children_docknizable = false;
property.is_childnizate = false;
property.is_children_docknizable = false;
widget.color_scheme = global_theme.label_color_scheme;
}
);
}

case ekg::type::scrollbar: {
ekg_registry_widget(
ekg::scrollbar_t,
ekg::pools.scrollbar,
ekg::pools.scrollbar_property,
false,
{
property.is_childnizate = false;
property.is_children_docknizable = false;
widget.color_scheme = global_theme.scrollbar_color_scheme;
}
);
}

case ekg::type::stack: {
ekg::stack_t &stack {
ekg::pools.stack.push_back(
Expand All @@ -240,7 +270,7 @@ namespace ekg {
)
);
case ekg::type::sampler:
return ekg::io::any_static_cast<t>(
return ekg::io::any_static_cast<t>(
&ekg::pools.sampler.push_back(
ekg::io::any_static_cast<ekg::sampler_t>(&descriptor)
)
Expand Down
19 changes: 14 additions & 5 deletions include/ekg/draw/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,28 @@
#include "ekg/gpu/sampler.hpp"

/**
* This macro prevent from dispatching any GPU-data under a render section
* if the content is not visible to the parent rect_scissor.
* Each rendering section must begin with this, so we can do smart-caching
* for CPU-side.
**/
#define ekg_draw_allocator_assert_scissor(rect_scissor, rect_child, rect_parent, is_parented) \
if (!ekg::p_core->draw_allocator.sync_scissor(rect_scissor, rect_child, rect_parent, is_parented)) return;

#define ekg_draw_allocator_bind_local(p_geometry_buffer, p_gpu_data_buffer) \
ekg::p_core->draw_allocator.bind_local(p_geometry_buffer, p_gpu_data_buffer);

/**
* Each rendering section must end with this, for send buffers to GPU.
**/
#define ekg_draw_allocator_pass() \
ekg::p_core->draw_allocator.pass(); \
return;

/**
* This macro prevent from dispatching any GPU-data under a render section
* if the content is not visible to the parent rect_scissor.
**/
#define ekg_draw_allocator_assert_scissor(rect_scissor, rect_child, rect_parent, is_parented) \
if (!ekg::p_core->draw_allocator.sync_scissor(rect_scissor, rect_child, rect_parent, is_parented)) { \
ekg_draw_allocator_pass(); \
};

namespace ekg::draw {
class allocator {
public:
Expand Down
2 changes: 1 addition & 1 deletion include/ekg/handler/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace ekg {

struct input_info_t {
public:
float scroll_speed {0.4f};
float scroll_speed {1.0f};
ekg::timing_t ui_timeout_timing {};
ekg::timing_t ui_scrolling_timing {};
ekg::timing_t timing_last_interact {};
Expand Down
6 changes: 4 additions & 2 deletions include/ekg/handler/theme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ekg/ui/button/button.hpp"
#include "ekg/ui/frame/frame.hpp"
#include "ekg/ui/label/label.hpp"
#include "ekg/ui/scrollbar/scrollbar.hpp"

namespace ekg {
struct theme_t {
Expand All @@ -40,10 +41,11 @@ namespace ekg {
ekg::button_color_scheme_t button_color_scheme {};
ekg::frame_color_scheme_t frame_color_scheme {};
ekg::label_color_scheme_t label_color_scheme {};
ekg::scrollbar_color_scheme_t scrollbar_color_scheme {};
};

ekg::theme_t &theme(std::string_view tag = "");
ekg::theme_t &set_current_theme(std::string_view tag);
ekg::theme_t &theme(std::string tag = "");
ekg::theme_t &set_current_theme(const std::string &tag);
}

#endif
8 changes: 4 additions & 4 deletions include/ekg/handler/theme/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
namespace ekg::handler {
class theme {
protected:
std::string_view current_theme_tag {"dark-theme"};
std::map<std::string_view, ekg::theme_t> themes {};
std::string current_theme_tag {"dark-theme"};
std::map<std::string, ekg::theme_t> themes {};
public:
void init();
void quit();

ekg::theme_t &registry(const std::string_view &tag);
ekg::theme_t &registry(const std::string &tag);
ekg::theme_t &get_current_theme();
ekg::theme_t &set_current_theme(const std::string_view &tag);
ekg::theme_t &set_current_theme(const std::string &tag);
};
}

Expand Down
6 changes: 4 additions & 2 deletions include/ekg/io/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ namespace ekg {
hover,
active,
press,
release
release,
drag,
resize
};
constexpr size_t enum_action_size {static_cast<size_t>(ekg::action::release)+1};
constexpr size_t enum_action_size {static_cast<size_t>(ekg::action::resize)+1};

template<typename t, size_t s>
struct at_array_t {
Expand Down
2 changes: 1 addition & 1 deletion include/ekg/math/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ namespace ekg {
}

template<typename s>
ekg::rect_t<t> operator + (ekg::vec4_t<s> vec) {
ekg::rect_t<t> operator + (const ekg::vec4_t<s> &vec) {
return ekg::rect_t<t> {
this->x + static_cast<t>(vec.x),
this->y + static_cast<t>(vec.y),
Expand Down
4 changes: 2 additions & 2 deletions include/ekg/ui/button/button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "ekg/io/font.hpp"
#include "ekg/math/geometry.hpp"
#include "ekg/io/event.hpp"
#include "ekg/ui/property.hpp"

namespace ekg {
struct button_color_scheme_t {
Expand All @@ -51,8 +52,6 @@ namespace ekg {
public:
struct widget_t {
public:
bool is_highlight {};
bool is_active {};
ekg::rect_t<float> rect_text {};
ekg::rect_t<float> rect_box {};
};
Expand All @@ -63,6 +62,7 @@ namespace ekg {
ekg::flags_t box {ekg::dock::none};
ekg::flags_t dock {ekg::dock::left};
ekg::button_t::check_t::widget_t widget {};
ekg::property_t::states_t states {};
ekg::at_array_t<ekg::layer, ekg::enum_layer_size> layers {};
ekg::at_array_t<ekg::action, ekg::enum_action_size> actions {};
};
Expand Down
2 changes: 1 addition & 1 deletion include/ekg/ui/label/label.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace ekg {
ekg::at_t property_at {};
public:
std::string tag {};
ekg::rect_t<float> rect {};
ekg::rect_t<float> rect {0.0f, 0.0f, 75.0f, 0.0f};
ekg::value<std::string> text {};
ekg::flags_t dock {};
ekg::flags_t dock_text {};
Expand Down
29 changes: 18 additions & 11 deletions include/ekg/ui/property.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
namespace ekg {
struct property_t {
public:
struct states_t {
public:
bool is_absolute {};
bool is_active {};
bool is_hovering {};
bool is_visible {true};
bool is_enabled {true};
bool is_highlight {};
bool is_focused {};
bool is_warning {};
};

struct operation_t {
public:
bool should_reload {};
Expand All @@ -53,18 +65,8 @@ namespace ekg {
ekg::rect_t<float> rect_scissor {};
ekg::vec2_t<float> min_size {};
ekg::rect_t<float> rect {};
bool is_childnizate {};
bool is_children_docknizable {};
bool is_targeting_absolute_parent {};
bool is_absolute {};
bool is_active {};
bool is_hovering {};
bool is_visible {true};
bool is_enabled {true};
bool is_highlight {};
bool is_focused {};
bool is_warning {};
bool is_high_frequency {};
bool is_targeting_absolute_parent {};
bool should_refresh_size {true};
bool should_buffering {true};
};
Expand All @@ -75,8 +77,13 @@ namespace ekg {
ekg::at_t parent_at {ekg::at_t::not_found};
ekg::at_t abs_parent_at {ekg::at_t::not_found};
ekg::at_t descriptor_at {ekg::at_t::not_found};
ekg::at_t nearest_scrollbar_at {ekg::at_t::not_found};

bool is_childnizate {};
bool is_children_docknizable {};
std::vector<ekg::at_t> children {};
public:
ekg::property_t::states_t states {};
ekg::property_t::widget_t widget {};
ekg::property_t::scroll_t scroll {};
ekg::property_t::operation_t operation {};
Expand Down
74 changes: 74 additions & 0 deletions include/ekg/ui/scrollbar/scrollbar.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* MIT License
*
* Copyright (c) 2022-2025 Rina Wilk / [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef EKG_UI_SCROLLBAR_HPP
#define EKG_UI_SCROLLBAR_HPP

#include "ekg/ui/property.hpp"
#include "ekg/io/event.hpp"

namespace ekg {
struct scrollbar_color_scheme_t {
public:
ekg::rgba_t<uint8_t> background {};
ekg::rgba_t<uint8_t> outline {};

ekg::rgba_t<uint8_t> bar_background {};
ekg::rgba_t<uint8_t> bar_highlight {};
ekg::rgba_t<uint8_t> bar_active {};
ekg::rgba_t<uint8_t> bar_outline {};

ekg::pixel_thickness_t bar_thickness {8};
ekg::pixel_t bar_size_limit {20};
};

struct scrollbar_t {
public:
struct widget_t {
public:
ekg::property_t::states_t states_horizontal_bar {};
ekg::property_t::states_t states_vertical_bar {};
ekg::rect_t<float> rect_horizontal {};
ekg::rect_t<float> rect_vertical {};
ekg::rect_t<float> rect_delta {};
};
public:
static constexpr ekg::type type {ekg::type::scrollbar};
static ekg::scrollbar_t not_found;
public:
ekg::at_t property_at {};
public:
std::string tag {};
ekg::rect_t<float> rect {};
ekg::vec2_t<float> acceleration {};
ekg::scrollbar_color_scheme_t color_scheme {};
ekg::at_array_t<ekg::layer, ekg::enum_layer_size> layers {};
ekg::at_array_t<ekg::action, ekg::enum_action_size> actions {};
ekg::scrollbar_t::widget_t widget {};
ekg::flags_t dock {}; // useless
public:
ekg_descriptor(ekg::scrollbar_t);
};
}

#endif
Loading
Loading