Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Window

繼承: Viewport < Node < Object

被繼承: AcceptDialog, Popup

所有視窗、對話方塊、彈出框的基底類別。

說明

建立視窗的節點。視窗可以是原生系統視窗,也可以是嵌入到其他 Window 中的視窗(見 Viewport.gui_embed_subwindows)。

運作時,Window 不會在請求關閉時自動關閉。你需要使用 close_requested 訊號手動處理(適用於點擊關閉按鈕和點擊快顯視窗外部)。

教學

屬性

String

accessibility_description

""

String

accessibility_name

""

bool

always_on_top

false

bool

auto_translate

bool

borderless

false

ContentScaleAspect

content_scale_aspect

0

float

content_scale_factor

1.0

ContentScaleMode

content_scale_mode

0

Vector2i

content_scale_size

Vector2i(0, 0)

ContentScaleStretch

content_scale_stretch

0

int

current_screen

bool

exclude_from_capture

false

bool

exclusive

false

bool

extend_to_title

false

bool

force_native

false

bool

hdr_output_requested

false

WindowInitialPosition

initial_position

0

bool

keep_title_visible

false

Vector2i

max_size

Vector2i(0, 0)

bool

maximize_disabled

false

Vector2i

min_size

Vector2i(0, 0)

bool

minimize_disabled

false

Mode

mode

0

bool

mouse_passthrough

false

PackedVector2Array

mouse_passthrough_polygon

PackedVector2Array()

Rect2i

nonclient_area

Rect2i(0, 0, 0, 0)

bool

popup_window

false

bool

popup_wm_hint

false

Vector2i

position

Vector2i(0, 0)

bool

sharp_corners

false

Vector2i

size

Vector2i(100, 100)

Theme

theme

StringName

theme_type_variation

&""

String

title

""

bool

transient

false

bool

transient_to_focused

false

bool

transparent

false

bool

unfocusable

false

bool

unresizable

false

bool

visible

true

bool

wrap_controls

false

方法

Vector2

_get_contents_minimum_size() virtual const

void

add_theme_color_override(name: StringName, color: Color)

void

add_theme_constant_override(name: StringName, constant: int)

void

add_theme_font_override(name: StringName, font: Font)

void

add_theme_font_size_override(name: StringName, font_size: int)

void

add_theme_icon_override(name: StringName, texture: Texture2D)

void

add_theme_stylebox_override(name: StringName, stylebox: StyleBox)

void

begin_bulk_theme_override()

bool

can_draw() const

void

child_controls_changed()

void

end_bulk_theme_override()

Vector2

get_contents_minimum_size() const

bool

get_flag(flag: Flags) const

Window

get_focused_window() static

LayoutDirection

get_layout_direction() const

float

get_output_max_linear_value() const

Vector2i

get_position_with_decorations() const

Vector2i

get_size_with_decorations() const

Color

get_theme_color(name: StringName, theme_type: StringName = &"") const

int

get_theme_constant(name: StringName, theme_type: StringName = &"") const

float

get_theme_default_base_scale() const

Font

get_theme_default_font() const

int

get_theme_default_font_size() const

Font

get_theme_font(name: StringName, theme_type: StringName = &"") const

int

get_theme_font_size(name: StringName, theme_type: StringName = &"") const

Texture2D

get_theme_icon(name: StringName, theme_type: StringName = &"") const

StyleBox

get_theme_stylebox(name: StringName, theme_type: StringName = &"") const

int

get_window_id() const

void

grab_focus()

bool

has_focus() const

bool

has_theme_color(name: StringName, theme_type: StringName = &"") const

bool

has_theme_color_override(name: StringName) const

bool

has_theme_constant(name: StringName, theme_type: StringName = &"") const

bool

has_theme_constant_override(name: StringName) const

bool

has_theme_font(name: StringName, theme_type: StringName = &"") const

bool

has_theme_font_override(name: StringName) const

bool

has_theme_font_size(name: StringName, theme_type: StringName = &"") const

bool

has_theme_font_size_override(name: StringName) const

bool

has_theme_icon(name: StringName, theme_type: StringName = &"") const

bool

has_theme_icon_override(name: StringName) const

bool

has_theme_stylebox(name: StringName, theme_type: StringName = &"") const

bool

has_theme_stylebox_override(name: StringName) const

void

hide()

bool

is_embedded() const

bool

is_layout_rtl() const

bool

is_maximize_allowed() const

bool

is_using_font_oversampling() const

void

move_to_center()

void

move_to_foreground()

void

popup(rect: Rect2i = Rect2i(0, 0, 0, 0))

void

popup_centered(minsize: Vector2i = Vector2i(0, 0))

void

popup_centered_clamped(minsize: Vector2i = Vector2i(0, 0), fallback_ratio: float = 0.75)

void

popup_centered_ratio(ratio: float = 0.8)

void

popup_exclusive(from_node: Node, rect: Rect2i = Rect2i(0, 0, 0, 0))

void

popup_exclusive_centered(from_node: Node, minsize: Vector2i = Vector2i(0, 0))

void

popup_exclusive_centered_clamped(from_node: Node, minsize: Vector2i = Vector2i(0, 0), fallback_ratio: float = 0.75)

void

popup_exclusive_centered_ratio(from_node: Node, ratio: float = 0.8)

void

popup_exclusive_on_parent(from_node: Node, parent_rect: Rect2i)

void

popup_on_parent(parent_rect: Rect2i)

void

remove_theme_color_override(name: StringName)

void

remove_theme_constant_override(name: StringName)

void

remove_theme_font_override(name: StringName)

void

remove_theme_font_size_override(name: StringName)

void

remove_theme_icon_override(name: StringName)

void

remove_theme_stylebox_override(name: StringName)

void

request_attention()

void

reset_size()

void

set_flag(flag: Flags, enabled: bool)

void

set_ime_active(active: bool)

void

set_ime_position(position: Vector2i)

void

set_layout_direction(direction: LayoutDirection)

void

set_taskbar_progress_state(state: ProgressState)

void

set_taskbar_progress_value(value: float)

void

set_unparent_when_invisible(unparent: bool)

void

set_use_font_oversampling(enable: bool)

void

show()

void

start_drag()

void

start_resize(edge: WindowResizeEdge)

主題屬性

Color

title_color

Color(0.875, 0.875, 0.875, 1)

