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: ModeThe current session Mode.
prev_mode: Option<Mode>The previous Mode.
state: StateThe current session State.
width: f32The width of the session workspace.
height: f32The height of the session workspace.
hidpi_factor: f64The HiDPI factor of the host.
cursor: SessionCoordsThe 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: MessageThe current message displayed to the user.
fg: Rgba8The session foreground color.
bg: Rgba8The session background color.
key_bindings: KeyBindingsThe list of all active key bindings.
selection: Option<Selection>Current pixel selection.
settings: SettingsThe session’s current settings.
settings_changed: HashSet<String>Settings recently changed.
views: ViewManagerViews loaded in the session.
effects: Vec<Effect>Effects produced by the session. Cleared at the beginning of every update.
cmdline: CommandLineThe current state of the command line.
palette: PaletteThe color palette.
avg_time: DurationAverage time it takes for a session update.
tool: ToolThe current tool. Only used in Normal mode.
prev_tool: Option<Tool>The previous tool, if any.
Implementations§
Source§impl Session
impl Session
Sourcepub const DEFAULT_VIEW_W: u32 = 128u32
pub const DEFAULT_VIEW_W: u32 = 128u32
Default view width.
Sourcepub const DEFAULT_VIEW_H: u32 = 128u32
pub const DEFAULT_VIEW_H: u32 = 128u32
Default view height.
Sourcepub fn new(
w: u32,
h: u32,
hidpi_factor: f64,
resources: ResourceManager,
base_dirs: ProjectDirs,
) -> Self
pub fn new( w: u32, h: u32, hidpi_factor: f64, resources: ResourceManager, base_dirs: ProjectDirs, ) -> Self
Create a new un-initialized session.
pub fn reset(&mut self) -> Result<()>
Sourcepub fn transition(&mut self, to: State)
pub fn transition(&mut self, to: State)
Transition to a new state. Only allows valid state transitions.
Sourcepub fn update(
&mut self,
events: &mut Vec<Event>,
exec: Rc<RefCell<Execution>>,
delta: Duration,
avg_time: Duration,
) -> Vec<Effect>
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.
Sourcepub fn quit(&mut self, r: ExitReason)
pub fn quit(&mut self, r: ExitReason)
Quit the session.
Sourcepub fn snap(
&self,
p: SessionCoords,
offx: f32,
offy: f32,
zoom: f32,
) -> SessionCoords
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.
Sourcepub fn message<D: Display>(&mut self, msg: D, t: MessageType)
pub fn message<D: Display>(&mut self, msg: D, t: MessageType)
Messages Display a message to the user. Also logs.
Sourcepub fn active_view(&self) -> &View
pub fn active_view(&self) -> &View
Sourcepub fn active_view_mut(&mut self) -> &mut View
pub fn active_view_mut(&mut self) -> &mut View
Sourcepub fn activate(&mut self, id: ViewId)
pub fn activate(&mut self, id: ViewId)
Activate a view. This makes the given view the “active” view.
Sourcepub fn window_to_session_coords(
&self,
position: LogicalPosition,
) -> SessionCoords
pub fn window_to_session_coords( &self, position: LogicalPosition, ) -> SessionCoords
Convert “logical” window coordinates to session coordinates.
Sourcepub fn view_coords(&self, v: ViewId, p: SessionCoords) -> ViewCoords<f32>
pub fn view_coords(&self, v: ViewId, p: SessionCoords) -> ViewCoords<f32>
Convert session coordinates to view coordinates of the given view.
Sourcepub fn session_coords(&self, v: ViewId, p: ViewCoords<f32>) -> SessionCoords
pub fn session_coords(&self, v: ViewId, p: ViewCoords<f32>) -> SessionCoords
Convert view coordinates to session coordinates.
Sourcepub fn active_view_coords(&self, p: SessionCoords) -> ViewCoords<f32>
pub fn active_view_coords(&self, p: SessionCoords) -> ViewCoords<f32>
Convert session coordinates to view coordinates of the active view.
Sourcepub fn is_selected(&self, p: ViewCoords<i32>) -> bool
pub fn is_selected(&self, p: ViewCoords<i32>) -> bool
Check whether a point is inside the selection, if any.
Sourcepub fn edit<P: AsRef<Path>>(&mut self, paths: &[P]) -> Result<()>
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.
Sourcepub fn save_view(&mut self, id: ViewId) -> Result<()>
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.
Sourcepub fn save_view_as<P: AsRef<Path>>(
&mut self,
id: ViewId,
path: P,
) -> Result<()>
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.