class_name TrayControls extends RefCounted ## Builds the result tray's fixed controls: the EARLIER / VARIABLES tab ## buttons, the Copy menu (with "Save as a file"), and the sheet headline box ## that shows a finished sheet left of the chips. ResultTray.setup() calls these. ## A flat tab button with an accent underline when pressed. static func tab_button(text: String) -> Button: var button := Button.new() button.text = text button.toggle_mode = true button.add_theme_font_override("font", Style.caps()) button.add_theme_font_size_override("font_size", 12) var normal := Style.box(Color(0, 0, 0, 0), 0, [0, 0, 0, 3]) var pressed := Style.box(Color(0, 0, 0, 0), 0, [0, 0, 0, 1]) pressed.border_width_bottom = 2 pressed.border_color = Style.ACCENT Style.skin_button(button, normal, normal, pressed, Style.ON_BG_MUTED, Style.ON_BG, Style.ON_BG) button.add_theme_stylebox_override("focus", Style.box(Color(0, 0, 0, 0))) return button ## The Copy menu: copy as text, BBCode or with details, or save as a file. static func copy_menu(main: Main) -> MenuButton: var menu := MenuButton.new() menu.text = "Copy" menu.tooltip_text = "Copy this result, or save it as a file" menu.flat = false var normal := Style.bordered(Style.box(Color(1, 1, 1, 0.04), 8, [12, 6, 12, 6]), 1, Color(1, 1, 1, 0.16)) var hover := Style.bordered(Style.box(Color(1, 1, 1, 0.1), 8, [12, 6, 12, 6]), 1, Color(1, 1, 1, 0.16)) Style.skin_button(menu, normal, hover, hover, Style.ON_BG) menu.add_theme_font_size_override("font_size", 15) var popup := menu.get_popup() popup.add_item("Copy as text", ResultTray.COPY_TEXT) popup.add_item("Copy as BBCode", ResultTray.COPY_BBCODE) popup.add_item("Copy with details", ResultTray.COPY_DETAILS) popup.add_theme_stylebox_override("panel", Style.bordered(Style.box(Style.CARD, 8, [6, 6, 6, 6]), 1, Style.RULE)) popup.add_theme_stylebox_override("hover", Style.box(Style.LIT, 5, [8, 4, 8, 4])) popup.add_theme_color_override("font_color", Style.INK) popup.add_theme_color_override("font_hover_color", Style.INK) popup.add_theme_font_override("font", Style.body()) popup.add_theme_font_size_override("font_size", 15) popup.id_pressed.connect(func(id: int) -> void: main.copy_current(id)) # Save as a file to use outside the app (SheetExport). var save := PopupMenu.new() ModalCard.style_popup(save) for i in SheetExport.FORMATS.size(): save.add_item(str(SheetExport.FORMATS[i]["label"]) + "…", i) save.id_pressed.connect(func(i: int) -> void: SheetExport.save(main, i)) popup.add_child(save) popup.add_separator() popup.add_submenu_node_item("Save as a file", save) return menu ## Builds the sheet headline box into tray._headline (hidden until a chain ## reaches a sheet card), with its caption, text and scroll area. static func build_headline(tray: ResultTray) -> void: tray._headline = PanelContainer.new() var headline_box := Style.box(Style.CARD, 10, [16, 10, 16, 12]) Style.bordered(headline_box, 2, Style.ACCENT) tray._headline.add_theme_stylebox_override("panel", headline_box) tray._headline.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN var column := VBoxContainer.new() column.add_theme_constant_override("separation", 2) tray._headline.add_child(column) tray._headline_cap = Style.make_label("", Style.body(), 12, Style.MUTED) column.add_child(tray._headline_cap) # A sheet wraps at a fixed width and scrolls inside the tray, so a long # sheet can't widen the window or take over the tray. tray._headline_text = RichText.label("", 17, Style.INK, false, true) tray._headline_text.custom_minimum_size = Vector2(ResultTray.HEADLINE_W, 0) RichText.hook_hover(tray._headline_text, tray.main) tray._headline_scroll = ScrollContainer.new() tray._headline_scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED tray._headline_scroll.custom_minimum_size = Vector2(ResultTray.HEADLINE_W + 12, 0) tray._headline_scroll.add_child(tray._headline_text) column.add_child(tray._headline_scroll) tray._headline.hide() tray._headline.size_flags_vertical = Control.SIZE_SHRINK_BEGIN