Color

title_outline_modulate

Color(0, 0, 0, 1)

int

close_h_offset

18

int

close_v_offset

24

int

resize_margin

4

int

title_height

36

int

title_outline_size

0

Font

title_font

int

title_font_size

Texture2D

close

Texture2D

close_pressed

StyleBox

embedded_border

StyleBox

embedded_unfocused_border


訊號

about_to_popup() 🔗

在呼叫 popup() 之後但在 Window 出現或執行任何操作之前發送的訊號。


close_requested() 🔗

按下該 Window 的關閉按鈕或啟用 popup_window 並且使用者在視窗外點擊時發出。

這個訊號可以用來處理視窗的關閉,例如將其連接到 hide()


dpi_changed() 🔗

Emitted when the Window's DPI changes as a result of OS-level changes (e.g. moving the window from a Retina display to a lower resolution one).

Note: Only implemented on macOS and Linux (Wayland).


files_dropped(files: PackedStringArray) 🔗

Emitted when files are dragged from the OS file manager and dropped in the game window. The argument is a list of file paths.

func _ready():
    get_window().files_dropped.connect(on_files_dropped)

func on_files_dropped(files):
    print(files)

Note: This signal only works with native windows, i.e. the main window and Window-derived nodes when Viewport.gui_embed_subwindows is disabled in the main viewport.


focus_entered() 🔗

當該 Window 獲得焦點時發出。


focus_exited() 🔗

當該 Window 失去焦點時發出。


go_back_requested() 🔗

發送返回請求時,在 Node.NOTIFICATION_WM_GO_BACK_REQUEST 之後發出(例如在 Android 上按下“返回”按鈕)。


mouse_entered() 🔗

當滑鼠遊標進入Window的可見區域時發出,該區域未被其他Control或視窗遮擋,前提是其Viewport.gui_disable_input``false ``,不論目前是否處於焦點狀態。


mouse_exited() 🔗

當滑鼠遊標離開Window的可見區域時發出,該區域未被其他Control或視窗遮擋,前提是其Viewport.gui_disable_input``false ``,不論目前是否處於焦點狀態。


nonclient_window_input(event: InputEvent) 🔗

Emitted when the mouse event is received by the custom decoration area defined by nonclient_area, and normal input to the window is blocked (such as when it has an exclusive child opened). event's position is in the embedder's coordinate system.


output_max_linear_value_changed(output_max_linear_value: float) 🔗

Emitted when the output max linear value returned by get_output_max_linear_value() has changed. This occurs when HDR output is enabled or disabled and when any HDR output luminance values of the window have changed, such as when the player adjusts their screen brightness setting or moves the window to a different screen. output_max_linear_value is the new value.


theme_changed() 🔗

發送 NOTIFICATION_THEME_CHANGED 通知時發出。


title_changed() 🔗

Emitted when window title bar text is changed.


titlebar_changed() 🔗

視窗標題列裝飾發生改變時發出,例如 macOS 視窗進入/退出全屏模式,或者“擴充至標題”旗標發生改變。


visibility_changed() 🔗

顯示或隱藏該 Window 時發出。


window_input(event: InputEvent) 🔗

Window 持有焦點並收到任何輸入時發出,會把收到的事件作為參數傳入。該事件如果存在位置屬性,該位置使用嵌入器的坐標系。


列舉

enum Mode: 🔗

Mode MODE_WINDOWED = 0

視窗模式,即 Window 不佔據整個螢幕(除非設定為螢幕的大小)。

Mode MODE_MINIMIZED = 1

最小化視窗模式,即 Window 在視窗管理器的視窗列表中既不可見也不可用。通常發生在按下最小化按鈕時。

Mode MODE_MAXIMIZED = 2

最大化視窗模式,即 Window 會佔據整個螢幕區域,工作列除外,並且會顯示邊框。通常發生在按下最大化按鈕時。

Mode MODE_FULLSCREEN = 3

Full screen mode with full multi-window support.

Full screen window covers the entire display area of a screen and has no decorations. The display's video mode is not changed.

On Android: This enables immersive mode.

On macOS: A new desktop is used to display the running project.

Note: Regardless of the platform, enabling full screen will change the window size to match the monitor's size. Therefore, make sure your project supports multiple resolutions when enabling full screen mode.

Mode MODE_EXCLUSIVE_FULLSCREEN = 4

A single window full screen mode. This mode has less overhead, but only one window can be open on a given screen at a time (opening a child window or application switching will trigger a full screen transition).

Full screen window covers the entire display area of a screen and has no border or decorations. The display's video mode is not changed.

Note: This mode might not work with screen recording software.

On Android: This enables immersive mode.

On Windows: Depending on video driver, full screen transition might cause screens to go black for a moment.

On macOS: A new desktop is used to display the running project. Exclusive full screen mode prevents Dock and Menu from showing up when the mouse pointer is hovering the edge of the screen.

On Linux (X11): Exclusive full screen mode bypasses compositor.

On Linux (Wayland): Equivalent to MODE_FULLSCREEN.

Note: Regardless of the platform, enabling full screen will change the window size to match the monitor's size. Therefore, make sure your project supports multiple resolutions when enabling full screen mode.


enum Flags: 🔗

Flags FLAG_RESIZE_DISABLED = 0

該視窗不能通過拖動其調整大小的手柄來調整大小。仍然可以使用 size 來調整視窗的大小。這個旗標對於全屏視窗來說是被忽略的。用 unresizable 設置。

Flags FLAG_BORDERLESS = 1

該視窗沒有原生標題列和其他裝飾。全屏視窗會忽略該旗標。由 borderless 設定。

Flags FLAG_ALWAYS_ON_TOP = 2

該視窗漂浮在所有其他視窗之上。全屏視窗會忽略該旗標。由 always_on_top 設定。

Flags FLAG_TRANSPARENT = 3

該視窗的背景可以是透明的。使用 transparent 設定。

注意:如果 ProjectSettings.display/window/per_pixel_transparency/allowed 或該視窗的 Viewport.transparent_bgfalse,則這個旗標無效。

Flags FLAG_NO_FOCUS = 4

該視窗無法被聚焦。無焦點視窗會忽略除滑鼠點擊之外的所有輸入。由 unfocusable 設定。

Flags FLAG_POPUP = 5

