diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/color_picker.cpp | 2 | ||||
-rw-r--r-- | scene/gui/control.cpp | 128 | ||||
-rw-r--r-- | scene/gui/control.h | 36 | ||||
-rw-r--r-- | scene/gui/graph_edit.cpp | 2 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 2 | ||||
-rw-r--r-- | scene/gui/popup.cpp | 2 | ||||
-rw-r--r-- | scene/gui/scroll_bar.cpp | 2 | ||||
-rw-r--r-- | scene/gui/spin_box.cpp | 2 | ||||
-rw-r--r-- | scene/gui/tab_container.cpp | 4 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 12 |
10 files changed, 153 insertions, 39 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 704c00b1d6..62a48ad496 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -461,7 +461,7 @@ void ColorPicker::_screen_pick_pressed() { screen = memnew(Control); r->add_child(screen); screen->set_as_toplevel(true); - screen->set_area_as_parent_rect(); + screen->set_anchors_and_margins_preset(Control::PRESET_WIDE); screen->set_default_cursor_shape(CURSOR_POINTING_HAND); screen->connect("gui_input", this, "_screen_input"); } diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 2c01a0e2d1..d22357ce99 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1471,6 +1471,110 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) { } } +void Control::set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) { + if (!is_inside_tree()) + return; + + Point2 new_pos; + Size2 min_size = get_minimum_size(); + Size2 new_size = get_size(); + Size2 parent_size = get_parent_area_size(); + + // Width + switch (p_preset) { + case PRESET_TOP_WIDE: + case PRESET_BOTTOM_WIDE: + case PRESET_HCENTER_WIDE: + case PRESET_WIDE: + new_size.x = parent_size.x - 2 * p_margin; + break; + default: + if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_HEIGHT) { + new_size.x = min_size.x; + } + break; + } + + // Height + switch (p_preset) { + case PRESET_LEFT_WIDE: + case PRESET_RIGHT_WIDE: + case PRESET_VCENTER_WIDE: + case PRESET_WIDE: + new_size.y = parent_size.y - 2 * p_margin; + break; + default: + if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_WIDTH) { + new_size.y = min_size.y; + } + break; + } + + // x pos + switch (p_preset) { + case PRESET_TOP_LEFT: + case PRESET_BOTTOM_LEFT: + case PRESET_CENTER_LEFT: + case PRESET_TOP_WIDE: + case PRESET_BOTTOM_WIDE: + case PRESET_LEFT_WIDE: + case PRESET_HCENTER_WIDE: + case PRESET_WIDE: + new_pos.x = p_margin; + break; + + case PRESET_CENTER_TOP: + case PRESET_CENTER_BOTTOM: + case PRESET_CENTER: + case PRESET_VCENTER_WIDE: + new_pos.x = (parent_size.x - new_size.x) / 2.0; + break; + + case PRESET_TOP_RIGHT: + case PRESET_BOTTOM_RIGHT: + case PRESET_CENTER_RIGHT: + case PRESET_RIGHT_WIDE: + new_pos.x = parent_size.x - new_size.x - p_margin; + break; + } + + // y pos + switch (p_preset) { + case PRESET_TOP_LEFT: + case PRESET_TOP_RIGHT: + case PRESET_CENTER_TOP: + case PRESET_LEFT_WIDE: + case PRESET_RIGHT_WIDE: + case PRESET_TOP_WIDE: + case PRESET_VCENTER_WIDE: + case PRESET_WIDE: + new_pos.y = p_margin; + break; + + case PRESET_CENTER_LEFT: + case PRESET_CENTER_RIGHT: + case PRESET_CENTER: + case PRESET_HCENTER_WIDE: + new_pos.y = (parent_size.y - new_size.y) / 2.0; + break; + + case PRESET_BOTTOM_LEFT: + case PRESET_BOTTOM_RIGHT: + case PRESET_CENTER_BOTTOM: + case PRESET_BOTTOM_WIDE: + new_pos.y = parent_size.y - new_size.y - p_margin; + break; + } + + set_position(new_pos); + set_size(new_size); +} + +void Control::set_anchors_and_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) { + set_anchors_preset(p_preset); + set_margins_preset(p_preset, p_resize_mode, p_margin); +} + float Control::get_anchor(Margin p_margin) const { return data.anchor[p_margin]; @@ -1622,20 +1726,6 @@ Rect2 Control::get_item_rect() const { return Rect2(Point2(), get_size()); } -void Control::set_area_as_parent_rect(int p_margin) { - - data.anchor[MARGIN_LEFT] = ANCHOR_BEGIN; - data.margin[MARGIN_LEFT] = p_margin; - data.anchor[MARGIN_TOP] = ANCHOR_BEGIN; - data.margin[MARGIN_TOP] = p_margin; - data.anchor[MARGIN_RIGHT] = ANCHOR_END; - data.margin[MARGIN_RIGHT] = -p_margin; - data.anchor[MARGIN_BOTTOM] = ANCHOR_END; - data.margin[MARGIN_BOTTOM] = -p_margin; - - _size_changed(); -} - void Control::add_icon_override(const StringName &p_name, const Ref<Texture> &p_icon) { ERR_FAIL_COND(p_icon.is_null()); @@ -2471,9 +2561,11 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("accept_event"), &Control::accept_event); ClassDB::bind_method(D_METHOD("get_minimum_size"), &Control::get_minimum_size); ClassDB::bind_method(D_METHOD("get_combined_minimum_size"), &Control::get_combined_minimum_size); + ClassDB::bind_method(D_METHOD("set_anchors_preset", "preset", "keep_margin"), &Control::set_anchors_preset, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("set_margins_preset", "preset", "resize_mode", "margin"), &Control::set_margins_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0)); + ClassDB::bind_method(D_METHOD("set_anchors_and_margins_preset", "preset", "resize_mode", "margin"), &Control::set_anchors_and_margins_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0)); ClassDB::bind_method(D_METHOD("set_anchor", "margin", "anchor", "keep_margin", "push_opposite_anchor"), &Control::set_anchor, DEFVAL(false), DEFVAL(true)); ClassDB::bind_method(D_METHOD("_set_anchor", "margin", "anchor"), &Control::_set_anchor); - ClassDB::bind_method(D_METHOD("set_anchors_preset", "preset", "keep_margin"), &Control::set_anchors_preset, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_anchor", "margin"), &Control::get_anchor); ClassDB::bind_method(D_METHOD("set_margin", "margin", "offset"), &Control::set_margin); ClassDB::bind_method(D_METHOD("set_anchor_and_margin", "margin", "anchor", "offset", "push_opposite_anchor"), &Control::set_anchor_and_margin, DEFVAL(false)); @@ -2505,7 +2597,6 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("get_global_position"), &Control::get_global_position); ClassDB::bind_method(D_METHOD("get_rect"), &Control::get_rect); ClassDB::bind_method(D_METHOD("get_global_rect"), &Control::get_global_rect); - ClassDB::bind_method(D_METHOD("set_area_as_parent_rect", "margin"), &Control::set_area_as_parent_rect, DEFVAL(0)); ClassDB::bind_method(D_METHOD("show_modal", "exclusive"), &Control::show_modal, DEFVAL(false)); ClassDB::bind_method(D_METHOD("set_focus_mode", "mode"), &Control::set_focus_mode); ClassDB::bind_method(D_METHOD("get_focus_mode"), &Control::get_focus_mode); @@ -2689,6 +2780,11 @@ void Control::_bind_methods() { BIND_ENUM_CONSTANT(PRESET_HCENTER_WIDE); BIND_ENUM_CONSTANT(PRESET_WIDE); + BIND_ENUM_CONSTANT(PRESET_MODE_MINSIZE); + BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_HEIGHT); + BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_WIDTH); + BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_SIZE); + BIND_ENUM_CONSTANT(SIZE_EXPAND); BIND_ENUM_CONSTANT(SIZE_FILL); BIND_ENUM_CONSTANT(SIZE_EXPAND_FILL); diff --git a/scene/gui/control.h b/scene/gui/control.h index da5c4d0908..5b146b4454 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -124,6 +124,13 @@ public: PRESET_WIDE }; + enum LayoutPresetMode { + PRESET_MODE_MINSIZE, + PRESET_MODE_KEEP_WIDTH, + PRESET_MODE_KEEP_HEIGHT, + PRESET_MODE_KEEP_SIZE + }; + private: struct CComparator { @@ -294,34 +301,32 @@ public: /* POSITIONING */ - void set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin = false, bool p_push_opposite_anchor = true); - void set_anchor_and_margin(Margin p_margin, float p_anchor, float p_pos, bool p_push_opposite_anchor = true); void set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin = false); + void set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0); + void set_anchors_and_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0); + void set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin = false, bool p_push_opposite_anchor = true); float get_anchor(Margin p_margin) const; void set_margin(Margin p_margin, float p_value); + float get_margin(Margin p_margin) const; + + void set_anchor_and_margin(Margin p_margin, float p_anchor, float p_pos, bool p_push_opposite_anchor = true); void set_begin(const Point2 &p_point); // helper void set_end(const Point2 &p_point); // helper - void set_h_grow_direction(GrowDirection p_direction); - GrowDirection get_h_grow_direction() const; - - void set_v_grow_direction(GrowDirection p_direction); - GrowDirection get_v_grow_direction() const; - - float get_margin(Margin p_margin) const; Point2 get_begin() const; Point2 get_end() const; void set_position(const Point2 &p_point); - void set_size(const Size2 &p_size); void set_global_position(const Point2 &p_point); - Point2 get_position() const; Point2 get_global_position() const; + + void set_size(const Size2 &p_size); Size2 get_size() const; + Rect2 get_rect() const; Rect2 get_global_rect() const; Rect2 get_window_rect() const; ///< use with care, as it blocks waiting for the visual server @@ -331,14 +336,18 @@ public: float get_rotation() const; float get_rotation_deg() const; + void set_h_grow_direction(GrowDirection p_direction); + GrowDirection get_h_grow_direction() const; + + void set_v_grow_direction(GrowDirection p_direction); + GrowDirection get_v_grow_direction() const; + void set_pivot_offset(const Vector2 &p_pivot); Vector2 get_pivot_offset() const; void set_scale(const Vector2 &p_scale); Vector2 get_scale() const; - void set_area_as_parent_rect(int p_margin = 0); - void show_modal(bool p_exclusive = false); void set_theme(const Ref<Theme> &p_theme); @@ -449,6 +458,7 @@ VARIANT_ENUM_CAST(Control::FocusMode); VARIANT_ENUM_CAST(Control::SizeFlags); VARIANT_ENUM_CAST(Control::CursorShape); VARIANT_ENUM_CAST(Control::LayoutPreset); +VARIANT_ENUM_CAST(Control::LayoutPresetMode); VARIANT_ENUM_CAST(Control::MouseFilter); VARIANT_ENUM_CAST(Control::GrowDirection); VARIANT_ENUM_CAST(Control::Anchor); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 3ffa6d57a4..b0eb12fb6b 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -1182,7 +1182,7 @@ GraphEdit::GraphEdit() { top_layer = memnew(GraphEditFilter(this)); add_child(top_layer); top_layer->set_mouse_filter(MOUSE_FILTER_PASS); - top_layer->set_area_as_parent_rect(); + top_layer->set_anchors_and_margins_preset(Control::PRESET_WIDE); top_layer->connect("draw", this, "_top_layer_draw"); top_layer->set_mouse_filter(MOUSE_FILTER_PASS); top_layer->connect("gui_input", this, "_top_layer_input"); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 7493ea95a8..aa5ae089bf 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -534,7 +534,7 @@ void LineEdit::_notification(int p_what) { switch (p_what) { #ifdef TOOLS_ENABLED case NOTIFICATION_ENTER_TREE: { - if (Engine::get_singleton()->is_editor_hint()) { + if (!get_tree()->is_node_being_edited(this)) { cursor_set_blink_enabled(EDITOR_DEF("text_editor/cursor/caret_blink", false)); cursor_set_blink_speed(EDITOR_DEF("text_editor/cursor/caret_blink_speed", 0.65)); diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 5a2a552943..1460fba89a 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -265,7 +265,7 @@ void PopupPanel::set_child_rect(Control *p_child) { ERR_FAIL_NULL(p_child); Ref<StyleBox> p = get_stylebox("panel"); - p_child->set_area_as_parent_rect(); + p_child->set_anchors_and_margins_preset(Control::PRESET_WIDE); p_child->set_margin(MARGIN_LEFT, p->get_margin(MARGIN_LEFT)); p_child->set_margin(MARGIN_RIGHT, -p->get_margin(MARGIN_RIGHT)); p_child->set_margin(MARGIN_TOP, p->get_margin(MARGIN_TOP)); diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 41f4beb1c9..6044b86ef5 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -343,7 +343,7 @@ void ScrollBar::_notification(int p_what) { double dist = sqrt(target * target); double vel = ((target / dist) * 500) * get_fixed_process_delta_time(); - if (vel >= dist) { + if (Math::abs(vel) >= dist) { set_value(target_scroll); } else { set_value(get_value() + vel); diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 60b6746ae8..05f2809bfc 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -268,7 +268,7 @@ SpinBox::SpinBox() { line_edit = memnew(LineEdit); add_child(line_edit); - line_edit->set_area_as_parent_rect(); + line_edit->set_anchors_and_margins_preset(Control::PRESET_WIDE); //connect("value_changed",this,"_value_changed"); line_edit->connect("text_entered", this, "_text_entered", Vector<Variant>(), CONNECT_DEFERRED); line_edit->connect("focus_exited", this, "_line_edit_focus_exit", Vector<Variant>(), CONNECT_DEFERRED); diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 98a8db336e..80e12e9580 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -367,7 +367,7 @@ void TabContainer::add_child_notify(Node *p_child) { current = 0; previous = 0; } - c->set_area_as_parent_rect(); + c->set_anchors_and_margins_preset(Control::PRESET_WIDE); if (tabs_visible) c->set_margin(MARGIN_TOP, _get_top_margin()); Ref<StyleBox> sb = get_stylebox("panel"); @@ -401,7 +401,7 @@ void TabContainer::set_current_tab(int p_current) { Control *c = tabs[i]; if (i == current) { c->show(); - c->set_area_as_parent_rect(); + c->set_anchors_and_margins_preset(Control::PRESET_WIDE); if (tabs_visible) c->set_margin(MARGIN_TOP, _get_top_margin()); c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP))); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 8d6eb0f8e2..822136820e 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2135,8 +2135,15 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (selected_item->get_children() != NULL && !selected_item->is_collapsed()) { selected_item->set_collapsed(true); } else { - selected_col = columns.size() - 1; - dobreak = false; // fall through to key_up + if (columns.size() == 1) { // goto parent with one column + TreeItem *parent = selected_item->get_parent(); + if (selected_item != get_root() && parent && parent->is_selectable(selected_col) && !(hide_root && parent == get_root())) { + select_single_item(parent, get_root(), selected_col); + } + } else { + selected_col = columns.size() - 1; + dobreak = false; // fall through to key_up + } } } else { if (select_mode == SELECT_MULTI) { @@ -2149,6 +2156,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { } update(); accept_event(); + ensure_cursor_is_visible(); if (dobreak) { break; |