void tcontrol::request_reduce_width(const unsigned maximum_width) { assert(config_); if(!label_.empty() && can_wrap()) { tpoint size = get_best_text_size( tpoint(0,0), tpoint(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 { DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_) << "' failed; either no label or wrapping not allowed.\n"; } }
void styled_widget::update_canvas() { const int max_width = get_text_maximum_width(); const int max_height = get_text_maximum_height(); // set label in canvases for(auto & canvas : canvas_) { canvas.set_variable("text", variant(label_)); canvas.set_variable("text_markup", variant(use_markup_)); canvas.set_variable("text_link_aware", variant(get_link_aware())); // Possible TODO: Consider making a formula_callable for colours color_t link_color = get_link_color(); std::vector<variant> link_color_as_list{variant(link_color.r), variant(link_color.g), variant(link_color.b), variant(link_color.a)}; canvas.set_variable("text_link_color", variant(&link_color_as_list)); canvas.set_variable("text_alignment", variant(encode_text_alignment(text_alignment_))); canvas.set_variable("text_maximum_width", variant(max_width)); canvas.set_variable("text_maximum_height", variant(max_height)); canvas.set_variable("text_wrap_mode", variant(can_wrap() ? PANGO_ELLIPSIZE_NONE : PANGO_ELLIPSIZE_END)); canvas.set_variable("text_characters_per_line", variant(get_characters_per_line())); } }
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 ttext_box::update_canvas() { /***** Gather the info *****/ // Set the cursor info. const unsigned start = get_selection_start(); const int length = get_selection_length(); set_maximum_length(max_input_length_); PangoEllipsizeMode ellipse_mode = PANGO_ELLIPSIZE_NONE; if(!can_wrap()) { if((start + length) > (get_length() / 2)) { ellipse_mode = PANGO_ELLIPSIZE_START; } else { ellipse_mode = PANGO_ELLIPSIZE_END; } } set_ellipse_mode(ellipse_mode); // Set the selection info unsigned start_offset = 0; unsigned end_offset = 0; if(length == 0) { // No nothing. } else if(length > 0) { start_offset = get_cursor_position(start).x; end_offset = get_cursor_position(start + length).x; } else { start_offset = get_cursor_position(start + length).x; end_offset = get_cursor_position(start).x; } /***** Set in all canvases *****/ const int max_width = get_text_maximum_width(); const int max_height = get_text_maximum_height(); for(auto & tmp : canvas()) { tmp.set_variable("text", variant(get_value())); tmp.set_variable("text_x_offset", variant(text_x_offset_)); tmp.set_variable("text_y_offset", variant(text_y_offset_)); tmp.set_variable("text_maximum_width", variant(max_width)); tmp.set_variable("text_maximum_height", variant(max_height)); tmp.set_variable("cursor_offset", variant(get_cursor_position(start + length).x)); tmp.set_variable("selection_offset", variant(start_offset)); tmp.set_variable("selection_width", variant(end_offset - start_offset)); tmp.set_variable("text_wrap_mode", variant(ellipse_mode)); } }
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 tcontrol::update_canvas() { const int max_width = get_text_maximum_width(); const int max_height = get_text_maximum_height(); // set label in canvases for(auto & canvas : canvas_) { canvas.set_variable("text", variant(label_)); canvas.set_variable("text_markup", variant(use_markup_)); canvas.set_variable("text_link_aware", variant(get_link_aware())); canvas.set_variable("text_link_color", variant(get_link_color())); canvas.set_variable("text_alignment", variant(encode_text_alignment(text_alignment_))); canvas.set_variable("text_maximum_width", variant(max_width)); canvas.set_variable("text_maximum_height", variant(max_height)); canvas.set_variable("text_wrap_mode", variant(can_wrap() ? PANGO_ELLIPSIZE_NONE : PANGO_ELLIPSIZE_END)); canvas.set_variable("text_characters_per_line", variant(get_characters_per_line())); } }
/** * Get the text's ellipsize mode. * * Note that if can_wrap is true, it override the manual setting. */ PangoEllipsizeMode get_text_ellipse_mode() const { return can_wrap() ? PANGO_ELLIPSIZE_NONE : text_ellipse_mode_; }
/** * Wraps the contents of the widget. * * @todo implement this function properly. * * @param maximum_width The wanted maximum width of the widget. * * @pre can_wrap() == true. */ virtual void layout_wrap(const unsigned /*maximum_width*/) { assert(can_wrap()); }
point styled_widget::get_best_text_size(point minimum_size, point maximum_size) const { log_scope2(log_gui_layout, LOG_SCOPE_HEADER); assert(!label_.empty()); const point border(config_->text_extra_width, config_->text_extra_height); point size = minimum_size - border; renderer_.set_link_aware(get_link_aware()) .set_link_color(get_link_color()); renderer_.set_text(label_, use_markup_); renderer_.set_family_class(config_->text_font_family); renderer_.set_font_size(config_->text_font_size); renderer_.set_font_style(config_->text_font_style); renderer_.set_alignment(text_alignment_); // Try with the minimum wanted size. const int maximum_width = text_maximum_width_ != 0 ? text_maximum_width_ : maximum_size.x; renderer_.set_maximum_width(maximum_width); if(can_wrap()) { renderer_.set_ellipse_mode(PANGO_ELLIPSIZE_NONE); } renderer_.set_characters_per_line(get_characters_per_line()); if(get_characters_per_line() != 0 && !can_wrap()) { WRN_GUI_L << LOG_HEADER << " Limited the number of characters per line, " << "but wrapping is not set, output may not be as expected.\n"; } DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_) << "' status: " << " minimum_size " << minimum_size << " maximum_size " << maximum_size << " text_maximum_width_ " << text_maximum_width_ << " can_wrap " << can_wrap() << " characters_per_line " << get_characters_per_line() << " truncated " << renderer_.is_truncated() << " renderer size " << renderer_.get_size() << ".\n"; // If doesn't fit try the maximum. if(renderer_.is_truncated() && !can_wrap()) { // FIXME if maximum size is defined we should look at that // but also we don't adjust for the extra text space yet!!! maximum_size = point(config_->max_width, config_->max_height); renderer_.set_maximum_width(maximum_size.x ? maximum_size.x - border.x : -1); } size = renderer_.get_size() + border; if(size.x < minimum_size.x) { size.x = minimum_size.x; } if(size.y < minimum_size.y) { size.y = minimum_size.y; } DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_) << "' result " << size << ".\n"; return size; }