視窗為功能表或 OptionButton 下拉式功能表的一部分。視窗可見時無法更改這個旗標。活動的快顯視窗會以獨佔的形式接收所有輸入,但不會從其父視窗竊取焦點。使用者在區域外點擊或切換套用程式時,快顯視窗會自動關閉。快顯視窗必須設定臨時父級(見 transient)。

注意:這個旗標在嵌入式視窗中無效(除非該視窗是 Popup)。

Flags FLAG_EXTEND_TO_TITLE = 6

視窗內容擴充到視窗的全部尺寸。與無邊框視窗不同,框架保持不變,可以用來調整窗口的大小,標題列是透明的,但有最小/最大/關閉按鈕。用 extend_to_title 設定。

注意:這個旗標在 macOS 上實作。

注意:這個旗標在嵌入式視窗中無效。

Flags FLAG_MOUSE_PASSTHROUGH = 7

所有滑鼠事件都被傳遞到同一套用程式的底層視窗。

注意:這個旗標在嵌入式視窗中無效。

Flags FLAG_SHARP_CORNERS = 8

Window style is overridden, forcing sharp corners.

Note: This flag has no effect in embedded windows.

Note: This flag is implemented only on Windows (11).

Flags FLAG_EXCLUDE_FROM_CAPTURE = 9

Windows is excluded from screenshots taken by DisplayServer.screen_get_image(), DisplayServer.screen_get_image_rect(), and DisplayServer.screen_get_pixel().

Note: This flag has no effect in embedded windows.

Note: This flag is implemented on macOS and Windows (10, 20H1).

Note: Setting this flag will prevent standard screenshot methods from capturing a window image, but does NOT guarantee that other apps won't be able to capture an image. It should not be used as a DRM or security measure.

Flags FLAG_POPUP_WM_HINT = 10

Signals the window manager that this window is supposed to be an implementation-defined "popup" (usually a floating, borderless, untileable and immovable child window).

Flags FLAG_MINIMIZE_DISABLED = 11

Window minimize button is disabled.

Note: This flag is implemented on macOS and Windows.

Flags FLAG_MAXIMIZE_DISABLED = 12

Window maximize button is disabled.

Note: This flag is implemented on macOS and Windows.

Flags FLAG_MAX = 13

Flags 的最大值。


enum ContentScaleMode: 🔗

ContentScaleMode CONTENT_SCALE_MODE_DISABLED = 0

The content will not be scaled to match the Window's size (content_scale_size is ignored).

ContentScaleMode CONTENT_SCALE_MODE_CANVAS_ITEMS = 1

會將內容按照目標大小算繪。比 CONTENT_SCALE_MODE_VIEWPORT 更消耗性能,但結果更佳。

ContentScaleMode CONTENT_SCALE_MODE_VIEWPORT = 2

會將內容按照原始大小算繪,然後再縮放到目標大小。比 CONTENT_SCALE_MODE_CANVAS_ITEMS 性能更高,但會導致圖像的圖元化。


enum ContentScaleAspect: 🔗

ContentScaleAspect CONTENT_SCALE_ASPECT_IGNORE = 0

會忽略縱橫比。縮放就是簡單地將內容拉伸至目標大小。

ContentScaleAspect CONTENT_SCALE_ASPECT_KEEP = 1

會保留內容的縱橫比。如果目標大小與原始大小的縱橫比不同,則會將圖像居中,左右兩側會出現黑條。

ContentScaleAspect CONTENT_SCALE_ASPECT_KEEP_WIDTH = 2

內容可以垂直擴充。橫向縮放時,會保留寬度比,在左右兩側新增黑條。

ContentScaleAspect CONTENT_SCALE_ASPECT_KEEP_HEIGHT = 3

內容可以水平擴充。縱向縮放時,會保留高度比,在上下兩側新增黑條。

ContentScaleAspect CONTENT_SCALE_ASPECT_EXPAND = 4

會保留內容的縱橫比。如果目標大小與原始大小的縱橫比不同,則內容會保持在左上角,將拉伸出的空間增加為可見區域。


enum ContentScaleStretch: 🔗

ContentScaleStretch CONTENT_SCALE_STRETCH_FRACTIONAL = 0

內容將根據分數因子進行拉伸。這會填充視窗中的所有可用空間,但會由於像素縮放不均勻而導致出現“像素擺動”。

ContentScaleStretch CONTENT_SCALE_STRETCH_INTEGER = 1

內容將僅根據整數因子進行拉伸,保留銳利像素。這可能會在視窗邊緣留下可見的黑色背景,具體取決於視窗大小。


enum LayoutDirection: 🔗

LayoutDirection LAYOUT_DIRECTION_INHERITED = 0

自動佈局方向,由父視窗的佈局方向決定。

LayoutDirection LAYOUT_DIRECTION_APPLICATION_LOCALE = 1

自動佈局方向,根據目前語言環境確定。

LayoutDirection LAYOUT_DIRECTION_LTR = 2

從左至右的佈局方向。

LayoutDirection LAYOUT_DIRECTION_RTL = 3

從右至左的佈局方向。

LayoutDirection LAYOUT_DIRECTION_SYSTEM_LOCALE = 4

Automatic layout direction, determined from the system locale.

LayoutDirection LAYOUT_DIRECTION_MAX = 5

Represents the size of the LayoutDirection enum.

LayoutDirection LAYOUT_DIRECTION_LOCALE = 1

已棄用: Use LAYOUT_DIRECTION_APPLICATION_LOCALE instead.


enum WindowInitialPosition: 🔗

WindowInitialPosition WINDOW_INITIAL_POSITION_ABSOLUTE = 0

初始視窗位置由 position 決定。

WindowInitialPosition WINDOW_INITIAL_POSITION_CENTER_PRIMARY_SCREEN = 1

初始視窗位置為主螢幕的中心。

WindowInitialPosition WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN = 2

初始視窗位置為主視窗螢幕的中心。

WindowInitialPosition WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN = 3

初始視窗位置為 current_screen 螢幕的中心。

WindowInitialPosition WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_MOUSE_FOCUS = 4

初始視窗位置為滑鼠指標所在螢幕的中心。

WindowInitialPosition WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_KEYBOARD_FOCUS = 5

初始視窗位置為鍵盤聚焦的視窗所在螢幕的中心。


常數

