Fix field resolution not resolving constant value properly

This commit is contained in:
Krzosa Karol
2024-06-10 08:45:58 +02:00
parent f8cf91ed2a
commit ff612d00ef
9 changed files with 66 additions and 39 deletions

View File

@@ -28,6 +28,10 @@ main :: proc(): int {
font_spacing: float = 1;
font: Font = LoadFontEx("C:/Windows/Fonts/consola.ttf", :int(font_size), nil, 0);
glyph_info: GlyphInfo = GetGlyphInfo(font, 'A');
size := MeasureTextEx(font, "A", font_size, font_spacing);
TE.Monosize = {:float(glyph_info.image.width), size.y};
SANDBOX_TEXT_EDITOR :: 1;
SANDBOX_PROTOTYPE :: 2;
sandbox_chosen := SANDBOX_PROTOTYPE;

View File

@@ -3,6 +3,7 @@ Perm: MA_Arena;
Transcripts: TranscriptStack;
SearchBar: TE.Buffer;
FilenamesBuffer: TE.Buffer;
ResultsBuffer: TE.Buffer;
UpdatePrototype :: proc(rect: Rect2P, font: Font, font_size: float, font_spacing: float) {
@@ -10,8 +11,6 @@ UpdatePrototype :: proc(rect: Rect2P, font: Font, font_size: float, font_spacing
Inited = true;
for iter := OS_IterateFiles(&Perm, S8("C:/video")); OS_IsValid(iter); OS_Advance(&iter) {
if S8_EndsWith(iter.absolute_path, S8(".srt"), true) {
printf("%.*s\n", :int(iter.absolute_path.len), iter.absolute_path.str);
file_content := OS_ReadFile(&Perm, iter.absolute_path);
PushTranscript(&Transcripts, {
absolute_path = STR(iter.absolute_path),
@@ -19,27 +18,21 @@ UpdatePrototype :: proc(rect: Rect2P, font: Font, font_size: float, font_spacing
}
}
for i := 0; i < Transcripts.len; i += 1 {
TE.ReplaceText(&FilenamesBuffer, {FilenamesBuffer.len, FilenamesBuffer.len}, Transcripts.data[i].absolute_path);
TE.ReplaceText(&FilenamesBuffer, {FilenamesBuffer.len, FilenamesBuffer.len}, "\n");
}
TE.ReplaceText(&ResultsBuffer, {ResultsBuffer.len, ResultsBuffer.len}, Transcripts.data[0].file_content);
TE.ReplaceText(&SearchBar, {SearchBar.len, SearchBar.len}, "");
TE.AddWindow({buffer = &SearchBar});
TE.AddWindow({buffer = &ResultsBuffer});
TE.AddWindow({buffer = &ResultsBuffer, flags = TE.WindowFlags_DrawScrollbar});
TE.FocusedWindow = &TE.WindowStack[0];
TE.FocusedWindow = nil;
}
for key := GetCharPressed(); key; key = GetCharPressed() {
selection_range := :TE.Range{0,0};
result: UTF8_Result = UTF32ToUTF8(:u32(key));
if result.error == 0 {
TE.ReplaceText(&SearchBar, selection_range, {:*char(&result.out_str[0]), result.len});
} else {
TE.ReplaceText(&SearchBar, selection_range, "?");
}
}
// Te.ComputeWindowRects(rect);
TE.WindowStack[0].rect = CutLeft(&rect, 0.5 * GetRectX(rect));
TE.WindowStack[0].rect = CutTop(&rect, font_size * 2);
TE.WindowStack[1].rect = CutLeft(&rect, 1.0 * GetRectX(rect));
TE.UpdateAndDrawWindows(font, font_size);

View File

@@ -14,11 +14,6 @@ WindowStackCount: int;
UpdateTextEditor :: proc(rect: Rect2P, font: Font, font_size: float, font_spacing: float) {
if !Inited {
Inited = true;
glyph_info: GlyphInfo = GetGlyphInfo(font, 'A');
size := MeasureTextEx(font, "A", font_size, font_spacing);
Monosize = {:float(glyph_info.image.width), size.y};
file_content := LoadFileText("C:/Work/language/examples/text_editor/entry_point/entry_point.lc");
AddText(&TeBuffer, {file_content, :int(strlen(file_content))});
UnloadFileText(file_content);
@@ -31,8 +26,13 @@ UpdateTextEditor :: proc(rect: Rect2P, font: Font, font_size: float, font_spacin
UpdateAndDrawWindows(font, font_size);
}
WindowFlags :: typedef u64;
WindowFlags_DrawScrollbar :: 1;
Window :: struct {
flags: WindowFlags;
buffer: *Buffer;
cursor: Selection;
scroll: Vector2;
mouse_scrolling: bool;
@@ -324,8 +324,7 @@ UpdateAndDrawWindow :: proc(w: *Window, font: Font, font_size: float) {
if (w.scroll.x < 0) w.scroll.x = 0;
if (w.scroll.y < 0) w.scroll.y = 0;
adjusted_kind_of_end := buffer_end_wpos.y - GetRectY(text_window_rect) * 0.8;
if (w.scroll.y > adjusted_kind_of_end) w.scroll.y = adjusted_kind_of_end;
if (w.scroll.y > buffer_end_wpos.y) w.scroll.y = buffer_end_wpos.y;
//
// Mouse