2024-05-13 13:07:49 -07:00
|
|
|
package sectr
|
|
|
|
|
|
|
|
UI_Floating :: struct {
|
|
|
|
label : string,
|
|
|
|
using links : DLL_NodePN(UI_Floating),
|
|
|
|
captures : rawptr,
|
|
|
|
builder : UI_FloatingBuilder,
|
|
|
|
queued : b32,
|
|
|
|
}
|
|
|
|
UI_FloatingBuilder :: #type proc( captures : rawptr ) -> (became_active : b32)
|
|
|
|
|
|
|
|
// Overlapping/Stacking window/frame manager
|
|
|
|
// AKA: Stacking or Floating Window Manager
|
|
|
|
UI_FloatingManager :: struct {
|
|
|
|
using links : DLL_NodeFL(UI_Floating),
|
|
|
|
build_queue : Array(UI_Floating),
|
2024-05-14 18:54:12 -07:00
|
|
|
tracked : HMapChainedPtr(UI_Floating),
|
2024-05-13 13:07:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ui_floating_startup :: proc( self : ^UI_FloatingManager, allocator : Allocator, build_queue_cap, tracked_cap : u64, dbg_name : string = "" ) -> AllocatorError
|
|
|
|
{
|
|
|
|
error : AllocatorError
|
|
|
|
|
|
|
|
queue_dbg_name := str_intern(str_fmt_tmp("%s: build_queue", dbg_name))
|
|
|
|
self.build_queue, error = array_init_reserve( UI_Floating, allocator, build_queue_cap, dbg_name = queue_dbg_name.str )
|
|
|
|
if error != AllocatorError.None
|
|
|
|
{
|
|
|
|
ensure(false, "Failed to allocate the build_queue")
|
|
|
|
return error
|
|
|
|
}
|
|
|
|
|
|
|
|
tracked_dbg_name := str_intern(str_fmt_tmp("%s: tracked", dbg_name))
|
2024-05-14 18:54:12 -07:00
|
|
|
self.tracked, error = hmap_chained_init(UI_Floating, uint(tracked_cap), allocator, dbg_name = tracked_dbg_name.str )
|
2024-05-13 13:07:49 -07:00
|
|
|
if error != AllocatorError.None
|
|
|
|
{
|
|
|
|
ensure(false, "Failed to allocate tracking table")
|
|
|
|
return error
|
|
|
|
}
|
|
|
|
return error
|
|
|
|
}
|
|
|
|
|
2024-05-14 08:47:44 -07:00
|
|
|
ui_floating_reload :: proc( self : ^UI_FloatingManager, allocator : Allocator )
|
|
|
|
{
|
|
|
|
using self
|
|
|
|
build_queue.backing = allocator
|
2024-05-14 18:54:12 -07:00
|
|
|
hmap_chained_reload(tracked, allocator)
|
2024-05-14 08:47:44 -07:00
|
|
|
}
|
|
|
|
|
2024-05-13 13:07:49 -07:00
|
|
|
ui_floating_just_builder :: #force_inline proc( label : string, builder : UI_FloatingBuilder ) -> ^UI_Floating
|
|
|
|
{
|
|
|
|
No_Captures : rawptr = nil
|
|
|
|
return ui_floating_with_capture(label, No_Captures, builder)
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_floating_with_capture :: proc( label : string, captures : rawptr = nil, builder : UI_FloatingBuilder ) -> ^UI_Floating
|
|
|
|
{
|
|
|
|
entry := UI_Floating {
|
|
|
|
label = label,
|
|
|
|
captures = captures,
|
|
|
|
builder = builder,
|
|
|
|
}
|
|
|
|
|
|
|
|
floating := get_state().ui_floating_context
|
|
|
|
array_append( & floating.build_queue, entry )
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
@(deferred_none = ui_floating_manager_end)
|
|
|
|
ui_floating_manager :: proc ( manager : ^UI_FloatingManager )
|
|
|
|
{
|
|
|
|
ui_floating_manager_begin(manager)
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_floating_manager_begin :: proc ( manager : ^UI_FloatingManager )
|
|
|
|
{
|
|
|
|
state := get_state()
|
|
|
|
state.ui_floating_context = manager
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_floating_manager_end :: proc()
|
|
|
|
{
|
|
|
|
state := get_state()
|
|
|
|
floating := & state.ui_floating_context
|
|
|
|
ui_floating_build()
|
|
|
|
floating = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_floating_build :: proc()
|
|
|
|
{
|
2024-05-15 15:48:20 -07:00
|
|
|
ui := ui_context()
|
2024-05-13 13:07:49 -07:00
|
|
|
using floating := get_state().ui_floating_context
|
|
|
|
|
2024-05-14 08:47:44 -07:00
|
|
|
for to_enqueue in array_to_slice( build_queue)
|
2024-05-13 13:07:49 -07:00
|
|
|
{
|
|
|
|
key := ui_key_from_string(to_enqueue.label)
|
2024-05-14 18:54:12 -07:00
|
|
|
lookup := hmap_chained_get( tracked, transmute(u64) key )
|
2024-05-13 13:07:49 -07:00
|
|
|
|
|
|
|
// Check if entry is already present
|
2024-05-15 00:34:52 -07:00
|
|
|
if lookup != nil && (lookup.next != nil || lookup == last) {
|
2024-05-13 13:07:49 -07:00
|
|
|
lookup.captures = to_enqueue.captures
|
|
|
|
lookup.builder = to_enqueue.builder
|
|
|
|
lookup.queued = true
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if lookup == nil {
|
|
|
|
error : AllocatorError
|
2024-05-14 18:54:12 -07:00
|
|
|
lookup, error = hmap_chained_set( tracked, transmute(u64) key, to_enqueue )
|
2024-05-13 13:07:49 -07:00
|
|
|
if error != AllocatorError.None {
|
|
|
|
ensure(false, "Failed to allocate entry to hashtable")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lookup.captures = to_enqueue.captures
|
|
|
|
lookup.builder = to_enqueue.builder
|
|
|
|
}
|
2024-05-15 00:34:52 -07:00
|
|
|
lookup.queued = true
|
2024-05-14 18:54:12 -07:00
|
|
|
if first == nil {
|
|
|
|
first = lookup
|
|
|
|
last = lookup
|
|
|
|
continue
|
|
|
|
}
|
2024-05-15 00:34:52 -07:00
|
|
|
if first == last {
|
|
|
|
last = lookup
|
|
|
|
last.prev = first
|
|
|
|
first.next = last
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
last.next = lookup
|
|
|
|
lookup.prev = last
|
|
|
|
last = lookup
|
2024-05-13 13:07:49 -07:00
|
|
|
}
|
|
|
|
array_clear(build_queue)
|
|
|
|
|
2024-05-15 00:34:52 -07:00
|
|
|
to_raise : ^UI_Floating
|
2024-05-13 13:07:49 -07:00
|
|
|
for entry := first; entry != nil; entry = entry.next
|
|
|
|
{
|
2024-05-15 00:34:52 -07:00
|
|
|
if ! entry.queued
|
2024-05-13 13:07:49 -07:00
|
|
|
{
|
2024-05-15 00:34:52 -07:00
|
|
|
ensure(false, "There should be no queue failures yet")
|
|
|
|
|
2024-05-13 13:07:49 -07:00
|
|
|
if entry == first
|
|
|
|
{
|
|
|
|
first = entry.next
|
|
|
|
entry.next = nil
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if entry == last
|
|
|
|
{
|
|
|
|
last = last.prev
|
|
|
|
last.prev = nil
|
|
|
|
entry.prev = nil
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
left := entry.prev
|
|
|
|
right := entry.next
|
|
|
|
|
|
|
|
left.next = right
|
|
|
|
right.prev = left
|
|
|
|
entry.prev = nil
|
|
|
|
entry.next = nil
|
|
|
|
}
|
|
|
|
|
2024-05-15 00:34:52 -07:00
|
|
|
if entry.builder( entry.captures ) && entry != last && to_raise == nil
|
2024-05-13 13:07:49 -07:00
|
|
|
{
|
2024-05-15 00:34:52 -07:00
|
|
|
to_raise = entry
|
2024-05-13 13:07:49 -07:00
|
|
|
}
|
2024-05-15 00:34:52 -07:00
|
|
|
entry.queued = false
|
|
|
|
}
|
|
|
|
if to_raise != nil
|
|
|
|
{
|
|
|
|
dll_full_pop( to_raise, floating )
|
|
|
|
dll_full_push_back( floating, to_raise, nil )
|
2024-05-13 13:07:49 -07:00
|
|
|
}
|
|
|
|
}
|