Skip to content

Commit

Permalink
Merge branch 'pr-41'
Browse files Browse the repository at this point in the history
  • Loading branch information
TankOs committed Mar 14, 2017
2 parents add850e + db1f201 commit f86aaec
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examples/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SampleApp {
void OnAddButtonVClick();
void OnToggleTitlebarClick();
void OnHideWindowClicked();
void OnToggleOrientationClick();
void OnToggleSpaceClick();
void OnLimitCharsToggle();
void OnLoadThemeClick();
Expand All @@ -36,6 +37,7 @@ class SampleApp {
sfg::Window::Ptr m_wndmain;
sfg::Box::Ptr m_boxbuttonsh;
sfg::Box::Ptr m_boxbuttonsv;
sfg::Box::Ptr m_boxorientation;
sfg::Entry::Ptr m_entry;
sfg::Table::Ptr m_table;
sfg::ScrolledWindow::Ptr m_scrolled_window;
Expand Down Expand Up @@ -226,6 +228,7 @@ void SampleApp::Run() {
}
}

auto btntoggleori = sfg::Button::Create( L"Box Orientation" );
auto btntogglespace = sfg::Button::Create( L"Box Spacing" );
auto btnloadstyle = sfg::Button::Create( L"Load theme" );

Expand Down Expand Up @@ -254,6 +257,7 @@ void SampleApp::Run() {

auto boxtoolbar2 = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL );
boxtoolbar2->SetSpacing( 5.f );
boxtoolbar2->Pack( btntoggleori, false );
boxtoolbar2->Pack( btntogglespace, false );
boxtoolbar2->Pack( btnloadstyle, false );

Expand All @@ -263,6 +267,11 @@ void SampleApp::Run() {
m_boxbuttonsv = sfg::Box::Create( sfg::Box::Orientation::VERTICAL );
m_boxbuttonsv->SetSpacing( 5.f );

m_boxorientation = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL );
m_boxorientation->SetSpacing( 5.f );
m_boxorientation->Pack( sfg::Button::Create( L"Hello" ) );
m_boxorientation->Pack( sfg::Button::Create( L"World" ) );

auto username_entry = sfg::Entry::Create();
username_entry->SetMaximumLength( 8 );

Expand Down Expand Up @@ -411,6 +420,7 @@ void SampleApp::Run() {
boxmain->Pack( box_image, true );
boxmain->Pack( separatorh, false );
boxmain->Pack( m_table, true );
boxmain->Pack( m_boxorientation, true );
boxmain->Pack( m_scrolled_window );

auto notebook1 = sfg::Notebook::Create();
Expand Down Expand Up @@ -444,6 +454,7 @@ void SampleApp::Run() {
btnaddbuttonv->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &SampleApp::OnAddButtonVClick, this ) );
m_titlebar_toggle->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &SampleApp::OnToggleTitlebarClick, this ) );
btnhidewindow->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &SampleApp::OnHideWindowClicked, this ) );
btntoggleori->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &SampleApp::OnToggleOrientationClick, this ) );
btntogglespace->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &SampleApp::OnToggleSpaceClick, this ) );
m_limit_check->GetSignal( sfg::ToggleButton::OnToggle ).Connect( std::bind( &SampleApp::OnLimitCharsToggle, this ) );
btnloadstyle->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &SampleApp::OnLoadThemeClick, this ) );
Expand Down Expand Up @@ -626,6 +637,15 @@ void SampleApp::OnHideWindowClicked() {
m_wndmain->Show( !m_wndmain->IsLocallyVisible() );
}

void SampleApp::OnToggleOrientationClick() {
if( m_boxorientation->GetOrientation() == sfg::Box::Orientation::HORIZONTAL ) {
m_boxorientation->SetOrientation( sfg::Box::Orientation::VERTICAL );
}
else {
m_boxorientation->SetOrientation( sfg::Box::Orientation::HORIZONTAL );
}
}

void SampleApp::OnToggleSpaceClick() {
if( m_scrolled_window_box->GetSpacing() > .0f ) {
m_scrolled_window_box->SetSpacing( .0f );
Expand All @@ -635,6 +655,7 @@ void SampleApp::OnToggleSpaceClick() {
}
}


void SampleApp::OnLimitCharsToggle() {
if( m_limit_check->IsActive() ) {
m_entry->SetMaximumLength( 4 );
Expand Down
10 changes: 10 additions & 0 deletions include/SFGUI/Box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ class SFGUI_API Box : public Container {
*/
void ReorderChild( Widget::Ptr widget, std::size_t position );

/** Set orientation.
* @param orientation Orientation.
*/
void SetOrientation( Orientation orientation );

/** Get orientation.
* @return Orientation.
*/
Orientation GetOrientation() const;

/** Set spacing.
* @param spacing Spacing.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/SFGUI/Box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,20 @@ void Box::SetSpacing( float spacing ) {
Invalidate();
}

void Box::SetOrientation( Orientation orientation ) {
m_orientation = orientation;
RequestResize();
Invalidate();
}

float Box::GetSpacing() const {
return m_spacing;
}

Box::Orientation Box::GetOrientation() const {
return m_orientation;
}

void Box::AllocateChildren() const {
unsigned int num_expand( 0 );
unsigned int num_visible( 0 );
Expand Down

0 comments on commit f86aaec

Please sign in to comment.