Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: 233 split winit,gpu from core #290

Closed
wants to merge 11 commits into from
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
[workspace]
members = [
"algo",
"app",
"core",
"geometry",
"gpu",
"painter",
"macros",
"macros/builtin",
"algo",
"text",
"widgets",
"painter",
"ribir",
"text",
"tests",
"widgets",
"winit",
]
resolver = "2"

Expand Down
9 changes: 9 additions & 0 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "ribir_app"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ribir_core = { path = "../core" }
18 changes: 18 additions & 0 deletions app/src/application.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// use ribir_core::{
// prelude::{AppContext, Theme},
// window::{Window, WindowId},
// };

// use crate::event_loop::EventLoop;

// pub trait Application {
// fn with_theme(self, theme: Theme) -> Self;

// fn context(&self) -> &AppContext;

// fn event_loop(&self) -> &EventLoop<()>;

// fn exec(self, wnd_id: Box<dyn WindowId>);

// fn add_window(&mut self, wnd: Window) -> Box<dyn WindowId>;
// }
1 change: 1 addition & 0 deletions app/src/event_loop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub trait EventLoop {}
6 changes: 6 additions & 0 deletions app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod application;
pub mod event_loop;
pub mod shell_window;
pub mod prelude {
pub use crate::application::*;
}
1 change: 1 addition & 0 deletions app/src/shell_window.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub trait ShellWindow {}
41 changes: 41 additions & 0 deletions app/src/window_builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// use ribir_app::prelude::Application;
// use ribir_core::{prelude::AppContext, widget::Widget, window::Window as RibirWindow};
// use ribir_geometry::{DeviceSize, Point, Size};

// pub trait WindowBuilder {
// fn build(self, app: dyn Application) -> RibirWindow;

// /// Requests the window to be of specific dimensions.
// fn with_inner_size(self, size: Size) -> Self;

// /// Sets a minimum dimension size for the window.
// fn with_min_inner_size( self, min_size: Size) -> Self;

// /// Sets a maximum dimension size for the window.
// fn with_max_inner_size( self, max_size: Size) -> Self;

// /// Sets a desired initial position for the window.
// fn with_position(self, position: Point) -> Self;

// /// Sets whether the window is resizable or not.
// fn with_resizable( self, resizable: bool) -> Self;

// /// Requests a specific title for the window.
// fn with_title<T: Into<String>>( self, title: T) -> Self;

// /// Requests maximized mode.
// fn with_maximized( self, maximized: bool) -> Self;

// /// Sets whether the window will be initially hidden or visible.
// fn with_visible( self, visible: bool) -> Self;

// /// Sets whether the background of the window should be transparent.
// fn with_transparent( self, transparent: bool) -> Self;

// /// Sets whether the window should have a border, a title bar, etc.

// fn with_decorations( self, decorations: bool) -> Self;

// /// Sets the window icon.
// // fn with_window_icon( self, window_icon: WindowIcon>) -> Self;
// }
4 changes: 2 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ lyon_algorithms = "1.0.1"
lyon_geom = "1.0.1"
png = {version = "0.17.3", optional = true}
ribir_algo = {path = "../algo", version = "0.0.0"}
ribir_gpu = {path = "../gpu", version = "0.0.0", features = ["wgpu_gl"]}
#ribir_gpu = {path = "../gpu", version = "0.0.0", features = ["wgpu_gl"]}
ribir_macros = {path = "../macros", version = "0.0.0"}
ribir_painter = {path = "../painter", version = "0.0.0"}
ribir_text = {path = "../text", version = "0.0.0"}
rxrust = "1.0.0-beta.1"

smallvec = "1.8.0"
winit = "0.28.1"
# winit = "0.28.1"

[dependencies.blake3]
features = ["rayon"]
Expand Down
2 changes: 1 addition & 1 deletion core/src/builtin_widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pub use key::{Key, KeyWidget};
mod theme;
pub use theme::*;
mod cursor;
pub use crate::cursor_icon::CursorIcon;
pub use cursor::Cursor;
pub use winit::window::CursorIcon;
mod margin;
pub use margin::*;
mod padding;
Expand Down
28 changes: 10 additions & 18 deletions core/src/builtin_widgets/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::prelude::*;
use std::{cell::Cell, rc::Rc};
use winit::window::CursorIcon;

/// `Cursor` is an attribute to assign an `cursor` to a widget.

