aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.odin69
-rw-r--r--src/tafl/tafl.odin47
2 files changed, 109 insertions, 7 deletions
diff --git a/src/main.odin b/src/main.odin
index ead0e83..1f37461 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -32,7 +32,9 @@ main :: proc() {
{
t.tafl(color={0,0,0,0},
sizing_height=t.GROW,
- sizing_width=t.GROW)}
+ sizing_width=t.GROW)
+ }
+ slider()
{
t.tafl(
padding={8,8,8,8},
@@ -40,9 +42,15 @@ main :: proc() {
color={.0, .0, .0, 0.4},
)
{
- if button("Yeet", "yeet").clicked do fmt.println("YEEET!")
- if button("Test", "test").clicked do fmt.println("Test!")
- if button("Render", "render").clicked do fmt.println("Render!")
+ if button("Yeet", "yeet").clicked {
+ fmt.println("YEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEET!")
+ }
+ if button("Bawls", "bawls").clicked {
+ fmt.println("Baaaaaaaaaaaawwwwwwwwwwwllllllls.")
+ }
+ if button("Render", "render").clicked {
+ fmt.println("Reeeeeennnnnndeeeeeeeeeeeeeeeer!")
+ }
}
}
@@ -120,18 +128,67 @@ button :: proc(text : string, id : string) -> t.Com {
padding={2,2,2,2},
flags=t.BUTTON,
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}
+ if com.hover do color = {.2,.2,.2, 1}
+ if com.clicked || com.is_down do color = {.05,.05,.05, 1}
t.tafl(sizing_width=t.GROW,
sizing_height=t.GROW,
color=color,
position_horizontal=.MIDDLE,
position_vertical=.MIDDLE,)
+
t.tafl(text=text)
return com
}
+slider_root : int = 0
+slider_delta : int = 0
+slider_current : int = 0
+slider :: proc(id : string = "a_slider") -> t.Com {
+ com : t.Com
+ com = t.tafl(sizing_width=t.GROW,
+ sizing_height=t.FIXED(30),
+ color={.1,.1,.1,1},
+ padding={2,2,2,2},
+ layout=.LEFT_TO_RIGHT,
+ flags={.DRAGGABLE, .CLICKABLE, .HOVERABLE},
+ id=id)
+
+ core_color : t.Color = {.2,.2,.2,1}
+ if com.hover {
+ core_color = {.3,.3,.3,1}
+ }
+
+ if com.pressed_down {
+ slider_root = slider_root+slider_delta
+ }
+ if com.dragging {
+ core_color = {.12,.12,.12,1}
+ fmt.println(com.drag_delta)
+ slider_delta = com.drag_delta.x
+ slider_current = slider_root+slider_delta
+ fmt.println(slider_current)
+ }
+
+ {t.tafl(sizing_width=t.FIXED(slider_current),
+ sizing_height=t.GROW)
+ }
+ {
+ t.tafl(sizing_width=t.FIXED(80),
+ sizing_height=t.GROW,
+ color={.5,.5,.5,1},
+ padding={2,2,2,2})
+ {
+ t.tafl(sizing_height=t.GROW,
+ sizing_width=t.GROW,
+ color=core_color)
+ }
+ }
+ return com
+}
+
+
Color_Scheme :: struct {
background : t.Color,
panel_blackground : t.Color,
diff --git a/src/tafl/tafl.odin b/src/tafl/tafl.odin
index 993a231..31be7e2 100644
--- a/src/tafl/tafl.odin
+++ b/src/tafl/tafl.odin
@@ -24,6 +24,12 @@ scissor_stack : [1024]Box
mouse_position : [2]int
+tafl_cache : map[string]Tafl_Cache
+
+dragging_id : string = ""
+drag_root : [2]int
+drag_delta : [2]int
+
mouse_left_pressed := false
mouse_left_is_down := false
mouse_left_released := false
@@ -172,6 +178,8 @@ tafl_open :: proc(
}
}
}
+ output_com.pressed_down = mouse_left_pressed && clicked_pressed_id != "" && clicked_pressed_id == this_tafl.id
+ output_com.press_released = mouse_left_released && clicked_release_id != "" && clicked_release_id == this_tafl.id
}
if .HOVERABLE in flags {
if hovered_id == this_tafl.id {
@@ -181,6 +189,17 @@ tafl_open :: proc(
}
}
}
+ if .DRAGGABLE in flags {
+ if dragging_id != "" {
+ if dragging_id == this_tafl.id {
+ output_com.dragging = true
+ if mouse_left_is_down && dragging_id == this_tafl.id {
+ output_com.drag_root = drag_root
+ output_com.drag_delta = drag_delta
+ }
+ }
+ }
+ }
return output_com
}
@@ -536,6 +555,23 @@ process_features :: proc() {
}
}
+
+ if .DRAGGABLE in tafl.flags {
+ if mouse_left_pressed {
+ if collide(mouse_position, tafl) {
+ drag_root = mouse_position
+ dragging_id = strings.clone(tafl.id)
+ }
+ }
+ if mouse_left_is_down && dragging_id==tafl.id {
+ drag_delta = mouse_position-drag_root
+ }
+ if mouse_left_released && dragging_id==tafl.id {
+ delete(dragging_id)
+ dragging_id = ""
+ drag_delta = mouse_position-drag_root
+ }
+ }
}
if !something_is_hovered {
@@ -607,19 +643,28 @@ Tafl :: struct {
hover_t : f32,
press_t : f32,
}
+Tafl_Cache :: struct{
+ hover_t : f32,
+ press_t : f32,
+}
Feature_Flag :: enum {
CLICKABLE,
HOVERABLE,
+ DRAGGABLE,
}
Feature_Flags :: bit_set[Feature_Flag]
Com :: struct {
__tafl_index : int,
clicked : bool,
+ press_released : bool,
+ pressed_down : bool,
hover : bool,
is_down : bool,
- press_root : [2]int,
+ dragging : bool,
+
+ drag_root : [2]int,
drag_delta : [2]int,
hover_t : f32,