or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

camera-system.mdcore-graphics.mdgui-framework.mdindex.mdmath-utilities.mdphysics-engines.mdsound-system.mdspecialized-features.mdsprite-system.mdtexture-management.mdwindow-management.md

gui-framework.mddocs/

0

# GUI Framework

1

2

Complete user interface framework with widgets, layouts, event handling, styling, and theming for creating game menus, HUDs, and interactive interfaces.

3

4

## Capabilities

5

6

### Core GUI Classes

7

8

```python { .api }

9

class UIManager:

10

"""

11

Main UI manager for handling GUI elements, events, and rendering.

12

"""

13

def __init__(self, window: arcade.Window = None):

14

"""Create UI manager for window."""

15

16

def add(self, widget: arcade.gui.UIWidget) -> None:

17

"""Add widget to manager."""

18

19

def remove(self, widget: arcade.gui.UIWidget) -> None:

20

"""Remove widget from manager."""

21

22

def clear(self) -> None:

23

"""Remove all widgets."""

24

25

def on_draw(self) -> None:

26

"""Draw all widgets."""

27

28

def on_update(self, delta_time: float) -> None:

29

"""Update widgets."""

30

31

class UIView(arcade.View):

32

"""

33

View with built-in UI manager for easy GUI integration.

34

"""

35

def __init__(self):

36

super().__init__()

37

self.ui_manager = arcade.gui.UIManager()

38

39

class UIWidget:

40

"""

41

Base widget class for all GUI elements.

42

"""

43

def __init__(self, x: float = 0, y: float = 0, width: float = 100, height: float = 100):

44

"""Create base widget."""

45

46

x: float

47

y: float

48

width: float

49

height: float

50

visible: bool

51

52

def on_draw(self) -> None:

53

"""Draw the widget."""

54

55

def on_update(self, delta_time: float) -> None:

56

"""Update widget logic."""

57

58

class UIInteractiveWidget(UIWidget):

59

"""

60

Base class for interactive widgets that handle events.

61

"""

62

def on_click(self, event: arcade.gui.UIOnClickEvent) -> None:

63

"""Handle click events."""

64

65

def on_hover(self, event: arcade.gui.UIMouseEvent) -> None:

66

"""Handle hover events."""

67

```

68

69

### Button Widgets

70

71

```python { .api }

72

class UIFlatButton(UIInteractiveWidget):

73

"""

74

Flat-style button widget with text and click handling.

75

"""

76

def __init__(self, text: str = "Button", x: float = 0, y: float = 0,

77

width: float = 100, height: float = 50,

78

style: dict = None):

79

"""Create flat button."""

80

81

text: str

82

style: dict

83

84

def on_click(self, event: arcade.gui.UIOnClickEvent) -> None:

85

"""Handle button click."""

86

87

class UITextureButton(UIInteractiveWidget):

88

"""

89

Button widget using textures for different states.

90

"""

91

def __init__(self, x: float = 0, y: float = 0,

92

texture: arcade.Texture = None,

93

texture_hovered: arcade.Texture = None,

94

texture_pressed: arcade.Texture = None):

95

"""Create texture button."""

96

97

texture: arcade.Texture

98

texture_hovered: arcade.Texture

99

texture_pressed: arcade.Texture

100

```

101

102

### Layout Widgets

103

104

```python { .api }

105

class UILayout(UIWidget):

106

"""

107

Base layout widget for organizing child widgets.

108

"""

109

def add(self, widget: UIWidget) -> None:

110

"""Add child widget to layout."""

111

112

def remove(self, widget: UIWidget) -> None:

113

"""Remove child widget."""

114

115

class UIBoxLayout(UILayout):

116

"""

117

Linear layout (horizontal or vertical).

118

"""

119

def __init__(self, vertical: bool = True, align: str = "center", space_between: int = 0):

120

"""Create box layout."""

121

122

vertical: bool

123

align: str

124

space_between: int

125

126

class UIGridLayout(UILayout):

127

"""

128

Grid-based layout with rows and columns.

129

"""

130

def __init__(self, column_count: int = 1, row_count: int = 1):

131

"""Create grid layout."""

132

133

column_count: int

134

row_count: int

135

```

136

137

### Text Widgets

138

139

```python { .api }

140

class UILabel(UIWidget):

141

"""

142

Text label widget for displaying static text.

143

"""

144

def __init__(self, text: str = "Label", x: float = 0, y: float = 0,

145

font_name: str = "Arial", font_size: int = 16,

146

text_color: tuple = (255, 255, 255, 255)):

147

"""Create text label."""

148

149

text: str

150

font_name: str

151

font_size: int

152

text_color: tuple

153

154

class UIInputText(UIInteractiveWidget):

155

"""

156

Text input field for user text entry.

157

"""

158

def __init__(self, x: float = 0, y: float = 0, width: float = 200,

159

text: str = "", placeholder: str = ""):

160

"""Create text input."""

161

162

text: str

163

placeholder: str

164

cursor_position: int

165

166

def on_text(self, text: str) -> None:

167

"""Handle text input."""

168

```

169

170

### Event System

171

172

```python { .api }

173

class UIEvent:

174

"""Base UI event class."""

175

pass

176

177

class UIOnClickEvent(UIEvent):

178

"""Click event with position and button info."""

179

x: int

180

y: int

181

button: int

182

183

class UIOnChangeEvent(UIEvent):

184

"""Value change event for inputs."""

185

old_value: object

186

new_value: object

187

188

class UIMouseEvent(UIEvent):

189

"""Mouse event with position and movement."""

190

x: int

191

y: int

192

dx: int

193

dy: int

194

```

195

196

## Usage Examples

197

198

### Basic GUI Menu

199

200

```python

201

import arcade

202

import arcade.gui

203

204

class MenuView(arcade.gui.UIView):

205

def __init__(self):

206

super().__init__()

207

self.setup_ui()

208

209

def setup_ui(self):

210

# Create vertical layout

211

v_box = arcade.gui.UIBoxLayout(vertical=True, space_between=20)

212

213

# Title

214

title = arcade.gui.UILabel("Game Menu", font_size=32)

215

v_box.add(title)

216

217

# Buttons

218

start_button = arcade.gui.UIFlatButton("Start Game", width=200)

219

start_button.on_click = self.on_start_click

220

v_box.add(start_button)

221

222

options_button = arcade.gui.UIFlatButton("Options", width=200)

223

v_box.add(options_button)

224

225

quit_button = arcade.gui.UIFlatButton("Quit", width=200)

226

quit_button.on_click = self.on_quit_click

227

v_box.add(quit_button)

228

229

# Add layout to UI manager

230

self.ui_manager.add(v_box)

231

232

def on_start_click(self, event):

233

game_view = GameView()

234

self.window.show_view(game_view)

235

236

def on_quit_click(self, event):

237

arcade.exit()

238

239

def on_draw(self):

240

self.clear()

241

self.ui_manager.on_draw()

242

243

def main():

244

window = arcade.Window(800, 600, "GUI Example")

245

menu = MenuView()

246

window.show_view(menu)

247

arcade.run()

248

249

if __name__ == "__main__":

250

main()

251

```