Skip to content

Commit

Permalink
[ref] new docknize system with fill feature
Browse files Browse the repository at this point in the history
  • Loading branch information
MrsRina committed Aug 29, 2024
1 parent 8c9cdec commit 8625c93
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 94 deletions.
5 changes: 0 additions & 5 deletions include/ekg/ekg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ namespace ekg {
*/
ekg::ui::textbox *textbox(std::string_view tag, std::string_view text, ekg::flags dock = ekg::dock::none);

/**
* Create listbox container UI.
*/
ekg::ui::listbox *listbox_container(std::string_view tag, std::vector<ekg::ui::abstract*> element_list, ekg::flags dock = ekg::dock::none);

/*
* Create listbox container UI.
*/
Expand Down
3 changes: 2 additions & 1 deletion include/ekg/layout/docknize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ namespace ekg::layout {
ekg::flags flags {};
};
protected:
std::vector<ekg::layout::mask::rect> dock_rect_list {};

float respective_all {};
float respective_center {};
ekg::axis axis {};
ekg::vec3 offset {};
std::vector<ekg::layout::mask::rect> dock_rect_list {};
ekg::rect mask {};
protected:
void extentnize(
Expand Down
27 changes: 4 additions & 23 deletions src/ekg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ ekg::ui::button *ekg::button(std::string_view text, ekg::flags dock) {
p_ui->set_place(dock);
p_ui->set_scaled_height(1);
p_ui->set_font_size(ekg::font::normal);
p_ui->set_text_align(ekg::dock::left | ekg::dock::center);
p_ui->set_text_align(ekg::dock::left);
p_ui->set_tag(text);

return p_ui;
Expand All @@ -170,7 +170,7 @@ ekg::ui::label *ekg::label(std::string_view text, ekg::flags dock) {
p_ui->set_place(dock);
p_ui->set_scaled_height(1);
p_ui->set_font_size(ekg::font::normal);
p_ui->set_text_align(ekg::dock::left | ekg::dock::center);
p_ui->set_text_align(ekg::dock::left);
p_ui->set_tag(text);

return p_ui;
Expand All @@ -187,8 +187,8 @@ ekg::ui::checkbox *ekg::checkbox(std::string_view text, bool value, ekg::flags d
p_ui->set_place(dock);
p_ui->set_scaled_height(1);
p_ui->set_font_size(ekg::font::normal);
p_ui->set_text_align(ekg::dock::left | ekg::dock::center);
p_ui->set_box_align(ekg::dock::left | ekg::dock::center);
p_ui->set_text_align(ekg::dock::left);
p_ui->set_box_align(ekg::dock::left);
p_ui->set_tag(text);
p_ui->set_value(value);

Expand Down Expand Up @@ -260,25 +260,6 @@ ekg::ui::listbox *ekg::listbox(
return p_ui;
}

ekg::ui::listbox *ekg::listbox_container(
std::string_view tag,
std::vector<ekg::ui::abstract*> element_list,
ekg::flags dock
) {
ekg::ui::listbox *p_ui {new ekg::ui::listbox()};
p_ui->registry(p_ui);
p_ui->reset_ownership();

p_ui->unsafe_set_type(ekg::type::listbox);
ekg::core->gen_widget(p_ui);

p_ui->set_tag(tag);
p_ui->set_place(dock);
p_ui->set_scaled_height(6);

return p_ui;
}

ekg::ui::scrollbar *ekg::scrollbar(std::string_view tag) {
ekg::ui::scrollbar *p_ui {new ekg::ui::scrollbar()};
p_ui->unsafe_set_type(ekg::type::scrollbar);
Expand Down
141 changes: 87 additions & 54 deletions src/layout/docknize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,40 @@ void ekg::layout::mask::docknize() {

int64_t count {};
float dimensional_extent {};
float rect_height {};
float rect_width {};
float dimension_width {};
float dimension_height {};

bool is_left {};
bool is_right {};
bool is_center {};
bool is_top {};
bool is_bottom {};

/**
* All dock rects within left corner (ekg::dock::left)
* starts from left to right.
**/
ekg::rect left_corner {};

/**
* All dock rects within right corner (ekg::dock::right)
* starts from right (dimension width based) to left.
**/
ekg::rect right_corner {};

/**
* All dock rects within center left corner (ekg::dock::right & ekg::dock::center)
* starts from right (dimension width divided by 2 based) to left.
**/
ekg::rect center_left_corner {};

/**
* All dock rects within center right corner (ekg::dock::right & ekg::dock::center)
* starts from left (dimension width divided by 2 based) to right.
**/
ekg::rect center_right_corner {};

switch (this->axis) {
case ekg::axis::horizontal:
Expand All @@ -437,21 +471,34 @@ void ekg::layout::mask::docknize() {
this->mask.w = this->offset.x;
this->mask.h = this->offset.z;

dimension_width = this->respective_all;
dimension_height = this->offset.z;

left_corner.w += this->offset.x;
right_corner.w += this->offset.x;

center_left_corner.x = dimension_width / 2.0f;
center_left_corner.w = this->offset.x;

center_right_corner.x = dimension_width / 2.0f;
center_right_corner.w = this->offset.x;

for (uint64_t it {}; it < this->dock_rect_list.size(); it++) {
ekg::layout::mask::rect &dock_rect {this->dock_rect_list.at(it)};
if (dock_rect.p_rect == nullptr) {
continue;
}

clamped_offset = ekg_clamp(
(dock_rect.p_rect->h + this->offset.y) - this->offset.z,
0.0f,
this->offset.y
);
is_left = ekg_bitwise_contains(dock_rect.flags, ekg::dock::left);
is_right = ekg_bitwise_contains(dock_rect.flags, ekg::dock::right);
is_center = ekg_bitwise_contains(dock_rect.flags, ekg::dock::center);
is_bottom = ekg_bitwise_contains(dock_rect.flags, ekg::dock::bottom);
is_top = ekg_bitwise_contains(dock_rect.flags, ekg::dock::top);

if (ekg_bitwise_contains(dock_rect.flags, ekg::dock::fill)) {
dock_rect.p_rect->x = this->mask.w;
rect_width = dock_rect.p_rect->w;
rect_height = dock_rect.p_rect->h;

if (ekg_bitwise_contains(dock_rect.flags, ekg::dock::fill)) {
count = it;
this->extentnize(
dimensional_extent,
Expand All @@ -461,7 +508,7 @@ void ekg::layout::mask::docknize() {
ekg::axis::horizontal
);

dimensional_extent = ekg_min(
rect_width = ekg_min(
ekg_layout_get_dimensional_extent(
this->respective_all,
dimensional_extent,
Expand All @@ -470,60 +517,46 @@ void ekg::layout::mask::docknize() {
),
1.0f
);

dock_rect.p_rect->w = dimensional_extent;
opposite = 0;
uniform = dock_rect.p_rect->w + this->offset.x;
this->mask.w += dimensional_extent + this->offset.x + opposite;
}

left_or_right = (
ekg_bitwise_contains(dock_rect.flags, ekg::dock::left) ||
ekg_bitwise_contains(dock_rect.flags, ekg::dock::right)
);

if (ekg_bitwise_contains(dock_rect.flags, ekg::dock::center) && !left_or_right) {
if ekg_bitwise_contains(dock_rect.flags, ekg::dock::full) {
dock_rect.p_rect->x = (this->respective_all / 2) - (dock_rect.p_rect->w / 2);
this->mask.w += dock_rect.p_rect->w + this->offset.x;
}

dock_rect.p_rect->y = centered_dimension - (dock_rect.p_rect->h / 2);
} else if (ekg_bitwise_contains(dock_rect.flags, ekg::dock::center)) {
dock_rect.p_rect->y = centered_dimension - (dock_rect.p_rect->h / 2);
if (is_left && !is_center) {
dock_rect.p_rect->x = left_corner.w;
dock_rect.p_rect->w = rect_width;
left_corner.w += dock_rect.p_rect->w + this->offset.x;
} else if (is_right && !is_center) {
dock_rect.p_rect->w = rect_width;
dock_rect.p_rect->x = dimension_width - right_corner.w - dock_rect.p_rect->w;
right_corner.w += dock_rect.p_rect->w + this->offset.x;
} else if (is_left && is_center) {
dock_rect.p_rect->w = rect_width;
dock_rect.p_rect->x = center_left_corner.x - center_left_corner.w - dock_rect.p_rect->w;
center_left_corner.w += dock_rect.p_rect->w + this->offset.x;
} else if (is_right && is_center) {
dock_rect.p_rect->x = center_right_corner.x + center_right_corner.w;
dock_rect.p_rect->w = rect_width;
center_right_corner.w += dock_rect.p_rect->w + this->offset.x;
} else if (is_center) {
dock_rect.p_rect->w = rect_width;
dock_rect.p_rect->x = (dimension_width / 2.0f) - (dock_rect.p_rect->w / 2.0f);
}

if (ekg_bitwise_contains(dock_rect.flags, ekg::dock::left)) {
if (static_cast<int32_t>(opposite) != 0) {
this->mask.w -= opposite;
}

dock_rect.p_rect->x = this->mask.w;
this->mask.w += dock_rect.p_rect->w + this->offset.x + opposite;
opposite = 0;
uniform = dock_rect.p_rect->w + this->offset.x;
}

if (ekg_bitwise_contains(dock_rect.flags, ekg::dock::right)) {
if (static_cast<int32_t>(uniform) != 0) {
this->mask.w -= uniform;
}

this->mask.w += dock_rect.p_rect->w;
dock_rect.p_rect->x = this->respective_all - this->mask.w;
this->mask.w += uniform + this->offset.x;
opposite = dock_rect.p_rect->w + this->offset.x;
uniform = 0;
if (is_top | is_bottom) {
dock_rect.p_rect->y = (
is_top ? (this->offset.y) : (dimension_height - rect_height - this->offset.y)
);
} else {
dock_rect.p_rect->y = (
(dimension_height / 2.0f) - (rect_height / 2.0f)
);
}

if (ekg_bitwise_contains(dock_rect.flags, ekg::dock::top)) {
dock_rect.p_rect->y = clamped_offset;
} else if (ekg_bitwise_contains(dock_rect.flags, ekg::dock::bottom)) {
dock_rect.p_rect->y = this->offset.z - clamped_offset - dock_rect.p_rect->h;
}
this->mask.h = dimension_height;
}

this->mask.w = ekg_min(this->respective_all, this->mask.w);
this->mask.w = ekg_min(
this->respective_all,
left_corner.w + right_corner.w + center_left_corner.w + center_right_corner.w
);
break;
case ekg::axis::vertical:
if (this->dock_rect_list.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/button/ui_button_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void ekg::ui::button_widget::on_reload() {
float dimension_offset {static_cast<float>((int32_t) (text_height / 2.0f))};
float offset {ekg::find_min_offset(text_width, dimension_offset)};

this->dimension.w = ekg_min(this->dimension.w, text_height);
this->dimension.w = ekg_min(this->dimension.w, text_width);
this->dimension.h = (text_height + dimension_offset) * static_cast<float>(p_ui->get_scaled_height());

this->min_size.x = ekg_min(this->min_size.x, text_height);
Expand Down
4 changes: 2 additions & 2 deletions src/util/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ekg::item::item(
this->placement.rect.w = 100.0f;
this->value = insert_value;
this->attr_bits = insert_attr_bits;
this->placement.text_dock_flags = ekg::dock::left | ekg::dock::center;
this->placement.text_dock_flags = ekg::dock::left;
}

ekg::item::item(
Expand All @@ -48,7 +48,7 @@ ekg::item::item(
this->value = insert_value;
this->insert(this->begin(), insert_item_list.begin(), insert_item_list.end());
this->attr_bits = insert_attr_bits;
this->placement.text_dock_flags = ekg::dock::left | ekg::dock::center;
this->placement.text_dock_flags = ekg::dock::left;
}

ekg::item::~item() {
Expand Down
28 changes: 20 additions & 8 deletions test/src/ekg_gui_showcase_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,15 +642,15 @@ int32_t showcase_useless_window() {
content.at(it).insert(content.at(it).end(), content.at(it).begin(), content.at(it).end());*/
}

auto p = ekg::slider<uint8_t>(
auto p = ekg::slider<float>(
"meow",
ekg::dock::fill | ekg::dock::next
)
->set_text_align(ekg::dock::right)
->range<uint8_t>(0, 0, 0, 100)
//->range<uint8_t>(0).f32.transfer_ownership(&ekg::current_theme_scheme().frame_outline.w)
->range<uint8_t>(1, 10, 0, 127);
//->range<uint8_t>(1).f32.transfer_ownership(&ekg::current_theme_scheme().frame_background.w);
->range<float>(0, 0.0f, 0.0f, 100.0f)
->range<float>(0).f32.transfer_ownership(&ekg::current_theme_scheme().frame_outline.w)
->range<float>(1, 10.0f, 0.0f, 127.0f)
->range<float>(1).f32.transfer_ownership(&ekg::current_theme_scheme().frame_background.w);

ekg::button("Dead-allocate the instance of life", ekg::dock::fill | ekg::dock::next)
->set_task(
Expand Down Expand Up @@ -681,7 +681,11 @@ int32_t showcase_useless_window() {
->set_mode(ekg::mode::multicolumn)
->transfer_ownership(&content);

auto p_dpi = ekg::checkbox("DPI-scale:", true, ekg::dock::next);
ekg::checkbox("DPI-scale:", true, ekg::dock::next | ekg::dock::fill)
->set_box_align(ekg::dock::left)
->set_text_align(ekg::dock::left)
->transfer_ownership(&ekg::ui::auto_scale);

ekg::textbox("DPI", "1920x1080", ekg::dock::fill)
->set_max_lines(1)
->set_task(
Expand Down Expand Up @@ -895,7 +899,6 @@ int32_t showcase_useless_window() {
" GD: " + std::to_string(ekg::gpu::allocator::current_rendering_data_count)
);

ekg::ui::auto_scale = p_dpi->get_value();
frame_couting = 0;
}

Expand Down Expand Up @@ -1043,7 +1046,16 @@ int32_t laboratory_testing() {
float prev_pos {10.2f};
float scale {2.0f};

message_gui msg_gui {};
ekg::frame("campo", {20, 20}, {200, 200})
->set_drag(ekg::dock::full)
->set_resize(ekg::dock::left | ekg::dock::right | ekg::dock::bottom);

ekg::checkbox("comer pasto pra ficar gorda", true, ekg::dock::fill)
->set_box_align(ekg::dock::right | ekg::dock::fill)
->set_text_align(ekg::dock::left | ekg::dock::fill)
->set_scaled_height(1);

ekg::pop_group();

while (running) {
last = now;
Expand Down

0 comments on commit 8625c93

Please sign in to comment.