diff options
| author | aura <nw@moneybot.cc> | 2026-03-16 12:51:06 +0100 |
|---|---|---|
| committer | aura <nw@moneybot.cc> | 2026-03-16 12:51:06 +0100 |
| commit | f1882249843caa8bd931ecb76bb489615e079b10 (patch) | |
| tree | 15d0e3f7d775684ff91d85cc37843138e72b1735 /src/editor/editor_contextmenu.cpp | |
| parent | b71bb14c7dec546304e3396d7040d88c6c86a3a7 (diff) | |
editor work
Diffstat (limited to 'src/editor/editor_contextmenu.cpp')
| -rw-r--r-- | src/editor/editor_contextmenu.cpp | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/editor/editor_contextmenu.cpp b/src/editor/editor_contextmenu.cpp index 2b0bb1f..4f9dbe6 100644 --- a/src/editor/editor_contextmenu.cpp +++ b/src/editor/editor_contextmenu.cpp @@ -1,6 +1,6 @@ #include "editor_gui_internal.h" -static U8 editor_contextmenu_item_enabled( const EDITOR_CONTEXTMENU_ITEM* item ) { +U8 editor_contextmenu_item_enabled( EDITOR_CONTEXTMENU_ITEM* item ) { if( !item ) return 0; @@ -10,15 +10,15 @@ static U8 editor_contextmenu_item_enabled( const EDITOR_CONTEXTMENU_ITEM* item ) return item->enabled; } -static I32 editor_contextmenu_title_h( const GUI_EDITOR_CONTEXTMENU* menu ) { +I32 editor_contextmenu_title_h( GUI_EDITOR_CONTEXTMENU* menu ) { return ( menu && menu->title[0] ) ? 18 : 0; } -static I32 editor_contextmenu_row_h() { +I32 editor_contextmenu_row_h() { return 20; } -static I32 editor_contextmenu_width( LIST<EDITOR_CONTEXTMENU_ITEM>* items, const char* title ) { +I32 editor_contextmenu_width( LIST<EDITOR_CONTEXTMENU_ITEM>* items, const char* title ) { I32 width = EDITOR_TOOLBAR_DROPDOWN_W; if( title && title[0] ) { I32 text_w = 0; @@ -38,7 +38,7 @@ static I32 editor_contextmenu_width( LIST<EDITOR_CONTEXTMENU_ITEM>* items, const return width; } -static I32 editor_contextmenu_height( LIST<EDITOR_CONTEXTMENU_ITEM>* items, const char* title ) { +I32 editor_contextmenu_height( LIST<EDITOR_CONTEXTMENU_ITEM>* items, const char* title ) { I32 height = 4 + editor_contextmenu_row_h() * ( items ? (I32)items->size : 0 ); if( title && title[0] ) height += 18 + 1; @@ -52,7 +52,7 @@ static I32 editor_contextmenu_items_y( GUI_EDITOR_CONTEXTMENU* menu ) { return y; } -static I32 editor_contextmenu_hit_test( GUI_EDITOR_CONTEXTMENU* menu, I32 mx, I32 my ) { +I32 editor_contextmenu_hit_test( GUI_EDITOR_CONTEXTMENU* menu, I32 mx, I32 my ) { if( !menu || !menu->items ) return -1; @@ -72,7 +72,7 @@ static I32 editor_contextmenu_hit_test( GUI_EDITOR_CONTEXTMENU* menu, I32 mx, I3 return idx; } -static void gui_editor_contextmenu_draw_fn( void* ptr ) { +void gui_editor_contextmenu_draw_fn( void* ptr ) { GUI_EDITOR_CONTEXTMENU* menu = (GUI_EDITOR_CONTEXTMENU*)ptr; if( !menu || !menu->items || !menu->items->size ) return; @@ -128,7 +128,7 @@ static void gui_editor_contextmenu_draw_fn( void* ptr ) { } } -static void gui_editor_contextmenu_input_fn( void* ptr ) { +void gui_editor_contextmenu_input_fn( void* ptr ) { GUI_EDITOR_CONTEXTMENU* menu = (GUI_EDITOR_CONTEXTMENU*)ptr; if( !menu || !menu->items || !menu->items->size ) return; @@ -199,6 +199,25 @@ U8 editor_contextmenu_open() { return editor && editor->gui.contextmenu && editor->gui.contextmenu->enabled; } + +void editor_contextmenu_set_item( + EDITOR_CONTEXTMENU_ITEM* item, + const char* text, + EDITOR_CONTEXTMENU_CALLBACK cb, + void* data, + EDITOR_CONTEXTMENU_ENABLED_CALLBACK enabled_cb +) { + if( !item ) + return; + + item->items.clear(); + snprintf( item->text, sizeof( item->text ), "%s", text ? text : "" ); + item->cb = cb; + item->data = data; + item->enabled = 1; + item->enabled_cb = enabled_cb; +} + void editor_show_contextmenu( I32 x, I32 y, LIST<EDITOR_CONTEXTMENU_ITEM>* items, const char* title ) { editor_hide_contextmenu(); if( !editor || !editor->wnd || !items || !items->size ) |
