add force caret display to line edit
This commit is contained in:
parent
81a47d033d
commit
dc46bc8857
|
@ -699,7 +699,7 @@ void LineEdit::_notification(int p_what) {
|
||||||
update();
|
update();
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_DRAW: {
|
case NOTIFICATION_DRAW: {
|
||||||
if ((!has_focus() && !menu->has_focus()) || !window_has_focus) {
|
if ((!has_focus() && !menu->has_focus() && !caret_force_displayed) || !window_has_focus) {
|
||||||
draw_caret = false;
|
draw_caret = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -925,10 +925,14 @@ void LineEdit::_notification(int p_what) {
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_FOCUS_ENTER: {
|
case NOTIFICATION_FOCUS_ENTER: {
|
||||||
if (caret_blink_enabled) {
|
if (!caret_force_displayed) {
|
||||||
caret_blink_timer->start();
|
if (caret_blink_enabled) {
|
||||||
} else {
|
if (caret_blink_timer->is_stopped()) {
|
||||||
draw_caret = true;
|
caret_blink_timer->start();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
draw_caret = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID) {
|
if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID) {
|
||||||
|
@ -947,7 +951,7 @@ void LineEdit::_notification(int p_what) {
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_FOCUS_EXIT: {
|
case NOTIFICATION_FOCUS_EXIT: {
|
||||||
if (caret_blink_enabled) {
|
if (caret_blink_enabled && !caret_force_displayed) {
|
||||||
caret_blink_timer->stop();
|
caret_blink_timer->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1167,9 +1171,11 @@ bool LineEdit::cursor_get_blink_enabled() const {
|
||||||
void LineEdit::cursor_set_blink_enabled(const bool p_enabled) {
|
void LineEdit::cursor_set_blink_enabled(const bool p_enabled) {
|
||||||
caret_blink_enabled = p_enabled;
|
caret_blink_enabled = p_enabled;
|
||||||
|
|
||||||
if (has_focus()) {
|
if (has_focus() || caret_force_displayed) {
|
||||||
if (p_enabled) {
|
if (p_enabled) {
|
||||||
caret_blink_timer->start();
|
if (caret_blink_timer->is_stopped()) {
|
||||||
|
caret_blink_timer->start();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
caret_blink_timer->stop();
|
caret_blink_timer->stop();
|
||||||
}
|
}
|
||||||
|
@ -1178,6 +1184,16 @@ void LineEdit::cursor_set_blink_enabled(const bool p_enabled) {
|
||||||
draw_caret = true;
|
draw_caret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LineEdit::cursor_get_force_displayed() const {
|
||||||
|
return caret_force_displayed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineEdit::cursor_set_force_displayed(const bool p_enabled) {
|
||||||
|
caret_force_displayed = p_enabled;
|
||||||
|
cursor_set_blink_enabled(caret_blink_enabled);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
float LineEdit::cursor_get_blink_speed() const {
|
float LineEdit::cursor_get_blink_speed() const {
|
||||||
return caret_blink_timer->get_wait_time();
|
return caret_blink_timer->get_wait_time();
|
||||||
}
|
}
|
||||||
|
@ -1200,7 +1216,7 @@ void LineEdit::_reset_caret_blink_timer() {
|
||||||
|
|
||||||
void LineEdit::_toggle_draw_caret() {
|
void LineEdit::_toggle_draw_caret() {
|
||||||
draw_caret = !draw_caret;
|
draw_caret = !draw_caret;
|
||||||
if (is_visible_in_tree() && has_focus() && window_has_focus) {
|
if (is_visible_in_tree() && ((has_focus() && window_has_focus) || caret_force_displayed)) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1796,6 +1812,8 @@ void LineEdit::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("get_expand_to_text_length"), &LineEdit::get_expand_to_text_length);
|
ClassDB::bind_method(D_METHOD("get_expand_to_text_length"), &LineEdit::get_expand_to_text_length);
|
||||||
ClassDB::bind_method(D_METHOD("cursor_set_blink_enabled", "enabled"), &LineEdit::cursor_set_blink_enabled);
|
ClassDB::bind_method(D_METHOD("cursor_set_blink_enabled", "enabled"), &LineEdit::cursor_set_blink_enabled);
|
||||||
ClassDB::bind_method(D_METHOD("cursor_get_blink_enabled"), &LineEdit::cursor_get_blink_enabled);
|
ClassDB::bind_method(D_METHOD("cursor_get_blink_enabled"), &LineEdit::cursor_get_blink_enabled);
|
||||||
|
ClassDB::bind_method(D_METHOD("cursor_set_force_displayed", "enabled"), &LineEdit::cursor_set_force_displayed);
|
||||||
|
ClassDB::bind_method(D_METHOD("cursor_get_force_displayed"), &LineEdit::cursor_get_force_displayed);
|
||||||
ClassDB::bind_method(D_METHOD("cursor_set_blink_speed", "blink_speed"), &LineEdit::cursor_set_blink_speed);
|
ClassDB::bind_method(D_METHOD("cursor_set_blink_speed", "blink_speed"), &LineEdit::cursor_set_blink_speed);
|
||||||
ClassDB::bind_method(D_METHOD("cursor_get_blink_speed"), &LineEdit::cursor_get_blink_speed);
|
ClassDB::bind_method(D_METHOD("cursor_get_blink_speed"), &LineEdit::cursor_get_blink_speed);
|
||||||
ClassDB::bind_method(D_METHOD("set_max_length", "chars"), &LineEdit::set_max_length);
|
ClassDB::bind_method(D_METHOD("set_max_length", "chars"), &LineEdit::set_max_length);
|
||||||
|
@ -1859,6 +1877,7 @@ void LineEdit::_bind_methods() {
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "cursor_set_blink_enabled", "cursor_get_blink_enabled");
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "cursor_set_blink_enabled", "cursor_get_blink_enabled");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "cursor_set_blink_speed", "cursor_get_blink_speed");
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "cursor_set_blink_speed", "cursor_get_blink_speed");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "caret_position"), "set_cursor_position", "get_cursor_position");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "caret_position"), "set_cursor_position", "get_cursor_position");
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_force_displayed"), "cursor_set_force_displayed", "cursor_get_force_displayed");
|
||||||
}
|
}
|
||||||
|
|
||||||
LineEdit::LineEdit() {
|
LineEdit::LineEdit() {
|
||||||
|
@ -1888,6 +1907,7 @@ LineEdit::LineEdit() {
|
||||||
|
|
||||||
draw_caret = true;
|
draw_caret = true;
|
||||||
caret_blink_enabled = false;
|
caret_blink_enabled = false;
|
||||||
|
caret_force_displayed = false;
|
||||||
caret_blink_timer = memnew(Timer);
|
caret_blink_timer = memnew(Timer);
|
||||||
add_child(caret_blink_timer);
|
add_child(caret_blink_timer);
|
||||||
caret_blink_timer->set_wait_time(0.65);
|
caret_blink_timer->set_wait_time(0.65);
|
||||||
|
|
|
@ -134,6 +134,7 @@ private:
|
||||||
void update_placeholder_width();
|
void update_placeholder_width();
|
||||||
|
|
||||||
bool caret_blink_enabled;
|
bool caret_blink_enabled;
|
||||||
|
bool caret_force_displayed;
|
||||||
bool draw_caret;
|
bool draw_caret;
|
||||||
bool window_has_focus;
|
bool window_has_focus;
|
||||||
|
|
||||||
|
@ -201,6 +202,9 @@ public:
|
||||||
float cursor_get_blink_speed() const;
|
float cursor_get_blink_speed() const;
|
||||||
void cursor_set_blink_speed(const float p_speed);
|
void cursor_set_blink_speed(const float p_speed);
|
||||||
|
|
||||||
|
bool cursor_get_force_displayed() const;
|
||||||
|
void cursor_set_force_displayed(const bool p_enabled);
|
||||||
|
|
||||||
void copy_text();
|
void copy_text();
|
||||||
void cut_text();
|
void cut_text();
|
||||||
void paste_text();
|
void paste_text();
|
||||||
|
|
Loading…
Reference in New Issue