Struct Session

Source
pub struct Session {
Show 24 fields pub mode: Mode, pub prev_mode: Option<Mode>, pub state: State, pub width: f32, pub height: f32, pub hidpi_factor: f64, pub cursor: SessionCoords, pub hover_color: Option<Rgba8>, pub hover_view: Option<ViewId>, pub offset: Vector2<f32>, pub message: Message, pub fg: Rgba8, pub bg: Rgba8, pub key_bindings: KeyBindings, pub selection: Option<Selection>, pub settings: Settings, pub settings_changed: HashSet<String>, pub views: ViewManager, pub effects: Vec<Effect>, pub cmdline: CommandLine, pub palette: Palette, pub avg_time: Duration, pub tool: Tool, pub prev_tool: Option<Tool>, /* private fields */
}
Expand description

The user session.

Stores all relevant session state.

Fields§

§mode: Mode

The current session Mode.

§prev_mode: Option<Mode>

The previous Mode.

§state: State

The current session State.

§width: f32

The width of the session workspace.

§height: f32

The height of the session workspace.

§hidpi_factor: f64

The HiDPI factor of the host.

§cursor: SessionCoords

The cursor coordinates.

§hover_color: Option<Rgba8>

The color under the cursor, if any.

§hover_view: Option<ViewId>

The view under the cursor, if any.

§offset: Vector2<f32>

The workspace offset. Views are offset by this vector.

§message: Message

The current message displayed to the user.

§fg: Rgba8

The session foreground color.

§bg: Rgba8

The session background color.

§key_bindings: KeyBindings

The list of all active key bindings.

§selection: Option<Selection>

Current pixel selection.

§settings: Settings

The session’s current settings.

§settings_changed: HashSet<String>

Settings recently changed.

§views: ViewManager

Views loaded in the session.

§effects: Vec<Effect>

Effects produced by the session. Cleared at the beginning of every update.

§cmdline: CommandLine

The current state of the command line.

§palette: Palette

The color palette.

§avg_time: Duration

Average time it takes for a session update.

§tool: Tool

The current tool. Only used in Normal mode.

§prev_tool: Option<Tool>

The previous tool, if any.

Implementations§

Source§

impl Session

Source

pub const MAX_VIEWS: usize = 64usize

Maximum number of views in a session.

Source

pub const DEFAULT_VIEW_W: u32 = 128u32

Default view width.

Source

pub const DEFAULT_VIEW_H: u32 = 128u32

Default view height.

Source

pub fn new( w: u32, h: u32, hidpi_factor: f64, resources: ResourceManager, base_dirs: ProjectDirs, ) -> Self

Create a new un-initialized session.

Source

pub fn init(self, source: Option<PathBuf>) -> Result<Self>

Initialize a session.

Source

pub fn reset(&mut self) -> Result<()>

Source

pub fn blank(&mut self, fs: FileStatus, w: u32, h: u32)

Create a blank view.

Source

pub fn transition(&mut self, to: State)

Transition to a new state. Only allows valid state transitions.

Source

pub fn update( &mut self, events: &mut Vec<Event>, exec: Rc<RefCell<Execution>>, delta: Duration, avg_time: Duration, ) -> Vec<Effect>

Update the session by processing new user events and advancing the internal state.

Source

pub fn quit(&mut self, r: ExitReason)

Quit the session.

Source

pub fn effects(&mut self) -> Vec<Effect>

Drain and return effects.

Source

pub fn transform(&self) -> Matrix4<f32>

Return the session offset as a transformation matrix.

Source

pub fn snap( &self, p: SessionCoords, offx: f32, offy: f32, zoom: f32, ) -> SessionCoords

Snap the given session coordinates to the pixel grid. This only has an effect at zoom levels greater than 1.0.

Source

pub fn message<D: Display>(&mut self, msg: D, t: MessageType)

Messages Display a message to the user. Also logs.

Source

pub fn view(&self, id: ViewId) -> &View

View functions Get the view with the given id.

§Panics

Panics if the view isn’t found.

Source

pub fn view_mut(&mut self, id: ViewId) -> &mut View

Get the view with the given id (mutable).

§Panics

Panics if the view isn’t found.

Source

pub fn active_view(&self) -> &View

Get the currently active view.

§Panics

Panics if there is no active view.

Source

pub fn active_view_mut(&mut self) -> &mut View

Get the currently active view (mutable).

§Panics

Panics if there is no active view.

Source

pub fn activate(&mut self, id: ViewId)

Activate a view. This makes the given view the “active” view.

Source

pub fn is_active(&self, id: ViewId) -> bool

Check whether a view is active.

Source

pub fn window_to_session_coords( &self, position: LogicalPosition, ) -> SessionCoords

Convert “logical” window coordinates to session coordinates.

Source

pub fn view_coords(&self, v: ViewId, p: SessionCoords) -> ViewCoords<f32>

Convert session coordinates to view coordinates of the given view.

Source

pub fn session_coords(&self, v: ViewId, p: ViewCoords<f32>) -> SessionCoords

Convert view coordinates to session coordinates.

Source

pub fn active_view_coords(&self, p: SessionCoords) -> ViewCoords<f32>

Convert session coordinates to view coordinates of the active view.

Source

pub fn is_selected(&self, p: ViewCoords<i32>) -> bool

Check whether a point is inside the selection, if any.

Source

pub fn edit<P: AsRef<Path>>(&mut self, paths: &[P]) -> Result<()>

Edit paths.

Loads the given files into the session. Returns an error if one of the paths couldn’t be loaded. If a path points to a directory, loads all files within that directory.

If a path doesn’t exist, creates a blank view for that path.

Source

pub fn save_view(&mut self, id: ViewId) -> Result<()>

Save the given view to disk with the current file name. Returns an error if the view has no file name.

Source

pub fn save_view_as<P: AsRef<Path>>( &mut self, id: ViewId, path: P, ) -> Result<()>

Save a view with the given file name. Returns an error if the format is not supported.

Source

pub fn handle_event(&mut self, event: Event, exec: &mut Execution)

Source

pub fn handle_resized(&mut self, size: LogicalSize)

Source

pub fn color_at(&self, v: ViewId, p: ViewCoords<u32>) -> Option<Rgba8>

Get the color at the given view coordinate.

Auto Trait Implementations§

§

impl Freeze for Session

§

impl !RefUnwindSafe for Session

§

impl !Send for Session

§

impl !Sync for Session

§

impl Unpin for Session

§

impl !UnwindSafe for Session

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.