Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge from Develop #154

Merged
merged 6 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/complex_layout/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn main() {
.height(800)
.title("Complex Layout")
.transparent(true)
.defer_display(true)
.build();

app.connect_activate(build_ui);
Expand All @@ -25,5 +26,6 @@ fn main() {
}

fn build_ui(window: &mut ApplicationWindow) {
window.child(View::new())
window.child(View::new());
window.show_on_ready();
}
3 changes: 3 additions & 0 deletions examples/input_element/holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ impl WidgetImpl for Holder {
let geometry = Rect::new(pos.x(), pos.y(), 0, 0);
InputDialog::hide_on_win_changed(true);
let dialog = InputDialog::text(geometry, None);
dialog.register_visibility_changed(|w, visible| {
println!("InputDialog {} visibility changed, {}", w.name(), visible)
});
assert!(dialog.input_mut::<Text>().is_some());
assert!(dialog.input_mut::<Number>().is_none());
}
Expand Down
20 changes: 17 additions & 3 deletions examples/label_window/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@ fn main() {
}

fn build_ui(window: &mut ApplicationWindow) {
let mut label = Label::new(Some("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()/\\"));
label.set_font(Font::with_families(&["Courier New"]));
window.child(label)
let mut vbox = VBox::new();

let mut label_1 = Label::new(Some("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()/\\"));
label_1.set_font(Font::with_families(&["Courier New"]));

let mut label_2 = Label::new(Some(r#"virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2""#));
label_2.set_auto_wrap(true);
label_2.set_font(Font::with_families(&["Courier New"]));
label_2.width_request(230);

vbox.set_vexpand(true);
vbox.set_hexpand(true);
vbox.set_spacing(10);
vbox.add_child(label_1);
vbox.add_child(label_2);

window.child(vbox)
}
16 changes: 16 additions & 0 deletions examples/skia_paint/skia_paint.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::f32;

use log::debug;
use skia_safe::textlayout::{FontCollection, ParagraphBuilder, ParagraphStyle, TextStyle};
use tlib::{
Expand Down Expand Up @@ -58,6 +60,8 @@ impl WidgetImpl for SkiaPaint {

self.draw_blur_border(painter);

self.draw_multi_line_label(painter);

println!("cnt: {}", painter.save_count());
}
}
Expand Down Expand Up @@ -381,4 +385,16 @@ impl SkiaPaint {
rect.set_height(rect.height() + 5.);
// painter.draw_rect(rect);
}

fn draw_multi_line_label(&self, painter: &mut Painter) {
let origin = Point::new(1000, 700);
painter.draw_paragraph(
r#"virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2""#,
origin,
0.,
220.,
None,
false,
);
}
}
7 changes: 2 additions & 5 deletions examples/tree_view/ctx_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ impl ObjectImpl for CtxMenu {
fn on_property_set(&mut self, name: &str, value: &Value) {
self.parent_on_property_set(name, value);

match name {
"view_id" => {
self.selection_list.set_property("view_id", value.clone());
}
_ => {}
if name == "view_id" {
self.selection_list.set_property("view_id", value.clone());
}
}
}
Expand Down
36 changes: 31 additions & 5 deletions examples/tree_view/tree_view_holder.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#![allow(dead_code)]
use std::{cmp::Ordering, time::Duration};
use std::{cmp::Ordering, rc::Rc, time::Duration};
use tlib::{
actions::ActionExt, compare::Compare, connect, global::SemanticExt, namespace::MouseButton,
timer::Timer, tokio::task::JoinHandle,
actions::ActionExt, compare::Compare, connect, figure::OptionSize, global::SemanticExt, namespace::MouseButton, timer::Timer, tokio::task::JoinHandle
};
use tmui::{
container::ScaleStrat,
cursor::Cursor,
graphics::styles::Styles,
prelude::*,
tlib::object::{ObjectImpl, ObjectSubclass},
tooltip::Tooltip,
views::{
cell::{cell_render::TextCellRender, Cell},
node::node_render::NodeRender,
Expand All @@ -33,6 +35,8 @@ pub struct TreeViewHolder {

#[children]
tree_view_3: Box<TreeView>,

tooltip_timer: Rc<Box<Timer>>,
}

impl ObjectSubclass for TreeViewHolder {
Expand All @@ -42,6 +46,7 @@ impl ObjectSubclass for TreeViewHolder {
impl ObjectImpl for TreeViewHolder {
fn construct(&mut self) {
self.parent_construct();
connect!(self.tooltip_timer, timeout(), self, tooltip());

self.tree_view
.set_layout_mode(tmui::scroll_area::LayoutMode::Overlay);
Expand Down Expand Up @@ -91,11 +96,16 @@ impl ObjectImpl for TreeViewHolder {
evt.position()
);
});
self.tree_view.register_node_enter(|node, _| {
let timer = self.tooltip_timer.clone();
self.tree_view.register_node_enter(move |node, _| {
println!("Node enter, id = {}", node.id());
timer.start(Duration::from_millis(500));
});
self.tree_view.register_node_leave(|node, _| {
let timer = self.tooltip_timer.clone();
self.tree_view.register_node_leave(move |node, _| {
println!("Node leave, id = {}", node.id());
timer.stop();
Tooltip::hide();
});
self.tree_view.register_free_area_released(|node, evt| {
if evt.mouse_button() != MouseButton::RightButton {
Expand Down Expand Up @@ -333,6 +343,22 @@ impl TreeViewHolder {
pub fn new() -> Box<Self> {
Object::new(&[])
}

#[inline]
fn tooltip(&self) {
println!("Show tooltip");
self.tooltip_timer.stop();
Tooltip::show(
"This is a multiple-line Tooltip text content, to test Label auto line wrapping.",
Cursor::position(),
OptionSize::width_only(200),
Some(
Styles::default()
.with_halign(Align::Center)
.with_valign(Align::Center),
),
);
}
}

#[extends(Object)]
Expand Down
2 changes: 1 addition & 1 deletion macros/src/extend_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ pub(crate) fn expand(
// Popup related end.

let inner_on_property_set_clause = if layout.is(LayoutType::Stack) {
generate_stack_inner_on_property_set()?
generate_stack_inner_on_property_set(use_prefix)?
} else {
quote!(false)
};
Expand Down
4 changes: 3 additions & 1 deletion macros/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ pub(crate) fn generate_stack_inner_initial() -> syn::Result<proc_macro2::TokenSt
})
}

pub(crate) fn generate_stack_inner_on_property_set() -> syn::Result<proc_macro2::TokenStream> {
pub(crate) fn generate_stack_inner_on_property_set(use_prefix: &Ident) -> syn::Result<proc_macro2::TokenStream> {
Ok(quote!{
use #use_prefix::widget::InnerEventProcess;
match name {
"visible" => {
let visible = value.get::<bool>();
emit!(self.visibility_changed(), visible);
self.inner_visibility_changed(visible);
self.on_visibility_changed(visible);
if visible {
if let Some(c) = self.current_child_mut() {
Expand Down
43 changes: 43 additions & 0 deletions tlib/src/figure/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,49 @@ impl SizeHint {
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
/// OptionSize
//////////////////////////////////////////////////////////////////////////////////////////////////////
pub struct OptionSize {
width: Option<i32>,
height: Option<i32>,
}

impl OptionSize {
#[inline]
pub fn new(width: i32, height: i32) -> Self {
Self {
width: Some(width),
height: Some(height),
}
}

#[inline]
pub fn width_only(width: i32) -> Self {
Self { width: Some(width), height: None }
}

#[inline]
pub fn height_only(height: i32) -> Self {
Self { width: None, height: Some(height) }
}

#[inline]
pub fn none() -> Self {
Self { width: None, height: None }
}

#[inline]
pub fn width(&self) -> Option<i32> {
self.width
}

#[inline]
pub fn height(&self) -> Option<i32> {
self.height
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
Loading
Loading