Skip to content

Commit

Permalink
[feature] bottom-left, bottom-right
Browse files Browse the repository at this point in the history
  • Loading branch information
MrsRina committed Oct 19, 2024
1 parent 095d565 commit ad9b65f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 35 deletions.
98 changes: 67 additions & 31 deletions src/layout/docknize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,18 @@ void ekg::layout::docknize(ekg::ui::abstract_widget *p_widget_parent) {
}

/**
* Container width (scaled container size), works right for left docknization
* Container size (scaled container size), works right for left docknization
* but right dockinization no, due the precision and difference between
* sides where is calculated the positions of widget.
* So there is a special width number to use as container rect.
* So there is a special size number to use as container rect.
**/
float right_container_width {container_rect.w - initial_offset - ekg::layout::offset - ekg::layout::offset};
float total_offset {(initial_offset + ekg::layout::offset) * 2.0f};
ekg::vec2 side_container_fixed {
container_rect.w - initial_offset - ekg::layout::offset,
container_rect.h - initial_offset - ekg::layout::offset
};

container_rect.w -= total_offset;
container_rect.h -= total_offset;
container_rect.w -= initial_offset + ekg::layout::offset + ekg::layout::offset;
container_rect.h -= (initial_offset + ekg::layout::offset) * 2.0f;

ekg::ui::abstract_widget *p_widgets {};
ekg::flags flags {};
Expand Down Expand Up @@ -261,9 +263,9 @@ void ekg::layout::docknize(ekg::ui::abstract_widget *p_widget_parent) {
bool is_next {};

ekg::rect corner_top_left {parent_offset};
ekg::rect corner_top_right {0.0f, parent_offset.y, 0.0f, 0.0f};
ekg::rect corner_bottom_left {parent_offset};
ekg::rect corner_bottom_right {parent_offset};
ekg::rect corner_top_right {0.0f, container_rect.y, 0.0f, 0.0f};
ekg::rect corner_bottom_left {parent_offset.x, 0.0f, 0.0f, 0.0f};
ekg::rect corner_bottom_right {};

for (int32_t &ids: p_widget_parent->p_data->get_child_id_list()) {
if (ids == 0 || (p_widgets = ekg::core->get_fast_widget_by_id(ids)) == nullptr) {
Expand Down Expand Up @@ -319,34 +321,68 @@ void ekg::layout::docknize(ekg::ui::abstract_widget *p_widget_parent) {
should_estimated_extentinize = false;
}

if (is_next && is_top && is_left) {
corner_top_left.x = parent_offset.x;
corner_top_right.x = 0.0f;
switch (flags & ekg::dock::bottom) {
case ekg::dock::bottom:
if (is_next && is_left) {
corner_bottom_left.x = parent_offset.x;
corner_bottom_right.x = 0.0f;

corner_top_left.y += layout.h + ekg::layout::offset;
corner_top_right.y = corner_top_left.y;
}
corner_bottom_left.y += layout.h + ekg::layout::offset;
corner_bottom_right.y = corner_bottom_left.y;
}

if (is_top && is_left) {
layout.x = corner_top_left.x;
layout.y = corner_top_left.y;
if (is_left) {
layout.x = corner_bottom_left.x;
layout.y = side_container_fixed.y - layout.h - corner_bottom_left.y;

corner_top_left.x += layout.w + ekg::layout::offset;
}
corner_bottom_left.x += layout.w + ekg::layout::offset;
}

if (is_next && is_top && is_right) {
corner_top_left.x = parent_offset.x;
corner_top_right.x = 0.0f;
if (is_next && is_right) {
corner_bottom_left.x = parent_offset.x;
corner_bottom_right.x = 0.0f;

corner_top_right.y += layout.h + ekg::layout::offset;
corner_top_left.y = corner_top_right.y;
}
corner_bottom_right.y += layout.h + ekg::layout::offset;
corner_bottom_left.y = corner_bottom_right.y;
}

if (is_right) {
corner_bottom_right.x += layout.w;
layout.x = side_container_fixed.x - corner_bottom_right.x;
corner_bottom_right.x += ekg::layout::offset;
layout.y = side_container_fixed.y - layout.h - corner_bottom_right.y;
}

if (is_top && is_right) {
corner_top_right.x += layout.w;
layout.x = right_container_width - corner_top_right.x;
corner_top_right.x += ekg::layout::offset;
layout.y = corner_top_right.y;
break;
default:
if (is_next && is_left) {
corner_top_left.x = parent_offset.x;
corner_top_right.x = 0.0f;
corner_top_left.y += layout.h + ekg::layout::offset;
corner_top_right.y = corner_top_left.y;
}

if (is_left) {
layout.x = corner_top_left.x;
layout.y = corner_top_left.y;

corner_top_left.x += layout.w + ekg::layout::offset;
}

if (is_next && is_right) {
corner_top_left.x = parent_offset.x;
corner_top_right.x = 0.0f;
corner_top_right.y += layout.h + ekg::layout::offset;
corner_top_left.y = corner_top_right.y;
}

if (is_right) {
corner_top_right.x += layout.w;
layout.x = side_container_fixed.x - corner_top_right.x;
corner_top_right.x += ekg::layout::offset;
layout.y = corner_top_right.y;
}
break;
}

if (should_estimated_extentinize) {
Expand Down
27 changes: 23 additions & 4 deletions test/src/ekg_gui_showcase_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,7 @@ int32_t showcase_useless_window() {
ekg::button("🐈 oi me pressiona 🤭 mwm 🐮", ekg::dock::fill | ekg::dock::next)
->set_text_align(ekg::dock::center)
->set_font_size(ekg::font::big)
->set_task(
new ekg::task {
->set_task( new ekg::task {
.info = {
.tag = "oi bu"
},
Expand Down Expand Up @@ -1218,9 +1217,29 @@ int32_t laboratory_testing() {
->set_drag(ekg::dock::full)
->set_resize(ekg::dock::left | ekg::dock::right | ekg::dock::bottom);

ekg::button("1", ekg::dock::right)->set_width(60.0f);
ekg::button("1", ekg::dock::fill);
ekg::button("4", ekg::dock::next);
ekg::button("5", ekg::dock::right | ekg::dock::fill);
ekg::button("3", ekg::dock::right | ekg::dock::fill);
ekg::button("Exit", ekg::dock::bottom | ekg::dock::right)
->set_width(60.0f)
->set_task(
new ekg::task {
.info = {
.tag = "oi eu quero virar uma panqueca de chocolate"
},
.function = [](ekg::info &task_info) {
SDL_Event sdl_event_quit {};
sdl_event_quit.type = SDL_QUIT;
SDL_PushEvent(&sdl_event_quit);

ekg::log() << "task executed: " << task_info.tag;
}
},
ekg::action::activity
);

ekg::button("666", ekg::dock::right | ekg::dock::bottom | ekg::dock::fill);


ekg::pop_group();
ekg::vec3 clear_color {};
Expand Down

0 comments on commit ad9b65f

Please sign in to comment.