dash-frontend: games: pagination
This commit is contained in:
@@ -195,7 +195,7 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
|
||||
color: TOOLTIP_COLOR,
|
||||
border_color: TOOLTIP_BORDER_COLOR,
|
||||
border: 2.0,
|
||||
round: WLength::Percent(1.0),
|
||||
round: WLength::Units(24.0),
|
||||
..Default::default()
|
||||
}),
|
||||
taffy::Style {
|
||||
|
||||
@@ -138,6 +138,7 @@ pub type ModifyLayoutStateFunc = Box<dyn FnOnce(ModifyLayoutStateData) -> anyhow
|
||||
|
||||
pub enum LayoutTask {
|
||||
RemoveWidget(WidgetID),
|
||||
SetWidgetStyle(WidgetID, event::StyleSetRequest),
|
||||
ModifyLayoutState(ModifyLayoutStateFunc),
|
||||
PlaySound(WguiSoundType),
|
||||
Dispatch(Box<dyn FnOnce(&mut CallbackDataCommon) -> anyhow::Result<()>>),
|
||||
@@ -706,12 +707,51 @@ impl Layout {
|
||||
func(&mut c.common())?;
|
||||
c.finish()?;
|
||||
}
|
||||
LayoutTask::SetWidgetStyle(widget_id, style_request) => {
|
||||
self.set_style_request(widget_id, style_request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_style_request(&mut self, widget_id: WidgetID, style_request: event::StyleSetRequest) {
|
||||
let Some(node_id) = self.state.nodes.get(widget_id) else {
|
||||
return;
|
||||
};
|
||||
|
||||
// taffy requires us to copy this whole 536-byte style struct.
|
||||
// we can't get `&mut Style` directly from taffy unfortunately
|
||||
let mut cur_style = self.state.tree.style(*node_id).unwrap().clone() /* always safe */;
|
||||
|
||||
match style_request {
|
||||
event::StyleSetRequest::Display(display) => {
|
||||
// refresh the component in case if visibility/display mode has changed
|
||||
if cur_style.display != display
|
||||
&& let Some(component) = self.registered_components_to_refresh.get(node_id)
|
||||
{
|
||||
self.components_to_refresh_once.insert(component.clone());
|
||||
}
|
||||
|
||||
cur_style.display = display;
|
||||
}
|
||||
event::StyleSetRequest::Margin(margin) => {
|
||||
cur_style.margin = margin;
|
||||
}
|
||||
event::StyleSetRequest::Width(val) => {
|
||||
cur_style.size.width = val;
|
||||
}
|
||||
event::StyleSetRequest::Height(val) => {
|
||||
cur_style.size.height = val;
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(e) = self.state.tree.set_style(*node_id, cur_style) {
|
||||
log::error!("failed to set style for taffy widget ID {node_id:?}: {e:?}");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process_alterables(&mut self, alterables: EventAlterables) -> anyhow::Result<()> {
|
||||
for task in alterables.tasks {
|
||||
self.tasks.push(task);
|
||||
@@ -747,39 +787,7 @@ impl Layout {
|
||||
}
|
||||
|
||||
for (widget_id, style_request) in alterables.style_set_requests {
|
||||
let Some(node_id) = self.state.nodes.get(widget_id) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
// taffy requires us to copy this whole 536-byte style struct.
|
||||
// we can't get `&mut Style` directly from taffy unfortunately
|
||||
let mut cur_style = self.state.tree.style(*node_id).unwrap().clone() /* always safe */;
|
||||
|
||||
match style_request {
|
||||
event::StyleSetRequest::Display(display) => {
|
||||
// refresh the component in case if visibility/display mode has changed
|
||||
if cur_style.display != display
|
||||
&& let Some(component) = self.registered_components_to_refresh.get(node_id)
|
||||
{
|
||||
self.components_to_refresh_once.insert(component.clone());
|
||||
}
|
||||
|
||||
cur_style.display = display;
|
||||
}
|
||||
event::StyleSetRequest::Margin(margin) => {
|
||||
cur_style.margin = margin;
|
||||
}
|
||||
event::StyleSetRequest::Width(val) => {
|
||||
cur_style.size.width = val;
|
||||
}
|
||||
event::StyleSetRequest::Height(val) => {
|
||||
cur_style.size.height = val;
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(e) = self.state.tree.set_style(*node_id, cur_style) {
|
||||
log::error!("failed to set style for taffy widget ID {node_id:?}: {e:?}");
|
||||
}
|
||||
self.set_style_request(widget_id, style_request);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -47,7 +47,7 @@ impl WidgetObj for WidgetRectangle {
|
||||
let boundary = drawing::Boundary::construct_relative(state.transform_stack);
|
||||
|
||||
let round_units = match self.params.round {
|
||||
WLength::Units(units) => units as u8,
|
||||
WLength::Units(units) => (f32::min(boundary.size.x, boundary.size.y) as u8 / 2).min(units as u8),
|
||||
WLength::Percent(percent) => (f32::min(boundary.size.x, boundary.size.y) * percent / 2.0) as u8,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user