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",
|
"glue",
|
||||||
"gtk4",
|
"gtk4",
|
||||||
"image",
|
"image",
|
||||||
|
"libadwaita",
|
||||||
"libloading 0.8.0",
|
"libloading 0.8.0",
|
||||||
"ndarray",
|
"ndarray",
|
||||||
"npyz",
|
"npyz",
|
||||||
@ -1269,6 +1270,39 @@ version = "0.5.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
|
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]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.147"
|
version = "0.2.147"
|
||||||
|
|||||||
@ -42,3 +42,7 @@ glib-build-tools = "0.17.0"
|
|||||||
|
|
||||||
[dependencies.geo-macros]
|
[dependencies.geo-macros]
|
||||||
path = "geo-macros"
|
path = "geo-macros"
|
||||||
|
|
||||||
|
[dependencies.adw]
|
||||||
|
package = "libadwaita"
|
||||||
|
version = "*"
|
||||||
@ -1,7 +1,7 @@
|
|||||||
use super::control_panel::ControlPanelModel;
|
use super::{control_panel::ControlPanelModel, render_panel::RenderPanelModel};
|
||||||
use gtk::prelude::{
|
use gtk::{prelude::{
|
||||||
ApplicationExt, ButtonExt, DialogExt, GtkWindowExt, ToggleButtonExt, WidgetExt,
|
ApplicationExt, ButtonExt, DialogExt, GtkWindowExt, ToggleButtonExt, WidgetExt,
|
||||||
};
|
}, traits::OrientableExt};
|
||||||
use relm4::*;
|
use relm4::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -21,6 +21,7 @@ pub enum AppMsg {
|
|||||||
pub struct AppModel {
|
pub struct AppModel {
|
||||||
mode: AppMode,
|
mode: AppMode,
|
||||||
control: Controller<ControlPanelModel>,
|
control: Controller<ControlPanelModel>,
|
||||||
|
render: Controller<RenderPanelModel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[relm4::component(pub)]
|
#[relm4::component(pub)]
|
||||||
@ -31,9 +32,15 @@ impl SimpleComponent for AppModel {
|
|||||||
|
|
||||||
view! {
|
view! {
|
||||||
main_window = gtk::Window {
|
main_window = gtk::Window {
|
||||||
set_default_width: 500,
|
set_default_width: 1000,
|
||||||
set_default_height: 250,
|
set_default_height: 700,
|
||||||
set_titlebar: Some(>k::HeaderBar::new()),
|
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 |_| {
|
connect_close_request[sender] => move |_| {
|
||||||
sender.input(AppMsg::CloseRequest);
|
sender.input(AppMsg::CloseRequest);
|
||||||
gtk::Inhibit(true)
|
gtk::Inhibit(true)
|
||||||
@ -49,11 +56,19 @@ impl SimpleComponent for AppModel {
|
|||||||
let control = ControlPanelModel::builder()
|
let control = ControlPanelModel::builder()
|
||||||
.launch(0)
|
.launch(0)
|
||||||
.forward(sender.input_sender(), |msg| AppMsg::Close);
|
.forward(sender.input_sender(), |msg| AppMsg::Close);
|
||||||
|
|
||||||
|
let render = RenderPanelModel::builder()
|
||||||
|
.launch(0)
|
||||||
|
.forward(sender.input_sender(), |a| AppMsg::Close);
|
||||||
|
|
||||||
let model = AppModel {
|
let model = AppModel {
|
||||||
mode: AppMode::View,
|
mode: AppMode::View,
|
||||||
control: control,
|
control: control,
|
||||||
|
render: render,
|
||||||
};
|
};
|
||||||
|
|
||||||
let widgets = view_output!();
|
let widgets = view_output!();
|
||||||
|
|
||||||
ComponentParts { model, widgets }
|
ComponentParts { model, widgets }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
use adw::prelude::WidgetExt;
|
||||||
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt, ToggleButtonExt};
|
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt, ToggleButtonExt};
|
||||||
use relm4::*;
|
use relm4::*;
|
||||||
|
|
||||||
@ -18,38 +19,19 @@ impl SimpleComponent for ControlPanelModel {
|
|||||||
|
|
||||||
view! {
|
view! {
|
||||||
#[root]
|
#[root]
|
||||||
gtk::HeaderBar {
|
gtk::Box {
|
||||||
#[wrap(Some)]
|
set_orientation: gtk::Orientation::Horizontal,
|
||||||
set_title_widget = >k::Box {
|
set_spacing: 10,
|
||||||
#[name = "group"]
|
set_size_request: (100, 150),
|
||||||
gtk::ToggleButton {
|
gtk::Button {
|
||||||
set_label: "View",
|
set_label: "View",
|
||||||
set_active: true,
|
|
||||||
connect_toggled[sender] => move |btn| {
|
|
||||||
if btn.is_active() {
|
|
||||||
sender.output(HeaderOutput::View).unwrap()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
gtk::Button {
|
||||||
gtk::ToggleButton {
|
|
||||||
set_label: "Edit",
|
set_label: "Edit",
|
||||||
set_group: Some(&group),
|
|
||||||
connect_toggled[sender] => move |btn| {
|
|
||||||
if btn.is_active() {
|
|
||||||
sender.output(HeaderOutput::Edit).unwrap()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
gtk::Button {
|
||||||
gtk::ToggleButton {
|
|
||||||
set_label: "Export",
|
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;
|
pub mod app;
|
||||||
mod control_panel;
|
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 {
|
impl From<Proj> for Mapper {
|
||||||
fn from(proj: Proj) -> Self {
|
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();
|
let bounds = Self::bound(&proj, default_range.clone()).unwrap();
|
||||||
Self {
|
Self {
|
||||||
proj: proj,
|
proj: proj,
|
||||||
@ -53,14 +53,16 @@ impl Mapper {
|
|||||||
Ok((x, y))
|
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.range.0 = range.into();
|
||||||
self.bounds = Self::bound(&self.proj, self.range.clone()).unwrap();
|
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.range.1 = range.into();
|
||||||
self.bounds = Self::bound(&self.proj, self.range.clone()).unwrap();
|
self.bounds = Self::bound(&self.proj, self.range.clone()).unwrap();
|
||||||
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bound(proj: &Proj, range: (Range, Range)) -> Result<(f64, f64, f64, f64), ProjError> {
|
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 background_widget = BackgroundWidget::new(background_config);
|
||||||
let foreground_widget = ForegroundWidget::new(foreground_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 path = "/Users/ruomu/projects/cinrad_g/test2.npz";
|
||||||
let data = Radar2d::<i8>::load(path, Npz).unwrap();
|
let data = Radar2d::<i8>::load(path, Npz).unwrap();
|
||||||
|
|||||||
@ -44,6 +44,7 @@ impl Monitor {
|
|||||||
render.add_controller(pointer_location_detecture);
|
render.add_controller(pointer_location_detecture);
|
||||||
render.add_controller(scale_detecture);
|
render.add_controller(scale_detecture);
|
||||||
render.set_hexpand(true);
|
render.set_hexpand(true);
|
||||||
|
render.set_vexpand(true);
|
||||||
render.set_parent(&this);
|
render.set_parent(&this);
|
||||||
this.imp().renderer.replace(render);
|
this.imp().renderer.replace(render);
|
||||||
|
|
||||||
|
|||||||
@ -74,7 +74,7 @@ impl BackgroundWidget {
|
|||||||
if config.show_lat_lines {
|
if config.show_lat_lines {
|
||||||
config.lat_lines.iter().for_each(|lat| {
|
config.lat_lines.iter().for_each(|lat| {
|
||||||
let mut paint = Paint::color(Color::white());
|
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);
|
paint.set_line_width(1.0);
|
||||||
let text_location = mapper.map((left, *lat)).unwrap();
|
let text_location = mapper.map((left, *lat)).unwrap();
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ impl BackgroundWidget {
|
|||||||
if config.show_lon_lines {
|
if config.show_lon_lines {
|
||||||
config.lon_lines.iter().for_each(|lon| {
|
config.lon_lines.iter().for_each(|lon| {
|
||||||
let mut paint = Paint::color(Color::white());
|
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);
|
paint.set_line_width(1.0);
|
||||||
let text_location = mapper.map((*lon, top + 0.1)).unwrap();
|
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>) {
|
pub fn set_lat_lines(&self, lat_lines: Vec<f64>) {
|
||||||
|
println!("set lat lines {:?}", lat_lines);
|
||||||
let imp = self.imp();
|
let imp = self.imp();
|
||||||
imp.config.borrow_mut().lat_lines = lat_lines;
|
imp.config.borrow_mut().lat_lines = lat_lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_lon_lines(&self, lon_lines: Vec<f64>) {
|
pub fn set_lon_lines(&self, lon_lines: Vec<f64>) {
|
||||||
|
println!("set lon lines {:?}", lon_lines);
|
||||||
let imp = self.imp();
|
let imp = self.imp();
|
||||||
imp.config.borrow_mut().lon_lines = lon_lines;
|
imp.config.borrow_mut().lon_lines = lon_lines;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -104,11 +104,11 @@ impl GLAreaImpl for Render {
|
|||||||
|
|
||||||
{
|
{
|
||||||
let background_widget = self.background.borrow_mut();
|
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();
|
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
|
self.foreground
|
||||||
|
|||||||
@ -27,12 +27,12 @@ glib::wrapper! {
|
|||||||
|
|
||||||
impl Default for Render {
|
impl Default for Render {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new(BackgroundWidget::default(), ForegroundWidget::default())
|
Self::new(BackgroundWidget::default(), ForegroundWidget::default(),None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render {
|
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();
|
let this: Self = glib::Object::new();
|
||||||
this.imp().background.replace(background);
|
this.imp().background.replace(background);
|
||||||
this.imp().foreground.replace(foreground);
|
this.imp().foreground.replace(foreground);
|
||||||
@ -40,6 +40,9 @@ impl Render {
|
|||||||
let mut configs = this.imp().config.borrow_mut();
|
let mut configs = this.imp().config.borrow_mut();
|
||||||
configs.scale = 1.0;
|
configs.scale = 1.0;
|
||||||
}
|
}
|
||||||
|
if let Some(mapper) = mapper {
|
||||||
|
this.set_mapper(mapper);
|
||||||
|
}
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user