diff --git a/src/widget_manager.cpp b/src/widget_manager.cpp index ef3f181e7..b7996bd7c 100644 --- a/src/widget_manager.cpp +++ b/src/widget_manager.cpp @@ -97,6 +97,54 @@ bool WidgetManager::add_wgt return true; } +//----------------------------------------------------------------------------- +bool WidgetManager::insert_column() +{ + const int NUM_WGTS = m_widgets.size(); + const int LAST_BREAK = m_breaks.size() - 1; + + //Check if we are at the beginning of a line + if( NUM_WGTS > 0) + { + if( LAST_BREAK < 0 || m_breaks[LAST_BREAK] != NUM_WGTS - 1) + { + std::cerr << "Warning: tried to add a column that is not at " << + "the beginning of a line, after widget with token " << + m_widgets[NUM_WGTS - 1].token << ".\n"; + return false; + } + } + + + const int NUM_COLUMNS = m_columns.size(); + + if( NUM_COLUMNS > 0 ) + { + if( !column_starts(NUM_WGTS) ) m_columns.push_back(NUM_WGTS); + else + { + if( NUM_WGTS > 0 ) + { + std::cerr << "Warning: tried to add a column twice at " << + "widget with token" << m_widgets[NUM_WGTS - 1].token << + ".\n"; + } + else + { + std::cerr << "Warning: tried to add a column twice before" << + "the first widget.\n"; + } + return false; + } + } + else + { + m_columns.push_back(NUM_WGTS); + } + + return true; +} + //----------------------------------------------------------------------------- bool WidgetManager::break_line() { @@ -143,6 +191,22 @@ void WidgetManager::delete_wgts() m_widgets.clear(); } +//----------------------------------------------------------------------------- +bool WidgetManager::column_starts( const int WGT ) const +{ + const int NUM_COLUMNS = m_columns.size(); + + if( NUM_COLUMNS > 0) + { + for(int i = 0; i < NUM_COLUMNS; ++i ) + { + if( m_columns[i] == WGT ) return true; + } + } + + return false; +} + //----------------------------------------------------------------------------- bool WidgetManager::line_breaks( const int WGT ) const { @@ -232,9 +296,21 @@ int WidgetManager::calc_width() const curr_width = 0; } + if( column_starts(i) ) + { + curr_width = calc_column_width(i); + + //Jump to the next line break + for(; i < NUM_WIDGETS; ++i) + { + if( line_breaks(i) ) break; + } + } } + if( curr_width > total_width ) total_width = curr_width; + std::cerr << total_width << " W" <m_height; } + + if( column_starts(i) ) + { + column_height = calc_column_height(i); + if( line_height < column_height ) + { + line_height = column_height; + } + } + if( line_breaks(i) ) break; } return line_height; } +//----------------------------------------------------------------------------- +int WidgetManager::calc_column_width(const int START_WGT) const +{ + int column_width = 0; + const int NUM_WIDGETS = m_widgets.size(); + + for( int i = START_WGT; i < NUM_WIDGETS; ++i ) + { + if( column_width < m_widgets[i].widget->m_width ) + { + column_width = m_widgets[i].widget->m_width; + } + if( line_breaks(i) ) break; + } + + return column_width; +} + +//----------------------------------------------------------------------------- +int WidgetManager::calc_column_height(const int START_WGT) const +{ + int total_height = 0; + const int NUM_WIDGETS = m_widgets.size(); + + for( int i = START_WGT; i < NUM_WIDGETS; ++i ) + { + total_height += m_widgets[i].widget->m_height; + if( line_breaks(i) ) break; + } + + return total_height; +} + //----------------------------------------------------------------------------- void WidgetManager::set_selected_wgt(const int TOKEN) { @@ -938,6 +1059,7 @@ int WidgetManager::handle_joystick return m_selected_wgt_token; } +//FIXME: find_left_widget() doesn't works properly yet /** find_left_widget() returns the closest widget to the left of START_WGT. */ int WidgetManager::find_left_widget(const int START_WGT) const @@ -1002,6 +1124,7 @@ int WidgetManager::find_left_widget(const int START_WGT) const return closest_wgt; } +//FIXME: find_right_widget() doesn't works properly yet /** find_right_widget() returns the closest widget to the right of START_WGT */ int WidgetManager::find_right_widget(const int START_WGT) const diff --git a/src/widget_manager.hpp b/src/widget_manager.hpp index 7a440a27c..8b6f11aac 100644 --- a/src/widget_manager.hpp +++ b/src/widget_manager.hpp @@ -57,6 +57,7 @@ class WidgetManager std::vector m_widgets; std::vector m_breaks; + std::vector m_columns; int m_x; int m_y; @@ -82,13 +83,17 @@ class WidgetManager /* int m_default_scroll_x_speed;*/ int m_default_scroll_y_speed; + bool column_starts( const int WGT ) const; bool line_breaks( const int WGT ) const; + int get_next_line_break(const int START_WGT) const; int find_id(const int TOKEN) const; int calc_width() const; int calc_height() const; int calc_line_width(const int START_WGT) const; int calc_line_height(const int START_WGT) const; + int calc_column_width(const int START_WGT) const; + int calc_column_height(const int START_WGT) const; int find_left_widget(const int START_WGT) const; int find_right_widget(const int START_WGT) const; @@ -105,12 +110,18 @@ public: bool add_wgt ( const int TOKEN, //A number that names the widget. - const int MIN_WIDTH, //These values are percentages not pixels. If - //the widget is inside a container, 100% - //represents container space, otherwise 100% is - //the screen space. + const int MIN_WIDTH, //These values are percentages not pixels. 100% + //is the whole screen. const int MIN_HEIGHT ); + bool insert_column(); //This function changes the orientation from left to + //right and top to bottom of the widgets at line + //breaks, and switches it, making it from top to + //bottom, and left to right at a line break, + //until the next line break or the next layout() + //call. It can only be used right at the beginning + //of a line (that is, before any widgets have been + //created, or just after a line break). bool break_line(); void delete_wgts();