add render_panel and set default paint
This commit is contained in:
parent
7a87a50764
commit
42e001d00d
34
Cargo.lock
generated
34
Cargo.lock
generated
@ -282,6 +282,7 @@ dependencies = [
|
||||
"glue",
|
||||
"gtk4",
|
||||
"image",
|
||||
"libadwaita",
|
||||
"libloading 0.8.0",
|
||||
"ndarray",
|
||||
"npyz",
|
||||
@ -1269,6 +1270,39 @@ version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
|
||||
|
||||
[[package]]
|
||||
name = "libadwaita"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ab9c0843f9f23ff25634df2743690c3a1faffe0a190e60c490878517eb81abf"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"gdk-pixbuf",
|
||||
"gdk4",
|
||||
"gio",
|
||||
"glib",
|
||||
"gtk4",
|
||||
"libadwaita-sys",
|
||||
"libc",
|
||||
"pango",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libadwaita-sys"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4231cb2499a9f0c4cdfa4885414b33e39901ddcac61150bc0bb4ff8a57ede404"
|
||||
dependencies = [
|
||||
"gdk4-sys",
|
||||
"gio-sys",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"gtk4-sys",
|
||||
"libc",
|
||||
"pango-sys",
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.147"
|
||||
|
||||
@ -42,3 +42,7 @@ glib-build-tools = "0.17.0"
|
||||
|
||||
[dependencies.geo-macros]
|
||||
path = "geo-macros"
|
||||
|
||||
[dependencies.adw]
|
||||
package = "libadwaita"
|
||||
version = "*"
|
||||
@ -1,7 +1,7 @@
|
||||
use super::control_panel::ControlPanelModel;
|
||||
use gtk::prelude::{
|
||||
use super::{control_panel::ControlPanelModel, render_panel::RenderPanelModel};
|
||||
use gtk::{prelude::{
|
||||
ApplicationExt, ButtonExt, DialogExt, GtkWindowExt, ToggleButtonExt, WidgetExt,
|
||||
};
|
||||
}, traits::OrientableExt};
|
||||
use relm4::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -21,6 +21,7 @@ pub enum AppMsg {
|
||||
pub struct AppModel {
|
||||
mode: AppMode,
|
||||
control: Controller<ControlPanelModel>,
|
||||
render: Controller<RenderPanelModel>,
|
||||
}
|
||||
|
||||
#[relm4::component(pub)]
|
||||
@ -31,9 +32,15 @@ impl SimpleComponent for AppModel {
|
||||
|
||||
view! {
|
||||
main_window = gtk::Window {
|
||||
set_default_width: 500,
|
||||
set_default_height: 250,
|
||||
set_default_width: 1000,
|
||||
set_default_height: 700,
|
||||
set_titlebar: Some(>k::HeaderBar::new()),
|
||||
gtk::Box{
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
set_valign:gtk::Align::Fill,
|
||||
model.control.widget(),
|
||||
model.render.widget(),
|
||||
},
|
||||
connect_close_request[sender] => move |_| {
|
||||
sender.input(AppMsg::CloseRequest);
|
||||
gtk::Inhibit(true)
|
||||
@ -49,11 +56,19 @@ impl SimpleComponent for AppModel {
|
||||
let control = ControlPanelModel::builder()
|
||||
.launch(0)
|
||||
.forward(sender.input_sender(), |msg| AppMsg::Close);
|
||||
|
||||
let render = RenderPanelModel::builder()
|
||||
.launch(0)
|
||||
.forward(sender.input_sender(), |a| AppMsg::Close);
|
||||
|
||||
let model = AppModel {
|
||||
mode: AppMode::View,
|
||||
control: control,
|
||||
render: render,
|
||||
};
|
||||
|
||||
let widgets = view_output!();
|
||||
|
||||
ComponentParts { model, widgets }
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
use adw::prelude::WidgetExt;
|
||||
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt, ToggleButtonExt};
|
||||
use relm4::*;
|
||||
|
||||
@ -18,38 +19,19 @@ impl SimpleComponent for ControlPanelModel {
|
||||
|
||||
view! {
|
||||
#[root]
|
||||
gtk::HeaderBar {
|
||||
#[wrap(Some)]
|
||||
set_title_widget = >k::Box {
|
||||
#[name = "group"]
|
||||
gtk::ToggleButton {
|
||||
gtk::Box {
|
||||
set_orientation: gtk::Orientation::Horizontal,
|
||||
set_spacing: 10,
|
||||
set_size_request: (100, 150),
|
||||
gtk::Button {
|
||||
set_label: "View",
|
||||
set_active: true,
|
||||
connect_toggled[sender] => move |btn| {
|
||||
if btn.is_active() {
|
||||
sender.output(HeaderOutput::View).unwrap()
|
||||
}
|
||||
},
|
||||
},
|
||||
gtk::ToggleButton {
|
||||
gtk::Button {
|
||||
set_label: "Edit",
|
||||
set_group: Some(&group),
|
||||
connect_toggled[sender] => move |btn| {
|
||||
if btn.is_active() {
|
||||
sender.output(HeaderOutput::Edit).unwrap()
|
||||
}
|
||||
},
|
||||
},
|
||||
gtk::ToggleButton {
|
||||
gtk::Button {
|
||||
set_label: "Export",
|
||||
set_group: Some(&group),
|
||||
connect_toggled[sender] => move |btn| {
|
||||
if btn.is_active() {
|
||||
sender.output(HeaderOutput::Export).unwrap()
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
pub mod app;
|
||||
mod control_panel;
|
||||
mod render_panel;
|
||||
40
src/components/render_panel.rs
Normal file
40
src/components/render_panel.rs
Normal file
@ -0,0 +1,40 @@
|
||||
use crate::monitor::Monitor;
|
||||
use crate::coords::proj::Mercator;
|
||||
use crate::render::{
|
||||
BackgroundConfig, BackgroundWidget, ForegroundConfig, ForegroundWidget, Render,
|
||||
};
|
||||
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt, ToggleButtonExt};
|
||||
use relm4::*;
|
||||
|
||||
pub struct RenderPanelModel;
|
||||
|
||||
#[relm4::component(pub)]
|
||||
impl SimpleComponent for RenderPanelModel {
|
||||
type Init = i8;
|
||||
type Output = ();
|
||||
type Input = ();
|
||||
|
||||
view! {
|
||||
#[root]
|
||||
Monitor::new(
|
||||
Render::new(
|
||||
BackgroundWidget::new(BackgroundConfig{ show_lat_lines: true, show_lon_lines: true, ..Default::default() }),
|
||||
ForegroundWidget::new(ForegroundConfig::default()),
|
||||
Some(Mercator::new().into())
|
||||
)
|
||||
),
|
||||
}
|
||||
|
||||
fn init(
|
||||
init: Self::Init,
|
||||
root: &Self::Root,
|
||||
sender: relm4::ComponentSender<Self>,
|
||||
) -> relm4::ComponentParts<Self> {
|
||||
let model = RenderPanelModel {};
|
||||
// Insert the macro code generation here
|
||||
let widgets = view_output!();
|
||||
|
||||
ComponentParts { model, widgets }
|
||||
}
|
||||
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {}
|
||||
}
|
||||
@ -10,7 +10,7 @@ pub struct Mapper {
|
||||
}
|
||||
impl From<Proj> for Mapper {
|
||||
fn from(proj: Proj) -> Self {
|
||||
let default_range: (Range, Range) = ((-180.0..180.0).into(), (-90.0..90.0).into());
|
||||
let default_range: (Range, Range) = ((-180.0..180.0).into(), (-81.0..81.0).into());
|
||||
let bounds = Self::bound(&proj, default_range.clone()).unwrap();
|
||||
Self {
|
||||
proj: proj,
|
||||
@ -53,14 +53,16 @@ impl Mapper {
|
||||
Ok((x, y))
|
||||
}
|
||||
|
||||
pub fn set_lon_range(&mut self, range: std::ops::Range<f64>) {
|
||||
pub fn set_lon_range(&mut self, range: std::ops::Range<f64>)->&mut Self {
|
||||
self.range.0 = range.into();
|
||||
self.bounds = Self::bound(&self.proj, self.range.clone()).unwrap();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_lat_range(&mut self, range: std::ops::Range<f64>) {
|
||||
pub fn set_lat_range(&mut self, range: std::ops::Range<f64>)->&mut Self {
|
||||
self.range.1 = range.into();
|
||||
self.bounds = Self::bound(&self.proj, self.range.clone()).unwrap();
|
||||
self
|
||||
}
|
||||
|
||||
fn bound(proj: &Proj, range: (Range, Range)) -> Result<(f64, f64, f64, f64), ProjError> {
|
||||
|
||||
@ -70,7 +70,7 @@ fn build_ui(app: &Application) {
|
||||
|
||||
let background_widget = BackgroundWidget::new(background_config);
|
||||
let foreground_widget = ForegroundWidget::new(foreground_config);
|
||||
let render = Render::new(background_widget, foreground_widget);
|
||||
let render = Render::new(background_widget, foreground_widget,None);
|
||||
|
||||
let path = "/Users/ruomu/projects/cinrad_g/test2.npz";
|
||||
let data = Radar2d::<i8>::load(path, Npz).unwrap();
|
||||
|
||||
@ -44,6 +44,7 @@ impl Monitor {
|
||||
render.add_controller(pointer_location_detecture);
|
||||
render.add_controller(scale_detecture);
|
||||
render.set_hexpand(true);
|
||||
render.set_vexpand(true);
|
||||
render.set_parent(&this);
|
||||
this.imp().renderer.replace(render);
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ impl BackgroundWidget {
|
||||
if config.show_lat_lines {
|
||||
config.lat_lines.iter().for_each(|lat| {
|
||||
let mut paint = Paint::color(Color::white());
|
||||
paint.set_font_size(35.0);
|
||||
paint.set_font_size(25.0);
|
||||
paint.set_line_width(1.0);
|
||||
let text_location = mapper.map((left, *lat)).unwrap();
|
||||
|
||||
@ -90,7 +90,7 @@ impl BackgroundWidget {
|
||||
if config.show_lon_lines {
|
||||
config.lon_lines.iter().for_each(|lon| {
|
||||
let mut paint = Paint::color(Color::white());
|
||||
paint.set_font_size(35.0);
|
||||
paint.set_font_size(25.0);
|
||||
paint.set_line_width(1.0);
|
||||
let text_location = mapper.map((*lon, top + 0.1)).unwrap();
|
||||
|
||||
@ -136,11 +136,13 @@ impl BackgroundWidget {
|
||||
}
|
||||
|
||||
pub fn set_lat_lines(&self, lat_lines: Vec<f64>) {
|
||||
println!("set lat lines {:?}", lat_lines);
|
||||
let imp = self.imp();
|
||||
imp.config.borrow_mut().lat_lines = lat_lines;
|
||||
}
|
||||
|
||||
pub fn set_lon_lines(&self, lon_lines: Vec<f64>) {
|
||||
println!("set lon lines {:?}", lon_lines);
|
||||
let imp = self.imp();
|
||||
imp.config.borrow_mut().lon_lines = lon_lines;
|
||||
}
|
||||
|
||||
@ -104,11 +104,11 @@ impl GLAreaImpl for Render {
|
||||
|
||||
{
|
||||
let background_widget = self.background.borrow_mut();
|
||||
background_widget.set_lat_lines(lat_range.key_points(5));
|
||||
background_widget.set_lat_lines(lat_range.key_points(9));
|
||||
}
|
||||
{
|
||||
let background_widget = self.background.borrow_mut();
|
||||
background_widget.set_lon_lines(lon_range.key_points(10));
|
||||
background_widget.set_lon_lines(lon_range.key_points(20));
|
||||
}
|
||||
|
||||
self.foreground
|
||||
|
||||
@ -27,12 +27,12 @@ glib::wrapper! {
|
||||
|
||||
impl Default for Render {
|
||||
fn default() -> Self {
|
||||
Self::new(BackgroundWidget::default(), ForegroundWidget::default())
|
||||
Self::new(BackgroundWidget::default(), ForegroundWidget::default(),None)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render {
|
||||
pub fn new(background: BackgroundWidget, foreground: ForegroundWidget) -> Self {
|
||||
pub fn new(background: BackgroundWidget, foreground: ForegroundWidget,mapper: Option<Mapper>) -> Self {
|
||||
let this: Self = glib::Object::new();
|
||||
this.imp().background.replace(background);
|
||||
this.imp().foreground.replace(foreground);
|
||||
@ -40,6 +40,9 @@ impl Render {
|
||||
let mut configs = this.imp().config.borrow_mut();
|
||||
configs.scale = 1.0;
|
||||
}
|
||||
if let Some(mapper) = mapper {
|
||||
this.set_mapper(mapper);
|
||||
}
|
||||
this
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user