From 8740c8865a120f26db242bbfbf301d323af18d0e Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Mon, 2 Jan 2023 16:47:29 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=8F=90=E5=89=8Dpush=E4=B8=80?= =?UTF-8?q?=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Difficult_Rocket/api/types/__init__.py | 30 ++++++++++++++++++------- Difficult_Rocket/client/guis/widgets.py | 26 ++++----------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/Difficult_Rocket/api/types/__init__.py b/Difficult_Rocket/api/types/__init__.py index 276c04b..592c04b 100644 --- a/Difficult_Rocket/api/types/__init__.py +++ b/Difficult_Rocket/api/types/__init__.py @@ -11,16 +11,12 @@ github: @shenjackyuanjie gitee: @shenjackyuanjie """ -""" -存档模块 -尽量同时兼容SR1和DR -包含: - 解析存档文件 - 创建存档文件 -""" - +import dataclasses from typing import get_type_hints, Type, List, Union, Dict, Any, Callable, Tuple +# from Difficult Rocket +from Difficult_Rocket.utils import translate + def get_type_hints_(cls: Type): try: @@ -110,3 +106,21 @@ class Options: cls.options: Dict[str, Union[Callable, object]] = {} cls.options[name] = value return cls.options + + +@dataclasses.dataclass +class FontData: + """ 用于保存字体的信息 """ + font_name: str = translate.鸿蒙简体 + font_size: int = 13 + bold: bool = False + italic: bool = False + stretch: bool = False + + def dict(self) -> Dict[str, Union[str, int, bool]]: + return dict(font_name=self.font_name, + font_size=self.font_size, + bold=self.bold, + italic=self.italic, + stretch=self.stretch) + diff --git a/Difficult_Rocket/client/guis/widgets.py b/Difficult_Rocket/client/guis/widgets.py index ee12487..27ac382 100644 --- a/Difficult_Rocket/client/guis/widgets.py +++ b/Difficult_Rocket/client/guis/widgets.py @@ -29,6 +29,7 @@ from pyglet.text.layout import IncrementalTextLayout # from libs import pyperclip # from libs.pyperclip import paste +from Difficult_Rocket.api.types import FontData from Difficult_Rocket.utils import translate from Difficult_Rocket.client.guis.format import html from Difficult_Rocket import DR_option @@ -36,25 +37,6 @@ from Difficult_Rocket import DR_option __all__ = ['InputBox'] -# class Parts(widgets.WidgetBase): -# """ -# parts -# """ -# -# def __init__(self, -# x: int, -# y: int, -# width: int, -# height: int, -# textures: AbstractImage, -# # textures, -# batch: Batch, -# parts_data: dict): -# super().__init__(x, y, width, height) -# self.sprite = Sprite(img=textures, x=x, y=y, batch=batch) -# self._value = 0 - - class TextButton(widgets.WidgetBase): """ 自带字符的按钮,就不用单独做材质了 @@ -85,14 +67,13 @@ if not DR_option.InputBox_use_TextEntry: def __init__(self, x: int, y: int, width: int, text: str, side_width: int = 2, - font_name: str = translate.鸿蒙简体, - font_size: str = 13, + font_data: Optional[FontData] = None, color: Optional[Tuple[int, int, int, int]] = (255, 255, 255, 255), text_color: Optional[Tuple[int, int, int, int]] = (0, 0, 0, 255), caret_color: Optional[Tuple[int, int, int, int]] = (0, 0, 0), batch: Optional[Batch] = None, group: Optional[Group] = None): self._doc = UnformattedDocument(text) - self._doc.set_style(0, len(self._doc.text), dict(color=text_color, font_name=font_name)) + self._doc.set_style(0, len(self._doc.text), {**font_data.dict(), 'text_color': text_color}) font = self._doc.get_font() height = font.ascent - font.descent @@ -113,6 +94,7 @@ if not DR_option.InputBox_use_TextEntry: self._caret.visible = False self._focus = False + super().__init__() # InputBox.register_event_type('on_commit')