Skip to content

Commit c7fbd6b

Browse files
committed
resolve conflicts
2 parents de626e5 + ebc5850 commit c7fbd6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1297
-703
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.0.0"
44
edition = "2021"
55

66
[workspace]
7-
members = ["crates/layout", "crates/renderer", "crates/state", "crates/freya", "crates/elements", "crates/components", "crates/hooks", "crates/common", "crates/core", "crates/testing", "crates/devtools", "crates/dom", "crates/torin", "crates/engine"]
7+
members = ["crates/renderer", "crates/state", "crates/freya", "crates/elements", "crates/components", "crates/hooks", "crates/common", "crates/core", "crates/testing", "crates/devtools", "crates/dom", "crates/torin", "crates/engine"]
88

99
[features]
1010
log = ["freya/log"]
@@ -15,7 +15,6 @@ use_camera = ["freya/use_camera"]
1515
freya = { path = "crates/freya", version = "0.1" }
1616
freya-devtools = { path = "crates/devtools", version = "0.1" }
1717
freya-node-state = { path = "crates/state", version = "0.1" }
18-
freya-layout = { path = "crates/layout", version = "0.1" }
1918
freya-renderer = { path = "crates/renderer", version = "0.1" }
2019
freya-elements = { path = "crates/elements", version = "0.1" }
2120
freya-common = { path = "crates/common", version = "0.1" }