NOTIFICATION_VISIBILITY_CHANGED = 30 🔗

Window 的可見性發生改變時,在 visibility_changed 之前發出。

NOTIFICATION_THEME_CHANGED = 32 🔗

當節點需要更新其主題項時發送。以下任意情況都會觸發:

  • 此節點或其任何祖先節點更改了 theme 屬性。

  • 此節點更改了 theme_type_variation 屬性。

  • 節點進入場景樹。

注意:為了優化性能,此節點在場景樹之外發生更改時不會發送此通知。取而代之的是,當節點進入場景樹時會均勻套用所有主題項的更新。


屬性說明

String accessibility_description = "" 🔗

  • void set_accessibility_description(value: String)

  • String get_accessibility_description()

The human-readable node description that is reported to assistive apps.


String accessibility_name = "" 🔗

  • void set_accessibility_name(value: String)

  • String get_accessibility_name()

The human-readable node name that is reported to assistive apps.


bool always_on_top = false 🔗

如果為 true,則該視窗將位於所有其他視窗的頂部。如果啟用了 transient 則不起作用。


bool auto_translate 🔗

  • void set_auto_translate(value: bool)

  • bool is_auto_translating()

已棄用: Use Node.auto_translate_mode and Node.can_auto_translate() instead.

切換是否所有文字都應該根據目前區域設定自動變為翻譯後的版本。


bool borderless = false 🔗

如果為 true,則該視窗將沒有邊框。


ContentScaleAspect content_scale_aspect = 0 🔗

指定當 Window 的大小改變時,內容縱橫比的行為。基礎縱橫比由 content_scale_size 決定。


float content_scale_factor = 1.0 🔗

  • void set_content_scale_factor(value: float)

  • float get_content_scale_factor()

Specifies the base scale of Window's content when its size is equal to content_scale_size. See also Viewport.get_stretch_transform().


ContentScaleMode content_scale_mode = 0 🔗

指定當 Window 的大小改變時,如何對內容進行縮放。


Vector2i content_scale_size = Vector2i(0, 0) 🔗

  • void set_content_scale_size(value: Vector2i)

  • Vector2i get_content_scale_size()

The content's base size in "virtual" pixels. Not to be confused with size, which sets the actual window's physical size in pixels. If set to a value greater than 0 and content_scale_mode is set to a value other than CONTENT_SCALE_MODE_DISABLED, the Window's content will be scaled when the window is resized to a different size. Higher values will make the content appear smaller, as it will be able to fit more of the project in view. On the root Window, this is set to match ProjectSettings.display/window/size/viewport_width and ProjectSettings.display/window/size/viewport_height by default.

For example, when using CONTENT_SCALE_MODE_CANVAS_ITEMS and content_scale_size set to Vector2i(1280, 720), using a window size of 2560×1440 will make 2D elements appear at double their original size, as the content is scaled by a factor of 2.0 (2560.0 / 1280.0 = 2.0, 1440.0 / 720.0 = 2.0).

See the Base size section of the Multiple resolutions documentation for details.


ContentScaleStretch content_scale_stretch = 0 🔗

用於確定 2D 元素的最終比例因子的策略。除了由 content_scale_size 確定的自動比例因子之外,這還會影響 content_scale_factor 的應用方式。


int current_screen 🔗

  • void set_current_screen(value: int)

  • int get_current_screen()

該視窗目前所在的螢幕。


bool exclude_from_capture = false 🔗

If true, the Window is excluded from screenshots taken by DisplayServer.screen_get_image(), DisplayServer.screen_get_image_rect(), and DisplayServer.screen_get_pixel().

Note: This property is implemented on macOS and Windows.

Note: Enabling this setting will prevent standard screenshot methods from capturing a window image, but does NOT guarantee that other apps won't be able to capture an image. It should not be used as a DRM or security measure.


bool exclusive = false 🔗

  • void set_exclusive(value: bool)

  • bool is_exclusive()

如果為 true,則 Window 將處於獨佔模式。獨佔視窗總是在其父視窗的頂部,會阻止所有輸入到達父級 Window

需要啟用 transient 才能正常工作。


bool extend_to_title = false 🔗

如果為 true,則 Window 的內容將會擴充到視窗的完整大小,視窗標題欄是透明的。

注意:這個屬性僅在 macOS 上實作。

注意:這個屬性僅對原生視窗有效。


bool force_native = false 🔗

  • void set_force_native(value: bool)

  • bool get_force_native()

If true, native window will be used regardless of parent viewport and project settings.


bool hdr_output_requested = false 🔗

  • void set_hdr_output_requested(value: bool)

  • bool is_hdr_output_requested()

If true, requests HDR output for the Window, falling back to SDR if not supported, and automatically switching between HDR and SDR as the window moves between screens, screen capabilities change, or system settings are modified. This will internally force Viewport.use_hdr_2d to be enabled on the main Viewport. All other SubViewport of this Window must have their Viewport.use_hdr_2d property enabled to produce HDR output.


WindowInitialPosition initial_position = 0 🔗

Specifies the initial type of position for the Window.


bool keep_title_visible = false 🔗

  • void set_keep_title_visible(value: bool)

  • bool get_keep_title_visible()

If true, the Window width is expanded to keep the title bar text fully visible.


Vector2i max_size = Vector2i(0, 0) 🔗

如果非零,則調整該 Window 的大小時無法大於該尺寸。

注意:如果值小於 min_size,該屬性將被忽略。


bool maximize_disabled = false 🔗

If true, the Window's maximize button is disabled.

Note: If both minimize and maximize buttons are disabled, buttons are fully hidden, and only close button is visible.

Note: This property is implemented only on macOS and Windows.


Vector2i min_size = Vector2i(0, 0) 🔗

如果非零,則調整該 Window 的大小時無法小於該尺寸。

注意:如果啟用了 wrap_controls 並且 get_contents_minimum_size() 更大,則此屬性將被忽略。


bool minimize_disabled = false 🔗

If true, the Window's minimize button is disabled.

Note: If both minimize and maximize buttons are disabled, buttons are fully hidden, and only close button is visible.

Note: This property is implemented only on macOS and Windows.


Mode mode = 0 🔗

  • void set_mode(value: Mode)

  • Mode get_mode()

設定該視窗的目前模式。

注意:在 Windows 和 Linux 上,全屏與獨佔全屏是不同的模式。

