def generate_widget_init_helper(widget, is_graph_description=False):
    font_size = '0'

    # Common attributes
    color = [channel / 255.0 for channel in widget.color]
    offset_x, offset_x_is_left = get_offset_x(widget)
    offset_y, offset_y_is_top = get_offset_y(widget)

    if is_text_type(widget.type):
        # Attributes deriven from text properties
        font_size = widget.font
        width = str(widget.length) + ' * kFontGlyphWidths[fontSize]'
        height = 'kFontGlyphHeights[fontSize]'
    else:
        # Attributes deriven from graph properties
        width = str(widget.bar_width) + ' * static_cast<uint32_t>(widget->runningValues.size())'
        height = widget.height

    is_left_aligned = not widget.negative_alignment[0]
    is_top_aligned = not widget.negative_alignment[1]

    # We have offset_x, offset_y, width and height which together determine the bounding box.  If
    # offset_x_is_left, the bounding box X would be in [offset_x, offset_x + width], otherwise it
    # would be in [offset_x - width, offset_x].  Similarly for y.  Since we use negative values to
    # mean aligned to the right side of the screen, we need to make sure that:
    #
    # - if left aligned: offset_x - width is at minimum 1
    # - if right aligned: offset_x + width is at maximum -1
    #
    # We therefore have the following combinations for the X axis:
    #
    # -  offset_x_is_left &&  is_left_aligned: [offset_x, offset_x + width]
    # -  offset_x_is_left && !is_left_aligned: [offset_x, std::min(offset_x + width, -1)]
    # - !offset_x_is_left &&  is_left_aligned: [std::max(1, offset_x - width), offset_x]
    # - !offset_x_is_left && !is_left_aligned: [offset_x - width, offset_x]
    #
    # Similarly for y.
    coord0, coord2 = get_bounding_box_coords('offsetX', 'width', offset_x_is_left, is_left_aligned)
    coord1, coord3 = get_bounding_box_coords('offsetY', 'height', offset_y_is_top, is_top_aligned)

    return template_init_widget.format(
        subwidget='description.' if is_graph_description else '',
        offset_x=offset_x,
        offset_y=offset_y,
        width=width,
        height=height,
        type=widget.type,
        font_size=font_size,
        coord0=coord0,
        coord1=coord1,
        coord2=coord2,
        coord3=coord3,
        color_r=color[0],
        color_g=color[1],
        color_b=color[2],
        color_a=color[3])