Add editor settings for call hint placement

Added settings: text_editor/put_callhint_tooltip_below_current_line
and text_editor/callhint_tooltip_offset
This commit is contained in:
Martin Chuckeles 2016-03-04 11:05:42 +01:00
parent 26cc14e839
commit 47206b409d
4 changed files with 45 additions and 4 deletions

View File

@ -847,7 +847,7 @@ void TextEdit::_notification(int p_what) {
} }
} }
bool completion_below = false;
if (completion_active) { if (completion_active) {
// code completion box // code completion box
Ref<StyleBox> csb = get_stylebox("completion"); Ref<StyleBox> csb = get_stylebox("completion");
@ -878,11 +878,12 @@ void TextEdit::_notification(int p_what) {
} }
int th = h + csb->get_minimum_size().y; int th = h + csb->get_minimum_size().y;
if (cursor_pos.y+get_row_height()+th > get_size().height) { if (cursor_pos.y+get_row_height()+th > get_size().height) {
completion_rect.pos.y=cursor_pos.y-th; completion_rect.pos.y=cursor_pos.y-th;
} else { } else {
completion_rect.pos.y=cursor_pos.y+get_row_height()+csb->get_offset().y; completion_rect.pos.y=cursor_pos.y+get_row_height()+csb->get_offset().y;
completion_below = true;
} }
if (cursor_pos.x-nofs+w+scrollw > get_size().width) { if (cursor_pos.x-nofs+w+scrollw > get_size().width) {
@ -931,7 +932,23 @@ void TextEdit::_notification(int p_what) {
} }
if (completion_hint!="" && !completion_active) { // check to see if the hint should be drawn
bool show_hint = false;
if (completion_hint!="") {
if (completion_active) {
if (completion_below && !callhint_below) {
show_hint = true;
}
else if (!completion_below && callhint_below) {
show_hint = true;
}
}
else {
show_hint = true;
}
}
if (show_hint) {
Ref<StyleBox> sb = get_stylebox("panel","TooltipPanel"); Ref<StyleBox> sb = get_stylebox("panel","TooltipPanel");
Ref<Font> font = cache.font; Ref<Font> font = cache.font;
@ -967,7 +984,15 @@ void TextEdit::_notification(int p_what) {
} }
Point2 hint_ofs = Vector2(completion_hint_offset,cursor_pos.y+minsize.y); Point2 hint_ofs = Vector2(completion_hint_offset,cursor_pos.y) + callhint_offset;
if (callhint_below) {
hint_ofs.y += get_row_height() + sb->get_offset().y;
}
else {
hint_ofs.y -= minsize.y + sb->get_offset().y;
}
draw_style_box(sb,Rect2(hint_ofs,minsize)); draw_style_box(sb,Rect2(hint_ofs,minsize));
spacing=0; spacing=0;

View File

@ -231,6 +231,9 @@ class TextEdit : public Control {
bool next_operation_is_complex; bool next_operation_is_complex;
bool callhint_below;
Vector2 callhint_offset;
int get_visible_rows() const; int get_visible_rows() const;
int get_char_count(); int get_char_count();
@ -326,6 +329,10 @@ public:
brace_matching_enabled=p_enabled; brace_matching_enabled=p_enabled;
update(); update();
} }
inline void set_callhint_settings(bool below, Vector2 offset) {
callhint_below = below;
callhint_offset = offset;
}
void set_auto_indent(bool p_auto_indent); void set_auto_indent(bool p_auto_indent);
void cursor_set_column(int p_col, bool p_adjust_viewport=true); void cursor_set_column(int p_col, bool p_adjust_viewport=true);

View File

@ -568,6 +568,12 @@ void CodeTextEditor::_on_settings_change() {
); );
enable_complete_timer = EDITOR_DEF("text_editor/enable_code_completion_delay",true); enable_complete_timer = EDITOR_DEF("text_editor/enable_code_completion_delay",true);
// call hint settings
text_editor->set_callhint_settings(
EDITOR_DEF("text_editor/put_callhint_tooltip_below_current_line", true),
EDITOR_DEF("text_editor/callhint_tooltip_offset", Vector2())
);
} }
void CodeTextEditor::_text_changed_idle_timeout() { void CodeTextEditor::_text_changed_idle_timeout() {

View File

@ -1928,6 +1928,9 @@ void ScriptEditor::edit(const Ref<Script>& p_script) {
ste->set_edited_script(p_script); ste->set_edited_script(p_script);
ste->get_text_edit()->set_tooltip_request_func(this,"_get_debug_tooltip",ste); ste->get_text_edit()->set_tooltip_request_func(this,"_get_debug_tooltip",ste);
ste->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/auto_brace_complete")); ste->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/auto_brace_complete"));
ste->get_text_edit()->set_callhint_settings(
EditorSettings::get_singleton()->get("text_editor/put_callhint_tooltip_below_current_line"),
EditorSettings::get_singleton()->get("text_editor/callhint_tooltip_offset"));
tab_container->add_child(ste); tab_container->add_child(ste);
_go_to_tab(tab_container->get_tab_count()-1); _go_to_tab(tab_container->get_tab_count()-1);