#[derive(Declare, Debug)]
pub struct Cursor {
#[declare(convert=custom, builtin, default)]
Expand Down Expand Up @@ -91,7 +89,6 @@ impl Default for Cursor {
mod tests {
use super::*;
use crate::test::*;
use winit::event::{DeviceId, WindowEvent};

#[test]
fn tree_down_up() {
Expand All @@ -117,61 +114,56 @@ mod tests {
wnd.draw_frame();
let tree = &mut wnd.widget_tree;

let device_id = unsafe { DeviceId::dummy() };
let device_id = MockPointerId::zero();
let dispatcher = &mut wnd.dispatcher;
dispatcher.dispatch(
WindowEvent::CursorMoved {
device_id,
position: (1f64, 1.).into(),
modifiers: ModifiersState::default(),
position: DevicePoint::new(1, 1),
},
tree,
1.,
);
assert_eq!(dispatcher.take_cursor_icon(), Some(CursorIcon::Help));

let device_id = unsafe { DeviceId::dummy() };
let device_id = MockPointerId::zero();
dispatcher.dispatch(
WindowEvent::CursorMoved {
device_id,
position: (101f64, 1.).into(),
modifiers: ModifiersState::default(),
position: DevicePoint::new(101, 1),
},
tree,
1.,
);
assert_eq!(dispatcher.take_cursor_icon(), Some(CursorIcon::Hand));

let device_id = unsafe { DeviceId::dummy() };
let device_id = MockPointerId::zero();
dispatcher.dispatch(
WindowEvent::CursorMoved {
device_id,
position: (201f64, 1.).into(),
modifiers: ModifiersState::default(),
position: DevicePoint::new(201, 1),
},
tree,
1.,
);
assert_eq!(dispatcher.take_cursor_icon(), Some(CursorIcon::AllScroll));

let device_id = unsafe { DeviceId::dummy() };
let device_id = MockPointerId::zero();
dispatcher.dispatch(
WindowEvent::CursorMoved {
device_id,
position: (101f64, 1.).into(),
modifiers: ModifiersState::default(),
position: DevicePoint::new(101, 1),
},
tree,
1.,
);
assert_eq!(dispatcher.take_cursor_icon(), Some(CursorIcon::Hand));

let device_id = unsafe { DeviceId::dummy() };
let device_id = MockPointerId::zero();
dispatcher.dispatch(
WindowEvent::CursorMoved {
device_id,
position: (1f64, 1.).into(),
modifiers: ModifiersState::default(),
position: DevicePoint::new(1, 1),
},
tree,
1.,
Expand Down
38 changes: 21 additions & 17 deletions core/src/builtin_widgets/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ impl ScrollableWidget {

#[cfg(test)]
mod tests {
use crate::test::{layout_position_by_path, MockBox};
use crate::test::{layout_position_by_path, MockBox, MockPointerId};

use super::*;
use winit::event::{DeviceId, ModifiersState, MouseScrollDelta, TouchPhase, WindowEvent};

fn test_assert(scrollable: Scrollable, delta_x: f32, delta_y: f32, expect_x: f32, expect_y: f32) {
fn test_assert(scrollable: Scrollable, delta_x: i32, delta_y: i32, expect_x: i32, expect_y: i32) {
let w = widget! {
MockBox {
size: Size::new(1000., 1000.),
Expand All @@ -124,39 +123,44 @@ mod tests {

wnd.draw_frame();

let device_id = unsafe { DeviceId::dummy() };
let device_id = MockPointerId::zero();
wnd.processes_native_event(WindowEvent::MouseWheel {
device_id,
delta: MouseScrollDelta::PixelDelta((delta_x, delta_y).into()),
delta: MouseScrollDelta::PixelDelta(DeviceOffset::new(delta_x, delta_y)),
phase: TouchPhase::Started,
modifiers: ModifiersState::default(),
});

wnd.layout();
let pos = layout_position_by_path(&wnd, &[0, 0, 0, 0]);
assert_eq!(pos.y, expect_y);
assert!((pos.y - expect_y as f32).abs() < f32::EPSILON);
let pos = layout_position_by_path(&wnd, &[0, 0, 0, 0, 0]);
assert_eq!(pos.x, expect_x);
assert!((pos.x - expect_x as f32).abs() < f32::EPSILON);
// TODO(zoechi)
// let scale = ScaleOffsetToPhysic::new(1);
// let rect = scale.transform_rect(&layout_info_by_path(&wnd, &[0, 0, 0,
// 0]).cast()); assert_eq!(rect.origin.y, expect_y);
// let rect = scale.transform_rect(&layout_info_by_path(&wnd, &[0, 0, 0, 0,
// 0]).cast()); assert_eq!(rect.origin.x, expect_x);
}

#[test]
fn x_scroll() {
test_assert(Scrollable::X, -10., -10., -10., 0.);
test_assert(Scrollable::X, -10000., -10., -900., 0.);
test_assert(Scrollable::X, 100., -10., 0., 0.);
test_assert(Scrollable::X, -10, -10, -10, 0);
test_assert(Scrollable::X, -10000, -10, -900, 0);
test_assert(Scrollable::X, 100, -10, 0, 0);
}

#[test]
fn y_scroll() {
test_assert(Scrollable::Y, -10., -10., 0., -10.);
test_assert(Scrollable::Y, -10., -10000., 0., -900.);
test_assert(Scrollable::Y, 10., 100., 0., 0.);
test_assert(Scrollable::Y, -10, -10, 0, -10);
test_assert(Scrollable::Y, -10, -10000, 0, -900);
test_assert(Scrollable::Y, 10, 100, 0, 0);
}

#[test]
fn both_scroll() {
test_assert(Scrollable::Both, -10., -10., -10., -10.);
test_assert(Scrollable::Both, -10000., -10000., -900., -900.);
test_assert(Scrollable::Both, 100., 100., 0., 0.);
test_assert(Scrollable::Both, -10, -10, -10, -10);
test_assert(Scrollable::Both, -10000, -10000, -900, -900);
test_assert(Scrollable::Both, 100, 100, 0, 0);
}
}
4 changes: 2 additions & 2 deletions core/src/context/event_context.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{define_widget_context, WidgetCtxImpl, WindowCtx};
use crate::{
events::dispatcher::DispatchInfo,
cursor_icon::CursorIcon,
events::{dispatcher::DispatchInfo, ModifiersState},
widget::{LayoutStore, TreeArena},
widget_tree::WidgetId,
};
use winit::{event::ModifiersState, window::CursorIcon};

define_widget_context!(EventCtx, info: &'a mut DispatchInfo);

Expand Down
58 changes: 58 additions & 0 deletions core/src/cursor_icon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/// Describes the appearance of the mouse cursor.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum CursorIcon {
/// The platform-dependent default cursor.
#[default]
Default,
/// A simple crosshair.
Crosshair,
/// A hand (often used to indicate links in web browsers).
Hand,
/// Self explanatory.
Arrow,
/// Indicates something is to be moved.
Move,
/// Indicates text that may be selected or edited.
Text,
/// Program busy indicator.
Wait,
/// Help indicator (often rendered as a "?")
Help,
/// Progress indicator. Shows that processing is being done. But in contrast
/// with "Wait" the user may still interact with the program. Often rendered
/// as a spinning beach ball, or an arrow with a watch or hourglass.
Progress,

/// Cursor showing that something cannot be done.
NotAllowed,
ContextMenu,
Cell,
VerticalText,
Alias,
Copy,
NoDrop,
/// Indicates something can be grabbed.
Grab,
/// Indicates something is grabbed.
Grabbing,
AllScroll,
ZoomIn,
ZoomOut,

/// Indicate that some edge is to be moved. For example, the 'SeResize' cursor
/// is used when the movement starts from the south-east corner of the box.
EResize,
NResize,
NeResize,
NwResize,
SResize,
SeResize,
SwResize,
WResize,
EwResize,
NsResize,
NeswResize,
NwseResize,
ColResize,
RowResize,
}
3 changes: 2 additions & 1 deletion core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use crate::{
use std::ptr::NonNull;

pub(crate) mod dispatcher;
mod event;
pub use event::*;
mod pointers;
pub use pointers::*;
use ribir_painter::Point;
pub use winit::event::{ModifiersState, ScanCode, VirtualKeyCode};
mod focus;
pub use focus::*;
mod keyboard;
Expand Down
1 change: 0 additions & 1 deletion core/src/events/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ mod tests {
use crate::test::*;

use std::{cell::RefCell, rc::Rc};
use winit::event::WindowEvent;

#[test]
fn smoke() {
Expand Down
Loading