Skip to content

Commit

Permalink
Move azul-widgets into azul-dll, debug hit tester
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed May 14, 2021
1 parent 60c00fb commit 8d67426
Show file tree
Hide file tree
Showing 21 changed files with 578 additions and 492 deletions.
8 changes: 0 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ members = [
"azul-core",
"azul-layout",
"azul-text-layout",
"azul-widgets",
"azul-css-parser",
"examples",
]
Expand Down
161 changes: 97 additions & 64 deletions api.json
Original file line number Diff line number Diff line change
Expand Up @@ -2020,70 +2020,6 @@
}
}
},
"menu": {
"classes": {
"Menu": {
"doc": "Menu struct (application / window menu, dropdown menu, context menu). Modeled after the Windows API",
"external": "azul_impl::window::Menu",
"struct_fields": [
{"items": {"type": "MenuItemVec", "doc": "Items in this menu"}}
]
},
"MenuItem": {
"doc": "Item entry in a menu or menu bar",
"external": "azul_impl::window::MenuItem",
"enum_fields": [
{"Label": {"type": "StringMenuItem", "doc": "Regular \"labeled\" menu item"}},
{"Separator": {"doc": "Line separator, usually only rendered in vertical menus"}},
{"BreakLine": {"doc": "Breaks items in a menu onto separate lines, usually only rendered in horizontal menu bars"}}
]
},
"StringMenuItem": {
"doc": "Regular labeled menu item",
"external": "azul_impl::window::StringMenuItem",
"struct_fields": [
{"label": {"type": "String", "doc": "Label of the menu entry"}},
{"accelerator": {"type": "OptionVirtualKeyCodeCombo", "doc": "Optional accelerator combination, (ex. \"CTRL + X\" = [VirtualKeyCode::Ctrl, VirtualKeyCode::X]) for keyboard shortcut"}},
{"callback": {"type": "OptionMenuCallback", "doc": "Optional callback to call when the item is activated"}},
{"state": {"type": "MenuItemState", "doc": "State of the menu entry (normal, greyed, disabled)"}},
{"icon": {"type": "OptionMenuItemIcon", "doc": "Optional icon (checkbox or custom image) of the menu entry"}},
{"children": {"type": "MenuItemVec", "doc": "Sub-menus of the window (empty by default)"}}
]
},
"VirtualKeyCodeCombo": {
"doc": "Combination of virtual key codes that have to be pressed together",
"external": "azul_impl::window::VirtualKeyCodeCombo",
"struct_fields": [
{"keys": {"type": "VirtualKeyCodeVec"}}
]
},
"MenuCallback": {
"doc": "Similar to `dom.CallbackData`, stores some data + a callback to call when the menu is activated",
"external": "azul_impl::window::MenuCallback",
"struct_fields": [
{"callback": {"type": "Callback", "doc": "Callback to be called when the menu item is clicked"}},
{"data": {"type": "RefAny", "doc": "Data of the callback to be called on"}}
]
},
"MenuItemIcon": {
"doc": "Icon of a menu entry",
"external": "azul_impl::window::MenuItemIcon",
"enum_fields": [
{"Checkbox": {"type": "bool", "doc": "Menu item shows a checkbox (either checked or not)"}},
{"Image": {"type": "ImageRef", "doc": "Menu item shows a custom image, usually in 16x16 format"}}
]
},
"MenuItemState": {
"doc": "Describes the state of a menu item",
"external": "azul_impl::window::MenuItemState",
"enum_fields": [
{"Normal": {"doc": "Normal menu item (default)"}},
{"Greyed": {"doc": "Menu item is greyed out and clicking it does nothing"}},
{"Disabled": {"doc": "Menu item is disabled, clicking it does nothing - but NOT greyed out"}}
]
}
}
},
"dom": {
"doc": "`Dom` construction and configuration",
"classes": {
Expand Down Expand Up @@ -2959,6 +2895,70 @@
}
}
},
"menu": {
"classes": {
"Menu": {
"doc": "Menu struct (application / window menu, dropdown menu, context menu). Modeled after the Windows API",
"external": "azul_impl::window::Menu",
"struct_fields": [
{"items": {"type": "MenuItemVec", "doc": "Items in this menu"}}
]
},
"MenuItem": {
"doc": "Item entry in a menu or menu bar",
"external": "azul_impl::window::MenuItem",
"enum_fields": [
{"Label": {"type": "StringMenuItem", "doc": "Regular \"labeled\" menu item"}},
{"Separator": {"doc": "Line separator, usually only rendered in vertical menus"}},
{"BreakLine": {"doc": "Breaks items in a menu onto separate lines, usually only rendered in horizontal menu bars"}}
]
},
"StringMenuItem": {
"doc": "Regular labeled menu item",
"external": "azul_impl::window::StringMenuItem",
"struct_fields": [
{"label": {"type": "String", "doc": "Label of the menu entry"}},
{"accelerator": {"type": "OptionVirtualKeyCodeCombo", "doc": "Optional accelerator combination, (ex. \"CTRL + X\" = [VirtualKeyCode::Ctrl, VirtualKeyCode::X]) for keyboard shortcut"}},
{"callback": {"type": "OptionMenuCallback", "doc": "Optional callback to call when the item is activated"}},
{"state": {"type": "MenuItemState", "doc": "State of the menu entry (normal, greyed, disabled)"}},
{"icon": {"type": "OptionMenuItemIcon", "doc": "Optional icon (checkbox or custom image) of the menu entry"}},
{"children": {"type": "MenuItemVec", "doc": "Sub-menus of the window (empty by default)"}}
]
},
"VirtualKeyCodeCombo": {
"doc": "Combination of virtual key codes that have to be pressed together",
"external": "azul_impl::window::VirtualKeyCodeCombo",
"struct_fields": [
{"keys": {"type": "VirtualKeyCodeVec"}}
]
},
"MenuCallback": {
"doc": "Similar to `dom.CallbackData`, stores some data + a callback to call when the menu is activated",
"external": "azul_impl::window::MenuCallback",
"struct_fields": [
{"callback": {"type": "Callback", "doc": "Callback to be called when the menu item is clicked"}},
{"data": {"type": "RefAny", "doc": "Data of the callback to be called on"}}
]
},
"MenuItemIcon": {
"doc": "Icon of a menu entry",
"external": "azul_impl::window::MenuItemIcon",
"enum_fields": [
{"Checkbox": {"type": "bool", "doc": "Menu item shows a checkbox (either checked or not)"}},
{"Image": {"type": "ImageRef", "doc": "Menu item shows a custom image, usually in 16x16 format"}}
]
},
"MenuItemState": {
"doc": "Describes the state of a menu item",
"external": "azul_impl::window::MenuItemState",
"enum_fields": [
{"Normal": {"doc": "Normal menu item (default)"}},
{"Greyed": {"doc": "Menu item is greyed out and clicking it does nothing"}},
{"Disabled": {"doc": "Menu item is disabled, clicking it does nothing - but NOT greyed out"}}
]
}
}
},
"css": {
"doc": "`Css` parsing module",
"classes": {
Expand Down Expand Up @@ -4909,6 +4909,39 @@
}
}
},
"widgets": {
"doc": "Default, built-in widgets (button, label, textinput, etc.)",
"classes": {
"Button": {
"external": "crate::widgets::button::Button",

},
"CheckBox": {
"external": "crate::widgets::check_box::CheckBox",

},
"Label": {
"external": "crate::widgets::label::Label",

},
"TextInput": {
"external": "crate::widgets::text_input::TextInput",

},
"NumberInput": {
"external": "crate::widgets::number_input::NumberInput",

},
"ColorInput": {
"external": "crate::widgets::color_input::ColorInput",

},
"Spreadsheet": {
"external": "crate::widgets::table_view::TableView",

},
}
},
"style": {
"doc": "DOM to CSS cascading and styling module",
"classes": {
Expand Down
12 changes: 0 additions & 12 deletions azul-core/src/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,20 +1411,8 @@ fn convert_dom_into_compact_dom(mut dom: Dom) -> CompactDom {
last_child: if dom.children.is_empty() { None } else { Some(root_node_id + dom.estimated_total_children) },
};

println!("converting DOM into compact DOM:
dom: {:#?}
node_hierarchy: {:#?}
node_data: {:#?}
root_node_id: {:#?}
root_node: {:#?}
cur_node_id: {:#?}
", dom, node_hierarchy, node_data, root_node_id, root_node, cur_node_id);

convert_dom_into_compact_dom_internal(&mut dom, &mut node_hierarchy, &mut node_data, root_node_id, root_node, &mut cur_node_id);

println!("ok: converted: {:?}, {:?}", node_hierarchy, node_data);

CompactDom {
node_hierarchy: NodeHierarchy { internal: node_hierarchy },
node_data: NodeDataContainer { internal: node_data },
Expand Down
32 changes: 0 additions & 32 deletions azul-core/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,44 +478,19 @@ impl ScrollStates {
.set(scroll_position.x, scroll_position.y, &node.child_rect);
}

/// NOTE: This has to be a getter, because we need to update
#[must_use = "function marks the scroll ID as dirty, therefore the function is must_use"]
pub fn get_scroll_position_and_mark_as_used(&mut self, scroll_id: &ExternalScrollId) -> Option<LogicalPosition> {
let entry = self.0.get_mut(&scroll_id)?;
Some(entry.get_and_mark_as_used())
}

/// Updating (add to) the existing scroll amount does not update the `entry.used_this_frame`,
/// since that is only relevant when we are actually querying the renderer.
pub fn scroll_node(&mut self, node: &OverflowingScrollNode, scroll_by_x: f32, scroll_by_y: f32) {
self.0.entry(node.parent_external_scroll_id)
.or_insert_with(|| ScrollState::default())
.add(scroll_by_x, scroll_by_y, &node.child_rect);
}

/// Removes all scroll states that weren't used in the last frame
pub fn remove_unused_scroll_states(&mut self) {
// NOTE: originally this code used retain(), but retain() is not available on no_std
let mut scroll_states_to_remove = Vec::new();

for (key, state) in self.0.iter_mut() {
if !state.used_this_frame {
scroll_states_to_remove.push(*key);
}
}

for key in scroll_states_to_remove {
self.0.remove(&key);
}
}
}

#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
pub struct ScrollState {
/// Amount in pixel that the current node is scrolled
pub scroll_position: LogicalPosition,
/// Was the scroll amount used in this frame?
pub used_this_frame: bool,
}

impl ScrollState {
Expand All @@ -536,19 +511,12 @@ impl ScrollState {
self.scroll_position.x = x.max(0.0).min(child_rect.size.width);
self.scroll_position.y = y.max(0.0).min(child_rect.size.height);
}

/// Returns the scroll position and also set the "used_this_frame" flag
pub fn get_and_mark_as_used(&mut self) -> LogicalPosition {
self.used_this_frame = true;
self.scroll_position
}
}

impl Default for ScrollState {
fn default() -> Self {
ScrollState {
scroll_position: LogicalPosition::zero(),
used_this_frame: true,
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions azul-desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,13 @@ fn run_inner(app: App) -> ! {
window.regenerate_styled_dom(&mut data, &image_cache, &mut resource_updates, &mut fc_cache);
window.rebuild_display_list(&mut transaction, &image_cache, resource_updates);
window.render_async(transaction, /* display list was rebuilt */ true);
window.force_synchronize_hit_tester_during();

// do the same thing again, but this time after the hit_tester has been updated
let mut resource_updates = Vec::new();
let mut transaction = WrTransaction::new();
window.rebuild_display_list(&mut transaction, &image_cache, resource_updates);
window.render_async(transaction, /* display list was rebuilt */ true);
hit_tester_request = Some((*window_id, window.render_api.request_hit_tester(
wr_translate_document_id(window.internal.document_id)))
);
Expand Down Expand Up @@ -775,9 +782,7 @@ fn run_inner(app: App) -> ! {
loop {
let events = Events::new(&window.internal.current_window_state, &window.internal.previous_window_state);
let layout_callback_changed = window.internal.current_window_state.layout_callback_changed(&window.internal.previous_window_state);
let hit_test = if !events.needs_hit_test() {
FullHitTest::empty(window.internal.current_window_state.focused_node)
} else {
let hit_test = {
let ht = crate::wr_translate::fullhittest_new_webrender(
&*window.hit_tester,
window.internal.document_id,
Expand Down Expand Up @@ -1199,12 +1204,14 @@ fn run_inner(app: App) -> ! {
}
}

/*
// resolve the hit-testing scene
if let Some((window_id, new_hit_test_results)) = hit_tester_request {
if let Some(w) = active_windows.get_mut(&window_id) {
w.hit_tester = new_hit_test_results.resolve();
}
}
*/

// end: handle control flow and app shutdown
let new_control_flow = if !active_windows.is_empty() {
Expand Down Expand Up @@ -1528,7 +1535,7 @@ fn create_window(
}

let timer = Timer::new(data.clone(), hot_reload_timer, config.system_callbacks.get_system_time_fn)
.with_interval(StdDuration::from_millis(200).into());
.with_interval(StdDuration::from_millis(800).into());

timers
.entry(glutin_window_id)
Expand Down
Loading

0 comments on commit 8d67426

Please sign in to comment.