resize & move
This commit is contained in:
parent
fb3e351a56
commit
8a8b8b7464
21
Cargo.lock
generated
21
Cargo.lock
generated
@ -37,6 +37,12 @@ dependencies = [
|
|||||||
"zerocopy",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "allocator-api2"
|
||||||
|
version = "0.2.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "android-activity"
|
name = "android-activity"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
@ -551,12 +557,23 @@ name = "fonotes"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arboard",
|
"arboard",
|
||||||
|
"fontdue",
|
||||||
"rdev",
|
"rdev",
|
||||||
"softbuffer",
|
"softbuffer",
|
||||||
"tiny-skia",
|
"tiny-skia",
|
||||||
"winit",
|
"winit",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fontdue"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9099a2f86b8e674b75d03ff154b3fe4c5208ed249ced8d69cc313a9fa40bb488"
|
||||||
|
dependencies = [
|
||||||
|
"hashbrown",
|
||||||
|
"ttf-parser",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "foreign-types"
|
name = "foreign-types"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@ -625,6 +642,10 @@ name = "hashbrown"
|
|||||||
version = "0.14.3"
|
version = "0.14.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
|
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
|
||||||
|
dependencies = [
|
||||||
|
"ahash",
|
||||||
|
"allocator-api2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
|
@ -10,4 +10,5 @@ arboard = "3.3.2"
|
|||||||
winit = "0.29.15"
|
winit = "0.29.15"
|
||||||
tiny-skia = "0.11.4"
|
tiny-skia = "0.11.4"
|
||||||
softbuffer = "0.4.2"
|
softbuffer = "0.4.2"
|
||||||
rdev = "0.5.3"
|
rdev = "0.5.3"
|
||||||
|
fontdue = "0.8.0"
|
111
src/main.rs
111
src/main.rs
@ -1,13 +1,18 @@
|
|||||||
|
use std::iter::Zip;
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
|
use fontdue::Font;
|
||||||
use tiny_skia::{Color, FillRule, Paint, PathBuilder, Pixmap, Stroke, Transform};
|
use tiny_skia::{Color, FillRule, Paint, PathBuilder, Pixmap, Stroke, Transform};
|
||||||
use softbuffer::{Context, Surface};
|
use softbuffer::{Context, Surface};
|
||||||
use arboard::{Clipboard, ImageData};
|
use arboard::{Clipboard, ImageData};
|
||||||
|
|
||||||
use winit::event::{Event, WindowEvent, KeyEvent, ElementState};
|
use winit::event::{ElementState, Event, KeyEvent, MouseButton, WindowEvent};
|
||||||
use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder};
|
use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder};
|
||||||
use winit::platform::x11::EventLoopBuilderExtX11;
|
use winit::platform::x11::EventLoopBuilderExtX11;
|
||||||
use winit::window::{WindowBuilder, WindowButtons, WindowLevel};
|
use winit::window::{WindowBuilder, WindowButtons, WindowLevel};
|
||||||
|
use winit::dpi::PhysicalPosition;
|
||||||
|
use winit::window::CursorIcon;
|
||||||
|
use winit::window::ResizeDirection;
|
||||||
|
|
||||||
use rdev::*;
|
use rdev::*;
|
||||||
|
|
||||||
@ -37,16 +42,47 @@ fn get_clipboard(clipboard: &mut Clipboard) -> ClipboardContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_text(text: String, size: f32, font: Font) -> Pixmap {
|
||||||
|
let mut chars: Vec<((usize, usize), Vec<u8>)> = Vec::new();
|
||||||
|
for ele in text.chars() {
|
||||||
|
let (metrics, bitmap) = font.rasterize(ele, size);
|
||||||
|
chars.push(((metrics.width, metrics.height), bitmap));
|
||||||
|
}
|
||||||
|
|
||||||
|
let width: usize = chars.iter().map(|i| i.0.0).sum();
|
||||||
|
let height: usize = chars.iter().map(|i| i.0.1).sum();
|
||||||
|
let mut pixmap = Pixmap::new(width as u32, height as u32).unwrap();
|
||||||
|
|
||||||
|
for ele in chars {
|
||||||
|
let mut i: u32 = 0;
|
||||||
|
for x in 0..(ele.0.0) {
|
||||||
|
for y in 0..(ele.0.1) {
|
||||||
|
|
||||||
|
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pixmap
|
||||||
|
}
|
||||||
|
|
||||||
fn popup_clipboard(content: ClipboardContent) {
|
fn popup_clipboard(content: ClipboardContent) {
|
||||||
let event_loop = EventLoopBuilder::new().with_any_thread(true).build().unwrap();
|
let event_loop = EventLoopBuilder::new().with_any_thread(true).build().unwrap();
|
||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
.with_enabled_buttons(WindowButtons::empty())
|
.with_enabled_buttons(WindowButtons::empty())
|
||||||
.with_window_level(WindowLevel::AlwaysOnTop)
|
|
||||||
.with_decorations(false)
|
.with_decorations(false)
|
||||||
.with_title("My Window")
|
.with_window_level(WindowLevel::AlwaysOnTop)
|
||||||
|
.with_title("FONotes - ".to_owned() + (match content {
|
||||||
|
ClipboardContent::Image(_) => "Image",
|
||||||
|
ClipboardContent::Text(_) => "Text",
|
||||||
|
_ => "???"
|
||||||
|
}))
|
||||||
.with_inner_size(winit::dpi::LogicalSize::new(800.0, 600.0))
|
.with_inner_size(winit::dpi::LogicalSize::new(800.0, 600.0))
|
||||||
.with_resizable(true)
|
.with_resizable(true)
|
||||||
.with_visible(true)
|
.with_visible(true)
|
||||||
|
.with_min_inner_size(winit::dpi::LogicalSize::new(50.0, 50.0))
|
||||||
|
// .with_resize_increments((0,0))
|
||||||
.build(&event_loop).unwrap();
|
.build(&event_loop).unwrap();
|
||||||
|
|
||||||
event_loop.set_control_flow(ControlFlow::Poll);
|
event_loop.set_control_flow(ControlFlow::Poll);
|
||||||
@ -55,23 +91,72 @@ fn popup_clipboard(content: ClipboardContent) {
|
|||||||
let context = Context::new(&window).unwrap();
|
let context = Context::new(&window).unwrap();
|
||||||
let mut surface = Surface::new(&context, &window).unwrap();
|
let mut surface = Surface::new(&context, &window).unwrap();
|
||||||
|
|
||||||
|
let mut mouse_pos = PhysicalPosition::new(0.0, 0.0);
|
||||||
|
|
||||||
event_loop.run(|event, elwt| {
|
event_loop.run(|event, elwt| {
|
||||||
match event {
|
match event {
|
||||||
Event::Resumed => {
|
Event::Resumed => {},
|
||||||
dbg!("what");
|
|
||||||
},
|
|
||||||
Event::WindowEvent { window_id, event } => match event {
|
Event::WindowEvent { window_id, event } => match event {
|
||||||
WindowEvent::CloseRequested => {
|
WindowEvent::CloseRequested => {
|
||||||
elwt.exit();
|
elwt.exit();
|
||||||
},
|
},
|
||||||
WindowEvent::MouseInput { device_id, state, button } => {
|
WindowEvent::MouseInput { device_id, state, button } => {
|
||||||
dbg!((device_id, state, button));
|
// dbg!((device_id, state, button));
|
||||||
|
|
||||||
|
let (width, height) = {
|
||||||
|
let size = window.inner_size();
|
||||||
|
(size.width as f64, size.height as f64)
|
||||||
|
};
|
||||||
|
|
||||||
|
if button == MouseButton::Left && state.is_pressed() {
|
||||||
|
if mouse_pos.x > width - 30.0 && mouse_pos.y < 30.0 { // close button
|
||||||
|
elwt.exit();
|
||||||
|
} else if mouse_pos.x < 20.0 && mouse_pos.y < 20.0 { // west north
|
||||||
|
window.drag_resize_window(ResizeDirection::NorthWest).unwrap();
|
||||||
|
} else if mouse_pos.x < 20.0 && mouse_pos.y > height - 20.0 { // west south
|
||||||
|
window.drag_resize_window(ResizeDirection::SouthWest).unwrap();
|
||||||
|
} else if mouse_pos.x > width - 20.0 && mouse_pos.y < 20.0 { // east north
|
||||||
|
window.drag_resize_window(ResizeDirection::NorthEast).unwrap();
|
||||||
|
} else if mouse_pos.x > width - 20.0 && mouse_pos.y > height - 20.0 { // east south
|
||||||
|
window.drag_resize_window(ResizeDirection::SouthEast).unwrap();
|
||||||
|
} else if mouse_pos.y < 20.0 && mouse_pos.x < 20.0 { // north west
|
||||||
|
window.drag_resize_window(ResizeDirection::NorthWest).unwrap();
|
||||||
|
} else if mouse_pos.y < 20.0 && mouse_pos.x > width - 20.0 { // north east
|
||||||
|
window.drag_resize_window(ResizeDirection::NorthEast).unwrap();
|
||||||
|
} else if mouse_pos.y > height - 20.0 && mouse_pos.x < 20.0 { // south west
|
||||||
|
window.drag_resize_window(ResizeDirection::SouthWest).unwrap();
|
||||||
|
} else if mouse_pos.y > height - 20.0 && mouse_pos.x > width - 20.0 { // south east
|
||||||
|
window.drag_resize_window(ResizeDirection::SouthEast).unwrap();
|
||||||
|
} else if mouse_pos.x < 20.0 { // west
|
||||||
|
window.drag_resize_window(ResizeDirection::West).unwrap();
|
||||||
|
} else if mouse_pos.x > width - 20.0 { // east
|
||||||
|
window.drag_resize_window(ResizeDirection::East).unwrap();
|
||||||
|
} else if mouse_pos.y > height - 20.0 { // south
|
||||||
|
window.drag_resize_window(ResizeDirection::South).unwrap();
|
||||||
|
} else if mouse_pos.y < 20.0 { // north
|
||||||
|
window.drag_resize_window(ResizeDirection::North).unwrap();
|
||||||
|
} else { // else
|
||||||
|
window.drag_window();
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
WindowEvent::CursorMoved { device_id, position } => {
|
WindowEvent::CursorMoved { device_id, position } => {
|
||||||
dbg!((device_id, position));
|
mouse_pos = position;
|
||||||
},
|
|
||||||
WindowEvent::CursorEntered { device_id } => {
|
let (width, height) = {
|
||||||
println!("cursor entered in the window {window_id:?}");
|
let size = window.inner_size();
|
||||||
|
(size.width as f64, size.height as f64)
|
||||||
|
};
|
||||||
|
|
||||||
|
if position.x > width - 30.0 && position.y < 30.0 {
|
||||||
|
window.set_cursor_icon(CursorIcon::Pointer);
|
||||||
|
} else if position.x < 20.0 || position.x > width - 20.0 {
|
||||||
|
window.set_cursor_icon(CursorIcon::EwResize)
|
||||||
|
} else if position.y < 20.0 || position.y > height - 20.0 {
|
||||||
|
window.set_cursor_icon(CursorIcon::NsResize)
|
||||||
|
} else {
|
||||||
|
window.set_cursor_icon(CursorIcon::Pointer);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
WindowEvent::RedrawRequested => {
|
WindowEvent::RedrawRequested => {
|
||||||
let (width, height) = { // объявляем переменные
|
let (width, height) = { // объявляем переменные
|
||||||
@ -87,6 +172,8 @@ fn popup_clipboard(content: ClipboardContent) {
|
|||||||
|
|
||||||
let mut pixmap = Pixmap::new(width, height).unwrap(); // берем
|
let mut pixmap = Pixmap::new(width, height).unwrap(); // берем
|
||||||
pixmap.fill(Color::WHITE);
|
pixmap.fill(Color::WHITE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mut buffer = surface.buffer_mut().unwrap();
|
let mut buffer = surface.buffer_mut().unwrap();
|
||||||
for index in 0..(width * height) as usize {
|
for index in 0..(width * height) as usize {
|
||||||
@ -102,6 +189,8 @@ fn popup_clipboard(content: ClipboardContent) {
|
|||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
|
window.set_visible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user