Przeglądaj źródła

Account for TreeItem's Cell icon and center the text Popup vertically

Micky 3 lat temu
rodzic
commit
550616293a
1 zmienionych plików z 6 dodań i 1 usunięć
  1. 6 1
      scene/gui/tree.cpp

+ 6 - 1
scene/gui/tree.cpp

@@ -3591,12 +3591,17 @@ bool Tree::edit_selected() {
 	} else if (c.mode == TreeItem::CELL_MODE_STRING || c.mode == TreeItem::CELL_MODE_RANGE) {
 	} else if (c.mode == TreeItem::CELL_MODE_STRING || c.mode == TreeItem::CELL_MODE_RANGE) {
 		Rect2 popup_rect;
 		Rect2 popup_rect;
 
 
-		Vector2 ofs(0, (text_editor->get_size().height - rect.size.height) / 2);
+		Vector2 ofs(0, Math::floor((text_editor->get_size().height - rect.size.height) / 2)); // "floor()" centers vertically.
 
 
 		Point2i textedpos = get_screen_position() + rect.position - ofs;
 		Point2i textedpos = get_screen_position() + rect.position - ofs;
 		cache.text_editor_position = textedpos;
 		cache.text_editor_position = textedpos;
 		popup_rect.position = textedpos;
 		popup_rect.position = textedpos;
 		popup_rect.size = rect.size;
 		popup_rect.size = rect.size;
+
+		// Account for icon.
+		popup_rect.position.x += c.get_icon_size().x;
+		popup_rect.size.x -= c.get_icon_size().x;
+
 		text_editor->clear();
 		text_editor->clear();
 		text_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::range_step_decimals(c.step)));
 		text_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::range_step_decimals(c.step)));
 		text_editor->select_all();
 		text_editor->select_all();