[Update] Config Window: Dropdown Menu Window. UI Size変更対応。

[bugfix] Config Window: Dropdown Menu Window. それに伴いrootのgeometry, positionが崩れたのでその修正。
This commit is contained in:
Sakamoto Shiina
2023-10-10 08:46:14 +09:00
parent 6657903c57
commit 7fd8b089d5
4 changed files with 64 additions and 30 deletions

View File

@@ -10,6 +10,14 @@ class _CreateDropdownMenuWindow(CTkToplevel):
def __init__(self,
settings,
view_variable,
window_additional_y_pos,
window_border_width,
scrollbar_ipadx,
value_padx,
value_pady,
value_font_size,
window_bg_color,
window_border_color,
values_bg_color,
@@ -31,6 +39,13 @@ class _CreateDropdownMenuWindow(CTkToplevel):
self.resizable(width=False, height=False)
self.window_additional_y_pos=window_additional_y_pos
self.window_border_width=window_border_width
self.scrollbar_ipadx=scrollbar_ipadx
self.value_padx=value_padx
self.value_pady=value_pady
self.value_font_size=value_font_size
self.window_bg_color=window_bg_color
self.window_border_color=window_border_color
self.values_bg_color=values_bg_color
@@ -72,6 +87,7 @@ class _CreateDropdownMenuWindow(CTkToplevel):
dropdown_menu_values=dropdown_menu_values,
command=self.dropdown_menu_widgets[dropdown_menu_widget_id].command,
wrapper_widget=self.dropdown_menu_widgets[dropdown_menu_widget_id].wrapper_widget,
attach_widget=self.dropdown_menu_widgets[dropdown_menu_widget_id].attach_widget,
dropdown_menu_width=self.dropdown_menu_widgets[dropdown_menu_widget_id].dropdown_menu_settings.dropdown_menu_width,
dropdown_menu_height=self.dropdown_menu_widgets[dropdown_menu_widget_id].dropdown_menu_settings.dropdown_menu_height,
@@ -79,20 +95,22 @@ class _CreateDropdownMenuWindow(CTkToplevel):
)
def createDropdownMenuBox(self, dropdown_menu_widget_id, dropdown_menu_values, command, wrapper_widget, dropdown_menu_width=None, dropdown_menu_height=None, max_display_length=None):
self.new_width = dropdown_menu_width if dropdown_menu_width is not None else self.init_width
def createDropdownMenuBox(self, dropdown_menu_widget_id, dropdown_menu_values, command, wrapper_widget, attach_widget, dropdown_menu_width=None, dropdown_menu_height=None, max_display_length=None):
self.attach_widget = attach_widget
self.wrapper_widget = wrapper_widget
self.update()
self.new_width = dropdown_menu_width if dropdown_menu_width is not None else self.attach_widget.winfo_width()
self.new_height = dropdown_menu_height if dropdown_menu_height is not None else self.init_height
self.max_display_length = max_display_length if max_display_length is not None else self.init_max_display_length
self.wrapper_widget = wrapper_widget
self.dropdown_menu_container = CTkFrame(self, corner_radius=0, fg_color=self.window_border_color, width=0, height=0)
# self.dropdown_menu_container = CTkFrame(self, corner_radius=0, fg_color="#ff7f50", width=0, height=0)
self.dropdown_menu_container.grid(row=0, column=0, sticky="nsew")
BORDER_WIDTH=1
BORDER_WIDTH=self.window_border_width
self.scroll_frame_container = CTkScrollableFrame(
self.dropdown_menu_container,
corner_radius=0,
@@ -102,7 +120,7 @@ class _CreateDropdownMenuWindow(CTkToplevel):
border_width=0,
)
self.scroll_frame_container.grid(row=0, column=0, padx=BORDER_WIDTH, pady=BORDER_WIDTH, sticky="nsew")
self.scroll_frame_container._scrollbar.grid_configure(padx=(2, 2))
self.scroll_frame_container._scrollbar.grid_configure(padx=self.scrollbar_ipadx)
self.scroll_frame_container.grid_columnconfigure(0, weight=1)
@@ -115,14 +133,16 @@ class _CreateDropdownMenuWindow(CTkToplevel):
self._createDropdownMenuValues(dropdown_menu_widget_id, dropdown_menu_values, command)
geometry_width = int(self.new_width + self.scroll_frame_container._scrollbar.winfo_width() + (BORDER_WIDTH*2) + 4)
geometry_width = int(self.new_width + self.scroll_frame_container._scrollbar.winfo_width() + (BORDER_WIDTH*2) + (self.scrollbar_ipadx[0] + self.scrollbar_ipadx[1]))
geometry_height = int(self.new_height + (BORDER_WIDTH*2))
self.dropdown_menu_widgets[dropdown_menu_widget_id] = SimpleNamespace()
self.dropdown_menu_widgets[dropdown_menu_widget_id] = SimpleNamespace(
widget=self.dropdown_menu_container,
command=command,
wrapper_widget=wrapper_widget,
attach_widget=attach_widget,
dropdown_menu_settings=SimpleNamespace(
dropdown_menu_width=dropdown_menu_width,
dropdown_menu_height=dropdown_menu_height,
@@ -145,7 +165,7 @@ class _CreateDropdownMenuWindow(CTkToplevel):
# for get to the height__________________
__dropdown_menu_value_wrapper = CTkFrame(self.dropdown_menu_values_wrapper, corner_radius=0, fg_color=self.values_bg_color, width=0, height=0)
__dropdown_menu_value_wrapper.grid(row=0, column=0, ipadx=6, ipady=6, sticky="nsew")
__dropdown_menu_value_wrapper.grid(row=0, column=0, sticky="nsew")
setattr(self, f"{dropdown_menu_widget_id}__{0}", __dropdown_menu_value_wrapper)
@@ -156,13 +176,13 @@ class _CreateDropdownMenuWindow(CTkToplevel):
text="Aa",
height=0,
corner_radius=0,
font=CTkFont(family=self.settings.FONT_FAMILY, size=14, weight="normal"),
font=CTkFont(family=self.settings.FONT_FAMILY, size=self.value_font_size, weight="normal"),
anchor="w",
text_color=self.values_text_color,
)
# setattr(self, f"l", __label_widget)
__label_widget.grid(row=1, column=0, padx=(8,0), sticky="w")
__label_widget.grid(row=1, column=0, padx=self.value_padx, pady=self.value_pady, sticky="w")
label_height = getLatestHeight(__dropdown_menu_value_wrapper)
# ______________________________________
@@ -190,7 +210,7 @@ class _CreateDropdownMenuWindow(CTkToplevel):
for dropdown_menu_value in dropdown_menu_values:
dropdown_menu_value_wrapper = CTkFrame(self.dropdown_menu_values_wrapper, corner_radius=0, fg_color=self.values_bg_color, width=0, height=0, cursor="hand2")
dropdown_menu_value_wrapper.grid(row=row, column=0, ipadx=6, ipady=6, sticky="nsew")
dropdown_menu_value_wrapper.grid(row=row, column=0, sticky="nsew")
setattr(self, f"{dropdown_menu_widget_id}__{row}", dropdown_menu_value_wrapper)
@@ -202,14 +222,13 @@ class _CreateDropdownMenuWindow(CTkToplevel):
text=dropdown_menu_value,
height=0,
corner_radius=0,
font=CTkFont(family=self.settings.FONT_FAMILY, size=14, weight="normal"),
font=CTkFont(family=self.settings.FONT_FAMILY, size=self.value_font_size, weight="normal"),
anchor="w",
text_color=self.values_text_color,
)
# setattr(self, f"l", label_widget)
label_widget.grid(row=1, column=0, padx=(8,0), sticky="w")
label_widget.grid(row=1, column=0, padx=self.value_padx, pady=self.value_pady, sticky="w")
bindEnterAndLeaveColor([dropdown_menu_value_wrapper, label_widget], self.values_hovered_bg_color, self.values_bg_color)
@@ -228,17 +247,18 @@ class _CreateDropdownMenuWindow(CTkToplevel):
def show(self, dropdown_menu_widget_id, target_widget):
def show(self, dropdown_menu_widget_id):
if self.hide is False: return
self.wm_attributes("-alpha", 0)
self.attach_widget = target_widget
if self.active_dropdown_menu_widget is not None:
self.active_dropdown_menu_widget.grid_remove()
target_data = self.dropdown_menu_widgets[dropdown_menu_widget_id]
self.attach_widget = target_data.attach_widget
target_data.widget.grid()
self.active_dropdown_menu_widget = target_data.widget
@@ -297,7 +317,7 @@ class _CreateDropdownMenuWindow(CTkToplevel):
self.attach_widget_y_pos = self.attach_widget.winfo_rooty()
self.y_pos = int(self.attach_widget_y_pos + self.attach_widget_height + 4)
self.y_pos = int(self.attach_widget_y_pos + self.attach_widget_height + self.window_additional_y_pos)
if self.wrapper_widget_y_pos > self.y_pos or self.y_pos > self.wrapper_widget_bottom_y_pos:
self.hideTemporarily()