注意:這個方法僅對原生視窗有效,即主視窗和禁用主視口 Viewport.gui_embed_subwindows 時的 Window 衍生節點。


bool mouse_passthrough = false 🔗

如果為 true,則所有滑鼠事件都會傳遞給同一套用的底層視窗。另見 mouse_passthrough_polygon

注意:這個屬性在 Linux(X11)、macOS 和 Windows 上實作。

注意:這個屬性僅對原生視窗有效。


PackedVector2Array mouse_passthrough_polygon = PackedVector2Array() 🔗

Sets a polygonal region of the window which accepts mouse events. Mouse events outside the region will be passed through.

Passing an empty array will disable passthrough support (all mouse events will be intercepted by the window, which is the default behavior).

# Set region, using Path2D node.
$Window.mouse_passthrough_polygon = $Path2D.curve.get_baked_points()

# Set region, using Polygon2D node.
$Window.mouse_passthrough_polygon = $Polygon2D.polygon

# Reset region to default.
$Window.mouse_passthrough_polygon = []

Note: This property is ignored if mouse_passthrough is set to true.

Note: On Windows, the portion of a window that lies outside the region is not drawn, while on Linux (X11) and macOS it is.

Note: This property is implemented on Linux (X11), macOS and Windows.

Note: The returned array is copied and any changes to it will not update the original property value. See PackedVector2Array for more details.


Rect2i nonclient_area = Rect2i(0, 0, 0, 0) 🔗

  • void set_nonclient_area(value: Rect2i)

  • Rect2i get_nonclient_area()

If set, defines the window's custom decoration area which will receive mouse input, even if normal input to the window is blocked (such as when it has an exclusive child opened). See also nonclient_window_input.


bool popup_window = false 🔗

如果為 true,則該 Window 將被視為快顯視窗。快顯視窗是子視窗,不會在系統視窗管理器的視窗列表中顯示為單獨的視窗,並且會在按一下它們之外的任何位置時發送關閉請求(除非啟用了 exclusive)。


bool popup_wm_hint = false 🔗

If true, the Window will signal to the window manager that it is supposed to be an implementation-defined "popup" (usually a floating, borderless, untileable and immovable child window).


Vector2i position = Vector2i(0, 0) 🔗

該視窗的位置,單位為圖元。

如果 ProjectSettings.display/window/subwindows/embed_subwindowsfalse,則該位置使用螢幕絕對座標。通常適用於編輯器外掛程式。如果該設置項為 true,則該視窗的位置使用其父 Viewport 中的座標。

注意:這個屬性僅在 initial_positionWINDOW_INITIAL_POSITION_ABSOLUTE 時有效。


bool sharp_corners = false 🔗

If true, the Window will override the OS window style to display sharp corners.

Note: This property is implemented only on Windows (11).

Note: This property only works with native windows.


Vector2i size = Vector2i(100, 100) 🔗

The window's size in pixels. See also content_scale_size, which doesn't set the window's physical size but affects how scaling works relative to the current content_scale_mode.


Theme theme 🔗

該節點及其子 ControlWindow 所使用的 Theme 資源。如果子節點也設定了 Theme 資源,則會合並主題項,子節點的定義優先順序更高。

注意:除非 Window 為嵌入式,否則視窗樣式無效。


StringName theme_type_variation = &"" 🔗

Window 用於搜尋其自己的主題專案的主題型別變體的名稱。詳情見 Control.theme_type_variation


String title = "" 🔗

該視窗的標題。如果 Window 是原生的,則 Theme 中設定的標題樣式無效。


bool transient = false 🔗

  • void set_transient(value: bool)

  • bool is_transient()

如果為 true 則該 Window 是臨時視窗,即會被認為是另一個 Window 的子級。臨時視窗會和臨時父級一起銷毀,關閉時會將焦點返還給父級。臨時視窗顯示在非獨占全屏父視窗之上。臨時視窗無法進入全屏模式。

請注意,不同平臺可能由不同的行為。


bool transient_to_focused = false 🔗

  • void set_transient_to_focused(value: bool)

  • bool is_transient_to_focused()

If true, and the Window is transient, this window will (at the time of becoming visible) become transient to the currently focused window instead of the immediate parent window in the hierarchy. Note that the transient parent is assigned at the time this window becomes visible, so changing it afterwards has no effect until re-shown.


bool transparent = false 🔗

If true, the Window's background can be transparent. This is best used with embedded windows.

Note: Transparency support is implemented on Linux, macOS and Windows, but availability might vary depending on GPU driver, display manager, and compositor capabilities.

Note: This property has no effect if ProjectSettings.display/window/per_pixel_transparency/allowed is set to false.


bool unfocusable = false 🔗

如果為 true,則該 Window 既無法聚焦也無法互動,但仍然可見。


bool unresizable = false 🔗

If true, the window can't be resized.


bool visible = true 🔗

  • void set_visible(value: bool)

  • bool is_visible()

如果為 true,則該視窗可見。


bool wrap_controls = false 🔗

  • void set_wrap_controls(value: bool)

  • bool is_wrapping_controls()

如果為 true,則新增或刪除子節點時,視窗的大小會自動更新,新的大小更大時會忽略 min_size

如果為 false,則需要手動呼叫 child_controls_changed()


方法說明

Vector2 _get_contents_minimum_size() virtual const 🔗

可以被使用者重寫的虛方法。在匯出完成後被呼叫。


void add_theme_color_override(name: StringName, color: Color) 🔗

為名為 name 的主題 Color 建立本地覆蓋項。為控制項獲取主題時,本地覆蓋項始終優先。覆蓋項可以使用 remove_theme_color_override() 移除。

詳情請參閱 get_theme_color()Control.add_theme_color_override()


void add_theme_constant_override(name: StringName, constant: int) 🔗

為名稱為 name 的主題常數建立本地覆蓋項。為控制項獲取主題專案時,本地覆蓋項始終優先。覆蓋項可以使用 remove_theme_constant_override() 移除。

另見 get_theme_constant()


void add_theme_font_override(name: StringName, font: Font) 🔗

為名稱為 name 的主題 Font 建立本地覆蓋項。為控制項獲取主題專案時,本地覆蓋項始終優先。覆蓋項可以使用 remove_theme_font_override() 移除。

另見 get_theme_font()


