remember checked settings in memory

This commit is contained in:
Aleksander
2025-11-06 21:12:26 +01:00
parent e087eb3743
commit 433b7f53b5
13 changed files with 136 additions and 69 deletions

View File

@@ -84,18 +84,18 @@ fn set_box_checked(widgets: &layout::WidgetMap, data: &Data, checked: bool) {
}
impl ComponentCheckbox {
pub fn set_text(&self, state: &LayoutState, common: &mut CallbackDataCommon, text: Translation) {
let Some(mut label) = state.widgets.get_as::<WidgetLabel>(self.data.id_label) else {
pub fn set_text(&self, common: &mut CallbackDataCommon, text: Translation) {
let Some(mut label) = common.state.widgets.get_as::<WidgetLabel>(self.data.id_label) else {
return;
};
label.set_text(common, text);
}
pub fn set_checked(&self, state: &LayoutState, alterables: &mut EventAlterables, checked: bool) {
pub fn set_checked(&self, common: &mut CallbackDataCommon, checked: bool) {
self.state.borrow_mut().checked = checked;
set_box_checked(&state.widgets, &self.data, checked);
alterables.mark_redraw();
set_box_checked(&common.state.widgets, &self.data, checked);
common.alterables.mark_redraw();
}
pub fn on_toggle(&self, func: CheckboxToggleCallback) {

View File

@@ -6,7 +6,7 @@ use std::{
};
use glam::Vec2;
use slotmap::{new_key_type, DenseSlotMap};
use slotmap::{DenseSlotMap, new_key_type};
use crate::{
animation::{self, Animation},

View File

@@ -8,14 +8,14 @@ use std::{
use crate::{
animation::Animations,
components::{Component, InitData},
drawing::{self, push_scissor_stack, push_transform_stack, Boundary, ANSI_BOLD_CODE, ANSI_RESET_CODE},
drawing::{self, ANSI_BOLD_CODE, ANSI_RESET_CODE, Boundary, push_scissor_stack, push_transform_stack},
event::{self, CallbackDataCommon, EventAlterables},
globals::WguiGlobals,
widget::{self, div::WidgetDiv, EventParams, EventResult, WidgetObj, WidgetState},
widget::{self, EventParams, EventResult, WidgetObj, WidgetState, div::WidgetDiv},
};
use glam::{vec2, Vec2};
use slotmap::{new_key_type, HopSlotMap, SecondaryMap};
use glam::{Vec2, vec2};
use slotmap::{HopSlotMap, SecondaryMap, new_key_type};
use taffy::{NodeId, TaffyTree, TraversePartialTree};
new_key_type! {
@@ -196,7 +196,34 @@ fn add_child_internal(
))
}
pub struct LayoutCommon<'a> {
alterables: EventAlterables,
layout: &'a mut Layout,
}
impl LayoutCommon<'_> {
pub const fn common(&mut self) -> CallbackDataCommon<'_> {
CallbackDataCommon {
alterables: &mut self.alterables,
state: &self.layout.state,
}
}
pub fn finish(self) -> anyhow::Result<()> {
self.layout.process_alterables(self.alterables)?;
Ok(())
}
}
impl Layout {
// helper function
pub fn start_common(&mut self) -> LayoutCommon<'_> {
LayoutCommon {
alterables: EventAlterables::default(),
layout: self,
}
}
pub fn as_rc(self) -> RcLayout {
Rc::new(RefCell::new(self))
}
@@ -580,9 +607,7 @@ impl Layout {
pub fn update(&mut self, size: Vec2, timestep_alpha: f32) -> anyhow::Result<()> {
let mut alterables = EventAlterables::default();
self.animations.process(&self.state, &mut alterables, timestep_alpha);
self.process_alterables(alterables)?;
self.try_recompute_layout(size)?;
Ok(())