Skip to content

Commit 5b5c8f9

Browse files
committed
[ref][update] theme flags and refactored extentinze, remains docknize
1 parent b88884f commit 5b5c8f9

File tree

15 files changed

+338
-216
lines changed

15 files changed

+338
-216
lines changed

include/ekg/io/design.hpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef EKG_IO_DESIGN_HPP
2+
#define EKG_IO_DESIGN_HPP
3+
4+
#include "ekg/ui/button/button.hpp"
5+
#include "ekg/ui/checkbox/checkbox.hpp"
6+
#include "ekg/ui/combobox/combobox.hpp"
7+
#include "ekg/ui/frame/frame.hpp"
8+
#include "ekg/ui/label/label.hpp"
9+
#include "ekg/ui/listbox/listbox.hpp"
10+
#include "ekg/ui/menu/menu.hpp"
11+
#include "ekg/ui/popup/popup.hpp"
12+
#include "ekg/ui/scrollbar/scrollbar.hpp"
13+
#include "ekg/ui/slider/slider.hpp"
14+
#include "ekg/ui/textbox/textbox.hpp"
15+
16+
namespace ekg {
17+
struct theme_t {
18+
public:
19+
std::string_view name {};
20+
std::string_view author {};
21+
std::string_view description {};
22+
std::string_view path {};
23+
public:
24+
bool symmetric_layout {};
25+
float min_widget_size {5};
26+
float layout_offset {2.0f};
27+
28+
ekg::button_theme_t button {};
29+
ekg::checkbox_theme_t checkbox {};
30+
ekg::combobox_theme_t combobox {};
31+
ekg::frame_theme_t frame {};
32+
ekg::label_theme_t label {};
33+
ekg::listbox_theme_t listbox {};
34+
ekg::menu_theme_t menu {};
35+
ekg::popup_theme_t popup {};
36+
ekg::scrollbar_theme_t scrollbar {};
37+
ekg::slider_theme_t slider {};
38+
ekg::textbox_theme_t textbox {};
39+
};
40+
41+
std::map<std::string_view, ekg::theme_t> &themes();
42+
ekg::theme_t &theme(std::string_view name = "");
43+
ekg::theme_t &theme(ekg::theme_t theme);
44+
ekg::theme_t &set_current_theme(std::string_view name);
45+
}
46+
47+
#endif

