Skip to content

Commit e08c101

Browse files
committed
[fix] performance overhead
1 parent 206c393 commit e08c101

File tree

7 files changed

+191
-52
lines changed

7 files changed

+191
-52
lines changed

include/ekg/io/memory.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ namespace ekg {
130130

131131
descriptor.at.unique_id = this->highest_unique_id++;
132132
descriptor.at.flags = t::type;
133-
descriptor.at.index = index;
133+
descriptor.at.index = index;
134134

135135
return descriptor;
136136
}
@@ -149,6 +149,7 @@ namespace ekg {
149149
for (size_t it {}; it < size; it++) {
150150
t &descriptor {this->loaded.at(it)};
151151
descriptor.at.index = it;
152+
152153
if (descriptor.at.unique_id == at.unique_id) {
153154
at.index = it;
154155
return descriptor;

include/ekg/io/utf.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ namespace ekg {
135135
class text {
136136
protected:
137137
std::vector<ekg::io::chunk_t> loaded_chunks {};
138-
size_t lines_per_chunk_limit {10};
138+
size_t lines_per_chunk_limit {100000};
139139
size_t total_lines {};
140140
size_t total_chars {};
141141
size_t prev_lines {};
@@ -177,6 +177,7 @@ namespace ekg {
177177
size_t length_of_chars();
178178

179179
bool audited();
180+
void unset_audited();
180181
};
181182
}
182183

include/ekg/ui/textbox/textbox.hpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "ekg/io/descriptor.hpp"
2929
#include "ekg/io/utf.hpp"
3030
#include "ekg/io/font.hpp"
31+
#include "ekg/ui/property.hpp"
3132

3233
namespace ekg {
3334
struct textbox_color_scheme_t {
@@ -39,6 +40,7 @@ namespace ekg {
3940
ekg::rgba_t<float> text_cursor_foreground {};
4041
ekg::pixel_thickness_t cursor_thickness {2};
4142
bool caret_cursor {};
43+
ekg::pixel_thickness_t gutter_margin {2};
4244
};
4345

4446
struct textbox_t {
@@ -51,38 +53,39 @@ namespace ekg {
5153

5254
struct cursor_t {
5355
public:
54-
size_t index_a {};
55-
size_t index_b {};
56+
ekg::vec2_t<size_t> a {};
57+
ekg::vec2_t<size_t> b {};
5658
ekg::rect_t<float> rect {};
5759
public:
58-
bool operator == (size_t index) {
59-
return index == this->index_a && index == this->index_b;
60+
bool operator == (const ekg::vec2_t<size_t> &index) {
61+
return index.x == this->a.x && index.y == this->a.y && index.x == this->b.x && index.y == this->b.y;
6062
}
6163

62-
bool operator > (size_t index) {
63-
return index > this->index_a;
64+
bool operator > (const ekg::vec2_t<size_t> &index) {
65+
return (index.x > this->a.x && index.y == this->a.y) || (index.y > this->a.y);
6466
}
6567

66-
bool operator >= (size_t index) {
67-
return index >= this->index_a;
68+
bool operator >= (const ekg::vec2_t<size_t> &index) {
69+
return (index.x >= this->a.x && index.y == this->a.y) || (index.y > this->a.y);
6870
}
6971

70-
bool operator < (size_t index) {
71-
return index < this->index_b;
72+
bool operator < (const ekg::vec2_t<size_t> &index) {
73+
return (index.x < this->b.x && index.y == this->b.y) || (index.y < this->b.y);
7274
}
7375

74-
bool operator <= (size_t index) {
75-
return index <= this->index_b;
76+
bool operator <= (const ekg::vec2_t<size_t> &index) {
77+
return (index.x <= this->b.x && index.y == this->b.y) || (index.y < this->b.y);
7678
}
7779

7880
bool operator == (const ekg::textbox_t::cursor_t &cursor) {
79-
return this->index_a == cursor.index_a && this->index_b == cursor.index_b;
81+
return *this == cursor.a && *this == cursor.b;
8082
}
8183
};
8284

8385
struct widget_t {
8486
public:
8587
ekg::rect_t<float> rect_text_size {};
88+
ekg::property_t scrollbar_property {};
8689
ekg::scrollbar_t scrollbar {};
8790
std::vector<ekg::textbox_t::cursor_t> cursors {};
8891
std::vector<ekg::textbox_t::select_draw_layer_t> layers_select {};

include/ekg/ui/textbox/widget.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
namespace ekg::ui {
3131
bool find_cursor(
3232
ekg::textbox_t &textbox,
33-
size_t len,
33+
ekg::vec2_t<size_t> &index,
3434
ekg::textbox_t::cursor_t &cursor_out
3535
);
3636

src/io/utf.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ void ekg::text::push_back(std::string_view line) {
501501
this->loaded_chunks.size() - 1,
502502
last_chunk.size() - !last_chunk.empty(),
503503
splitted,
504-
true
504+
false
505505
);
506506
}
507507

@@ -535,7 +535,9 @@ size_t ekg::text::length_of_chars() {
535535
bool ekg::text::audited() {
536536
this->was_audited = this->was_audited || (this->prev_lines != this->total_lines);
537537
this->prev_lines = this->total_lines;
538-
bool was_audited {this->was_audited};
538+
return this->was_audited;
539+
}
540+
541+
void ekg::text::unset_audited() {
539542
this->was_audited = false;
540-
return was_audited;
541543
}

src/ui/scrollbar/widget.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ void ekg::ui::reload(
187187
parent.scroll.nearest_scroll_bar_thickness = scrollbar.color_scheme.bar_thickness;
188188
}
189189

190-
191190
void ekg::ui::event(
192191
ekg::property_t &property,
193192
ekg::scrollbar_t &scrollbar,
@@ -207,7 +206,7 @@ void ekg::ui::event(
207206
input.has_motion
208207
||
209208
input.was_wheel
210-
) {
209+
) {
211210
bool is_visible {
212211
ekg::rect_collide_vec2<float>(property.widget.rect_scissor, interact)
213212
};

0 commit comments

Comments
 (0)