aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSan Jacobs2025-09-30 15:43:57 +0200
committerSan Jacobs2025-09-30 15:43:57 +0200
commit44c9db3ff6445cf9e58dd5f18a33a95581fbdd14 (patch)
treed8ae88496059fffc2fd94be0512e7a4fc67739c5
parent98880c8a886848889e4b5a6fc21a961fddf1e607 (diff)
downloadtafl-44c9db3ff6445cf9e58dd5f18a33a95581fbdd14.tar.gz
tafl-44c9db3ff6445cf9e58dd5f18a33a95581fbdd14.tar.bz2
tafl-44c9db3ff6445cf9e58dd5f18a33a95581fbdd14.zip
Slider improvements
-rw-r--r--src/main.odin56
-rw-r--r--src/tafl/tafl.odin15
2 files changed, 39 insertions, 32 deletions
diff --git a/src/main.odin b/src/main.odin
index 1f37461..7533cab 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -147,44 +147,50 @@ 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,
+ t.tafl(padding={2,2,2,2},
+ sizing_width=t.GROW)
+ t.tafl(sizing_width=t.GROW,
sizing_height=t.FIXED(30),
color={.1,.1,.1,1},
- padding={2,2,2,2},
+ padding={5,5,5,5},
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}
- }
+ position_horizontal=.END,
+ position_vertical=.END)
- 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),
+ com = t.tafl(sizing_width=t.FIXED(80),
sizing_height=t.GROW,
color={.5,.5,.5,1},
- padding={2,2,2,2})
+ padding={2,2,2,2},
+ 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_height=t.GROW,
sizing_width=t.GROW,
color=core_color)
}
}
+
+
+ {
+ t.tafl(sizing_width=t.FIXED(-slider_current),
+ sizing_height=t.GROW)
+ }
return com
}
diff --git a/src/tafl/tafl.odin b/src/tafl/tafl.odin
index 31be7e2..a83be1e 100644
--- a/src/tafl/tafl.odin
+++ b/src/tafl/tafl.odin
@@ -340,26 +340,27 @@ position_children :: proc(parent: ^Tafl) {
childrens_width += child.width
}
- left_offset : int = parent.x + parent.padding.left
+ left_offset : int = parent.x
switch parent.positioning.horizontal {
case .START:
- // nothing needs to be done
+ left_offset += parent.padding.left
case .MIDDLE:
left_offset += int(f64(parent.width - childrens_width) * 0.5)
case .END:
- left_offset += parent.width - childrens_width
+ left_offset += parent.width - childrens_width - parent.padding.left
}
for child in children_of(parent) {
child.x = left_offset
- child.y = parent.padding.top + parent.y
+ child.y = parent.y
switch parent.positioning.horizontal {
case .START:
+ child.y += parent.padding.top
// nothing
case .MIDDLE:
child.y += int(f64(parent.height - child.height) * 0.5)
case .END:
- child.y += parent.height - child.height
+ child.y += parent.height - child.height - parent.padding.top
}
left_offset += child.width + parent.child_gap
}
@@ -370,10 +371,10 @@ position_children :: proc(parent: ^Tafl) {
childrens_height += child.height
}
- top_offset : int = parent.y + parent.padding.top
+ top_offset : int = parent.y
switch parent.positioning.vertical {
case .START:
- // nothing needs to be done
+ top_offset += parent.padding.top
case .MIDDLE:
top_offset += int(f64(parent.height - childrens_height) * 0.5)
case .END: