Skip to content

Commit 0067350

Browse files
committed
v0.2.67: Fix native status bar sections and resize
1 parent 3ce48f4 commit 0067350

3 files changed

Lines changed: 43 additions & 30 deletions

File tree

imgui.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[Window][Editor]
22
Pos=0,0
3-
Size=1196,668
3+
Size=1124,613
44
Collapsed=0
55

66
[Window][DockSpace]
77
Size=1280,800
88
Collapsed=0
99

1010
[Window][Debug##Default]
11-
Pos=117,246
11+
Pos=117,84
1212
Size=1280,800
1313
Collapsed=1
1414

pcode-settings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"window_w": 1196,
3-
"window_h": 668,
2+
"window_w": 1124,
3+
"window_h": 613,
44
"dark_theme": true,
55
"show_status_bar": true,
66
"word_wrap": true,
@@ -13,5 +13,5 @@
1313
"font_size": 18,
1414
"font_name": "",
1515
"last_open_dir": "C:\\Users\\casse\\github\\pcode-editor\\src",
16-
"recent_files": ["C:\\Users\\casse\\github\\pcode-editor\\src\\main.cpp", ".\\BUILD_SYSTEM.md", "C:\\Users\\casse\\github\\pcode-editor\\src\\editor_app.cpp", "C:\\Users\\casse\\github\\pcode-editor\\src\\editor_app.h"]
16+
"recent_files": ["C:\\Users\\casse\\github\\pcode-editor\\src\\editor_app.h", "C:\\Users\\casse\\github\\pcode-editor\\src\\main.cpp", ".\\BUILD_SYSTEM.md", "C:\\Users\\casse\\github\\pcode-editor\\src\\editor_app.cpp"]
1717
}

src/editor_app.cpp

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -329,31 +329,22 @@ void EditorApp::create_native_status_bar() {
329329
HWND hwnd = glfwGetWin32Window(window_);
330330
if (!hwnd) return;
331331

332-
// Create status bar with parts
332+
// Create status bar - let it auto-position at bottom
333333
HWND status_hwnd = CreateWindowEx(
334334
0,
335335
STATUSCLASSNAME,
336336
"",
337337
WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
338-
0, 0, 0, 0,
338+
0, 0, 0, 0, // Position/size - let Windows handle this
339339
hwnd,
340340
(HMENU)1,
341341
GetModuleHandle(NULL),
342342
NULL
343343
);
344344
native_status_bar = (void*)status_hwnd;
345345

346-
// Initialize with 6 parts
347-
int parts[6] = {80, 250, 350, 420, 480, -1};
348-
SendMessage(status_hwnd, SB_SETPARTS, 6, (LPARAM)parts);
349-
350-
// Set initial text
351-
SendMessage(status_hwnd, SB_SETTEXT, 0, (LPARAM)L"NORMAL");
352-
SendMessage(status_hwnd, SB_SETTEXT, 1, (LPARAM)L"");
353-
SendMessage(status_hwnd, SB_SETTEXT, 2, (LPARAM)L"Ln 1, Col 1");
354-
SendMessage(status_hwnd, SB_SETTEXT, 3, (LPARAM)L"UTF-8");
355-
SendMessage(status_hwnd, SB_SETTEXT, 4, (LPARAM)L"LF");
356-
SendMessage(status_hwnd, SB_SETTEXT, 5, (LPARAM)L"Tab:4");
346+
// Show the window to initialize
347+
ShowWindow(status_hwnd, SW_SHOW);
357348
#endif
358349
}
359350

