feat: add A4 page option to Word Processor
This commit is contained in:
@@ -159,8 +159,13 @@ static void wp_insert_divider_choice(WordProcessorState* wp, uint8_t divider_typ
|
||||
wp_history_checkpoint(wp);
|
||||
}
|
||||
|
||||
static int wp_hit_test_text(WordProcessorState* wp, int local_x, int local_y, int edit_y) {
|
||||
static int wp_hit_test_text(WordProcessorState* wp, int local_x, int local_y, int edit_y,
|
||||
int page_off_x, int page_off_y) {
|
||||
int click_y = local_y - edit_y + wp->scrollbar.scroll_offset;
|
||||
// In page view mode, subtract the page y offset
|
||||
if (wp->page_view_mode) {
|
||||
click_y = local_y - page_off_y + wp->scrollbar.scroll_offset;
|
||||
}
|
||||
|
||||
int target_line = wp->wrap_line_count - 1;
|
||||
for (int i = 0; i < wp->wrap_line_count; i++) {
|
||||
@@ -175,7 +180,12 @@ static int wp_hit_test_text(WordProcessorState* wp, int local_x, int local_y, in
|
||||
if (wl->divider_type != PARA_DIVIDER_NONE)
|
||||
return wp_wrap_line_start(wp, target_line);
|
||||
|
||||
int click_x = local_x - wl->x;
|
||||
// In page view mode, subtract the page x offset from click x
|
||||
int click_x = local_x;
|
||||
if (wp->page_view_mode) {
|
||||
click_x = local_x - page_off_x;
|
||||
}
|
||||
click_x -= wl->x;
|
||||
int ri = wl->run_idx;
|
||||
int ro = wl->run_offset;
|
||||
int chars_left = wl->char_count;
|
||||
@@ -226,6 +236,25 @@ void wp_handle_mouse(const Montauk::WinEvent& ev) {
|
||||
int edit_y = WP_TOOLBAR_H + (wp->show_pathbar ? WP_PATHBAR_H : 0);
|
||||
int text_area_h = g_win_h - edit_y - WP_STATUS_H;
|
||||
|
||||
// Handle pending page view toggle first (from toolbar button click)
|
||||
if (wp->pending_page_view_toggle) {
|
||||
wp->page_view_mode = !wp->page_view_mode;
|
||||
wp->pending_page_view_toggle = false;
|
||||
wp->wrap_dirty = true;
|
||||
}
|
||||
|
||||
// Compute page offsets for hit testing (same logic as wp_render)
|
||||
int page_off_x = 0;
|
||||
int page_off_y = edit_y;
|
||||
int recompute_w = g_win_w;
|
||||
if (wp->page_view_mode) {
|
||||
page_off_x = (g_win_w - WP_A4_PAGE_W) / 2;
|
||||
if (page_off_x < 0) page_off_x = 0;
|
||||
page_off_y = edit_y + WP_PAGE_TOP_MARGIN;
|
||||
// Use A4 page width for wrap computation (to get proper margins)
|
||||
recompute_w = WP_A4_PAGE_W;
|
||||
}
|
||||
|
||||
wp->scrollbar.handle_mouse(local_x, local_y, ev.mouse.buttons, ev.mouse.prev_buttons, ev.mouse.scroll);
|
||||
|
||||
if (wp->font_dropdown_open && wp_left_pressed(ev.mouse.buttons, ev.mouse.prev_buttons)) {
|
||||
@@ -413,6 +442,11 @@ void wp_handle_mouse(const Montauk::WinEvent& ev) {
|
||||
wp->special_char_flyout_open = open;
|
||||
return;
|
||||
}
|
||||
if (local_x >= WP_BTN_PAGEVIEW_X && local_x < WP_BTN_PAGEVIEW_X + 24 && local_y >= 6 && local_y < 30) {
|
||||
wp_close_dropdowns(wp);
|
||||
wp->pending_page_view_toggle = true;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -428,13 +462,13 @@ void wp_handle_mouse(const Montauk::WinEvent& ev) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_recompute_wrap(wp, g_win_w, WP_SCREEN_DPI);
|
||||
wp_recompute_wrap(wp, recompute_w, WP_SCREEN_DPI);
|
||||
|
||||
if (wp_left_pressed(ev.mouse.buttons, ev.mouse.prev_buttons) &&
|
||||
local_y >= edit_y && local_y < edit_y + text_area_h) {
|
||||
wp_close_dropdowns(wp);
|
||||
|
||||
int abs = wp_hit_test_text(wp, local_x, local_y, edit_y);
|
||||
int abs = wp_hit_test_text(wp, local_x, local_y, edit_y, page_off_x, page_off_y);
|
||||
wp_pos_to_run(wp, abs, &wp->cursor_run, &wp->cursor_offset);
|
||||
wp->sel_anchor = abs;
|
||||
wp->sel_end = abs;
|
||||
@@ -444,7 +478,7 @@ void wp_handle_mouse(const Montauk::WinEvent& ev) {
|
||||
}
|
||||
|
||||
if (wp->mouse_selecting && wp_left_held(ev.mouse.buttons) && local_y >= edit_y - 20) {
|
||||
int abs = wp_hit_test_text(wp, local_x, local_y, edit_y);
|
||||
int abs = wp_hit_test_text(wp, local_x, local_y, edit_y, page_off_x, page_off_y);
|
||||
wp->sel_end = abs;
|
||||
wp_pos_to_run(wp, abs, &wp->cursor_run, &wp->cursor_offset);
|
||||
wp->has_selection = (wp->sel_anchor != wp->sel_end);
|
||||
|
||||
Reference in New Issue
Block a user