mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 00:34:25 +00:00
Wells: the spelling suggestions, the file list and the recently used glyphs in a sunken well, and the notes editor in the text well
This commit is contained in:
@@ -5,8 +5,8 @@ use craft_behavior::{DisplayOrder, EditEvent, ItemSource, Selection};
|
||||
use craft_host::{PickId, PickKind, PickRequest};
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{
|
||||
Bind, BodyCx, CollectionEvent, Entry, Held, NoValue, Outcome, Props as _, Remember as _, ReorderRule, SelectMode, Show as _, ShowCollection as _,
|
||||
ShowContainer as _, clicked,
|
||||
Bind, BodyCx, CollectionEvent, Entry, Held, NoValue, Outcome, Pad, Props as _, Remember as _, ReorderRule, SelectMode, Show as _,
|
||||
ShowCollection as _, ShowContainer as _, clicked,
|
||||
};
|
||||
use craft_ui::display::{Shade, Text};
|
||||
use craft_ui::form::Field;
|
||||
@@ -14,6 +14,7 @@ use craft_ui::layout_components::Stack;
|
||||
use craft_ui::list::{List, ListRow};
|
||||
use craft_ui::pickers::Select;
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use craft_ui::style::SurfaceKind;
|
||||
use egui::{Response, Ui};
|
||||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
@@ -245,13 +246,20 @@ impl<'a> FileListPicker<'a> {
|
||||
let source = Rows::new(paths);
|
||||
let mut selection =
|
||||
now.selected.as_ref().filter(|path| paths.contains(path)).map_or_else(Selection::default, |path| Selection::single(path.clone()));
|
||||
let list = List::new(words.files.clone()).id_salt("files");
|
||||
let list = if folder {
|
||||
list.select(SelectMode::None)
|
||||
} else {
|
||||
list.select(SelectMode::Single).deletable(true).reorder(ReorderRule::new()).selection(Bind::bound(&mut selection))
|
||||
};
|
||||
let events = list.show_items(ui, &source, &mut |path, _| file_row(path, info)).events;
|
||||
let events = Stack::new()
|
||||
.surface(SurfaceKind::Sunken)
|
||||
.pad(Pad::Control)
|
||||
.show(ui, |ui, _| {
|
||||
let list = List::new(words.files.clone()).id_salt("files");
|
||||
let list = if folder {
|
||||
list.select(SelectMode::None)
|
||||
} else {
|
||||
list.select(SelectMode::Single).deletable(true).reorder(ReorderRule::new()).selection(Bind::bound(&mut selection))
|
||||
};
|
||||
list.show_items(ui, &source, &mut |path, _| file_row(path, info)).events
|
||||
})
|
||||
.inner
|
||||
.unwrap_or_default();
|
||||
if folder {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use std::sync::Arc;
|
||||
use craft_behavior::Selection;
|
||||
use craft_host::Section;
|
||||
use craft_ui::contract::{
|
||||
ActivateOn, Bind, CollectionEvent, Entry, NoValue, Outcome, Pattern, Props, Remember as _, SelectMode, Show as _, ShowCollection as _,
|
||||
ActivateOn, Bind, CollectionEvent, Entry, NoValue, Outcome, Pad, Pattern, Props, Remember as _, SelectMode, Show as _, ShowCollection as _,
|
||||
ShowContainer as _,
|
||||
};
|
||||
use craft_ui::display::Text;
|
||||
@@ -21,7 +21,7 @@ use craft_ui::pickers::Select;
|
||||
use craft_ui::primitives::ContentPainterCx;
|
||||
use craft_ui::primitives::textures::{Priority, Revision, ThumbPaint, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails};
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use craft_ui::style::DataColor;
|
||||
use craft_ui::style::{DataColor, SurfaceKind};
|
||||
use craft_ui::tile_grid::{CaptionPlace, ThumbnailSlider, Tile, TileGrid, TileZoom};
|
||||
use egui::{ColorImage, Rect, Response, Ui};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -356,19 +356,23 @@ impl<'a> GlyphsPanel<'a> {
|
||||
Text::new(words.recent.clone()).show(ui);
|
||||
let recent: Vec<char> = state.recent.iter().filter_map(|g| g.chars().next()).collect();
|
||||
let mut activated: Option<String> = None;
|
||||
let strip = TileGrid::<usize>::new(words.recent.clone())
|
||||
.thumb_size(ThumbSize::Medium)
|
||||
.zoom(RECENT_ZOOM)
|
||||
.caption(CaptionPlace::None)
|
||||
.select(SelectMode::Single)
|
||||
.activate(ActivateOn::Click)
|
||||
.sizing(craft_ui::contract::Sizing::FillWidth)
|
||||
.show_items(ui, &Chars(&recent), &mut |key, _| {
|
||||
let c = recent[*key];
|
||||
let name = words.cell.fill(&[("char", &c.to_string()), ("code", &code(c))]);
|
||||
Tile::new(name).thumb(ThumbAspect::SQUARE, paint(&face_family, &face_style, c))
|
||||
});
|
||||
for event in strip.response.events {
|
||||
let strip = Stack::new().fill_width().surface(SurfaceKind::Sunken).pad(Pad::Control).show(ui, |ui, _| {
|
||||
TileGrid::<usize>::new(words.recent.clone())
|
||||
.thumb_size(ThumbSize::Medium)
|
||||
.zoom(RECENT_ZOOM)
|
||||
.caption(CaptionPlace::None)
|
||||
.select(SelectMode::Single)
|
||||
.activate(ActivateOn::Click)
|
||||
.sizing(craft_ui::contract::Sizing::FillWidth)
|
||||
.show_items(ui, &Chars(&recent), &mut |key, _| {
|
||||
let c = recent[*key];
|
||||
let name = words.cell.fill(&[("char", &c.to_string()), ("code", &code(c))]);
|
||||
Tile::new(name).thumb(ThumbAspect::SQUARE, paint(&face_family, &face_style, c))
|
||||
})
|
||||
.response
|
||||
.events
|
||||
});
|
||||
for event in strip.inner.unwrap_or_default() {
|
||||
if let CollectionEvent::Activate(key) = event
|
||||
&& let Some(c) = recent.get(key)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ mod stories;
|
||||
|
||||
mod text;
|
||||
|
||||
use craft_behavior::{EditCommand, EditorInput, Granularity, Metrics, NavMove, PointerButton, PressPhase, Sense, TextPos};
|
||||
use craft_behavior::{EditCommand, EditorInput, Granularity, Insets, Metrics, NavMove, PointerButton, PressPhase, Sense, TextPos};
|
||||
use craft_ui::contract::{
|
||||
Animate as _, Commands as _, Common, Component, Cx, Focus as _, MeasureCx, NoValue, Outcome, PaintUi, PartsCx, Pointer as _, Props as _,
|
||||
Remember as _, Role, WordSetCx as _,
|
||||
@@ -21,7 +21,7 @@ use craft_ui::runtime::commands::ClipItem;
|
||||
use craft_ui::runtime::env::Label;
|
||||
use craft_ui::runtime::focus::KeyUse;
|
||||
use craft_ui::runtime::pending::Pending;
|
||||
use craft_ui::style::{ComponentStyle, DataColor, StyleColor, StyleCx, TypeRole};
|
||||
use craft_ui::style::{ComponentStyle, DataColor, StyleColor, StyleCx, SurfaceLook, TypeRole};
|
||||
use egui::epaint::text::CharIndex;
|
||||
use egui::{Pos2, Rect, Response, Vec2};
|
||||
|
||||
@@ -67,11 +67,13 @@ impl Outcome for NotesEditorOutput {
|
||||
}
|
||||
}
|
||||
|
||||
/// The notes' look: the body type at the pane's zoom, the text and caret colours and the selection fill. Indents are
|
||||
/// in document points and scale with the text size.
|
||||
/// The notes' look: the text well with a field's side padding all round, the body type at the pane's zoom, the text and
|
||||
/// caret colours and the selection fill. Indents are in document points and scale with the text size.
|
||||
#[derive(Clone, Debug, PartialEq, ComponentStyle)]
|
||||
#[non_exhaustive]
|
||||
pub struct NotesEditorStyle {
|
||||
#[style(surface)]
|
||||
surface: SurfaceLook,
|
||||
#[style(metrics)]
|
||||
metrics: Metrics,
|
||||
/// The text colour.
|
||||
@@ -311,7 +313,8 @@ impl Component for NotesEditor<'_> {
|
||||
|
||||
fn style(cx: &StyleCx<'_>, _: NotesEditorStyleKey) -> NotesEditorStyle {
|
||||
NotesEditorStyle {
|
||||
metrics: Metrics::new(),
|
||||
surface: cx.text_well(),
|
||||
metrics: Metrics::new().padding(Insets::uniform(cx.control().pad_x)),
|
||||
ink: cx.color(cx.tokens.color.text.normal),
|
||||
muted: cx.color(cx.tokens.color.text.muted),
|
||||
selection: cx.color(cx.tokens.color.state.text_selection),
|
||||
|
||||
@@ -25,7 +25,7 @@ use craft_host::Section;
|
||||
use craft_theme::variant::Tone;
|
||||
use craft_ui::choice::Checkbox;
|
||||
use craft_ui::contract::{
|
||||
Bind, CollectionEvent, NoValue, Outcome, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, Sizing,
|
||||
Bind, CollectionEvent, NoValue, Outcome, Pad, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, Sizing,
|
||||
};
|
||||
use craft_ui::dialog::{Dialog, DialogId, DialogOutput, DialogResult, DialogStack, StackDialog, dialog_id};
|
||||
use craft_ui::display::Text;
|
||||
@@ -36,6 +36,7 @@ use craft_ui::notices::{Notice, NoticeLayout};
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::runtime::overlay::CloseReason;
|
||||
use craft_ui::sections::{DialogRole, FooterButton};
|
||||
use craft_ui::style::SurfaceKind;
|
||||
use craft_ui::text::TextField;
|
||||
use egui::{Response, Ui};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -251,13 +252,22 @@ impl CheckSpellingDialog {
|
||||
let source = keyed(&positions, |at: &usize| *at);
|
||||
let mut selection =
|
||||
suggestions.iter().position(|s| s.as_str() == change_to.as_str()).map_or_else(Selection::default, Selection::single);
|
||||
let events = List::new(words.suggestions.clone())
|
||||
.select(SelectMode::Single)
|
||||
.sizing(Sizing::Content)
|
||||
.natural_height(true)
|
||||
.selection(Bind::bound(&mut selection))
|
||||
.show_items(ui, &source, &mut |at, _| ListRow::new(suggestions[*at].clone()))
|
||||
.events;
|
||||
let events = Stack::new()
|
||||
.fill_width()
|
||||
.surface(SurfaceKind::Sunken)
|
||||
.pad(Pad::Control)
|
||||
.show(ui, |ui, _| {
|
||||
List::new(words.suggestions.clone())
|
||||
.select(SelectMode::Single)
|
||||
// A `Fill` list measures its rows in the content-sized dialog and spans the well.
|
||||
.sizing(Sizing::Fill)
|
||||
.natural_height(true)
|
||||
.selection(Bind::bound(&mut selection))
|
||||
.show_items(ui, &source, &mut |at, _| ListRow::new(suggestions[*at].clone()))
|
||||
.events
|
||||
})
|
||||
.inner
|
||||
.unwrap_or_default();
|
||||
for event in events {
|
||||
match event {
|
||||
CollectionEvent::Selection(SelectionChange::Set(rows)) => {
|
||||
|
||||
Reference in New Issue
Block a user