@@ -363,10 +354,25 @@ void EditorApp::update_native_status_bar() {
363354

364355
HWND status_hwnd = (HWND)native_status_bar;
365356

357+
// Get window dimensions for dynamic sizing
358+
int width, height;
359+
glfwGetWindowSize(window_, &width, &height);
360+
361+
// Calculate part widths dynamically
362+
int p1 = 80; // Mode
363+
int p2 = width / 4; // Filename
364+
int p3 = width / 4 + 80; // Line/Col
365+
int p4 = width / 2; // Encoding
366+
int p5 = width * 3 / 4; // EOL
367+
// Part 6 fills the rest
368+
369+
int parts[6] = {p1, p2, p3, p4, p5, -1};
370+
SendMessage(status_hwnd, SB_SETPARTS, 6, (LPARAM)parts);
371+
366372
// Get vim mode
367373
std::string vim_mode = get_vim_mode_str();
368-
wchar_t mode_buf[32];
369-
mbstowcs(mode_buf, vim_mode.c_str(), 32);
374+
wchar_t mode_buf[32] = L"";
375+
mbstowcs(mode_buf, vim_mode.c_str(), 31);
370376
SendMessage(status_hwnd, SB_SETTEXT, 0, (LPARAM)mode_buf);
371377

372378
// Get filename
@@ -375,33 +381,40 @@ void EditorApp::update_native_status_bar() {
375381
std::string name = tab.display_name;
376382
if (tab.dirty) name += " *";
377383

378-
wchar_t file_buf[256];
379-
mbstowcs(file_buf, name.c_str(), 256);
384+
wchar_t file_buf[256] = L"";
385+
mbstowcs(file_buf, name.c_str(), 255);
380386
SendMessage(status_hwnd, SB_SETTEXT, 1, (LPARAM)file_buf);
381387

382388
// Get cursor position
383389
TextEditor* ed = get_active_editor();
384390
if (ed) {
385391
auto pos = ed->GetCursorPosition();
386-
wchar_t pos_buf[64];
387-
swprintf(pos_buf, 64, L"Ln %d, Col %d", pos.mLine + 1, pos.mColumn + 1);
392+
wchar_t pos_buf[64] = L"";
393+
swprintf(pos_buf, 63, L"Ln %d, Col %d", pos.mLine + 1, pos.mColumn + 1);
388394
SendMessage(status_hwnd, SB_SETTEXT, 2, (LPARAM)pos_buf);
389395
}
390396

391397
// Encoding
392-
wchar_t enc_buf[32];
393-
mbstowcs(enc_buf, tab.file_encoding.c_str(), 32);
398+
wchar_t enc_buf[32] = L"";
399+
mbstowcs(enc_buf, tab.file_encoding.c_str(), 31);
394400
SendMessage(status_hwnd, SB_SETTEXT, 3, (LPARAM)enc_buf);
395401

396402
// Line ending
397-
wchar_t eol_buf[16];
398-
mbstowcs(eol_buf, tab.line_ending.c_str(), 16);
403+
wchar_t eol_buf[16] = L"";
404+
mbstowcs(eol_buf, tab.line_ending.c_str(), 15);
399405
SendMessage(status_hwnd, SB_SETTEXT, 4, (LPARAM)eol_buf);
400406

401407
// Tab size
402-
wchar_t tab_buf[32];
403-
swprintf(tab_buf, 32, L"Tab:%d", settings_.tab_size);
408+
wchar_t tab_buf[32] = L"";
409+
swprintf(tab_buf, 31, L"Tab:%d", settings_.tab_size);
404410
SendMessage(status_hwnd, SB_SETTEXT, 5, (LPARAM)tab_buf);
411+
} else {
412+
// No file - clear sections
413+
SendMessage(status_hwnd, SB_SETTEXT, 1, (LPARAM)L"");
414+
SendMessage(status_hwnd, SB_SETTEXT, 2, (LPARAM)L"");
415+
SendMessage(status_hwnd, SB_SETTEXT, 3, (LPARAM)L"");
416+
SendMessage(status_hwnd, SB_SETTEXT, 4, (LPARAM)L"");
417+
SendMessage(status_hwnd, SB_SETTEXT, 5, (LPARAM)L"");
405418
}
406419
#endif
407420
}

0 commit comments

Comments
 (0)