Skip to content

Feature: Basic Text Tool for Canvas Annotation #4

Description

@josefdc

Description:
The application currently focuses on freehand drawing and geometric shapes. Adding a basic text tool would allow users to annotate their drawings, add titles, or incorporate textual elements into their artwork directly on the canvas.

Acceptance Criteria:

  • A new "Text Tool" (e.g., with an "T" icon or label) is added to the Controls panel.
  • When the Text Tool is selected:
    • Clicking on the canvas sets the starting position for the text.
    • The application enters a text input mode (similar to the AI prompt input, but rendering directly on the canvas or a temporary input box at the click position).
    • User can type text. Pressing Enter finalizes the text and renders it onto the main Canvas at the chosen position using the currently selected draw_color.
    • Pressing Escape during text input cancels the operation.
  • (Bonus) A small, predefined set of font sizes (e.g., Small, Medium, Large) can be selected, perhaps via additional UI elements or keyboard modifiers when the text tool is active. Default font is acceptable.
  • The text should be rendered onto the self.canvas.surface.

Possible Implementation Approach (Hints):

  • Add a new tool identifier (e.g., "text_tool") and button in Controls.
  • In Application._handle_events():
    • When the Text Tool is active and the user clicks on the canvas, store the click position (text_start_pos) and enter a new state (e.g., is_typing_on_canvas = True).
    • Capture pygame.KEYDOWN events to build the text string (similar to current_prompt_text).
    • In Application._render(), if is_typing_on_canvas, display the currently typed text at text_start_pos (or a small input box area).
    • When Enter is pressed:
      • Use pygame.font.Font to create a font object (e.g., self.ui_font_normal).
      • Render the text: text_surface = font.render(typed_text, True, self.draw_color).
      • Blit this text_surface onto self.canvas.surface at text_start_pos.
      • Exit is_typing_on_canvas state.
  • Consider how to handle multi-line text (e.g., Enter finalizes, or implement basic wrapping/newlines if feeling ambitious). For a first version, single-line text is fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions