fixed small scaling issues

This commit is contained in:
Tom Schimansky
2022-05-12 22:55:28 +02:00
parent d36cf416b7
commit b99f384241
25 changed files with 96 additions and 58 deletions

View File

@ -5,7 +5,7 @@ import os
import platform
import ctypes
import re
from typing import Union
from typing import Union, Tuple
from ..appearance_mode_tracker import AppearanceModeTracker
from ..theme_manager import CTkThemeManager
@ -33,8 +33,11 @@ class CTk(tkinter.Tk):
self.current_width = 600 # initial window size, always without scaling
self.current_height = 500
self.minsize: Union[tuple, None] = None
self.maxsize: Union[tuple, None] = None
self.min_width: Union[int, None] = None
self.min_height: Union[int, None] = None
self.max_width: Union[int, None] = None
self.max_height: Union[int, None] = None
self.last_resizable_args: Union[Tuple[list, dict], None] = None # (args, kwargs)
self.fg_color = CTkThemeManager.theme["color"]["window_bg_color"] if fg_color == "default_theme" else fg_color
@ -70,9 +73,25 @@ class CTk(tkinter.Tk):
def set_scaling(self, new_widget_scaling, new_spacing_scaling, new_window_scaling):
self.window_scaling = new_window_scaling
# reset min, max and resizable constraints for applying scaling
if self.last_resizable_args is not None:
super().resizable(True, True)
if self.min_width is not None or self.min_height is not None:
super().minsize(0, 0)
if self.max_width is not None or self.max_height is not None:
super().maxsize(1_000_000, 1_000_000)
# set new window size by applying scaling to the current window size
self.geometry(f"{self.current_width}x{self.current_height}")
# set scaled min, max sizes and reapply resizable
if self.last_resizable_args is not None:
super().resizable(self.last_resizable_args[0], self.last_resizable_args[1]) # args, kwargs
if self.min_width is not None or self.min_height is not None:
super().minsize(self.apply_window_scaling(self.min_width), self.apply_window_scaling(self.min_height))
if self.max_width is not None or self.max_height is not None:
super().maxsize(self.apply_window_scaling(self.max_width), self.apply_window_scaling(self.max_height))
def destroy(self):
AppearanceModeTracker.remove(self.set_appearance_mode)
self.disable_macos_dark_title_bar()
@ -92,6 +111,7 @@ class CTk(tkinter.Tk):
def resizable(self, *args, **kwargs):
super().resizable(*args, **kwargs)
self.last_resizable_args = (args, kwargs)
if sys.platform.startswith("win"):
if self.appearance_mode == 1:
@ -99,6 +119,16 @@ class CTk(tkinter.Tk):
else:
self.windows_set_titlebar_color("light")
def minsize(self, width=None, height=None):
self.min_width = width
self.min_height = height
super().minsize(self.apply_window_scaling(self.min_width), self.apply_window_scaling(self.min_height))
def maxsize(self, width=None, height=None):
self.max_width = width
self.max_height = height
super().maxsize(self.apply_window_scaling(self.max_width), self.apply_window_scaling(self.max_height))
def geometry(self, geometry_string):
super().geometry(self.apply_geometry_scaling(geometry_string))
@ -122,7 +152,7 @@ class CTk(tkinter.Tk):
def apply_window_scaling(self, value):
if isinstance(value, (int, float)):
return value * self.window_scaling
return int(value * self.window_scaling)
else:
return value