mirror of
https://github.com/1j01/textual-paint.git
synced 2024-09-11 23:57:12 +03:00
DRY textbox color updating
This commit is contained in:
parent
cbd85a0102
commit
c2decd47fe
@ -291,14 +291,7 @@ class PaintApp(App[None]):
|
|||||||
# CharInput now handles the background style itself PARTIALLY; it doesn't affect the whole area.
|
# CharInput now handles the background style itself PARTIALLY; it doesn't affect the whole area.
|
||||||
|
|
||||||
# update Text tool textbox immediately
|
# update Text tool textbox immediately
|
||||||
# TODO: DRY
|
self.update_textbox_style(Style(bgcolor=selected_bg_color))
|
||||||
style = Style(bgcolor=selected_bg_color)
|
|
||||||
if self.image.selection and self.image.selection.textbox_mode:
|
|
||||||
assert self.image.selection.contained_image is not None, "textbox_mode without contained_image"
|
|
||||||
for y in range(self.image.selection.region.height):
|
|
||||||
for x in range(self.image.selection.region.width):
|
|
||||||
self.image.selection.contained_image.st[y][x] += style
|
|
||||||
self.canvas.refresh_scaled_region(self.image.selection.region)
|
|
||||||
|
|
||||||
# update Polygon/Curve tool preview immediately
|
# update Polygon/Curve tool preview immediately
|
||||||
self.draw_tool_preview_on_canvas()
|
self.draw_tool_preview_on_canvas()
|
||||||
@ -311,13 +304,7 @@ class PaintApp(App[None]):
|
|||||||
self.query_one("#selected_color_char_input", CharInput).refresh()
|
self.query_one("#selected_color_char_input", CharInput).refresh()
|
||||||
|
|
||||||
# update Text tool textbox immediately
|
# update Text tool textbox immediately
|
||||||
style = Style(color=selected_fg_color)
|
self.update_textbox_style(Style(color=selected_fg_color))
|
||||||
if self.image.selection and self.image.selection.textbox_mode:
|
|
||||||
assert self.image.selection.contained_image is not None, "textbox_mode without contained_image"
|
|
||||||
for y in range(self.image.selection.region.height):
|
|
||||||
for x in range(self.image.selection.region.width):
|
|
||||||
self.image.selection.contained_image.st[y][x] += style
|
|
||||||
self.canvas.refresh_scaled_region(self.image.selection.region)
|
|
||||||
|
|
||||||
# update Polygon/Curve tool preview immediately
|
# update Polygon/Curve tool preview immediately
|
||||||
self.draw_tool_preview_on_canvas()
|
self.draw_tool_preview_on_canvas()
|
||||||
@ -340,6 +327,15 @@ class PaintApp(App[None]):
|
|||||||
"""Called when show_grid changes."""
|
"""Called when show_grid changes."""
|
||||||
self.canvas.show_grid = show_grid
|
self.canvas.show_grid = show_grid
|
||||||
|
|
||||||
|
def update_textbox_style(self, style: Style) -> None:
|
||||||
|
"""Apply a style to the whole textbox."""
|
||||||
|
if self.image.selection and self.image.selection.textbox_mode:
|
||||||
|
assert self.image.selection.contained_image is not None, "textbox_mode without contained_image"
|
||||||
|
for y in range(self.image.selection.region.height):
|
||||||
|
for x in range(self.image.selection.region.width):
|
||||||
|
self.image.selection.contained_image.st[y][x] += style
|
||||||
|
self.canvas.refresh_scaled_region(self.image.selection.region)
|
||||||
|
|
||||||
def stamp_brush(self, x: int, y: int, affected_region_base: Optional[Region] = None) -> Region:
|
def stamp_brush(self, x: int, y: int, affected_region_base: Optional[Region] = None) -> Region:
|
||||||
"""Draws the current brush at the given coordinates, with special handling for different tools."""
|
"""Draws the current brush at the given coordinates, with special handling for different tools."""
|
||||||
brush_diameter = 1
|
brush_diameter = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user