View File

@@ -82,13 +82,6 @@ class _SettingBoxGenerator():
variable.set(value)
command(value)
self.dropdown_menu_window.createDropdownMenuBox(
dropdown_menu_widget_id=optionmenu_attr_name,
dropdown_menu_values=dropdown_menu_values,
command=adjustedCommand,
wrapper_widget=self.config_window.main_bg_container,
dropdown_menu_width=dropdown_menu_width,
)
option_menu_widget = createOptionMenuBox(
parent_widget=setting_box_item_frame,
@@ -108,13 +101,21 @@ class _SettingBoxGenerator():
image_size=(14,14),
optionmenu_clicked_command=lambda _e: self.dropdown_menu_window.show(
dropdown_menu_widget_id=optionmenu_attr_name,
target_widget=option_menu_widget,
),
)
option_menu_widget.grid(row=1, column=SETTING_BOX_COLUMN, sticky="e")
setattr(self.config_window, optionmenu_attr_name, option_menu_widget)
self.dropdown_menu_window.createDropdownMenuBox(
dropdown_menu_widget_id=optionmenu_attr_name,
dropdown_menu_values=dropdown_menu_values,
command=adjustedCommand,
wrapper_widget=self.config_window.main_bg_container,
attach_widget=option_menu_widget,
dropdown_menu_width=dropdown_menu_width,
)
return setting_box_frame

