Skip to content

Commit

Permalink
wip - send interface
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Nov 23, 2023
1 parent 2f4e91e commit 9bb8637
Show file tree
Hide file tree
Showing 8 changed files with 716 additions and 339 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,17 @@ Access via [https://localhost:8080](https://localhost:8080)
This project currently supports Chrome browser extension target, but this component of the project is under heavy development and is not ready for use.
```
./build-chrome
```
```

<details>
<summary>Windows x64</summary>
Windows build instructions
</details>
<details>
<summary>Linux</summary>
Linux build instructions
</details>
<details>
<summary>Mac OS</summary>
Mac OS build instructions
</details>
106 changes: 106 additions & 0 deletions core/src/egui/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,109 @@ impl From<LayoutJobBuilder> for WidgetText {
builder.job.into()
}
}

pub trait HyperlinkExtension {
fn hyperlink_to_tab(&mut self, text: impl Into<WidgetText>, url: impl Into<String>)
-> Response;
fn hyperlink_url_to_tab(&mut self, url: impl Into<String>) -> Response;
}

impl HyperlinkExtension for Ui {
fn hyperlink_to_tab(
&mut self,
text: impl Into<WidgetText>,
url: impl Into<String>,
) -> Response {
let url = url.into();
Hyperlink::from_label_and_url(text, url)
.open_in_new_tab(true)
.ui(self)
}
fn hyperlink_url_to_tab(&mut self, url: impl Into<String>) -> Response {
let url = url.into();
Hyperlink::from_label_and_url(url.clone(), url)
.open_in_new_tab(true)
.ui(self)
}
}

type TextEditorCreateFn<'editor> = Box<dyn FnOnce(&mut Ui, &mut String) -> Response + 'editor>;
type TextEditorChangeFn<'editor> = Box<dyn FnOnce(&str) + 'editor>;
type TextEditorSubmitFn<'editor, Focus> = Box<dyn FnOnce(&str, &mut Focus) + 'editor>;

pub struct TextEditor<'editor, Focus>
where
Focus: PartialEq + Copy,
{
user_text: &'editor mut String,
focus_mut: &'editor mut Focus,
focus_value: Focus,
editor_create_fn: TextEditorCreateFn<'editor>,
editor_change_fn: Option<TextEditorChangeFn<'editor>>,
editor_submit_fn: Option<TextEditorSubmitFn<'editor, Focus>>,
}

impl<'editor, Focus> TextEditor<'editor, Focus>
where
Focus: PartialEq + Copy,
{
pub fn new(
user_text: &'editor mut String,
focus_mut_ref: &'editor mut Focus,
focus_value: Focus,
editor_create_fn: impl FnOnce(&mut Ui, &mut String) -> Response + 'editor,
) -> Self {
Self {
user_text,
focus_mut: focus_mut_ref,
focus_value,
editor_create_fn: Box::new(editor_create_fn),
editor_change_fn: None,
editor_submit_fn: None,
}
}

pub fn change(mut self, change: impl FnOnce(&str) + 'editor) -> Self {
self.editor_change_fn = Some(Box::new(change));
self
}

pub fn submit(mut self, submit: impl FnOnce(&str, &mut Focus) + 'editor) -> Self {
self.editor_submit_fn = Some(Box::new(submit));
self
}

pub fn build(self, ui: &mut Ui) -> Response {
let TextEditor {
user_text,
focus_mut,
focus_value,
editor_create_fn,
editor_change_fn,
editor_submit_fn,
} = self;

let mut editor_text = user_text.clone();
let response = editor_create_fn(ui, &mut editor_text);

if response.gained_focus() {
*focus_mut = focus_value;
} else if *focus_mut == focus_value && !response.has_focus() {
response.request_focus();
};

if *user_text != editor_text {
*user_text = editor_text;
if let Some(editor_change_fn) = editor_change_fn {
editor_change_fn(user_text.as_str());
}
} else if response.text_edit_submit(ui) {
*user_text = editor_text;
if let Some(editor_submit_fn) = editor_submit_fn {
editor_submit_fn(user_text.as_str(), focus_mut);
}
}

response
}
}
2 changes: 2 additions & 0 deletions core/src/egui/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Theme {
pub kaspa_color: Color32,
pub hyperlink_color: Color32,
pub node_data_color: Color32,
pub balance_color: Color32,
pub panel_icon_size: IconSize,
pub panel_margin_size: f32,
pub error_icon_size: IconSize,
Expand Down Expand Up @@ -43,6 +44,7 @@ impl Default for Theme {
hyperlink_color: Color32::from_rgb(141, 184, 178),
// node_data_color : Color32::from_rgb(217, 233,230),
node_data_color: Color32::WHITE,
balance_color: Color32::WHITE,
// node_data_color : Color32::from_rgb(151, 209, 198),
// panel_icon_size : IconSize::new(26.,36.),
panel_icon_size: IconSize::new(Vec2::splat(26.)).with_padding(Vec2::new(6., 0.)),
Expand Down
Loading

0 comments on commit 9bb8637

Please sign in to comment.