Merge pull request #9743 from Noshyaar/pr-itemlist
Enhanced About dialog, Add ItemList auto_height
This commit is contained in:
commit
93422e2ff2
3 changed files with 49 additions and 8 deletions
|
@ -58,6 +58,7 @@
|
|||
#include "servers/physics_2d_server.h"
|
||||
#include "translation.h"
|
||||
#include "version.h"
|
||||
#include "version_hash.gen.h"
|
||||
#include <stdio.h>
|
||||
// plugins
|
||||
#include "asset_library_editor_plugin.h"
|
||||
|
@ -5986,14 +5987,18 @@ EditorNode::EditorNode() {
|
|||
logo->set_texture(gui_base->get_icon("Logo", "EditorIcons"));
|
||||
hbc->add_child(logo);
|
||||
|
||||
String hash = String(VERSION_HASH);
|
||||
if (hash.length() != 0)
|
||||
hash = "." + hash.left(7);
|
||||
|
||||
Label *about_text = memnew(Label);
|
||||
about_text->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
|
||||
about_text->set_text(VERSION_FULL_NAME + String::utf8("\n\u00A9 2007-2017 Juan Linietsky, Ariel Manzur.\n\u00A9 2014-2017 ") +
|
||||
about_text->set_text(VERSION_FULL_NAME + hash + String::utf8("\n\u00A9 2007-2017 Juan Linietsky, Ariel Manzur.\n\u00A9 2014-2017 ") +
|
||||
TTR("Godot Engine contributors") + "\n");
|
||||
hbc->add_child(about_text);
|
||||
|
||||
TabContainer *tc = memnew(TabContainer);
|
||||
tc->set_custom_minimum_size(Size2(600, 240) * EDSCALE);
|
||||
tc->set_custom_minimum_size(Size2(630, 240) * EDSCALE);
|
||||
tc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
vbc->add_child(tc);
|
||||
|
||||
|
@ -6021,14 +6026,14 @@ EditorNode::EditorNode() {
|
|||
dev_vbc->add_child(lbl);
|
||||
|
||||
ItemList *il = memnew(ItemList);
|
||||
il->set_max_columns(32);
|
||||
il->set_max_columns(16);
|
||||
il->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
il->set_custom_minimum_size(Size2(0, i == 3 ? DEV_NAMES_COUNT * 7.6 : 30) * EDSCALE);
|
||||
il->set_fixed_column_width(230 * EDSCALE);
|
||||
il->set_auto_height(true);
|
||||
const char **dev_names_ptr = dev_src[i];
|
||||
while (*dev_names_ptr)
|
||||
il->add_item(String::utf8(*dev_names_ptr++), NULL, false);
|
||||
dev_vbc->add_child(il);
|
||||
il->set_fixed_column_width(240 * EDSCALE);
|
||||
|
||||
HSeparator *hs = memnew(HSeparator);
|
||||
hs->set_modulate(Color(0, 0, 0, 0));
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "item_list.h"
|
||||
#include "project_settings.h"
|
||||
#include "os/os.h"
|
||||
#include "project_settings.h"
|
||||
|
||||
void ItemList::add_item(const String &p_item, const Ref<Texture> &p_texture, bool p_selectable) {
|
||||
|
||||
|
@ -743,12 +743,10 @@ void ItemList::_notification(int p_what) {
|
|||
|
||||
Size2 size = get_size();
|
||||
|
||||
float page = size.height - bg->get_minimum_size().height;
|
||||
int width = size.width - bg->get_minimum_size().width;
|
||||
if (scroll_bar->is_visible()) {
|
||||
width -= mw + bg->get_margin(MARGIN_RIGHT);
|
||||
}
|
||||
scroll_bar->set_page(page);
|
||||
|
||||
draw_style_box(bg, Rect2(Point2(), size));
|
||||
|
||||
|
@ -883,8 +881,12 @@ void ItemList::_notification(int p_what) {
|
|||
}
|
||||
|
||||
if (all_fit) {
|
||||
float page = size.height - bg->get_minimum_size().height;
|
||||
float max = MAX(page, ofs.y + max_h);
|
||||
if (auto_height)
|
||||
auto_height_value = ofs.y + max_h + bg->get_minimum_size().height;
|
||||
scroll_bar->set_max(max);
|
||||
scroll_bar->set_page(page);
|
||||
//print_line("max: "+rtos(max)+" page "+rtos(page));
|
||||
if (max <= page) {
|
||||
scroll_bar->set_value(0);
|
||||
|
@ -1253,6 +1255,26 @@ Array ItemList::_get_items() const {
|
|||
return items;
|
||||
}
|
||||
|
||||
Size2 ItemList::get_minimum_size() const {
|
||||
|
||||
if (auto_height) {
|
||||
return Size2(0, auto_height_value);
|
||||
}
|
||||
return Size2();
|
||||
}
|
||||
|
||||
void ItemList::set_auto_height(bool p_enable) {
|
||||
|
||||
auto_height = p_enable;
|
||||
shape_changed = true;
|
||||
update();
|
||||
}
|
||||
|
||||
bool ItemList::has_auto_height() const {
|
||||
|
||||
return auto_height;
|
||||
}
|
||||
|
||||
void ItemList::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_item", "text", "icon:Texture", "selectable"), &ItemList::add_item, DEFVAL(Variant()), DEFVAL(true));
|
||||
|
@ -1323,6 +1345,9 @@ void ItemList::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_allow_rmb_select", "allow"), &ItemList::set_allow_rmb_select);
|
||||
ClassDB::bind_method(D_METHOD("get_allow_rmb_select"), &ItemList::get_allow_rmb_select);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_auto_height", "enable"), &ItemList::set_auto_height);
|
||||
ClassDB::bind_method(D_METHOD("has_auto_height"), &ItemList::has_auto_height);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_item_at_pos", "pos", "exact"), &ItemList::get_item_at_pos, DEFVAL(false));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("ensure_current_is_visible"), &ItemList::ensure_current_is_visible);
|
||||
|
@ -1340,6 +1365,7 @@ void ItemList::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Multi"), "set_select_mode", "get_select_mode");
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select");
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "max_text_lines"), "set_max_text_lines", "get_max_text_lines");
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "auto_height"), "set_auto_height", "has_auto_height");
|
||||
ADD_GROUP("Columns", "");
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "max_columns"), "set_max_columns", "get_max_columns");
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "same_column_width"), "set_same_column_width", "is_same_column_width");
|
||||
|
@ -1372,6 +1398,8 @@ ItemList::ItemList() {
|
|||
same_column_width = false;
|
||||
max_text_lines = 1;
|
||||
max_columns = 1;
|
||||
auto_height = false;
|
||||
auto_height_value = 0.0f;
|
||||
|
||||
scroll_bar = memnew(VScrollBar);
|
||||
add_child(scroll_bar);
|
||||
|
|
|
@ -78,6 +78,9 @@ private:
|
|||
bool ensure_selected_visible;
|
||||
bool same_column_width;
|
||||
|
||||
bool auto_height;
|
||||
float auto_height_value;
|
||||
|
||||
Vector<Item> items;
|
||||
Vector<int> separators;
|
||||
|
||||
|
@ -198,6 +201,11 @@ public:
|
|||
void set_icon_scale(real_t p_scale);
|
||||
real_t get_icon_scale() const;
|
||||
|
||||
void set_auto_height(bool p_enable);
|
||||
bool has_auto_height() const;
|
||||
|
||||
Size2 get_minimum_size() const;
|
||||
|
||||
VScrollBar *get_v_scroll() { return scroll_bar; }
|
||||
|
||||
ItemList();
|
||||
|
|
Loading…
Reference in a new issue