Connect ocrs to new ui
This commit is contained in:
@@ -32,17 +32,21 @@ use wayland_client::{
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use rten_tensor::NdTensor;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::wayland::{
|
||||
draw::DrawPath,
|
||||
draw::{DrawPath, Draw},
|
||||
builder::{TextAreaBuilder, DrawAreaBuilder, ButtonBuilder},
|
||||
ui::{self, Widget},
|
||||
ui::{self, Widget, ButtonType},
|
||||
Position,
|
||||
};
|
||||
|
||||
const WINDOW_HEIGHT: u32 = 256;
|
||||
const WINDOW_WIDTH: u32 = 512;
|
||||
use crate::process_point::print_words;
|
||||
|
||||
const WINDOW_HEIGHT: usize = 256;
|
||||
const WINDOW_WIDTH: usize = 512;
|
||||
|
||||
pub(crate) struct SimpleWindow {
|
||||
registry_state: RegistryState,
|
||||
@@ -55,8 +59,8 @@ pub(crate) struct SimpleWindow {
|
||||
pool: SlotPool,
|
||||
window: Window,
|
||||
ui: Option<ui::Window>,
|
||||
width: u32,
|
||||
height: u32,
|
||||
width: usize,
|
||||
height: usize,
|
||||
cursor_down: bool,
|
||||
exit: bool,
|
||||
first_configure: bool,
|
||||
@@ -87,8 +91,8 @@ impl SimpleWindow {
|
||||
|
||||
window.set_title("A window");
|
||||
window.set_app_id("simmer.simplewindow");
|
||||
window.set_min_size(Some((WINDOW_WIDTH, WINDOW_HEIGHT)));
|
||||
window.set_max_size(Some((WINDOW_WIDTH, WINDOW_HEIGHT)));
|
||||
window.set_min_size(Some((WINDOW_WIDTH as u32, WINDOW_HEIGHT as u32)));
|
||||
window.set_max_size(Some((WINDOW_WIDTH as u32, WINDOW_HEIGHT as u32)));
|
||||
|
||||
window.commit();
|
||||
|
||||
@@ -260,8 +264,8 @@ impl WindowHandler for SimpleWindow {
|
||||
let mut draw_area = DrawAreaBuilder::new();
|
||||
|
||||
draw_area.position(0.0, 50.0);
|
||||
draw_area.width(self.width as f32 - 100.0);
|
||||
draw_area.height(self.height as f32 - 50.0);
|
||||
draw_area.width(self.width - 100);
|
||||
draw_area.height(self.height - 50);
|
||||
draw_area.path(&mut self.draw_path);
|
||||
|
||||
let draw_area = draw_area.finish();
|
||||
@@ -273,22 +277,31 @@ impl WindowHandler for SimpleWindow {
|
||||
draw_area,
|
||||
);
|
||||
|
||||
let mut button = ButtonBuilder::new();
|
||||
let mut enter_button = ButtonBuilder::new();
|
||||
|
||||
button.position(self.width as f32 - 100.0, 50.0);
|
||||
button.width(100.0);
|
||||
button.height(50.0);
|
||||
let button = button.finish();
|
||||
enter_button.button_type(ButtonType::Enter);
|
||||
enter_button.position(self.width - 100, 60);
|
||||
enter_button.width(100);
|
||||
enter_button.height(50);
|
||||
let enter_button = enter_button.finish();
|
||||
|
||||
let mut clear_button = ButtonBuilder::new();
|
||||
|
||||
clear_button.button_type(ButtonType::Clear);
|
||||
clear_button.position(self.width - 100, 120);
|
||||
clear_button.width(100);
|
||||
clear_button.height(50);
|
||||
let clear_button = clear_button.finish();
|
||||
|
||||
let mut text_area = TextAreaBuilder::new();
|
||||
text_area.position(0.0, 0.0);
|
||||
text_area.width(self.width as f32);
|
||||
text_area.height(50.0);
|
||||
text_area.width(self.width);
|
||||
text_area.height(50);
|
||||
let text_area = text_area.finish();
|
||||
|
||||
|
||||
window.add_widget(button);
|
||||
window.add_widget(enter_button);
|
||||
window.add_widget(clear_button);
|
||||
window.add_widget(text_area);
|
||||
|
||||
self.ui = Some(window);
|
||||
@@ -354,12 +367,25 @@ impl PointerHandler for SimpleWindow {
|
||||
window.draw_area.path.add_point(pos, true);
|
||||
}
|
||||
|
||||
for widget in &window.widgets {
|
||||
if let Widget::Button(button) = widget {
|
||||
if button.contains_point(pos) {
|
||||
window.draw_area.path = DrawPath::default();
|
||||
}
|
||||
}
|
||||
for button in window.widgets
|
||||
.iter()
|
||||
.filter_map(|widget| {
|
||||
if let Widget::Button(button) = widget {
|
||||
Some(button)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
{
|
||||
match button.button_type {
|
||||
ButtonType::Clear if button.contains_point(pos) => {
|
||||
window.draw_area.path = DrawPath::default();
|
||||
},
|
||||
ButtonType::Enter if button.contains_point(pos) => {
|
||||
print_words((&window.draw_area).into()).unwrap()
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user