Skip to content

Commit

Permalink
Merge branch 'main' into renovate/all-minor-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Oct 22, 2023
2 parents 2708049 + 4ac85ef commit 0c1fd88
Show file tree
Hide file tree
Showing 20 changed files with 879 additions and 280 deletions.
1 change: 1 addition & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
on:
workflow_dispatch:
pull_request:
paths:
- 'crates/torin/**/*'
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ euclid = "0.22.9"
uuid = { version = "1.4.1", features = ["v4"]}
futures = "0.3.28"
anymap = "0.12.1"
fxhash = "0.2.1"
tracing = "0.1"
tracing-subscriber = "0.3.17"
rustc-hash = "1.1.0"
Expand All @@ -71,6 +70,7 @@ tracing-subscriber = "0.3.17"
dioxus-std = { version = "0.4", features = ["utils", "i18n"] }
rand = "0.8.5"
dioxus-router = { workspace = true }
itertools = "0.11.0"

[profile.release]
lto = true
Expand All @@ -79,4 +79,4 @@ opt-level = 3

[target."cfg(target_os = \"linux\")".dependencies.skia-safe]
workspace = true
features = ["gl", "textlayout", "svg", "x11", "wayland"]
features = ["gl", "textlayout", "svg", "x11", "wayland"]
2 changes: 2 additions & 0 deletions crates/components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod progress_bar;
mod scroll_views;
mod slider;
mod switch;
mod table;
mod theme;
mod tooltip;