void add_theme_font_size_override(name: StringName, font_size: int) 🔗

為名稱為 name 的主題字形大小建立本地覆蓋項。為控制項獲取主題專案時,本地覆蓋項始終優先。覆蓋項可以使用 remove_theme_font_size_override() 移除。

另見 get_theme_font_size()


void add_theme_icon_override(name: StringName, texture: Texture2D) 🔗

為名稱為 name 的主題圖示建立本地覆蓋項。為控制項獲取主題專案時,本地覆蓋項始終優先。覆蓋項可以使用 remove_theme_icon_override() 移除。

另見 get_theme_icon()


void add_theme_stylebox_override(name: StringName, stylebox: StyleBox) 🔗

為名為 name 的主題 StyleBox 建立本地覆蓋項。為控制項獲取主題時,本地覆蓋項始終優先。覆蓋項可以使用 remove_theme_stylebox_override() 移除。

詳情請參閱 get_theme_stylebox()Control.add_theme_stylebox_override()


void begin_bulk_theme_override() 🔗

防止 *_theme_*_override 方法發出 NOTIFICATION_THEME_CHANGED,直到 end_bulk_theme_override() 被呼叫。


bool can_draw() const 🔗

返回該視窗是否正在被繪製到螢幕上。


void child_controls_changed() 🔗

請求更新 Window 大小以適應底層 Control 節點。


void end_bulk_theme_override() 🔗

結束批量主題覆蓋更新。見 begin_bulk_theme_override()


Vector2 get_contents_minimum_size() const 🔗

Returns the combined minimum size from the child Control nodes of the window. Use child_controls_changed() to update it when child nodes have changed.

The value returned by this method can be overridden with _get_contents_minimum_size().


bool get_flag(flag: Flags) const 🔗

如果設定了旗標 flag,則返回 true


Window get_focused_window() static 🔗

Returns the focused window.


LayoutDirection get_layout_direction() const 🔗

返回排版方向和文字書寫方向。


float get_output_max_linear_value() const 🔗

Returns the maximum value for linear color components that can be displayed in this window, regardless of SDR or HDR output. Returns 1.0 if HDR is not enabled or not supported. The output_max_linear_value_changed signal will be emitted whenever this value changes.

This value is used by tonemapping and other Environment effects to ensure that bright colors are presented in the range that can be displayed by this window. When using this maximum linear value in your project, it should only be used to present colors directly to the screen without tonemapping and without influencing lighting, post-processing effects, or surrounding color. The following is an example that produces the brightest purple color that the screen can produce:

func _process(_delta):
    # output_max_linear_value may change often, so do this every frame.
    var max_linear_value = get_window().get_output_max_linear_value()
    # Replace this with your color:
    var original_color = Color.PURPLE
    # Normalize to max_linear_value to produce the brightest color possible,
    # regardless of SDR or HDR output:
    var bright_color = normalize_color(original_color, max_linear_value)


func normalize_color(srgb_color, max_linear_value = 1.0):
    # Color must be linear-encoded to use math operations.
    var linear_color = srgb_color.srgb_to_linear()
    var max_rgb_value = maxf(linear_color.r, maxf(linear_color.g, linear_color.b))
    var brightness_scale = max_linear_value / max_rgb_value
    linear_color *= brightness_scale
    # Undo changes to the alpha channel, which should not be modified.
    linear_color.a = srgb_color.a
    # Convert back to nonlinear sRGB encoding, which is required for Color in
    # Godot unless stated otherwise.
    return linear_color.linear_to_srgb()

Note: You will need to convert sRGB colors to linear before multiplying by this value to get correct results.


Vector2i get_position_with_decorations() const 🔗

Returns the window's position including its border.

Note: If visible is false, this method returns the same value as position.


Vector2i get_size_with_decorations() const 🔗

Returns the window's size including its border.

Note: If visible is false, this method returns the same value as size.


Color get_theme_color(name: StringName, theme_type: StringName = &"") const 🔗

從樹中第一個配對的 Theme 中返回 Color,該 Theme 中需要有名稱為 name 型別為 theme_type 的顏色專案。

詳情見 Control.get_theme_color()


int get_theme_constant(name: StringName, theme_type: StringName = &"") const 🔗

從樹中第一個配對的 Theme 中返回常數,該 Theme 中需要有名稱為 name 型別為 theme_type 的常數專案。

詳情見 Control.get_theme_color()


float get_theme_default_base_scale() const 🔗

從樹中第一個配對的 Theme 中返回預設基礎縮放,該 Theme 中需要具有有效的 Theme.default_base_scale 值。

詳情見 Control.get_theme_color()


Font get_theme_default_font() const 🔗

從樹中第一個配對的 Theme 中返回預設字形,該 Theme 中需要具有有效的 Theme.default_font 值。

詳情見 Control.get_theme_color()


int get_theme_default_font_size() const 🔗

從樹中第一個配對的 Theme 中返回預設字形大小,該 Theme 中需要具有有效的 Theme.default_font_size 值。

詳情見 Control.get_theme_color()


Font get_theme_font(name: StringName, theme_type: StringName = &"") const 🔗

從樹中第一個配對的 Theme 中返回 Font,該 Theme 中需要有名稱為 name 型別為 theme_type 的字形專案。

詳情見 Control.get_theme_color()


int get_theme_font_size(name: StringName, theme_type: StringName = &"") const 🔗

從樹中第一個配對的 Theme 中返回字形大小,該 Theme 中需要有名稱為 name 型別為 theme_type 的字形大小專案。

詳情見 Control.get_theme_color()


Texture2D get_theme_icon(name: StringName, theme_type: StringName = &"") const 🔗

從樹中第一個配對的 Theme 中返回圖示,該 Theme 中需要有名稱為 name 型別為 theme_type 的圖示專案。

詳情見 Control.get_theme_color()


StyleBox get_theme_stylebox(name: StringName, theme_type: StringName = &"") const 🔗

從樹中第一個配對的 Theme 中返回 StyleBox,該 Theme 中需要有名稱為 name 型別為 theme_type 的樣式盒專案。

詳情見 Control.get_theme_color()


int get_window_id() const 🔗

返回該視窗的 ID。


void grab_focus() 🔗

使該視窗獲得焦點,從而接收使用者輸入。


bool has_focus() const 🔗

如果該視窗已獲得焦點,則返回 true


bool has_theme_color(name: StringName, theme_type: StringName = &"") const 🔗

如果樹中存在配對的 Theme,具有指定名稱 name 和主題型別 theme_type 的顏色項,則返回 true

詳情見 Control.get_theme_color()


bool has_theme_color_override(name: StringName) const 🔗

如果該 Control 節點中存在名為指定 name 的主題 Color 本地覆蓋項,則返回 true

詳情請參閱 add_theme_color_override()


bool has_theme_constant(name: StringName, theme_type: StringName = &"") const 🔗

如果樹中存在配對的 Theme,具有指定名稱 name 和主題型別 theme_type 的常數項,則返回 true

詳情見 Control.get_theme_color()


bool has_theme_constant_override(name: StringName) const 🔗

如果該 Control 節點中存在名為指定 name 的主題常數本地覆蓋項,則返回 true

詳情請參閱 add_theme_constant_override()


bool has_theme_font(name: StringName, theme_type: StringName = &"") const 🔗

如果樹中存在配對的 Theme,具有指定名稱 name 和主題型別 theme_type 的字形項,則返回 true

詳情見 Control.get_theme_color()


bool has_theme_font_override(name: StringName) const 🔗

如果該 Control 節點中存在名為指定 name 的主題 Font 本地覆蓋項,則返回 true

詳情請參閱 add_theme_font_override()


bool has_theme_font_size(name: StringName, theme_type: StringName = &"") const 🔗

如果樹中存在配對的 Theme,具有指定名稱 name 和主題型別 theme_type 的字形大小項,則返回 true

詳情見 Control.get_theme_color()


bool has_theme_font_size_override(name: StringName) const 🔗

如果該 Control 節點中存在名為指定 name 的主題字形大小本地覆蓋項,則返回 true

詳情請參閱 add_theme_font_size_override()


bool has_theme_icon(name: StringName, theme_type: StringName = &"") const 🔗

如果樹中存在配對的 Theme,具有指定名稱 name 和主題型別 theme_type 的圖示項,則返回 true

詳情見 Control.get_theme_color()


bool has_theme_icon_override(name: StringName) const 🔗

如果該 Control 節點中存在名為指定 name 的主題圖示本地覆蓋項,則返回 true

詳情請參閱 add_theme_icon_override()


bool has_theme_stylebox(name: StringName, theme_type: StringName = &"") const 🔗

如果樹中存在配對的 Theme,具有指定名稱 name 和主題型別 theme_type 的樣式盒項,則返回 true

詳情見 Control.get_theme_color()


bool has_theme_stylebox_override(name: StringName) const 🔗

如果該 Control 節點中存在名為指定 name 的主題 StyleBox 本地覆蓋項,則返回 true

詳情請參閱 add_theme_stylebox_override()


void hide() 🔗

隱藏該視窗。與最小化狀態不同。隱藏視窗無法進行互動,需要用 show() 顯示。


bool is_embedded() const 🔗

如果該視窗目前嵌入在其他視窗中,則返回 true


bool is_layout_rtl() const 🔗

Returns true if the layout is right-to-left.


bool is_maximize_allowed() const 🔗

如果該視窗可以最大化(啟用了最大化按鈕),則返回 true


bool is_using_font_oversampling() const 🔗

如果啟用了字形過取樣,則返回 true。見 set_use_font_oversampling()


void move_to_center() 🔗

Centers the window in the current screen. If the window is embedded, it is centered in the embedder Viewport instead.


void move_to_foreground() 🔗

已棄用: Use grab_focus() instead.

使該視窗獲得焦點,從而接收使用者輸入。


void popup(rect: Rect2i = Rect2i(0, 0, 0, 0)) 🔗

Shows the Window and makes it transient (see transient). If rect is provided, it will be set as the Window's size. Fails if called on the main window.

If ProjectSettings.display/window/subwindows/embed_subwindows is true (single-window mode), rect's coordinates are global and relative to the main window's top-left corner (excluding window decorations). If rect's position coordinates are negative, the window will be located outside the main window and may not be visible as a result.

If ProjectSettings.display/window/subwindows/embed_subwindows is false (multi-window mode), rect's coordinates are global and relative to the top-left corner of the leftmost screen. If rect's position coordinates are negative, the window will be placed at the top-left corner of the screen.

Note: rect must be in global coordinates if specified.


void popup_centered(minsize: Vector2i = Vector2i(0, 0)) 🔗

在目前螢幕的中心彈出該 Window,可以選擇給定最小尺寸。如果該 Window 是嵌入的,它將在父 Viewport 中居中。

注意:minsize 的預設值呼叫它等同於用 size 呼叫它。


void popup_centered_clamped(minsize: Vector2i = Vector2i(0, 0), fallback_ratio: float = 0.75) 🔗

在父 Window 中居中彈出該 Windowfallback_ratio 確定 Window 相對於其父級的最大尺寸。

注意:minsize 的預設值呼叫它等同於用 size 呼叫它。


void popup_centered_ratio(ratio: float = 0.8) 🔗

如果 Window 為嵌入式視窗,則 Window 在彈出時會在嵌入器內居中,並按照嵌入器大小的比例 ratio 設定其大小。

如果 Window 為原生視窗,則 Window 在彈出時會在其父 Window 所在螢幕內居中,並按照螢幕大小的比例 ratio 設定其大小。


void popup_exclusive(from_node: Node, rect: Rect2i = Rect2i(0, 0, 0, 0)) 🔗

嘗試將該對話方塊的父節點設為最近的獨佔視窗,相對於 from_node,然後對其呼叫 popup()。對話方塊目前必須沒有父節點,否則該方法會失敗。

另見 set_unparent_when_invisible()Node.get_last_exclusive_window()


void popup_exclusive_centered(from_node: Node, minsize: Vector2i = Vector2i(0, 0)) 🔗

嘗試將該對話方塊的父節點設為最近的獨佔視窗,相對於 from_node,然後對其呼叫 popup_centered()。對話方塊目前必須沒有父節點,否則該方法會失敗。

另見 set_unparent_when_invisible()Node.get_last_exclusive_window()


void popup_exclusive_centered_clamped(from_node: Node, minsize: Vector2i = Vector2i(0, 0), fallback_ratio: float = 0.75) 🔗

