add fancy animation to sidebar
parent
f2a0c006f3
commit
c955a2621b
2
Makefile
2
Makefile
|
@ -1,6 +1,8 @@
|
||||||
all: editor
|
all: editor
|
||||||
|
|
||||||
editor: src/*.odin grep odin_highlighter
|
editor: src/*.odin grep odin_highlighter
|
||||||
|
odin build src/ -out:bin/editor.o -build-mode:obj -debug
|
||||||
|
dsymutil bin/editor.o -o bin/editor.dw
|
||||||
odin build src/ -out:bin/editor -lld
|
odin build src/ -out:bin/editor -lld
|
||||||
|
|
||||||
odin_highlighter:
|
odin_highlighter:
|
||||||
|
|
|
@ -4,7 +4,9 @@ local BufferSearchOpenElapsed = 0
|
||||||
local CurrentPreviewBufferIndex = Editor.get_current_buffer_index()
|
local CurrentPreviewBufferIndex = Editor.get_current_buffer_index()
|
||||||
local BufferSearchIndex = 0
|
local BufferSearchIndex = 0
|
||||||
|
|
||||||
|
local SideBarSmoothedWidth = 128
|
||||||
local SideBarWidth = 128
|
local SideBarWidth = 128
|
||||||
|
local SideBarClosed = false
|
||||||
|
|
||||||
function buffer_list_iter()
|
function buffer_list_iter()
|
||||||
local idx = 0
|
local idx = 0
|
||||||
|
@ -30,13 +32,14 @@ function centered(ctx, label, axis, width, height, body)
|
||||||
UI.pop_parent(ctx)
|
UI.pop_parent(ctx)
|
||||||
end
|
end
|
||||||
|
|
||||||
function render_ui_window(ctx)
|
function lerp(from, to, rate)
|
||||||
current_buffer_index = Editor.get_current_buffer_index()
|
return (1 - rate) * from + rate*to
|
||||||
|
end
|
||||||
|
|
||||||
numFrames = 7
|
function ui_sidebar(ctx)
|
||||||
CurrentPreviewBufferIndex = current_buffer_index
|
SideBarSmoothedWidth = slerp(SideBarSmoothedWidth, SideBarWidth, 0.3)
|
||||||
|
|
||||||
tabs = UI.push_rect(ctx, "tabs", false, false, UI.Vertical, UI.Exact(SideBarWidth), UI.Fill)
|
tabs = UI.push_rect(ctx, "sidebar", false, false, UI.Vertical, UI.Exact(SideBarSmoothedWidth), UI.Fill)
|
||||||
UI.push_parent(ctx, tabs)
|
UI.push_parent(ctx, tabs)
|
||||||
UI.push_rect(ctx, "padded top open files", false, false, UI.Horizontal, UI.Fill, UI.Exact(8))
|
UI.push_rect(ctx, "padded top open files", false, false, UI.Horizontal, UI.Fill, UI.Exact(8))
|
||||||
UI.push_parent(ctx, UI.push_rect(ctx, "padded open files", false, false, UI.Horizontal, UI.Fill, UI.ChildrenSum))
|
UI.push_parent(ctx, UI.push_rect(ctx, "padded open files", false, false, UI.Horizontal, UI.Fill, UI.ChildrenSum))
|
||||||
|
@ -69,17 +72,39 @@ function render_ui_window(ctx)
|
||||||
UI.spacer(ctx, "below tabs spacer")
|
UI.spacer(ctx, "below tabs spacer")
|
||||||
|
|
||||||
UI.pop_parent(ctx)
|
UI.pop_parent(ctx)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ui_tabs(ctx)
|
||||||
|
UI.buffer(ctx, CurrentPreviewBufferIndex)
|
||||||
|
end
|
||||||
|
|
||||||
|
function render_ui_window(ctx)
|
||||||
|
current_buffer_index = Editor.get_current_buffer_index()
|
||||||
|
|
||||||
|
numFrames = 7
|
||||||
|
CurrentPreviewBufferIndex = current_buffer_index
|
||||||
|
|
||||||
|
if not SidebarClosed or SideBarSmoothedWidth > 2 then
|
||||||
|
ui_sidebar(ctx)
|
||||||
|
end
|
||||||
if UI.advanced_button(ctx, "side bar grab handle", {"DrawBorder", "Hoverable"}, UI.Exact(16), UI.Fill).dragging then
|
if UI.advanced_button(ctx, "side bar grab handle", {"DrawBorder", "Hoverable"}, UI.Exact(16), UI.Fill).dragging then
|
||||||
x,y = UI.get_mouse_pos(ctx)
|
x,y = UI.get_mouse_pos(ctx)
|
||||||
SideBarWidth = x-8
|
SideBarWidth = x-8
|
||||||
|
|
||||||
|
if SideBarWidth < 32 then
|
||||||
|
SidebarClosed = true
|
||||||
|
SideBarWidth = 0
|
||||||
|
elseif SideBarWidth > 128 then
|
||||||
|
SidebarClosed = false
|
||||||
|
end
|
||||||
|
|
||||||
-- TODO: use some math.max function
|
-- TODO: use some math.max function
|
||||||
if SideBarWidth < 128 then
|
if not SidebarClosed and SideBarWidth < 128 then
|
||||||
SideBarWidth = 128
|
SideBarWidth = 128
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
UI.buffer(ctx, CurrentPreviewBufferIndex)
|
|
||||||
|
|
||||||
|
ui_tabs(ctx)
|
||||||
render_buffer_search(ctx)
|
render_buffer_search(ctx)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,10 @@ iterate_file_buffer :: proc(it: ^FileBufferIter) -> (character: u8, idx: FileBuf
|
||||||
return character, it.cursor.index, true;
|
return character, it.cursor.index, true;
|
||||||
}
|
}
|
||||||
iterate_file_buffer_reverse_mangle_cursor :: proc(it: ^FileBufferIter) -> (character: u8, idx: FileBufferIndex, cond: bool) {
|
iterate_file_buffer_reverse_mangle_cursor :: proc(it: ^FileBufferIter) -> (character: u8, idx: FileBufferIndex, cond: bool) {
|
||||||
|
if len(it.buffer.content_slices[it.cursor.index.slice_index]) < 0 {
|
||||||
|
return character, idx, false;
|
||||||
|
}
|
||||||
|
|
||||||
character = it.buffer.content_slices[it.cursor.index.slice_index][it.cursor.index.content_index];
|
character = it.buffer.content_slices[it.cursor.index.slice_index][it.cursor.index.content_index];
|
||||||
if it.cursor.index.content_index == 0 {
|
if it.cursor.index.content_index == 0 {
|
||||||
if it.cursor.index.slice_index > 0 {
|
if it.cursor.index.slice_index > 0 {
|
||||||
|
@ -889,6 +893,10 @@ delete_content :: proc(buffer: ^FileBuffer, amount: int) {
|
||||||
amount := amount - len(buffer.input_buffer);
|
amount := amount - len(buffer.input_buffer);
|
||||||
runtime.clear(&buffer.input_buffer);
|
runtime.clear(&buffer.input_buffer);
|
||||||
|
|
||||||
|
if len(buffer.content_slices) < 1 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
split_content_slice(buffer);
|
split_content_slice(buffer);
|
||||||
|
|
||||||
it := new_file_buffer_iter_with_cursor(buffer, buffer.cursor);
|
it := new_file_buffer_iter_with_cursor(buffer, buffer.cursor);
|
||||||
|
@ -898,8 +906,9 @@ delete_content :: proc(buffer: ^FileBuffer, amount: int) {
|
||||||
|
|
||||||
for i in 0..<amount {
|
for i in 0..<amount {
|
||||||
content_slice_ptr := &buffer.content_slices[it.cursor.index.slice_index];
|
content_slice_ptr := &buffer.content_slices[it.cursor.index.slice_index];
|
||||||
|
content_slice_len := len(content_slice_ptr^);
|
||||||
|
|
||||||
if len(content_slice_ptr^) == 1 {
|
if content_slice_len == 1 {
|
||||||
// move cursor to previous content_slice so we can delete the current one
|
// move cursor to previous content_slice so we can delete the current one
|
||||||
iterate_file_buffer_reverse(&it);
|
iterate_file_buffer_reverse(&it);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue