Basic scroll bars
This commit is contained in:
@@ -34,6 +34,8 @@ struct Window {
|
|||||||
|
|
||||||
Range selection_anchor_point;
|
Range selection_anchor_point;
|
||||||
bool mouse_selecting;
|
bool mouse_selecting;
|
||||||
|
bool mouse_selecting_hori_bar;
|
||||||
|
bool mouse_selecting_vert_bar;
|
||||||
Vec2 scroll; // window_world_to_window_units
|
Vec2 scroll; // window_world_to_window_units
|
||||||
Cursor main_cursor_begin_frame;
|
Cursor main_cursor_begin_frame;
|
||||||
Array<Cursor> cursors;
|
Array<Cursor> cursors;
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ int main() {
|
|||||||
for (int i = 0; i < 50; i += 1) {
|
for (int i = 0; i < 50; i += 1) {
|
||||||
BeforeEdit(&window);
|
BeforeEdit(&window);
|
||||||
Array<Edit> edits = {FrameArena};
|
Array<Edit> edits = {FrameArena};
|
||||||
AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: %d\n", i));
|
AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number line number line number line number line number line number: %d\n", i));
|
||||||
ApplyEdits(&window, edits);
|
ApplyEdits(&window, edits);
|
||||||
AfterEdit(&window, edits);
|
AfterEdit(&window, edits);
|
||||||
}
|
}
|
||||||
@@ -124,6 +124,7 @@ int main() {
|
|||||||
float mouse_wheel = GetMouseWheelMove() * 48;
|
float mouse_wheel = GetMouseWheelMove() * 48;
|
||||||
focused_window->scroll.y -= mouse_wheel;
|
focused_window->scroll.y -= mouse_wheel;
|
||||||
focused_window->scroll.y = ClampBottom(focused_window->scroll.y, 0.f);
|
focused_window->scroll.y = ClampBottom(focused_window->scroll.y, 0.f);
|
||||||
|
focused_window->scroll.x = ClampBottom(focused_window->scroll.x, 0.f);
|
||||||
|
|
||||||
MergeCursors(focused_window);
|
MergeCursors(focused_window);
|
||||||
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_A)) {
|
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_A)) {
|
||||||
@@ -418,19 +419,76 @@ int main() {
|
|||||||
|
|
||||||
ForItem(window, windows) {
|
ForItem(window, windows) {
|
||||||
// Draw and layout window overlay
|
// Draw and layout window overlay
|
||||||
|
Vec2 mouse = GetMousePosition();
|
||||||
{
|
{
|
||||||
window.rect = window.start_rect;
|
window.rect = window.start_rect;
|
||||||
Rect2 horizontal_bar_rect = CutBottom(&window.rect, 10);
|
Rect2 horizontal_bar_rect = CutBottom(&window.rect, 10);
|
||||||
Rect2 vertical_bar_rect = CutRight(&window.rect, 10);
|
Rect2 vertical_bar_rect = CutRight(&window.rect, 10);
|
||||||
Rect2 line_numbers = CutLeft(&window.rect, 50);
|
Rect2 line_numbers = CutLeft(&window.rect, 50);
|
||||||
|
|
||||||
Rectangle rectangle_in_render_units = ToRectangle(window.rect);
|
DrawRectangleRec(ToRectangle(window.rect), WHITE);
|
||||||
DrawRectangleRec(rectangle_in_render_units, WHITE);
|
|
||||||
|
Vec2 size = GetSize(window.rect);
|
||||||
|
Vec2 min = window.scroll / window.layout.buffer_world_pixel_size;
|
||||||
|
Vec2 max = (window.scroll + size) / window.layout.buffer_world_pixel_size;
|
||||||
|
|
||||||
|
DrawRectangleRec(ToRectangle(vertical_bar_rect), GRAY);
|
||||||
|
{
|
||||||
|
float vert_size = GetSize(vertical_bar_rect).y;
|
||||||
|
float vert_begin = min.y * vert_size;
|
||||||
|
float vert_end = max.y * vert_size;
|
||||||
|
Rect2 rect = vertical_bar_rect;
|
||||||
|
rect.min.y = vert_begin;
|
||||||
|
rect.max.y = vert_end;
|
||||||
|
rect = Shrink(rect, 2);
|
||||||
|
DrawRectangleRec(ToRectangle(rect), LIGHTGRAY);
|
||||||
|
|
||||||
|
if (CheckCollisionPointRec(mouse, ToRectangle(vertical_bar_rect))) {
|
||||||
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||||
|
window.mouse_selecting_vert_bar = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.mouse_selecting_vert_bar) {
|
||||||
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) == false) {
|
||||||
|
window.mouse_selecting_vert_bar = false;
|
||||||
|
}
|
||||||
|
float value = GetMouseDelta().y / vert_size;
|
||||||
|
window.scroll.y += value * window.layout.buffer_world_pixel_size.y;
|
||||||
|
window.scroll.y = ClampBottom(window.scroll.y, 0.f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawRectangleRec(ToRectangle(horizontal_bar_rect), GRAY);
|
||||||
|
{
|
||||||
|
float hori_size = GetSize(horizontal_bar_rect).x;
|
||||||
|
float hori_begin = min.x * hori_size;
|
||||||
|
float hori_end = max.x * hori_size;
|
||||||
|
Rect2 rect = horizontal_bar_rect;
|
||||||
|
rect.min.x = hori_begin;
|
||||||
|
rect.max.x = hori_end;
|
||||||
|
rect = Shrink(rect, 2);
|
||||||
|
DrawRectangleRec(ToRectangle(rect), LIGHTGRAY);
|
||||||
|
|
||||||
|
if (CheckCollisionPointRec(mouse, ToRectangle(horizontal_bar_rect))) {
|
||||||
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||||
|
window.mouse_selecting_hori_bar = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.mouse_selecting_hori_bar) {
|
||||||
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) == false) {
|
||||||
|
window.mouse_selecting_hori_bar = false;
|
||||||
|
}
|
||||||
|
float value = GetMouseDelta().x / hori_size;
|
||||||
|
window.scroll.x += value * window.layout.buffer_world_pixel_size.x;
|
||||||
|
window.scroll.x = ClampBottom(window.scroll.x, 0.f);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mouse selection
|
// Mouse selection
|
||||||
{
|
if (!window.mouse_selecting_hori_bar && !window.mouse_selecting_vert_bar) {
|
||||||
Vec2 mouse = GetMousePosition();
|
|
||||||
bool mouse_in_window = CheckCollisionPointRec(mouse, ToRectangle(window.rect));
|
bool mouse_in_window = CheckCollisionPointRec(mouse, ToRectangle(window.rect));
|
||||||
if (!window.mouse_selecting && mouse_in_window) {
|
if (!window.mouse_selecting && mouse_in_window) {
|
||||||
SetMouseCursor(MOUSE_CURSOR_IBEAM);
|
SetMouseCursor(MOUSE_CURSOR_IBEAM);
|
||||||
|
|||||||
Reference in New Issue
Block a user