Skip to content

Commit

Permalink
fix: adapt to tiny_skia
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Nov 6, 2023
1 parent d902d0f commit 4c9d659
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn main() -> iced::Result {
level: Level::AlwaysOnTop,
..Default::default()
},
antialiasing: true,
flags: settings,
..Default::default()
})
Expand Down
8 changes: 7 additions & 1 deletion src/ui/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use iced::{
widget::{container, image, mouse_area, text, Column},
Element, Length,
};
use iced_tiny_skia::core::text::Shaping;

use crate::settings::ClipboardItem;

Expand All @@ -26,7 +27,12 @@ pub fn render_item(
if !format_date.is_empty() {
col = col.push(top_item(fmt_date, i_pinned, item, pin_icon, unpin_icon));
}
col.push(text(value.replace('\t', " ")).size(18.)).into()
col.push(
text(value.replace('\t', " "))
.shaping(Shaping::Advanced)
.size(14.),
)
.into()
}
ClipboardItem::Image(_, w, h, b) => {
let mut col = Column::new().spacing(5.);
Expand Down
1 change: 1 addition & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ impl Application for MainApp {
self.pin_icon.clone(),
self.unpin_icon.clone(),
))
.id(scrollable::Id::new("clipboard_scroll"))
.height(Length::Fill)
.direction(scrollable::Direction::Vertical(
Properties::new().width(5.).scroller_width(5.),
Expand Down
39 changes: 30 additions & 9 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ use std::str::FromStr;

use device_query::DeviceQuery;
use global_hotkey::{hotkey::HotKey, GlobalHotKeyEvent};
use iced::widget::scrollable;
use iced::{window, Command};
use log::trace;

use crate::data::{save_pined, save_settings};
use crate::ui::RouterView;
use crate::{
settings::ClipboardItem,
ui::{MainApp, MainMessage, SettingsModified},
Expand All @@ -15,9 +17,15 @@ use crate::{
pub fn handle_update(app: &mut MainApp, message: MainMessage) -> Command<MainMessage> {
match message {
MainMessage::HiddeApplication => {
app.visible = false;
app.follow = true;
window::change_mode(window::Mode::Hidden)
#[cfg(not(debug_assertions))]
{
app.visible = false;
app.follow = true;
app.view = RouterView::Settings;
window::change_mode(window::Mode::Hidden)
}
#[cfg(debug_assertions)]
Command::none()
}
MainMessage::Open(url) => {
if url.is_empty() {
Expand Down Expand Up @@ -72,6 +80,9 @@ pub fn handle_update(app: &mut MainApp, message: MainMessage) -> Command<MainMes
) {
match msg {
utils::Message::AddClipboard(item) => {
if let ClipboardItem::Text(_, s) = &item {
app.clipboard_ctx.set_text(s).unwrap();
}
app.settings.push(item);
}
utils::Message::RemoveLastClipboard => {
Expand All @@ -85,18 +96,28 @@ pub fn handle_update(app: &mut MainApp, message: MainMessage) -> Command<MainMes
}
MainMessage::CheckShortcuts(_) => {
let mut commands = Vec::new();
if GlobalHotKeyEvent::receiver().try_recv().is_ok() {
app.visible = true;
commands.push(window::change_mode(window::Mode::Windowed));
}

if app.follow && !commands.is_empty() {
if app.follow {
app.follow = false;
let (x, y) =
track_mouse(app.last_data.mouse_pos, app.device_state.get_mouse().coords);
app.last_data.mouse_pos = (x, y);
commands.push(window::move_to(x, y));
}

if GlobalHotKeyEvent::receiver().try_recv().is_ok() {
app.visible = true;
app.view = RouterView::Home;

commands.push(scrollable::scroll_to(
scrollable::Id::new("clipboard_scroll"),
scrollable::AbsoluteOffset { x: 0., y: 0. },
));
commands.push(window::change_mode(window::Mode::Windowed));
} else {
app.follow = true;
commands.clear();
}

Command::batch(commands)
}
MainMessage::CheckSettings(_) => {
Expand Down

0 comments on commit 4c9d659

Please sign in to comment.