2024-03-08 16:51:46 -08:00
|
|
|
package sectr
|
|
|
|
|
|
|
|
import "core:math/linalg"
|
|
|
|
|
|
|
|
test_hover_n_click :: proc()
|
|
|
|
{
|
|
|
|
state := get_state(); using state
|
|
|
|
|
|
|
|
first_btn := ui_button( "FIRST BOX!" )
|
|
|
|
if first_btn.left_clicked || debug.frame_2_created {
|
|
|
|
debug.frame_2_created = true
|
|
|
|
|
|
|
|
second_layout := first_btn.style.layout
|
|
|
|
second_layout.pos = { 250, 0 }
|
|
|
|
ui_set_layout( second_layout )
|
|
|
|
|
|
|
|
second_box := ui_button( "SECOND BOX!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test_draggable :: proc()
|
|
|
|
{
|
|
|
|
state := get_state(); using state
|
|
|
|
ui := ui_context
|
|
|
|
|
2024-03-09 10:55:47 -08:00
|
|
|
draggable := ui_widget( "Draggable Box!", UI_BoxFlags { .Mouse_Clickable, .Mouse_Resizable } )
|
2024-03-08 16:51:46 -08:00
|
|
|
if draggable.first_frame {
|
|
|
|
debug.draggable_box_pos = draggable.style.layout.pos
|
|
|
|
debug.draggable_box_size = draggable.style.layout.size
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dragging
|
|
|
|
if draggable.dragging {
|
|
|
|
debug.draggable_box_pos += mouse_world_delta()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resize
|
|
|
|
if draggable.resizing
|
|
|
|
{
|
|
|
|
og_layout := ui_context.active_start_style.layout
|
|
|
|
|
|
|
|
center := debug.draggable_box_pos
|
2024-03-09 10:55:47 -08:00
|
|
|
original_distance := linalg.distance(ui.active_start_signal.cursor_pos, center)
|
2024-03-08 16:51:46 -08:00
|
|
|
cursor_distance := linalg.distance(draggable.cursor_pos, center)
|
|
|
|
scale_factor := cursor_distance * (1 / original_distance)
|
|
|
|
|
|
|
|
debug.draggable_box_size = og_layout.size * scale_factor
|
|
|
|
}
|
|
|
|
|
2024-03-09 10:55:47 -08:00
|
|
|
if (ui.hot == draggable.key) && (ui.hot_resizable || ui.active_start_signal.resizing) {
|
2024-03-08 16:51:46 -08:00
|
|
|
draggable.style.bg_color = Color_Blue
|
|
|
|
}
|
|
|
|
|
|
|
|
draggable.style.layout.pos = debug.draggable_box_pos
|
|
|
|
draggable.style.layout.size = debug.draggable_box_size
|
|
|
|
}
|