# asset_browser.h ## Index
`TM_TT_TYPE__ASSET_BROWSER`
`enum TM_TT_PROP__ASSET_BROWSER`
`enum tm_asset_save_status`
`enum tm_asset_save_file_tree_modification_type`
`struct tm_asset_save_file_tree_modification_t`
`tm_asset_save_o`

`struct tm_asset_save_i`
`inst`
`can_save_individual_assets()`
`file_tree_modifications()`
`status()`
`save_asset()`
`revert_asset()`
`save_all()`
`save_all_except()`
`asset_root_path()`

`struct tm_asset_browser_create_asset_i`
`inst`
`menu_name`
`asset_name`
`create()`

`tm_asset_browser_create_asset_i_version`

`struct tm_asset_browser_open_asset_api`
`inst`
`open()`
`can_open()`

`tm_asset_browser_open_asset_api_version`

`struct tm_asset_browser_add_asset_api`
`inst`
`current_directory()`
`exists()`
`add()`
`add_directory()`

`tm_asset_browser_add_asset_api_version`

`struct tm_asset_browser_select_asset_api`
`inst`
`select_asset()`
`select_assets()`

`tm_asset_browser_select_asset_api_version`
`tm_asset_browser_o`

`struct tm_asset_browser_custom_menu_item_i`
`ud`
`menu_item()`
`menu_select()`

`tm_asset_browser_custom_menu_item_i_version`
`struct tm_asset_browser_config_t`
`struct tm_asset_browser_ui_res_t`
`enum tm_asset_browser_shortcut`

`struct tm_asset_browser_api`
`create_asset_browser()`
`destroy_asset_browser()`
`ui()`
`set_new_truth()`
`menu()`
`process_dropped_os_files()`
`focused_object()`
`selected_objects()`
`shortcuts()`
`scroll_to_item()`

1.2.0
`ui_serial()`

