@@ -1222,6 +1222,118 @@ impl DrawApp {
12221222 }
12231223 }
12241224
1225+ /// The select tool's modes and what it does with the selection, in every editor's toolbar.
1226+ pub ( super ) fn selection_options ( & mut self , ui : & mut egui:: Ui , context : & egui:: Context ) {
1227+ use icy_draw:: document:: SelectionMode ;
1228+ let mut mode = self . document . selection_mode ;
1229+ if widgets:: segmented (
1230+ ui,
1231+ & mut mode,
1232+ & [
1233+ ( SelectionMode :: Rectangle , fl ! ( "tool-select-normal" ) , fl ! ( "select-mode-normal-tooltip" ) ) ,
1234+ ( SelectionMode :: Character , fl ! ( "tool-select-character" ) , fl ! ( "select-mode-character-tooltip" ) ) ,
1235+ ( SelectionMode :: Attribute , fl ! ( "tool-select-attribute" ) , fl ! ( "select-mode-attribute-tooltip" ) ) ,
1236+ ( SelectionMode :: Foreground , fl ! ( "tool-select-foreground" ) , fl ! ( "select-mode-foreground-tooltip" ) ) ,
1237+ ( SelectionMode :: Background , fl ! ( "tool-select-background" ) , fl ! ( "select-mode-background-tooltip" ) ) ,
1238+ ] ,
1239+ ) {
1240+ self . document . finish ( ) ;
1241+ self . document . selection_mode = mode;
1242+ }
1243+ widgets:: divider ( ui) ;
1244+ let selected = self . document . with_state ( |state| state. is_something_selected ( ) ) ;
1245+ let paint = self . document . can_paint ( ) ;
1246+ let shortcut = |label : String , shortcut : & egui:: KeyboardShortcut | format ! ( "{label} ({})" , context. format_shortcut( shortcut) ) ;
1247+ let key = |label : String , key : & str | format ! ( "{label} ({key})" ) ;
1248+ if self
1249+ . icons
1250+ . button ( ui, "select" , & shortcut ( fl ! ( "menu-select-all" ) , & menus:: SELECT_ALL ) , false )
1251+ . clicked ( )
1252+ {
1253+ self . select_all ( ) ;
1254+ }
1255+ ui. add_enabled_ui ( selected, |ui| {
1256+ ui. spacing_mut ( ) . item_spacing . x = 4.0 ;
1257+ if self
1258+ . icons
1259+ . button ( ui, "deselect" , & shortcut ( fl ! ( "select-deselect" ) , & menus:: DESELECT ) , false )
1260+ . clicked ( )
1261+ {
1262+ self . edit ( |state| state. clear_selection ( ) ) ;
1263+ }
1264+ widgets:: divider ( ui) ;
1265+ if self . icons . button ( ui, "file_copy" , & fl ! ( "select-copy" ) , false ) . clicked ( ) {
1266+ self . copy ( context) ;
1267+ }
1268+ ui. add_enabled_ui ( paint, |ui| {
1269+ ui. spacing_mut ( ) . item_spacing . x = 4.0 ;
1270+ if self . icons . button ( ui, "library_add" , & key ( fl ! ( "shortcut-block-copy" ) , "C" ) , false ) . clicked ( ) {
1271+ let result = self . document . float_selection ( false ) ;
1272+ self . result ( result) ;
1273+ }
1274+ if self . icons . button ( ui, "move" , & key ( fl ! ( "shortcut-block-move" ) , "M" ) , false ) . clicked ( ) {
1275+ let result = self . document . float_selection ( true ) ;
1276+ self . result ( result) ;
1277+ }
1278+ widgets:: divider ( ui) ;
1279+ if self . icons . button ( ui, "fill" , & key ( fl ! ( "shortcut-block-fill" ) , "F" ) , false ) . clicked ( ) {
1280+ let result = self . document . fill_selection ( ) ;
1281+ self . result ( result) ;
1282+ }
1283+ let erase = egui:: KeyboardShortcut :: new ( egui:: Modifiers :: NONE , egui:: Key :: Delete ) ;
1284+ if self
1285+ . icons
1286+ . button ( ui, "eraser" , & shortcut ( fl ! ( "shortcut-erase-selection" ) , & erase) , false )
1287+ . clicked ( )
1288+ {
1289+ self . document . finish ( ) ;
1290+ self . edit ( |state| state. erase_selection ( ) ) ;
1291+ }
1292+ if self . icons . button ( ui, "crop" , & shortcut ( fl ! ( "menu-crop" ) , & menus:: CROP ) , false ) . clicked ( ) {
1293+ self . edit ( |state| state. crop ( ) ) ;
1294+ }
1295+ widgets:: divider ( ui) ;
1296+ if self . icons . button ( ui, "flip_tool" , & fl ! ( "menu-flip-x" ) , false ) . clicked ( ) {
1297+ self . edit ( |state| state. flip_x ( ) ) ;
1298+ }
1299+ if self . icons . button ( ui, "swap" , & fl ! ( "menu-flip-y" ) , false ) . clicked ( ) {
1300+ self . edit ( |state| state. flip_y ( ) ) ;
1301+ }
1302+ let justify = self . icons . button ( ui, "format_align_center" , & fl ! ( "select-justify" ) , false ) ;
1303+ egui:: Popup :: menu ( & justify) . id ( egui:: Id :: new ( "select-justify" ) ) . show ( |ui| {
1304+ if ui. button ( fl ! ( "menu-justifyleft" ) ) . clicked ( ) {
1305+ self . edit ( |state| state. justify_left ( ) ) ;
1306+ ui. close ( ) ;
1307+ }
1308+ if ui. button ( fl ! ( "menu-justifycenter" ) ) . clicked ( ) {
1309+ self . edit ( |state| state. center ( ) ) ;
1310+ ui. close ( ) ;
1311+ }
1312+ if ui. button ( fl ! ( "menu-justifyright" ) ) . clicked ( ) {
1313+ self . edit ( |state| state. justify_right ( ) ) ;
1314+ ui. close ( ) ;
1315+ }
1316+ } ) ;
1317+ } ) ;
1318+ } ) ;
1319+ widgets:: divider ( ui) ;
1320+ match selection_add_type ( ui. input ( |input| input. modifiers ) ) {
1321+ AddType :: Add => {
1322+ ui. label ( egui:: RichText :: new ( fl ! ( "select-mode-add" ) ) . color ( appearance:: PRIMARY ) . strong ( ) ) ;
1323+ }
1324+ AddType :: Subtract => {
1325+ ui. label ( egui:: RichText :: new ( fl ! ( "select-mode-subtract" ) ) . color ( appearance:: PRIMARY ) . strong ( ) ) ;
1326+ }
1327+ AddType :: Default => {
1328+ if let Some ( bounds) = self . document . with_state ( |state| state. selection ( ) . map ( |selection| selection. as_rectangle ( ) ) ) {
1329+ ui. weak ( format ! ( "{}, {} · {} × {}" , bounds. left( ) , bounds. top( ) , bounds. width( ) , bounds. height( ) ) ) ;
1330+ } else {
1331+ ui. weak ( fl ! ( "tool-select-description" ) ) ;
1332+ }
1333+ }
1334+ }
1335+ }
1336+
12251337 /// Anchoring, a new layer, stamping, rotating, flipping and cancelling of a floating paste.
12261338 pub ( super ) fn paste_options ( & mut self , ui : & mut egui:: Ui ) {
12271339 use icy_draw:: document:: PasteAction ;
@@ -1484,116 +1596,7 @@ impl DrawApp {
14841596 Tool :: Pipette => {
14851597 self . pipette_options ( ui) ;
14861598 }
1487- Tool :: Select => {
1488- use icy_draw:: document:: SelectionMode ;
1489- let mut mode = self . document . selection_mode ;
1490- if widgets:: segmented (
1491- ui,
1492- & mut mode,
1493- & [
1494- ( SelectionMode :: Rectangle , fl ! ( "tool-select-normal" ) , fl ! ( "select-mode-normal-tooltip" ) ) ,
1495- ( SelectionMode :: Character , fl ! ( "tool-select-character" ) , fl ! ( "select-mode-character-tooltip" ) ) ,
1496- ( SelectionMode :: Attribute , fl ! ( "tool-select-attribute" ) , fl ! ( "select-mode-attribute-tooltip" ) ) ,
1497- ( SelectionMode :: Foreground , fl ! ( "tool-select-foreground" ) , fl ! ( "select-mode-foreground-tooltip" ) ) ,
1498- ( SelectionMode :: Background , fl ! ( "tool-select-background" ) , fl ! ( "select-mode-background-tooltip" ) ) ,
1499- ] ,
1500- ) {
1501- self . document . finish ( ) ;
1502- self . document . selection_mode = mode;
1503- }
1504- widgets:: divider ( ui) ;
1505- let selected = self . document . with_state ( |state| state. is_something_selected ( ) ) ;
1506- let paint = self . document . can_paint ( ) ;
1507- let shortcut = |label : String , shortcut : & egui:: KeyboardShortcut | format ! ( "{label} ({})" , context. format_shortcut( shortcut) ) ;
1508- let key = |label : String , key : & str | format ! ( "{label} ({key})" ) ;
1509- if self
1510- . icons
1511- . button ( ui, "select" , & shortcut ( fl ! ( "menu-select-all" ) , & menus:: SELECT_ALL ) , false )
1512- . clicked ( )
1513- {
1514- self . select_all ( ) ;
1515- }
1516- ui. add_enabled_ui ( selected, |ui| {
1517- ui. spacing_mut ( ) . item_spacing . x = 4.0 ;
1518- if self
1519- . icons
1520- . button ( ui, "deselect" , & shortcut ( fl ! ( "select-deselect" ) , & menus:: DESELECT ) , false )
1521- . clicked ( )
1522- {
1523- self . edit ( |state| state. clear_selection ( ) ) ;
1524- }
1525- widgets:: divider ( ui) ;
1526- if self . icons . button ( ui, "file_copy" , & fl ! ( "select-copy" ) , false ) . clicked ( ) {
1527- self . copy ( context) ;
1528- }
1529- ui. add_enabled_ui ( paint, |ui| {
1530- ui. spacing_mut ( ) . item_spacing . x = 4.0 ;
1531- if self . icons . button ( ui, "library_add" , & key ( fl ! ( "shortcut-block-copy" ) , "C" ) , false ) . clicked ( ) {
1532- let result = self . document . float_selection ( false ) ;
1533- self . result ( result) ;
1534- }
1535- if self . icons . button ( ui, "move" , & key ( fl ! ( "shortcut-block-move" ) , "M" ) , false ) . clicked ( ) {
1536- let result = self . document . float_selection ( true ) ;
1537- self . result ( result) ;
1538- }
1539- widgets:: divider ( ui) ;
1540- if self . icons . button ( ui, "fill" , & key ( fl ! ( "shortcut-block-fill" ) , "F" ) , false ) . clicked ( ) {
1541- let result = self . document . fill_selection ( ) ;
1542- self . result ( result) ;
1543- }
1544- let erase = egui:: KeyboardShortcut :: new ( egui:: Modifiers :: NONE , egui:: Key :: Delete ) ;
1545- if self
1546- . icons
1547- . button ( ui, "eraser" , & shortcut ( fl ! ( "shortcut-erase-selection" ) , & erase) , false )
1548- . clicked ( )
1549- {
1550- self . document . finish ( ) ;
1551- self . edit ( |state| state. erase_selection ( ) ) ;
1552- }
1553- if self . icons . button ( ui, "crop" , & shortcut ( fl ! ( "menu-crop" ) , & menus:: CROP ) , false ) . clicked ( ) {
1554- self . edit ( |state| state. crop ( ) ) ;
1555- }
1556- widgets:: divider ( ui) ;
1557- if self . icons . button ( ui, "flip_tool" , & fl ! ( "menu-flip-x" ) , false ) . clicked ( ) {
1558- self . edit ( |state| state. flip_x ( ) ) ;
1559- }
1560- if self . icons . button ( ui, "swap" , & fl ! ( "menu-flip-y" ) , false ) . clicked ( ) {
1561- self . edit ( |state| state. flip_y ( ) ) ;
1562- }
1563- let justify = self . icons . button ( ui, "format_align_center" , & fl ! ( "select-justify" ) , false ) ;
1564- egui:: Popup :: menu ( & justify) . id ( egui:: Id :: new ( "select-justify" ) ) . show ( |ui| {
1565- if ui. button ( fl ! ( "menu-justifyleft" ) ) . clicked ( ) {
1566- self . edit ( |state| state. justify_left ( ) ) ;
1567- ui. close ( ) ;
1568- }
1569- if ui. button ( fl ! ( "menu-justifycenter" ) ) . clicked ( ) {
1570- self . edit ( |state| state. center ( ) ) ;
1571- ui. close ( ) ;
1572- }
1573- if ui. button ( fl ! ( "menu-justifyright" ) ) . clicked ( ) {
1574- self . edit ( |state| state. justify_right ( ) ) ;
1575- ui. close ( ) ;
1576- }
1577- } ) ;
1578- } ) ;
1579- } ) ;
1580- widgets:: divider ( ui) ;
1581- match selection_add_type ( ui. input ( |input| input. modifiers ) ) {
1582- AddType :: Add => {
1583- ui. label ( egui:: RichText :: new ( fl ! ( "select-mode-add" ) ) . color ( appearance:: PRIMARY ) . strong ( ) ) ;
1584- }
1585- AddType :: Subtract => {
1586- ui. label ( egui:: RichText :: new ( fl ! ( "select-mode-subtract" ) ) . color ( appearance:: PRIMARY ) . strong ( ) ) ;
1587- }
1588- AddType :: Default => {
1589- if let Some ( bounds) = self . document . with_state ( |state| state. selection ( ) . map ( |selection| selection. as_rectangle ( ) ) ) {
1590- ui. weak ( format ! ( "{}, {} · {} × {}" , bounds. left( ) , bounds. top( ) , bounds. width( ) , bounds. height( ) ) ) ;
1591- } else {
1592- ui. weak ( fl ! ( "tool-select-description" ) ) ;
1593- }
1594- }
1595- }
1596- }
1599+ Tool :: Select => self . selection_options ( ui, context) ,
15971600
15981601 Tool :: Tag => {
15991602 if self . icons . button ( ui, "tag" , & fl ! ( "tag-list-title" ) , false ) . clicked ( ) {
0 commit comments