package main import "core:fmt" import t "tafl" BUTTON_SIZE : [2]int : {120, 40} main :: proc() { width, height : int = 1920, 1080 t.start_window(width, height, "tafl test") for !t.window_should_close() { if t.resized(){ width, height = t.get_window_size() } { t.tafl( // ROOT tafl width=width, height=height, layout=.LEFT_TO_RIGHT, color=colors.background, padding={5,5,5,5}, child_gap=5, ) { // Left bar t.tafl(color=colors.panel_blackground, width=BUTTON_SIZE.x*3 + 8*4, cut_from=.START, layout=.TOP_TO_BOTTOM, ) { t.tafl( height=BUTTON_SIZE.y+8*2, padding={8,8,8,8}, child_gap=8, color={.0, .0, .0, 0.4}, cut_from=.END, ) { if button("Yeet", "yeet").clicked { fmt.println("YEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEET!") } if button("Bawls", "bawls").clicked { fmt.println("Baaaaaaaaaaaawwwwwwwwwwwllllllls.") } if button("Render", "render").clicked { fmt.println("Reeeeeennnnnndeeeeeeeeeeeeeeeer!") } } } slider_h() } { // Right bar t.tafl(color=colors.panel_blackground, width=300, child_gap=20, layout=.TOP_TO_BOTTOM, cut_from=.END,) { {t.tafl(color={.5, .5, .5, 1}, height=50, )} {t.tafl(color={.5, .5, .5, 1}, height=50, )} {t.tafl(color={.5, .5, .5, 1}, height=50, cut_from=.END, )} {t.tafl(color={.5, .5, .8, 1}, )} } } { // Middle section big_square_size := 300 small_square_size := 200 total_size := big_square_size+small_square_size+5 t.tafl(color=colors.panel_blackground, layout=.TOP_TO_BOTTOM,) { t.tafl(height=total_size, layout=.TOP_TO_BOTTOM, align_children=.MIDDLE, cut_from=.MIDDLE, child_gap=5,) {// Red square (BIG) t.tafl(color={1,0,0,1}, width=big_square_size, height=big_square_size, padding={1,1,1,1},) { t.tafl(color={0,0,0,0.5},) } } {// Red square (Small) t.tafl(color={1,0,0,1}, width=small_square_size, height=small_square_size, padding={1,1,1,1},) { t.tafl(color={0,0,0,0.5},) } } } } } t.render() free_all(context.temp_allocator) } } button :: proc(text : string, id : string) -> t.Com { com := t.tafl(width=BUTTON_SIZE.x, height=BUTTON_SIZE.y, color=colors.button_outline, padding={2,2,2,2}, flags={.HIT_CHECK}, align_children=.MIDDLE, id=id) color : t.Color = {.1,.1,.1, 1} if com.hover do color = {.2,.2,.2, 1} if com.clicked || com.is_down do color = {.05,.05,.05, 1} t.tafl(color=color,) t.tafl(text=text, cut_from=.MIDDLE, width=0, height=0,) return com } slider_root : int = 0 slider_delta : int = 0 slider_current : int = 0 slider_grabbed : bool = false slider_output : f32 = 0 slider_h :: proc(id : string = "a_slider") { t.tafl( cut_from=.END, padding={2,2,2,2}, height=35, ) outer_com := t.tafl( layout=.LEFT_TO_RIGHT, color={.1,.1,.1,1}, padding={2,2,2,2} ) {// Space before t.tafl( width=slider_current, cut_from=.START) } {// Scroll handle com:=t.tafl( width=90, cut_from=.START, color={.4,.4,.4,1}, padding={2,2,2,2}, flags={.HIT_CHECK}, id=id, ) if com.pressed_down { slider_root = slider_current slider_grabbed = true } if t.mouse_left_released { slider_grabbed = false } slider_max := outer_com.tafl.width - com.tafl.width - outer_com.tafl.padding.left - outer_com.tafl.padding.right if slider_grabbed { slider_delta = t.mouse_position.x - t.mouse_left_press_position.x slider_current = slider_root + slider_delta slider_current = max(slider_current, 0) slider_current = min(slider_current, slider_max) slider_output = f32(slider_current)/f32(slider_max) fmt.printfln("slider_output: {}", slider_output) } color : t.Color = {.2,.2,.2,1} if com.hover do color={.3,.3,.3,1} if com.is_down do color={.13,.13,.13,1} t.tafl( color=color, ) } {// Area after t.tafl( width=slider_current, cut_from=.START) } } Color_Scheme :: struct { background : t.Color, panel_blackground : t.Color, panel_border : t.Color, button_outline : t.Color, } colors : Color_Scheme = { background = {.1, .1, .1, 1}, panel_blackground = {.2, .2, .2, 1}, panel_border = {.35, .35, .35, 1}, button_outline = {.1, .5, 1, 1}, } panel :: proc() { }