mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
added alignment to BoxContainer
Allows aligning contents of VBoxContainer and HBoxcontainer without having to insert expanding spacers.
This commit is contained in:
parent
20a1c765db
commit
c38808b5b1
2 changed files with 53 additions and 0 deletions
|
@ -99,8 +99,10 @@ void BoxContainer::_resort() {
|
|||
elements exist */
|
||||
|
||||
|
||||
bool has_stretched = false;
|
||||
while(stretch_ratio_total>0) { // first of all, dont even be here if no stretchable objects exist
|
||||
|
||||
has_stretched = true;
|
||||
bool refit_successful=true; //assume refit-test will go well
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
|
@ -143,6 +145,18 @@ void BoxContainer::_resort() {
|
|||
|
||||
|
||||
int ofs=0;
|
||||
if (!has_stretched) {
|
||||
switch (align) {
|
||||
case ALIGN_BEGIN:
|
||||
break;
|
||||
case ALIGN_CENTER:
|
||||
ofs = stretch_diff / 2;
|
||||
break;
|
||||
case ALIGN_END:
|
||||
ofs = stretch_diff;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
first=true;
|
||||
int idx=0;
|
||||
|
@ -254,6 +268,15 @@ void BoxContainer::_notification(int p_what) {
|
|||
}
|
||||
}
|
||||
|
||||
void BoxContainer::set_alignment(AlignMode p_align) {
|
||||
align = p_align;
|
||||
_resort();
|
||||
}
|
||||
|
||||
BoxContainer::AlignMode BoxContainer::get_alignment() const {
|
||||
return align;
|
||||
}
|
||||
|
||||
void BoxContainer::add_spacer(bool p_begin) {
|
||||
|
||||
Control *c = memnew( Control );
|
||||
|
@ -270,10 +293,23 @@ void BoxContainer::add_spacer(bool p_begin) {
|
|||
BoxContainer::BoxContainer(bool p_vertical) {
|
||||
|
||||
vertical=p_vertical;
|
||||
align = ALIGN_BEGIN;
|
||||
// set_ignore_mouse(true);
|
||||
set_stop_mouse(false);
|
||||
}
|
||||
|
||||
void BoxContainer::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_alignment"),&BoxContainer::get_alignment);
|
||||
ObjectTypeDB::bind_method(_MD("set_alignment","alignment"),&BoxContainer::set_alignment);
|
||||
|
||||
BIND_CONSTANT( ALIGN_BEGIN );
|
||||
BIND_CONSTANT( ALIGN_CENTER );
|
||||
BIND_CONSTANT( ALIGN_END );
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT,"alignment", PROPERTY_HINT_ENUM, "Begin,Center,End"), _SCS("set_alignment"),_SCS("get_alignment") );
|
||||
|
||||
}
|
||||
|
||||
MarginContainer* VBoxContainer::add_margin_child(const String& p_label,Control *p_control,bool p_expand) {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue