SplitContainer

继承: Container < Control < CanvasItem < Node < Object

派生: HSplitContainer, VSplitContainer

A container that arranges child controls horizontally or vertically and provides grabbers for adjusting the split ratios between them.

描述

A container that arranges child controls horizontally or vertically and creates grabbers between them. The grabbers can be dragged around to change the size relations between the child controls.

教程

属性

bool

collapsed

false

bool

drag_area_highlight_in_editor

false

int

drag_area_margin_begin

0

int

drag_area_margin_end

0

int

drag_area_offset

0

DraggerVisibility

dragger_visibility

0

bool

dragging_enabled

true

int

split_offset

0

PackedInt32Array

split_offsets

PackedInt32Array(0)

bool

touch_dragger_enabled

false

bool

vertical

false

方法

void

clamp_split_offset(priority_index: int = 0)

Control

get_drag_area_control()

Array[Control]

get_drag_area_controls()

主题属性

Color

touch_dragger_color

Color(1, 1, 1, 0.3)

Color

touch_dragger_hover_color

Color(1, 1, 1, 0.6)

Color

touch_dragger_pressed_color

Color(1, 1, 1, 1)

int

autohide

1

int

minimum_grab_thickness

6

int

separation

12

Texture2D

grabber

Texture2D

h_grabber

Texture2D

h_touch_dragger

Texture2D

touch_dragger

Texture2D

v_grabber

Texture2D

v_touch_dragger

StyleBox

split_bar_background


信号

drag_ended() 🔗

用户结束拖拽时发出。


drag_started() 🔗

用户开始拖拽时发出。


dragged(offset: int) 🔗

Emitted when any dragger is dragged by user.


枚举

enum DraggerVisibility: 🔗

DraggerVisibility DRAGGER_VISIBLE = 0

autohidefalse 时,拆分拖动器始终可见,否则仅在鼠标在拖动器上悬停时可见。

拖动器图标的大小决定了最小间隔 separation

拖动器图标如果比拆分条长,就会自动隐藏。

DraggerVisibility DRAGGER_HIDDEN = 1

拆分拖动器图标始终不可见,无视 autohide 的值。

拖动器图标的大小决定了最小间隔 separation

DraggerVisibility DRAGGER_HIDDEN_COLLAPSED = 2

拆分拖动器图标不可见,拆分条粗细折叠为零。


属性说明

bool collapsed = false 🔗

  • void set_collapsed(value: bool)

  • bool is_collapsed()

If true, the draggers will be disabled and the children will be sized as if all split_offsets were 0.


bool drag_area_highlight_in_editor = false 🔗

  • void set_drag_area_highlight_in_editor(value: bool)

  • bool is_drag_area_highlight_in_editor_enabled()

高亮拖动区域 Rect2,便于在开发时查看位置。dragging_enabledtrue 时拖动区域为金色,为 false 时则为红色。


int drag_area_margin_begin = 0 🔗

  • void set_drag_area_margin_begin(value: int)

  • int get_drag_area_margin_begin()

减少可拖动区域和拆分条 split_bar_background 在容器起始侧的大小。


int drag_area_margin_end = 0 🔗

  • void set_drag_area_margin_end(value: int)

  • int get_drag_area_margin_end()

减少可拖动区域和拆分条 split_bar_background 在容器结尾侧的大小。


int drag_area_offset = 0 🔗

  • void set_drag_area_offset(value: int)

  • int get_drag_area_offset()

将拖动区域在容器轴向上进行偏移,防止拖动区域与 ScrollBar 或其他子节点的可选中 Control 发生重叠。


DraggerVisibility dragger_visibility = 0 🔗

决定拖动器是否可见。该属性无法决定拖动器是否启用,这一需求请使用 dragging_enabled


bool dragging_enabled = true 🔗

  • void set_dragging_enabled(value: bool)

  • bool is_dragging_enabled()

启用或禁用拆分拖拽。


int split_offset = 0 🔗

  • void set_split_offset(value: int)

  • int get_split_offset()

已弃用: Use split_offsets instead. The first element of the array is the split offset between the first two children.

The first element of split_offsets.


PackedInt32Array split_offsets = PackedInt32Array(0) 🔗

Offsets for each dragger in pixels. Each one is the offset of the split between the Control nodes before and after the dragger, with 0 being the default position. The default position is based on the Control nodes expand flags and minimum sizes. See Control.size_flags_horizontal, Control.size_flags_vertical, and Control.size_flags_stretch_ratio.

If none of the Control nodes before the dragger are expanded, the default position will be at the start of the SplitContainer. If none of the Control nodes after the dragger are expanded, the default position will be at the end of the SplitContainer. If the dragger is in between expanded Control nodes, the default position will be in the middle, based on the Control.size_flags_stretch_ratios and minimum sizes.

Note: If the split offsets cause Control nodes to overlap, the first split will take priority when resolving the positions.

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


