Skip to content

Commit

Permalink
[update] pixel perfection for fill
Browse files Browse the repository at this point in the history
  • Loading branch information
MrsRina committed Nov 15, 2024
1 parent 167a270 commit f657467
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.10)

set(CMAKE_CXX_STANDARD 17)
set(EKG_VERSION 1.2.0)
Expand Down
13 changes: 13 additions & 0 deletions include/ekg/layout/docknize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ namespace ekg::layout {
extern ekg::layout::extent_t h_extent;
extern ekg::layout::extent_t v_extent;

struct fill_align_t {
public:
bool was_last_fill_found {};
bool was_found {};
bool must_calculate_pixel_perfect {};
bool was_pixel_perfect_calculated {};

float align {static_cast<float>(UINT32_MAX)}; // idk may i duwmb
int64_t index {};
int64_t end_fill_index {};
};

/**
* The between rects from widgets can be docknized
* and return a rect mask (the bouding limits of docknization action).
Expand Down Expand Up @@ -127,6 +139,7 @@ namespace ekg::layout {
**/
void extentnize(
float &extent,
fill_align_t *p_fill_align,
ekg::ui::abstract_widget *p_widget,
ekg::flags flag_ok,
ekg::flags flag_stop,
Expand Down
59 changes: 42 additions & 17 deletions src/layout/docknize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ekg::layout::extent_t ekg::layout::h_extent = {};

void ekg::layout::extentnize(
float &extent,
ekg::layout::fill_align_t *p_fill_align,
ekg::ui::abstract_widget *p_widget,
ekg::flags flag_ok,
ekg::flags flag_stop,
Expand All @@ -20,12 +21,13 @@ void ekg::layout::extentnize(
return;
}

int64_t begin_index {begin_and_count};
switch (axis) {
case ekg::axis::horizontal: {
ekg::flags flags {};
int32_t ids {};
int64_t flag_ok_count {};
int64_t it {begin_and_count};
int64_t it {begin_index};

if (
begin_and_count > static_cast<int64_t>(ekg::layout::h_extent.begin_index)
Expand All @@ -35,21 +37,22 @@ void ekg::layout::extentnize(

begin_and_count = static_cast<int64_t>(ekg::layout::h_extent.count);
extent = ekg::layout::h_extent.extent;

return;
break;
}

ekg::layout::h_extent.begin_index = static_cast<float>(it);
ekg::ui::abstract_widget *p_widgets {};
std::vector<int32_t> &child_id_list {p_widget->p_data->get_child_id_list()};

uint64_t size {child_id_list.size()};
uint64_t latest_index {size - (!child_id_list.empty())};
int64_t size {static_cast<int64_t>(child_id_list.size())};
int64_t latest_index {size - (!child_id_list.empty())};

bool is_scrollbar {};
bool is_last_index {};
bool is_ok_flag {};
bool is_last_index_but {};
bool is_ok {};
bool is_stop {};

/**
* The last index does not check if contains a next flag,
Expand All @@ -70,31 +73,31 @@ void ekg::layout::extentnize(
flags = p_widgets->p_data->get_place_dock();
is_scrollbar = p_widgets->p_data->get_type() == ekg::type::scrollbar;
is_last_index = it == latest_index;
is_ok = ekg_bitwise_contains(flags, flag_ok);
is_stop = ekg_bitwise_contains(flags, flag_stop);

if (
(ekg_bitwise_contains(flags, flag_stop) && it != begin_and_count) || is_last_index || is_scrollbar
(is_stop && it != begin_and_count) || is_last_index || is_scrollbar
) {

extent -= (ekg::layout::offset) * (extent > 0.0f);

is_last_index_but = (
ekg_bitwise_contains(flags, flag_ok) && is_last_index
is_ok && is_last_index
);

flag_ok_count += (
(is_ok_flag = (
!ekg_bitwise_contains(flags, flag_stop)
&&
is_last_index_but
))
!is_stop
&&
is_last_index_but
);

is_last_index_but = (
is_last_index
&&
!ekg_bitwise_contains(flags, flag_ok)
!is_ok
&&
!ekg_bitwise_contains(flags, flag_stop)
!is_stop
&&
!is_scrollbar
);
Expand Down Expand Up @@ -130,19 +133,19 @@ void ekg::layout::extentnize(
is_last_index_but = (
is_last_index
&&
(!ekg_bitwise_contains(flags, flag_stop) || (ekg_bitwise_contains(flags, flag_ok) && !ekg_bitwise_contains(flags, flag_stop)))
(!is_stop || (is_ok && !is_stop))
&&
!is_scrollbar
);

ekg::layout::h_extent.end_index = it + (is_last_index * is_last_index_but);
ekg::layout::h_extent.extent = extent;
ekg::layout::h_extent.count = flag_ok_count + (flag_ok_count == 0);

p_fill_align->index = is_stop ? it - (it > 0) : -1;
break;
}

if (ekg_bitwise_contains(flags, flag_ok)) {
if (is_ok) {
flag_ok_count++;
continue;
}
Expand All @@ -151,13 +154,22 @@ void ekg::layout::extentnize(
}

begin_and_count = flag_ok_count + (flag_ok_count == 0);
if (!p_fill_align->was_found && is_stop) {
p_fill_align->was_found = true;
}

break;
}

case ekg::axis::vertical: {
break;
}
}

p_fill_align->was_last_fill_found = p_fill_align->index == begin_index;
if (p_fill_align->was_found && !p_fill_align->must_calculate_pixel_perfect && p_fill_align->was_last_fill_found) {
p_fill_align->must_calculate_pixel_perfect = true;
}
}

void ekg::layout::docknize(
Expand Down Expand Up @@ -255,6 +267,7 @@ void ekg::layout::docknize(
ekg::layout::h_extent = {};
ekg::layout::extent_t h_extent_backup {};
ekg::layout::extent_t v_extent_backup {};
ekg::layout::fill_align_t fill_align {};

bool is_none {};
bool is_free {};
Expand All @@ -264,6 +277,7 @@ void ekg::layout::docknize(
bool is_bottom {};
bool is_fill {};
bool is_next {};
bool was_first_fill_right_align_found {};

ekg::rect corner_top_left {parent_offset};
ekg::rect corner_top_right {0.0f, parent_offset.y, 0.0f, 0.0f};
Expand Down Expand Up @@ -305,6 +319,7 @@ void ekg::layout::docknize(
count = it;
ekg::layout::extentnize(
dimensional_extent,
&fill_align,
p_widget_parent,
ekg::dock::fill,
ekg::dock::next | (is_top ? ekg::dock::bottom : ekg::dock::top),
Expand Down Expand Up @@ -445,6 +460,7 @@ void ekg::layout::docknize(
count = it;
ekg::layout::extentnize(
dimensional_extent,
&fill_align,
p_widget_parent,
ekg::dock::fill,
ekg::dock::next,
Expand All @@ -453,6 +469,15 @@ void ekg::layout::docknize(
);
}

if (!fill_align.was_pixel_perfect_calculated && fill_align.must_calculate_pixel_perfect) {
fill_align.align = container_rect.w - (layout.x + layout.w);
fill_align.was_pixel_perfect_calculated = true;
} else if (fill_align.was_last_fill_found && fill_align.was_pixel_perfect_calculated) {
layout.w = (
(container_rect.w - layout.x) - fill_align.align
);
}

max_previous_height = layout.h > max_previous_height ? layout.h : max_previous_height;
if (should_reload_widget) {
p_widgets->on_reload();
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.10)

message("-- EKG tests enabled")
message("-- EKG GUI showcase test building")
Expand Down

0 comments on commit f657467

Please sign in to comment.