Skip to content

Commit

Permalink
[Rust - agx] Cleanly interpolate scroll bar from ‘tuck in’ to expande…
Browse files Browse the repository at this point in the history
…d scroll
  • Loading branch information
codyd51 committed Mar 27, 2024
1 parent 118453c commit 5441ec5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
# Checks out repo at $GITHUB_WORKSPACE
- uses: actions/checkout@v2
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
python3 scripts/install_dependencies.py
python3 scripts/build_os_toolchain.py
echo "Toolchain built successfully"
- name: Build Rust toolchain
shell: bash
run: |
Expand Down
3 changes: 1 addition & 2 deletions bootloader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ int main(int argc, char** argv) {
draw(boot_info, 0x00e3a3d4);

printf("axle OS bootloader init...\n");
printf("Desired aspect ratio: %f\n", desired_aspect_ratio);
printf("Selected Mode %ld: %ldx%ld, %ld bpp\n", best_mode, gop_mode_info->HorizontalResolution, gop_mode_info->VerticalResolution, gop_mode_info->PixelFormat);
printf("Selected GOP mode #%ld: %ldx%ld, (pixel format #%ld)\n", best_mode, gop_mode_info->HorizontalResolution, gop_mode_info->VerticalResolution, gop_mode_info->PixelFormat);

pml4e_t* page_mapping_level4 = map2();
boot_info->boot_pml4 = (uint64_t)page_mapping_level4;
Expand Down
8 changes: 4 additions & 4 deletions rust_programs/agx_definitions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ mod test {
TileSegments(vec![TileSegment::new(
Rect::new(0, 0, 300, 300),
Rect::new(0, 0, 300, 300),
&tiles[0]
&tiles[0],
)])
);
assert_eq!(
Expand All @@ -982,12 +982,12 @@ mod test {
TileSegment::new(
Rect::new(0, 0, 300, 290),
Rect::new(0, 10, 300, 290),
&tiles[0]
&tiles[0],
),
TileSegment::new(
Rect::new(0, 290, 300, 10),
Rect::new(0, 0, 300, 10),
&tiles[1]
&tiles[1],
),
])
);
Expand Down Expand Up @@ -1072,7 +1072,7 @@ mod test {
// Left edge
Rect::new(0, 100, 50, 50),
// Right edge
Rect::new(350, 100, 50, 50)
Rect::new(350, 100, 50, 50),
]
);

Expand Down
2 changes: 1 addition & 1 deletion rust_programs/libgui/src/bordered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,6 @@ pub trait Bordered: Drawable + UIElement {
true,
self.currently_contains_mouse(),
)
.1
.1
}
}
19 changes: 14 additions & 5 deletions rust_programs/libgui/src/scroll_view.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use core::{cell::RefCell, fmt::Display};

use crate::bordered::{compute_inner_margin_and_content_frames, draw_border_with_insets, draw_outer_mouse_highlight};
use crate::bordered::{
compute_inner_margin_and_content_frames, draw_border_with_insets, draw_outer_mouse_highlight,
};
use crate::window_events::KeyCode;
use crate::{
bordered::Bordered,
Expand Down Expand Up @@ -980,17 +982,24 @@ fn compute_scrollbar_attributes(
};

let scrollable_region_size = scrollable_region_size(viewport_size, content_size);
let scrolled_proportion = (scroll_position.y as f64 / scrollable_region_size.height as f64);
let scrolled_proportion = scroll_position.y as f64 / scrollable_region_size.height as f64;
let scrollbar_width = (scroll_bar_onto_size.width as f64 * 0.4) as isize;

let scrollbar_tuck_in_proportion = 0.2;
let max_scrollbar_y = viewport_size.height - scrollbar_vertical_padding;
let max_nominal_scrollbar_origin_y = max_scrollbar_y as f64 - nominal_scrollbar_height;
let max_nominal_scrollbar_y = max_nominal_scrollbar_origin_y + nominal_scrollbar_height;
// Slightly tricky bit ahead:
// When not in the 'tuck in regions', the scrollbar should be linearly proportional to the scrolled proportion
// We need to find the slope and y-intercept of the line that crosses (0, scrollbar_vertical_padding) and (1, max_nominal_scrollbar_origin_y)
// Simplified slope intercept form
let slope = 1.0 / (1.0 - (scrollbar_tuck_in_proportion * 2.0));
let intercept = -slope * scrollbar_tuck_in_proportion;
// And ensure we never cross the [0, 1] bounds
let normalized_proportion = (intercept + (slope * scrolled_proportion)).max(0.0).min(1.0);
let nominal_scrollbar_origin_y = lerp(
scrollbar_vertical_padding as f64,
max_nominal_scrollbar_y,
scrolled_proportion - scrollbar_tuck_in_proportion,
max_nominal_scrollbar_origin_y,
normalized_proportion,
);

// The scroll bar should 'tuck in' if the user is near either extrema
Expand Down
2 changes: 1 addition & 1 deletion rust_programs/libgui/src/text_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl TextView {
let is_inserting_at_end = cursor_pos.0 == text.len();

if !is_inserting_at_end {
todo!("re-enable, disabled just while checking if this code path is hit");
//todo!("re-enable, disabled just while checking if this code path is hit");
// If we just inserted a newline, we need to adjust our cursor position
let mut cursor_point =
Self::next_cursor_pos_for_char(cursor_pos.1, ch, &font, font_size, onto);
Expand Down

0 comments on commit 5441ec5

Please sign in to comment.