mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-03-29 23:35:30 +01:00
Fix PopupMenu
margin and separation calculations
This commit is contained in:
parent
be3b2cf08f
commit
54f6334f40
@ -35,8 +35,6 @@
|
|||||||
#include "core/input/shortcut.h"
|
#include "core/input/shortcut.h"
|
||||||
#include "core/os/keyboard.h"
|
#include "core/os/keyboard.h"
|
||||||
#include "core/os/os.h"
|
#include "core/os/os.h"
|
||||||
#include "core/string/print_string.h"
|
|
||||||
#include "core/string/translation.h"
|
|
||||||
#include "scene/gui/margin_container.h"
|
#include "scene/gui/margin_container.h"
|
||||||
#include "scene/gui/scroll_bar.h"
|
#include "scene/gui/scroll_bar.h"
|
||||||
#include "scene/gui/scroll_container.h"
|
#include "scene/gui/scroll_container.h"
|
||||||
@ -144,8 +142,7 @@ int PopupMenu::_get_items_total_height() const {
|
|||||||
items_total_height += MAX(items[i].get_icon_size().height, font_height) + vsep;
|
items_total_height += MAX(items[i].get_icon_size().height, font_height) + vsep;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtract a separator which is not needed for the last item.
|
return items_total_height;
|
||||||
return items_total_height - vsep;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopupMenu::_scroll_to_item(int p_item) {
|
void PopupMenu::_scroll_to_item(int p_item) {
|
||||||
@ -174,16 +171,12 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const {
|
|||||||
int vseparation = get_theme_constant("vseparation");
|
int vseparation = get_theme_constant("vseparation");
|
||||||
float font_h = get_theme_font("font")->get_height();
|
float font_h = get_theme_font("font")->get_height();
|
||||||
|
|
||||||
Point2 ofs = style->get_offset() + Point2(0, vseparation / 2);
|
real_t ofs = style->get_margin(MARGIN_TOP) + control->get_position().y;
|
||||||
|
|
||||||
for (int i = 0; i < items.size(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
if (i > 0) {
|
ofs += MAX(items[i].get_icon_size().height, font_h) + vseparation;
|
||||||
ofs.y += vseparation;
|
|
||||||
}
|
|
||||||
|
|
||||||
ofs.y += MAX(items[i].get_icon_size().height, font_h);
|
if (p_over.y < ofs) {
|
||||||
|
|
||||||
if (p_over.y - control->get_position().y < ofs.y) {
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -354,7 +347,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
|
|||||||
|
|
||||||
// Make an area which does not include v scrollbar, so that items are not activated when dragging scrollbar.
|
// Make an area which does not include v scrollbar, so that items are not activated when dragging scrollbar.
|
||||||
Transform2D xform = get_global_transform_with_canvas();
|
Transform2D xform = get_global_transform_with_canvas();
|
||||||
Point2 item_origin = xform.get_origin();
|
Point2 item_origin = scroll_container->get_global_position();
|
||||||
float scroll_width = scroll_container->get_v_scrollbar()->is_visible_in_tree() ? scroll_container->get_v_scrollbar()->get_size().width : 0;
|
float scroll_width = scroll_container->get_v_scrollbar()->is_visible_in_tree() ? scroll_container->get_v_scrollbar()->get_size().width : 0;
|
||||||
Size2 item_size = (control->get_global_rect().get_size() - Vector2(scroll_width, 0)) * xform.get_scale();
|
Size2 item_size = (control->get_global_rect().get_size() - Vector2(scroll_width, 0)) * xform.get_scale();
|
||||||
Rect2 item_clickable_area = Rect2(item_origin, item_size);
|
Rect2 item_clickable_area = Rect2(item_origin, item_size);
|
||||||
@ -493,9 +486,9 @@ void PopupMenu::_draw_items() {
|
|||||||
margin_size.width = margin_container->get_theme_constant("margin_right") + margin_container->get_theme_constant("margin_left");
|
margin_size.width = margin_container->get_theme_constant("margin_right") + margin_container->get_theme_constant("margin_left");
|
||||||
margin_size.height = margin_container->get_theme_constant("margin_top") + margin_container->get_theme_constant("margin_bottom");
|
margin_size.height = margin_container->get_theme_constant("margin_top") + margin_container->get_theme_constant("margin_bottom");
|
||||||
|
|
||||||
Ref<StyleBox> style = get_theme_stylebox("panel");
|
|
||||||
Ref<StyleBox> hover = get_theme_stylebox("hover");
|
Ref<StyleBox> hover = get_theme_stylebox("hover");
|
||||||
Ref<Font> font = get_theme_font("font");
|
Ref<Font> font = get_theme_font("font");
|
||||||
|
|
||||||
select_font(font);
|
select_font(font);
|
||||||
|
|
||||||
// In Item::checkable_type enum order (less the non-checkable member)
|
// In Item::checkable_type enum order (less the non-checkable member)
|
||||||
@ -536,7 +529,7 @@ void PopupMenu::_draw_items() {
|
|||||||
check_ofs = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation;
|
check_ofs = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point2 ofs = Point2();
|
Point2 ofs = Point2(0, vseparation / 2);
|
||||||
|
|
||||||
// Loop through all items and draw each.
|
// Loop through all items and draw each.
|
||||||
for (int i = 0; i < items.size(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user