Skip to content

Commit

Permalink
[fix] ekg::log::flush copying not cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
MrsRina committed Jan 14, 2024
1 parent 98650cd commit aee0427
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 37 deletions.
25 changes: 17 additions & 8 deletions include/ekg/ui/textbox/ui_textbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,27 @@
namespace ekg::ui {
class textbox : public ekg::ui::abstract, public std::vector<std::string> {
protected:
std::string text {};
ekg::font font_size {};
std::string formatted_text {};
bool enabled {true};
bool must_format_text {};
uint8_t tab_size {4};

uint64_t max_lines {UINT32_MAX};
uint64_t max_chars_per_line {UINT32_MAX};
public:
/**
* As the name says, unsafe
* due the desynchronization between widget
* and UI interface.
* Set UI `must_format_text` value.
* If true `ekg::ui::listbox::get_text` return formatted,
* else false return the latest text formatted.
*/
void unsafe_set_text(std::string &ref_text);
public:
void set_must_format_text(bool state);

/**
* Return UI `must_format_text` value.
*/
bool is_must_format_text();

ekg::ui::textbox *set_enabled(bool enabled);

bool is_enabled();
Expand All @@ -65,8 +71,11 @@ namespace ekg::ui {

float get_height();

ekg::ui::textbox *set_text(std::string_view text);

/**
* Return formatted text from text box content.
* if `must_format_text` is true, then re-format the text,
* and automatically set `must_format_text` to false.
*/
std::string get_text();

ekg::ui::textbox *set_tab_size(uint8_t size);
Expand Down
8 changes: 4 additions & 4 deletions include/ekg/util/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ namespace ekg {
if (ekg::log::buffered) {
std::string p_log {ekg::log::buffer.str()};

#if defined(__ANDROID__)
#if defined(__ANDROID__)
__android_log_print(ANDROID_LOG_VERBOSE, "EKG", "%s", p_log.c_str());
#else
#else
std::cout << p_log;
#endif
#endif

ekg::log::buffer.clear();
ekg::log::buffer = std::ostringstream {};
ekg::log::buffered = false;
}
}
Expand Down
Binary file modified lib/windows/libekg.a
Binary file not shown.
30 changes: 9 additions & 21 deletions src/ui/textbox/ui_textbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
#include "ekg/ekg.hpp"
#include "ekg/ui/textbox/ui_textbox_widget.hpp"

void ekg::ui::textbox::unsafe_set_text(std::string &ref_text) {
this->text = ref_text;
}

ekg::ui::textbox *ekg::ui::textbox::set_tab_size(uint8_t size) {
this->tab_size = size < 1 ? 1 : size;
return this;
Expand Down Expand Up @@ -56,27 +52,19 @@ ekg::ui::textbox *ekg::ui::textbox::set_place(uint16_t flags) {
return this;
}

ekg::ui::textbox *ekg::ui::textbox::set_text(std::string_view string) {
if (this->text != string) {
this->text = string;
ekg::reload(this->id);
}

return this;
}

std::string ekg::ui::textbox::get_text() {
ekg::ui::textbox_widget *p_widget {
static_cast<ekg::ui::textbox_widget *>(ekg::core->get_fast_widget_by_id(this->id))
};

// It prevent useless iteration from text.
if (p_widget != nullptr && p_widget->text_edited) {
p_widget->update_ui_text_data();
p_widget->text_edited = true;
if (this->must_format_text) {
uint64_t text_chunk_size {this->size()};
for (uint64_t it {}; it < this->size(); it++) {
this->formatted_text += this->at(it);
this->formatted_text += '\n' && (it + 1 == text_chunk_size);
}

this->must_format_text = false;
}

return this->text;
return this->formatted_text;
}

ekg::ui::textbox *ekg::ui::textbox::set_width(float w) {
Expand Down
Binary file modified test/build/windows/ekg-gui-showcase-test.exe
Binary file not shown.
4 changes: 0 additions & 4 deletions test/src/ekg_gui_showcase_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ int32_t main_example() {
ekg::slider("pompo number!!", 0.34f, 0.11f, 0.934f, ekg::dock::fill | ekg::dock::next)->set_precision(4);

auto p_textbox = ekg::textbox("Le textbox", "", ekg::dock::next | ekg::dock::fill)->set_scaled_height(1);
p_textbox->set_text("oii");

/*
auto p_listbox = ekg::listbox("listbox", {"listbox"}, ekg::dock::fill | ekg::dock::next)->set_scaled_height(12);
Expand Down Expand Up @@ -383,9 +382,6 @@ int32_t main_example() {

create_exit_button();

std::string oi_cachorroo = "oi cachorror";
p_textbox->set_text(oi_cachorroo);

ekg::event event {};
ekg::theme().gen_default_dark_theme();

Expand Down

0 comments on commit aee0427

Please sign in to comment.