global_renderer->set_window_size(width, height);
}
+get_window_size :: () -> (width: i32, height: i32) {
+ return global_renderer.window_width, global_renderer.window_height;
+}
+
push_matrix :: () do global_renderer->push_matrix();
pop_matrix :: () do global_renderer->pop_matrix();
identity :: () do global_renderer->identity();
--- /dev/null
+package ui
+
+use package core
+
+#private_file
+Scrollable_Region_State :: struct {
+ transform: gfx.Transform = .{
+ translation = .{ 0, 0 },
+ scale = .{ 1, 1 },
+ };
+}
+
+#private
+scrollable_region_states : map.Map(UI_Id, Scrollable_Region_State);
+
+scrollable_region_start :: (use r: Rectangle, x_scroll: ^f32, y_scroll: ^f32, site := #callsite) {
+ hash := get_site_hash(site, 0);
+ x, y := Rectangle.top_left(r);
+ width, height := Rectangle.dimensions(r);
+
+ state := map.get(^scrollable_region_states, hash);
+
+ mx, my := get_mouse_position();
+ contained := false;
+ if Rectangle.contains(r, mx, my) {
+ // if hot_item == 0 do set_hot_item(hash);
+ contained = true;
+ }
+
+ if contained { // is_hot_item(hash) {
+ speed :: 30.0f; @ThemeConfiguration
+
+ if is_key_down(38) do state.transform.translation.y += speed;
+ if is_key_down(40) do state.transform.translation.y -= speed;
+
+ if mouse_state.dwheel > 0 do state.transform.translation.y += speed;
+ if mouse_state.dwheel < 0 do state.transform.translation.y -= speed;
+ }
+
+ map.put(^scrollable_region_states, hash, state);
+
+ gfx.push_scissor(x, y, width, height);
+ gfx.push_matrix();
+ gfx.apply_transform(state.transform);
+}
+
+scrollable_region_stop :: () {
+ gfx.pop_scissor();
+ gfx.pop_matrix();
+}
\ No newline at end of file
#load "./components/radio"
#load "./components/textbox"
#load "./components/workspace"
+#load "./components/scrollable_region"
// Package inclusions that are part of all files in the "ui" package.
#private gfx :: package immediate_mode // The immediate_mode module needs to be accessible
map.init(^animation_states, default=.{}, hash_count=4);
map.init(^workspace_states, default=.{}, hash_count=4);
+ map.init(^scrollable_region_states, default=.{}, hash_count=4);
// Register a default font so things don't break everywhere
builtin_font := create_font(#file_contents "./fonts/builtin.fnt", #file_contents "./fonts/builtin.data");
wasm_allocator = allocator;
@Cleanup @WasmStream // These are going to be needed in many places
- stream := io.string_stream_make(data);
+ stream := io.string_stream_make(data);
reader := io.reader_make(^stream);
io.stream_seek(^stream, map.get(^sections, .Type).offset, .Start);