-Add some offset to spinboxes in tree, so revert icon does not annoy much when pops up, fixes #3415

This commit is contained in:
Juan Linietsky 2016-02-02 20:44:42 -03:00
parent 9c4c6e4c4f
commit 6349c50f5a
4 changed files with 55 additions and 18 deletions

View file

@ -482,7 +482,7 @@ void TreeItem::deselect(int p_column) {
_cell_deselected(p_column);
}
void TreeItem::add_button(int p_column,const Ref<Texture>& p_button,int p_id) {
void TreeItem::add_button(int p_column, const Ref<Texture>& p_button, int p_id, bool p_disabled) {
ERR_FAIL_INDEX( p_column, cells.size() );
@ -492,6 +492,7 @@ void TreeItem::add_button(int p_column,const Ref<Texture>& p_button,int p_id) {
if (p_id<0)
p_id=cells[p_column].buttons.size();
button.id=p_id;
button.disabled=p_disabled;
cells[p_column].buttons.push_back(button);
_changed_notify(p_column);
}
@ -533,6 +534,15 @@ int TreeItem::get_button_by_id(int p_column,int p_id) const {
return -1;
}
bool TreeItem::is_button_disabled(int p_column, int p_idx) const {
ERR_FAIL_INDEX_V( p_column, cells.size(), false );
ERR_FAIL_INDEX_V( p_idx, cells[p_column].buttons.size(), false );
return cells[p_column].buttons[p_idx].disabled;
}
void TreeItem::set_button(int p_column,int p_idx,const Ref<Texture>& p_button){
ERR_FAIL_COND( p_button.is_null() );
@ -672,10 +682,11 @@ void TreeItem::_bind_methods() {
ObjectTypeDB::bind_method(_MD("clear_custom_bg_color","column"),&TreeItem::clear_custom_bg_color);
ObjectTypeDB::bind_method(_MD("get_custom_bg_color","column"),&TreeItem::get_custom_bg_color);
ObjectTypeDB::bind_method(_MD("add_button","column","button:Texture","button_idx"),&TreeItem::add_button);
ObjectTypeDB::bind_method(_MD("add_button","column","button:Texture","button_idx","disabled"),&TreeItem::add_button,DEFVAL(-1),DEFVAL(false));
ObjectTypeDB::bind_method(_MD("get_button_count","column"),&TreeItem::get_button_count);
ObjectTypeDB::bind_method(_MD("get_button:Texture","column","button_idx"),&TreeItem::get_button);
ObjectTypeDB::bind_method(_MD("erase_button","column","button_idx"),&TreeItem::erase_button);
ObjectTypeDB::bind_method(_MD("is_button_disabled","column","button_idx"),&TreeItem::is_button_disabled);
ObjectTypeDB::bind_method(_MD("set_tooltip","column","tooltip"),&TreeItem::set_tooltip);
ObjectTypeDB::bind_method(_MD("get_tooltip","column"),&TreeItem::get_tooltip);
@ -1015,14 +1026,15 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2&
Point2i o = Point2i( ofs+w-s.width, p_pos.y )-cache.offset+p_draw_ofs;
if (cache.click_type==Cache::CLICK_BUTTON && cache.click_item==p_item && cache.click_column==i) {
if (cache.click_type==Cache::CLICK_BUTTON && cache.click_item==p_item && cache.click_column==i && !p_item->cells[i].buttons[j].disabled) {
//being pressed
cache.button_pressed->draw(get_canvas_item(),Rect2(o,s));
}
o.y+=(label_h-s.height)/2;
o+=cache.button_pressed->get_offset();
b->draw(ci,o);
b->draw(ci,o,p_item->cells[i].buttons[j].disabled?Color(1,1,1,0.5):Color(1,1,1,1));
w-=s.width+cache.button_margin;
bw+=s.width+cache.button_margin;
}
@ -1472,7 +1484,13 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_
for(int j=c.buttons.size()-1;j>=0;j--) {
Ref<Texture> b=c.buttons[j].texture;
int w = b->get_size().width + cache.button_pressed->get_minimum_size().width;
if (x>col_width-w) {
if (c.buttons[j].disabled) {
pressed_button=-1;
cache.click_type=Cache::CLICK_NONE;
return -1;
}
pressed_button=j;
cache.click_type=Cache::CLICK_BUTTON;
cache.click_index=j;

View file

@ -86,8 +86,9 @@ friend class Tree;
struct Button {
int id;
bool disabled;
Ref<Texture> texture;
Button() { id=0; }
Button() { id=0; disabled=false; }
};
Vector< Button > buttons;
@ -172,12 +173,13 @@ public:
void set_icon_max_width(int p_column,int p_max);
int get_icon_max_width(int p_column) const;
void add_button(int p_column,const Ref<Texture>& p_button,int p_id=-1);
void add_button(int p_column,const Ref<Texture>& p_button,int p_id=-1,bool p_disabled=false);
int get_button_count(int p_column) const;
Ref<Texture> get_button(int p_column,int p_idx) const;
int get_button_id(int p_column,int p_idx) const;
void erase_button(int p_column,int p_idx);
int get_button_by_id(int p_column,int p_id) const;
bool is_button_disabled(int p_column,int p_idx) const;
void set_button(int p_column,int p_idx,const Ref<Texture>& p_button);
/* range works for mode number or mode combo */

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

View file

@ -714,7 +714,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty
RES r = v;
if (r.is_valid() && r->get_path().is_resource_file() && r->get_import_metadata().is_valid()) {
menu->add_separator();
menu->add_icon_item(get_icon("Reload","EditorIcons"),"Re-Import",OBJ_MENU_REIMPORT);
menu->add_icon_item(get_icon("ReloadSmall","EditorIcons"),"Re-Import",OBJ_MENU_REIMPORT);
}
/*if (r.is_valid() && r->get_path().is_resource_file()) {
menu->set_item_tooltip(1,r->get_path());
@ -2127,11 +2127,13 @@ void PropertyEditor::_check_reload_status(const String&p_name, TreeItem* item) {
bool has_reload=false;
int found=-1;
bool is_disabled=false;
for(int i=0;i<item->get_button_count(1);i++) {
if (item->get_button_id(1,i)==3) {
found=i;
is_disabled=item->is_button_disabled(1,i);
break;
}
}
@ -2149,7 +2151,7 @@ void PropertyEditor::_check_reload_status(const String&p_name, TreeItem* item) {
bool changed = _is_property_different(v,vorig,usage);
if ((found!=-1)!=changed) {
//if ((found!=-1 && !is_disabled)!=changed) {
if (changed) {
@ -2158,11 +2160,9 @@ void PropertyEditor::_check_reload_status(const String&p_name, TreeItem* item) {
}
}
}
//}
}
}
@ -2176,10 +2176,20 @@ void PropertyEditor::_check_reload_status(const String&p_name, TreeItem* item) {
}
}
//print_line("found: "+itos(found)+" has reload: "+itos(has_reload)+" is_disabled "+itos(is_disabled));
if (found!=-1 && !has_reload) {
item->erase_button(1,found);
if (!is_disabled) {
item->erase_button(1,found);
if (item->get_cell_mode(1)==TreeItem::CELL_MODE_RANGE && item->get_text(1)==String()) {
item->add_button(1,get_icon("ReloadEmpty","EditorIcons"),3,true);
}
}
} else if (found==-1 && has_reload) {
item->add_button(1,get_icon("Reload","EditorIcons"),3);
item->add_button(1,get_icon("ReloadSmall","EditorIcons"),3);
} else if (found!=-1 && has_reload && is_disabled) {
item->erase_button(1,found);
item->add_button(1,get_icon("ReloadSmall","EditorIcons"),3);
}
}
@ -2348,7 +2358,7 @@ void PropertyEditor::_refresh_item(TreeItem *p_item) {
if (!has_reload && found!=-1) {
p_item->erase_button(1,found);
} else if (has_reload && found==-1) {
p_item->add_button(1,get_icon("Reload","EditorIcons"),3);
p_item->add_button(1,get_icon("ReloadSmall","EditorIcons"),3);
}
#endif
Dictionary d=p_item->get_metadata(0);
@ -3092,7 +3102,9 @@ void PropertyEditor::update_tree() {
}
bool has_reload=false;
if (_might_be_in_instance()) {
bool mbi = _might_be_in_instance();
if (mbi) {
Variant vorig;
Dictionary d=item->get_metadata(0);
@ -3103,7 +3115,7 @@ void PropertyEditor::update_tree() {
if (_is_property_different(v,vorig,usage)) {
//print_line("FOR "+String(p.name)+" RELOAD WITH: "+String(v)+"("+Variant::get_type_name(v.get_type())+")=="+String(vorig)+"("+Variant::get_type_name(vorig.get_type())+")");
item->add_button(1,get_icon("Reload","EditorIcons"),3);
item->add_button(1,get_icon("ReloadSmall","EditorIcons"),3);
has_reload=true;
}
}
@ -3115,11 +3127,16 @@ void PropertyEditor::update_tree() {
Variant orig_value;
if (scr->get_property_default_value(p.name,orig_value)) {
if (orig_value!=obj->get(p.name)) {
item->add_button(1,get_icon("Reload","EditorIcons"),3);
item->add_button(1,get_icon("ReloadSmall","EditorIcons"),3);
has_reload=true;
}
}
}
if (mbi && !has_reload && item->get_cell_mode(1)==TreeItem::CELL_MODE_RANGE && item->get_text(1)==String()) {
item->add_button(1,get_icon("ReloadEmpty","EditorIcons"),3,true);
}
}