You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Reduce repetitive code in FoldableContainer
This commit is contained in:
@@ -219,8 +219,7 @@ void FoldableContainer::gui_input(const Ref<InputEvent> &p_event) {
|
|||||||
|
|
||||||
Ref<InputEventMouseMotion> m = p_event;
|
Ref<InputEventMouseMotion> m = p_event;
|
||||||
if (m.is_valid()) {
|
if (m.is_valid()) {
|
||||||
Rect2 title_rect = Rect2(0, (title_position == POSITION_TOP) ? 0 : get_size().height - title_minimum_size.height, get_size().width, title_minimum_size.height);
|
if (_get_title_rect().has_point(m->get_position())) {
|
||||||
if (title_rect.has_point(m->get_position())) {
|
|
||||||
if (!is_hovering) {
|
if (!is_hovering) {
|
||||||
is_hovering = true;
|
is_hovering = true;
|
||||||
queue_redraw();
|
queue_redraw();
|
||||||
@@ -241,8 +240,7 @@ void FoldableContainer::gui_input(const Ref<InputEvent> &p_event) {
|
|||||||
|
|
||||||
Ref<InputEventMouseButton> b = p_event;
|
Ref<InputEventMouseButton> b = p_event;
|
||||||
if (b.is_valid()) {
|
if (b.is_valid()) {
|
||||||
Rect2 title_rect = Rect2(0, (title_position == POSITION_TOP) ? 0 : get_size().height - title_minimum_size.height, get_size().width, title_minimum_size.height);
|
if (b->get_button_index() == MouseButton::LEFT && b->is_pressed() && _get_title_rect().has_point(b->get_position())) {
|
||||||
if (b->get_button_index() == MouseButton::LEFT && b->is_pressed() && title_rect.has_point(b->get_position())) {
|
|
||||||
set_folded(!folded);
|
set_folded(!folded);
|
||||||
emit_signal(SNAME("folding_changed"), folded);
|
emit_signal(SNAME("folding_changed"), folded);
|
||||||
accept_event();
|
accept_event();
|
||||||
@@ -272,9 +270,7 @@ void FoldableContainer::_notification(int p_what) {
|
|||||||
title_controls_width += h_separation;
|
title_controls_width += h_separation;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect2 title_rect(
|
const Rect2 title_rect = _get_title_rect();
|
||||||
Point2(0, (title_position == POSITION_TOP) ? 0 : size.height - title_minimum_size.height),
|
|
||||||
Size2(size.width, title_minimum_size.height));
|
|
||||||
_draw_flippable_stylebox(title_style, title_rect);
|
_draw_flippable_stylebox(title_style, title_rect);
|
||||||
|
|
||||||
Size2 title_ms = title_style->get_minimum_size();
|
Size2 title_ms = title_style->get_minimum_size();
|
||||||
@@ -431,6 +427,10 @@ Ref<Texture2D> FoldableContainer::_get_title_icon() const {
|
|||||||
return theme_cache.folded_arrow;
|
return theme_cache.folded_arrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect2 FoldableContainer::_get_title_rect() const {
|
||||||
|
return Rect2(0, (title_position == POSITION_TOP) ? 0 : (get_size().height - title_minimum_size.height), get_size().width, title_minimum_size.height);
|
||||||
|
}
|
||||||
|
|
||||||
void FoldableContainer::_update_title_min_size() const {
|
void FoldableContainer::_update_title_min_size() const {
|
||||||
Ref<StyleBox> title_style = folded ? theme_cache.title_collapsed_style : theme_cache.title_style;
|
Ref<StyleBox> title_style = folded ? theme_cache.title_collapsed_style : theme_cache.title_style;
|
||||||
Ref<Texture2D> icon = _get_title_icon();
|
Ref<Texture2D> icon = _get_title_icon();
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ private:
|
|||||||
|
|
||||||
Ref<StyleBox> _get_title_style() const;
|
Ref<StyleBox> _get_title_style() const;
|
||||||
Ref<Texture2D> _get_title_icon() const;
|
Ref<Texture2D> _get_title_icon() const;
|
||||||
|
Rect2 _get_title_rect() const;
|
||||||
int _get_h_separation() const { return MAX(theme_cache.h_separation, 0); }
|
int _get_h_separation() const { return MAX(theme_cache.h_separation, 0); }
|
||||||
real_t _get_title_controls_width() const;
|
real_t _get_title_controls_width() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user