From 8680c364dd980962e0e742cebc20bf56a88a35d9 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Tue, 23 May 2023 23:52:29 -0400 Subject: [PATCH] Clamp values --- src/textual_paint/edit_colors.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/textual_paint/edit_colors.py b/src/textual_paint/edit_colors.py index 385015a..d8068d0 100644 --- a/src/textual_paint/edit_colors.py +++ b/src/textual_paint/edit_colors.py @@ -205,7 +205,7 @@ class LuminosityRamp(Widget): def _update_color(self, y: int) -> None: """Update the color based on the given y coordinate.""" - self.luminosity = y / self.size.height + self.luminosity = max(0, min(1, y / self.size.height)) self.post_message(self.Changed(luminosity=self.luminosity)) self.refresh() @@ -261,8 +261,8 @@ class ColorField(Widget): def _update_color(self, offset: Offset) -> None: """Update the color based on the given offset.""" x, y = offset - self.hue = x / self.size.width - self.saturation = 1 - y / self.size.height + self.hue = max(0, min(1, x / self.size.width)) + self.saturation = max(0, min(1, 1 - y / self.size.height)) self.post_message(self.Changed(hue=self.hue, saturation=self.saturation)) self.refresh()