include/ekg/io/memory.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace ekg {
3737
enum result {
3838
success = 2 << 1,
3939
failed = 2 << 2,
40-
widget_not_found = 2 << 3,
40+
could_not_find = 2 << 3,
4141
not_implemented = 2 << 4
4242
};
4343

@@ -74,7 +74,7 @@ namespace ekg {
7474
t &get_value() {
7575
return (
7676
this->p_address
77-
?
77+
?
7878
/**
7979
*
8080
* idk idc i want

include/ekg/io/safety.hpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ namespace ekg::io {
6060
};
6161

6262
switch (descriptor.type) {
63+
case ekg::type::button: {
64+
ekg::button_t &button {
65+
ekg::io::any_static_cast<ekg::button_t>(
66+
descriptor
67+
)
68+
};
69+
70+
ekg::ui::button *p_button {
71+
ekg::io::new_widget_instance<ekg::ui::button>()
72+
};
73+
74+
p_button->descriptor = button;
75+
p_created_widget = p_button;
76+
77+
properties.descriptor = &p_button->descriptor;
78+
properties.p_widget = &p_button;
79+
properties.dock = button.dock; // i mean im dumb idk
80+
81+
break;
82+
}
83+
6384
case ekg::type::frame: {
6485
ekg::frame_t &frame {
6586
ekg::io::any_static_cast<ekg::frame_t>(
@@ -72,10 +93,12 @@ namespace ekg::io {
7293
};
7394

7495
p_frame->descriptor = frame;
96+
p_created_widget = p_frame;
97+
7598
properties.descriptor = &p_frame->descriptor;
7699
properties.p_widget = &p_frame;
100+
properties.dock = frame.dock;
77101

78-
p_created_widget = p_frame;
79102
break;
80103
}
81104
}

include/ekg/layout/docknize.hpp

Lines changed: 80 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,87 @@
11
#ifndef EKG_LAYOUT_DOCKNIZE_H
22
#define EKG_LAYOUT_DOCKNIZE_H
33

4-
#include "ekg/ui/abstract/ui_abstract_widget.hpp"
5-
#include "ekg/util/geometry.hpp"
4+
#include "ekg/ui/abstract.hpp"
5+
#include "ekg/math/geometry.hpp"
6+
#include "ekg/io/layout.hpp"
67

7-
/**
8-
* Returns the dimensional extent based in count and the offset (space between rects).
9-
*
10-
* The pixel imperfect issue was solved here...
11-
* For a long time I did not know what was going on with the pixels,
12-
* some solutions I used did not work, then I discovered that all the time
13-
* was this dimension extent with float imprecision loss.
14-
*
15-
* Each pixels represent 1.0f, if the GPU receives pixels with
16-
* (n + f) `n` a non-floating point number and `f` a floating point;
17-
* the rasterizer will jump between pixels, resulting in pixel-imperfect.
18-
*
19-
* The following formula make you understand:
20-
* ( (g - d) - (c * o) ) / c
21-
*
22-
* g = group rect
23-
* d = dimensional extent
24-
* c = amount of widgets with fill property flag until any flag next
25-
* o = UI offset setting
26-
*
27-
* Float-only without the int32_t cast may results in pixel-imperfect
28-
* due the influence of dimensional size of parent rect, font height, font width etc.
29-
*
30-
* - Rina.
31-
**/
32-
#define ekg_layout_get_dimensional_extent(dimension, extent, offset, count) \
33-
( \
34-
(static_cast<int32_t>(dimension) - static_cast<int32_t>(extent) - static_cast<int32_t>(count * offset)) \
35-
) / static_cast<int32_t>(count) \
8+
namespace ekg::layout {
9+
/**
10+
* Returns the dimensional extent based in count and the offset (space between rects).
11+
*
12+
* The pixel imperfect issue was solved here...
13+
* For a long time I did not know what was going on with the pixels,
14+
* some solutions I used did not work, then I discovered that all the time
15+
* was this dimension extent with float imprecision loss.
16+
*
17+
* Each pixels represent 1.0f, if the GPU receives pixels with
18+
* (n + f) `n` a non-floating point number and `f` a floating point;
19+
* the rasterizer will jump between pixels, resulting in pixel-imperfect.
20+
*
21+
* The following formula make you understand:
22+
* ( (g - d) - (c * o) ) / c
23+
*
24+
* g = group rect
25+
* d = dimensional extent
26+
* c = amount of widgets with fill property flag until any flag next
27+
* o = UI offset setting
28+
*
29+
* Float-only without the int32_t cast may results in pixel-imperfect
30+
* due the influence of dimensional size of parent rect, font height, font width etc.
31+
*
32+
* - Rina.
33+
**/
34+
constexpr float transform_dimension_from_extent(
35+
float dimension,
36+
float extent,
37+
float offset,
38+
int32_t count
39+
) {
40+
return static_cast<float>(
41+
(
42+
static_cast<int32_t>(dimension)
43+
-
44+
static_cast<int32_t>(extent)
45+
-
46+
static_cast<int32_t>(count * offset)
47+
)
48+
/
49+
count
50+
);
51+
}
3652

37-
/**
38-
* Pixel imperfection is a problem for UI widget placements, this macro provides
39-
* correction position for right/bottom based on left/top position.
40-
*
41-
* It is important to understand that is impossible to remove all the pixel
42-
* imperfections, but there are ways to round it, as example, you can place widget
43-
* from a side (left or right, top or bottom) and align with an offset. That is how EKG fix it.
44-
*
45-
* This method calculate the minimum possible position based on left until the pixel
46-
* escape for two or more offsets distance. Instead you use the container width directly
47-
* to calculate right widgets positions, EKG must use the left consistency to get the
48-
* real container (width/height) from the side of left (when using the container width directly
49-
* the position is pixel imperfect).
50-
*
51-
* - Rina.
52-
**/
53-
#define ekg_layout_get_pixel_perfect_position(side_a, side_b, container_dimension, offset) \
54-
ekg_min( \
55-
( \
56-
(side_a + (container_dimension - side_a) + offset) \
57-
- \
58-
side_b \
59-
), \
60-
side_a \
61-
) \
53+
/**
54+
* Pixel imperfection is a problem for UI widget placements, this macro provides
55+
* correction position for right/bottom based on left/top position.
56+
*
57+
* It is important to understand that is impossible to remove all the pixel
58+
* imperfections, but there are ways to round it, as example, you can place widget
59+
* from a side (left or right, top or bottom) and align with an offset. That is how EKG fix it.
60+
*
61+
* This method calculate the minimum possible position based on left until the pixel
62+
* escape for two or more offsets distance. Instead you use the container width directly
63+
* to calculate right widgets positions, EKG must use the left consistency to get the
64+
* real container (width/height) from the side of left (when using the container width directly
65+
* the position is pixel imperfect).
66+
*
67+
* - Rina.
68+
**/
69+
constexpr float transform_to_pixel_perfect_position(
70+
float side_a,
71+
float side_b,
72+
float container_dimension,
73+
float offset
74+
) {
75+
return ekg::min_clamp(
76+
(
77+
(side_a + (container_dimension - side_a) + offset)
78+
-
79+
(side_b)
80+
),
81+
side_a
82+
);
83+
}
6284

63-
namespace ekg::layout {
6485
class mask {
6586
protected:
6687
std::vector<ekg::rect_descriptor_t> rect_descriptor_list {};
@@ -88,8 +109,8 @@ namespace ekg::layout {
88109
* A mid-functional feature to process dock position from widgets.
89110
* Note: Recursive.
90111
**/
91-
void docknize(
92-
ekg::ui::abstract_widget *p_parent_widget
112+
void docknize_widget(
113+
ekg::ui::abstract *p_parent_widget
93114
);
94115
}
95116

include/ekg/layout/extentnize.hpp

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef EKG_LAYOUT_EXTENTNIZE_HPP
22
#define EKG_LAYOUT_EXTENTNIZE_HPP
33

4+
#include "ekg/ui/abstract.hpp"
5+
46
namespace ekg::layout {
57
struct fill_align_t {
68
public:
@@ -21,35 +23,63 @@ namespace ekg::layout {
2123
static ekg::layout::extent_t v_rect_descriptor;
2224
static ekg::layout::extent_t h_rect_descriptor;
2325
public:
24-
int64_t end_index {};
25-
int64_t begin_index {};
26-
int64_t count {};
26+
int32_t end_index {};
27+
int32_t begin_index {};
28+
int32_t count {};
2729
float extent {};
2830
};
2931

3032
/**
31-
* Obtain the remain extent size, from the latest rect descriptor list index.
33+
* The extentize is a method to calculate split (between all elements with `ekg::dock::fill` flag)
34+
* data from a container dimension, extent is the amount of non `ekg::dock::fill` calculated dimension.
35+
*
36+
* Both functions `extentnize_*` works almost equals, but with
37+
* difference of specialization-level, rect descriptors are a
38+
* compact way to calculate extent, while widgets works with some additional
39+
* variables. For performance reasons EKG does not want to make generic
40+
* this way, but soon maybe we can change it.
41+
*
42+
* ---
43+
*
44+
* How it works:
45+
*
46+
* The last index does not check if contains a next flag,
47+
* so it is needed to brute-check to stop at end of index.
48+
*
49+
* The extent data store the previous bounding indices,
50+
* in simply words, prevent useless iteration.
51+
*
52+
* The min offset is added for extent, because we need count
53+
* the offset position when split the dimension width, but the
54+
* last extent space is not necessary, so we need to subtract.
55+
**/
56+
57+
/**
58+
* Obtain the remain extent size, from the latest rect descriptor index `in`
59+
* and return the new count `out`.
3260
**/
3361
void extentnize_rect_descriptor(
3462
std::vector<ekg::rect_descriptor_t> &rect_descriptor_list,
63+
ekg::flags_t flag_ok,
64+
ekg::flags_t flag_stop,
65+
ekg::flags_t flag_axis,
66+
ekg::layout::fill_align_t &fill_align,
3567
float &extent,
36-
ekg::flags flag_ok,
37-
ekg::flags flag_stop,
38-
int64_t &begin_and_count,
39-
ekg::axis axis
68+
int32_t &in_out_count
4069
);
4170

4271
/**
43-
* Obtain the remain extent size, from the latest widget index.
72+
* Obtain the remain extent size, from the latest widget index `in`
73+
* and return the new count `out`.
4474
**/
4575
void extentnize_widget(
46-
ekg::ui::abstract_widget *p_widget,
76+
ekg::ui::abstract *p_widget,
77+
ekg::flags_t flag_ok,
78+
ekg::flags_t flag_stop,
79+
ekg::flags_t flag_axis,
80+
ekg::layout::fill_align_t &fill_align,
4781
float &extent,
48-
fill_align_t *p_fill_align,
49-
ekg::flags flag_ok,
50-
ekg::flags flag_stop,
51-
int64_t &begin_and_count,
52-
ekg::axis axis
82+
int32_t &in_out_count
5383
);
5484
}
5585

include/ekg/math/geometry.hpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
#ifndef EKG_MATH_GEOMETRY_HPP
22
#define EKG_MATH_GEOMETRY_HPP
33

4+
#include <cstdint>
5+
46
namespace ekg {
7+
enum dock {
8+
none = 2 << 1,
9+
free = 2 << 2,
10+
top = 2 << 3,
11+
bottom = 2 << 4,
12+
right = 2 << 5,
13+
left = 2 << 6,
14+
center = 2 << 7,
15+
full = 2 << 8,
16+
next = 2 << 9,
17+
fill = 2 << 10,
18+
resize = 2 << 11,
19+
bind = 2 << 12
20+
};
21+
22+
enum axis {
23+
vertical = 2 << 13,
24+
horizontal = 2 << 14
25+
};
26+
527
template<typename t>
628
struct vec2_t {
729
union {
@@ -134,4 +156,4 @@ namespace ekg {
134156
);
135157
}
136158

137-
#endif
159+
#endif

0 commit comments

Comments
 (0)