Skip to content

Commit 9fcd64b

Browse files
add raygui style example
1 parent 41b8958 commit 9fcd64b

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

examples/raygui/style_selector.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from pyray import *
2+
3+
screenWidth = 800
4+
screenHeight = 480
5+
6+
init_window(screenWidth, screenHeight, "raygui - styles selector")
7+
set_exit_key(0)
8+
9+
# TODO? fonts
10+
# font = LoadFontEx("fonts/custom_font.ttf", 12, 0, 0);
11+
# GuiSetFont(font)
12+
13+
exitWindow = False
14+
showMessageBox = False
15+
16+
# TODO? the styles that come with raggui
17+
# GuiLoadStyleBluish();
18+
visualStyleActive = ffi.new('int *', 0)
19+
prevVisualStyleActive = ffi.new('int *', 1)
20+
21+
set_target_fps(60)
22+
23+
while not exitWindow:
24+
exitWindow = window_should_close()
25+
26+
if is_key_pressed(KeyboardKey.KEY_ESCAPE):
27+
showMessageBox = not showMessageBox
28+
29+
if is_file_dropped():
30+
droppedFiles = load_dropped_files()
31+
32+
if (droppedFiles.count > 0) and is_file_extension(droppedFiles.paths[0], ".rgs"):
33+
gui_load_style(droppedFiles.paths[0])
34+
35+
unload_dropped_files(droppedFiles)
36+
37+
38+
if visualStyleActive[0] != prevVisualStyleActive[0]:
39+
gui_load_style_default()
40+
match visualStyleActive[0]:
41+
case 0:
42+
gui_set_style(GuiControl.DEFAULT, GuiDefaultProperty.BACKGROUND_COLOR, 0x000000FF) # black
43+
gui_set_style(GuiControl.DEFAULT, GuiDefaultProperty.LINE_COLOR, 0x00FF00FF) # green
44+
case 1:
45+
gui_set_style(GuiControl.DEFAULT, GuiDefaultProperty.BACKGROUND_COLOR, 0xF5F5F5FF) # white
46+
gui_set_style(GuiControl.DEFAULT, GuiDefaultProperty.LINE_COLOR, 0xFF0000FF) # red
47+
case 2:
48+
gui_set_style(GuiControl.DEFAULT, GuiDefaultProperty.BACKGROUND_COLOR, 0xFF0000FF) # red
49+
gui_set_style(GuiControl.DEFAULT, GuiDefaultProperty.LINE_COLOR, 0x0000FFFF) # blue
50+
51+
prevVisualStyleActive[0] = visualStyleActive[0]
52+
53+
begin_drawing()
54+
55+
style = gui_get_style(GuiControl.DEFAULT, GuiDefaultProperty.BACKGROUND_COLOR)
56+
clear_background(get_color(style))
57+
58+
gui_label((10, 10, 60, 24 ), "Style:")
59+
gui_label((200, 10, 160, 24 ), f"hex code: {hex(style)}")
60+
gui_combo_box((60,10, 120, 24 ), "black;whitish;red", visualStyleActive)
61+
62+
draw_rectangle(10, 44, gui_get_font().texture.width, gui_get_font().texture.height, BLACK)
63+
draw_texture(gui_get_font().texture, 10, 44, WHITE)
64+
draw_rectangle_lines(10, 44, gui_get_font().texture.width, gui_get_font().texture.height,
65+
get_color(gui_get_style(GuiControl.DEFAULT, GuiDefaultProperty.LINE_COLOR)))
66+
67+
68+
end_drawing()
69+
close_window()

0 commit comments

Comments
 (0)