Expand All @@ -36,5 +37,6 @@ pub use progress_bar::*;
pub use scroll_views::*;
pub use slider::*;
pub use switch::*;
pub use table::*;
pub use theme::*;
pub use tooltip::*;
3 changes: 2 additions & 1 deletion crates/components/src/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub fn ProgressBar(cx: Scope<ProgressBarProps>) -> Element {
let theme = use_get_theme(cx);

let ProgressBarTheme {
color,
background,
progress_background,
} = theme.progress_bar;
Expand Down Expand Up @@ -79,7 +80,7 @@ pub fn ProgressBar(cx: Scope<ProgressBarProps>) -> Element {
label {
align: "center",
width: "100%",
color: "white",
color: "{color}",
max_lines: "1",
"{progress.floor()}%"
}
Expand Down
26 changes: 22 additions & 4 deletions crates/components/src/scroll_views/scroll_thumb.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
use dioxus::prelude::*;
use freya_elements::elements as dioxus_elements;
use freya_elements::events::MouseEvent;
use freya_hooks::{use_get_theme, ScrollbarTheme};
use freya_hooks::use_get_theme;

#[derive(Props)]
pub struct ScrollThumbProps<'a> {
clicking_scrollbar: bool,
onmousedown: EventHandler<'a, MouseEvent>,
#[props(into)]
width: String,
#[props(into)]
height: String,
}

#[derive(Debug, Default, PartialEq, Clone, Copy)]
pub enum ScrollThumbState {
#[default]
Idle,
// Thumb is being hovered
Hovering,
}

#[allow(non_snake_case)]
pub fn ScrollThumb<'a>(cx: Scope<'a, ScrollThumbProps<'a>>) -> Element<'a> {
let theme = use_get_theme(cx);
let ScrollbarTheme {
thumb_background, ..
} = &theme.scrollbar;
let state = use_state(cx, ScrollThumbState::default);
let thumb_background = match state.get() {
_ if cx.props.clicking_scrollbar => theme.scrollbar.active_thumb_background,
ScrollThumbState::Idle => theme.scrollbar.thumb_background,
ScrollThumbState::Hovering => theme.scrollbar.hover_thumb_background,
};

render!(
rect {
onmouseenter: |_| {
state.set(ScrollThumbState::Hovering)
},
onmouseleave: |_| {
state.set(ScrollThumbState::Idle)
},
onmousedown: |e| {
cx.props.onmousedown.call(e);
},
Expand Down
21 changes: 18 additions & 3 deletions crates/components/src/scroll_views/scroll_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,20 @@ pub fn ScrollView<'a>(cx: Scope<'a, ScrollViewProps<'a>>) -> Element {
// Mark the Y axis scrollbar as the one being dragged
let onmousedown_y = |e: MouseEvent| {
let coordinates = e.get_element_coordinates();
*clicking_scrollbar.write_silent() = Some((Axis::Y, coordinates.y));
*clicking_scrollbar.write() = Some((Axis::Y, coordinates.y));
};

// Mark the X axis scrollbar as the one being dragged
let onmousedown_x = |e: MouseEvent| {
let coordinates = e.get_element_coordinates();
*clicking_scrollbar.write_silent() = Some((Axis::X, coordinates.x));
*clicking_scrollbar.write() = Some((Axis::X, coordinates.x));
};

// Unmark any scrollbar
let onclick = |_: MouseEvent| {
*clicking_scrollbar.write_silent() = None;
if clicking_scrollbar.read().is_some() {
*clicking_scrollbar.write() = None;
}
};

let horizontal_scrollbar_size = if horizontal_scrollbar_is_visible {
Expand All @@ -252,6 +254,17 @@ pub fn ScrollView<'a>(cx: Scope<'a, ScrollViewProps<'a>>) -> Element {
0
};

let is_scrolling_x = clicking_scrollbar
.read()
.as_ref()
.map(|f| f.0 == Axis::X)
.unwrap_or_default();
let is_scrolling_y = clicking_scrollbar
.read()
.as_ref()
.map(|f| f.0 == Axis::Y)
.unwrap_or_default();

render!(
rect {
role: "scrollView",
Expand Down Expand Up @@ -284,6 +297,7 @@ pub fn ScrollView<'a>(cx: Scope<'a, ScrollViewProps<'a>>) -> Element {
height: "{horizontal_scrollbar_size}",
offset_x: "{scrollbar_x}",
ScrollThumb {
clicking_scrollbar: is_scrolling_x,
onmousedown: onmousedown_x,
width: "{scrollbar_width}",
height: "100%",
Expand All @@ -295,6 +309,7 @@ pub fn ScrollView<'a>(cx: Scope<'a, ScrollViewProps<'a>>) -> Element {
height: "100%",
offset_y: "{scrollbar_y}",
ScrollThumb {
clicking_scrollbar: is_scrolling_y,
onmousedown: onmousedown_y,
width: "100%",
height: "{scrollbar_height}",
Expand Down
21 changes: 18 additions & 3 deletions crates/components/src/scroll_views/virtual_scroll_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,20 @@ pub fn VirtualScrollView<'a, T>(cx: Scope<'a, VirtualScrollViewProps<'a, T>>) ->
// Mark the Y axis scrollbar as the one being dragged
let onmousedown_y = |e: MouseEvent| {
let coordinates = e.get_element_coordinates();
*clicking_scrollbar.write_silent() = Some((Axis::Y, coordinates.y));
*clicking_scrollbar.write() = Some((Axis::Y, coordinates.y));
};

// Mark the X axis scrollbar as the one being dragged
let onmousedown_x = |e: MouseEvent| {
let coordinates = e.get_element_coordinates();
*clicking_scrollbar.write_silent() = Some((Axis::X, coordinates.x));
*clicking_scrollbar.write() = Some((Axis::X, coordinates.x));
};

// Unmark any scrollbar
let onclick = |_: MouseEvent| {
*clicking_scrollbar.write_silent() = None;
if clicking_scrollbar.read().is_some() {
*clicking_scrollbar.write() = None;
}
};

let horizontal_scrollbar_size = if horizontal_scrollbar_is_visible {
Expand Down Expand Up @@ -305,6 +307,17 @@ pub fn VirtualScrollView<'a, T>(cx: Scope<'a, VirtualScrollViewProps<'a, T>>) ->
let children =
render_range.map(|i| (cx.props.builder)((i + 1, i, cx, &cx.props.builder_values)));

let is_scrolling_x = clicking_scrollbar
.read()
.as_ref()
.map(|f| f.0 == Axis::X)
.unwrap_or_default();
let is_scrolling_y = clicking_scrollbar
.read()
.as_ref()
.map(|f| f.0 == Axis::Y)
.unwrap_or_default();

render!(
rect {
role: "scrollView",
Expand Down Expand Up @@ -335,6 +348,7 @@ pub fn VirtualScrollView<'a, T>(cx: Scope<'a, VirtualScrollViewProps<'a, T>>) ->
height: "{horizontal_scrollbar_size}",
offset_x: "{scrollbar_x}",
ScrollThumb {
clicking_scrollbar: is_scrolling_x,
onmousedown: onmousedown_x,
width: "{scrollbar_width}",
height: "100%",
Expand All @@ -346,6 +360,7 @@ pub fn VirtualScrollView<'a, T>(cx: Scope<'a, VirtualScrollViewProps<'a, T>>) ->
height: "100%",
offset_y: "{scrollbar_y}",
ScrollThumb {
clicking_scrollbar: is_scrolling_y,
onmousedown: onmousedown_y,
width: "100%",
height: "{scrollbar_height}",
Expand Down
Loading

0 comments on commit 0c1fd88

Please sign in to comment.