widgetry

Trait SimpleState

Source
pub trait SimpleState<A> {
    // Required method
    fn on_click(
        &mut self,
        ctx: &mut EventCtx<'_>,
        app: &mut A,
        action: &str,
        panel: &mut Panel,
    ) -> Transition<A>;

    // Provided methods
    fn on_click_custom(
        &mut self,
        _ctx: &mut EventCtx<'_>,
        _app: &mut A,
        _action: Box<dyn CloneableAny>,
        _panel: &mut Panel,
    ) -> Transition<A> { ... }
    fn panel_changed(
        &mut self,
        _: &mut EventCtx<'_>,
        _: &mut A,
        _: &mut Panel,
    ) -> Option<Transition<A>> { ... }
    fn on_mouseover(&mut self, _: &mut EventCtx<'_>, _: &mut A) { ... }
    fn other_event(&mut self, _: &mut EventCtx<'_>, _: &mut A) -> Transition<A> { ... }
    fn draw(&self, _: &mut GfxCtx<'_>, _: &A) { ... }
    fn draw_baselayer(&self) -> DrawBaselayer { ... }
}
Expand description

Many states fit a pattern of managing a single panel, handling mouseover events, and other interactions on the map. Implementing this instead of State reduces some boilerplate.

Required Methods§

Source

fn on_click( &mut self, ctx: &mut EventCtx<'_>, app: &mut A, action: &str, panel: &mut Panel, ) -> Transition<A>

Called when something on the panel has been clicked. Since the action is just a string, the fallback case can just use unreachable!().

Provided Methods§

Source

fn on_click_custom( &mut self, _ctx: &mut EventCtx<'_>, _app: &mut A, _action: Box<dyn CloneableAny>, _panel: &mut Panel, ) -> Transition<A>

Called when something on the panel has been clicked.

Source

fn panel_changed( &mut self, _: &mut EventCtx<'_>, _: &mut A, _: &mut Panel, ) -> Option<Transition<A>>

Called when something on the panel has changed. If a transition is returned, stop handling the event and immediately apply the transition.

Source

fn on_mouseover(&mut self, _: &mut EventCtx<'_>, _: &mut A)

Called when the mouse has moved.

Source

fn other_event(&mut self, _: &mut EventCtx<'_>, _: &mut A) -> Transition<A>

If a panel on_click event didn’t occur and panel_changed didn’t return transition, then call this to handle all other events.

Source

fn draw(&self, _: &mut GfxCtx<'_>, _: &A)

Source

fn draw_baselayer(&self) -> DrawBaselayer

Implementations§

Source§

impl<A: 'static> dyn SimpleState<A>

Source

pub fn new_state( panel: Panel, inner: Box<dyn SimpleState<A>>, ) -> Box<dyn State<A>>

Implementors§

impl SimpleState<SimpleApp<Options>> for ScoreHomes

impl SimpleState<App> for ChallengesPicker

impl SimpleState<App> for ShareProposal

impl SimpleState<App> for OneBlock

impl SimpleState<App> for UberTurnPicker

impl SimpleState<App> for UberTurnViewer

impl SimpleState<App> for GenericCompareCounts

impl SimpleState<App> for EditingMarker

impl SimpleState<App> for DevToolsMode

impl SimpleState<App> for StopSignEditor

impl SimpleState<App> for ChangeDuration

impl SimpleState<App> for ShowAbsolute

impl SimpleState<App> for ShowRelative

impl SimpleState<App> for TuneRelative

impl SimpleState<App> for Proposals

impl SimpleState<App> for About

impl SimpleState<App> for ChangeScenario

impl SimpleState<App> for DepartureSummary

impl SimpleState<App> for About

impl SimpleState<App> for ShareProposal

impl SimpleState<App> for EditRoad

impl<A: AppLike + 'static> SimpleState<A> for TitleScreen<A>

impl<A: AppLike + 'static, S: TripManagementState<A>> SimpleState<A> for RenameTrip<A, S>

impl SimpleState<SimpleApp<Session>> for Results

impl SimpleState<SimpleApp<Session>> for Strategize

impl SimpleState<SimpleApp<Session>> for Credits

impl SimpleState<SimpleApp<Session>> for TitleScreen