Merge pull request #11617 from groud/fix_bad_display

Fixes bad display
This commit is contained in:
Rémi Verschelde 2017-09-27 22:15:00 +02:00 committed by GitHub
commit da144fed4c
8 changed files with 74 additions and 52 deletions

View file

@ -3936,7 +3936,6 @@ AnimationKeyEditor::AnimationKeyEditor() {
key_editor_tab->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
key_editor = memnew(PropertyEditor);
key_editor->set_anchors_and_margins_preset(Control::PRESET_WIDE);
key_editor->hide_top_label();
key_editor->set_name(TTR("Key"));
key_editor_tab->add_child(key_editor);

View file

@ -1790,7 +1790,6 @@ EditorHelp::EditorHelp() {
{
class_desc = memnew(RichTextLabel);
vbc->add_child(class_desc);
class_desc->set_anchors_and_margins_preset(Control::PRESET_WIDE);
class_desc->set_v_size_flags(SIZE_EXPAND_FILL);
class_desc->add_color_override("selection_color", EDITOR_DEF("text_editor/highlighting/selection_color", Color(0.2, 0.2, 1)));
class_desc->connect("meta_clicked", this, "_class_desc_select");

View file

@ -161,7 +161,6 @@ EditorLog::EditorLog() {
log->set_selection_enabled(true);
log->set_focus_mode(FOCUS_CLICK);
log->set_custom_minimum_size(Size2(0, 180) * EDSCALE);
log->set_anchors_and_margins_preset(Control::PRESET_WIDE);
log->set_v_size_flags(SIZE_EXPAND_FILL);
log->set_h_size_flags(SIZE_EXPAND_FILL);
vb->add_child(log);

View file

@ -5083,9 +5083,6 @@ EditorNode::EditorNode() {
play_cc = memnew(CenterContainer);
play_cc->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
menu_hb->add_child(play_cc);
play_cc->set_anchors_and_margins_preset(Control::PRESET_WIDE);
play_cc->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_BEGIN, 10);
play_cc->set_margin(MARGIN_TOP, 5);
play_button_panel = memnew(PanelContainer);
// play_button_panel->add_style_override("panel", gui_base->get_stylebox("PlayButtonPanel", "EditorStyles"));

View file

@ -1504,7 +1504,6 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
Control *input_base = memnew(Control);
input_base->set_name(TTR("Input Map"));
input_base->set_anchors_and_margins_preset(Control::PRESET_WIDE);
tab_container->add_child(input_base);
VBoxContainer *vbc = memnew(VBoxContainer);

View file

@ -3268,7 +3268,6 @@ VisualScriptEditor::VisualScriptEditor() {
graph = memnew(GraphEdit);
add_child(graph);
graph->set_anchors_and_margins_preset(Control::PRESET_WIDE);
graph->set_h_size_flags(SIZE_EXPAND_FILL);
graph->connect("node_selected", this, "_node_selected");
graph->connect("_begin_node_move", this, "_begin_node_move");
graph->connect("_end_node_move", this, "_end_node_move");

View file

@ -1472,45 +1472,20 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) {
}
void Control::set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) {
if (!is_inside_tree())
return;
Point2 new_pos;
// Calculate the size if the node is not resized
Size2 min_size = get_minimum_size();
Size2 new_size = get_size();
Size2 parent_size = get_parent_area_size();
// Width
switch (p_preset) {
case PRESET_TOP_WIDE:
case PRESET_BOTTOM_WIDE:
case PRESET_HCENTER_WIDE:
case PRESET_WIDE:
new_size.x = parent_size.x - 2 * p_margin;
break;
default:
if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_HEIGHT) {
new_size.x = min_size.x;
}
break;
}
// Height
switch (p_preset) {
case PRESET_LEFT_WIDE:
case PRESET_RIGHT_WIDE:
case PRESET_VCENTER_WIDE:
case PRESET_WIDE:
new_size.y = parent_size.y - 2 * p_margin;
break;
default:
if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_WIDTH) {
new_size.y = min_size.y;
}
break;
}
// x pos
float pw = _get_parent_range(0);
float ph = _get_parent_range(1);
//Left
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_BOTTOM_LEFT:
@ -1520,25 +1495,25 @@ void Control::set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resiz
case PRESET_LEFT_WIDE:
case PRESET_HCENTER_WIDE:
case PRESET_WIDE:
new_pos.x = p_margin;
data.margin[0] = pw * (0.0 - data.anchor[0]) + p_margin;
break;
case PRESET_CENTER_TOP:
case PRESET_CENTER_BOTTOM:
case PRESET_CENTER:
case PRESET_VCENTER_WIDE:
new_pos.x = (parent_size.x - new_size.x) / 2.0;
data.margin[0] = pw * (0.5 - data.anchor[0]) - new_size.x / 2;
break;
case PRESET_TOP_RIGHT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_RIGHT:
case PRESET_RIGHT_WIDE:
new_pos.x = parent_size.x - new_size.x - p_margin;
data.margin[0] = pw * (1.0 - data.anchor[0]) - new_size.x - p_margin;
break;
}
// y pos
// Top
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_TOP_RIGHT:
@ -1548,26 +1523,81 @@ void Control::set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resiz
case PRESET_TOP_WIDE:
case PRESET_VCENTER_WIDE:
case PRESET_WIDE:
new_pos.y = p_margin;
data.margin[1] = ph * (0.0 - data.anchor[1]) + p_margin;
break;
case PRESET_CENTER_LEFT:
case PRESET_CENTER_RIGHT:
case PRESET_CENTER:
case PRESET_HCENTER_WIDE:
new_pos.y = (parent_size.y - new_size.y) / 2.0;
data.margin[1] = ph * (0.5 - data.anchor[1]) - new_size.y / 2;
break;
case PRESET_BOTTOM_LEFT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_BOTTOM:
case PRESET_BOTTOM_WIDE:
new_pos.y = parent_size.y - new_size.y - p_margin;
data.margin[1] = ph * (1.0 - data.anchor[1]) - new_size.y - p_margin;
break;
}
set_position(new_pos);
set_size(new_size);
// Right
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_BOTTOM_LEFT:
case PRESET_CENTER_LEFT:
case PRESET_LEFT_WIDE:
data.margin[2] = pw * (0.0 - data.anchor[2]) + new_size.x + p_margin;
break;
case PRESET_CENTER_TOP:
case PRESET_CENTER_BOTTOM:
case PRESET_CENTER:
case PRESET_VCENTER_WIDE:
data.margin[2] = pw * (0.5 - data.anchor[2]) + new_size.x / 2;
break;
case PRESET_TOP_RIGHT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_RIGHT:
case PRESET_TOP_WIDE:
case PRESET_RIGHT_WIDE:
case PRESET_BOTTOM_WIDE:
case PRESET_HCENTER_WIDE:
case PRESET_WIDE:
data.margin[2] = pw * (1.0 - data.anchor[2]) - p_margin;
break;
}
// Bottom
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_TOP_RIGHT:
case PRESET_CENTER_TOP:
case PRESET_TOP_WIDE:
data.margin[3] = ph * (0.0 - data.anchor[3]) + new_size.y + p_margin;
break;
case PRESET_CENTER_LEFT:
case PRESET_CENTER_RIGHT:
case PRESET_CENTER:
case PRESET_HCENTER_WIDE:
data.margin[3] = ph * (0.5 - data.anchor[3]) + new_size.y / 2;
break;
case PRESET_BOTTOM_LEFT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_BOTTOM:
case PRESET_LEFT_WIDE:
case PRESET_RIGHT_WIDE:
case PRESET_BOTTOM_WIDE:
case PRESET_VCENTER_WIDE:
case PRESET_WIDE:
data.margin[3] = ph * (1.0 - data.anchor[3]) - p_margin;
break;
}
_size_changed();
}
void Control::set_anchors_and_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) {

View file

@ -265,7 +265,7 @@ void PopupPanel::set_child_rect(Control *p_child) {
ERR_FAIL_NULL(p_child);
Ref<StyleBox> p = get_stylebox("panel");
p_child->set_anchors_and_margins_preset(Control::PRESET_WIDE);
p_child->set_anchors_preset(Control::PRESET_WIDE);
p_child->set_margin(MARGIN_LEFT, p->get_margin(MARGIN_LEFT));
p_child->set_margin(MARGIN_RIGHT, -p->get_margin(MARGIN_RIGHT));
p_child->set_margin(MARGIN_TOP, p->get_margin(MARGIN_TOP));