bool touch_dragger_enabled = false 🔗

  • void set_touch_dragger_enabled(value: bool)

  • bool is_touch_dragger_enabled()

如果为 true,则会启用适合触控的拖动手柄,方便在小尺寸屏幕上使用。与标准抓取器不同,这个拖动手柄与 SplitContainer 的子节点存在重叠,不会影响它们的最小间隔。启用该选项时不再绘制标准抓取器。


bool vertical = false 🔗

  • void set_vertical(value: bool)

  • bool is_vertical()

如果为 true,则该 SplitContainer 会垂直排列其子代,而不是水平排列。

在使用 HSplitContainerVSplitContainer 时无法改变。


方法说明

void clamp_split_offset(priority_index: int = 0) 🔗

Clamps the split_offsets values to ensure they are within valid ranges and do not overlap with each other. When overlaps occur, this method prioritizes one split offset (at index priority_index) by clamping any overlapping split offsets to it.


Control get_drag_area_control() 🔗

已弃用: Use the first element of get_drag_area_controls() instead.

返回拖拽区域 Control。例如你可以把一个预先配置好的按钮放到拖拽区域 Control 中,这样这个按钮就会跟随拆分条移动。调用 reparent() 前请尝试将 Button 的锚点设置为 center

$BarnacleButton.reparent($SplitContainer.get_drag_area_control())

注意:拖拽区域 Control 绘制在 SplitContainer 的子节点之上,因此 Control 调用 CanvasItem 绘制方法所绘制的内容和添加至 Control 的子节点也会显示在 SplitContainer 的子节点之上。如果需要阻止鼠标拖动,请尝试将自定义子节点的 Control.mouse_filter 设置为 Control.MOUSE_FILTER_IGNORE

警告:这是必要的内部节点,将其移除或释放都可能造成崩溃。


Array[Control] get_drag_area_controls() 🔗

Returns an Array of the drag area Controls. These are the interactable Control nodes between each child. For example, this can be used to add a pre-configured button to a drag area Control so that it rides along with the split bar. Try setting the Button anchors to center prior to the Node.reparent() call.

$BarnacleButton.reparent($SplitContainer.get_drag_area_controls()[0])

Note: The drag area Controls are drawn over the SplitContainer's children, so CanvasItem draw objects called from a drag area and children added to it will also appear over the SplitContainer's children. Try setting Control.mouse_filter of custom children to Control.MOUSE_FILTER_IGNORE to prevent blocking the mouse from dragging if desired.

Warning: These are required internal nodes, removing or freeing them may cause a crash.


主题属性说明

Color touch_dragger_color = Color(1, 1, 1, 0.3) 🔗

触摸拖动器的颜色。


Color touch_dragger_hover_color = Color(1, 1, 1, 0.6) 🔗

触摸拖动器悬停状态的颜色。


Color touch_dragger_pressed_color = Color(1, 1, 1, 1) 🔗

触摸拖动器按下状态的颜色。


int autohide = 1 🔗

Boolean value. If 1 (true), the grabbers will hide automatically when they aren't under the cursor. If 0 (false), the grabbers are always visible. The dragger_visibility must be DRAGGER_VISIBLE.


int minimum_grab_thickness = 6 🔗

The minimum thickness of the area users can click on to grab a split bar. This ensures that the split bar can still be dragged if separation or h_grabber / v_grabber's size is too narrow to easily select.


int separation = 12 🔗

The split bar thickness, i.e., the gap between each child of the container. This is overridden by the size of the grabber icon if dragger_visibility is set to DRAGGER_VISIBLE, or DRAGGER_HIDDEN, and separation is smaller than the size of the grabber icon in the same axis.

Note: To obtain separation values less than the size of the grabber icon, for example a 1 px hairline, set h_grabber or v_grabber to a new ImageTexture, which effectively sets the grabber icon size to 0 px.


Texture2D grabber 🔗

The icon used for the grabbers drawn in the separations. This is only used in HSplitContainer and VSplitContainer. For SplitContainer, see h_grabber and v_grabber instead.


Texture2D h_grabber 🔗

The icon used for the grabbers drawn in the separations when vertical is false.


Texture2D h_touch_dragger 🔗

touch_dragger_enabledtrueverticalfalse 时拖拽手柄所使用的图标。


Texture2D touch_dragger 🔗

touch_dragger_enabledtrue 时用于拖放手柄的图标。仅在 HSplitContainerVSplitContainer 中使用。对于 SplitContainer,见 h_touch_draggerv_touch_dragger


Texture2D v_grabber 🔗

The icon used for the grabbers drawn in the separations when vertical is true.


Texture2D v_touch_dragger 🔗

touch_dragger_enabledtrueverticaltrue 时拖拽手柄所使用的图标。


StyleBox split_bar_background 🔗

决定拆分条厚度大于零时的背景。