book/src/guides/layout.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ Learn how the layout attributes work.
66
- [`min_width & min_height`](#min_width--min_height)
77
- [`max_width & max_height`](#max_width--max_height)
88
- [`Size units`](#size_units)
9+
- [`auto`](#auto)
910
- [`Logical pixels`](#logical-pixels)
1011
- [`Percentages`](#percentages)
1112
- [`calc()`](#calc)
13+
- [`fill`](#fill)
1214
- [`direction`](#direction)
1315
- [`padding`](#padding)
14-
- [`margin`](#margin)
1516
- [`main_align & cross_align`](#main_align--cross_align)
17+
- [`margin`](#margin)
18+
- [`position`](#position)
1619

1720
> ⚠️ Freya's layout is still somewhat limited.
1821
@@ -81,6 +84,23 @@ fn app(cx: Scope) -> Element {
8184

8285
### Size Units
8386

87+
#### Auto
88+
Will use it's inner children as size, so in this case, the `rect` width will be defined bu the width of `label`:
89+
90+
```rust, no_run
91+
fn app(cx: Scope) -> Element {
92+
render!(
93+
rect {
94+
width: "auto",
95+
height: "33",
96+
label {
97+
"hello!"
98+
}
99+
}
100+
)
101+
}
102+
```
103+
84104
#### Logical pixels
85105

86106
```rust, no_run
@@ -108,6 +128,28 @@ fn app(cx: Scope) -> Element {
108128
}
109129
```
110130

131+
#### fill
132+
Use the remaining available space from the parent area:
133+
134+
```rust, no_run
135+
fn app(cx: Scope) -> Element {
136+
render!(
137+
rect {
138+
width: "100%",
139+
height: "100%",
140+
rect {
141+
height: "200",
142+
width: "100%",
143+
}
144+
rect {
145+
height: "fill", // This is the same as calc(100% - 200)
146+
width: "100%",
147+
}
148+
}
149+
)
150+
}
151+
```
152+
111153
#### `calc()`
112154

113155
For more complex logic you can use the `calc()` function.
@@ -214,4 +256,41 @@ fn app(cx: Scope) -> Element {
214256
}
215257
)
216258
}
259+
```
260+
261+
### position
262+
263+
Specify how you want the element to be positioned inside it's parent Area
264+
265+
Possible values for `position`:
266+
- `stacked` (default)
267+
- `absolute`
268+
269+
When using the `absolute` mode, you can also combine it with the following attributes:
270+
- `position_top`
271+
- `position_right`
272+
- `position_bottom`
273+
- `position_left`
274+
275+
These only support pixels.
276+
277+
Example:
278+
279+
```rust, no_run
280+
fn app(cx: Scope) -> Element {
281+
render!(
282+
rect {
283+
width: "100%",
284+
height: "100%",
285+
rect {
286+
position: "absolute",
287+
position_bottom: "15",
288+
position_right: "15",
289+
background: "black",
290+
width: "100",
291+
height: "100",
292+
}
293+
}
294+
)
295+
}
217296
```

crates/common/src/event_messages.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub enum EventMessage {
1515
RequestRelayout,
1616
/// Request a rerender
1717
RequestRerender,
18+
/// Request a redraw
19+
RequestRedraw,
1820
/// Remeasure a text elements group
1921
RemeasureTextGroup(Uuid),
2022
/// Change the cursor icon

crates/components/src/button.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use dioxus::prelude::*;
22
use freya_elements::elements as dioxus_elements;
33
use freya_elements::events::MouseEvent;
4-
use freya_hooks::{use_focus, use_get_theme};
4+
use freya_hooks::{use_focus, use_get_theme, use_platform};
5+
use winit::window::CursorIcon;
56

67
/// [`Button`] component properties.
78
#[derive(Props)]
@@ -67,6 +68,7 @@ pub fn Button<'a>(cx: Scope<'a, ButtonProps<'a>>) -> Element {
6768
let focus = use_focus(cx);
6869
let theme = use_get_theme(cx);
6970
let status = use_state(cx, ButtonStatus::default);
71+
let platform = use_platform(cx);
7072

7173
let focus_id = focus.attribute(cx);
7274

@@ -77,11 +79,25 @@ pub fn Button<'a>(cx: Scope<'a, ButtonProps<'a>>) -> Element {
7779
}
7880
};
7981

80-
let onmouseenter = move |_| {
81-
status.set(ButtonStatus::Hovering);
82+
use_on_unmount(cx, {
83+
to_owned![status, platform];
84+
move || {
85+
if *status.get() == ButtonStatus::Hovering {
86+
platform.set_cursor(CursorIcon::default());
87+
}
88+
}
89+
});
90+
91+
let onmouseenter = {
92+
to_owned![status, platform];
93+
move |_| {
94+
platform.set_cursor(CursorIcon::Hand);
95+
status.set(ButtonStatus::Hovering);
96+
}
8297
};
8398

8499
let onmouseleave = move |_| {
100+
platform.set_cursor(CursorIcon::default());
85101
status.set(ButtonStatus::default());
86102
};
87103

crates/components/src/scroll_views/scroll_bar.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use dioxus::prelude::*;
22
use freya_elements::elements as dioxus_elements;
3-
use freya_hooks::{use_get_theme, ScrollbarTheme};
3+
use freya_hooks::use_get_theme;
44

55
#[derive(Props)]
66
pub struct ScrollBarProps<'a> {
@@ -17,12 +17,29 @@ pub struct ScrollBarProps<'a> {
1717

1818
#[props(default = "0".to_string(), into)]
1919
offset_y: String,
20+
21+
clicking_scrollbar: bool,
22+
}
23+
24+
enum ScrollBarStatus {
25+
Idle,
26+
Hovering,
2027
}
2128

2229
#[allow(non_snake_case)]
2330
pub fn ScrollBar<'a>(cx: Scope<'a, ScrollBarProps<'a>>) -> Element<'a> {
31+
let status = use_state(cx, || ScrollBarStatus::Idle);
2432
let theme = use_get_theme(cx);
25-
let ScrollbarTheme { background, .. } = &theme.scrollbar;
33+
34+
let onmouseenter = |_| status.set(ScrollBarStatus::Hovering);
35+
36+
let onmouseleave = |_| status.set(ScrollBarStatus::Idle);
37+
38+
let background = match status.get() {
39+
_ if cx.props.clicking_scrollbar => theme.scrollbar.background,
40+
ScrollBarStatus::Hovering => theme.scrollbar.background,
41+
ScrollBarStatus::Idle => "transparent",
42+
};
2643

2744
render!(
2845
rect {
@@ -33,6 +50,8 @@ pub fn ScrollBar<'a>(cx: Scope<'a, ScrollBarProps<'a>>) -> Element<'a> {
3350
offset_x: "{cx.props.offset_x}",
3451
offset_y: "{cx.props.offset_y}",
3552
background: "{background}",
53+
onmouseenter: onmouseenter,
54+
onmouseleave: onmouseleave,
3655
&cx.props.children
3756
}
3857
)

crates/components/src/scroll_views/scroll_view.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ pub fn ScrollView<'a>(cx: Scope<'a, ScrollViewProps<'a>>) -> Element {
296296
width: "100%",
297297
height: "{horizontal_scrollbar_size}",
298298
offset_x: "{scrollbar_x}",
299+
clicking_scrollbar: is_scrolling_x,
299300
ScrollThumb {
300301
clicking_scrollbar: is_scrolling_x,
301302
onmousedown: onmousedown_x,
@@ -308,6 +309,7 @@ pub fn ScrollView<'a>(cx: Scope<'a, ScrollViewProps<'a>>) -> Element {
308309
width: "{vertical_scrollbar_size}",
309310
height: "100%",
310311
offset_y: "{scrollbar_y}",
312+
clicking_scrollbar: is_scrolling_y,
311313
ScrollThumb {
312314
clicking_scrollbar: is_scrolling_y,
313315
onmousedown: onmousedown_y,

crates/components/src/scroll_views/virtual_scroll_view.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ pub struct VirtualScrollViewProps<'a, T: 'a> {
4949
/// Enable scrolling with arrow keys.
5050
#[props(default = true, into)]
5151
pub scroll_with_arrows: bool,
52+
/// Tracker for the vertical scroll.
53+
#[props(optional)]
54+
pub scrolled_y: Option<UseRef<i32>>,
5255
}
5356

5457
fn get_render_range(
@@ -347,6 +350,7 @@ pub fn VirtualScrollView<'a, T>(cx: Scope<'a, VirtualScrollViewProps<'a, T>>) ->
347350
width: "100%",
348351
height: "{horizontal_scrollbar_size}",
349352
offset_x: "{scrollbar_x}",
353+
clicking_scrollbar: is_scrolling_x,
350354
ScrollThumb {
351355
clicking_scrollbar: is_scrolling_x,
352356
onmousedown: onmousedown_x,
@@ -359,6 +363,7 @@ pub fn VirtualScrollView<'a, T>(cx: Scope<'a, VirtualScrollViewProps<'a, T>>) ->
359363
width: "{vertical_scrollbar_size}",
360364
height: "100%",
361365
offset_y: "{scrollbar_y}",
366+
clicking_scrollbar: is_scrolling_y,
362367
ScrollThumb {
363368
clicking_scrollbar: is_scrolling_y,
364369
onmousedown: onmousedown_y,

crates/components/src/slider.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use dioxus::prelude::*;
22
use freya_elements::elements as dioxus_elements;
33
use freya_elements::events::{MouseEvent, WheelEvent};
4-
use freya_hooks::{use_get_theme, use_node_ref};
4+
use freya_hooks::{use_get_theme, use_node_ref, use_platform};
55
use tracing::info;
6+
use winit::window::CursorIcon;
67

78
/// [`Slider`] component properties.
89
#[derive(Props)]
@@ -28,6 +29,16 @@ fn ensure_correct_slider_range(value: f64) -> f64 {
2829
}
2930
}
3031

32+
/// Describes the current status of the Slider.
33+
#[derive(Debug, Default, PartialEq, Clone, Copy)]
34+
pub enum SliderStatus {
35+
/// Default state.
36+
#[default]
37+
Idle,
38+
/// Mouse is hovering the slider.
39+
Hovering,
40+
}
41+
3142
/// Controlled `Slider` component.
3243
///
3344
/// You must pass a percentage from 0.0 to 100.0 and listen for value changes with `onmoved` and then decide if this changes are applicable,
@@ -63,22 +74,39 @@ fn ensure_correct_slider_range(value: f64) -> f64 {
6374
pub fn Slider<'a>(cx: Scope<'a, SliderProps>) -> Element<'a> {
6475
let theme = use_get_theme(cx);
6576
let theme = &theme.slider;
66-
let hovering = use_state(cx, || false);
77+
let status = use_ref(cx, SliderStatus::default);
6778
let clicking = use_state(cx, || false);
79+
let platform = use_platform(cx);
80+
6881
let value = ensure_correct_slider_range(cx.props.value);
6982
let (node_reference, size) = use_node_ref(cx);
7083
let width = cx.props.width + 14.0;
7184

7285
let progress = (value / 100.0) * cx.props.width + 0.5;
7386

74-
let onmouseleave = |_: MouseEvent| {
75-
if !(*clicking.get()) {
76-
hovering.set(false);
87+
use_on_unmount(cx, {
88+
to_owned![status, platform];
89+
move || {
90+
if *status.read() == SliderStatus::Hovering {
91+
platform.set_cursor(CursorIcon::default());
92+
}
93+
}
94+
});
95+
96+
let onmouseleave = {
97+
to_owned![platform, status];
98+
move |_: MouseEvent| {
99+
*status.write_silent() = SliderStatus::Idle;
100+
platform.set_cursor(CursorIcon::default());
77101
}
78102
};
79103

104+
let onmouseenter = move |_: MouseEvent| {
105+
*status.write_silent() = SliderStatus::Hovering;
106+
platform.set_cursor(CursorIcon::Hand);
107+
};
108+
80109
let onmouseover = move |e: MouseEvent| {
81-
hovering.set(true);
82110
if *clicking.get() {
83111
let coordinates = e.get_element_coordinates();
84112
let mut x = coordinates.x - 7.5 - size.read().area.min_x() as f64;
@@ -119,6 +147,7 @@ pub fn Slider<'a>(cx: Scope<'a, SliderProps>) -> Element<'a> {
119147
height: "20",
120148
onmousedown: onmousedown,
121149
onglobalclick: onclick,
150+
onmouseenter: onmouseenter,
122151
onglobalmouseover: onmouseover,
123152
onmouseleave: onmouseleave,
124153
onwheel: onwheel,

0 commit comments

Comments
 (0)