imgui_md.pyi 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. ###############################################################################
  2. # This file is a part of Dear ImGui Bundle, NOT a part of imgui_md
  3. # -----------------------------------------------------------------------------
  4. # imgui_md.pyi: auto-generated bindings for imgui_md, a Markdown renderer
  5. # for ImGui.
  6. # See https://github.com/mekhontsev/imgui_md
  7. # Here, we also provide bindings for an additional wrapper, which is part of
  8. # ImGui Bundle: see external/imgui_md/imgui_md_wrapper
  9. #
  10. # Most of the code of this file is automatically generated (using https://pthom.github.io/litgen/),
  11. # and is generally very close to the C++ version. Comments, docs are identical.
  12. # Do not manually edit the autogenerated parts (look for "Autogenerated" comments)!
  13. ###############################################################################
  14. # ruff: noqa: B008
  15. import enum
  16. from typing import Optional, Callable
  17. from imgui_bundle.imgui import ImTextureID, ImVec2, ImVec4, ImFont
  18. import numpy as np
  19. # using VoidFunction = std::function<void(void)>;
  20. # using StringFunction = std::function<void(std::string)>;
  21. # using HtmlDivFunction = std::function<void(const std::string& divClass, bool openingDiv)>;
  22. # using HtmlSpanFunction = std::function<bool(const std::string& tagName, bool opening)>;
  23. # using MarkdownImageFunction = std::function<std::optional<MarkdownImage>(const std::string&)>;
  24. # using MarkdownDownloadFunction = std::function<MarkdownDownloadResult(const std::string& url)>;
  25. VoidFunction = Callable[[], None]
  26. StringFunction = Callable[[str], None]
  27. HtmlDivFunction = Callable[[str, bool], None]
  28. HtmlSpanFunction = Callable[[str, bool], bool]
  29. MarkdownImageFunction = Callable[[str], Optional[MarkdownImage]]
  30. MarkdownDownloadFunction = Callable[[str], MarkdownDownloadResult]
  31. # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! AUTOGENERATED CODE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  32. # <litgen_stub> // Autogenerated code below! Do not edit!
  33. #################### <generated_from:imgui_md_wrapper.h> ####################
  34. class MarkdownFontOptions:
  35. font_base_path: str = "fonts/Roboto/Roboto"
  36. # This size is in density-independent pixels
  37. regular_size: float = 16.0
  38. # Multipliers for header sizes, from h1 to h6
  39. header_size_factors: (
  40. np.ndarray
  41. ) # ndarray[type=float, size=6] default:float( 1.42, 1.33, 1.24, 1.15, 1.10, 1.05 )
  42. def __init__(self) -> None:
  43. """Autogenerated default constructor"""
  44. pass
  45. class MarkdownImage:
  46. texture_id: ImTextureID
  47. size: ImVec2
  48. uv0: ImVec2
  49. uv1: ImVec2
  50. col_tint: ImVec4
  51. col_border: ImVec4
  52. def __init__(self) -> None:
  53. """Autogenerated default constructor"""
  54. pass
  55. class SizedFont:
  56. """Note: Since v1.92, Fonts can be displayed at any size:
  57. in order to display a font at a given size, we need to call
  58. ImGui::PushFont(font, size) (or call separately ImGui::PushFontSize)
  59. """
  60. font: ImFont
  61. size: float
  62. def __init__(self) -> None:
  63. """Autogenerated default constructor"""
  64. pass
  65. class MarkdownDownloadStatus(enum.IntEnum):
  66. """Status of a download (used by OnDownloadData callback)"""
  67. not_started = enum.auto() # (= 0) # Download has not been initiated
  68. downloading = enum.auto() # (= 1) # Download is in progress (show placeholder)
  69. ready = enum.auto() # (= 2) # Download complete, data is available
  70. failed = enum.auto() # (= 3) # Download failed, errorMessage has details
  71. class MarkdownDownloadResult:
  72. """Result of a download attempt"""
  73. status: MarkdownDownloadStatus = MarkdownDownloadStatus.not_started
  74. error_message: str # Only valid if status == Failed
  75. def __init__(self) -> None:
  76. """Autogenerated default constructor"""
  77. pass
  78. def fill_from_bytes(self, data: bytes) -> None:
  79. """Fill the result data from a Python bytes object."""
  80. ...
  81. def on_image_default(image_path: str) -> Optional[MarkdownImage]:
  82. pass
  83. def on_open_link_default(url: str) -> None:
  84. pass
  85. class MarkdownCallbacks:
  86. # The default version will open the link in a browser iif it starts with "http"
  87. on_open_link: StringFunction = on_open_link_default
  88. # The default version will load the image as a cached texture and display it
  89. on_image: MarkdownImageFunction = on_image_default
  90. # OnHtmlDiv does nothing by default, by you could write:
  91. # In C++:
  92. # markdownOptions.callbacks.onHtmlDiv = [](const std::string& divClass, bool openingDiv)
  93. # {
  94. # if (divClass == "red")
  95. # {
  96. # if (openingDiv)
  97. # ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 0, 0, 255));
  98. # else
  99. # ImGui::PopStyleColor();
  100. # }
  101. # };
  102. # In Python:
  103. # def on_html_div(div_class: str, opening_div: bool) -> None:
  104. # if div_class == 'red':
  105. # if opening_div:
  106. # imgui.push_style_color(imgui.Col_.text.value, imgui.ImColor(255, 0, 0, 255).value)
  107. # else:
  108. # imgui.pop_style_color()
  109. # md_options = imgui_md.MarkdownOptions()
  110. # md_options.callbacks.on_html_div = on_html_div
  111. # immapp.run(
  112. # gui_function=gui, with_markdown_options=md_options #, more options here
  113. # )
  114. on_html_div: HtmlDivFunction
  115. # OnHtmlSpan: optional callback for inline HTML tags encountered in
  116. # markdown text (one call per open/close tag; e.g. "sub", "sup",
  117. # "kbd", "mark", or any custom tag).
  118. # Return True to indicate the tag was fully handled, False to let
  119. # the built-in renderer apply its default rendering (if any).
  120. # Example (C++):
  121. # callbacks.OnHtmlSpan = [](const std::string& tag, bool opening) {
  122. # if (tag == "small") {
  123. # // ... push/pop a smaller font
  124. # return True;
  125. # }
  126. # return False;
  127. # };
  128. on_html_span: HtmlSpanFunction
  129. def __init__(self) -> None:
  130. """Autogenerated default constructor"""
  131. pass
  132. @property
  133. def on_download_data(self) -> Optional[str]:
  134. """Returns None if not set, or a status string if set.
  135. Reading back the callable itself is not supported."""
  136. ...
  137. @on_download_data.setter
  138. def on_download_data(
  139. self, fn: Optional[Callable[[str], MarkdownDownloadResult]]
  140. ) -> None:
  141. """Set a callable that downloads data from a URL.
  142. The callable receives a URL string and should return a MarkdownDownloadResult.
  143. The callback is stateful: it will be called every frame for a given URL until
  144. it returns Ready or Failed. For synchronous downloads, return Ready or Failed
  145. immediately. For async downloads, return Downloading on first call, then
  146. Ready/Failed once done.
  147. Set to None to disable URL image support."""
  148. ...
  149. class MarkdownOptions:
  150. font_options: MarkdownFontOptions
  151. callbacks: MarkdownCallbacks
  152. # Enable native LaTeX math rendering via MicroTeX.
  153. # When True, $...$ and $$...$$ in markdown will be rendered as math formulas
  154. # (requires building with IMGUI_RICHMD_WITH_LATEX=ON, which is the default
  155. # when IMGUI_BUNDLE_WITH_MICROTEX and FreeType are both available).
  156. # When False, $ is rendered as a literal character (legacy behavior).
  157. with_latex: bool = False
  158. # Recognize bare URLs, email addresses and www.* as clickable links
  159. # without requiring <...> or []() syntax
  160. # (MD_FLAG_PERMISSIVEAUTOLINKS — URL + email + WWW).
  161. # Set to False to get strict CommonMark link behavior.
  162. autolinks: bool = True
  163. def __init__(self) -> None:
  164. """Autogenerated default constructor"""
  165. pass
  166. def initialize_markdown(options: Optional[MarkdownOptions] = None) -> None:
  167. """Python bindings defaults:
  168. If options is None, then its default value will be: MarkdownOptions()
  169. """
  170. pass
  171. def de_initialize_markdown() -> None:
  172. pass
  173. def get_font_loader_function() -> VoidFunction:
  174. """GetFontLoaderFunction() will return a function that you should call during ImGui initialization."""
  175. pass
  176. def render(markdown_string: str) -> None:
  177. """Renders a markdown string"""
  178. pass
  179. def render_unindented(markdown_string: str) -> None:
  180. """Renders a markdown string (after having unindented its main indentation)"""
  181. pass
  182. def get_code_font() -> SizedFont:
  183. pass
  184. class MarkdownFontSpec:
  185. italic: bool = False
  186. bold: bool = False
  187. header_level: int = 0 # 0 means no header, 1 means h1, 2 means h2, etc.
  188. def __init__(
  189. self, italic_: bool = False, bold_: bool = False, header_level_: int = 0
  190. ) -> None:
  191. pass
  192. def get_font(font_spec: MarkdownFontSpec) -> SizedFont:
  193. pass
  194. def link_color() -> ImVec4:
  195. pass
  196. def render_text_as_link(text: str, url: str) -> None:
  197. """Renders a link with the given text and url. Can be used outside of markdown rendering."""
  198. pass
  199. def _set_on_initialize_markdown_callback(
  200. callback: Optional[Callable[[MarkdownOptions], None]],
  201. ) -> None:
  202. """Private. Set a callback called during initialize_markdown() to customize options.
  203. Used internally by imgui_bundle to inject URL image download support."""
  204. pass
  205. #################### </generated_from:imgui_md_wrapper.h> ####################
  206. # </litgen_stub> // Autogenerated code end!