repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
effects-runtime
github_2023
galacean
typescript
ExampleAppConsole.TextEditCallbackStub
static TextEditCallbackStub (data: ImGui.InputTextCallbackData<ExampleAppConsole>): int { const console: ExampleAppConsole | null = data.UserData; ImGui.ASSERT(console); return console.TextEditCallback(data); }
// In C++11 you'd be better off using lambdas for this sort of forwarding callbacks
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6123-L6129
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ExampleAppLog.constructor
constructor () { this.AutoScroll = true; this.Clear(); }
// Keep scrolling if already at the bottom.
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6249-L6252
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ShowExampleAppLog
function ShowExampleAppLog (p_open: ImGui.Access<boolean>): void { const log = STATIC<ExampleAppLog>(UNIQUE('log#64c1f1c1'), new ExampleAppLog()); // For the demo: add a debug button _BEFORE_ the normal log window contents // We take advantage of a rarely used feature: multiple calls to Begin()/End() are appending to the _same_ window. // Most of the contents of the window will be added by the log.Draw() call. ImGui.SetNextWindowSize(new ImGui.Vec2(500, 400), ImGui.Cond.FirstUseEver); ImGui.Begin('Example: Log', p_open); if (ImGui.SmallButton('[Debug] Add 5 entries')) { const counter = STATIC<int>(UNIQUE('counter#b459af44'), 0); const categories: string[] = ['info', 'warn', 'error']; const words: string[] = ['Bumfuzzled', 'Cattywampus', 'Snickersnee', 'Abibliophobia', 'Absquatulate', 'Nincompoop', 'Pauciloquent']; for (let n = 0; n < 5; n++) { const category: string = categories[counter.value % ImGui.ARRAYSIZE(categories)]; const word: string = words[counter.value % ImGui.ARRAYSIZE(words)]; log.value.AddLog(`[${ImGui.GetFrameCount().toString().padStart(5, '0')}] [${category}] Hello, current time is ${ImGui.GetTime().toFixed(1)}, here's a word: '${word}'\n`); counter.value++; } } ImGui.End(); // Actually call in the regular Log helper (which will Begin() into the same window as we just did) log.value.Draw('Example: Log', p_open); }
// Demonstrate creating a simple log window with basic filtering.
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6360-L6385
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ShowExampleAppLayout
function ShowExampleAppLayout (p_open: ImGui.Access<boolean>): void { ImGui.SetNextWindowSize(new ImGui.Vec2(500, 440), ImGui.Cond.FirstUseEver); if (ImGui.Begin('Example: Simple layout', p_open, ImGui.WindowFlags.MenuBar)) { if (ImGui.BeginMenuBar()) { if (ImGui.BeginMenu('File')) { if (ImGui.MenuItem('Close')) {p_open(false);} ImGui.EndMenu(); } ImGui.EndMenuBar(); } // Left const selected = STATIC<int>(UNIQUE('selected#079abfa7'), 0); { ImGui.BeginChild('left pane', new ImGui.Vec2(150, 0), true); for (let i = 0; i < 100; i++) { const label: string = `MyObject ${i}`; if (ImGui.Selectable(label, selected.value === i)) {selected.value = i;} } ImGui.EndChild(); } ImGui.SameLine(); // Right { ImGui.BeginGroup(); ImGui.BeginChild('item view', new ImGui.Vec2(0, -ImGui.GetFrameHeightWithSpacing())); // Leave room for 1 line below us ImGui.Text(`MyObject: ${selected.value}`); ImGui.Separator(); if (ImGui.BeginTabBar('##Tabs', ImGui.TabBarFlags.None)) { if (ImGui.BeginTabItem('Description')) { ImGui.TextWrapped('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '); ImGui.EndTabItem(); } if (ImGui.BeginTabItem('Details')) { ImGui.Text('ID: 0123456789'); ImGui.EndTabItem(); } ImGui.EndTabBar(); } ImGui.EndChild(); if (ImGui.Button('Revert')) {} ImGui.SameLine(); if (ImGui.Button('Save')) {} ImGui.EndGroup(); } } ImGui.End(); }
//-----------------------------------------------------------------------------
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6392-L6442
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ShowPlaceholderObject
function ShowPlaceholderObject (prefix: string, uid: int): void { // Use object uid as identifier. Most commonly you could also use the object pointer as a base ID. ImGui.PushID(uid); // Text and Tree nodes are less high than framed widgets, using AlignTextToFramePadding() we add vertical spacing to make the tree lines equal high. ImGui.TableNextRow(); ImGui.TableSetColumnIndex(0); ImGui.AlignTextToFramePadding(); const node_open: boolean = ImGui.TreeNode('Object', `${prefix}_${uid}`); ImGui.TableSetColumnIndex(1); ImGui.Text('my sailor is rich'); if (node_open) { const placeholder_members = STATIC_ARRAY<float>(8, UNIQUE('placeholder_members#9a0bf6da'), [0.0, 0.0, 1.0, 3.1416, 100.0, 999.0]); for (let i = 0; i < 8; i++) { ImGui.PushID(i); // Use field index as identifier. if (i < 2) { ShowPlaceholderObject('Child', 424242); } else { // Here we use a TreeNode to highlight on hover (we could use e.g. Selectable as well) ImGui.TableNextRow(); ImGui.TableSetColumnIndex(0); ImGui.AlignTextToFramePadding(); const flags: ImGui.TreeNodeFlags = ImGui.TreeNodeFlags.Leaf | ImGui.TreeNodeFlags.NoTreePushOnOpen | ImGui.TreeNodeFlags.Bullet; ImGui.TreeNodeEx('Field', flags, `Field_${i}`); ImGui.TableSetColumnIndex(1); ImGui.SetNextItemWidth(-FLT_MIN); if (i >= 5) {ImGui.InputFloat('##value', placeholder_members.access(i), 1.0);} else {ImGui.DragFloat('##value', placeholder_members.access(i), 0.01);} ImGui.NextColumn(); } ImGui.PopID(); } ImGui.TreePop(); } ImGui.PopID(); }
//-----------------------------------------------------------------------------
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6448-L6487
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ShowExampleAppPropertyEditor
function ShowExampleAppPropertyEditor (p_open: ImGui.Access<boolean>): void { ImGui.SetNextWindowSize(new ImGui.Vec2(430, 450), ImGui.Cond.FirstUseEver); if (!ImGui.Begin('Example: Property editor', p_open)) { ImGui.End(); return; } HelpMarker( 'This example shows how you may implement a property editor using two columns.\n' + 'All objects/fields data are dummies here.\n' + 'Remember that in many simple cases, you can use ImGui.SameLine(xxx) to position\n' + 'your cursor horizontally instead of using the Columns() API.'); ImGui.PushStyleVar(ImGui.StyleVar.FramePadding, new ImGui.Vec2(2, 2)); if (ImGui.BeginTable('split', 2, ImGui.TableFlags.BordersOuter | ImGui.TableFlags.Resizable)) { // Iterate placeholder objects (all the same data) for (let obj_i = 0; obj_i < 4; obj_i++) { ShowPlaceholderObject('Object', obj_i); //ImGui.Separator(); } ImGui.EndTable(); } ImGui.PopStyleVar(); ImGui.End(); }
// Demonstrate create a simple property editor.
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6490-L6515
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ShowExampleAppLongText
function ShowExampleAppLongText (p_open: ImGui.Access<boolean>): void { ImGui.SetNextWindowSize(new ImGui.Vec2(520, 600), ImGui.Cond.FirstUseEver); if (!ImGui.Begin('Example: Long text display', p_open)) { ImGui.End(); return; } const test_type = STATIC<int>(UNIQUE('test_type#744ee350'), 0); const log = STATIC<ImGui.TextBuffer>(UNIQUE('log#1c9419eb'), new ImGui.TextBuffer()); const lines = STATIC<int>(UNIQUE('lines#a26d2454'), 0); ImGui.Text('Printing unusually long amount of text.'); ImGui.Combo('Test type', test_type.access, 'Single call to TextUnformatted()\0' + 'Multiple calls to Text(), clipped\0' + 'Multiple calls to Text(), not clipped (slow)\0'); ImGui.Text(`Buffer contents: ${lines.value} lines, ${log.value.size()} bytes`); if (ImGui.Button('Clear')) { log.value.clear(); lines.value = 0; } ImGui.SameLine(); if (ImGui.Button('Add 1000 lines')) { for (let i = 0; i < 1000; i++) {log.value.append(`${lines.value + i} The quick brown fox jumps over the lazy dog\n`);} lines.value += 1000; } ImGui.BeginChild('Log'); switch (test_type.value) { case 0: // Single call to TextUnformatted() with a big buffer // ImGui.TextUnformatted(log.begin(), log.end()); ImGui.TextUnformatted(log.value.Buf); break; case 1: { // Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the ImGui.ListClipper helper. ImGui.PushStyleVar(ImGui.StyleVar.ItemSpacing, new ImGui.Vec2(0, 0)); const clipper = new ImGui.ListClipper(); clipper.Begin(lines.value); while (clipper.Step()) { for (let i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {ImGui.Text(`${i} The quick brown fox jumps over the lazy dog`);} } ImGui.PopStyleVar(); break; } case 2: // Multiple calls to Text(), not clipped (slow) ImGui.PushStyleVar(ImGui.StyleVar.ItemSpacing, new ImGui.Vec2(0, 0)); for (let i = 0; i < lines.value; i++) {ImGui.Text(`${i} The quick brown fox jumps over the lazy dog`);} ImGui.PopStyleVar(); break; } ImGui.EndChild(); ImGui.End(); }
//-----------------------------------------------------------------------------
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6522-L6578
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ShowExampleAppAutoResize
function ShowExampleAppAutoResize (p_open: ImGui.Access<boolean>): void { if (!ImGui.Begin('Example: Auto-resizing window', p_open, ImGui.WindowFlags.AlwaysAutoResize)) { ImGui.End(); return; } const lines = STATIC<int>(UNIQUE('lines#5ebf3fd4'), 10); ImGui.TextUnformatted( 'Window will resize every-frame to the size of its content.\n' + 'Note that you probably don\'t want to query the window size to\n' + 'output your content because that would create a feedback loop.'); ImGui.SliderInt('Number of lines', lines.access, 1, 20); for (let i = 0; i < lines.value; i++) {ImGui.Text(`${''.padStart(i * 4)}This is line ${i}`);} // Pad with space to extend size horizontally ImGui.End(); }
//-----------------------------------------------------------------------------
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6585-L6601
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ShowExampleAppConstrainedResize
function ShowExampleAppConstrainedResize (p_open: ImGui.Access<boolean>): void { class CustomConstraints { // Helper functions to demonstrate programmatic constraints static Square<T>(data: ImGui.SizeCallbackData<T>): void { data.DesiredSize.x = data.DesiredSize.y = IM_MAX(data.DesiredSize.x, data.DesiredSize.y); } static Step (data: ImGui.SizeCallbackData<float>): void { const step = data.UserData; data.DesiredSize.Set(Math.floor/*(int)*/(data.DesiredSize.x / step + 0.5) * step, Math.floor/*(int)*/(data.DesiredSize.y / step + 0.5) * step); } } const test_desc: string[] = [ 'Resize vertical only', 'Resize horizontal only', 'Width > 100, Height > 100', 'Width 400-500', 'Height 400-500', 'Custom: Always Square', 'Custom: Fixed Steps (100)', ]; const auto_resize = STATIC<boolean>(UNIQUE('auto_resize#3fd1e552'), false); const type = STATIC<int>(UNIQUE('type#2ea441c9'), 0); const display_lines = STATIC<int>(UNIQUE('display_lines#154bc4b5'), 10); if (type.value === 0) {ImGui.SetNextWindowSizeConstraints(new ImGui.Vec2(-1, 0), new ImGui.Vec2(-1, FLT_MAX));} // Vertical only if (type.value === 1) {ImGui.SetNextWindowSizeConstraints(new ImGui.Vec2(0, -1), new ImGui.Vec2(FLT_MAX, -1));} // Horizontal only if (type.value === 2) {ImGui.SetNextWindowSizeConstraints(new ImGui.Vec2(100, 100), new ImGui.Vec2(FLT_MAX, FLT_MAX));} // Width > 100, Height > 100 if (type.value === 3) {ImGui.SetNextWindowSizeConstraints(new ImGui.Vec2(400, -1), new ImGui.Vec2(500, -1));} // Width 400-500 if (type.value === 4) {ImGui.SetNextWindowSizeConstraints(new ImGui.Vec2(-1, 400), new ImGui.Vec2(-1, 500));} // Height 400-500 if (type.value === 5) {ImGui.SetNextWindowSizeConstraints(new ImGui.Vec2(0, 0), new ImGui.Vec2(FLT_MAX, FLT_MAX), CustomConstraints.Square);} // Always Square if (type.value === 6) {ImGui.SetNextWindowSizeConstraints(new ImGui.Vec2(0, 0), new ImGui.Vec2(FLT_MAX, FLT_MAX), CustomConstraints.Step, /*(void*)(intptr_t)*/100);} // Fixed Step const flags: ImGui.WindowFlags = auto_resize ? ImGui.WindowFlags.AlwaysAutoResize : 0; if (ImGui.Begin('Example: Constrained Resize', p_open, flags)) { if (ImGui.Button('200x200')) { ImGui.SetWindowSize(new ImGui.Vec2(200, 200)); } ImGui.SameLine(); if (ImGui.Button('500x500')) { ImGui.SetWindowSize(new ImGui.Vec2(500, 500)); } ImGui.SameLine(); if (ImGui.Button('800x200')) { ImGui.SetWindowSize(new ImGui.Vec2(800, 200)); } ImGui.SetNextItemWidth(200); ImGui.Combo('Constraint', type.access, test_desc, ImGui.ARRAYSIZE(test_desc)); ImGui.SetNextItemWidth(200); ImGui.DragInt('Lines', display_lines.access, 0.2, 1, 100); ImGui.Checkbox('Auto-resize', auto_resize.access); for (let i = 0; i < display_lines.value; i++) {ImGui.Text(`${''.padStart(i * 4)}Hello, sailor! Making this line long enough for the example.`);} } ImGui.End(); }
//-----------------------------------------------------------------------------
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6608-L6656
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
CustomConstraints.Square
static Square<T>(data: ImGui.SizeCallbackData<T>): void { data.DesiredSize.x = data.DesiredSize.y = IM_MAX(data.DesiredSize.x, data.DesiredSize.y); }
// Helper functions to demonstrate programmatic constraints
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6611-L6611
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ShowExampleAppSimpleOverlay
function ShowExampleAppSimpleOverlay (p_open: ImGui.Access<boolean>): void { const DISTANCE: float = 10.0; const corner = STATIC<int>(UNIQUE('corner#63044b6f'), 0); const io: ImGui.IO = ImGui.GetIO(); let window_flags: ImGui.WindowFlags = ImGui.WindowFlags.NoDecoration | ImGui.WindowFlags.AlwaysAutoResize | ImGui.WindowFlags.NoSavedSettings | ImGui.WindowFlags.NoFocusOnAppearing | ImGui.WindowFlags.NoNav; if (corner.value !== -1) { window_flags |= ImGui.WindowFlags.NoMove; const window_pos: ImGui.Vec2 = new ImGui.Vec2((corner.value & 1) ? io.DisplaySize.x - DISTANCE : DISTANCE, (corner.value & 2) ? io.DisplaySize.y - DISTANCE : DISTANCE); const window_pos_pivot: ImGui.Vec2 = new ImGui.Vec2((corner.value & 1) ? 1.0 : 0.0, (corner.value & 2) ? 1.0 : 0.0); ImGui.SetNextWindowPos(window_pos, ImGui.Cond.Always, window_pos_pivot); } ImGui.SetNextWindowBgAlpha(0.35); // Transparent background if (ImGui.Begin('Example: Simple overlay', p_open, window_flags)) { ImGui.Text('Simple overlay\nin the corner of the screen.\n(right-click to change position)'); ImGui.Separator(); if (ImGui.IsMousePosValid()) {ImGui.Text(`Mouse Position: (${io.MousePos.x.toFixed(1)},${io.MousePos.y.toFixed(1)})`);} else {ImGui.Text('Mouse Position: <invalid>');} if (ImGui.BeginPopupContextWindow()) { if (ImGui.MenuItem('Custom', null, corner.value === -1)) {corner.value = -1;} if (ImGui.MenuItem('Top-left', null, corner.value === 0)) {corner.value = 0;} if (ImGui.MenuItem('Top-right', null, corner.value === 1)) {corner.value = 1;} if (ImGui.MenuItem('Bottom-left', null, corner.value === 2)) {corner.value = 2;} if (ImGui.MenuItem('Bottom-right', null, corner.value === 3)) {corner.value = 3;} if (p_open && ImGui.MenuItem('Close')) {p_open(false);} ImGui.EndPopup(); } } ImGui.End(); }
//-----------------------------------------------------------------------------
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6664-L6693
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ShowExampleAppWindowTitles
function ShowExampleAppWindowTitles (p_open: ImGui.Access<boolean>): void { // By default, Windows are uniquely identified by their title. // You can use the "##" and "###" markers to manipulate the display/ID. // Using "##" to display same title but have unique identifier. ImGui.SetNextWindowPos(new ImGui.Vec2(100, 100), ImGui.Cond.FirstUseEver); ImGui.Begin('Same title as another window##1'); ImGui.Text('This is window 1.\nMy title is the same as window 2, but my identifier is unique.'); ImGui.End(); ImGui.SetNextWindowPos(new ImGui.Vec2(100, 200), ImGui.Cond.FirstUseEver); ImGui.Begin('Same title as another window##2'); ImGui.Text('This is window 2.\nMy title is the same as window 1, but my identifier is unique.'); ImGui.End(); // Using "###" to display a changing title but keep a static identifier "AnimatedTitle" const buf: string = `Animated title ${'|/-\\'[Math.floor/*(int)*/(ImGui.GetTime() / 0.25) & 3]} ${ImGui.GetFrameCount()}###AnimatedTitle`; ImGui.SetNextWindowPos(new ImGui.Vec2(100, 300), ImGui.Cond.FirstUseEver); ImGui.Begin(buf); ImGui.Text('This window has a changing title.'); ImGui.End(); }
//-----------------------------------------------------------------------------
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6702-L6724
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ShowExampleAppCustomRendering
function ShowExampleAppCustomRendering (p_open: ImGui.Access<boolean>): void { if (!ImGui.Begin('Example: Custom rendering', p_open)) { ImGui.End(); return; } // Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of // overloaded operators, etc. Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your // types and ImGui.Vec2/ImGui.Vec4. Dear ImGui defines overloaded operators but they are internal to imgui.cpp and not // exposed outside (to avoid messing with your types) In this example we are not using the maths operators! if (ImGui.BeginTabBar('##TabBar')) { if (ImGui.BeginTabItem('Primitives')) { ImGui.PushItemWidth(-ImGui.GetFontSize() * 15); const draw_list: ImGui.DrawList = ImGui.GetWindowDrawList(); // Draw gradients // (note that those are currently exacerbating our sRGB/Linear issues) // Calling ImGui.GetColorU32() multiplies the given colors by the current Style Alpha, but you may pass the ImGui.COL32() directly as well.. ImGui.Text('Gradients'); const gradient_size: ImGui.Vec2 = new ImGui.Vec2(ImGui.CalcItemWidth(), ImGui.GetFrameHeight()); { const p0: ImGui.Vec2 = ImGui.GetCursorScreenPos(); const p1: ImGui.Vec2 = new ImGui.Vec2(p0.x + gradient_size.x, p0.y + gradient_size.y); const col_a: ImGui.U32 = ImGui.GetColorU32(ImGui.COL32(0, 0, 0, 255)); const col_b: ImGui.U32 = ImGui.GetColorU32(ImGui.COL32(255, 255, 255, 255)); draw_list.AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a); ImGui.InvisibleButton('##gradient1', gradient_size); } { const p0: ImGui.Vec2 = ImGui.GetCursorScreenPos(); const p1: ImGui.Vec2 = new ImGui.Vec2(p0.x + gradient_size.x, p0.y + gradient_size.y); const col_a: ImGui.U32 = ImGui.GetColorU32(ImGui.COL32(0, 255, 0, 255)); const col_b: ImGui.U32 = ImGui.GetColorU32(ImGui.COL32(255, 0, 0, 255)); draw_list.AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a); ImGui.InvisibleButton('##gradient2', gradient_size); } // Draw a bunch of primitives ImGui.Text('All primitives'); const sz = STATIC<float>(UNIQUE('sz#83665c0c'), 36.0); const thickness = STATIC<float>(UNIQUE('thickness#1b3baad0'), 3.0); const ngon_sides = STATIC<int>(UNIQUE('ngon_sides#a184dd3b'), 6); const circle_segments_override = STATIC<boolean>(UNIQUE('circle_segments_override#f5946c4d'), false); const circle_segments_override_v = STATIC<int>(UNIQUE('circle_segments_override_v#8ae75d44'), 12); const curve_segments_override = STATIC<boolean>(UNIQUE('curve_segments_override#4bc9456e'), false); const curve_segments_override_v = STATIC<int>(UNIQUE('curve_segments_override_v#c0102a7a'), 8); const colf = STATIC<ImGui.Vec4>(UNIQUE('colf#379f26e6'), new ImGui.Vec4(1.0, 1.0, 0.4, 1.0)); ImGui.DragFloat('Size', sz.access, 0.2, 2.0, 72.0, '%.0f'); ImGui.DragFloat('Thickness', thickness.access, 0.05, 1.0, 8.0, '%.02f'); ImGui.SliderInt('N-gon sides', ngon_sides.access, 3, 12); ImGui.Checkbox('##circlesegmentoverride', circle_segments_override.access); ImGui.SameLine(0.0, ImGui.GetStyle().ItemInnerSpacing.x); if (ImGui.SliderInt('Circle segments override', circle_segments_override_v.access, 3, 40)) { circle_segments_override.value = true; } ImGui.Checkbox('##curvessegmentoverride', curve_segments_override.access); ImGui.SameLine(0.0, ImGui.GetStyle().ItemInnerSpacing.x); if (ImGui.SliderInt('Curves segments override', curve_segments_override_v.access, 3, 40)) { curve_segments_override.value = true; } ImGui.ColorEdit4('Color', colf.value); const p: ImGui.Vec2 = ImGui.GetCursorScreenPos(); const col: ImGui.U32 = new ImGui.Color(colf.value).toImU32(); const spacing: float = 10.0; const corners_none: ImGui.DrawCornerFlags = 0; const corners_all: ImGui.DrawCornerFlags = ImGui.DrawCornerFlags.All; const corners_tl_br: ImGui.DrawCornerFlags = ImGui.DrawCornerFlags.TopLeft | ImGui.DrawCornerFlags.BotRight; const circle_segments: int = circle_segments_override.value ? circle_segments_override_v.value : 0; const curve_segments: int = curve_segments_override.value ? curve_segments_override_v.value : 0; let x: float = p.x + 4.0; let y: float = p.y + 4.0; for (let n = 0; n < 2; n++) { // First line uses a thickness of 1.0, second line uses the configurable thickness const th: float = (n === 0) ? 1.0 : thickness.value; draw_list.AddNgon(new ImGui.Vec2(x + sz.value * 0.5, y + sz.value * 0.5), sz.value * 0.5, col, ngon_sides.value, th); x += sz.value + spacing; // N-gon draw_list.AddCircle(new ImGui.Vec2(x + sz.value * 0.5, y + sz.value * 0.5), sz.value * 0.5, col, circle_segments, th); x += sz.value + spacing; // Circle draw_list.AddRect(new ImGui.Vec2(x, y), new ImGui.Vec2(x + sz.value, y + sz.value), col, 0.0, corners_none, th); x += sz.value + spacing; // Square draw_list.AddRect(new ImGui.Vec2(x, y), new ImGui.Vec2(x + sz.value, y + sz.value), col, 10.0, corners_all, th); x += sz.value + spacing; // Square with all rounded corners draw_list.AddRect(new ImGui.Vec2(x, y), new ImGui.Vec2(x + sz.value, y + sz.value), col, 10.0, corners_tl_br, th); x += sz.value + spacing; // Square with two rounded corners draw_list.AddTriangle(new ImGui.Vec2(x + sz.value * 0.5, y), new ImGui.Vec2(x + sz.value, y + sz.value - 0.5), new ImGui.Vec2(x, y + sz.value - 0.5), col, th);x += sz.value + spacing; // Triangle //draw_list.AddTriangle(new ImGui.Vec2(x+sz.value*0.2,y), new ImGui.Vec2(x, y+sz.value-0.5), new ImGui.Vec2(x+sz.value*0.4, y+sz.value-0.5), col, th);x+= sz.value*0.4 + spacing; // Thin triangle draw_list.AddLine(new ImGui.Vec2(x, y), new ImGui.Vec2(x + sz.value, y), col, th); x += sz.value + spacing; // Horizontal line (note: drawing a filled rectangle will be faster!) draw_list.AddLine(new ImGui.Vec2(x, y), new ImGui.Vec2(x, y + sz.value), col, th); x += spacing; // Vertical line (note: drawing a filled rectangle will be faster!) draw_list.AddLine(new ImGui.Vec2(x, y), new ImGui.Vec2(x + sz.value, y + sz.value), col, th); x += sz.value + spacing; // Diagonal line // Quadratic Bezier Curve (3 control points) const cp3: ImGui.Vec2[/*3*/] = [new ImGui.Vec2(x, y + sz.value * 0.6), new ImGui.Vec2(x + sz.value * 0.5, y - sz.value * 0.4), new ImGui.Vec2(x + sz.value, y + sz.value)]; draw_list.AddBezierQuadratic(cp3[0], cp3[1], cp3[2], col, th, curve_segments); x += sz.value + spacing; // Cubic Bezier Curve (4 control points) const cp4: ImGui.Vec2[/*4*/] = [new ImGui.Vec2(x, y), new ImGui.Vec2(x + sz.value * 1.3, y + sz.value * 0.3), new ImGui.Vec2(x + sz.value - sz.value * 1.3, y + sz.value - sz.value * 0.3), new ImGui.Vec2(x + sz.value, y + sz.value)]; draw_list.AddBezierCubic(cp4[0], cp4[1], cp4[2], cp4[3], col, th, curve_segments); x = p.x + 4; y += sz.value + spacing; } draw_list.AddNgonFilled(new ImGui.Vec2(x + sz.value * 0.5, y + sz.value * 0.5), sz.value * 0.5, col, ngon_sides.value); x += sz.value + spacing; // N-gon draw_list.AddCircleFilled(new ImGui.Vec2(x + sz.value * 0.5, y + sz.value * 0.5), sz.value * 0.5, col, circle_segments); x += sz.value + spacing; // Circle draw_list.AddRectFilled(new ImGui.Vec2(x, y), new ImGui.Vec2(x + sz.value, y + sz.value), col); x += sz.value + spacing; // Square draw_list.AddRectFilled(new ImGui.Vec2(x, y), new ImGui.Vec2(x + sz.value, y + sz.value), col, 10.0); x += sz.value + spacing; // Square with all rounded corners draw_list.AddRectFilled(new ImGui.Vec2(x, y), new ImGui.Vec2(x + sz.value, y + sz.value), col, 10.0, corners_tl_br); x += sz.value + spacing; // Square with two rounded corners draw_list.AddTriangleFilled(new ImGui.Vec2(x + sz.value * 0.5, y), new ImGui.Vec2(x + sz.value, y + sz.value - 0.5), new ImGui.Vec2(x, y + sz.value - 0.5), col); x += sz.value + spacing; // Triangle //draw_list.AddTriangleFilled(new ImGui.Vec2(x+sz.value*0.2,y), new ImGui.Vec2(x, y+sz.value-0.5), new ImGui.Vec2(x+sz.value*0.4, y+sz.value-0.5), col); x += sz.value*0.4 + spacing; // Thin triangle draw_list.AddRectFilled(new ImGui.Vec2(x, y), new ImGui.Vec2(x + sz.value, y + thickness.value), col); x += sz.value + spacing; // Horizontal line (faster than AddLine, but only handle integer thickness) draw_list.AddRectFilled(new ImGui.Vec2(x, y), new ImGui.Vec2(x + thickness.value, y + sz.value), col); x += spacing * 2.0;// Vertical line (faster than AddLine, but only handle integer thickness) draw_list.AddRectFilled(new ImGui.Vec2(x, y), new ImGui.Vec2(x + 1, y + 1), col); x += sz.value; // Pixel (faster than AddLine) draw_list.AddRectFilledMultiColor(new ImGui.Vec2(x, y), new ImGui.Vec2(x + sz.value, y + sz.value), ImGui.COL32(0, 0, 0, 255), ImGui.COL32(255, 0, 0, 255), ImGui.COL32(255, 255, 0, 255), ImGui.COL32(0, 255, 0, 255)); ImGui.Dummy(new ImGui.Vec2((sz.value + spacing) * 10.2, (sz.value + spacing) * 3.0)); ImGui.PopItemWidth(); ImGui.EndTabItem(); } if (ImGui.BeginTabItem('Canvas')) { const points = STATIC<ImGui.Vector<ImGui.Vec2>>(UNIQUE('points#a04ba04e'), new ImGui.Vector()); const scrolling = STATIC<ImGui.Vec2>(UNIQUE('scrolling#f5569b88'), new ImGui.Vec2(0.0, 0.0)); const opt_enable_grid = STATIC<boolean>(UNIQUE('opt_enable_grid#874bd734'), true); const opt_enable_context_menu = STATIC<boolean>(UNIQUE('opt_enable_context_menu#8733fbe9'), true); const adding_line = STATIC<boolean>(UNIQUE('adding_line#306a0717'), false); ImGui.Checkbox('Enable grid', opt_enable_grid.access); ImGui.Checkbox('Enable context menu', opt_enable_context_menu.access); ImGui.Text('Mouse Left: drag to add lines,\nMouse Right: drag to scroll, click for context menu.'); // Typically you would use a BeginChild()/EndChild() pair to benefit from a clipping region + own scrolling. // Here we demonstrate that this can be replaced by simple offsetting + custom drawing + PushClipRect/PopClipRect() calls. // To use a child window instead we could use, e.g: // ImGui.PushStyleVar(ImGui.StyleVar.WindowPadding, new ImGui.Vec2(0, 0)); // Disable padding // ImGui.PushStyleColor(ImGui.Col.ChildBg, ImGui.COL32(50, 50, 50, 255)); // Set a background color // ImGui.BeginChild("canvas", new ImGui.Vec2(0.0, 0.0), true, ImGui.WindowFlags.NoMove); // ImGui.PopStyleColor(); // ImGui.PopStyleVar(); // [...] // ImGui.EndChild(); // Using InvisibleButton() as a convenience 1) it will advance the layout cursor and 2) allows us to use IsItemHovered()/IsItemActive() const canvas_p0: ImGui.Vec2 = ImGui.GetCursorScreenPos(); // ImDrawList API uses screen coordinates! const canvas_sz: ImGui.Vec2 = ImGui.GetContentRegionAvail(); // Resize canvas to what's available if (canvas_sz.x < 50.0) {canvas_sz.x = 50.0;} if (canvas_sz.y < 50.0) {canvas_sz.y = 50.0;} const canvas_p1: ImGui.Vec2 = new ImGui.Vec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y); // Draw border and background color const io: ImGui.IO = ImGui.GetIO(); const draw_list: ImGui.DrawList = ImGui.GetWindowDrawList(); draw_list.AddRectFilled(canvas_p0, canvas_p1, ImGui.COL32(50, 50, 50, 255)); draw_list.AddRect(canvas_p0, canvas_p1, ImGui.COL32(255, 255, 255, 255)); // This will catch our interactions ImGui.InvisibleButton('canvas', canvas_sz, ImGui.ButtonFlags.MouseButtonLeft | ImGui.ButtonFlags.MouseButtonRight); const is_hovered: boolean = ImGui.IsItemHovered(); // Hovered const is_active: boolean = ImGui.IsItemActive(); // Held const origin: ImGui.Vec2 = new ImGui.Vec2(canvas_p0.x + scrolling.value.x, canvas_p0.y + scrolling.value.y); // Lock scrolled origin const mouse_pos_in_canvas: ImGui.Vec2 = new ImGui.Vec2(io.MousePos.x - origin.x, io.MousePos.y - origin.y); // Add first and second point if (is_hovered && !adding_line.value && ImGui.IsMouseClicked(ImGui.MouseButton.Left)) { points.value.push_back(new ImGui.Vec2().Copy(mouse_pos_in_canvas)); points.value.push_back(new ImGui.Vec2().Copy(mouse_pos_in_canvas)); adding_line.value = true; } if (adding_line.value) { points.value.back().Copy(mouse_pos_in_canvas); // points.back() = mouse_pos_in_canvas; if (!ImGui.IsMouseDown(ImGui.MouseButton.Left)) {adding_line.value = false;} } // Pan (we use a zero mouse threshold when there's no context menu) // You may decide to make that threshold dynamic based on whether the mouse is hovering something etc. const mouse_threshold_for_pan: float = opt_enable_context_menu ? -1.0 : 0.0; if (is_active && ImGui.IsMouseDragging(ImGui.MouseButton.Right, mouse_threshold_for_pan)) { scrolling.value.x += io.MouseDelta.x; scrolling.value.y += io.MouseDelta.y; } // Context menu (under default mouse threshold) const drag_delta: ImGui.Vec2 = ImGui.GetMouseDragDelta(ImGui.MouseButton.Right); if (opt_enable_context_menu.value && ImGui.IsMouseReleased(ImGui.MouseButton.Right) && drag_delta.x === 0.0 && drag_delta.y === 0.0) {ImGui.OpenPopupOnItemClick('context');} if (ImGui.BeginPopup('context')) { if (adding_line.value) {points.value.resize(points.value.size() - 2);} adding_line.value = false; if (ImGui.MenuItem('Remove one', null, false, points.value.Size > 0)) { points.value.resize(points.value.size() - 2); } if (ImGui.MenuItem('Remove all', null, false, points.value.Size > 0)) { points.value.clear(); } ImGui.EndPopup(); } // Draw grid + all lines in the canvas draw_list.PushClipRect(canvas_p0, canvas_p1, true); if (opt_enable_grid.value) { const GRID_STEP: float = 64.0; for (let x = fmodf(scrolling.value.x, GRID_STEP); x < canvas_sz.x; x += GRID_STEP) {draw_list.AddLine(new ImGui.Vec2(canvas_p0.x + x, canvas_p0.y), new ImGui.Vec2(canvas_p0.x + x, canvas_p1.y), ImGui.COL32(200, 200, 200, 40));} for (let y = fmodf(scrolling.value.y, GRID_STEP); y < canvas_sz.y; y += GRID_STEP) {draw_list.AddLine(new ImGui.Vec2(canvas_p0.x, canvas_p0.y + y), new ImGui.Vec2(canvas_p1.x, canvas_p0.y + y), ImGui.COL32(200, 200, 200, 40));} } for (let n = 0; n < points.value.Size; n += 2) {draw_list.AddLine(new ImGui.Vec2(origin.x + points.value[n].x, origin.y + points.value[n].y), new ImGui.Vec2(origin.x + points.value[n + 1].x, origin.y + points.value[n + 1].y), ImGui.COL32(255, 255, 0, 255), 2.0);} draw_list.PopClipRect(); ImGui.EndTabItem(); } if (ImGui.BeginTabItem('BG/FG draw lists')) { const draw_bg = STATIC<boolean>(UNIQUE('draw_bg#f42741fb'), true); const draw_fg = STATIC<boolean>(UNIQUE('draw_fg#f4199725'), true); ImGui.Checkbox('Draw in Background draw list', draw_bg.access); ImGui.SameLine(); HelpMarker('The Background draw list will be rendered below every Dear ImGui windows.'); ImGui.Checkbox('Draw in Foreground draw list', draw_fg.access); ImGui.SameLine(); HelpMarker('The Foreground draw list will be rendered over every Dear ImGui windows.'); const window_pos: ImGui.Vec2 = ImGui.GetWindowPos(); const window_size: ImGui.Vec2 = ImGui.GetWindowSize(); const window_center: ImGui.Vec2 = new ImGui.Vec2(window_pos.x + window_size.x * 0.5, window_pos.y + window_size.y * 0.5); if (draw_bg.value) {ImGui.GetBackgroundDrawList().AddCircle(window_center, window_size.x * 0.6, ImGui.COL32(255, 0, 0, 200), 0, 10 + 4);} if (draw_fg.value) {ImGui.GetForegroundDrawList().AddCircle(window_center, window_size.y * 0.6, ImGui.COL32(0, 255, 0, 200), 0, 10);} ImGui.EndTabItem(); } ImGui.EndTabBar(); } ImGui.End(); }
//-----------------------------------------------------------------------------
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6731-L6962
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ShowExampleAppDockspace
function ShowExampleAppDockspace (p_open: ImGui.Access<boolean>): void { // In 99% case you should be able to just call DockSpaceOverViewport() and ignore all the code below! // In this specific demo, we are not using DockSpaceOverViewport() because: // - we allow the host window to be floating/moveable instead of filling the viewport (when opt_fullscreen == false) // - we allow the host window to have padding (when opt_padding == true) // - we have a local menu bar in the host window (vs. you could use BeginMainMenuBar() + DockSpaceOverViewport() in your code!) // TL;DR; this demo is more complicated than what you would normally use. // If we removed all the options we are showcasing, this demo would become: // void ShowExampleAppDockSpace() // { // ImGui::DockSpaceOverViewport(ImGui::GetMainViewport()); // } const opt_fullscreen = STATIC('opt_fullscreen#dockspace', true); const opt_padding = STATIC('opt_padding#dockspace', false); const dockspace_flags = STATIC('dockspace_flags#dockspace', ImGui.DockNodeFlags.None); // We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into, // because it would be confusing to have two docking targets within each others. let window_flags = ImGui.WindowFlags.MenuBar | ImGui.WindowFlags.NoDocking; if (opt_fullscreen.value) { const viewport = ImGui.GetMainViewport(); if (!viewport) { ImGui.ASSERT(0); return; } ImGui.SetNextWindowPos(viewport.GetWorkPos()); ImGui.SetNextWindowSize(viewport.GetWorkSize()); ImGui.SetNextWindowViewport(viewport.ID); ImGui.PushStyleVar(ImGui.StyleVar.WindowRounding, 0.0); ImGui.PushStyleVar(ImGui.StyleVar.WindowBorderSize, 0.0); window_flags |= ImGui.WindowFlags.NoTitleBar | ImGui.WindowFlags.NoCollapse | ImGui.WindowFlags.NoResize | ImGui.WindowFlags.NoMove; window_flags |= ImGui.WindowFlags.NoBringToFrontOnFocus | ImGui.WindowFlags.NoNavFocus; } else { dockspace_flags.value &= ~ImGui.DockNodeFlags.PassthruCentralNode; } // When using ImGuiDockNodeFlags_PassthruCentralNode, DockSpace() will render our background // and handle the pass-thru hole, so we ask Begin() to not render a background. if (dockspace_flags.value & ImGui.DockNodeFlags.PassthruCentralNode) {window_flags |= ImGui.WindowFlags.NoBackground;} // Important: note that we proceed even if Begin() returns false (aka window is collapsed). // This is because we want to keep our DockSpace() active. If a DockSpace() is inactive, // all active windows docked into it will lose their parent and become undocked. // We cannot preserve the docking relationship between an active window and an inactive docking, otherwise // any change of dockspace/settings would lead to windows being stuck in limbo and never being visible. if (!opt_padding.value) {ImGui.PushStyleVar(ImGui.StyleVar.WindowPadding, new ImGui.Vec2(0.0, 0.0));} ImGui.Begin('DockSpace Demo', p_open, window_flags); if (!opt_padding.value) {ImGui.PopStyleVar();} if (opt_fullscreen.value) {ImGui.PopStyleVar(2);} // DockSpace const io = ImGui.GetIO(); if (io.ConfigFlags & ImGui.ConfigFlags.DockingEnable) { const dockspace_id = ImGui.GetID('MyDockSpace'); ImGui.DockSpace(dockspace_id, new ImGui.Vec2(0.0, 0.0), dockspace_flags.value); } else { ShowDockingDisabledMessage(); } if (ImGui.BeginMenuBar()) { if (ImGui.BeginMenu('Options')) { // Disabling fullscreen would allow the window to be moved to the front of other windows, // which we can't undo at the moment without finer window depth/z control. ImGui.MenuItem('Fullscreen', null, (value = opt_fullscreen.value) => opt_fullscreen.value = value); ImGui.MenuItem('Padding', null, (value = opt_padding.value) => opt_padding.value = value); ImGui.Separator(); if (ImGui.MenuItem('Flag: NoSplit', '', (dockspace_flags.value & ImGui.DockNodeFlags.NoSplit) != 0)) { dockspace_flags.value ^= ImGui.DockNodeFlags.NoSplit; } if (ImGui.MenuItem('Flag: NoResize', '', (dockspace_flags.value & ImGui.DockNodeFlags.NoResize) != 0)) { dockspace_flags.value ^= ImGui.DockNodeFlags.NoResize; } if (ImGui.MenuItem('Flag: NoDockingInCentralNode', '', (dockspace_flags.value & ImGui.DockNodeFlags.NoDockingInCentralNode) != 0)) { dockspace_flags.value ^= ImGui.DockNodeFlags.NoDockingInCentralNode; } if (ImGui.MenuItem('Flag: AutoHideTabBar', '', (dockspace_flags.value & ImGui.DockNodeFlags.AutoHideTabBar) != 0)) { dockspace_flags.value ^= ImGui.DockNodeFlags.AutoHideTabBar; } if (ImGui.MenuItem('Flag: PassthruCentralNode', '', (dockspace_flags.value & ImGui.DockNodeFlags.PassthruCentralNode) != 0, opt_fullscreen.value)) { dockspace_flags.value ^= ImGui.DockNodeFlags.PassthruCentralNode; } ImGui.Separator(); if (ImGui.MenuItem('Close', null, false, p_open())) {p_open(false);} ImGui.EndMenu(); } HelpMarker( 'When docking is enabled, you can ALWAYS dock MOST window into another! Try it now!' + '\n\n' + ' > if io.ConfigDockingWithShift==false (default):' + '\n' + ' drag windows from title bar to dock' + '\n' + ' > if io.ConfigDockingWithShift==true:' + '\n' + ' drag windows from anywhere and hold Shift to dock' + '\n\n' + 'This demo app has nothing to do with it!' + '\n\n' + 'This demo app only demonstrate the use of ImGui.DockSpace() which allows you to manually create a docking node _within_ another window. This is useful so you can decorate your main application window (e.g. with a menu bar).' + '\n\n' + 'ImGui.DockSpace() comes with one hard constraint: it needs to be submitted _before_ any window which may be docked into it. Therefore, if you use a dock spot as the central point of your application, you\'ll probably want it to be part of the very first window you are submitting to imgui every frame.' + '\n\n' + '(NB: because of this constraint, the implicit "Debug" window can not be docked into an explicit DockSpace() node, because that window is submitted as part of the NewFrame() call. An easy workaround is that you can create your own implicit "Debug##2" window after calling DockSpace() and leave it in the window stack for anyone to use.)' ); ImGui.EndMenuBar(); } ImGui.End(); }
//-----------------------------------------------------------------------------
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L6982-L7082
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ShowExampleAppDockspaceAlt
function ShowExampleAppDockspaceAlt (p_open: ImGui.Access<boolean>): void { const dockspace_flags = STATIC('dockspace_flags#dockspace', ImGui.DockNodeFlags.None); // DockSpace const io = ImGui.GetIO(); if (ImGui.BeginMainMenuBar()) { if (ImGui.BeginMenu('Options')) { if (ImGui.MenuItem('Flag: NoSplit', '', (dockspace_flags.value & ImGui.DockNodeFlags.NoSplit) != 0)) { dockspace_flags.value ^= ImGui.DockNodeFlags.NoSplit; } if (ImGui.MenuItem('Flag: NoResize', '', (dockspace_flags.value & ImGui.DockNodeFlags.NoResize) != 0)) { dockspace_flags.value ^= ImGui.DockNodeFlags.NoResize; } if (ImGui.MenuItem('Flag: NoDockingInCentralNode', '', (dockspace_flags.value & ImGui.DockNodeFlags.NoDockingInCentralNode) != 0)) { dockspace_flags.value ^= ImGui.DockNodeFlags.NoDockingInCentralNode; } if (ImGui.MenuItem('Flag: AutoHideTabBar', '', (dockspace_flags.value & ImGui.DockNodeFlags.AutoHideTabBar) != 0)) { dockspace_flags.value ^= ImGui.DockNodeFlags.AutoHideTabBar; } if (ImGui.MenuItem('Flag: PassthruCentralNode', '', (dockspace_flags.value & ImGui.DockNodeFlags.PassthruCentralNode) != 0)) { dockspace_flags.value ^= ImGui.DockNodeFlags.PassthruCentralNode; } ImGui.Separator(); if (ImGui.MenuItem('Close', null, false, p_open())) {p_open(false);} ImGui.EndMenu(); } HelpMarker( 'When docking is enabled, you can ALWAYS dock MOST window into another! Try it now!' + '\n\n' + ' > if io.ConfigDockingWithShift==false (default):' + '\n' + ' drag windows from title bar to dock' + '\n' + ' > if io.ConfigDockingWithShift==true:' + '\n' + ' drag windows from anywhere and hold Shift to dock' + '\n\n' + 'This demo app has nothing to do with it!' + '\n\n' + 'This demo app only demonstrate the use of ImGui.DockSpace() which allows you to manually create a docking node _within_ another window. This is useful so you can decorate your main application window (e.g. with a menu bar).' + '\n\n' + 'ImGui.DockSpace() comes with one hard constraint: it needs to be submitted _before_ any window which may be docked into it. Therefore, if you use a dock spot as the central point of your application, you\'ll probably want it to be part of the very first window you are submitting to imgui every frame.' + '\n\n' + '(NB: because of this constraint, the implicit "Debug" window can not be docked into an explicit DockSpace() node, because that window is submitted as part of the NewFrame() call. An easy workaround is that you can create your own implicit "Debug##2" window after calling DockSpace() and leave it in the window stack for anyone to use.)' ); ImGui.EndMenuBar(); } if (io.ConfigFlags & ImGui.ConfigFlags.DockingEnable) { if (false) { const dockspace_id = ImGui.GetID('MyDockSpace'); ImGui.DockSpace(dockspace_id, new ImGui.Vec2(0.0, 0.0), dockspace_flags.value); } else { const vp = ImGui.GetMainViewport(); if (!vp) { ImGui.ASSERT(0); return; } //ImGui.DockSpaceOverViewport(vp); //ImGui.DockSpaceOverViewportID(vp.ID, dockspace_flags.value); ImGui.DockSpaceOverMainViewport(dockspace_flags.value); } } else { ShowDockingDisabledMessage(); } }
// An alternative way of creating a main dockspace.
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L7085-L7138
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
MyDocument.constructor
constructor (name: string, open: boolean = true, color: ImGui.Vec4 = new ImGui.Vec4(1.0, 1.0, 1.0, 1.0)) { this.ID = MyDocument.ID++; this.Name = name; this.Open = this.OpenPrev = open; this.Dirty = false; this.WantClose = false; this.Color = color; }
// An arbitrary variable associated to the document
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L7155-L7162
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
MyDocument.DisplayContents
static DisplayContents (doc: MyDocument): void { ImGui.PushID(doc.ID); ImGui.Text(`Document "${doc.Name}"`); ImGui.PushStyleColor(ImGui.Col.Text, doc.Color); ImGui.TextWrapped('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'); ImGui.PopStyleColor(); if (ImGui.Button('Modify', new ImGui.Vec2(100, 0))) {doc.Dirty = true;} ImGui.SameLine(); if (ImGui.Button('Save', new ImGui.Vec2(100, 0))) {doc.DoSave();} ImGui.ColorEdit3('color', doc.Color); // Useful to test drag and drop and hold-dragged-to-open-tab behavior. ImGui.PopID(); }
// Display placeholder contents for the Document
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L7169-L7180
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
MyDocument.DisplayContextMenu
static DisplayContextMenu (doc: MyDocument): void { if (!ImGui.BeginPopupContextItem()) {return;} const buf: string = `Save ${doc.Name}`; if (ImGui.MenuItem(buf, 'CTRL+S', false, doc.Open)) {doc.DoSave();} if (ImGui.MenuItem('Close', 'CTRL+W', false, doc.Open)) {doc.DoQueueClose();} ImGui.EndPopup(); }
// Display context menu for the Document
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L7183-L7191
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
NotifyOfDocumentsClosedElsewhere
function NotifyOfDocumentsClosedElsewhere (app: ExampleAppDocuments): void { for (let doc_n = 0; doc_n < app.Documents.Size; doc_n++) { const doc: MyDocument = app.Documents[doc_n]; if (!doc.Open && doc.OpenPrev) {ImGui.SetTabItemClosed(doc.Name);} doc.OpenPrev = doc.Open; } }
// [Optional] Notify the system of Tabs/Windows closure that happened outside the regular tab interface.
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_demo.ts#L7215-L7222
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
MemoryEditor.DrawWindow
public DrawWindow (title: string, mem_data: ArrayBuffer, mem_size: number = mem_data.byteLength, base_display_addr: number = 0x0000): void { const s: MemoryEditor.Sizes = new MemoryEditor.Sizes(); this.CalcSizes(s, mem_size, base_display_addr); ImGui.SetNextWindowSizeConstraints(new ImGui.Vec2(0.0, 0.0), new ImGui.Vec2(s.WindowWidth, Number.MAX_VALUE)); this.Open = true; if (ImGui.Begin(title, (_ = this.Open) => this.Open = _, ImGui.WindowFlags.NoScrollbar)) { if (ImGui.IsWindowHovered(ImGui.HoveredFlags.RootAndChildWindows) && ImGui.IsMouseReleased(ImGui.MouseButton.Right)) {ImGui.OpenPopup('context');} this.DrawContents(mem_data, mem_size, base_display_addr); if (this.ContentsWidthChanged) { this.CalcSizes(s, mem_size, base_display_addr); ImGui.SetWindowSize(new ImGui.Vec2(s.WindowWidth, ImGui.GetWindowSize().y)); } } ImGui.End(); }
// Standalone Memory Editor window
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_memory_editor.ts#L159-L175
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
MemoryEditor.DrawContents
public DrawContents (mem_data: ArrayBuffer, mem_size: number = mem_data.byteLength, base_display_addr: number = 0x0000): void { if (this.Cols < 1) {this.Cols = 1;} // ImU8* mem_data = (ImU8*)mem_data_void; const s: MemoryEditor.Sizes = new MemoryEditor.Sizes(); this.CalcSizes(s, mem_size, base_display_addr); const style: ImGui.Style = ImGui.GetStyle(); // We begin into our scrolling region with the 'ImGui.WindowFlags.NoMove' in order to prevent click from moving the window. // This is used as a facility since our main click detection code doesn't assign an ActiveId so the click would normally be caught as a window-move. const height_separator: float = style.ItemSpacing.y; let footer_height: float = 0; if (this.OptShowOptions) {footer_height += height_separator + ImGui.GetFrameHeightWithSpacing() * 1;} if (this.OptShowDataPreview) {footer_height += height_separator + ImGui.GetFrameHeightWithSpacing() * 1 + ImGui.GetTextLineHeightWithSpacing() * 3;} ImGui.BeginChild('##scrolling', new ImGui.Vec2(0, -footer_height), false, ImGui.WindowFlags.NoMove | ImGui.WindowFlags.NoNav); const draw_list: ImGui.DrawList = ImGui.GetWindowDrawList(); ImGui.PushStyleVar(ImGui.StyleVar.FramePadding, new ImGui.Vec2(0, 0)); ImGui.PushStyleVar(ImGui.StyleVar.ItemSpacing, new ImGui.Vec2(0, 0)); // We are not really using the clipper API correctly here, because we rely on visible_start_addr/visible_end_addr for our scrolling function. const line_total_count: int = 0 | /*(int)*/((mem_size + this.Cols - 1) / this.Cols); // ImGuiListClipper clipper; const clipper = new ImGui.ListClipper(); clipper.Begin(line_total_count, s.LineHeight); clipper.Step(); const visible_start_addr: size_t = clipper.DisplayStart * this.Cols; const visible_end_addr: size_t = clipper.DisplayEnd * this.Cols; let data_next: boolean = false; if (this.ReadOnly || this.DataEditingAddr >= mem_size) {this.DataEditingAddr = <size_t>-1;} if (this.DataPreviewAddr >= mem_size) {this.DataPreviewAddr = <size_t>-1;} const preview_data_type_size: size_t = this.OptShowDataPreview ? this.DataTypeGetSize(this.PreviewDataType) : 0; const data_editing_addr_backup: size_t = this.DataEditingAddr; let data_editing_addr_next: size_t = <size_t>-1; if (this.DataEditingAddr !== <size_t>-1) { // Move cursor but only apply on next frame so scrolling with be synchronized (because currently we can't change the scrolling while the window is being rendered) if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGui.Key.UpArrow)) && this.DataEditingAddr >= this.Cols) { data_editing_addr_next = this.DataEditingAddr - this.Cols; this.DataEditingTakeFocus = true; } else if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGui.Key.DownArrow)) && this.DataEditingAddr < mem_size - this.Cols) { data_editing_addr_next = this.DataEditingAddr + this.Cols; this.DataEditingTakeFocus = true; } else if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGui.Key.LeftArrow)) && this.DataEditingAddr > 0) { data_editing_addr_next = this.DataEditingAddr - 1; this.DataEditingTakeFocus = true; } else if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGui.Key.RightArrow)) && this.DataEditingAddr < mem_size - 1) { data_editing_addr_next = this.DataEditingAddr + 1; this.DataEditingTakeFocus = true; } } if (data_editing_addr_next !== <size_t>-1 && (data_editing_addr_next / this.Cols) !== (data_editing_addr_backup / this.Cols)) { // Track cursor movements const scroll_offset: int = (/*(int)*/(data_editing_addr_next / this.Cols) - /*(int)*/(data_editing_addr_backup / this.Cols)); const scroll_desired: boolean = (scroll_offset < 0 && data_editing_addr_next < visible_start_addr + this.Cols * 2) || (scroll_offset > 0 && data_editing_addr_next > visible_end_addr - this.Cols * 2); if (scroll_desired) {ImGui.SetScrollY(ImGui.GetScrollY() + scroll_offset * s.LineHeight);} } // Draw vertical separator const window_pos: ImGui.Vec2 = ImGui.GetWindowPos(); if (this.OptShowAscii) {draw_list.AddLine(new ImGui.Vec2(window_pos.x + s.PosAsciiStart - s.GlyphWidth, window_pos.y), new ImGui.Vec2(window_pos.x + s.PosAsciiStart - s.GlyphWidth, window_pos.y + 9999), ImGui.GetColorU32(ImGui.Col.Border));} const color_text: ImGui.U32 = ImGui.GetColorU32(ImGui.Col.Text); const color_disabled: ImGui.U32 = this.OptGreyOutZeroes ? ImGui.GetColorU32(ImGui.Col.TextDisabled) : color_text; // const char* format_address = this.OptUpperCaseHex ? "%0*" _PRISizeT "X: " : "%0*" _PRISizeT "x: "; const format_address = (n: number, a: number): string => { let s = a.toString(16).padStart(n, '0'); if (this.OptUpperCaseHex) { s = s.toUpperCase(); } return s; }; // const char* format_data = this.OptUpperCaseHex ? "%0*" _PRISizeT "X" : "%0*" _PRISizeT "x"; const format_data = (n: number, a: number): string => { let s = a.toString(16).padStart(n, '0'); if (this.OptUpperCaseHex) { s = s.toUpperCase(); } return s; }; // const char* format_byte = this.OptUpperCaseHex ? "%02X" : "%02x"; const format_byte = (b: number): string => { let s = b.toString(16).padStart(2, '0'); if (this.OptUpperCaseHex) { s = s.toUpperCase(); } return s; }; // const char* format_byte_space = this.OptUpperCaseHex ? "%02X " : "%02x "; const format_byte_space = (b: number): string => { return `${format_byte(b)} `; }; for (let /*int*/ line_i = clipper.DisplayStart; line_i < clipper.DisplayEnd; line_i++) { // display only visible lines let addr: size_t = (line_i * this.Cols); // ImGui.Text(format_address, s.AddrDigitsCount, base_display_addr + addr); ImGui.Text(format_address(s.AddrDigitsCount, base_display_addr + addr)); // Draw Hexadecimal for (let /*int*/ n = 0; n < this.Cols && addr < mem_size; n++, addr++) { let byte_pos_x: float = s.PosHexStart + s.HexCellWidth * n; if (this.OptMidColsCount > 0) {byte_pos_x += /*(float)*/(n / this.OptMidColsCount) * s.SpacingBetweenMidCols;} ImGui.SameLine(byte_pos_x); // Draw highlight const is_highlight_from_user_range: boolean = (addr >= this.HighlightMin && addr < this.HighlightMax); const is_highlight_from_user_func: boolean = (this.HighlightFn !== null && this.HighlightFn(mem_data, addr)); const is_highlight_from_preview: boolean = (addr >= this.DataPreviewAddr && addr < this.DataPreviewAddr + preview_data_type_size); if (is_highlight_from_user_range || is_highlight_from_user_func || is_highlight_from_preview) { const pos: ImGui.Vec2 = ImGui.GetCursorScreenPos(); let highlight_width: float = s.GlyphWidth * 2; const is_next_byte_highlighted: boolean = (addr + 1 < mem_size) && ((this.HighlightMax !== <size_t>-1 && addr + 1 < this.HighlightMax) || (this.HighlightFn !== null && this.HighlightFn(mem_data, addr + 1))); if (is_next_byte_highlighted || (n + 1 === this.Cols)) { highlight_width = s.HexCellWidth; if (this.OptMidColsCount > 0 && n > 0 && (n + 1) < this.Cols && ((n + 1) % this.OptMidColsCount) === 0) {highlight_width += s.SpacingBetweenMidCols;} } draw_list.AddRectFilled(pos, new ImGui.Vec2(pos.x + highlight_width, pos.y + s.LineHeight), this.HighlightColor); } if (this.DataEditingAddr === addr) { // Display text input on current byte let data_write: boolean = false; ImGui.PushID(/*(void*)*/addr); if (this.DataEditingTakeFocus) { ImGui.SetKeyboardFocusHere(); ImGui.CaptureKeyboardFromApp(true); // sprintf(AddrInputBuf, format_data, s.AddrDigitsCount, base_display_addr + addr); this.AddrInputBuf.buffer = format_data(s.AddrDigitsCount, base_display_addr + addr); // sprintf(DataInputBuf, format_byte, ReadFn ? ReadFn(mem_data, addr) : mem_data[addr]); this.DataInputBuf.buffer = format_byte(this.ReadFn ? this.ReadFn(mem_data, addr) : new Uint8Array(mem_data)[addr]); } ImGui.PushItemWidth(s.GlyphWidth * 2); class UserData { // FIXME: We should have a way to retrieve the text edit cursor position more easily in the API, this is rather tedious. This is such a ugly mess we may be better off not using InputText() at all here. static Callback (data: ImGui.InputTextCallbackData<UserData>) { const user_data: UserData | null = data.UserData; ImGui.ASSERT(user_data !== null); if (!data.HasSelection()) {user_data.CursorPos = data.CursorPos;} if (data.SelectionStart === 0 && data.SelectionEnd === data.BufTextLen) { // When not editing a byte, always rewrite its content (this is a bit tricky, since InputText technically "owns" the master copy of the buffer we edit it in there) data.DeleteChars(0, data.BufTextLen); data.InsertChars(0, user_data.CurrentBufOverwrite.buffer); data.SelectionStart = 0; data.SelectionEnd = 2; data.CursorPos = 0; } return 0; } readonly CurrentBufOverwrite: ImGui.StringBuffer = new ImGui.StringBuffer(3); // Input CursorPos: number = 0; // Output } const user_data: UserData = new UserData(); user_data.CursorPos = -1; // sprintf(user_data.CurrentBufOverwrite, format_byte, ReadFn ? ReadFn(mem_data, addr) : mem_data[addr]); user_data.CurrentBufOverwrite.buffer = format_byte(this.ReadFn ? this.ReadFn(mem_data, addr) : new Uint8Array(mem_data)[addr]); const flags: ImGui.InputTextFlags = ImGui.InputTextFlags.CharsHexadecimal | ImGui.InputTextFlags.EnterReturnsTrue | ImGui.InputTextFlags.AutoSelectAll | ImGui.InputTextFlags.NoHorizontalScroll | ImGui.InputTextFlags.AlwaysOverwrite | ImGui.InputTextFlags.CallbackAlways; if (ImGui.InputText('##data', this.DataInputBuf, 32, flags, UserData.Callback, user_data)) {data_write = data_next = true;} else if (!this.DataEditingTakeFocus && !ImGui.IsItemActive()) {this.DataEditingAddr = data_editing_addr_next = <size_t>-1;} this.DataEditingTakeFocus = false; ImGui.PopItemWidth(); if (user_data.CursorPos >= 2) {data_write = data_next = true;} if (data_editing_addr_next !== <size_t>-1) {data_write = data_next = false;} // unsigned int data_input_value = 0; let data_input_value: number/*unsigned int*/ = 0; // if (data_write && sscanf(DataInputBuf, "%X", &data_input_value) === 1) if (data_write && Number.isInteger(data_input_value = parseInt(this.DataInputBuf.buffer, 16))) { if (this.WriteFn) {this.WriteFn(mem_data, addr, /*(ImU8)*/data_input_value);} else { // mem_data[addr] = (ImU8)data_input_value; new Uint8Array(mem_data)[addr] = data_input_value; } } ImGui.PopID(); } else { // NB: The trailing space is not visible but ensure there's no gap that the mouse cannot click on. // ImU8 b = ReadFn ? ReadFn(mem_data, addr) : mem_data[addr]; const b: number/*ImU8*/ = this.ReadFn ? this.ReadFn(mem_data, addr) : new Uint8Array(mem_data)[addr]; if (this.OptShowHexII) { if ((b >= 32 && b < 128)) { // ImGui.Text(".%c ", b); ImGui.Text(`.${String.fromCharCode(b)} `); } else if (b === 0xFF && this.OptGreyOutZeroes) {ImGui.TextDisabled('## ');} else if (b === 0x00) {ImGui.Text(' ');} else {ImGui.Text(format_byte_space(b));} } else { if (b === 0 && this.OptGreyOutZeroes) {ImGui.TextDisabled('00 ');} else {ImGui.Text(format_byte_space(b));} } if (!this.ReadOnly && ImGui.IsItemHovered() && ImGui.IsMouseClicked(0)) { this.DataEditingTakeFocus = true; data_editing_addr_next = addr; } } } if (this.OptShowAscii) { // Draw ASCII values ImGui.SameLine(s.PosAsciiStart); const pos: ImGui.Vec2 = ImGui.GetCursorScreenPos(); addr = line_i * this.Cols; ImGui.PushID(line_i); if (ImGui.InvisibleButton('ascii', new ImGui.Vec2(s.PosAsciiEnd - s.PosAsciiStart, s.LineHeight))) { this.DataEditingAddr = this.DataPreviewAddr = addr + ((ImGui.GetIO().MousePos.x - pos.x) / s.GlyphWidth); this.DataEditingTakeFocus = true; } ImGui.PopID(); for (let /*int*/ n = 0; n < this.Cols && addr < mem_size; n++, addr++) { if (addr === this.DataEditingAddr) { draw_list.AddRectFilled(pos, new ImGui.Vec2(pos.x + s.GlyphWidth, pos.y + s.LineHeight), ImGui.GetColorU32(ImGui.Col.FrameBg)); draw_list.AddRectFilled(pos, new ImGui.Vec2(pos.x + s.GlyphWidth, pos.y + s.LineHeight), ImGui.GetColorU32(ImGui.Col.TextSelectedBg)); } // unsigned char c = ReadFn ? ReadFn(mem_data, addr) : mem_data[addr]; const c: number = this.ReadFn ? this.ReadFn(mem_data, addr) : new Uint8Array(mem_data)[addr]; // char display_c = (c < 32 || c >= 128) ? '.' : c; const display_c: string = (c < 32 || c >= 128) ? '.' : String.fromCharCode(c); // draw_list.AddText(pos, (display_c === c) ? color_text : color_disabled, &display_c, &display_c + 1); draw_list.AddText(pos, (display_c === '.') ? color_disabled : color_text, display_c); pos.x += s.GlyphWidth; } } } ImGui.ASSERT(clipper.Step() === false); clipper.End(); ImGui.PopStyleVar(2); ImGui.EndChild(); if (data_next && this.DataEditingAddr < mem_size) { this.DataEditingAddr = this.DataPreviewAddr = this.DataEditingAddr + 1; this.DataEditingTakeFocus = true; } else if (data_editing_addr_next !== <size_t>-1) { this.DataEditingAddr = this.DataPreviewAddr = data_editing_addr_next; } const lock_show_data_preview: boolean = this.OptShowDataPreview; if (this.OptShowOptions) { ImGui.Separator(); this.DrawOptionsLine(s, mem_data, mem_size, base_display_addr); } if (lock_show_data_preview) { ImGui.Separator(); this.DrawPreviewLine(s, mem_data, mem_size, base_display_addr); } // Notify the main window of our ideal child content size (FIXME: we are missing an API to get the contents size from the child) ImGui.SetCursorPosX(s.WindowWidth); }
// void DrawContents(void* mem_data_void, size_t mem_size, size_t base_display_addr = 0x0000)
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_memory_editor.ts#L179-L432
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
format_address
const format_address = (n: number, a: number): string => { let s = a.toString(16).padStart(n, '0'); if (this.OptUpperCaseHex) { s = s.toUpperCase(); } return s; };
// const char* format_address = this.OptUpperCaseHex ? "%0*" _PRISizeT "X: " : "%0*" _PRISizeT "x: ";
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_memory_editor.ts#L242-L248
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
format_data
const format_data = (n: number, a: number): string => { let s = a.toString(16).padStart(n, '0'); if (this.OptUpperCaseHex) { s = s.toUpperCase(); } return s; };
// const char* format_data = this.OptUpperCaseHex ? "%0*" _PRISizeT "X" : "%0*" _PRISizeT "x";
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_memory_editor.ts#L250-L256
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
format_byte
const format_byte = (b: number): string => { let s = b.toString(16).padStart(2, '0'); if (this.OptUpperCaseHex) { s = s.toUpperCase(); } return s; };
// const char* format_byte = this.OptUpperCaseHex ? "%02X" : "%02x";
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_memory_editor.ts#L258-L264
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
format_byte_space
const format_byte_space = (b: number): string => { return `${format_byte(b)} `; };
// const char* format_byte_space = this.OptUpperCaseHex ? "%02X " : "%02x ";
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_memory_editor.ts#L266-L268
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
UserData.Callback
static Callback (data: ImGui.InputTextCallbackData<UserData>) { const user_data: UserData | null = data.UserData; ImGui.ASSERT(user_data !== null); if (!data.HasSelection()) {user_data.CursorPos = data.CursorPos;} if (data.SelectionStart === 0 && data.SelectionEnd === data.BufTextLen) { // When not editing a byte, always rewrite its content (this is a bit tricky, since InputText technically "owns" the master copy of the buffer we edit it in there) data.DeleteChars(0, data.BufTextLen); data.InsertChars(0, user_data.CurrentBufOverwrite.buffer); data.SelectionStart = 0; data.SelectionEnd = 2; data.CursorPos = 0; } return 0; }
// FIXME: We should have a way to retrieve the text edit cursor position more easily in the API, this is rather tedious. This is such a ugly mess we may be better off not using InputText() at all here.
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_memory_editor.ts#L316-L331
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
format_range
const format_range = (n_min: number, a_min: number, n_max: number, a_max: number): string => { let s_min = a_min.toString(16).padStart(n_min, '0'); let s_max = a_max.toString(16).padStart(n_max, '0'); if (this.OptUpperCaseHex) { s_min = s_min.toUpperCase(); s_max = s_max.toUpperCase(); } return `Range ${s_min}..${s_max}`; };
// const char* format_range = OptUpperCaseHex ? "Range %0*" _PRISizeT "X..%0*" _PRISizeT "X" : "Range %0*" _PRISizeT "x..%0*" _PRISizeT "x";
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_memory_editor.ts#L438-L448
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
MemoryEditor.DrawPreviewLine
DrawPreviewLine (s: MemoryEditor.Sizes, mem_data: ArrayBuffer, mem_size: size_t, base_display_addr: size_t): void { // IM_UNUSED(base_display_addr); // ImU8* mem_data = (ImU8*)mem_data_void; const style: ImGui.Style = ImGui.GetStyle(); ImGui.AlignTextToFramePadding(); ImGui.Text('Preview as:'); ImGui.SameLine(); ImGui.PushItemWidth((s.GlyphWidth * 10.0) + style.FramePadding.x * 2.0 + style.ItemInnerSpacing.x); if (ImGui.BeginCombo('##combo_type', this.DataTypeGetDesc(this.PreviewDataType), ImGui.ComboFlags.HeightLargest)) { for (let /*int*/ n = 0; n < ImGui.DataType.COUNT; n++) { if (ImGui.Selectable(this.DataTypeGetDesc(<ImGui.DataType>n), this.PreviewDataType === n)) {this.PreviewDataType = <ImGui.DataType>n;} } ImGui.EndCombo(); } ImGui.PopItemWidth(); ImGui.SameLine(); ImGui.PushItemWidth((s.GlyphWidth * 6.0) + style.FramePadding.x * 2.0 + style.ItemInnerSpacing.x); ImGui.Combo('##combo_endianess', (_ = this.PreviewEndianess) => this.PreviewEndianess = _, 'LE\0BE\0\0'); ImGui.PopItemWidth(); // char buf[128] = ""; const buf: ImGui.StringBuffer = new ImGui.StringBuffer(128); const x: float = s.GlyphWidth * 6.0; const has_value: boolean = this.DataPreviewAddr !== <size_t>-1; if (has_value) {this.DrawPreviewData(this.DataPreviewAddr, mem_data, mem_size, this.PreviewDataType, MemoryEditor.DataFormat.Dec, buf, ImGui.ARRAYSIZE(buf));} ImGui.Text('Dec'); ImGui.SameLine(x); ImGui.TextUnformatted(has_value ? buf.buffer : 'N/A'); if (has_value) {this.DrawPreviewData(this.DataPreviewAddr, mem_data, mem_size, this.PreviewDataType, MemoryEditor.DataFormat.Hex, buf, ImGui.ARRAYSIZE(buf));} ImGui.Text('Hex'); ImGui.SameLine(x); ImGui.TextUnformatted(has_value ? buf.buffer : 'N/A'); if (has_value) {this.DrawPreviewData(this.DataPreviewAddr, mem_data, mem_size, this.PreviewDataType, MemoryEditor.DataFormat.Bin, buf, ImGui.ARRAYSIZE(buf));} // buf[ImGui.ARRAYSIZE(buf) - 1] = 0; ImGui.Text('Bin'); ImGui.SameLine(x); ImGui.TextUnformatted(has_value ? buf.buffer : 'N/A'); }
// void DrawPreviewLine(const Sizes& s, void* mem_data_void, size_t mem_size, size_t base_display_addr)
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_memory_editor.ts#L495-L528
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
MemoryEditor.DataTypeGetDesc
DataTypeGetDesc (data_type: ImGui.DataType): string { const descs: string[] = ['Int8', 'Uint8', 'Int16', 'Uint16', 'Int32', 'Uint32', 'Int64', 'Uint64', 'Float', 'Double']; ImGui.ASSERT(data_type >= 0 && data_type < ImGui.DataType.COUNT); return descs[data_type]; }
// Utilities for Data Preview
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_memory_editor.ts#L531-L537
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
MemoryEditor.DrawPreviewData
DrawPreviewData (addr: size_t, mem_data: ArrayBuffer, mem_size: size_t, data_type: ImGui.DataType, data_format: MemoryEditor.DataFormat, out_buf: ImGui.StringBuffer, out_buf_size: size_t): void { // uint8_t buf[8]; const buf = new Uint8Array(8); const elem_size: size_t = this.DataTypeGetSize(data_type); const size: size_t = addr + elem_size > mem_size ? mem_size - addr : elem_size; if (this.ReadFn) { for (let /*int*/ i = 0, n = /*(int)*/size; i < n; ++i) {buf[i] = this.ReadFn(mem_data, addr + i);} } else { // memcpy(buf, mem_data + addr, size); buf.set(new Uint8Array(mem_data, addr, size)); } if (this.PreviewEndianess) { new Uint8Array(buf.buffer, 0, size).reverse(); } if (data_format === MemoryEditor.DataFormat.Bin) { // uint8_t binbuf[8]; // EndianessCopy(binbuf, buf, size); // ImSnprintf(out_buf, out_buf_size, "%s", FormatBinary(binbuf, (int)size * 8)); out_buf.buffer = ''; for (let i = 0; i < size; ++i) { out_buf.buffer += buf[i].toString(2).padStart(8, '0') + ' '; } return; } // out_buf[0] = 0; out_buf.buffer = ''; switch (data_type) { case ImGui.DataType.S8: { // int8_t int8 = 0; // EndianessCopy(&int8, buf, size); // if (data_format === MemoryEditor.DataFormat.Dec) { ImSnprintf(out_buf, out_buf_size, "%hhd", int8); return; } // if (data_format === MemoryEditor.DataFormat.Hex) { ImSnprintf(out_buf, out_buf_size, "0x%02x", int8 & 0xFF); return; } const int8 = new Int8Array(buf.buffer); if (data_format === MemoryEditor.DataFormat.Dec) { out_buf.buffer = int8[0].toString(); return; } if (data_format === MemoryEditor.DataFormat.Hex) { out_buf.buffer = `0x${int8[0].toString(16).padStart(2, '0')}`; return; } break; } case ImGui.DataType.U8: { // uint8_t uint8 = 0; // EndianessCopy(&uint8, buf, size); // if (data_format === MemoryEditor.DataFormat.Dec) { ImSnprintf(out_buf, out_buf_size, "%hhu", uint8); return; } // if (data_format === MemoryEditor.DataFormat.Hex) { ImSnprintf(out_buf, out_buf_size, "0x%02x", uint8 & 0XFF); return; } const uint8 = new Uint8Array(buf.buffer); if (data_format === MemoryEditor.DataFormat.Dec) { out_buf.buffer = uint8[0].toString(); return; } if (data_format === MemoryEditor.DataFormat.Hex) { out_buf.buffer = `0x${uint8[0].toString(16).padStart(2, '0')}`; return; } break; } case ImGui.DataType.S16: { // int16_t int16 = 0; // EndianessCopy(&int16, buf, size); // if (data_format === MemoryEditor.DataFormat.Dec) { ImSnprintf(out_buf, out_buf_size, "%hd", int16); return; } // if (data_format === MemoryEditor.DataFormat.Hex) { ImSnprintf(out_buf, out_buf_size, "0x%04x", int16 & 0xFFFF); return; } const int16 = new Int16Array(buf.buffer); if (data_format === MemoryEditor.DataFormat.Dec) { out_buf.buffer = int16[0].toString(); return; } if (data_format === MemoryEditor.DataFormat.Hex) { out_buf.buffer = `0x${int16[0].toString(16).padStart(4, '0')}`; return; } break; } case ImGui.DataType.U16: { // uint16_t uint16 = 0; // EndianessCopy(&uint16, buf, size); // if (data_format === MemoryEditor.DataFormat.Dec) { ImSnprintf(out_buf, out_buf_size, "%hu", uint16); return; } // if (data_format === MemoryEditor.DataFormat.Hex) { ImSnprintf(out_buf, out_buf_size, "0x%04x", uint16 & 0xFFFF); return; } const uint16 = new Uint16Array(buf.buffer); if (data_format === MemoryEditor.DataFormat.Dec) { out_buf.buffer = uint16[0].toString(); return; } if (data_format === MemoryEditor.DataFormat.Hex) { out_buf.buffer = `0x${uint16[0].toString(16).padStart(4, '0')}`; return; } break; } case ImGui.DataType.S32: { // int32_t int32 = 0; // EndianessCopy(&int32, buf, size); // if (data_format === MemoryEditor.DataFormat.Dec) { ImSnprintf(out_buf, out_buf_size, "%d", int32); return; } // if (data_format === MemoryEditor.DataFormat.Hex) { ImSnprintf(out_buf, out_buf_size, "0x%08x", int32); return; } const int32 = new Int32Array(buf.buffer); if (data_format === MemoryEditor.DataFormat.Dec) { out_buf.buffer = int32[0].toString(); return; } if (data_format === MemoryEditor.DataFormat.Hex) { out_buf.buffer = `0x${int32[0].toString(16).padStart(8, '0')}`; return; } break; } case ImGui.DataType.U32: { // uint32_t uint32 = 0; // EndianessCopy(&uint32, buf, size); // if (data_format === MemoryEditor.DataFormat.Dec) { ImSnprintf(out_buf, out_buf_size, "%u", uint32); return; } // if (data_format === MemoryEditor.DataFormat.Hex) { ImSnprintf(out_buf, out_buf_size, "0x%08x", uint32); return; } const uint32 = new Uint32Array(buf.buffer); if (data_format === MemoryEditor.DataFormat.Dec) { out_buf.buffer = uint32[0].toString(); return; } if (data_format === MemoryEditor.DataFormat.Hex) { out_buf.buffer = `0x${uint32[0].toString(16).padStart(8, '0')}`; return; } break; } case ImGui.DataType.S64: { // int64_t int64 = 0; // EndianessCopy(&int64, buf, size); // if (data_format === MemoryEditor.DataFormat.Dec) { ImSnprintf(out_buf, out_buf_size, "%lld", (long long)int64); return; } // if (data_format === MemoryEditor.DataFormat.Hex) { ImSnprintf(out_buf, out_buf_size, "0x%016llx", (long long)int64); return; } const int64 = new BigInt64Array(buf.buffer); if (data_format === MemoryEditor.DataFormat.Dec) { out_buf.buffer = int64[0].toString(); return; } if (data_format === MemoryEditor.DataFormat.Hex) { out_buf.buffer = `0x${int64[0].toString(16).padStart(16, '0')}`; return; } break; } case ImGui.DataType.U64: { // uint64_t uint64 = 0; // EndianessCopy(&uint64, buf, size); // if (data_format === MemoryEditor.DataFormat.Dec) { ImSnprintf(out_buf, out_buf_size, "%llu", (long long)uint64); return; } // if (data_format === MemoryEditor.DataFormat.Hex) { ImSnprintf(out_buf, out_buf_size, "0x%016llx", (long long)uint64); return; } const uint64 = new BigUint64Array(buf.buffer); if (data_format === MemoryEditor.DataFormat.Dec) { out_buf.buffer = uint64[0].toString(); return; } if (data_format === MemoryEditor.DataFormat.Hex) { out_buf.buffer = `0x${uint64[0].toString(16).padStart(16, '0')}`; return; } break; } case ImGui.DataType.Float: { // float float32 = 0.0f; // EndianessCopy(&float32, buf, size); // if (data_format === MemoryEditor.DataFormat.Dec) { ImSnprintf(out_buf, out_buf_size, "%f", float32); return; } // if (data_format === MemoryEditor.DataFormat.Hex) { ImSnprintf(out_buf, out_buf_size, "%a", float32); return; } const float32 = new Float32Array(buf.buffer); if (data_format === MemoryEditor.DataFormat.Dec) { out_buf.buffer = float32[0].toString(); return; } if (data_format === MemoryEditor.DataFormat.Hex) { out_buf.buffer = `0x${float32[0].toString(16)}`; return; } break; } case ImGui.DataType.Double: { // double float64 = 0.0; // EndianessCopy(&float64, buf, size); // if (data_format === MemoryEditor.DataFormat.Dec) { ImSnprintf(out_buf, out_buf_size, "%f", float64); return; } // if (data_format === MemoryEditor.DataFormat.Hex) { ImSnprintf(out_buf, out_buf_size, "%a", float64); return; } const float64 = new Float64Array(buf.buffer); if (data_format === MemoryEditor.DataFormat.Dec) { out_buf.buffer = float64[0].toString(); return; } if (data_format === MemoryEditor.DataFormat.Hex) { out_buf.buffer = `0x${float64[0].toString(16)}`; return; } break; } case ImGui.DataType.COUNT: break; } // Switch // ImGui.ASSERT(0); // Shouldn't reach }
// [Internal]
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/imgui/imgui_memory_editor.ts#L623-L867
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
AssetLock.acquire
async acquire (): Promise<void> { if (this.isLocked) { await new Promise<void>(resolve => this.waitingResolvers.push(resolve)); } this.isLocked = true; }
// 尝试获取锁,如果锁被占用则返回一个会等待锁释放的 Promise
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/project.ts#L23-L28
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
AssetLock.release
release (): void { if (!this.isLocked) { throw new Error('Lock is not acquired yet.'); } this.isLocked = false; const resolve = this.waitingResolvers.shift(); if (resolve) { resolve(); } }
// 释放锁,并通知下一个等待者(如果有的话)
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/project.ts#L31-L43
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
NodeStyle.constructor
constructor ( header_bg: number, header_title_color: ImColor, radius: number ) { this.header_bg = header_bg; this.header_title_color = header_title_color; this.radius = radius; this.padding = new ImGui.ImVec4(13.7, 6.0, 13.7, 2.0); }
// Border thickness when selected
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/base-node.ts#L30-L39
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
NodeStyle.cyan
static cyan (): NodeStyle { return new NodeStyle( ImGui.IM_COL32(71, 142, 173, 255), new ImColor(233, 241, 244, 255), 6.5 ); }
// Static methods for default styles
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/base-node.ts#L42-L48
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
Link.destroy
destroy (): void { this.m_isDestroyed = true; this.m_left.deleteLink(); }
/** * Destruction of a link * Deletes references of this links from connected pins */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/link.ts#L27-L30
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
Link.update
update (): void { const start: ImGui.ImVec2 = this.m_left.pinPoint(); const end: ImGui.ImVec2 = this.m_right.pinPoint(); const windowPos = ImGui.GetWindowPos(); start.x += windowPos.x; start.y += windowPos.y; end.x += windowPos.x; end.y += windowPos.y; let thickness: number = this.m_left.getStyle().extra.link_thickness; const mouseClickState: boolean = this.m_inf.getSingleUseClick(); const leftCtrlKeyCode = 17; if (!ImGui.IsKeyDown(leftCtrlKeyCode) && ImGui.IsMouseClicked(ImGui.ImGuiMouseButton.Left)) { this.m_selected = false; } if (smart_bezier_collider(ImGui.GetMousePos(), start, end, 2.5)) { this.m_hovered = true; thickness = this.m_left.getStyle().extra.link_hovered_thickness; if (mouseClickState) { this.m_inf.consumeSingleUseClick(); this.m_selected = true; } } else { this.m_hovered = false; } if (this.m_selected) { smart_bezier( start, end, this.m_left.getStyle().extra.outline_color, thickness + this.m_left.getStyle().extra.link_selected_outline_thickness ); } smart_bezier(start, end, this.m_left.getStyle().color, thickness); const deleteKeyCode = 8; if (this.m_selected && ImGui.IsKeyPressed(deleteKeyCode, false)) { this.m_right.deleteLink(); } }
/** * Main update function * Draws the Link and updates Hovering and Selected status. */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/link.ts#L39-L84
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
Link.getLeft
getLeft (): Pin { return this.m_left; }
/** * Get Left pin of the link * @returns Pointer to the Pin */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/link.ts#L90-L92
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
Link.getRight
getRight (): Pin { return this.m_right; }
/** * Get Right pin of the link * @returns Pointer to the Pin */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/link.ts#L98-L100
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
Link.isHovered
isHovered (): boolean { return this.m_hovered; }
/** * Get hovering status * @returns TRUE If the link is hovered in the current frame */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/link.ts#L106-L108
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
Link.isSelected
isSelected (): boolean { return this.m_selected; }
/** * Get selected status * @returns TRUE If the link is selected in the current frame */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/link.ts#L114-L116
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ContainedContext.destroy
destroy (): void { if (this.m_ctx) { ImGui.DestroyContext(this.m_ctx); this.m_ctx = null; } }
/** * 析构函数,用于清理ImGui上下文 */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L77-L82
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ContainedContext.begin
begin (): void { // ImGui.PushID(this.getid); // 使用对象引用作为ID ImGui.PushStyleColor(ImGui.Col.ChildBg, this.m_config.color); // ImGui.BeginChild('view_port', this.m_config.size.clone(), false, ImGuiWindowFlags.NoMove); ImGui.PopStyleColor(); this.m_pos = ImGui.GetWindowPos(); this.m_size = ImGui.GetContentRegionAvail(); this.m_origin = ImGui.GetCursorScreenPos(); this.m_original_ctx = ImGui.GetCurrentContext(); const orig_style = ImGui.GetStyle(); // if (!this.m_ctx) { // this.m_ctx = ImGui.CreateContext(); // } // ImGui.SetCurrentContext(this.m_ctx); const new_style = ImGui.GetStyle(); // new_style.cloneFrom(orig_style); // 复制原始样式 // 复制输入事件 // CopyIOEvents(this.m_original_ctx, this.m_ctx, this.m_origin, this.m_scale); // 设置显示大小和其他配置 // ImGui.GetIO().DisplaySize = new ImVec2(this.m_size.x / this.m_scale, this.m_size.y / this.m_scale); // ImGui.GetIO().ConfigInputTrickleEventQueue = false; // ImGui.NewFrame(); ImGui.SetWindowFontScale(this.m_scale); // if (this.m_config.extra_window_wrapper) { // ImGui.SetNextWindowPos(new ImVec2(0, 0), ImGuiCond.Once); // ImGui.SetNextWindowSize(ImGui.GetMainViewport()?.WorkSize.clone() || new ImVec2(800, 600)); // ImGui.PushStyleVar(ImGui.StyleVar.WindowPadding, new ImVec2(0, 0)); // ImGui.Begin('viewport_container', null, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoMove // | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse); // ImGui.PopStyleVar(); // } }
/** * 开始渲染一个封闭的ImGui窗口 */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L87-L127
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ContainedContext.end
end (): void { this.m_anyWindowHovered = ImGui.IsWindowHovered(ImGui.HoveredFlags.AnyWindow); if (this.m_config.extra_window_wrapper && ImGui.IsWindowHovered()) { this.m_anyWindowHovered = false; } this.m_anyItemActive = ImGui.IsAnyItemActive(); // if (this.m_config.extra_window_wrapper) { // ImGui.End(); // } // ImGui.Render(); const draw_data = ImGui.GetDrawData(); // ImGui.SetCurrentContext(this.m_original_ctx); // this.m_original_ctx = null; // 将绘制数据附加到当前窗口的绘制列表 // for (let i = 0; i < draw_data.CmdListsCount; i++) { // AppendDrawData(draw_data.CmdLists[i], this.m_origin, this.m_scale); // } // 检测悬停状态 this.m_hovered = ImGui.IsWindowHovered(ImGui.HoveredFlags.ChildWindows) && !this.m_anyWindowHovered; // 处理缩放 if (this.m_config.zoom_enabled && this.m_hovered && ImGui.GetIO().MouseWheel !== 0) { this.m_scaleTarget += ImGui.GetIO().MouseWheel / this.m_config.zoom_divisions; this.m_scaleTarget = Math.max(this.m_config.zoom_min, Math.min(this.m_scaleTarget, this.m_config.zoom_max)); if (this.m_config.zoom_smoothness === 0) { this.m_scroll = add(this.m_scroll, new ImVec2( (ImGui.GetIO().MousePos.x - this.m_pos.x) / this.m_scaleTarget - (ImGui.GetIO().MousePos.x - this.m_pos.x) / this.m_scale, (ImGui.GetIO().MousePos.y - this.m_pos.y) / this.m_scaleTarget - (ImGui.GetIO().MousePos.y - this.m_pos.y) / this.m_scale )); this.m_scale = this.m_scaleTarget; } } // 平滑缩放 if (Math.abs(this.m_scaleTarget - this.m_scale) >= 0.015 / this.m_config.zoom_smoothness) { const cs = (this.m_scaleTarget - this.m_scale) / this.m_config.zoom_smoothness; // this.m_scroll = add(this.m_scroll, new ImVec2( // (ImGui.GetIO().MousePos.x - this.m_pos.x) / (this.m_scale + cs) - (ImGui.GetIO().MousePos.x - this.m_pos.x) / this.m_scale, // (ImGui.GetIO().MousePos.y - this.m_pos.y) / (this.m_scale + cs) - (ImGui.GetIO().MousePos.y - this.m_pos.y) / this.m_scale // )); this.m_scale += (this.m_scaleTarget - this.m_scale) / this.m_config.zoom_smoothness; if (Math.abs(this.m_scaleTarget - this.m_scale) < 0.015 / this.m_config.zoom_smoothness) { // this.m_scroll = add(this.m_scroll, new ImVec2( // (ImGui.GetIO().MousePos.x - this.m_pos.x) / this.m_scaleTarget - (ImGui.GetIO().MousePos.x - this.m_pos.x) / this.m_scale, // (ImGui.GetIO().MousePos.y - this.m_pos.y) / this.m_scaleTarget - (ImGui.GetIO().MousePos.y - this.m_pos.y) / this.m_scale // )); this.m_scale = this.m_scaleTarget; } } // 重置缩放 if (ImGui.IsKeyPressed(this.m_config.reset_zoom_key, false)) { this.m_scaleTarget = this.m_config.default_zoom; } // console.log(this.m_hovered, !this.m_anyItemActive, ImGui.IsMouseDragging(this.m_config.scroll_button, 0)); // 处理滚动 if (this.m_hovered && !this.m_anyItemActive && ImGui.IsMouseDragging(this.m_config.scroll_button, 0)) { this.m_scroll = add(this.m_scroll, multiplyScalar(ImGui.GetIO().MouseDelta, 1 / this.m_scale)); this.m_scrollTarget = new ImVec2(this.m_scroll.x, this.m_scroll.y); } // ImGui.EndChild(); // ImGui.PopID(); }
/** * 结束渲染封闭的ImGui窗口 */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L132-L207
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ContainedContext.config
config (): ContainedContextConfig { return this.m_config; }
/** * 获取配置 */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L216-L218
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ContainedContext.scale
scale (): number { return this.m_scale; }
/** * 获取当前缩放比例 */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L223-L225
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ContainedContext.scroll
scroll (): ImVec2 { return this.m_scroll; }
/** * 获取当前滚动偏移 */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L230-L232
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ContainedContext.size
size (): ImVec2 { return this.m_size; }
/** * 获取绘制区域大小 */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L237-L239
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.update
update (): void { // Reset hovered node and dragging status this.m_hovering = null; this.m_hoveredNode = null; this.m_draggingNode = this.m_draggingNodeNext; this.m_singleUseClick = ImGui.IsMouseClicked(ImGui.ImGuiMouseButton.Left); // Begin ImGui context this.m_context.begin(); // ImGui.GetIO().IniFilename = ''; const drawList = ImGui.GetWindowDrawList(); const windowPos = ImGui.GetWindowPos(); // 显示网格 const windowSize = ImGui.GetWindowSize(); const gradSize = this.m_style.grid_size * this.m_context.scale(); const subGridStep = gradSize / this.m_style.grid_subdivisions; const gridStartX = (this.m_context.scroll().x - windowSize.x / 2) * this.m_context.scale() + windowSize.x / 2; const gridStartY = (this.m_context.scroll().y - windowSize.y / 2) * this.m_context.scale() + windowSize.y / 2; // 绘制主网格线 for (let x = this.mod(gridStartX, gradSize); x < windowSize.x; x += gradSize) { drawList.AddLine(new ImGui.ImVec2(x + windowPos.x, windowPos.y), new ImGui.ImVec2(x + windowPos.x, windowPos.y + windowSize.y), this.m_style.grid); } for (let y = this.mod(gridStartY, gradSize); y < windowSize.y; y += gradSize) { drawList.AddLine(new ImGui.ImVec2(windowPos.x, y + windowPos.y), new ImGui.ImVec2(windowPos.x + windowSize.x, y + windowPos.y), this.m_style.grid); } // 绘制子网格线 if (this.m_context.scale() > 0.7) { for (let x = this.mod(gridStartX, subGridStep); x < windowSize.x; x += subGridStep) { drawList.AddLine(new ImGui.ImVec2(x + windowPos.x, windowPos.y), new ImGui.ImVec2(x + windowPos.x, windowPos.y + windowSize.y), this.m_style.subGrid); } for (let y = this.mod(gridStartY, subGridStep); y < windowSize.y; y += subGridStep) { drawList.AddLine(new ImGui.ImVec2(windowPos.x, y + windowPos.y), new ImGui.ImVec2(windowPos.x + windowSize.x, y + windowPos.y), this.m_style.subGrid); } } // Update and draw nodes drawList.ChannelsSplit(2); for (const [uid, node] of this.m_nodes) { node.update(); } // Remove "toDestroy" nodes for (const [uid, node] of Array.from(this.m_nodes)) { if (node.toDestroy()) { this.m_nodes.delete(uid); } } drawList.ChannelsMerge(); // Update and draw links for (const link of this.m_links) { link.update(); } // Handle links drop-off if (this.m_dragOut && ImGui.IsMouseReleased(ImGui.ImGuiMouseButton.Left)) { if (!this.m_hovering) { if (this.on_free_space() && this.m_droppedLinkPopUp) { if (this.m_droppedLinkPupUpComboKey === 0 || ImGui.IsKeyDown(this.m_droppedLinkPupUpComboKey)) { this.m_droppedLinkLeft = this.m_dragOut; ImGui.OpenPopup('DroppedLinkPopUp'); } } } else { this.m_dragOut.createLink(this.m_hovering); } } // Handle links drag-out if (!this.m_draggingNode && this.m_hovering && !this.m_dragOut && ImGui.IsMouseClicked(ImGui.ImGuiMouseButton.Left)) { this.m_dragOut = this.m_hovering; } if (this.m_dragOut) { const dragOutPinPoint = this.m_dragOut.pinPoint(); dragOutPinPoint.x += windowPos.x; dragOutPinPoint.y += windowPos.y; if (this.m_dragOut.getType() === PinType.Output) { smart_bezier( dragOutPinPoint, new ImGui.ImVec2(ImGui.GetIO().MousePos.x, ImGui.GetIO().MousePos.y), this.m_dragOut.getStyle().color, this.m_dragOut.getStyle().extra.link_dragged_thickness ); } else { smart_bezier( new ImGui.ImVec2(ImGui.GetIO().MousePos.x, ImGui.GetIO().MousePos.y), dragOutPinPoint, this.m_dragOut.getStyle().color, this.m_dragOut.getStyle().extra.link_dragged_thickness ); } if (ImGui.IsMouseReleased(ImGui.ImGuiMouseButton.Left)) { this.m_dragOut = null; } } // Right-click PopUp if (this.m_rightClickPopUp && ImGui.IsMouseClicked(ImGui.ImGuiMouseButton.Right) && ImGui.IsWindowHovered()) { this.m_hoveredNodeAux = this.m_hoveredNode; ImGui.OpenPopup('RightClickPopUp'); } if (ImGui.BeginPopup('RightClickPopUp')) { if (this.m_hoveredNodeAux) { this.m_rightClickPopUp!(this.m_hoveredNodeAux); } ImGui.EndPopup(); } // Dropped Link PopUp if (ImGui.BeginPopup('DroppedLinkPopUp')) { if (this.m_droppedLinkPopUp && this.m_droppedLinkLeft) { this.m_droppedLinkPopUp(this.m_droppedLinkLeft); } ImGui.EndPopup(); } // Removing dead links this.m_links = this.m_links.filter(link => !link.isDestroyed()); // Clearing recursion blacklist this.m_pinRecursionBlacklist = []; // End ImGui context this.m_context.end(); }
/** * Handler loop * Main update function. Refreshes all the logic and draws everything. Must be called every frame. */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L310-L447
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.addNode
addNode<T extends BaseNode>(type: { new(m_inf: ImNodeFlow, ...args: any[]): T }, pos: ImGui.ImVec2, ...args: any[]): T { const node: T = new type(this, ...args); node.setPos(pos); node.setHandler(this); if (!node.getStyle()) { node.setStyle(NodeStyle.cyan()); } node.setUID(this.generateUID()); this.m_nodes.set(node.getUID(), node); return node; }
/** * Add a node to the grid * @param type Class constructor of the node * @param pos Position of the Node in grid coordinates * @param args Optional arguments to be forwarded to derived class ctor * @returns Instance of the newly added node */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L456-L469
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.placeNodeAt
placeNodeAt<T extends BaseNode>(type: { new(...args: any[]): T }, pos: ImGui.ImVec2, ...args: any[]): T { return this.addNode(type, this.screen2grid(pos), ...args); }
/** * Add a node to the grid at specific position */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L474-L476
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.placeNode
placeNode<T extends BaseNode>(type: { new(...args: any[]): T }, ...args: any[]): T { const mousePos = new ImGui.ImVec2(ImGui.GetIO().MousePos.x, ImGui.GetIO().MousePos.y); const nodePos = this.screen2grid(mousePos); return this.addNode(type, nodePos, ...args); }
/** * Add a node to the grid using mouse position */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L481-L486
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.addLink
addLink (link: Link): void { this.m_links.push(link); }
/** * Add link to the handler internal list * @param link Reference to the link */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L492-L494
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.droppedLinkPopUpContent
droppedLinkPopUpContent (content: (dragged: Pin) => void, key: ImGui.ImGuiKey = 0): void { this.m_droppedLinkPopUp = content; this.m_droppedLinkPupUpComboKey = key; }
/** * Pop-up when link is "dropped" * @param content Function containing the contents of the pop-up and subsequent logic * @param key Optional key required in order to open the pop-up */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L501-L504
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.rightClickPopUpContent
rightClickPopUpContent (content: (node: BaseNode) => void): void { this.m_rightClickPopUp = content; }
/** * Pop-up when right-clicking * @param content Function containing the contents of the pop-up and subsequent logic */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L510-L512
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.getSingleUseClick
getSingleUseClick (): boolean { return this.m_singleUseClick; }
/** * Get mouse clicking status * @returns TRUE if mouse is clicked and click hasn't been consumed */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L518-L520
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.consumeSingleUseClick
consumeSingleUseClick (): void { this.m_singleUseClick = false; }
/** * Consume the click for the given frame */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L525-L527
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.getName
getName (): string { return this.m_name; }
/** * Get editor's name * @returns Name of the editor */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L533-L535
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.getPos
getPos (): ImGui.ImVec2 { return this.m_context.origin(); }
/** * Get editor's position * @returns Position in screen coordinates */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L541-L543
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.getScroll
getScroll (): ImGui.ImVec2 { return this.m_context.scroll(); }
/** * Get editor's grid scroll * @returns Scroll offset from the origin of the grid */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L549-L551
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.getNodes
getNodes (): Map<NodeUID, BaseNode> { return this.m_nodes; }
/** * Get editor's list of nodes * @returns Internal nodes list */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L557-L559
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.getNodesCount
getNodesCount (): number { return this.m_nodes.size; }
/** * Get nodes count * @returns Number of nodes present in the editor */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L565-L567
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.getLinks
getLinks (): Link[] { return this.m_links; }
/** * Get editor's list of links * @returns Internal links list */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L573-L575
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.getGrid
getGrid (): ContainedContext { return this.m_context; }
/** * Get zooming viewport * @returns Internal viewport for zoom support */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L581-L583
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.isNodeDragged
isNodeDragged (): boolean { return this.m_draggingNode; }
/** * Get dragging status * @returns TRUE if a Node is being dragged around the grid */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L589-L591
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.getStyle
getStyle (): InfStyler { return this.m_style; }
/** * Get current style * @returns Style variables */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L597-L599
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.setSize
setSize (size: ImGui.ImVec2): void { this.m_context.config().size = size; }
/** * Set editor's size * @param size Editor's size. Set to (0, 0) to auto-fit. */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L605-L607
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.draggingNode
draggingNode (state: boolean): void { this.m_draggingNodeNext = state; }
/** * Set dragging status * @param state New dragging state */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L613-L615
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.hovering
hovering (hovering: Pin | null): void { this.m_hovering = hovering; }
/** * Set what pin is being hovered * @param hovering Pointer to the hovered pin */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L621-L623
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.hoveredNode
hoveredNode (hovering: BaseNode | null): void { this.m_hoveredNode = hovering; }
/** * Set what node is being hovered * @param hovering Pointer to the hovered node */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L629-L631
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.screen2grid
screen2grid (p: ImGui.ImVec2): ImGui.ImVec2 { const currentContext = ImGui.GetCurrentContext(); if (currentContext === this.m_context.getRawContext()) { return new ImGui.ImVec2(p.x - this.m_context.scroll().x, p.y - this.m_context.scroll().y); } else { return new ImGui.ImVec2( p.x - this.m_context.origin().x - this.m_context.scroll().x * this.m_context.scale(), p.y - this.m_context.origin().y - this.m_context.scroll().y * this.m_context.scale() ); } }
/** * Convert coordinates from screen to grid * @param p Point in screen coordinates to be converted * @returns Point in grid's coordinates */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L638-L649
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.grid2screen
grid2screen (p: ImGui.ImVec2): ImGui.ImVec2 { const currentContext = ImGui.GetCurrentContext(); if (currentContext === this.m_context.getRawContext()) { return new ImGui.ImVec2(p.x + this.m_context.scroll().x, p.y + this.m_context.scroll().y); } else { return new ImGui.ImVec2( p.x + this.m_context.origin().x + this.m_context.scroll().x * this.m_context.scale(), p.y + this.m_context.origin().y + this.m_context.scroll().y * this.m_context.scale() ); } }
/** * Convert coordinates from grid to screen * @param p Point in grid's coordinates to be converted * @returns Point in screen coordinates */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L656-L667
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.on_selected_node
on_selected_node (): boolean { for (const [uid, node] of this.m_nodes) { if (node.isSelected() && node.isHovered()) { return true; } } return false; }
/** * Check if mouse is on selected node * @returns TRUE if the mouse is hovering a selected node */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L673-L681
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.on_free_space
on_free_space (): boolean { for (const [uid, node] of this.m_nodes) { if (node.isHovered()) {return false;} } for (const link of this.m_links) { if (link.isHovered()) {return false;} } return true; }
/** * Check if mouse is on a free point on the grid * @returns TRUE if the mouse is not hovering a node or a link */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L687-L696
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.generateUID
private generateUID (): NodeUID { return ImNodeFlow.m_instances++; }
/** * Generate unique UID for nodes * @returns Unique NodeUID */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L702-L704
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
ImNodeFlow.hashString
private hashString (str: string): number { let hash = 0; for (let i = 0; i < str.length; i++) { const chr = str.charCodeAt(i); hash = ((hash << 5) - hash) + chr; hash |= 0; // Convert to 32bit integer } return Math.abs(hash); }
// Hash Function (Simplistic)
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/node-flow.ts#L708-L719
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
PinStyle.constructor
constructor ( color: number, socket_shape: number, socket_radius: number, socket_hovered_radius: number, socket_connected_radius: number, socket_thickness: number ) { this.color = color; this.socket_shape = socket_shape; this.socket_radius = socket_radius; this.socket_hovered_radius = socket_hovered_radius; this.socket_connected_radius = socket_connected_radius; this.socket_thickness = socket_thickness; this.extra = { padding: new ImGui.ImVec2(3.0, 1.0), bg_radius: 8.0, border_thickness: 1.0, bg_color: ImGui.IM_COL32(23, 16, 16, 0), bg_hover_color: ImGui.IM_COL32(100, 100, 255, 70), border_color: ImGui.IM_COL32(255, 255, 255, 0), link_thickness: 2.6, link_dragged_thickness: 2.2, link_hovered_thickness: 3.5, link_selected_outline_thickness: 4.0, outline_color: ImGui.IM_COL32(80, 20, 255, 200), socket_padding: 6.6, }; }
// List of less common properties
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L57-L87
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
PinStyle.cyan
static cyan (): PinStyle { return new PinStyle( ImGui.IM_COL32(87, 155, 185, 255), 0, 4.0, 4.67, 3.7, 1.0 ); }
// Static methods for default styles
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L90-L99
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
InPin.createLink
createLink (other: Pin): void { if (other.getType() !== PinType.Output) {return;} if (!this.m_allowSelfConnection && this.m_parent === other.getParent()) {return;} if (this.m_link && this.m_link.getLeft() === other) { return; } if (!this.m_filter(other, this)) {return;} this.m_link = new Link(other, this, this.m_inf); other.setLink(this.m_link); this.m_inf.addLink(this.m_link); }
/** * Create link between pins * @param other Pointer to the other pin */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L469-L482
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
InPin.deleteLink
deleteLink (): void { this.m_link?.destroy(); this.m_link = null; }
/** * Delete the link connected to the pin */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L487-L490
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
InPin.allowSameNodeConnections
allowSameNodeConnections (state: boolean): void { this.m_allowSelfConnection = state; }
/** * Specify if connections from an output on the same node are allowed * @param state New state of the flag */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L496-L498
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
InPin.isConnected
isConnected (): boolean { return this.m_link !== null; }
/** * Get connected status * @returns TRUE if pin is connected to a link */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L504-L506
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
InPin.getLink
getLink (): Link | null { return this.m_link; }
/** * Get pin's link * @returns Link connected to the pin */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L512-L514
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
InPin.getFilter
getFilter (): (out: Pin, input: Pin) => boolean { return this.m_filter; }
/** * Get InPin's connection filter * @returns InPin's connection filter configuration */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L520-L522
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
InPin.getDataType
getDataType (): string { return typeof this.m_emptyVal; }
/** * Get pin's data type (aka: <T>) * @returns String containing unique information identifying the data type */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L528-L530
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
InPin.pinPoint
pinPoint (): ImGui.ImVec2 { return new ImGui.ImVec2( this.m_pos.x - this.m_style.extra.socket_padding, this.m_pos.y + this.m_size.y / 2 ); }
/** * Get pin's link attachment point (socket) * @returns Grid coordinates to the attachment point between the link and the pin's socket */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L536-L541
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
InPin.val
val (): T { if (this.m_link) { const outPin = this.m_link.getLeft(); if (outPin instanceof OutPin) { return outPin.val(); } } return this.m_emptyVal; }
/** * Get value carried by the connected link * @returns Reference to the value of the connected OutPin. Or the default value if not connected */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L547-L557
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
OutPin.destroy
destroy (): void { this.m_links.forEach(link => { const otherPin = link.getRight(); otherPin.deleteLink(); }); this.m_links.length = 0; }
/** * When parent gets deleted, remove the links */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L582-L589
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
OutPin.createLink
createLink (other: Pin): void { if (other.getType() !== PinType.Input) {return;} other.createLink(this); }
/** * Create link between pins * @param other Pointer to the other pin */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L595-L599
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
OutPin.setLink
setLink (link: Link): void { this.m_links.push(link); }
/** * Add a connected link to the internal list * @param link Link to add */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L605-L607
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
OutPin.deleteLink
deleteLink (): void { this.m_links = this.m_links.filter(link => !link.isDestroyed()); }
/** * Delete any expired weak pointers to a (now deleted) link */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L616-L618
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
OutPin.isConnected
isConnected (): boolean { return this.m_links.length > 0; }
/** * Get connected status * @returns TRUE if pin is connected to one or more links */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L624-L626
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
OutPin.pinPoint
pinPoint (): ImGui.ImVec2 { return new ImGui.ImVec2( this.m_pos.x + this.m_size.x + this.m_style.extra.socket_padding, this.m_pos.y + this.m_size.y / 2 ); }
/** * Get pin's link attachment point (socket) * @returns Grid coordinates to the attachment point between the link and the pin's socket */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L632-L637
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
OutPin.val
val (): T { if (this.m_behaviour) { return this.m_behaviour(); } if (this.m_val !== null) { return this.m_val; } throw new Error('No value defined for this OutPin'); }
/** * Get output value * @returns Internal value of the pin */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L643-L651
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
OutPin.behaviour
behaviour (func: () => T): this { this.m_behaviour = func; return this; }
/** * Set logic to calculate output value * @param func Function or lambda expression used to calculate output value */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L657-L661
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
OutPin.getDataType
getDataType (): string { return typeof (this.m_val as any); }
/** * Get pin's data type (aka: <T>) * @returns String containing unique information identifying the data type */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L667-L669
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
OutPin.resolve
resolve (): void { if (this.m_behaviour) { this.m_val = this.m_behaviour(); } }
/** * Used by output pins to calculate their values */
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/imgui-demo/src/panels/node-graph/pin.ts#L674-L678
20512f4406e62c400b2b4255576cfa628db74a22
effects-runtime
github_2023
galacean
typescript
generateTexture
function generateTexture (engine: Engine) { const writePixelData = [255, 100, 50, 0]; const buffer = new Uint8Array([1, 2, ...writePixelData, 3, 4]); return Texture.createWithData(engine, { width: 1, height: 1, data: new Uint8Array(buffer.buffer, 2 * Uint8Array.BYTES_PER_ELEMENT, 4), }, { format: glContext.RGBA, type: glContext.UNSIGNED_BYTE, }); }
// function generateMeshAndUBO (
https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/web-packages/test/unit/src/effects-webgl/gl-material.spec.ts#L1671-L1681
20512f4406e62c400b2b4255576cfa628db74a22
reactjs-template
github_2023
Telegram-Mini-Apps
typescript
ErrorBoundary.getDerivedStateFromError
static getDerivedStateFromError: GetDerivedStateFromError<ErrorBoundaryProps, ErrorBoundaryState> = (error) => ({ error })
// eslint-disable-next-line max-len
https://github.com/Telegram-Mini-Apps/reactjs-template/blob/345709d1bb8350fe523ef2de05662716136b8196/src/components/ErrorBoundary.tsx
345709d1bb8350fe523ef2de05662716136b8196
cloudypad
github_2023
PierreBeucher
typescript
DataRootDirManager.getEnvironmentDataRootDir
static getEnvironmentDataRootDir(): string { if (process.env.CLOUDYPAD_HOME) { return process.env.CLOUDYPAD_HOME } else { if (!process.env.HOME){ throw new Error("Neither CLOUDYPAD_HOME nor HOME environment variable is set. Could not define Cloudy Pad data root directory.") } return path.resolve(`${ process.env.HOME}/.cloudypad`) } }
/** * Return current environments Cloudy Pad data root dir, by order of priority: * - $CLOUDYPAD_HOME environment variable * - $HOME/.cloudypad * - Fails is neither CLOUDYPAD_HOME nor HOME is set * * This function is used by all components with side effects in Cloudy Pad data root dir (aka Cloudy Pad Home) * and can be mocked during tests to control side effect */
https://github.com/PierreBeucher/cloudypad/blob/f476990dedf0a856b1a8ce7dc82d28382ca67f7c/src/core/data-dir.ts#L14-L24
f476990dedf0a856b1a8ce7dc82d28382ca67f7c
cloudypad
github_2023
PierreBeucher
typescript
InteractiveInstanceInitializer.initializeInstance
async initializeInstance(cliArgs: A, options?: InstancerInitializationOptions): Promise<void> { try { this.analyticsEvent("create_instance_start") this.logger.debug(`Initializing instance from CLI args ${JSON.stringify(cliArgs)} and options ${JSON.stringify(options)}`) const input = await this.cliArgsToInput(cliArgs) const state = await this.doInitializeState(input) const manager = await new InstanceManagerBuilder().buildInstanceManager(state.name) await this.doProvisioning(manager, state.name, cliArgs.yes) await this.doConfiguration(manager, state.name) await this.doPairing(manager, state.name, cliArgs.skipPairing ?? false, cliArgs.yes ?? false) this.showPostInitInfo(options) this.analyticsEvent("create_instance_finish") } catch (error) { if(error instanceof UserVoluntaryInterruptionError){ console.info("Instance initialization cancelled.") this.analyticsEvent("create_instance_user_voluntary_interruption") return } const errMsg = error instanceof Error ? error.message : String(error) this.analyticsEvent("create_instance_error", { errorMessage: errMsg }) throw new Error(`Instance initialization failed`, { cause: error }) } }
/** * Interactively initialize a new instance from CLI args: * - Parse CLI args into known Input interface * - Interactively prompt for missing args * - Run instance initialization */
https://github.com/PierreBeucher/cloudypad/blob/f476990dedf0a856b1a8ce7dc82d28382ca67f7c/src/core/initializer.ts#L45-L74
f476990dedf0a856b1a8ce7dc82d28382ca67f7c