View File

@@ -153,10 +153,14 @@ class UiScalingManager():
self.config_window.SB__OPTION_MENU_FONT_SIZE = self.config_window.SB__SELECTOR_FONT_SIZE
self.config_window.SB__OPTIONMENU_MIN_HEIGHT = self._calculateUiSize(30)
self.config_window.SB__OPTIONMENU_MIN_WIDTH = self._calculateUiSize(200)
self.config_window.SB__DROPDOWN_MENU_WINDOW_ADDITIONAL_Y_POS = self._calculateUiSize(4)
self.config_window.SB__DROPDOWN_MENU_WIDTH = self.config_window.SB__OPTIONMENU_MIN_WIDTH
self.config_window.SB__DROPDOWN_MENU_MAX_BUTTON_HEIGHT = int(self.config_window.SB__OPTION_MENU_FONT_SIZE + self._calculateUiSize(6))
self.config_window.SB__DROPDOWN_MENU_FRAME_CORNER_RADIUS = self._calculateUiSize(10)
self.config_window.SB__DROPDOWN_MENU_FRAME_MAX_HEIGHT = self._calculateUiSize(200)
self.config_window.SB__DROPDOWN_MENU_WINDOW_BORDER_WIDTH = self._calculateUiSize(1, is_allowed_odd=True)
self.config_window.SB__DROPDOWN_MENU_SCROLLBAR_IPADX = (self._calculateUiSize(2), self._calculateUiSize(2))
self.config_window.SB__DROPDOWN_MENU_VALUE_PADX = (self._calculateUiSize(8), 0)
self.config_window.SB__DROPDOWN_MENU_VALUE_PADY = self._calculateUiSize(6)
self.config_window.SB__DROPDOWN_MENU_VALUE_FONT_SIZE = self._calculateUiSize(14)
self.config_window.SB__SWITCH_WIDTH = self._calculateUiSize(50)
@@ -186,9 +190,12 @@ class UiScalingManager():
def _calculateUiSize(self, default_size, is_allowed_odd: bool = False):
def _calculateUiSize(self, default_size, is_allowed_odd:bool=False, is_zero_allowed:bool=False):
size = int(default_size * self.SCALING_FLOAT)
size += 1 if not is_allowed_odd and size % 2 != 0 else 0
if size <= 0:
size = 0 if is_zero_allowed else 1
return size
@staticmethod

View File

@@ -36,6 +36,12 @@ class VRCT_GUI(CTk):
self.dropdown_menu_window = _CreateDropdownMenuWindow(
settings=self.settings.config_window,
view_variable=self._view_variable,
window_additional_y_pos=self.settings.config_window.uism.SB__DROPDOWN_MENU_WINDOW_ADDITIONAL_Y_POS,
window_border_width=self.settings.config_window.uism.SB__DROPDOWN_MENU_WINDOW_BORDER_WIDTH,
scrollbar_ipadx=self.settings.config_window.uism.SB__DROPDOWN_MENU_SCROLLBAR_IPADX,
value_padx=self.settings.config_window.uism.SB__DROPDOWN_MENU_VALUE_PADX,
value_pady=self.settings.config_window.uism.SB__DROPDOWN_MENU_VALUE_PADY,
value_font_size=self.settings.config_window.uism.SB__DROPDOWN_MENU_VALUE_FONT_SIZE,
window_bg_color=self.settings.config_window.ctm.SB__DROPDOWN_MENU_WINDOW_BG_COLOR,
window_border_color=self.settings.config_window.ctm.SB__DROPDOWN_MENU_WINDOW_BORDER_COLOR,