Skip to content
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/input_element/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ impl ObjectImpl for InputPopup {

self.width_request(300);
self.height_request(300);
self.set_borders(1., 1., 1., 1.);
self.set_border_radius(6.);
// self.set_borders(1., 1., 1., 1.);
self.set_border_color(Color::GREY_LIGHT);
self.set_background(Color::GREY_LIGHT);
self.set_box_shadow(BoxShadow::new(
6.,
Color::BLACK,
Expand Down
3 changes: 2 additions & 1 deletion examples/list_view/list_view_holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl ObjectImpl for ListViewHolder {
self.list_view_1.set_hexpand(true);
self.list_view_1.set_vexpand(true);
self.list_view_1.set_hscale(0.3);
self.list_view_1.set_line_height(40);

self.list_view_2.set_hexpand(true);
self.list_view_2.set_vexpand(true);
Expand Down Expand Up @@ -125,7 +126,7 @@ impl ObjectImpl for ListViewHolder {
}
list.add_group(group);

for i in 10..1000000 {
for i in 10..100 {
list.add_node(&Node {
name: format!("Node_{}", i),
});
Expand Down
24 changes: 20 additions & 4 deletions examples/list_view/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use list_view_holder::ListViewHolder;
use tmui::{
application::Application,
application_window::ApplicationWindow,
icons::svg_dom::SvgDom,
prelude::*,
views::{
cell::{
cell_render::TextCellRender,
cell_render::{SvgCellRender, TextCellRender},
Cell,
},
list_view::list_view_object::ListViewObject,
Expand Down Expand Up @@ -39,14 +40,29 @@ struct Node {
impl ListViewObject for Node {
#[inline]
fn cells(&self) -> Vec<Cell> {
let dom = SvgDom::from_file("examples/resources/sword_rose.svg");
vec![
Cell::string()
.value(self.name.clone())
.cell_render(TextCellRender::builder().color(Color::BLACK).build())
.cell_render(
TextCellRender::builder()
.color(Color::BLACK)
.halign(Align::Center)
.valign(Align::Center)
.build(),
)
.build(),
Cell::string()
.value(self.name.clone())
.cell_render(TextCellRender::builder().color(Color::BLACK).build())
.cell_render(
TextCellRender::builder()
.color(Color::BLACK)
.valign(Align::Center)
.build(),
)
.build(),
Cell::svg()
.cell_render(SvgCellRender::builder().dom(Some(dom)).build())
.build(),
]
}
Expand All @@ -55,4 +71,4 @@ impl ListViewObject for Node {
fn node_render(&self) -> NodeRender {
NodeRender::builder().build()
}
}
}
25 changes: 21 additions & 4 deletions tmui/src/application_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub struct ApplicationWindow {
root_ancestors: Vec<ObjectId>,
win_widgets: Vec<WinWidgetHnd>,
removed: Vec<DynTr>,
radius_widgets: Vec<ObjectId>,

#[cfg(not(win_dialog))]
input_dialog: Option<Tr<crate::input::dialog::InputDialog>>,
Expand Down Expand Up @@ -776,14 +777,15 @@ impl ApplicationWindow {
self.mouse_over_widget = None;
}
self.mouse_enter_widgets
.retain_mut(|r| nonnull_ref!(r).id() != id);
self.run_afters.retain_mut(|r| nonnull_ref!(r).id() != id);
.retain(|r| nonnull_ref!(r).id() != id);
self.run_afters.retain(|r| nonnull_ref!(r).id() != id);
for map in self.watch_map.values_mut() {
map.remove(&id);
}
self.overlaids.remove(&id);
self.root_ancestors.retain_mut(|r| *r != id);
self.win_widgets.retain_mut(|r| nonnull_ref!(r).id() != id);
self.root_ancestors.retain(|r| *r != id);
self.win_widgets.retain(|r| nonnull_ref!(r).id() != id);
self.radius_widgets.retain(|r| *r != id);

nonnull_ref!(self.board).remove_element(id);
AnimationMgr::with(|mgr| mgr.borrow_mut().remove_snapshot(id));
Expand All @@ -808,6 +810,21 @@ impl ApplicationWindow {
&mut self.overlaids
}

#[inline]
pub(crate) fn get_radius_widgets(&self) -> &[ObjectId] {
&self.radius_widgets
}

#[inline]
pub(crate) fn remove_radius_widget(&mut self, id: ObjectId) {
self.radius_widgets.retain(|w| *w != id);
}

#[inline]
pub(crate) fn add_radius_widget(&mut self, id: ObjectId) {
self.radius_widgets.push(id);
}

#[inline]
pub(crate) fn set_modal_widget(&mut self, id: Option<ObjectId>) {
// Trigger the mouse leave method for all entered widgets
Expand Down
11 changes: 11 additions & 0 deletions tmui/src/graphics/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ impl<'a> Painter<'a> {
rect.offset(self.x_offset, self.y_offset)
}

#[inline]
pub fn font(&self) -> Option<&Font> {
self.font.as_ref()
}

#[inline]
pub fn set_transform(&mut self, transform: Matrix, combined: bool) {
if combined {
Expand Down Expand Up @@ -217,6 +222,12 @@ impl<'a> Painter<'a> {

#[inline]
pub fn translate(&self, dx: f32, dy: f32) {
self.canvas
.translate((dx + self.x_offset as f32, dy + self.y_offset as f32));
}

#[inline]
pub fn translate_global(&self, dx: f32, dy: f32) {
self.canvas.translate((dx, dy));
}

Expand Down
2 changes: 1 addition & 1 deletion tmui/src/icons/svg_icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl WidgetImpl for SvgIcon {
let origin = FPoint::new(x1 + (w1 - w2) / 2., y1 + (h1 - h2) / 2.);

painter.save();
painter.translate(origin.x(), origin.y());
painter.translate_global(origin.x(), origin.y());
painter.draw_dom(dom);
painter.restore();
}
Expand Down
2 changes: 1 addition & 1 deletion tmui/src/icons/svg_toggle_icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl WidgetImpl for SvgToggleIcon {
fn paint(&mut self, painter: &mut Painter) {
if let Some(dom) = self.doms.get(self.index) {
painter.save();
painter.translate(self.origin.x(), self.origin.y());
painter.translate_global(self.origin.x(), self.origin.y());
painter.draw_dom(dom);
painter.restore();
}
Expand Down
4 changes: 2 additions & 2 deletions tmui/src/input/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl Number {
let y = inner1.y() + (inner1.height() - ARROW_SIZE) / 2.;
if let Some(ref dom) = self.arrow_up {
painter.save();
painter.translate(x, y);
painter.translate_global(x, y);
painter.draw_dom(dom);
painter.restore();
}
Expand All @@ -435,7 +435,7 @@ impl Number {
let y = inner2.y() + (inner1.height() - ARROW_SIZE) / 2.;
if let Some(ref dom) = self.arrow_down {
painter.save();
painter.translate(x, y);
painter.translate_global(x, y);
painter.draw_dom(dom);
painter.restore();
}
Expand Down
2 changes: 1 addition & 1 deletion tmui/src/input/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl<T: SelectBounds> Select<T> {
if let Some(ref dom) = self.dom {
painter.save();
let pos = self.arrow_pos();
painter.translate(pos.x(), pos.y());
painter.translate_global(pos.x(), pos.y());
painter.draw_dom(dom);
painter.restore();
}
Expand Down
Loading