void tgrid::reduce_height(const unsigned maximum_height) { /***** ***** ***** ***** INIT ***** ***** ***** *****/ log_scope2(log_gui_layout, LOG_SCOPE_HEADER); DBG_GUI_L << LOG_HEADER << " maximum height " << maximum_height << ".\n"; tpoint size = get_best_size(); if(size.y <= static_cast<int>(maximum_height)) { DBG_GUI_L << LOG_HEADER << " Already fits.\n"; return; } /***** ***** ***** ***** Request resize ***** ***** ***** *****/ request_reduce_height(maximum_height); size = get_best_size(); if(size.y <= static_cast<int>(maximum_height)) { DBG_GUI_L << LOG_HEADER << " Resize request honored.\n"; return; } /***** ***** ***** ***** Demand resize ***** ***** ***** *****/ /** @todo Implement. */ /***** ***** ***** ***** Acknowlegde failure ***** ***** ***** *****/ DBG_GUI_L << LOG_HEADER << " Resizing failed.\n"; throw tlayout_exception_height_resize_failed(); }
void tcontrol::layout_shrink_width(const unsigned maximum_width) { DBG_G_L << "tcontrol(" + get_control_type() + ") " + __func__ + ":" << " maximum_width " << maximum_width << ".\n"; /** @todo handle the tooltip properly. */ shrunken_ = true; set_layout_size(tpoint(maximum_width, get_best_size().y)); assert(static_cast<unsigned>(get_best_size().x) == maximum_width); }
void styled_widget::request_reduce_width(const unsigned maximum_width) { assert(config_); if(!label_.empty() && can_wrap()) { point size = get_best_text_size( point(), point(maximum_width - config_->text_extra_width, 0)); size.x += config_->text_extra_width; size.y += config_->text_extra_height; set_layout_size(size); DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_) << "' maximum_width " << maximum_width << " result " << size << ".\n"; } else if(label_.empty()) { point size = get_best_size(); point min_size = get_config_minimum_size(); size.x = std::min(size.x, std::max<int>(maximum_width, min_size.x)); set_layout_size(size); DBG_GUI_L << LOG_HEADER << " styled_widget " << id() << " maximum_width " << maximum_width << " result " << size << ".\n"; } else { DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_) << "' failed; either no label or wrapping not allowed.\n"; } }
void grid::request_reduce_height(const unsigned maximum_height) { point size = get_best_size(); if(size.y <= static_cast<int>(maximum_height)) { /** @todo this point shouldn't be reached, find out why it does. */ return; } const unsigned too_high = size.y - maximum_height; unsigned reduced = 0; for(size_t row = 0; row < rows_; ++row) { unsigned wanted_height = row_height_[row] - (too_high - reduced); /** * @todo Improve this code. * * Now we try every item to be reduced, maybe items need a flag whether * or not to try to reduce and also evaluate whether the force * reduction is still needed. */ if(too_high - reduced >= row_height_[row]) { DBG_GUI_L << LOG_HEADER << " row " << row << " height " << row_height_[row] << " want to reduce " << too_high << " is too small to be reduced fully try 1 pixel.\n"; wanted_height = 1; } /* Reducing the height of a widget causes the widget to save its new size in widget::layout_size_. After that, get_best_size() will return that size and not the originally calculated optimal size. Thus, it's perfectly correct that grid::calculate_best_size() that we call later calls get_best_size() for child widgets as if size reduction had never happened. */ const unsigned height = grid_implementation::row_request_reduce_height( *this, row, wanted_height); if(height < row_height_[row]) { unsigned reduction = row_height_[row] - height; DBG_GUI_L << LOG_HEADER << " row " << row << " height " << row_height_[row] << " want to reduce " << too_high << " reduced " << reduction << " pixels.\n"; size.y -= reduction; reduced += reduction; } if(size.y <= static_cast<int>(maximum_height)) { break; } } size = calculate_best_size(); DBG_GUI_L << LOG_HEADER << " Requested maximum " << maximum_height << " resulting height " << size.y << ".\n"; set_layout_size(size); }
void tcontrol::layout_fit_width(const unsigned maximum_width, const tfit_flags flags) { assert(get_visible() != twidget::INVISIBLE); log_scope2(gui_layout, "tcontrol(" + get_control_type() + ") " + __func__); DBG_G_L << "maximum_width " << maximum_width << " flags " << flags << ".\n"; // Already fits. if(get_best_size().x <= static_cast<int>(maximum_width)) { DBG_G_L << "Already fits.\n"; return; } // Wrap. if((flags & twidget::WRAP) && can_wrap()) { layout_wrap(maximum_width); if(get_best_size().x <= static_cast<int>(maximum_width)) { DBG_G_L << "Success: Wrapped.\n"; return; } } // Horizontal scrollbar. if((flags & twidget::SCROLLBAR) && has_horizontal_scrollbar()) { layout_use_horizontal_scrollbar(maximum_width); if(get_best_size().x <= static_cast<int>(maximum_width)) { DBG_G_L << "Success: Horizontal scrollbar.\n"; return; } } // Shrink. if((flags & twidget::SHRINK) && can_shrink_width()) { layout_shrink_width(maximum_width); DBG_G_L << "Success: Shrunken.\n"; } DBG_G_L << "Failed.\n"; }
void tgrid::request_reduce_height(const unsigned maximum_height) { tpoint size = get_best_size(); if(size.y <= static_cast<int>(maximum_height)) { /** @todo this point shouldn't be reached, find out why it does. */ return; } const unsigned too_high = size.y - maximum_height; unsigned reduced = 0; for(size_t row = 0; row < rows_; ++row) { unsigned wanted_height = row_height_[row] - (too_high - reduced); /** * @todo Improve this code. * * Now we try every item to be reduced, maybe items need a flag whether * or not to try to reduce and also evaluate whether the force * reduction is still needed. */ if(too_high - reduced >= row_height_[row]) { DBG_GUI_L << LOG_HEADER << " row " << row << " height " << row_height_[row] << " want to reduce " << too_high << " is too small to be reduced fully try 1 pixel.\n"; wanted_height = 1; } const unsigned height = tgrid_implementation::row_request_reduce_height( *this, row, wanted_height); if(height < row_height_[row]) { DBG_GUI_L << LOG_HEADER << " row " << row << " height " << row_height_[row] << " want to reduce " << too_high << " reduced " << row_height_[row] - height << " pixels.\n"; size.y -= row_height_[row] - height; row_height_[row] = height; } if(size.y <= static_cast<int>(maximum_height)) { break; } } size = calculate_best_size(); DBG_GUI_L << LOG_HEADER << " Requested maximum " << maximum_height << " resulting height " << size.y << ".\n"; set_layout_size(size); }
void styled_widget::request_reduce_height(const unsigned maximum_height) { if(!label_.empty()) { // Do nothing } else { point size = get_best_size(); point min_size = get_config_minimum_size(); size.y = std::min(size.y, std::max<int>(maximum_height, min_size.y)); set_layout_size(size); DBG_GUI_L << LOG_HEADER << " styled_widget " << id() << " maximum_height " << maximum_height << " result " << size << ".\n"; } }
void grid::request_placement(dispatcher&, const event::ui_event, bool& handled, bool&) { if (get_window()->invalidate_layout_blocked()) { handled = true; return; } point size = get_size(); point best_size = calculate_best_size(); if(size.x >= best_size.x && size.y >= best_size.y) { place(get_origin(), size); handled = true; return; } recalculate_best_size(); if(size.y >= best_size.y) { // We have enough space in the Y direction, but not in the X direction. // Try wrapping the content. request_reduce_width(size.x); best_size = get_best_size(); if(size.x >= best_size.x && size.y >= best_size.y) { // Wrapping succeeded, we still fit vertically. place(get_origin(), size); handled = true; return; } else { // Wrapping failed, we no longer fit. // Reset the sizes of child widgets. layout_initialize(true); } } /* Not enough space. Let the event flow higher up. This is a pre-event handler, so the event flows upwards. */ }
void grid::request_reduce_width(const unsigned maximum_width) { point size = get_best_size(); if(size.x <= static_cast<int>(maximum_width)) { /** @todo this point shouldn't be reached, find out why it does. */ return; } const unsigned too_wide = size.x - maximum_width; unsigned reduced = 0; for(size_t col = 0; col < cols_; ++col) { if(too_wide - reduced >= col_width_[col]) { DBG_GUI_L << LOG_HEADER << " column " << col << " is too small to be reduced.\n"; continue; } const unsigned wanted_width = col_width_[col] - (too_wide - reduced); const unsigned width = grid_implementation::column_request_reduce_width( *this, col, wanted_width); if(width < col_width_[col]) { unsigned reduction = col_width_[col] - width; DBG_GUI_L << LOG_HEADER << " reduced " << reduction << " pixels for column " << col << ".\n"; size.x -= reduction; reduced += reduction; } if(size.x <= static_cast<int>(maximum_width)) { break; } } set_layout_size(calculate_best_size()); }
void *sos_mem_alloc(uint32_t size) { void *ptr; int size_type = get_best_size(size); if(size_type < 0) return NULL; ptr = (void *)_sos_mem_alloc(size_type); if(NULL == ptr) { if(SEC_OK == sos_mem_replenish(size_type)) { return _sos_mem_alloc(size_type); } else { return NULL; } } return ptr; }
void tscrollbar_container::request_reduce_width( const unsigned maximum_width) { DBG_GUI_L << LOG_HEADER << " requested width " << maximum_width << ".\n"; // First ask our content, it might be able to wrap which looks better as // a scrollbar. assert(content_grid_); const unsigned offset = vertical_scrollbar_grid_ && vertical_scrollbar_grid_->get_visible() != twidget::tvisible::invisible ? vertical_scrollbar_grid_->get_best_size().x : 0; content_grid_->request_reduce_width(maximum_width - offset); // Did we manage to achieve the wanted size? tpoint size = get_best_size(); if(static_cast<unsigned>(size.x) <= maximum_width) { DBG_GUI_L << LOG_HEADER << " child honored request, width " << size.x << ".\n"; return; } if(horizontal_scrollbar_mode_ == always_invisible) { DBG_GUI_L << LOG_HEADER << " request failed due to scrollbar mode.\n"; return; } // Always set the bar visible, is a nop when it's already visible. assert(horizontal_scrollbar_grid_); horizontal_scrollbar_grid_->set_visible(twidget::tvisible::visible); size = get_best_size(); const tpoint scrollbar_size = horizontal_scrollbar_grid_->get_best_size(); // If showing the scrollbar increased the width, hide and abort. if(horizontal_scrollbar_mode_ == auto_visible_first_run && scrollbar_size.x > size.x) { horizontal_scrollbar_grid_->set_visible(twidget::tvisible::invisible); DBG_GUI_L << LOG_HEADER << " request failed, showing the scrollbar" << " increased the width to " << scrollbar_size.x << ".\n"; return; } if(maximum_width > static_cast<unsigned>(scrollbar_size.x)) { size.x = maximum_width; } else { size.x = scrollbar_size.x; } // FIXME adjust for the step size of the scrollbar set_layout_size(size); DBG_GUI_L << LOG_HEADER << " resize resulted in " << size.x << ".\n"; }
void tscrollbar_container::request_reduce_height( const unsigned maximum_height) { DBG_GUI_L << LOG_HEADER << " requested height " << maximum_height << ".\n"; /* * First ask the content to reduce it's height. This seems to work for now, * but maybe some sizing hints will be required later. */ /** @todo Evaluate whether sizing hints are required. */ assert(content_grid_); const unsigned offset = horizontal_scrollbar_grid_ && horizontal_scrollbar_grid_->get_visible() != twidget::tvisible::invisible ? horizontal_scrollbar_grid_->get_best_size().y : 0; content_grid_->request_reduce_height(maximum_height - offset); // Did we manage to achieve the wanted size? tpoint size = get_best_size(); if(static_cast<unsigned>(size.y) <= maximum_height) { DBG_GUI_L << LOG_HEADER << " child honored request, height " << size.y << ".\n"; return; } if(vertical_scrollbar_mode_ == always_invisible) { DBG_GUI_L << LOG_HEADER << " request failed due to scrollbar mode.\n"; return; } assert(vertical_scrollbar_grid_); const bool resized = vertical_scrollbar_grid_->get_visible() == twidget::tvisible::invisible; // Always set the bar visible, is a nop is already visible. vertical_scrollbar_grid_->set_visible(twidget::tvisible::visible); const tpoint scrollbar_size = vertical_scrollbar_grid_->get_best_size(); // If showing the scrollbar increased the height, hide and abort. if(resized && scrollbar_size.y > size.y) { vertical_scrollbar_grid_->set_visible(twidget::tvisible::invisible); DBG_GUI_L << LOG_HEADER << " request failed, showing the scrollbar" << " increased the height to " << scrollbar_size.y << ".\n"; return; } if(maximum_height > static_cast<unsigned>(scrollbar_size.y)) { size.y = maximum_height; } else { size.y = scrollbar_size.y; } // FIXME adjust for the step size of the scrollbar set_layout_size(size); DBG_GUI_L << LOG_HEADER << " resize resulted in " << size.y << ".\n"; if(resized) { DBG_GUI_L << LOG_HEADER << " resize modified the width, throw notification.\n"; throw tlayout_exception_width_modified(); } }
tpoint tcontrol::request_reduce_width(const unsigned maximum_width) { return get_best_size(); }