switch to Rc<RefCell<...>> for widget storage

This commit is contained in:
2025-12-07 14:36:38 -05:00
parent 38266debb6
commit c99d466b75
27 changed files with 685 additions and 784 deletions

View File

@@ -5,9 +5,9 @@ use winit::dpi::{LogicalPosition, LogicalSize};
pub struct Selector;
impl<W: 'static> WidgetAttr<W> for Selector {
type Input = WidgetId<TextEdit>;
type Input = WidgetRef<TextEdit>;
fn run(ui: &mut Ui, container: &WidgetId<W>, id: Self::Input) {
fn run(ui: &mut Ui, container: &WidgetRef<W>, id: Self::Input) {
let container = container.clone();
ui.register_event(
&container.clone(),
@@ -30,7 +30,7 @@ pub struct Selectable;
impl WidgetAttr<TextEdit> for Selectable {
type Input = ();
fn run(ui: &mut Ui, id: &WidgetId<TextEdit>, _: Self::Input) {
fn run(ui: &mut Ui, id: &WidgetRef<TextEdit>, _: Self::Input) {
let id = id.clone();
ui.register_event(&id.clone(), CursorSense::click_or_drag(), move |ctx| {
select(ctx.ui, id.clone(), ctx.state, ctx.data);
@@ -38,11 +38,11 @@ impl WidgetAttr<TextEdit> for Selectable {
}
}
fn select(ui: &mut Ui, id: WidgetId<TextEdit>, state: &mut UiState, data: CursorData) {
fn select(ui: &mut Ui, id: WidgetRef<TextEdit>, state: &mut UiState, data: CursorData) {
let now = Instant::now();
let recent = (now - state.last_click) < Duration::from_millis(300);
state.last_click = now;
ui.text(&id)
id.get_mut()
.select(data.cursor, data.size, data.sense.is_dragging(), recent);
if let Some(region) = ui.window_region(&id) {
state.window.set_ime_allowed(true);