Пример #1
0
/**
 * @brief Inserts a character into a string, at a given position
 * @param string a string. If @a string is NULL, a new string is created
 * @param pos the position where to insert the char
 * @param c the character to insert into the string
 * @return Returns the string
 */
Etk_String *etk_string_insert_char(Etk_String *string, int pos, char c)
{
   int i;

   if (!string)
      return etk_string_insert_char(etk_string_new(NULL), pos, c);
   if (c == '\0')
      return etk_string_truncate(string, pos);

   pos = ETK_CLAMP(pos, 0, string->length);
   if (string->length + 1 > string->allocated_length)
   {
      string->string = realloc(string->string, SIZE_TO_ALLOC(string->length + 1) + 1);
      string->allocated_length = SIZE_TO_ALLOC(string->length + 1);
   }
   for (i = string->length - 1; i >= pos; i--)
      string->string[i + 1] = string->string[i];

   string->string[pos] = c;
   string->length++;
   string->string[string->length] = '\0';

   etk_object_notify(ETK_OBJECT(string), "string");
   return string;
}
Пример #2
0
/**
 * @brief Sets the max width allocated to the image in the image model. If the image's width is smaller than
 * the max width, the image will be aligned according to @a alignment
 * @param model an image model
 * @param width the max width of the image of the model. 0 or a negative value to make Etk compute the width of
 * each image
 * @param alignment the horizontal alignment of the image, used if its width is smaller than the max width,
 * from 0.0 (left alignment) to 1.0 (right alignment)
 */
void etk_tree_model_image_width_set(Etk_Tree_Model *model, int width, float alignment)
{
   Etk_Tree_Model_Image *image_model;

   if (!(image_model = (Etk_Tree_Model_Image *)model))
      return;

   image_model->width = width;
   image_model->halign = ETK_CLAMP(alignment, 0.0, 1.0);
   etk_widget_redraw_queue(ETK_WIDGET(model->tree));
}
Пример #3
0
/**
 * @brief Attachs a widget to the table
 * @param table a table
 * @param child the widget to attach
 * @param left_attach the column where the left side of the child will be attached (starting from 0)
 * @param right_attach the column where the right side of the child will be attached (starting from 0)
 * @param top_attach the row where the top side of the child will be attached (starting from 0)
 * @param bottom_attach the row where the bottom side of the child will be attached (starting from 0)
 * @param fill_policy The fill policy of the child
 * @param x_padding the amount of free space on the left and on the right sides of the child widget
 * @param y_padding the amount of free space on the top and on the bottom sides of the child widget
 */
void etk_table_attach(Etk_Table *table, Etk_Widget *child, int left_attach, int right_attach, int top_attach, int bottom_attach, Etk_Table_Fill_Policy fill_policy, int x_padding, int y_padding)
{
   Etk_Table_Cell *cell;
   int i, j;

   if (!table || !table->cells || !child)
      return;

   left_attach = ETK_CLAMP(left_attach, 0, table->num_cols - 1);
   right_attach = ETK_CLAMP(right_attach, left_attach, table->num_cols - 1);
   top_attach = ETK_CLAMP(top_attach, 0, table->num_rows - 1);
   bottom_attach = ETK_CLAMP(bottom_attach, top_attach, table->num_rows - 1);

   cell = malloc(sizeof(Etk_Table_Cell));
   cell->left_attach = left_attach;
   cell->right_attach = right_attach;
   cell->top_attach = top_attach;
   cell->bottom_attach = bottom_attach;
   cell->x_padding = x_padding;
   cell->y_padding = y_padding;
   cell->fill_policy = fill_policy;
   cell->child = child;

   for (i = left_attach; i <= right_attach; i++)
   {
      for (j = top_attach; j <= bottom_attach; j++)
      {
         etk_table_cell_clear(table, i, j);
         table->cells[CELL_INDEX(table, i, j)] = cell;
      }
   }

   table->cells_list = eina_list_append(table->cells_list, cell);
   cell->node = eina_list_last(table->cells_list);

   etk_object_data_set(ETK_OBJECT(child), "_Etk_Table::Cell", cell);
   etk_widget_parent_set(child, ETK_WIDGET(table));
   etk_signal_emit(ETK_CONTAINER_CHILD_ADDED_SIGNAL, ETK_OBJECT(table), child);
}
Пример #4
0
/**
 * @brief Inserts a text with a specific length into a string, at a given position
 * @param string a string. If @a string is NULL, a new string is created
 * @param pos the position where to insert the text (starting from 0)
 * @param text the text to insert into the string
 * @param length the maximum length of the text to insert
 * @return Returns the string
 */
Etk_String *etk_string_insert_sized(Etk_String *string, int pos, const char *text, int length)
{
   if (!string)
      return etk_string_new_sized(text, length);
   if (!text || text[0] == '\0' || length <= 0)
      return string;

   pos = ETK_CLAMP(pos, 0, string->length);
   length = _etk_string_strlen_max(text, length);
   if (string->length + length > string->allocated_length)
   {
      string->string = realloc(string->string, SIZE_TO_ALLOC(string->length + length) + 1);
      string->allocated_length = SIZE_TO_ALLOC(string->length + length);
   }

   memmove(&string->string[pos + length], &string->string[pos], string->length - pos);
   strncpy(&string->string[pos], text, length);
   string->length += length;
   string->string[string->length] = '\0';

   etk_object_notify(ETK_OBJECT(string), "string");
   return string;
}