mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-04-08 17:05:59 +02:00
Rename view_context to build_context
This commit is contained in:
parent
40a984e137
commit
11a4d24d52
@ -30,7 +30,7 @@ use crate::{
|
||||
canvas::Painter,
|
||||
constants,
|
||||
data_conversion::ConvertedData,
|
||||
tuine::{Application, Element, Status, ViewContext},
|
||||
tuine::{Application, Element, Status, BuildContext},
|
||||
units::data_units::DataUnit,
|
||||
Pid,
|
||||
};
|
||||
@ -251,7 +251,7 @@ impl Application for AppState {
|
||||
self.terminator.load(SeqCst)
|
||||
}
|
||||
|
||||
fn view<'b>(&mut self, ctx: &mut ViewContext<'_>) -> Element<Self::Message> {
|
||||
fn view<'b>(&mut self, ctx: &mut BuildContext<'_>) -> Element<Self::Message> {
|
||||
match self.current_screen {
|
||||
CurrentScreen::Main => {
|
||||
// The main screen.
|
||||
|
@ -150,7 +150,7 @@ pub struct WidgetLayoutRoot {
|
||||
|
||||
impl WidgetLayoutRoot {
|
||||
pub fn build<Message>(
|
||||
&self, ctx: &mut ViewContext<'_>, app_state: &AppState, data: &mut ConvertedData<'_>,
|
||||
&self, ctx: &mut BuildContext<'_>, app_state: &AppState, data: &mut ConvertedData<'_>,
|
||||
) -> Element<Message> {
|
||||
Flex::column_with_children(
|
||||
self.children
|
||||
@ -186,7 +186,7 @@ pub enum WidgetLayoutNode {
|
||||
|
||||
impl WidgetLayoutNode {
|
||||
fn new_row<Message>(
|
||||
ctx: &mut ViewContext<'_>, app_state: &AppState, data: &mut ConvertedData<'_>,
|
||||
ctx: &mut BuildContext<'_>, app_state: &AppState, data: &mut ConvertedData<'_>,
|
||||
children: &[WidgetLayoutNode], parent_ratio: u16,
|
||||
) -> FlexElement<Message> {
|
||||
FlexElement::with_flex(
|
||||
@ -201,7 +201,7 @@ impl WidgetLayoutNode {
|
||||
}
|
||||
|
||||
fn new_col<Message>(
|
||||
ctx: &mut ViewContext<'_>, app_state: &AppState, data: &mut ConvertedData<'_>,
|
||||
ctx: &mut BuildContext<'_>, app_state: &AppState, data: &mut ConvertedData<'_>,
|
||||
children: &[WidgetLayoutNode], parent_ratio: u16,
|
||||
) -> FlexElement<Message> {
|
||||
FlexElement::with_flex(
|
||||
@ -216,7 +216,7 @@ impl WidgetLayoutNode {
|
||||
}
|
||||
|
||||
fn new_carousel<Message>(
|
||||
ctx: &mut ViewContext<'_>, app_state: &AppState, data: &mut ConvertedData<'_>,
|
||||
ctx: &mut BuildContext<'_>, app_state: &AppState, data: &mut ConvertedData<'_>,
|
||||
children: &[BottomWidgetType], selected: bool,
|
||||
) -> FlexElement<Message> {
|
||||
// FIXME: Carousel!
|
||||
@ -231,7 +231,7 @@ impl WidgetLayoutNode {
|
||||
}
|
||||
|
||||
fn make_element<Message>(
|
||||
ctx: &mut ViewContext<'_>, app_state: &AppState, data: &mut ConvertedData<'_>,
|
||||
ctx: &mut BuildContext<'_>, app_state: &AppState, data: &mut ConvertedData<'_>,
|
||||
widget_type: &BottomWidgetType, selected: bool,
|
||||
) -> Element<Message> {
|
||||
let painter = &app_state.painter;
|
||||
@ -270,7 +270,7 @@ impl WidgetLayoutNode {
|
||||
}
|
||||
|
||||
pub fn build<Message>(
|
||||
&self, ctx: &mut ViewContext<'_>, app_state: &AppState, data: &mut ConvertedData<'_>,
|
||||
&self, ctx: &mut BuildContext<'_>, app_state: &AppState, data: &mut ConvertedData<'_>,
|
||||
) -> FlexElement<Message> {
|
||||
match self {
|
||||
WidgetLayoutNode::Row {
|
||||
|
@ -4,7 +4,7 @@ use tui::Terminal;
|
||||
|
||||
use super::{
|
||||
runtime::{self, RuntimeEvent},
|
||||
Element, Event, Status, ViewContext,
|
||||
Element, Event, Status, BuildContext,
|
||||
};
|
||||
|
||||
/// An alias to the [`tui::backend::CrosstermBackend`] writing to [`std::io::Stdout`].
|
||||
@ -22,7 +22,7 @@ pub trait Application: Sized {
|
||||
fn is_terminated(&self) -> bool;
|
||||
|
||||
/// Creates the user interface.
|
||||
fn view<'b>(&mut self, ctx: &mut ViewContext<'_>) -> Element<Self::Message>;
|
||||
fn view<'b>(&mut self, ctx: &mut BuildContext<'_>) -> Element<Self::Message>;
|
||||
|
||||
/// To run upon stopping the application.
|
||||
fn destructor(&mut self) {}
|
||||
|
@ -24,3 +24,6 @@ pub use padding::*;
|
||||
|
||||
pub mod time_graph;
|
||||
pub use time_graph::TimeGraph;
|
||||
|
||||
pub mod focus;
|
||||
pub use focus::*;
|
||||
|
@ -145,7 +145,7 @@ where
|
||||
|
||||
type ComponentState = ShortcutState;
|
||||
|
||||
fn build(ctx: &mut crate::tuine::ViewContext<'_>, props: Self::Properties) -> Self {
|
||||
fn build(ctx: &mut crate::tuine::BuildContext<'_>, props: Self::Properties) -> Self {
|
||||
let (key, state) =
|
||||
ctx.register_and_mut_state::<_, Self::ComponentState>(Location::caller());
|
||||
let mut forest: FxHashMap<Vec<Event>, bool> = FxHashMap::default();
|
||||
|
@ -211,7 +211,7 @@ impl<Message> StatefulComponent<Message> for TextTable<Message> {
|
||||
|
||||
type ComponentState = TextTableState;
|
||||
|
||||
fn build(ctx: &mut crate::tuine::ViewContext<'_>, mut props: Self::Properties) -> Self {
|
||||
fn build(ctx: &mut crate::tuine::BuildContext<'_>, mut props: Self::Properties) -> Self {
|
||||
let sort = props.sort;
|
||||
let (key, state) = ctx.register_and_mut_state_with_default::<_, Self::ComponentState, _>(
|
||||
Location::caller(),
|
||||
@ -372,15 +372,15 @@ impl<Message> TmpComponent<Message> for TextTable<Message> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tuine::{
|
||||
text_table::SortType, StateMap, StatefulComponent, TextTableProps, ViewContext,
|
||||
text_table::SortType, StateMap, StatefulComponent, TextTableProps, BuildContext,
|
||||
};
|
||||
|
||||
use super::{DataRow, TextTable};
|
||||
|
||||
type Message = ();
|
||||
|
||||
fn ctx<'a>(map: &'a mut StateMap) -> ViewContext<'a> {
|
||||
ViewContext::new(map)
|
||||
fn ctx<'a>(map: &'a mut StateMap) -> BuildContext<'a> {
|
||||
BuildContext::new(map)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -22,15 +22,6 @@ use super::{Bounds, DrawContext, Element, Event, LayoutNode, Size, StateContext,
|
||||
#[allow(unused_variables)]
|
||||
#[enum_dispatch]
|
||||
pub trait TmpComponent<Message> {
|
||||
/// Builds as component into an [`Element`](super::Element).
|
||||
#[track_caller]
|
||||
fn build(self, ctx: ()) -> Element<Message>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Draws the component.
|
||||
fn draw<Backend>(
|
||||
&mut self, state_ctx: &mut StateContext<'_>, draw_ctx: &DrawContext<'_>,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::tuine::{State, StateContext, ViewContext};
|
||||
use crate::tuine::{State, StateContext, BuildContext};
|
||||
|
||||
use super::TmpComponent;
|
||||
|
||||
@ -11,5 +11,5 @@ pub trait StatefulComponent<Message>: TmpComponent<Message> {
|
||||
type ComponentState: State;
|
||||
|
||||
#[track_caller]
|
||||
fn build(ctx: &mut ViewContext<'_>, props: Self::Properties) -> Self;
|
||||
fn build(ctx: &mut BuildContext<'_>, props: Self::Properties) -> Self;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ pub struct BatteryTable {}
|
||||
|
||||
impl super::AppWidget for BatteryTable {
|
||||
fn build(
|
||||
ctx: &mut crate::tuine::ViewContext<'_>, painter: &crate::canvas::Painter,
|
||||
ctx: &mut crate::tuine::BuildContext<'_>, painter: &crate::canvas::Painter,
|
||||
config: &crate::app::AppConfig, data: &mut crate::data_conversion::ConvertedData<'_>,
|
||||
) -> Self {
|
||||
Self {}
|
||||
|
@ -8,7 +8,7 @@ pub struct CpuGraph {}
|
||||
|
||||
impl super::AppWidget for CpuGraph {
|
||||
fn build(
|
||||
ctx: &mut crate::tuine::ViewContext<'_>, painter: &crate::canvas::Painter,
|
||||
ctx: &mut crate::tuine::BuildContext<'_>, painter: &crate::canvas::Painter,
|
||||
config: &crate::app::AppConfig, data: &mut crate::data_conversion::ConvertedData<'_>,
|
||||
) -> Self {
|
||||
Self {}
|
||||
|
@ -9,7 +9,7 @@ pub struct CpuSimple {}
|
||||
|
||||
impl super::AppWidget for CpuSimple {
|
||||
fn build(
|
||||
ctx: &mut crate::tuine::ViewContext<'_>, painter: &crate::canvas::Painter,
|
||||
ctx: &mut crate::tuine::BuildContext<'_>, painter: &crate::canvas::Painter,
|
||||
config: &crate::app::AppConfig, data: &mut crate::data_conversion::ConvertedData<'_>,
|
||||
) -> Self {
|
||||
Self {}
|
||||
|
@ -4,7 +4,7 @@ use crate::{
|
||||
data_conversion::ConvertedData,
|
||||
tuine::{
|
||||
Bounds, DrawContext, LayoutNode, SimpleTable, Size, StateContext, Status, TmpComponent,
|
||||
ViewContext,
|
||||
BuildContext,
|
||||
},
|
||||
};
|
||||
|
||||
@ -21,7 +21,7 @@ impl<Message> DiskTable<Message> {}
|
||||
|
||||
impl<Message> AppWidget for DiskTable<Message> {
|
||||
fn build(
|
||||
ctx: &mut ViewContext<'_>, painter: &Painter, config: &AppConfig,
|
||||
ctx: &mut BuildContext<'_>, painter: &Painter, config: &AppConfig,
|
||||
data: &mut ConvertedData<'_>,
|
||||
) -> Self {
|
||||
let style = simple_table::StyleSheet {
|
||||
|
@ -7,7 +7,7 @@ pub struct MemGraph {}
|
||||
|
||||
impl super::AppWidget for MemGraph {
|
||||
fn build(
|
||||
ctx: &mut crate::tuine::ViewContext<'_>, painter: &crate::canvas::Painter,
|
||||
ctx: &mut crate::tuine::BuildContext<'_>, painter: &crate::canvas::Painter,
|
||||
config: &crate::app::AppConfig, data: &mut crate::data_conversion::ConvertedData<'_>,
|
||||
) -> Self {
|
||||
Self {}
|
||||
|
@ -9,7 +9,7 @@ pub struct MemSimple {}
|
||||
|
||||
impl super::AppWidget for MemSimple {
|
||||
fn build(
|
||||
ctx: &mut crate::tuine::ViewContext<'_>, painter: &crate::canvas::Painter,
|
||||
ctx: &mut crate::tuine::BuildContext<'_>, painter: &crate::canvas::Painter,
|
||||
config: &crate::app::AppConfig, data: &mut crate::data_conversion::ConvertedData<'_>,
|
||||
) -> Self {
|
||||
Self {}
|
||||
|
@ -31,11 +31,11 @@ pub use mem_simple::*;
|
||||
pub mod net_simple;
|
||||
pub use net_simple::*;
|
||||
|
||||
use crate::{app::AppConfig, canvas::Painter, data_conversion::ConvertedData, tuine::ViewContext};
|
||||
use crate::{app::AppConfig, canvas::Painter, data_conversion::ConvertedData, tuine::BuildContext};
|
||||
|
||||
pub trait AppWidget {
|
||||
fn build(
|
||||
ctx: &mut ViewContext<'_>, painter: &Painter, config: &AppConfig,
|
||||
ctx: &mut BuildContext<'_>, painter: &Painter, config: &AppConfig,
|
||||
data: &mut ConvertedData<'_>,
|
||||
) -> Self;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ pub struct NetGraph {}
|
||||
|
||||
impl super::AppWidget for NetGraph {
|
||||
fn build(
|
||||
ctx: &mut crate::tuine::ViewContext<'_>, painter: &crate::canvas::Painter,
|
||||
ctx: &mut crate::tuine::BuildContext<'_>, painter: &crate::canvas::Painter,
|
||||
config: &crate::app::AppConfig, data: &mut crate::data_conversion::ConvertedData<'_>,
|
||||
) -> Self {
|
||||
Self {}
|
||||
|
@ -9,7 +9,7 @@ pub struct NetSimple {}
|
||||
|
||||
impl super::AppWidget for NetSimple {
|
||||
fn build(
|
||||
ctx: &mut crate::tuine::ViewContext<'_>, painter: &crate::canvas::Painter,
|
||||
ctx: &mut crate::tuine::BuildContext<'_>, painter: &crate::canvas::Painter,
|
||||
config: &crate::app::AppConfig, data: &mut crate::data_conversion::ConvertedData<'_>,
|
||||
) -> Self {
|
||||
Self {}
|
||||
|
@ -7,7 +7,7 @@ pub struct ProcessTable {}
|
||||
|
||||
impl super::AppWidget for ProcessTable {
|
||||
fn build(
|
||||
ctx: &mut crate::tuine::ViewContext<'_>, painter: &crate::canvas::Painter,
|
||||
ctx: &mut crate::tuine::BuildContext<'_>, painter: &crate::canvas::Painter,
|
||||
config: &crate::app::AppConfig, data: &mut crate::data_conversion::ConvertedData<'_>,
|
||||
) -> Self {
|
||||
Self {}
|
||||
|
@ -5,7 +5,7 @@ use crate::tuine::{
|
||||
self, block,
|
||||
shortcut::ShortcutProps,
|
||||
text_table::{self, DataRow, SortType, TextTableProps, TextTableState},
|
||||
Block, Event, Shortcut, StatefulComponent, Status, TextTable, TmpComponent, ViewContext,
|
||||
Block, BuildContext, Event, Shortcut, StatefulComponent, Status, TextTable, TmpComponent,
|
||||
};
|
||||
|
||||
/// A set of styles for a [`SimpleTable`].
|
||||
@ -28,7 +28,7 @@ pub struct SimpleTable<Message> {
|
||||
impl<Message> SimpleTable<Message> {
|
||||
#[track_caller]
|
||||
pub fn build<C: Into<std::borrow::Cow<'static, str>>, R: Into<DataRow>>(
|
||||
ctx: &mut ViewContext<'_>, style: StyleSheet, columns: Vec<C>, data: Vec<R>,
|
||||
ctx: &mut BuildContext<'_>, style: StyleSheet, columns: Vec<C>, data: Vec<R>,
|
||||
sort_index: usize,
|
||||
) -> Self {
|
||||
let text_table = TextTable::build(
|
||||
|
@ -4,7 +4,7 @@ use crate::{
|
||||
data_conversion::ConvertedData,
|
||||
tuine::{
|
||||
Bounds, DrawContext, LayoutNode, SimpleTable, Size, StateContext, Status, TmpComponent,
|
||||
ViewContext,
|
||||
BuildContext,
|
||||
},
|
||||
};
|
||||
|
||||
@ -21,7 +21,7 @@ impl<Message> TempTable<Message> {}
|
||||
|
||||
impl<Message> AppWidget for TempTable<Message> {
|
||||
fn build(
|
||||
ctx: &mut ViewContext<'_>, painter: &Painter, config: &AppConfig,
|
||||
ctx: &mut BuildContext<'_>, painter: &Painter, config: &AppConfig,
|
||||
data: &mut ConvertedData<'_>,
|
||||
) -> Self {
|
||||
let style = simple_table::StyleSheet {
|
||||
|
@ -2,12 +2,12 @@ use crate::tuine::{Caller, Key, State, StateMap};
|
||||
|
||||
use super::StateContext;
|
||||
|
||||
pub struct ViewContext<'a> {
|
||||
pub struct BuildContext<'a> {
|
||||
key_counter: usize,
|
||||
state_context: StateContext<'a>,
|
||||
}
|
||||
|
||||
impl<'a> ViewContext<'a> {
|
||||
impl<'a> BuildContext<'a> {
|
||||
pub fn new(state_map: &'a mut StateMap) -> Self {
|
||||
Self {
|
||||
key_counter: 0,
|
@ -4,8 +4,8 @@ pub use state_map::StateMap;
|
||||
pub mod draw_context;
|
||||
pub use draw_context::DrawContext;
|
||||
|
||||
pub mod view_context;
|
||||
pub use view_context::ViewContext;
|
||||
pub mod build_context;
|
||||
pub use build_context::BuildContext;
|
||||
|
||||
pub mod state_context;
|
||||
pub use state_context::StateContext;
|
||||
|
@ -6,7 +6,7 @@ use crate::tuine::Status;
|
||||
|
||||
use super::{
|
||||
build_layout_tree, Application, DrawContext, Element, Event, LayoutNode, StateContext,
|
||||
StateMap, TmpComponent, ViewContext,
|
||||
StateMap, TmpComponent, BuildContext,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@ -118,7 +118,7 @@ fn create_user_interface<A>(application: &mut A, app_data: &mut AppData) -> Elem
|
||||
where
|
||||
A: Application + 'static,
|
||||
{
|
||||
let mut ctx = ViewContext::new(&mut app_data.state_map);
|
||||
let mut ctx = BuildContext::new(&mut app_data.state_map);
|
||||
application.view(&mut ctx)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user