diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/color_picker.cpp | 3 | ||||
-rw-r--r-- | scene/gui/color_picker.h | 3 | ||||
-rw-r--r-- | scene/gui/file_dialog.cpp | 15 | ||||
-rw-r--r-- | scene/gui/file_dialog.h | 7 | ||||
-rw-r--r-- | scene/gui/graph_edit.cpp | 13 | ||||
-rw-r--r-- | scene/gui/graph_edit.h | 10 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 16 | ||||
-rw-r--r-- | scene/gui/rich_text_label.cpp | 33 | ||||
-rw-r--r-- | scene/gui/rich_text_label.h | 7 | ||||
-rw-r--r-- | scene/gui/tool_button.cpp | 35 | ||||
-rw-r--r-- | scene/gui/tool_button.h | 43 |
11 files changed, 81 insertions, 104 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 84170a65d1..fafbb298b7 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -758,7 +758,8 @@ ColorPicker::ColorPicker() : sample->set_h_size_flags(SIZE_EXPAND_FILL); sample->connect("draw", callable_mp(this, &ColorPicker::_sample_draw)); - btn_pick = memnew(ToolButton); + btn_pick = memnew(Button); + btn_pick->set_flat(true); hb_smpl->add_child(btn_pick); btn_pick->set_toggle_mode(true); btn_pick->set_tooltip(TTR("Pick a color from the editor window.")); diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index 31ae92f4e4..b2e8263e7f 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -41,7 +41,6 @@ #include "scene/gui/slider.h" #include "scene/gui/spin_box.h" #include "scene/gui/texture_rect.h" -#include "scene/gui/tool_button.h" class ColorPicker : public BoxContainer { GDCLASS(ColorPicker, BoxContainer); @@ -57,7 +56,7 @@ private: HSeparator *preset_separator; Button *bt_add_preset; List<Color> presets; - ToolButton *btn_pick; + Button *btn_pick; CheckButton *btn_hsv; CheckButton *btn_raw; HSlider *scroll[4]; diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 630f3c8ff6..41ca6458af 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -45,9 +45,9 @@ VBoxContainer *FileDialog::get_vbox() { } void FileDialog::_theme_changed() { - Color font_color = vbox->get_theme_color("font_color", "ToolButton"); - Color font_color_hover = vbox->get_theme_color("font_color_hover", "ToolButton"); - Color font_color_pressed = vbox->get_theme_color("font_color_pressed", "ToolButton"); + Color font_color = vbox->get_theme_color("font_color", "Button"); + Color font_color_hover = vbox->get_theme_color("font_color_hover", "Button"); + Color font_color_pressed = vbox->get_theme_color("font_color_pressed", "Button"); dir_up->add_theme_color_override("icon_color_normal", font_color); dir_up->add_theme_color_override("icon_color_hover", font_color_hover); @@ -859,7 +859,8 @@ FileDialog::FileDialog() { HBoxContainer *hbc = memnew(HBoxContainer); - dir_up = memnew(ToolButton); + dir_up = memnew(Button); + dir_up->set_flat(true); dir_up->set_tooltip(RTR("Go to parent folder.")); hbc->add_child(dir_up); dir_up->connect("pressed", callable_mp(this, &FileDialog::_go_up)); @@ -877,12 +878,14 @@ FileDialog::FileDialog() { hbc->add_child(dir); dir->set_h_size_flags(Control::SIZE_EXPAND_FILL); - refresh = memnew(ToolButton); + refresh = memnew(Button); + refresh->set_flat(true); refresh->set_tooltip(RTR("Refresh files.")); refresh->connect("pressed", callable_mp(this, &FileDialog::update_file_list)); hbc->add_child(refresh); - show_hidden = memnew(ToolButton); + show_hidden = memnew(Button); + show_hidden->set_flat(true); show_hidden->set_toggle_mode(true); show_hidden->set_pressed(is_showing_hidden_files()); show_hidden->set_tooltip(RTR("Toggle the visibility of hidden files.")); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index 8bc536d576..44050a2376 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -36,7 +36,6 @@ #include "scene/gui/dialogs.h" #include "scene/gui/line_edit.h" #include "scene/gui/option_button.h" -#include "scene/gui/tool_button.h" #include "scene/gui/tree.h" class FileDialog : public ConfirmationDialog { @@ -87,10 +86,10 @@ private: DirAccess *dir_access; ConfirmationDialog *confirm_save; - ToolButton *dir_up; + Button *dir_up; - ToolButton *refresh; - ToolButton *show_hidden; + Button *refresh; + Button *show_hidden; Vector<String> filters; diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 5080ba74e2..2b0e084db4 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -33,6 +33,7 @@ #include "core/input/input.h" #include "core/os/keyboard.h" #include "scene/gui/box_container.h" +#include "scene/gui/button.h" #ifdef TOOLS_ENABLED #include "editor/editor_scale.h" @@ -1310,25 +1311,29 @@ GraphEdit::GraphEdit() { top_layer->add_child(zoom_hb); zoom_hb->set_position(Vector2(10, 10)); - zoom_minus = memnew(ToolButton); + zoom_minus = memnew(Button); + zoom_minus->set_flat(true); zoom_hb->add_child(zoom_minus); zoom_minus->set_tooltip(RTR("Zoom Out")); zoom_minus->connect("pressed", callable_mp(this, &GraphEdit::_zoom_minus)); zoom_minus->set_focus_mode(FOCUS_NONE); - zoom_reset = memnew(ToolButton); + zoom_reset = memnew(Button); + zoom_reset->set_flat(true); zoom_hb->add_child(zoom_reset); zoom_reset->set_tooltip(RTR("Zoom Reset")); zoom_reset->connect("pressed", callable_mp(this, &GraphEdit::_zoom_reset)); zoom_reset->set_focus_mode(FOCUS_NONE); - zoom_plus = memnew(ToolButton); + zoom_plus = memnew(Button); + zoom_plus->set_flat(true); zoom_hb->add_child(zoom_plus); zoom_plus->set_tooltip(RTR("Zoom In")); zoom_plus->connect("pressed", callable_mp(this, &GraphEdit::_zoom_plus)); zoom_plus->set_focus_mode(FOCUS_NONE); - snap_button = memnew(ToolButton); + snap_button = memnew(Button); + snap_button->set_flat(true); snap_button->set_toggle_mode(true); snap_button->set_tooltip(RTR("Enable snap and show grid.")); snap_button->connect("pressed", callable_mp(this, &GraphEdit::_snap_toggled)); diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index c632490855..a627a8eec8 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -32,12 +32,12 @@ #define GRAPH_EDIT_H #include "scene/gui/box_container.h" +#include "scene/gui/button.h" #include "scene/gui/graph_node.h" #include "scene/gui/scroll_bar.h" #include "scene/gui/slider.h" #include "scene/gui/spin_box.h" #include "scene/gui/texture_rect.h" -#include "scene/gui/tool_button.h" class GraphEdit; @@ -65,11 +65,11 @@ public: }; private: - ToolButton *zoom_minus; - ToolButton *zoom_reset; - ToolButton *zoom_plus; + Button *zoom_minus; + Button *zoom_reset; + Button *zoom_plus; - ToolButton *snap_button; + Button *snap_button; SpinBox *snap_amount; void _zoom_minus(); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index ee6783167a..ba55927980 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -274,6 +274,22 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { set_cursor_position(text.length()); shift_selection_check_post(k->get_shift()); } break; + case (KEY_BACKSPACE): { + if (!editable) + break; + + // If selected, delete the selection + if (selection.enabled) { + selection_delete(); + break; + } + + // Otherwise delete from cursor to beginning of text edit + int current_pos = get_cursor_position(); + if (current_pos != 0) { + delete_text(0, current_pos); + } + } break; #endif default: { handled = false; diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 92508f7fd2..5ae27081ea 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1570,6 +1570,10 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { } updating_scroll = false; + + if (fit_content_height) { + minimum_size_changed(); + } } void RichTextLabel::_invalidate_current_line(ItemFrame *p_frame) { @@ -1989,6 +1993,17 @@ int RichTextLabel::get_tab_size() const { return tab_size; } +void RichTextLabel::set_fit_content_height(bool p_enabled) { + if (p_enabled != fit_content_height) { + fit_content_height = p_enabled; + minimum_size_changed(); + } +} + +bool RichTextLabel::is_fit_content_height_enabled() const { + return fit_content_height; +} + void RichTextLabel::set_meta_underline(bool p_underline) { underline_meta = p_underline; update(); @@ -2646,7 +2661,7 @@ void RichTextLabel::install_effect(const Variant effect) { } } -int RichTextLabel::get_content_height() { +int RichTextLabel::get_content_height() const { int total_height = 0; if (main->lines.size()) { total_height = main->lines[main->lines.size() - 1].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height; @@ -2701,6 +2716,9 @@ void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("set_tab_size", "spaces"), &RichTextLabel::set_tab_size); ClassDB::bind_method(D_METHOD("get_tab_size"), &RichTextLabel::get_tab_size); + ClassDB::bind_method(D_METHOD("set_fit_content_height", "enabled"), &RichTextLabel::set_fit_content_height); + ClassDB::bind_method(D_METHOD("is_fit_content_height_enabled"), &RichTextLabel::is_fit_content_height_enabled); + ClassDB::bind_method(D_METHOD("set_selection_enabled", "enabled"), &RichTextLabel::set_selection_enabled); ClassDB::bind_method(D_METHOD("is_selection_enabled"), &RichTextLabel::is_selection_enabled); @@ -2743,6 +2761,8 @@ void RichTextLabel::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_size", PROPERTY_HINT_RANGE, "0,24,1"), "set_tab_size", "get_tab_size"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fit_content_height"), "set_fit_content_height", "is_fit_content_height_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_active"), "set_scroll_active", "is_scroll_active"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_following"), "set_scroll_follow", "is_scroll_following"); @@ -2809,12 +2829,17 @@ void RichTextLabel::set_fixed_size_to_width(int p_width) { } Size2 RichTextLabel::get_minimum_size() const { + Size2 size(0, 0); if (fixed_width != -1) { + size.x = fixed_width; + } + + if (fixed_width != -1 || fit_content_height) { const_cast<RichTextLabel *>(this)->_validate_line_caches(main); - return Size2(fixed_width, const_cast<RichTextLabel *>(this)->get_content_height()); + size.y = get_content_height(); } - return Size2(); + return size; } Ref<RichTextEffect> RichTextLabel::_get_custom_effect_by_code(String p_bbcode_identifier) { @@ -2934,6 +2959,8 @@ RichTextLabel::RichTextLabel() { visible_line_count = 0; fixed_width = -1; + fit_content_height = false; + set_clip_contents(true); } diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 4cec435568..7eeb071cb5 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -403,6 +403,8 @@ private: int fixed_width; + bool fit_content_height; + protected: void _notification(int p_what); @@ -456,13 +458,16 @@ public: void set_tab_size(int p_spaces); int get_tab_size() const; + void set_fit_content_height(bool p_enabled); + bool is_fit_content_height_enabled() const; + bool search(const String &p_string, bool p_from_selection = false, bool p_search_previous = false); void scroll_to_line(int p_line); int get_line_count() const; int get_visible_line_count() const; - int get_content_height(); + int get_content_height() const; VScrollBar *get_v_scroll() { return vscroll; } diff --git a/scene/gui/tool_button.cpp b/scene/gui/tool_button.cpp deleted file mode 100644 index c9f87f0015..0000000000 --- a/scene/gui/tool_button.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************/ -/* tool_button.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "tool_button.h" - -ToolButton::ToolButton() { - set_flat(true); -} diff --git a/scene/gui/tool_button.h b/scene/gui/tool_button.h deleted file mode 100644 index 9848b21381..0000000000 --- a/scene/gui/tool_button.h +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************************/ -/* tool_button.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef TOOL_BUTTON_H -#define TOOL_BUTTON_H - -#include "scene/gui/button.h" - -class ToolButton : public Button { - GDCLASS(ToolButton, Button); - -public: - ToolButton(); -}; - -#endif // TOOL_BUTTON_H |