Compare commits
2 Commits
1e6b9fc337
...
3f6fa16bdb
Author | SHA1 | Date | |
---|---|---|---|
3f6fa16bdb | |||
3e373914c7 |
46
src/ui.rs
46
src/ui.rs
@@ -6,7 +6,7 @@ use std::{
|
|||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
glib, Application, ApplicationWindow, Box, Button, FileChooserAction, FileChooserDialog,
|
glib, Application, ApplicationWindow, Box, Button, FileChooserAction, FileChooserDialog,
|
||||||
HeaderBar, Label, Orientation, Picture, ResponseType,
|
HeaderBar, Label, Overlay, Picture, ResponseType,
|
||||||
};
|
};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ pub struct Ui {
|
|||||||
bottom_bar: gtk::Box,
|
bottom_bar: gtk::Box,
|
||||||
header_bar: gtk::HeaderBar,
|
header_bar: gtk::HeaderBar,
|
||||||
page_indicator: gtk::Label,
|
page_indicator: gtk::Label,
|
||||||
pub app_wrapper: Box,
|
pub app_wrapper: Overlay,
|
||||||
pub image_container: Box,
|
pub image_container: Box,
|
||||||
pub image_left: Picture,
|
pub image_left: Picture,
|
||||||
pub image_right: Picture,
|
pub image_right: Picture,
|
||||||
@@ -151,9 +151,14 @@ fn process_left_click(ui: &mut Ui, x: f64, y: f64) {
|
|||||||
if ui.document_canvas.is_none() {
|
if ui.document_canvas.is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let edge_touch_area_size = f64::min(100.0, ui.app_wrapper.height() as f64 / 10.0);
|
||||||
|
|
||||||
let center = ui.app_wrapper.width() / 2;
|
let center = ui.app_wrapper.width() / 2;
|
||||||
if y < (ui.app_wrapper.height() / 5) as f64 {
|
if y < edge_touch_area_size {
|
||||||
|
if x > ui.app_wrapper.width() as f64 - edge_touch_area_size {
|
||||||
|
ui.window.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
toggle_fullscreen(ui);
|
toggle_fullscreen(ui);
|
||||||
} else if x > center as f64 {
|
} else if x > center as f64 {
|
||||||
if x < ui.app_wrapper.width() as f64 * 0.75 {
|
if x < ui.app_wrapper.width() as f64 * 0.75 {
|
||||||
@@ -178,16 +183,6 @@ impl Ui {
|
|||||||
debug!("building ui");
|
debug!("building ui");
|
||||||
let open_file_button = Button::from_icon_name("document-open");
|
let open_file_button = Button::from_icon_name("document-open");
|
||||||
|
|
||||||
let app_wrapper = Box::builder().orientation(Orientation::Vertical).build();
|
|
||||||
let window = ApplicationWindow::builder()
|
|
||||||
.application(app)
|
|
||||||
.title("Music Reader")
|
|
||||||
.child(&app_wrapper)
|
|
||||||
.maximized(true)
|
|
||||||
.width_request(600)
|
|
||||||
.height_request(400)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let image_container = Box::builder()
|
let image_container = Box::builder()
|
||||||
.spacing(0)
|
.spacing(0)
|
||||||
// .width_request(600)
|
// .width_request(600)
|
||||||
@@ -211,10 +206,28 @@ impl Ui {
|
|||||||
image_container.append(&image_left);
|
image_container.append(&image_left);
|
||||||
image_container.append(&image_right);
|
image_container.append(&image_right);
|
||||||
|
|
||||||
|
let app_wrapper = Overlay::builder()
|
||||||
|
// .orientation(Orientation::Vertical)
|
||||||
|
.hexpand(true)
|
||||||
|
.vexpand(true)
|
||||||
|
.child(&image_container)
|
||||||
|
.build();
|
||||||
|
let window = ApplicationWindow::builder()
|
||||||
|
.application(app)
|
||||||
|
.title("Music Reader")
|
||||||
|
.child(&app_wrapper)
|
||||||
|
.maximized(true)
|
||||||
|
.width_request(600)
|
||||||
|
.height_request(400)
|
||||||
|
.build();
|
||||||
|
|
||||||
let ui = Ui {
|
let ui = Ui {
|
||||||
window,
|
window,
|
||||||
app_wrapper,
|
app_wrapper,
|
||||||
bottom_bar: Box::builder().hexpand_set(true).build(),
|
bottom_bar: Box::builder()
|
||||||
|
.hexpand_set(true)
|
||||||
|
.valign(gtk::Align::End)
|
||||||
|
.build(),
|
||||||
header_bar: HeaderBar::builder().build(),
|
header_bar: HeaderBar::builder().build(),
|
||||||
page_indicator: Label::builder().build(),
|
page_indicator: Label::builder().build(),
|
||||||
image_container,
|
image_container,
|
||||||
@@ -225,10 +238,7 @@ impl Ui {
|
|||||||
let ui = Rc::new(RefCell::new(ui));
|
let ui = Rc::new(RefCell::new(ui));
|
||||||
|
|
||||||
ui.borrow().header_bar.pack_start(&open_file_button);
|
ui.borrow().header_bar.pack_start(&open_file_button);
|
||||||
ui.borrow()
|
ui.borrow().app_wrapper.add_overlay(&ui.borrow().bottom_bar);
|
||||||
.app_wrapper
|
|
||||||
.prepend(&ui.borrow().image_container);
|
|
||||||
ui.borrow().app_wrapper.append(&ui.borrow().bottom_bar);
|
|
||||||
ui.borrow().bottom_bar.append(&ui.borrow().page_indicator);
|
ui.borrow().bottom_bar.append(&ui.borrow().page_indicator);
|
||||||
|
|
||||||
let click_left = gtk::GestureClick::new();
|
let click_left = gtk::GestureClick::new();
|
||||||
|
Reference in New Issue
Block a user