Rendering fix in apps

This commit is contained in:
boreddevnl 2026-02-26 21:56:50 +01:00
parent fcc290f3f9
commit 34ceff4290
57 changed files with 112 additions and 136 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
disk.img

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,17 +0,0 @@
timeout: 3
/BoredOS
protocol: limine
kernel_path: boot():/boredos.elf
#resolution: 1280x720
module_path: boot():/bin/calculator.elf
module_path: boot():/bin/crash.elf
module_path: boot():/bin/hello.elf
module_path: boot():/bin/markdown.elf
module_path: boot():/bin/minesweeper.elf
module_path: boot():/bin/notepad.elf
module_path: boot():/bin/paint.elf
module_path: boot():/bin/settings.elf
module_path: boot():/bin/txtedit.elf
module_path: boot():/bin/viewer.elf

View file

@ -141,19 +141,19 @@ static void flag_cell(int x, int y) {
static void minesweeper_paint(ui_window_t win) { static void minesweeper_paint(ui_window_t win) {
int win_w = 240, win_h = 340; int win_w = 240, win_h = 340;
ui_draw_rect(win, 4, 0, win_w - 8, win_h - 34, COLOR_DARK_BG); ui_draw_rect(win, 4, 0, win_w - 8, win_h, COLOR_DARK_BG);
if (game_over) { if (game_over) {
ui_draw_string(win, 10, 6, "Game Over!", COLOR_TRAFFIC_RED); ui_draw_string(win, 10, 4, "Game Over!", COLOR_TRAFFIC_RED);
} else if (game_won) { } else if (game_won) {
ui_draw_string(win, 10, 6, "You Won!", 0xFF00FF00); // Bright green ui_draw_string(win, 10, 4, "You Won!", 0xFF00FF00); // Bright green
} else { } else {
ui_draw_string(win, 10, 6, "", COLOR_DARK_TEXT); ui_draw_string(win, 10, 4, "", COLOR_DARK_TEXT);
} }
// Draw grid // Draw grid
int grid_start_x = 10; int grid_start_x = 10;
int grid_start_y = 26; int grid_start_y = 22;
for (int y = 0; y < GRID_HEIGHT; y++) { for (int y = 0; y < GRID_HEIGHT; y++) {
for (int x = 0; x < GRID_WIDTH; x++) { for (int x = 0; x < GRID_WIDTH; x++) {
@ -191,7 +191,7 @@ static void minesweeper_paint(ui_window_t win) {
static void minesweeper_handle_click(ui_window_t win, int x, int y, int button) { static void minesweeper_handle_click(ui_window_t win, int x, int y, int button) {
int grid_start_x = 10; int grid_start_x = 10;
int grid_start_y = 26; int grid_start_y = 22;
int btn_y = grid_start_y + GRID_HEIGHT * CELL_SIZE + 10; int btn_y = grid_start_y + GRID_HEIGHT * CELL_SIZE + 10;
// Check "New Game" button // Check "New Game" button
@ -211,10 +211,8 @@ static void minesweeper_handle_click(ui_window_t win, int x, int y, int button)
int cell_y = (y - grid_start_y) / CELL_SIZE; int cell_y = (y - grid_start_y) / CELL_SIZE;
if (button == GUI_EVENT_RIGHT_CLICK) { if (button == GUI_EVENT_RIGHT_CLICK) {
debug_print("[MINESWEEPER] Flagging cell");
flag_cell(cell_x, cell_y); flag_cell(cell_x, cell_y);
} else { } else {
debug_print("[MINESWEEPER] Revealing cell");
reveal_cell(cell_x, cell_y); reveal_cell(cell_x, cell_y);
} }
} }
@ -236,12 +234,10 @@ int main(int argc, char **argv) {
minesweeper_paint(win); minesweeper_paint(win);
ui_mark_dirty(win, 0, 0, 240, 320); ui_mark_dirty(win, 0, 0, 240, 320);
} else if (ev.type == GUI_EVENT_CLICK) { } else if (ev.type == GUI_EVENT_CLICK) {
debug_print("[MINESWEEPER] LEFT CLICK");
minesweeper_handle_click(win, ev.arg1, ev.arg2, ev.type); minesweeper_handle_click(win, ev.arg1, ev.arg2, ev.type);
minesweeper_paint(win); minesweeper_paint(win);
ui_mark_dirty(win, 0, 0, 240, 320); ui_mark_dirty(win, 0, 0, 240, 320);
} else if (ev.type == GUI_EVENT_RIGHT_CLICK) { } else if (ev.type == GUI_EVENT_RIGHT_CLICK) {
debug_print("[MINESWEEPER] RIGHT CLICK DETECTED");
minesweeper_handle_click(win, ev.arg1, ev.arg2, ev.type); minesweeper_handle_click(win, ev.arg1, ev.arg2, ev.type);
minesweeper_paint(win); minesweeper_paint(win);
ui_mark_dirty(win, 0, 0, 240, 320); ui_mark_dirty(win, 0, 0, 240, 320);

Binary file not shown.

View file

@ -13,7 +13,7 @@ static int cursor_pos = 0;
static int notepad_scroll_line = 0; static int notepad_scroll_line = 0;
static void notepad_ensure_cursor_visible(int h) { static void notepad_ensure_cursor_visible(int h) {
int visible_lines = (h - 40) / 10 + 3; int visible_lines = (h - 10) / 10;
if (visible_lines < 1) visible_lines = 1; if (visible_lines < 1) visible_lines = 1;
int cursor_line = 0; int cursor_line = 0;
@ -53,23 +53,23 @@ static void notepad_save_state() {
} }
static void notepad_paint(ui_window_t win, int w, int h) { static void notepad_paint(ui_window_t win, int w, int h) {
ui_draw_rect(win, 4, 30, w - 8, h - 34, COLOR_NOTEPAD_BG); ui_draw_rect(win, 0, 0, w, h, COLOR_NOTEPAD_BG);
int visual_line = 0; int visual_line = 0;
int current_x = 8; int current_x = 4;
int current_y = 36; int current_y = 4;
int window_right = w - 16; int window_right = w - 8;
for (int i = 0; i < buf_len; i++) { for (int i = 0; i < buf_len; i++) {
if (visual_line < notepad_scroll_line) { if (visual_line < notepad_scroll_line) {
if (buffer[i] == '\n') { if (buffer[i] == '\n') {
visual_line++; visual_line++;
current_x = 8; current_x = 4;
current_y = 36; current_y = 4;
} else { } else {
if (current_x >= window_right) { if (current_x >= window_right) {
visual_line++; visual_line++;
current_x = 8; current_x = 4;
current_y += 10; current_y += 10;
} }
current_x += 8; current_x += 8;
@ -77,21 +77,21 @@ static void notepad_paint(ui_window_t win, int w, int h) {
continue; continue;
} }
if (visual_line >= notepad_scroll_line + (h - 40) / 10) { if (visual_line >= notepad_scroll_line + (h - 8) / 10) {
break; break;
} }
if (buffer[i] == '\n') { if (buffer[i] == '\n') {
current_x = 8; current_x = 4;
current_y += 10; current_y += 10;
visual_line++; visual_line++;
} else { } else {
if (current_x >= window_right) { if (current_x >= window_right) {
current_x = 8; current_x = 4;
current_y += 10; current_y += 10;
visual_line++; visual_line++;
if (visual_line >= notepad_scroll_line + (h - 40) / 10) { if (visual_line >= notepad_scroll_line + (h - 8) / 10) {
break; break;
} }
} }
@ -103,18 +103,18 @@ static void notepad_paint(ui_window_t win, int w, int h) {
} }
// Cursor // Cursor
int cx = 8; int cx = 4;
int cy = 36; int cy = 4;
int c_visual_line = 0; int c_visual_line = 0;
for (int i = 0; i < cursor_pos; i++) { for (int i = 0; i < cursor_pos; i++) {
if (buffer[i] == '\n') { if (buffer[i] == '\n') {
cx = 8; cx = 4;
cy += 10; cy += 10;
c_visual_line++; c_visual_line++;
} else { } else {
if (cx >= window_right) { if (cx >= window_right) {
cx = 8; cx = 4;
cy += 10; cy += 10;
c_visual_line++; c_visual_line++;
} }
@ -123,7 +123,7 @@ static void notepad_paint(ui_window_t win, int w, int h) {
} }
if (c_visual_line >= notepad_scroll_line && if (c_visual_line >= notepad_scroll_line &&
c_visual_line < notepad_scroll_line + (h - 40) / 10) { c_visual_line < notepad_scroll_line + (h - 8) / 10) {
ui_draw_rect(win, cx, cy, 2, 8, COLOR_BLACK); ui_draw_rect(win, cx, cy, 2, 8, COLOR_BLACK);
} }

Binary file not shown.

View file

@ -137,10 +137,10 @@ static uint32_t parse_rgb_separate(const char *r, const char *g, const char *b)
static void control_panel_paint_main(ui_window_t win) { static void control_panel_paint_main(ui_window_t win) {
int offset_x = 8; int offset_x = 8;
int offset_y = 21; int offset_y = 6;
int win_w = 350; int win_w = 350;
int item_y = 15; int item_y = 0;
int item_h = 60; int item_h = 60;
int item_spacing = 10; int item_spacing = 10;
@ -180,7 +180,7 @@ static void control_panel_paint_main(ui_window_t win) {
static void control_panel_paint_wallpaper(ui_window_t win) { static void control_panel_paint_wallpaper(ui_window_t win) {
int offset_x = 8; int offset_x = 8;
int offset_y = 21; int offset_y = 6;
ui_draw_rounded_rect_filled(win, offset_x, offset_y + 5, 80, 25, 6, COLOR_DARK_PANEL); ui_draw_rounded_rect_filled(win, offset_x, offset_y + 5, 80, 25, 6, COLOR_DARK_PANEL);
ui_draw_string(win, offset_x + 10, offset_y + 13, "< Back", COLOR_DARK_TEXT); ui_draw_string(win, offset_x + 10, offset_y + 13, "< Back", COLOR_DARK_TEXT);
@ -311,7 +311,7 @@ static void control_panel_paint_wallpaper(ui_window_t win) {
static void control_panel_paint_network(ui_window_t win) { static void control_panel_paint_network(ui_window_t win) {
int offset_x = 8; int offset_x = 8;
int offset_y = 21; int offset_y = 6;
ui_draw_rounded_rect_filled(win, offset_x, offset_y + 5, 80, 25, 6, COLOR_DARK_PANEL); ui_draw_rounded_rect_filled(win, offset_x, offset_y + 5, 80, 25, 6, COLOR_DARK_PANEL);
ui_draw_string(win, offset_x + 10, offset_y + 13, "< Back", COLOR_DARK_TEXT); ui_draw_string(win, offset_x + 10, offset_y + 13, "< Back", COLOR_DARK_TEXT);
@ -327,7 +327,7 @@ static void control_panel_paint_network(ui_window_t win) {
static void control_panel_paint_desktop(ui_window_t win) { static void control_panel_paint_desktop(ui_window_t win) {
int offset_x = 8; int offset_x = 8;
int offset_y = 21; int offset_y = 6;
ui_draw_rounded_rect_filled(win, offset_x, offset_y + 5, 80, 25, 6, COLOR_DARK_PANEL); ui_draw_rounded_rect_filled(win, offset_x, offset_y + 5, 80, 25, 6, COLOR_DARK_PANEL);
ui_draw_string(win, offset_x + 10, offset_y + 13, "< Back", COLOR_DARK_TEXT); ui_draw_string(win, offset_x + 10, offset_y + 13, "< Back", COLOR_DARK_TEXT);
@ -371,7 +371,7 @@ static void control_panel_paint_desktop(ui_window_t win) {
static void control_panel_paint_mouse(ui_window_t win) { static void control_panel_paint_mouse(ui_window_t win) {
int offset_x = 8; int offset_x = 8;
int offset_y = 21; int offset_y = 6;
ui_draw_rounded_rect_filled(win, offset_x, offset_y + 5, 80, 25, 6, COLOR_DARK_PANEL); ui_draw_rounded_rect_filled(win, offset_x, offset_y + 5, 80, 25, 6, COLOR_DARK_PANEL);
ui_draw_string(win, offset_x + 10, offset_y + 13, "< Back", COLOR_DARK_TEXT); ui_draw_string(win, offset_x + 10, offset_y + 13, "< Back", COLOR_DARK_TEXT);
@ -393,7 +393,7 @@ static void control_panel_paint_mouse(ui_window_t win) {
static void control_panel_paint(ui_window_t win) { static void control_panel_paint(ui_window_t win) {
// Fill background // Fill background
ui_draw_rect(win, 0, 20, 350, 480, COLOR_DARK_BG); ui_draw_rect(win, 0, 0, 350, 500, COLOR_DARK_BG);
if (current_view == VIEW_MAIN) { if (current_view == VIEW_MAIN) {
control_panel_paint_main(win); control_panel_paint_main(win);
@ -439,11 +439,11 @@ static void control_panel_handle_click(int x, int y) {
if (current_view == VIEW_MAIN) { if (current_view == VIEW_MAIN) {
int offset_x = 8; int offset_x = 8;
int offset_y = 21; int offset_y = 6;
int item_h = 60; int item_h = 60;
int item_spacing = 10; int item_spacing = 10;
int item_y = offset_y + 15; int item_y = offset_y + 0;
if (x >= offset_x && x < win_w - 8 && y >= item_y && y < item_y + item_h) { if (x >= offset_x && x < win_w - 8 && y >= item_y && y < item_y + item_h) {
current_view = VIEW_WALLPAPER; current_view = VIEW_WALLPAPER;
focused_field = -1; focused_field = -1;
@ -463,7 +463,7 @@ static void control_panel_handle_click(int x, int y) {
} }
} else if (current_view == VIEW_WALLPAPER) { } else if (current_view == VIEW_WALLPAPER) {
int offset_x = 8; int offset_x = 8;
int offset_y = 21; int offset_y = 6;
int button_y = offset_y + 65; int button_y = offset_y + 65;
int button_x = offset_x; int button_x = offset_x;
@ -541,7 +541,7 @@ static void control_panel_handle_click(int x, int y) {
} }
} else if (current_view == VIEW_NETWORK) { } else if (current_view == VIEW_NETWORK) {
int offset_x = 8; int offset_x = 8;
int offset_y = 21; int offset_y = 6;
if (x >= offset_x && x < offset_x + 80 && y >= offset_y + 5 && y < offset_y + 30) { if (x >= offset_x && x < offset_x + 80 && y >= offset_y + 5 && y < offset_y + 30) {
current_view = VIEW_MAIN; current_view = VIEW_MAIN;
@ -560,7 +560,7 @@ static void control_panel_handle_click(int x, int y) {
} }
} else if (current_view == VIEW_DESKTOP) { } else if (current_view == VIEW_DESKTOP) {
int offset_x = 8; int offset_x = 8;
int offset_y = 21; int offset_y = 6;
if (x >= offset_x && x < offset_x + 80 && y >= offset_y + 5 && y < offset_y + 30) { if (x >= offset_x && x < offset_x + 80 && y >= offset_y + 5 && y < offset_y + 30) {
current_view = VIEW_MAIN; current_view = VIEW_MAIN;
@ -608,7 +608,7 @@ static void control_panel_handle_click(int x, int y) {
} }
} else if (current_view == VIEW_MOUSE) { } else if (current_view == VIEW_MOUSE) {
int offset_x = 8; int offset_x = 8;
int offset_y = 21; int offset_y = 6;
if (x >= offset_x && x < offset_x + 80 && y >= offset_y + 5 && y < offset_y + 30) { if (x >= offset_x && x < offset_x + 80 && y >= offset_y + 5 && y < offset_y + 30) {
current_view = VIEW_MAIN; current_view = VIEW_MAIN;

Binary file not shown.

View file

@ -52,7 +52,11 @@ static void editor_clear_all(void) {
} }
static void editor_ensure_cursor_visible(void) { static void editor_ensure_cursor_visible(void) {
int visible_lines = 22; int header_h = 32;
int footer_h = 24;
int editor_h = win_h - header_h - footer_h;
int visible_lines = (editor_h - 10) / EDITOR_LINE_HEIGHT;
if (cursor_line < scroll_top) { if (cursor_line < scroll_top) {
scroll_top = cursor_line; scroll_top = cursor_line;
} }
@ -196,43 +200,48 @@ static void editor_insert_char(char ch) {
} }
static void editor_paint(ui_window_t win) { static void editor_paint(ui_window_t win) {
int offset_x = 4; int header_h = 32;
int offset_y = 0; int footer_h = 24;
int content_width = win_w - 8; int padding = 4;
int content_height = win_h - 28;
// Top content bar int content_width = win_w - (padding * 2);
ui_draw_rounded_rect_filled(win, offset_x, offset_y, content_width, 25, 6, COLOR_DARK_PANEL); int editor_y = header_h;
ui_draw_string(win, offset_x + 10, offset_y + 6, "File", COLOR_DARK_TEXT); int editor_h = win_h - header_h - footer_h;
ui_draw_string(win, offset_x + 55, offset_y + 6, open_filename, COLOR_DARK_TEXT);
// Header bar
ui_draw_rounded_rect_filled(win, padding, 2, content_width, header_h - 4, 6, COLOR_DARK_PANEL);
ui_draw_string(win, padding + 10, 8, "File", COLOR_DARK_TEXT);
ui_draw_string(win, padding + 60, 8, open_filename, COLOR_DARK_TEXT);
// Save button // Save button
int save_btn_x = offset_x + content_width - 80; int save_btn_w = 70;
int save_btn_y = offset_y + 3; int save_btn_h = 22;
ui_draw_rounded_rect_filled(win, save_btn_x, save_btn_y, 70, 20, 6, COLOR_DARK_BORDER); int save_btn_x = padding + content_width - save_btn_w - 5;
ui_draw_string(win, save_btn_x + 20, save_btn_y + 6, "Save", COLOR_DARK_TEXT); int save_btn_y = 3;
ui_draw_rounded_rect_filled(win, save_btn_x, save_btn_y, save_btn_w, save_btn_h, 6, COLOR_DARK_BORDER);
ui_draw_string(win, save_btn_x + 18, save_btn_y + 4, "Save", COLOR_DARK_TEXT);
if (file_modified) { if (file_modified) {
ui_draw_string(win, offset_x + content_width - 200, offset_y + 5, "[Modified]", COLOR_RED); ui_draw_string(win, padding + content_width - 180, 8, "[Modified]", COLOR_RED);
} }
// Editor background // Editor background
ui_draw_rect(win, 4, 54, win_w - 8, win_h - 58, COLOR_DARK_BG); ui_draw_rect(win, padding, editor_y, content_width, editor_h, COLOR_DARK_BG);
int text_start_x = offset_x + 40; int text_start_x = padding + 40;
int available_width = content_width - 40; int available_width = content_width - 40;
int max_chars_per_line = available_width / EDITOR_CHAR_WIDTH; int max_chars_per_line = available_width / EDITOR_CHAR_WIDTH;
if (max_chars_per_line < 1) max_chars_per_line = 1; if (max_chars_per_line < 1) max_chars_per_line = 1;
int display_line = 0; int visible_lines = (editor_h - 10) / EDITOR_LINE_HEIGHT;
int visible_lines = (content_height - 55) / EDITOR_LINE_HEIGHT;
int max_display_lines = visible_lines; int max_display_lines = visible_lines;
int display_line = 0;
int line_idx = scroll_top; int line_idx = scroll_top;
while (line_idx < line_count && display_line < max_display_lines) { while (line_idx < line_count && display_line < max_display_lines) {
int display_y = offset_y + 35 + display_line * EDITOR_LINE_HEIGHT; int display_y = editor_y + 5 + display_line * EDITOR_LINE_HEIGHT;
if (display_line == 0 || line_idx < line_count) { // Line number
char line_num_str[16]; char line_num_str[16];
int temp = line_idx + 1; int temp = line_idx + 1;
int str_len = 0; int str_len = 0;
@ -251,18 +260,16 @@ static void editor_paint(ui_window_t win) {
} }
} }
line_num_str[str_len] = 0; line_num_str[str_len] = 0;
ui_draw_string(win, offset_x + 4, display_y, line_num_str, COLOR_DKGRAY); ui_draw_string(win, padding + 4, display_y, line_num_str, COLOR_DKGRAY);
}
const char *text = lines[line_idx].content; const char *text = lines[line_idx].content;
int text_len = lines[line_idx].length; int text_len = lines[line_idx].length;
int char_idx = 0; int char_idx = 0;
int local_display_line = 0;
_Bool first_pass = 1; _Bool first_pass = 1;
while ((char_idx < text_len || (text_len == 0 && first_pass)) && display_line < max_display_lines) { while ((char_idx < text_len || (text_len == 0 && first_pass)) && display_line < max_display_lines) {
first_pass = 0; first_pass = 0;
int current_display_y = offset_y + 35 + display_line * EDITOR_LINE_HEIGHT; int current_display_y = editor_y + 5 + display_line * EDITOR_LINE_HEIGHT;
char segment[256]; char segment[256];
int segment_len = 0; int segment_len = 0;
@ -273,6 +280,7 @@ static void editor_paint(ui_window_t win) {
} }
segment[segment_len] = 0; segment[segment_len] = 0;
// Basic word wrap
if (char_idx < text_len && segment_len > 0) { if (char_idx < text_len && segment_len > 0) {
int last_space = -1; int last_space = -1;
for (int i = segment_len - 1; i >= 0; i--) { for (int i = segment_len - 1; i >= 0; i--) {
@ -285,9 +293,6 @@ static void editor_paint(ui_window_t win) {
segment_len = last_space; segment_len = last_space;
segment[segment_len] = 0; segment[segment_len] = 0;
char_idx = segment_start + last_space + 1; char_idx = segment_start + last_space + 1;
while (char_idx < text_len && text[char_idx] == ' ') {
char_idx++;
}
} }
} }
@ -310,48 +315,38 @@ static void editor_paint(ui_window_t win) {
} }
display_line++; display_line++;
local_display_line++;
if (char_idx >= text_len) break; if (char_idx >= text_len) break;
} }
line_idx++; line_idx++;
} }
int status_y = offset_y + content_height - 20; // Status bar
ui_draw_rounded_rect_filled(win, offset_x, status_y, content_width, 20, 6, COLOR_DARK_PANEL); int status_y = win_h - footer_h;
ui_draw_string(win, offset_x + 10, status_y + 5, "Line: ", COLOR_DARK_TEXT); ui_draw_rounded_rect_filled(win, padding, status_y + 2, content_width, footer_h - 4, 6, COLOR_DARK_PANEL);
char status_text[128];
// Simple manual sprintf-like functionality for BoredOS userspace
// We'll just draw parts for now as before but cleaned up
ui_draw_string(win, padding + 15, status_y + 5, "Line:", COLOR_DKGRAY);
char line_str[32]; char line_str[32];
int temp = cursor_line + 1; int temp = cursor_line + 1;
int idx = 0; int idx = 0;
while (temp > 0) { while (temp > 0) { line_str[idx++] = (temp % 10) + '0'; temp /= 10; }
line_str[idx++] = (temp % 10) + '0'; if (idx == 0) line_str[idx++] = '0';
temp /= 10; for (int j = 0; j < idx / 2; j++) { char t = line_str[j]; line_str[j] = line_str[idx - 1 - j]; line_str[idx - 1 - j] = t; }
}
for (int j = 0; j < idx / 2; j++) {
char t = line_str[j];
line_str[j] = line_str[idx - 1 - j];
line_str[idx - 1 - j] = t;
}
line_str[idx] = 0; line_str[idx] = 0;
ui_draw_string(win, padding + 65, status_y + 5, line_str, COLOR_DARK_TEXT);
ui_draw_string(win, offset_x + 60, status_y + 5, line_str, COLOR_DARK_TEXT); ui_draw_string(win, padding + 120, status_y + 5, "Col:", COLOR_DKGRAY);
ui_draw_string(win, offset_x + 100, status_y + 5, " Col: ", COLOR_DARK_TEXT);
char col_str[32]; char col_str[32];
temp = cursor_col + 1; temp = cursor_col + 1;
idx = 0; idx = 0;
while (temp > 0) { while (temp > 0) { col_str[idx++] = (temp % 10) + '0'; temp /= 10; }
col_str[idx++] = (temp % 10) + '0'; if (idx == 0) col_str[idx++] = '0';
temp /= 10; for (int j = 0; j < idx / 2; j++) { char t = col_str[j]; col_str[j] = col_str[idx - 1 - j]; col_str[idx - 1 - j] = t; }
}
for (int j = 0; j < idx / 2; j++) {
char t = col_str[j];
col_str[j] = col_str[idx - 1 - j];
col_str[idx - 1 - j] = t;
}
col_str[idx] = 0; col_str[idx] = 0;
ui_draw_string(win, padding + 160, status_y + 5, col_str, COLOR_DARK_TEXT);
ui_draw_string(win, offset_x + 170, status_y + 5, col_str, COLOR_DARK_TEXT);
} }
static void editor_handle_key(char c) { static void editor_handle_key(char c) {
@ -365,8 +360,7 @@ static void editor_handle_key(char c) {
if (cursor_line < line_count - 1) { if (cursor_line < line_count - 1) {
cursor_line++; cursor_line++;
if (cursor_col > lines[cursor_line].length) cursor_col = lines[cursor_line].length; if (cursor_col > lines[cursor_line].length) cursor_col = lines[cursor_line].length;
int visible_lines = 20; editor_ensure_cursor_visible();
if (cursor_line >= scroll_top + visible_lines) scroll_top = cursor_line - visible_lines + 1;
} }
} else if (c == 19) { // LEFT } else if (c == 19) { // LEFT
if (cursor_col > 0) { if (cursor_col > 0) {
@ -388,11 +382,14 @@ static void editor_handle_key(char c) {
} }
static void editor_handle_click(int x, int y) { static void editor_handle_click(int x, int y) {
int content_width = win_w - 8; int padding = 4;
int button_x = 4 + content_width - 80; int content_width = win_w - (padding * 2);
int button_y = 3; int save_btn_w = 70;
int save_btn_x = padding + content_width - save_btn_w - 5;
int save_btn_y = 3;
int save_btn_h = 22;
if (x >= button_x && x < button_x + 70 && y >= button_y && y < button_y + 20) { if (x >= save_btn_x && x < save_btn_x + save_btn_w && y >= save_btn_y && y < save_btn_y + save_btn_h) {
editor_save_file(); editor_save_file();
} }
} }
@ -413,15 +410,15 @@ int main(int argc, char **argv) {
if (ui_get_event(win, &ev)) { if (ui_get_event(win, &ev)) {
if (ev.type == GUI_EVENT_PAINT) { if (ev.type == GUI_EVENT_PAINT) {
editor_paint(win); editor_paint(win);
ui_mark_dirty(win, 0, 0, win_w, win_h - 20); ui_mark_dirty(win, 0, 0, win_w, win_h);
} else if (ev.type == GUI_EVENT_CLICK) { } else if (ev.type == GUI_EVENT_CLICK) {
editor_handle_click(ev.arg1, ev.arg2); editor_handle_click(ev.arg1, ev.arg2);
editor_paint(win); editor_paint(win);
ui_mark_dirty(win, 0, 0, win_w, win_h - 20); ui_mark_dirty(win, 0, 0, win_w, win_h);
} else if (ev.type == GUI_EVENT_KEY) { } else if (ev.type == GUI_EVENT_KEY) {
editor_handle_key((char)ev.arg1); editor_handle_key((char)ev.arg1);
editor_paint(win); editor_paint(win);
ui_mark_dirty(win, 0, 0, win_w, win_h - 20); ui_mark_dirty(win, 0, 0, win_w, win_h);
} else if (ev.type == GUI_EVENT_CLOSE) { } else if (ev.type == GUI_EVENT_CLOSE) {
sys_exit(0); sys_exit(0);
} }

Binary file not shown.