嘗試將該對話方塊的父節點設為最近的獨佔視窗,相對於 from_node,然後對其呼叫 popup_centered_clamped()。對話方塊目前必須沒有父節點,否則該方法會失敗。

另見 set_unparent_when_invisible()Node.get_last_exclusive_window()


void popup_exclusive_centered_ratio(from_node: Node, ratio: float = 0.8) 🔗

嘗試將該對話方塊的父節點設為最近的獨佔視窗,相對於 from_node,然後對其呼叫 popup_centered_ratio()。對話方塊目前必須沒有父節點,否則該方法會失敗。

另見 set_unparent_when_invisible()Node.get_last_exclusive_window()


void popup_exclusive_on_parent(from_node: Node, parent_rect: Rect2i) 🔗

嘗試將該對話方塊的父節點設為最近的獨佔視窗,相對於 from_node,然後對其呼叫 popup_on_parent()。對話方塊目前必須沒有父節點,否則該方法會失敗。

另見 set_unparent_when_invisible()Node.get_last_exclusive_window()


void popup_on_parent(parent_rect: Rect2i) 🔗

彈出該 Window,位置會根據父級 Window 的位置進行偏移。如果該 Window 是內嵌的,則與 popup() 等效。


void remove_theme_color_override(name: StringName) 🔗

移除先前由 add_theme_color_override() 或透過屬性檢視器面板所加入,給定主題 Color 的本地覆寫,該覆寫使用指定的 name


void remove_theme_constant_override(name: StringName) 🔗

移除針對使用指定 name 的主題常數所設定的本機覆寫,該覆寫先前透過 add_theme_constant_override() 或屬性檢視器面板新增。


void remove_theme_font_override(name: StringName) 🔗

移除先前透過 add_theme_font_override() 或透過屬性檢視器面板新增的、名稱為指定 name 的主題 Font 本地覆寫。


void remove_theme_font_size_override(name: StringName) 🔗

移除使用指定的 name,先前由 add_theme_font_size_override() 或透過屬性檢視器面板新增的主題字型大小的本地覆寫。


void remove_theme_icon_override(name: StringName) 🔗

移除先前透過 add_theme_icon_override() 或屬性檢視器面板新增的、具有指定 name 的主題圖示本地覆寫。


void remove_theme_stylebox_override(name: StringName) 🔗

移除先前由 add_theme_stylebox_override() 或透過屬性檢視器面板新增的、具有指定 name 的主題 StyleBox 本地覆寫。


void request_attention() 🔗

告訴作業系統 Window 需要注意。這樣會讓該視窗以某種方式脫穎而出,具體形式取決於系統,例如可能會在工作列上閃爍。


void reset_size() 🔗

將大小重設為最小大小,即 min_size 和(wrap_controls 啟用時)get_contents_minimum_size() 之間的較大值。相當於呼叫 set_size(Vector2i())(或低於最小值的任何大小)。


void set_flag(flag: Flags, enabled: bool) 🔗

設定指定的視窗旗標。


void set_ime_active(active: bool) 🔗

如果 activetrue,則啟用系統的原生 IME(輸入法編輯器)。


void set_ime_position(position: Vector2i) 🔗

將 IME 移動到給定位置。


void set_layout_direction(direction: LayoutDirection) 🔗

設定佈局方向和文字書寫方向。某些語言需要從右至左的佈局(例如阿拉伯語和希伯來語)。


void set_taskbar_progress_state(state: ProgressState) 🔗

Sets the type and state of the progress bar on the taskbar/dock icon of the Window. See ProgressState for possible values and how each mode behaves.

Note: This method is implemented only on Windows and macOS.


void set_taskbar_progress_value(value: float) 🔗

Creates a progress bar on the taskbar/dock icon of the Window if it does not exist, sets the progress of the icon.

value acts as a relative percentage value, ranges from 0.0 (lowest) to 1.0 (highest).

Note: This method is implemented only on Windows and macOS.


void set_unparent_when_invisible(unparent: bool) 🔗

如果 unparenttrue,則視窗會在隱藏時自動解除與父節點的關係。

注意:請確保存在對該節點的引用,否則該節點會變為孤兒節點。沒有父節點時,你還需要手動呼叫 Node.queue_free() 來釋放該視窗。


void set_use_font_oversampling(enable: bool) 🔗

啟用字形過取樣。會使得字形在放大後更好看。


void show() 🔗

讓該 Window 出現。這樣會啟用與 Window 的互動,除了可見性之外不會更改其他任何屬性(與 popup() 不同)。


void start_drag() 🔗

Starts an interactive drag operation on the window, using the current mouse position. Call this method when handling a mouse button being pressed to simulate a pressed event on the window's title bar. Using this method allows the window to participate in space switching, tiling, and other system features.


void start_resize(edge: WindowResizeEdge) 🔗

Starts an interactive resize operation on the window, using the current mouse position. Call this method when handling a mouse button being pressed to simulate a pressed event on the window's edge.


主題屬性說明

Color title_color = Color(0.875, 0.875, 0.875, 1) 🔗

標題文字的顏色。


Color title_outline_modulate = Color(0, 0, 0, 1) 🔗

標題文字輪廓的顏色。


int close_h_offset = 18 🔗

Horizontal position offset of the close button, relative to the end of the title bar, towards the beginning of the title bar.


int close_v_offset = 24 🔗

Vertical position offset of the close button, relative to the bottom of the title bar, towards the top of the title bar.


int resize_margin = 4 🔗

定義了視窗邊框外側可以使用滑鼠抓取和調整大小的邊距。


int title_height = 36 🔗

標題列的高度。


int title_outline_size = 0 🔗

標題輪廓的尺寸。


Font title_font 🔗

用於繪製標題的字形。


int title_font_size 🔗

標題字形的大小。


Texture2D close 🔗

關閉按鈕的圖示。


Texture2D close_pressed 🔗

關閉按鈕被按下時的圖示。


StyleBox embedded_border 🔗

Window 為嵌入模式時使用的背景樣式。請注意,背景僅繪製在視窗內容的下方,不包括標題。要得到合適的邊框和標題列樣式,可以使用 StyleBoxFlatexpand_margin_* 屬性。

注意:只有在啟用 transparent 時,內容背景才會可見。


StyleBox embedded_unfocused_border 🔗

GraphNode 被選中時使用的背景。