gl.bindTexture(gl.TEXTURE_2D, -1);
}
+ test_window.size = .{ 800, 800 };
+ test_window.border_width = 8.0f;
+ test_window.border_color = config.Colors.primary;
+ test_window.background_color = config.Colors.dark_background;
+ test_window.active_color = config.Colors.background;
+
load_colors :: () {
json :: package json
}
update :: (dt: f32) {
+ t += dt;
}
+t := 0.0f;
+test_window : ui.Window_State;
+
draw :: () {
bg_color := config.Colors.background;
gl.clearColor(bg_color.r, bg_color.g, bg_color.b, bg_color.a);
menu_bar, main_area := ui.Flow.split_horizontal(window_rectangle, top_height=32);
ui.workspace_start(main_area);
-
draw_background_lines(~~window_width, ~~window_height, line_color=config.Colors.background);
- if ui.button(.{ 200, 300, 500, 400 }, "Test Button") do search_buffer.count = 0;
- ui.textbox(.{ 200, 400, 500, 450 }, ^search_buffer);
+ ui.draw_rect(0, 0, 20, 20, color=.{1,0,0});
+
+ {
+ test_window.position = .{ 200, 200 };
+
+ ui.window_start(^test_window);
+ defer ui.window_end();
+
+ if ui.button(.{ 0, 0, 400, 300 }, "Top-Left") do search_buffer.count = 0;
+ ui.textbox(.{ 0, 300, 400, 350 }, ^search_buffer);
+ }
ui.workspace_end();
--- /dev/null
+package ui
+#private_file map :: package core.map
+
+// This will be stored by the end user's library.
+Window_State :: struct {
+ position: gfx.Vector2;
+ size: gfx.Vector2;
+
+ border_width := 4.0f;
+ border_color := gfx.Color4.{ 1, 0, 0 };
+ background_color := gfx.Color4.{ 0.2, 0.2, 0.2 };
+ active_color := gfx.Color4.{ 0.3, 0.3, 0.3 };
+
+ get_rectangle :: (use w: ^Window_State) -> Rectangle {
+ return .{ position.x, position.y, position.x + size.x, position.y + size.y };
+ }
+}
+
+// I don't know if this needs the site and increment parameters
+window_start :: (use state: ^Window_State, site := #callsite, increment := 0) {
+
+ hash := get_site_hash(site, increment);
+ animation_state := map.get(^animation_states, hash);
+
+ mx, my := get_mouse_position();
+ contained := false;
+ if state->get_rectangle() |> Rectangle.contains(mx, my) {
+ contained = true;
+ }
+
+ if contained {
+ move_towards(^animation_state.hover_time, 1.0f, 0.06);
+ } else {
+ move_towards(^animation_state.hover_time, 0.0f, 0.06);
+ }
+
+ x, y := position.x + border_width, position.y + border_width;
+ w, h := size.x - border_width * 2, size.y - border_width * 2;
+
+ bg_color := color_lerp(animation_state.hover_time, background_color, active_color);
+ draw_rect(position.x, position.y, size.x, size.y, color=border_color);
+ draw_rect(x, y, w, h, bg_color);
+
+ if animation_state.click_time > 0 || animation_state.hover_time > 0 {
+ map.put(^animation_states, hash, animation_state);
+ } else {
+ map.delete(^animation_states, hash);
+ }
+
+ gfx.push_scissor(x, y, w, h);
+ gfx.push_matrix();
+ gfx.apply_transform(.{ translation = position, scale = .{ 1, 1 } });
+}
+
+window_end :: () {
+ gfx.pop_scissor();
+ gfx.pop_matrix();
+}
\ No newline at end of file