`tm_asset_browser_api_version`
## API
### `TM_TT_TYPE__ASSET_BROWSER`
~~~c #define TM_TT_TYPE__ASSET_BROWSER "tm_asset_browser" #define TM_TT_TYPE_HASH__ASSET_BROWSER TM_STATIC_HASH("tm_asset_browser", 0xa77c74e6207f94dbULL) ~~~ Truth type for Asset Browser settings. This type is used at runtime to hold the view settings for the asset browser. It is also serialized as part of the project settings so that the asset browser view can be restored when a project is loaded.
### `enum TM_TT_PROP__ASSET_BROWSER`
Properties of `TM_TT_TYPE__ASSET_BROWSER`. ~~~c enum { // Selected assets. TM_TT_PROP__ASSET_BROWSER__SELECTION, // reference_set [[TM_TT_TYPE__ASSET]] / [[TM_TT_TYPE__ASSET_DIRECTORY]] // Current directory. TM_TT_PROP__ASSET_BROWSER__CURRENT_DIRECTORY, // reference [[TM_TT_TYPE__ASSET_DIRECTORY]] // Focused asset (last selected). TM_TT_PROP__ASSET_BROWSER__FOCUS, // reference [[TM_TT_TYPE__ASSET]] / [[TM_TT_TYPE__ASSET_DIRECTORY]] // Sort mode: ascending (true) or descending (false). TM_TT_PROP__ASSET_BROWSER__SORT_ASCENDING, // bool // Sort by: (0) name, (1) type, (2) size. TM_TT_PROP__ASSET_BROWSER__SORT_BY, // uint32_t // View mode: (1) grid, (2) list, (3) details. TM_TT_PROP__ASSET_BROWSER__VIEW_MODE, // uint32_t // Item size. An item is composed by both Icon and Label. TM_TT_PROP__ASSET_BROWSER__ITEM_SIZE, // float // File extension filter. TM_TT_PROP__ASSET_BROWSER__FILTER_BY_FILE_EXT, // uint64_t // Label filter bitflag. (See [[tm_asset_label_bitflag_t]].) TM_TT_PROP__ASSET_BROWSER__FILTER_BY_LABEL_BITFLAG_1, // uint64_t TM_TT_PROP__ASSET_BROWSER__FILTER_BY_LABEL_BITFLAG_2, // uint64_t TM_TT_PROP__ASSET_BROWSER__FILTER_BY_LABEL_BITFLAG_3, // uint64_t TM_TT_PROP__ASSET_BROWSER__FILTER_BY_LABEL_BITFLAG_4, // uint64_t // UUID of current directory [[tm_uuid_t]]. TM_TT_PROP__ASSET_BROWSER__CURRENT_DIRECTORY_UUID_A, // uint64_t TM_TT_PROP__ASSET_BROWSER__CURRENT_DIRECTORY_UUID_B, // uint64_t }; ~~~
### `enum tm_asset_save_status`
Reports the status of an asset with respect to the last save. ~~~c enum tm_asset_save_status { // The asset has not been changed since the last save. TM_ASSET_SAVE_STATUS__SAVED, // The asset exists in the last saved data, but has been modified since the last save. TM_ASSET_SAVE_STATUS__MODIFIED, // The asset does not exist in the save data and has been created since the last save. TM_ASSET_SAVE_STATUS__CREATED, }; ~~~
### `enum tm_asset_save_file_tree_modification_type`
Used to enumerate the different possible types of file tree modification. ~~~c enum tm_asset_save_file_tree_modification_type { TM_ASSET_SAVE_FILE_TREE_MODIFICATION_TYPE__CREATED, TM_ASSET_SAVE_FILE_TREE_MODIFICATION_TYPE__DELETED, TM_ASSET_SAVE_FILE_TREE_MODIFICATION_TYPE__MOVED, TM_ASSET_SAVE_FILE_TREE_MODIFICATION_TYPE__RENAMED, }; ~~~
### `struct tm_asset_save_file_tree_modification_t`
Describes a modification made to the file tree. ~~~c typedef struct tm_asset_save_file_tree_modification_t { // The item (asset or directory) that was modified. tm_tt_id_t item; // The type of modification (CREATE, DELETE, MOVE or RENAME). enum tm_asset_save_file_tree_modification_type type; TM_PAD(4); // The original name of the item. const char *original_name; // The original directory of the item. tm_tt_id_t original_directory; } tm_asset_save_file_tree_modification_t; ~~~
### `tm_asset_save_o`
~~~c typedef struct tm_asset_save_o tm_asset_save_o; ~~~ User data object for `tm_asset_save_i`.
### `struct tm_asset_save_i`
Interface that can be used to save individual assets. !!! TODO: API-REVIEW Should we get rid of the `can_save_individual_assets()` function, since the single-file format is deprecated in favor of the asset database? #### `inst` ~~~c struct tm_asset_save_o *inst; ~~~ #### `can_save_individual_assets()` ~~~c bool (*can_save_individual_assets)(tm_asset_save_o *inst); ~~~ Returns *true* if assets can be saved individually using this interface. #### `file_tree_modifications()` ~~~c tm_asset_save_file_tree_modification_t *(*file_tree_modifications)(tm_asset_save_o *inst, struct tm_temp_allocator_i *ta, uint32_t *n); ~~~ Returns an array with the changes to the file tree since the last save. The array is allocated using the specified temp allocator `ta`. The number of items in the array is returned in `n`. #### `status()` ~~~c enum tm_asset_save_status (*status)(tm_asset_save_o *inst, tm_tt_id_t asset); ~~~ Return the saved status of the specified `asset`. #### `save_asset()` ~~~c void (*save_asset)(tm_asset_save_o *inst, tm_tt_id_t asset); ~~~ Saves the specified asset individually. Note that this can only be done for assets with status `TM_ASSET_SAVE_STATUS__MODIFIED` and only if `can_save_individual_assets()` returns *true*. #### `revert_asset()` ~~~c void (*revert_asset)(tm_asset_save_o *inst, tm_tt_id_t asset, tm_tt_undo_scope_t undo_scope); ~~~ Reverts the specified asset individually. Note that this can only be done for assets with status `TM_ASSET_SAVE_STATUS__MODIFIED` and only if `can_save_individual_assets()` returns true. #### `save_all()` ~~~c void (*save_all)(tm_asset_save_o *inst); ~~~ Saves all assets and all changes to the file tree. #### `save_all_except()` ~~~c void (*save_all_except)(tm_asset_save_o *inst, tm_tt_id_t *ignore, uint32_t num_ignore); ~~~ Saves all assets except the ones in the `ignore` list. !!! NOTE If there are changes to the file tree (renames or moves) that affect the ignored files they will NOT be saved. The ignored files always remain in their original location. #### `asset_root_path()` ~~~c const char *(*asset_root_path)(const tm_asset_save_o *inst); ~~~ Returns the OS path the asset root was last saved at. Returns `NULL` if the application does not have an asset root or has never been saved.
### `struct tm_asset_browser_create_asset_i`
Interface that can be implemented to make it possible to create assets in the Asset Browser, using the **New** context menu. #### `inst` ~~~c struct tm_asset_browser_create_asset_o *inst; ~~~ #### `menu_name` ~~~c const char *menu_name; ~~~ `TM_LOCALIZE_LATER()` name of menu option to display for creating the asset (e.g. "New Entity"). #### `asset_name` ~~~c const char *asset_name; ~~~ `TM_LOCALIZE_LATER()` name of the newly created asset (e.g. "New Entity"); #### `create()` ~~~c tm_tt_id_t (*create)(struct tm_asset_browser_create_asset_o *inst, struct tm_the_truth_o *tt, tm_tt_undo_scope_t undo_scope); ~~~ Create callback, should return The Truth ID for the newly created asset.
### `tm_asset_browser_create_asset_i_version`
~~~c #define tm_asset_browser_create_asset_i_version ~~~
### `struct tm_asset_browser_open_asset_api`
API for "opening" assets in the editor. #### `inst` ~~~c struct tm_asset_browser_open_asset_o *inst; ~~~ #### `open()` ~~~c void (*open)(struct tm_asset_browser_open_asset_o *inst, struct tm_ui_o *ui, struct tm_tab_i *from_tab, tm_tt_id_t object); ~~~ "Opens" the specified Truth object for editing in an editor view. The object can either be of type `TM_TT_TYPE__ASSET` in which case the object inside the asset (`TM_TT_PROP__ASSET__OBJECT`) is opened for editing. Or it can be any truth object that can be edited. #### `can_open()` ~~~c bool (*can_open)(struct tm_asset_browser_open_asset_o *inst, struct tm_ui_o *ui, tm_tt_id_t object); ~~~ Returns `true` if the specified object can be "opened" by the `open()` function.
### `tm_asset_browser_open_asset_api_version`
~~~c #define tm_asset_browser_open_asset_api_version ~~~
### `struct tm_asset_browser_add_asset_api`
API for adding objects to the asset root. Thread-safe. !!! TODO: API-REVIEW Rearrange arguments to put `undo_scope` last. #### `inst` ~~~c struct tm_asset_browser_add_asset_o *inst; ~~~ #### `current_directory()` ~~~c tm_tt_id_t (*current_directory)(struct tm_asset_browser_add_asset_o *inst, struct tm_ui_o *ui); ~~~ If an asset browser is found in the `ui`, returns the current open directory in that asset browser, otherwise `(tm_tt_id_t){0}`, which represents the root folder. #### `exists()` ~~~c tm_tt_id_t (*exists)(struct tm_asset_browser_add_asset_o *inst, tm_tt_id_t directory, const char *name); ~~~ If an asset with `name` already exists in `directory`, returns it's ID, otherwise 0. #### `add()` ~~~c void (*add)(struct tm_asset_browser_add_asset_o *inst, tm_tt_id_t directory, tm_tt_id_t object, const char *name, tm_tt_undo_scope_t undo_scope, bool select, struct tm_ui_o *ui, uint64_t *asset_labels, uint32_t num_asset_labels); ~~~ Wraps a `TM_TT_TYPE__ASSET` around the `object` and adds it to the `directory`. The asset will be given the specified `name` and `asset_labels`. If `select` is *true*, the asset will be selected in the *Asset Browser* tab in the specified `ui`. (If `ui` is `NULL` we look for Asset Browser tabs in all the UIs.) #### `add_directory()` ~~~c tm_tt_id_t (*add_directory)(struct tm_asset_browser_add_asset_o *inst, tm_tt_id_t parent_directory, const char *name, tm_tt_undo_scope_t undo_scope, bool select, struct tm_ui_o *ui); ~~~ Adds a new directory with `name` under the `parent_directory`. If a directory with the specified `name` already exists, it will be returned instead. If `select` is *true*, the newly created directory will be selected, using the same mechanism as `add()`.
### `tm_asset_browser_add_asset_api_version`
~~~c #define tm_asset_browser_add_asset_api_version ~~~
### `struct tm_asset_browser_select_asset_api`
API for having a system external to the Asset Browser select an asset within it. #### `inst` ~~~c struct tm_asset_browser_select_asset_o *inst; ~~~ #### `select_asset()` ~~~c void (*select_asset)(struct tm_asset_browser_select_asset_o *inst, struct tm_ui_o *ui, tm_tt_id_t asset); ~~~ Selects the `asset` in the Asset Browser tab in the `ui`. Also changes the current directory to the directory where `asset` is located. Note that the selection will send focus events to other tabs. #### `select_assets()` ~~~c void (*select_assets)(struct tm_asset_browser_select_asset_o *inst, struct tm_ui_o *ui, tm_tt_id_t *assets, uint32_t count); ~~~ As `select_asset()`, but selects more than one asset.
### `tm_asset_browser_select_asset_api_version`
~~~c #define tm_asset_browser_select_asset_api_version ~~~
### `tm_asset_browser_o`
~~~c typedef struct tm_asset_browser_o tm_asset_browser_o; ~~~ Represents an asset browser object in `tm_asset_browser_api`.
### `struct tm_asset_browser_custom_menu_item_i`
Defines a custom command that can be added to the Asset Browser context menu. #### `ud` ~~~c void *ud; ~~~ User data for callbacks. #### `menu_item()` ~~~c void (*menu_item)(struct tm_ui_menu_item_t *item, void *ud, tm_asset_browser_o *ab, struct tm_the_truth_o *tt, tm_tt_id_t asset_browser_object); ~~~ Returns the menu item to draw in `item`. An item with `item->text` set to NULL will be ignored. Note that the `item_id` field in the returned item will be ignored, instead the asset browser will assign its own id to the returned items. !!! TODO: API-REVIEW `item` should be a return value instead of a parameter. #### `menu_select()` ~~~c void (*menu_select)(void *ud, tm_asset_browser_o *ab, struct tm_ui_o *ui, struct tm_the_truth_o *tt, tm_tt_id_t asset_browser_object, struct tm_undo_stack_i *undo_stack); ~~~ Called if the menu item returned by `menu_item()` is selected.
### `tm_asset_browser_custom_menu_item_i_version`
~~~c #define tm_asset_browser_custom_menu_item_i_version ~~~
### `struct tm_asset_browser_config_t`
Configuration parameters for the Asset Browser. ~~~c typedef struct tm_asset_browser_config_t { // The Truth where the assets live. struct tm_the_truth_o *tt; // [[TM_TT_TYPE__ASSET_BROWSER]] Truth object that owns the selected items, etc. tm_tt_id_t asset_browser; // Stack for queuing undo events. struct tm_undo_stack_i *undo_stack; // Tab that the asset browser lives in. struct tm_tab_i *tab; // Callback for open events (double-click). // // This is called by [[ui_serial()]] and thus does not need to be thread-safe. void *open_ud; void (*open)(void *open_ud, struct tm_ui_o *ui, struct tm_tab_i *tab, tm_tt_id_t asset); // True to disable thumbnail generation. Existing thumbnails will be shown but no attemps will be made // to refresh them. Useful when asset browser is used for importing the contents from another project. bool disable_thumbnail_generation; TM_PAD(3); // Custom menu items for the asset browser. The menu items specified here will be copied to // local memory. uint32_t num_custom_menu_items; const tm_asset_browser_custom_menu_item_i *custom_menu_items; // Interface for saving and/or reverting assets. tm_asset_save_i *save_interface; struct tm_ui_renderer_o *ui_renderer; } tm_asset_browser_config_t; ~~~
### `struct tm_asset_browser_ui_res_t`
Result of `tm_asset_browser_api->ui()`. ~~~c typedef struct tm_asset_browser_ui_res_t { // Returns *true* if the focus or the selection changed in the asset browser. bool focus_changed; } tm_asset_browser_ui_res_t; ~~~
### `enum tm_asset_browser_shortcut`
Identifiers for shortcuts exposed by the Asset Browser. ~~~c enum tm_asset_browser_shortcut { // Shortcut to open an asset in a new workspace. TM_ASSET_BROWSER_SHORTCUT__OPEN_ASSET_IN_NEW_WORKSPACE, // Shortcut to open an asset in a new tab. TM_ASSET_BROWSER_SHORTCUT__OPEN_ASSET_IN_NEW_TAB, // Shortcut to open an asset in a new tab and pin it. TM_ASSET_BROWSER_SHORTCUT__OPEN_ASSET_IN_NEW_TAB_AND_PIN, }; ~~~
### `struct tm_asset_browser_api`
Represents an Asset Browser. The asset browser is a UI for browsing and selecting "assets" (Truth objects of type `TM_TT_TYPE__ASSET`). An "asset" is an independent, persistent object that can be referenced by other objects. It is typically what we would think of as a "file" in a file-based system. #### `create_asset_browser()` ~~~c tm_asset_browser_o *(*create_asset_browser)(struct tm_allocator_i *allocator, const tm_asset_browser_config_t *config); ~~~ Creates a new asset browser based on the config settings. #### `destroy_asset_browser()` ~~~c void (*destroy_asset_browser)(tm_asset_browser_o *asset_browser); ~~~ Destroys an asset browser created with `create_asset_browser()`. #### `ui()` ~~~c tm_asset_browser_ui_res_t (*ui)(tm_asset_browser_o *inst, tm_tt_id_t asset_root, struct tm_ui_o *ui, const struct tm_ui_style_t *style, tm_rect_t rect, uint64_t tab_id); ~~~ Draws the UI of the asset browser. #### `set_new_truth()` ~~~c void (*set_new_truth)(tm_asset_browser_o *inst, struct tm_the_truth_o *tt, tm_tt_id_t asset_browser); ~~~ Associates the asset browser with a new truth and asset browser settings object. #### `menu()` ~~~c void (*menu)(tm_asset_browser_o *inst, tm_tt_id_t asset_root, struct tm_ui_o *ui, const struct tm_ui_style_t *style, tm_vec2_t pos); ~~~ Draws the asset browser menu. #### `process_dropped_os_files()` ~~~c void (*process_dropped_os_files)(tm_asset_browser_o *inst, struct tm_ui_o *ui, tm_tt_id_t asset_root, char **files, uint32_t num_files); ~~~ Imports all the files that can be imported from the list of `files`. #### `focused_object()` ~~~c tm_tt_id_t (*focused_object)(tm_asset_browser_o *inst); ~~~ Returns the focused object in the asset browser. #### `selected_objects()` ~~~c const tm_tt_id_t *(*selected_objects)(tm_asset_browser_o *inst, struct tm_temp_allocator_i *ta); ~~~ Gets the list of selected objects in the asset browser. #### `shortcuts()` ~~~c struct tm_shortcut_i **(*shortcuts)(void); ~~~ Returns the list of common shortcuts used by the asset browser. The size of the array is `TM_ASSET_BROWSER_SHORTCUT__COUNT`. #### `scroll_to_item()` ~~~c void (*scroll_to_item)(tm_asset_browser_o *inst, tm_tt_id_t item); ~~~ The asset browser will scroll to this item the next time the asset browser is drawn.

1.2.0

#### `ui_serial()` ~~~c void (*ui_serial)(tm_asset_browser_o *inst, tm_tt_id_t asset_root, struct tm_ui_o *ui, const struct tm_ui_style_t *style, tm_rect_t rect, uint64_t tab_id); ~~~ Performs any serial actions initiated by the UI. This involves opening assets.
### `tm_asset_browser_api_version`
~~~c #define tm_asset_browser_api_version ~~~