The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
list.c File Reference

idunn: a list view: rows of 32 pixels with an icon, text and a muted second text on the right; and a grid view, the same with tiles: a 48 pixel colour icon and the name below it (a file manager's icons). More...

#include "idunn_internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Macros

#define PAD   4
#define ROW   32
#define ROW_GAP   1
#define ROW_PAD   10
#define ICON   16
#define ICON_GAP   10
#define TILE_W   96
#define TILE_H   88
#define PICTURE   48
#define ROW_PICTURE   20
#define TILE_GAP   4
#define FIND_MS   1000
#define FIND_MAX   32
#define EDIT_TILE_W   150
#define EDIT_ROW_W   360
#define COLUMNS_MAX   8

Enumerations

enum  { EDIT_OPEN , EDIT_KEEP , EDIT_CANCEL }

Functions

idunn_widget_t * idunn_list_view (void)
 a list view: rows with a Lucide icon (or NULL), text and a muted second text on the right (or NULL).
idunn_widget_t * idunn_grid_view (void)
 a grid view: the same, as tiles of a 48 point Tela icon (a file or folder icon name) with the name below; it wraps to the width.
int idunn_list_view_add (idunn_widget_t *list, const char *icon, const char *text, const char *detail)
void idunn_list_view_clear (idunn_widget_t *list)
void idunn_list_view_set_item (idunn_widget_t *list, int item, const char *icon, const char *text, const char *detail)
 change an item; only its row is drawn again, and only when something differs (a list that is filled again each second, as in a monitor).
void idunn_list_view_set_count (idunn_widget_t *list, int count)
 keep only the first count items (a smaller count than now)
int idunn_list_view_count (const idunn_widget_t *list)
void idunn_list_view_set_multiple (idunn_widget_t *list, bool multiple)
 many items can be selected (Ctrl, Shift, Ctrl+A)
void idunn_list_view_set_framed (idunn_widget_t *list, bool framed)
 a border, the large radius and the card colour around the items
bool idunn_list_view_selected (const idunn_widget_t *list, int row)
void idunn_list_view_select (idunn_widget_t *list, int row, bool selected)
void idunn_list_view_go_to (idunn_widget_t *list, int item)
 make an item the current one and select only it, as the arrow keys do
int idunn_list_view_columns (const idunn_widget_t *list)
 the items in a line (1 for a list, more for a grid)
int idunn_list_view_current (const idunn_widget_t *list)
 the item with the keyboard, or -1
const char * idunn_list_view_text (const idunn_widget_t *list, int row)
void idunn_list_view_on_select (idunn_widget_t *list, idunn_callback_t on_select, void *data)
 on_select after the selection changes; on_activate on a double click or Enter
void idunn_list_view_on_activate (idunn_widget_t *list, idunn_callback_t on_activate, void *data)
void idunn_list_view_set_single_click (idunn_widget_t *list, bool single)
 one click activates an item (a launcher); the arrow keys only move
void idunn_list_view_on_menu (idunn_widget_t *list, idunn_callback_t on_menu, void *data)
 on_menu on a right click: on an item that is not selected, it selects only that item first; on no item, nothing stays selected.
int idunn_list_view_item_at (const idunn_widget_t *list, int32_t x, int32_t y)
 the item at a point of the window, or -1
bool idunn_list_view_edit (idunn_widget_t *list, int item, size_t start, size_t end, idunn_edit_done_t done, void *data)
 edit an item's text in place (a rename): a text field over it with the bytes start to end selected ((size_t)-1: to the end).
void idunn_list_view_set_columns (idunn_widget_t *list, const int32_t *widths, int count)
 columns at the right of the rows: an item's detail is split at tabs, and each part is drawn at the right of its column (numbers line up).
int idunn_list_columns_at (const idunn_widget_t *list, int32_t *name_x, int32_t *row_x, int32_t *left, int32_t *right)
 the columns of a list view, in the window (for its heads).
bool idunn_list_column_left (const idunn_widget_t *list, int column)
 true if a column of a list is drawn at its left
void idunn_list_view_set_columns_left (idunn_widget_t *list, uint32_t mask)
 draw some columns at their left, for text (a date, a type); the others stay at their right, for numbers.
void idunn_list_set_heads (idunn_widget_t *list, idunn_widget_t *heads)
 the heads over a list (NULL: none); the list draws them again on layout
bool idunn_list_view_editing (const idunn_widget_t *list)
 true while an item is edited in place
void idunn_list_view_set_pictures (idunn_widget_t *list, bool pictures)
 rows with a Tela icon (a file or folder icon name) in colour, not a Lucide one

Detailed Description

idunn: a list view: rows of 32 pixels with an icon, text and a muted second text on the right; and a grid view, the same with tiles: a 48 pixel colour icon and the name below it (a file manager's icons).

the item under the pointer has the hover colour, selected items the selection colour. only the items that can be seen are drawn, so a long list in a scroll view is fast.

keys: the arrows, Page Up and Page Down, Home and End move the current row (with Shift, they select from the anchor when many can be selected); Space selects; Enter activates; Ctrl+A selects all; typing finds the next row that starts with what was typed. the mouse: a press selects, Ctrl toggles a row, Shift selects a range, a double click activates.

idunn_list_view_edit puts a text field over an item's name (a rename in place). Enter or a press elsewhere keeps the text, Escape takes it back. the result comes from a timer, after the event, so the program can make the list again in it.

Macro Definition Documentation

◆ PAD

#define PAD   4

◆ ROW

#define ROW   32

◆ ROW_GAP

#define ROW_GAP   1

◆ ROW_PAD

#define ROW_PAD   10

◆ ICON

#define ICON   16

◆ ICON_GAP

#define ICON_GAP   10

◆ TILE_W

#define TILE_W   96

◆ TILE_H

#define TILE_H   88

◆ PICTURE

#define PICTURE   48

◆ ROW_PICTURE

#define ROW_PICTURE   20

◆ TILE_GAP

#define TILE_GAP   4

◆ FIND_MS

#define FIND_MS   1000

◆ FIND_MAX

#define FIND_MAX   32

◆ EDIT_TILE_W

#define EDIT_TILE_W   150

◆ EDIT_ROW_W

#define EDIT_ROW_W   360

◆ COLUMNS_MAX

#define COLUMNS_MAX   8

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
EDIT_OPEN 
EDIT_KEEP 
EDIT_CANCEL 

Function Documentation

◆ idunn_list_view()

idunn_widget_t * idunn_list_view ( void )

a list view: rows with a Lucide icon (or NULL), text and a muted second text on the right (or NULL).

put it in a scroll view when it is long.

◆ idunn_grid_view()

idunn_widget_t * idunn_grid_view ( void )

a grid view: the same, as tiles of a 48 point Tela icon (a file or folder icon name) with the name below; it wraps to the width.

◆ idunn_list_view_add()

int idunn_list_view_add ( idunn_widget_t * list,
const char * icon,
const char * text,
const char * detail )
Returns
the index of the new item, or -1

◆ idunn_list_view_clear()

void idunn_list_view_clear ( idunn_widget_t * list)

◆ idunn_list_view_set_item()

void idunn_list_view_set_item ( idunn_widget_t * list,
int item,
const char * icon,
const char * text,
const char * detail )

change an item; only its row is drawn again, and only when something differs (a list that is filled again each second, as in a monitor).

◆ idunn_list_view_set_count()

void idunn_list_view_set_count ( idunn_widget_t * list,
int count )

keep only the first count items (a smaller count than now)

◆ idunn_list_view_count()

int idunn_list_view_count ( const idunn_widget_t * list)

◆ idunn_list_view_set_multiple()

void idunn_list_view_set_multiple ( idunn_widget_t * list,
bool multiple )

many items can be selected (Ctrl, Shift, Ctrl+A)

◆ idunn_list_view_set_framed()

void idunn_list_view_set_framed ( idunn_widget_t * list,
bool framed )

a border, the large radius and the card colour around the items

◆ idunn_list_view_selected()

bool idunn_list_view_selected ( const idunn_widget_t * list,
int row )

◆ idunn_list_view_select()

void idunn_list_view_select ( idunn_widget_t * list,
int row,
bool selected )

◆ idunn_list_view_go_to()

void idunn_list_view_go_to ( idunn_widget_t * list,
int item )

make an item the current one and select only it, as the arrow keys do

◆ idunn_list_view_columns()

int idunn_list_view_columns ( const idunn_widget_t * list)

the items in a line (1 for a list, more for a grid)

◆ idunn_list_view_current()

int idunn_list_view_current ( const idunn_widget_t * list)

the item with the keyboard, or -1

◆ idunn_list_view_text()

const char * idunn_list_view_text ( const idunn_widget_t * list,
int row )

◆ idunn_list_view_on_select()

void idunn_list_view_on_select ( idunn_widget_t * list,
idunn_callback_t on_select,
void * data )

on_select after the selection changes; on_activate on a double click or Enter

◆ idunn_list_view_on_activate()

void idunn_list_view_on_activate ( idunn_widget_t * list,
idunn_callback_t on_activate,
void * data )

◆ idunn_list_view_set_single_click()

void idunn_list_view_set_single_click ( idunn_widget_t * list,
bool single )

one click activates an item (a launcher); the arrow keys only move

◆ idunn_list_view_on_menu()

void idunn_list_view_on_menu ( idunn_widget_t * list,
idunn_callback_t on_menu,
void * data )

on_menu on a right click: on an item that is not selected, it selects only that item first; on no item, nothing stays selected.

open a menu with idunn_menu_popup_at_pointer.

◆ idunn_list_view_item_at()

int idunn_list_view_item_at ( const idunn_widget_t * list,
int32_t x,
int32_t y )

the item at a point of the window, or -1

◆ idunn_list_view_edit()

bool idunn_list_view_edit ( idunn_widget_t * list,
int item,
size_t start,
size_t end,
idunn_edit_done_t done,
void * data )

edit an item's text in place (a rename): a text field over it with the bytes start to end selected ((size_t)-1: to the end).

Enter, or the keyboard going elsewhere, keeps the text; Escape takes it back.

Returns
false when the item is not there or the list is not shown.

◆ idunn_list_view_set_columns()

void idunn_list_view_set_columns ( idunn_widget_t * list,
const int32_t * widths,
int count )

columns at the right of the rows: an item's detail is split at tabs, and each part is drawn at the right of its column (numbers line up).

Parameters
widthsthe columns' widths in design pixels, left to right.

◆ idunn_list_columns_at()

int idunn_list_columns_at ( const idunn_widget_t * list,
int32_t * name_x,
int32_t * row_x,
int32_t * left,
int32_t * right )

the columns of a list view, in the window (for its heads).

Parameters
name_xwhere the names start.
row_xwhere the rows start.
left,rightthe edges of each column (COLUMNS_MAX at most).
Returns
the column count (0 for a grid).

◆ idunn_list_column_left()

bool idunn_list_column_left ( const idunn_widget_t * list,
int column )

true if a column of a list is drawn at its left

◆ idunn_list_view_set_columns_left()

void idunn_list_view_set_columns_left ( idunn_widget_t * list,
uint32_t mask )

draw some columns at their left, for text (a date, a type); the others stay at their right, for numbers.

bit c is column c.

◆ idunn_list_set_heads()

void idunn_list_set_heads ( idunn_widget_t * list,
idunn_widget_t * heads )

the heads over a list (NULL: none); the list draws them again on layout

◆ idunn_list_view_editing()

bool idunn_list_view_editing ( const idunn_widget_t * list)

true while an item is edited in place

◆ idunn_list_view_set_pictures()

void idunn_list_view_set_pictures ( idunn_widget_t * list,
bool pictures )

rows with a Tela icon (a file or folder icon name) in colour, not a Lucide one