Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion box.odin
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ box_set_style :: proc(box: ^Box, style: ^Box_Style_Override, use_transitions: bo

box_apply_style :: proc(box: ^Box, style: Box_Style_Override, use_transitions: bool = true) {
layout_box_apply_style(box, style, use_transitions)
}
}
Binary file added examples/assets/Lora.ttf
Binary file not shown.
File renamed without changes.
File renamed without changes.
76 changes: 8 additions & 68 deletions examples/counters.odin
Original file line number Diff line number Diff line change
@@ -1,54 +1,7 @@
package main

import syl "../"
import renderer "../renderer/raylib"
import "core:math/ease"
import "core:fmt"
import rl "vendor:raylib"

GREEN :: [4]u8{175,194,30, 255}
BLUE :: [4]u8{0, 0, 255, 255}
YELLOW :: [4]u8{255,255,40, 255}
WHITE :: [4]u8{255,255,255, 255}
BLACK :: [4]u8{0,0,0, 255}
BLANK :: [4]u8{0, 0, 0, 0}
RED :: [4]u8{255, 0, 0, 255}
DARK :: [4]u8{31,31,33, 255}
CELESTE :: [4]u8{80,99,132, 255}

SCREEN_W :: 800
SCREEN_H :: 500

style_sheet := syl.Style_Sheet {
box = {
padding = 0
},
button = {
normal = {
text_color = BLACK,
font_size = 18,
background_color = GREEN,
padding = {10,15,10,15},
border_radius = 8,
transitions = {
background_color = {0.05, .Linear},
},
},
hover = {
background_color = YELLOW,
},
press = {
background_color = GREEN,
transitions = syl.Box_Transitions{
background_color = {0, .Linear}
}
}
},
text = {
color = WHITE,
font_size = 18
}
}

primary_button := syl.Button_Styles_Override {
normal = {
Expand All @@ -72,7 +25,7 @@ primary_button := syl.Button_Styles_Override {
}
}

Message :: enum {
Message_Counter :: enum {
Increment,
Decrement
}
Expand All @@ -83,7 +36,7 @@ Counter :: struct {
counter_label: ^syl.Text,
}

counter_update:: proc(using counter: ^Counter, message: ^Message) {
counter_update:: proc(using counter: ^Counter, message: ^Message_Counter) {
switch message^ {
case .Increment: count += 1
case .Decrement: count -= 1
Expand All @@ -99,26 +52,22 @@ counter_destroy :: proc(counter: ^Counter) {
counter :: proc() -> ^Counter {
c := new(Counter)
syl.box(
handler = syl.make_handler(c, syl.Box, Message, counter_update, counter_destroy),
handler = syl.make_handler(c, syl.Box, Message_Counter, counter_update, counter_destroy),
layout_direction = .Left_To_Right,
gap = 10,
children = {
syl.button(text_content = "-", on_click = Message.Decrement, style=&primary_button),
syl.button(text_content = "-", on_click = Message_Counter.Decrement, style=&primary_button),
syl.box(
syl.text("0", ref = &c.counter_label),
sizing=syl.Expand,
),
syl.button(text_content = "+", on_click = Message.Increment),
syl.button(text_content = "+", on_click = Message_Counter.Increment),
}
)
return c
}

main :: proc() {
rl.SetConfigFlags({.MSAA_4X_HINT})
rl.InitWindow(SCREEN_W, SCREEN_H, "Syl in Raylib")
rl.SetTargetFPS(60)

counter_app :: proc () -> ^syl.Box{
app := syl.box(
counter(),
counter(),
Expand All @@ -131,15 +80,6 @@ main :: proc() {
gap=4,
)

renderer.init()
for !rl.WindowShouldClose() {
renderer.update(app)

rl.BeginDrawing()
rl.ClearBackground(cast(rl.Color)BLACK)
renderer.render(app)
rl.EndDrawing()
}

rl.CloseWindow()
return app
}

Loading